unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, FTexture *hirescheck, bool createexpanded, bool alphatrans) { unsigned char * buffer; int W, H; int isTransparent = -1; // Textures that are already scaled in the texture lump will not get replaced // by hires textures if (gl_texture_usehires && hirescheck != NULL && !alphatrans) { buffer = LoadHiresTexture (hirescheck, &w, &h); if (buffer) { return buffer; } } int exx = bExpandFlag && createexpanded; W = w = tex->GetWidth() + 2 * exx; H = h = tex->GetHeight() + 2 * exx; buffer=new unsigned char[W*(H+1)*4]; memset(buffer, 0, W * (H+1) * 4); FGLBitmap bmp(buffer, W*4, W, H); bmp.SetTranslationInfo(translation, alphatrans); if (tex->bComplex) { FBitmap imgCreate; // The texture contains special processing so it must be composited using the // base bitmap class and then be converted as a whole. if (imgCreate.Create(W, H)) { memset(imgCreate.GetPixels(), 0, W * H * 4); int trans = tex->CopyTrueColorPixels(&imgCreate, exx, exx); bmp.CopyPixelDataRGB(0, 0, imgCreate.GetPixels(), W, H, 4, W * 4, 0, CF_BGRA); tex->CheckTrans(buffer, W*H, trans); isTransparent = tex->gl_info.mIsTransparent; if (bIsTransparent == -1) bIsTransparent = isTransparent; } } else if (translation<=0) { int trans = tex->CopyTrueColorPixels(&bmp, exx, exx); tex->CheckTrans(buffer, W*H, trans); isTransparent = tex->gl_info.mIsTransparent; if (bIsTransparent == -1) bIsTransparent = isTransparent; } else { // When using translations everything must be mapped to the base palette. // Since FTexture's method is doing exactly that by calling GetPixels let's use that here // to do all the dirty work for us. ;) tex->FTexture::CopyTrueColorPixels(&bmp, exx, exx); isTransparent = 0; // This is not conclusive for setting the texture's transparency info. } // if we just want the texture for some checks there's no need for upsampling. if (!createexpanded) return buffer; // [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it. // [BB] Potentially upsample the buffer. return gl_CreateUpsampledTextureBuffer ( tex, buffer, W, H, w, h, !!isTransparent); }
unsigned char * FGLTexture::CreateTexBuffer(int translation, int & w, int & h, FTexture *hirescheck, bool createexpanded, bool alphatrans) { unsigned char * buffer; int W, H; int isTransparent = -1; // Textures that are already scaled in the texture lump will not get replaced // by hires textures if (gl_texture_usehires && hirescheck != NULL && !alphatrans) { buffer = LoadHiresTexture (hirescheck, &w, &h); if (buffer) { return buffer; } } int exx = bExpandFlag && createexpanded; W = w = tex->GetWidth() + 2 * exx; H = h = tex->GetHeight() + 2 * exx; buffer=new unsigned char[W*(H+1)*4]; memset(buffer, 0, W * (H+1) * 4); FBitmap bmp(buffer, W*4, W, H); if (translation <= 0) { // Q: Is this special treatment still needed? Needs to be checked. if (tex->bComplex) { FBitmap imgCreate; // The texture contains special processing so it must be fully composited before being converted as a whole. if (imgCreate.Create(W, H)) { memset(imgCreate.GetPixels(), 0, W * H * 4); int trans = tex->CopyTrueColorPixels(&imgCreate, exx, exx); bmp.CopyPixelDataRGB(0, 0, imgCreate.GetPixels(), W, H, 4, W * 4, 0, CF_BGRA); tex->CheckTrans(buffer, W*H, trans); isTransparent = tex->gl_info.mIsTransparent; if (bIsTransparent == -1) bIsTransparent = isTransparent; } } else { int trans = tex->CopyTrueColorPixels(&bmp, exx, exx); tex->CheckTrans(buffer, W*H, trans); isTransparent = tex->gl_info.mIsTransparent; if (bIsTransparent == -1) bIsTransparent = isTransparent; } } else { #ifdef __MOBILE__ if( alphatrans ) { //tex->CopyTrueColorRedToAlpha(&bmp, exx, exx);# tex->CopyTrueColorPixels(&bmp, exx, exx); uint32_t* pix = ( uint32_t *)bmp.GetPixels(); uint32_t w = bmp.GetWidth(); uint32_t h = bmp.GetHeight(); uint32_t pit = bmp.GetPitch(); LOGI("%d %d %d",w,h,pit); for(int y = 0; y < h; y++ ) { for(int x = 0; x < w; x++ ) { uint32_t p = *pix; p = (p & 0x00FFFFFF) | ((p & 0x00FF0000) << 8); // Copy red to alpha channel *pix = p; pix++; } } isTransparent = 0; } else #endif { // When using translations everything must be mapped to the base palette. // so use CopyTrueColorTranslated tex->CopyTrueColorTranslated(&bmp, exx, exx, 0, GLTranslationPalette::GetPalette(translation)); isTransparent = 0; // This is not conclusive for setting the texture's transparency info. } } // if we just want the texture for some checks there's no need for upsampling. if (!createexpanded) return buffer; // [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it. // [BB] Potentially upsample the buffer. return gl_CreateUpsampledTextureBuffer ( tex, buffer, W, H, w, h, !!isTransparent); }