///////////////////////////////////////////////////////////////// // - Bitmap services (bit-block copy methods) ------------------- ///////////////////////////////////////////////////////////////// // -------------------------------------------------------------- bool GDeviceWin32::CopyPixels( VGDevice* pSrcDC, float alpha ) { return CopyPixels( int(mOriginX), int(mOriginY), pSrcDC, int(pSrcDC->GetXOrigin()), int(pSrcDC->GetYOrigin()), int(pSrcDC->GetWidth()), int(pSrcDC->GetHeight()), alpha ); }
Texture* Texture::LoadTexture(string filename,int flags){ if (flags&128) { //filename=Strip(filename); // get rid of path info filename=File::ResourceFilePath(filename); /*if (filename==""){ cout << "Error: Cannot Find Texture: " << filename << endl; return NULL; }*/ Texture* tex=new Texture(); tex->file=filename; // set tex.flags before TexInList tex->flags=flags; tex->FilterFlags(); // check to see if texture with same properties exists already, if so return existing texture Texture* old_tex=tex->TexInList(); if(old_tex){ return old_tex; }else{ tex_list.push_back(tex); } string filename_left=Left(filename,Len(filename)-4); string filename_right=Right(filename,3); //const char* c_filename_left=filename_left.c_str(); //const char* c_filename_right=filename_right.c_str(); unsigned char* buffer; buffer=stbi_load(filename.c_str(),&tex->width,&tex->height,0,4); unsigned int name; tex->no_frames=1; tex->width=tex->width/6; tex->frames=new unsigned int[6]; unsigned char* dstbuffer=new unsigned char[tex->width*tex->height*4]; glGenTextures (1,&name); glBindTexture (GL_TEXTURE_CUBE_MAP,name); //tex.gltex=tex.gltex[..tex.no_frames] for (int i=0;i<6;i++){ CopyPixels (buffer,tex->width*6, tex->height,tex->width*i, 0, dstbuffer, tex->width, tex->height, 4); switch(i){ case 0: gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_RGBA,tex->width, tex->height, GL_RGBA, GL_UNSIGNED_BYTE, dstbuffer); break; case 1: gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_RGBA,tex->width, tex->height, GL_RGBA, GL_UNSIGNED_BYTE, dstbuffer); break; case 2: gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_RGBA,tex->width, tex->height, GL_RGBA, GL_UNSIGNED_BYTE, dstbuffer); break; case 3: gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, GL_RGBA,tex->width, tex->height, GL_RGBA, GL_UNSIGNED_BYTE, dstbuffer); break; case 4: gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_RGBA,tex->width, tex->height, GL_RGBA, GL_UNSIGNED_BYTE, dstbuffer); break; case 5: gluBuild2DMipmaps(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_RGBA,tex->width, tex->height, GL_RGBA, GL_UNSIGNED_BYTE, dstbuffer); break; } } delete dstbuffer; stbi_image_free(buffer); tex->texture=name; return tex; } else { return Texture::LoadAnimTexture(filename,flags,0,0,0,1); } }
TArray<uint8_t> FMultiPatchTexture::CreatePalettedPixels(int conversion) { int numpix = Width * Height; uint8_t blendwork[256]; bool buildrgb = bComplex; TArray<uint8_t> Pixels(numpix, true); memset (Pixels.Data(), 0, numpix); if (conversion == luminance) { // For alpha textures, downconversion to the palette would lose too much precision if not all patches use the palette. buildrgb = !UseGamePalette(); } else { // For regular textures we can use paletted compositing if all patches are just being copied because they all can create a paletted buffer. if (!buildrgb) for (int i = 0; i < NumParts; ++i) { if (Parts[i].op != OP_COPY) { buildrgb = true; } } } if (conversion == noremap0) { // sky remapping will only happen if // - the texture was defined through a TEXTUREx lump (this implies only trivial copies) // - all patches use the base palette. // All other cases would not be able to properly deal with this special case. // For textual definitions this hack isn't necessary. if (bTextual || !UseGamePalette()) conversion = normal; } if (!buildrgb) { for (int i = 0; i < NumParts; ++i) { uint8_t *trans = Parts[i].Translation? Parts[i].Translation->Remap : nullptr; { if (Parts[i].Blend != 0) { trans = GetBlendMap(Parts[i].Blend, blendwork); } CopyToBlock (Pixels.Data(), Width, Height, Parts[i].Image, Parts[i].OriginX, Parts[i].OriginY, Parts[i].Rotate, trans, conversion); } } } else { // In case there are translucent patches let's do the composition in // True color to keep as much precision as possible before downconverting to the palette. FBitmap PixelsIn; PixelsIn.Create(Width, Height); CopyPixels(&PixelsIn, normal); for(int y = 0; y < Height; y++) { uint8_t *in = PixelsIn.GetPixels() + Width * y * 4; uint8_t *out = Pixels.Data() + y; for (int x = 0; x < Width; x++) { if (*out == 0 && in[3] != 0) { *out = ImageHelpers::RGBToPalette(conversion == luminance, in[2], in[1], in[0]); } out += Height; in += 4; } } } return Pixels; }
Texture* Texture::LoadAnimTexture(string filename,int flags, int frame_width,int frame_height,int first_frame,int frame_count){ //filename=Strip(filename); // get rid of path info filename=File::ResourceFilePath(filename); /*if (filename==""){ cout << "Error: Cannot Find Texture: " << filename << endl; return NULL; }*/ Texture* tex=new Texture(); tex->file=filename; // set tex.flags before TexInList tex->flags=flags; tex->FilterFlags(); // check to see if texture with same properties exists already, if so return existing texture Texture* old_tex=tex->TexInList(); if(old_tex){ return old_tex; }else{ tex_list.push_back(tex); } string filename_left=Left(filename,Len(filename)-4); string filename_right=Right(filename,3); //const char* c_filename_left=filename_left.c_str(); //const char* c_filename_right=filename_right.c_str(); unsigned char* buffer; buffer=stbi_load(filename.c_str(),&tex->width,&tex->height,0,4); unsigned int name; if (frame_count<=2){ glGenTextures (1,&name); glBindTexture (GL_TEXTURE_2D,name); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex->width, tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA,tex->width, tex->height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); tex->texture=name; } else { tex->no_frames=frame_count; tex->frames=new unsigned int[frame_count]; unsigned char* dstbuffer=new unsigned char[frame_width*frame_height*4]; //tex.gltex=tex.gltex[..tex.no_frames] int frames_in_row=tex->width/frame_width; for (int i=0;i<frame_count;i++){ CopyPixels (buffer,tex->width, tex->height,frame_width*(i%frames_in_row), frame_height*(i/frames_in_row), dstbuffer, frame_width, frame_height, 4); glGenTextures (1,&name); glBindTexture (GL_TEXTURE_2D,name); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA,frame_width, frame_height, GL_RGBA, GL_UNSIGNED_BYTE, dstbuffer); tex->frames[i]=name; } tex->texture=tex->frames[0]; tex->width=frame_width; tex->height=frame_height; delete dstbuffer; } stbi_image_free(buffer); return tex; }
static FIBITMAP * DLL_CALLCONV Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) { PKImageDecode *pDecoder = NULL; // decoder interface ERR error_code = 0; // error code as returned by the interface PKPixelFormatGUID guid_format; // loaded pixel format (== input file pixel format if no conversion needed) FREE_IMAGE_TYPE image_type = FIT_UNKNOWN; // input image type unsigned bpp = 0; // input image bit depth FIBITMAP *dib = NULL; // get the I/O stream wrapper WMPStream *pDecodeStream = (WMPStream*)data; if(!handle || !pDecodeStream) { return NULL; } BOOL header_only = (flags & FIF_LOAD_NOPIXELS) == FIF_LOAD_NOPIXELS; try { int width, height; // image dimensions (in pixels) // create a JXR decoder interface and initialize function pointers with *_WMP functions error_code = PKImageDecode_Create_WMP(&pDecoder); JXR_CHECK(error_code); // attach the stream to the decoder ... // ... then read the image container and the metadata error_code = pDecoder->Initialize(pDecoder, pDecodeStream); JXR_CHECK(error_code); // set decoder parameters SetDecoderParameters(pDecoder, flags); // get dst image format specifications unsigned red_mask = 0, green_mask = 0, blue_mask = 0; error_code = GetInputPixelFormat(pDecoder, &guid_format, &image_type, &bpp, &red_mask, &green_mask, &blue_mask); JXR_CHECK(error_code); // get image dimensions pDecoder->GetSize(pDecoder, &width, &height); // allocate dst image { dib = FreeImage_AllocateHeaderT(header_only, image_type, width, height, bpp, red_mask, green_mask, blue_mask); if(!dib) { throw FI_MSG_ERROR_DIB_MEMORY; } if(FreeImage_GetBPP(dib) == 1) { // BD_1 - build a FIC_MINISBLACK palette RGBQUAD *pal = FreeImage_GetPalette(dib); pal[0].rgbRed = pal[0].rgbGreen = pal[0].rgbBlue = 0; pal[1].rgbRed = pal[1].rgbGreen = pal[1].rgbBlue = 255; } } // get image resolution { float resX, resY; // image resolution (in dots per inch) // convert from English units, i.e. dots per inch to universal units, i.e. dots per meter pDecoder->GetResolution(pDecoder, &resX, &resY); FreeImage_SetDotsPerMeterX(dib, (unsigned)(resX / 0.0254F + 0.5F)); FreeImage_SetDotsPerMeterY(dib, (unsigned)(resY / 0.0254F + 0.5F)); } // get metadata & ICC profile error_code = ReadMetadata(pDecoder, dib); JXR_CHECK(error_code); if(header_only) { // header only mode ... // free the decoder pDecoder->Release(&pDecoder); assert(pDecoder == NULL); return dib; } // copy pixels into the dib, perform pixel conversion if needed error_code = CopyPixels(pDecoder, guid_format, dib, width, height); JXR_CHECK(error_code); // free the decoder pDecoder->Release(&pDecoder); assert(pDecoder == NULL); return dib; } catch (const char *message) { // unload the dib FreeImage_Unload(dib); // free the decoder pDecoder->Release(&pDecoder); if(NULL != message) { FreeImage_OutputMessageProc(s_format_id, message); } } return NULL; }