diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index 6be9d0355a..1774354bfc 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -52,8 +52,8 @@ class FVoxelTexture : public FImageSource public: FVoxelTexture(FVoxel *voxel); - int CopyPixels(FBitmap *bmp) override; - TArray Get8BitPixels(bool alphatex) override; + int CopyPixels(FBitmap *bmp, int conversion) override; + TArray GetPalettedPixels(int conversion) override; protected: FVoxel *SourceVox; @@ -79,7 +79,7 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox) // //=========================================================================== -TArray FVoxelTexture::Get8BitPixels(bool alphatex) +TArray FVoxelTexture::GetPalettedPixels(int conversion) { // GetPixels gets called when a translated palette is used so we still need to implement it here. TArray Pixels(256, true); @@ -94,7 +94,7 @@ TArray FVoxelTexture::Get8BitPixels(bool alphatex) pe.g = (pp[1] << 2) | (pp[1] >> 4); pe.b = (pp[2] << 2) | (pp[2] >> 4); // Alphatexture handling is just for completeness, but rather unlikely to be used ever. - Pixels[i] = alphatex? pe.r : ColorMatcher.Pick(pe); + Pixels[i] = conversion == luminance ? pe.r : ColorMatcher.Pick(pe); } } else @@ -116,7 +116,7 @@ TArray FVoxelTexture::Get8BitPixels(bool alphatex) // //=========================================================================== -int FVoxelTexture::CopyPixels(FBitmap *bmp) +int FVoxelTexture::CopyPixels(FBitmap *bmp, int conversion) { PalEntry pe[256]; uint8_t bitmap[256]; diff --git a/src/textures/formats/automaptexture.cpp b/src/textures/formats/automaptexture.cpp index 39285d2803..80395b8eed 100644 --- a/src/textures/formats/automaptexture.cpp +++ b/src/textures/formats/automaptexture.cpp @@ -52,7 +52,7 @@ class FAutomapTexture : public FImageSource { public: FAutomapTexture(int lumpnum); - TArray Get8BitPixels(bool alphatex); + TArray GetPalettedPixels(int conversion) override; }; @@ -91,7 +91,7 @@ FAutomapTexture::FAutomapTexture (int lumpnum) // //========================================================================== -TArray FAutomapTexture::Get8BitPixels(bool alphatex) +TArray FAutomapTexture::GetPalettedPixels(int conversion) { int x, y; FMemLump data = Wads.ReadLump (SourceLump); @@ -99,7 +99,7 @@ TArray FAutomapTexture::Get8BitPixels(bool alphatex) TArray Pixels(Width * Height, true); - const uint8_t *remap = ImageHelpers::GetRemap(alphatex); + const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance); for (x = 0; x < Width; ++x) { for (y = 0; y < Height; ++y) diff --git a/src/textures/formats/brightmaptexture.cpp b/src/textures/formats/brightmaptexture.cpp index 1277cf5273..5d2f48ae04 100644 --- a/src/textures/formats/brightmaptexture.cpp +++ b/src/textures/formats/brightmaptexture.cpp @@ -46,7 +46,7 @@ class FBrightmapTexture : public FImageSource public: FBrightmapTexture (FImageSource *source); - int CopyPixels(FBitmap *bmp) override; + int CopyPixels(FBitmap *bmp, int conversion) override; protected: FImageSource *SourcePic; @@ -68,7 +68,7 @@ FBrightmapTexture::FBrightmapTexture (FImageSource *source) bMasked = false; } -int FBrightmapTexture::CopyPixels(FBitmap *bmp) +int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion) { SourcePic->CopyTranslatedPixels(bmp, TexMan.GlobalBrightmap.Palette); return 0; diff --git a/src/textures/formats/buildtexture.cpp b/src/textures/formats/buildtexture.cpp index 8900d54005..a76e1666e8 100644 --- a/src/textures/formats/buildtexture.cpp +++ b/src/textures/formats/buildtexture.cpp @@ -57,8 +57,8 @@ class FBuildTexture : public FImageSource { public: FBuildTexture (const FString &pathprefix, int tilenum, const uint8_t *pixels, int translation, int width, int height, int left, int top); - TArray Get8BitPixels(bool alphatex) override; - int CopyPixels(FBitmap *bmp) override; + TArray GetPalettedPixels(int conversion) override; + int CopyPixels(FBitmap *bmp, int conversion) override; protected: const uint8_t *RawPixels; @@ -81,19 +81,19 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8 TopOffset = top; } -TArray FBuildTexture::Get8BitPixels(bool alphatex) +TArray FBuildTexture::GetPalettedPixels(int conversion) { TArray Pixels(Width * Height, true); FRemapTable *Remap = translationtables[TRANSLATION_Standard][Translation]; for (int i = 0; i < Width*Height; i++) { auto c = RawPixels[i]; - Pixels[i] = alphatex ? Remap->Palette[c].Luminance() : Remap->Remap[c]; + Pixels[i] = conversion == luminance ? Remap->Palette[c].Luminance() : Remap->Remap[c]; } return Pixels; } -int FBuildTexture::CopyPixels(FBitmap *bmp) +int FBuildTexture::CopyPixels(FBitmap *bmp, int conversion) { PalEntry *Remap = translationtables[TRANSLATION_Standard][Translation]->Palette; bmp->CopyPixelData(0, 0, RawPixels, Width, Height, Height, 1, 0, Remap); diff --git a/src/textures/formats/ddstexture.cpp b/src/textures/formats/ddstexture.cpp index f00a14172f..2672d7b2d8 100644 --- a/src/textures/formats/ddstexture.cpp +++ b/src/textures/formats/ddstexture.cpp @@ -164,7 +164,7 @@ class FDDSTexture : public FImageSource public: FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc); - TArray Get8BitPixels(bool alphatex) override; + TArray GetPalettedPixels(int conversion) override; protected: uint32_t Format; @@ -183,7 +183,7 @@ protected: void DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode); void DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode); - int CopyPixels(FBitmap *bmp) override; + int CopyPixels(FBitmap *bmp, int conversion) override; bool UseBasePalette(); friend class FTexture; @@ -373,7 +373,7 @@ void FDDSTexture::CalcBitShift (uint32_t mask, uint8_t *lshiftp, uint8_t *rshift // //========================================================================== -TArray FDDSTexture::Get8BitPixels(bool alphatex) +TArray FDDSTexture::GetPalettedPixels(int conversion) { auto lump = Wads.OpenLumpReader (SourceLump); @@ -381,7 +381,7 @@ TArray FDDSTexture::Get8BitPixels(bool alphatex) lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet); - int pmode = alphatex ? PIX_Alphatex : PIX_Palette; + int pmode = conversion == luminance ? PIX_Alphatex : PIX_Palette; if (Format >= 1 && Format <= 4) // RGB: Format is # of bytes per pixel { ReadRGB (lump, Pixels.Data(), pmode); @@ -782,7 +782,7 @@ void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t // //=========================================================================== -int FDDSTexture::CopyPixels(FBitmap *bmp) +int FDDSTexture::CopyPixels(FBitmap *bmp, int conversion) { auto lump = Wads.OpenLumpReader (SourceLump); diff --git a/src/textures/formats/emptytexture.cpp b/src/textures/formats/emptytexture.cpp index 1246760b3f..fe8c1e9010 100644 --- a/src/textures/formats/emptytexture.cpp +++ b/src/textures/formats/emptytexture.cpp @@ -51,7 +51,7 @@ class FEmptyTexture : public FImageSource { public: FEmptyTexture (int lumpnum); - TArray Get8BitPixels(bool alphatex) override; + TArray GetPalettedPixels(int conversion) override; }; //========================================================================== @@ -91,7 +91,7 @@ FEmptyTexture::FEmptyTexture (int lumpnum) // //========================================================================== -TArray FEmptyTexture::Get8BitPixels(bool alphatex) +TArray FEmptyTexture::GetPalettedPixels(int conversion) { TArray Pixel(1, true); Pixel[0] = 0; diff --git a/src/textures/formats/flattexture.cpp b/src/textures/formats/flattexture.cpp index 46b9e43fc1..c6ce44fb82 100644 --- a/src/textures/formats/flattexture.cpp +++ b/src/textures/formats/flattexture.cpp @@ -50,7 +50,7 @@ class FFlatTexture : public FImageSource { public: FFlatTexture (int lumpnum); - TArray Get8BitPixels(bool alphatex) override; + TArray GetPalettedPixels(int conversion) override; }; @@ -104,7 +104,7 @@ FFlatTexture::FFlatTexture (int lumpnum) // //========================================================================== -TArray FFlatTexture::Get8BitPixels(bool alphatex) +TArray FFlatTexture::GetPalettedPixels(int conversion) { auto lump = Wads.OpenLumpReader (SourceLump); TArray Pixels(Width*Height, true); @@ -113,7 +113,7 @@ TArray FFlatTexture::Get8BitPixels(bool alphatex) { memset (Pixels.Data() + numread, 0xBB, Width*Height - numread); } - ImageHelpers::FlipSquareBlockRemap(Pixels.Data(), Width, ImageHelpers::GetRemap(alphatex)); + ImageHelpers::FlipSquareBlockRemap(Pixels.Data(), Width, ImageHelpers::GetRemap(conversion == luminance)); return Pixels; } diff --git a/src/textures/formats/imgztexture.cpp b/src/textures/formats/imgztexture.cpp index b87f4b63d1..e505c0714a 100644 --- a/src/textures/formats/imgztexture.cpp +++ b/src/textures/formats/imgztexture.cpp @@ -68,8 +68,8 @@ class FIMGZTexture : public FImageSource public: FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t, bool isalpha); - TArray Get8BitPixels(bool alphatex) override; - int CopyPixels(FBitmap *bmp) override; + TArray GetPalettedPixels(int conversion) override; + int CopyPixels(FBitmap *bmp, int conversion) override; }; @@ -120,7 +120,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1 // //========================================================================== -TArray FIMGZTexture::Get8BitPixels(bool alphatex) +TArray FIMGZTexture::GetPalettedPixels(int conversion) { FMemLump lump = Wads.ReadLump (SourceLump); const ImageHeader *imgz = (const ImageHeader *)lump.GetMem(); @@ -133,7 +133,7 @@ TArray FIMGZTexture::Get8BitPixels(bool alphatex) TArray Pixels(Width*Height, true); dest_p = Pixels.Data(); - const uint8_t *remap = ImageHelpers::GetRemap(alphatex, isalpha); + const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance, isalpha); // Convert the source image from row-major to column-major format and remap it if (!imgz->Compression) @@ -200,9 +200,9 @@ TArray FIMGZTexture::Get8BitPixels(bool alphatex) // //========================================================================== -int FIMGZTexture::CopyPixels(FBitmap *bmp) +int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion) { - if (!isalpha) return FImageSource::CopyPixels(bmp); + if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); else return CopyTranslatedPixels(bmp, translationtables[TRANSLATION_Standard][STD_Grayscale]->Palette); } diff --git a/src/textures/formats/jpegtexture.cpp b/src/textures/formats/jpegtexture.cpp index 06b093e95e..b41549c023 100644 --- a/src/textures/formats/jpegtexture.cpp +++ b/src/textures/formats/jpegtexture.cpp @@ -185,8 +185,8 @@ class FJPEGTexture : public FImageSource public: FJPEGTexture (int lumpnum, int width, int height); - int CopyPixels(FBitmap *bmp) override; - TArray Get8BitPixels(bool alphatex) override; + int CopyPixels(FBitmap *bmp, int conversion) override; + TArray GetPalettedPixels(int conversion) override; }; //========================================================================== @@ -260,7 +260,7 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height) // //========================================================================== -TArray FJPEGTexture::Get8BitPixels(bool doalpha) +TArray FJPEGTexture::GetPalettedPixels(int conversion) { auto lump = Wads.OpenLumpReader (SourceLump); JSAMPLE *buff = NULL; @@ -279,6 +279,7 @@ TArray FJPEGTexture::Get8BitPixels(bool doalpha) FLumpSourceMgr sourcemgr(&lump, &cinfo); try { + bool doalpha = conversion == luminance; jpeg_read_header(&cinfo, TRUE); if (!((cinfo.out_color_space == JCS_RGB && cinfo.num_components == 3) || (cinfo.out_color_space == JCS_CMYK && cinfo.num_components == 4) || @@ -381,7 +382,7 @@ TArray FJPEGTexture::Get8BitPixels(bool doalpha) // //=========================================================================== -int FJPEGTexture::CopyPixels(FBitmap *bmp) +int FJPEGTexture::CopyPixels(FBitmap *bmp, int conversion) { PalEntry pe[256]; diff --git a/src/textures/formats/patchtexture.cpp b/src/textures/formats/patchtexture.cpp index f988b9c021..ca6e54755d 100644 --- a/src/textures/formats/patchtexture.cpp +++ b/src/textures/formats/patchtexture.cpp @@ -62,11 +62,10 @@ class FPatchTexture : public FImageSource { bool badflag = false; bool isalpha = false; - bool bNoRemap0 = false; // Unfortunately this was done as a very bad hack in ZDoom and will need impovement public: FPatchTexture (int lumpnum, patch_t *header, bool isalphatex); - TArray Get8BitPixels(bool alphatex) override; - int CopyPixels(FBitmap *bmp) override; + TArray GetPalettedPixels(int conversion) override; + int CopyPixels(FBitmap *bmp, int conversion) override; void DetectBadPatches(); }; @@ -164,7 +163,7 @@ FPatchTexture::FPatchTexture (int lumpnum, patch_t * header, bool isalphatex) // //========================================================================== -TArray FPatchTexture::Get8BitPixels(bool alphatex) +TArray FPatchTexture::GetPalettedPixels(int conversion) { uint8_t *remap, remaptable[256]; int numspans; @@ -176,9 +175,9 @@ TArray FPatchTexture::Get8BitPixels(bool alphatex) maxcol = (const column_t *)((const uint8_t *)patch + Wads.LumpLength (SourceLump) - 3); - remap = ImageHelpers::GetRemap(alphatex, isalpha); + remap = ImageHelpers::GetRemap(conversion == luminance, isalpha); // Special case for skies - if (bNoRemap0 && remap == GPalette.Remap) + if (conversion == noremap0 && remap == GPalette.Remap) { memcpy(remaptable, GPalette.Remap, 256); remaptable[0] = 0; @@ -261,9 +260,9 @@ TArray FPatchTexture::Get8BitPixels(bool alphatex) // //========================================================================== -int FPatchTexture::CopyPixels(FBitmap *bmp) +int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion) { - if (!isalpha) return FImageSource::CopyPixels(bmp); + if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); else return CopyTranslatedPixels(bmp, translationtables[TRANSLATION_Standard][STD_Grayscale]->Palette); } diff --git a/src/textures/formats/pcxtexture.cpp b/src/textures/formats/pcxtexture.cpp index c755723e46..f2e9f828d2 100644 --- a/src/textures/formats/pcxtexture.cpp +++ b/src/textures/formats/pcxtexture.cpp @@ -85,7 +85,7 @@ class FPCXTexture : public FImageSource public: FPCXTexture (int lumpnum, PCXHeader &); - int CopyPixels(FBitmap *bmp) override; + int CopyPixels(FBitmap *bmp, int conversion) override; protected: void ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr); @@ -93,7 +93,7 @@ protected: void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr); void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes); - TArray Get8BitPixels(bool alphatex) override; + TArray GetPalettedPixels(int conversion) override; }; @@ -358,7 +358,7 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr // //========================================================================== -TArray FPCXTexture::Get8BitPixels(bool alphatex) +TArray FPCXTexture::GetPalettedPixels(int conversion) { uint8_t PaletteMap[256]; PCXHeader header; @@ -371,6 +371,7 @@ TArray FPCXTexture::Get8BitPixels(bool alphatex) bitcount = header.bitsPerPixel * header.numColorPlanes; TArray Pixels(Width*Height, true); + bool alphatex = conversion == luminance; if (bitcount < 24) { if (bitcount < 8) @@ -446,7 +447,7 @@ TArray FPCXTexture::Get8BitPixels(bool alphatex) // //=========================================================================== -int FPCXTexture::CopyPixels(FBitmap *bmp) +int FPCXTexture::CopyPixels(FBitmap *bmp, int conversion) { PalEntry pe[256]; PCXHeader header; diff --git a/src/textures/formats/pngtexture.cpp b/src/textures/formats/pngtexture.cpp index 91b70b7451..1990aa6cb8 100644 --- a/src/textures/formats/pngtexture.cpp +++ b/src/textures/formats/pngtexture.cpp @@ -54,9 +54,8 @@ public: FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace); ~FPNGTexture(); - int CopyPixels(FBitmap *bmp) override; - bool UseBasePalette() override; - TArray Get8BitPixels(bool alphatex) override; + int CopyPixels(FBitmap *bmp, int conversion) override; + TArray GetPalettedPixels(int conversion) override; protected: void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap); @@ -182,7 +181,7 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) return NULL; } - return new FPNGTexture (png->File, -1, filename, width, height, bitdepth, colortype, interlace); + return new FImageTexture(new FPNGTexture (png->File, -1, filename, width, height, bitdepth, colortype, interlace)); } //========================================================================== @@ -193,7 +192,7 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, uint8_t depth, uint8_t colortype, uint8_t interlace) -: FWorldTexture(NULL, lumpnum), SourceFile(filename), +: FImageSource(lumpnum), SourceFile(filename), BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false) { union @@ -205,7 +204,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename uint32_t len, id; int i; - UseType = ETextureType::MiscPatch; bMasked = false; Width = width; @@ -247,8 +245,8 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename Printf ("Y-Offset for PNG texture %s is bad: %d (0x%08x)\n", Wads.GetLumpFullName (lumpnum), ihoty, ihoty); ihoty = 0; } - _LeftOffset[1] = _LeftOffset[0] = ihotx; - _TopOffset[1] = _TopOffset[0] = ihoty; + LeftOffset = ihotx; + TopOffset = ihoty; } break; @@ -369,7 +367,7 @@ void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap) // //========================================================================== -TArray FPNGTexture::Get8BitPixels(bool alphatex) +TArray FPNGTexture::GetPalettedPixels(int conversion) { FileReader *lump; FileReader lfr; @@ -396,13 +394,14 @@ TArray FPNGTexture::Get8BitPixels(bool alphatex) lump->Read(&len, 4); lump->Read(&id, 4); + bool alphatex = conversion == luminance; if (ColorType == 0 || ColorType == 3) /* Grayscale and paletted */ { M_ReadIDAT (*lump, Pixels.Data(), Width, Height, Width, BitDepth, ColorType, Interlace, BigLong((unsigned int)len)); if (Width == Height) { - if (!alphatex) + if (conversion != luminance) { ImageHelpers::FlipSquareBlockRemap (Pixels.Data(), Width, PaletteMap); } @@ -420,7 +419,7 @@ TArray FPNGTexture::Get8BitPixels(bool alphatex) else { TArray newpix(Width*Height, true); - if (!alphatex) + if (conversion != luminance) { ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap); } @@ -513,7 +512,7 @@ TArray FPNGTexture::Get8BitPixels(bool alphatex) // //=========================================================================== -int FPNGTexture::CopyPixels(FBitmap *bmp) +int FPNGTexture::CopyPixels(FBitmap *bmp, int conversion) { // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? PalEntry pe[256]; @@ -631,17 +630,3 @@ int FPNGTexture::CopyPixels(FBitmap *bmp) delete[] Pixels; return transpal; } - - -//=========================================================================== -// -// This doesn't check if the palette is identical with the base palette -// I don't think it's worth the hassle because it's only of importance -// when compositing multipatch textures. -// -//=========================================================================== - -bool FPNGTexture::UseBasePalette() -{ - return false; -} diff --git a/src/textures/formats/rawpagetexture.cpp b/src/textures/formats/rawpagetexture.cpp index 9c38748e25..6fd805ff5a 100644 --- a/src/textures/formats/rawpagetexture.cpp +++ b/src/textures/formats/rawpagetexture.cpp @@ -54,8 +54,8 @@ class FRawPageTexture : public FImageSource int mPaletteLump = -1; public: FRawPageTexture (int lumpnum); - TArray Get8BitPixels(bool alphatex) override; - int CopyPixels(FBitmap *bmp) override; + TArray GetPalettedPixels(int conversion) override; + int CopyPixels(FBitmap *bmp, int conversion) override; }; //========================================================================== @@ -173,7 +173,7 @@ FRawPageTexture::FRawPageTexture (int lumpnum) // //========================================================================== -TArray FRawPageTexture::Get8BitPixels(bool alphatex) +TArray FRawPageTexture::GetPalettedPixels(int conversion) { FMemLump lump = Wads.ReadLump (SourceLump); const uint8_t *source = (const uint8_t *)lump.GetMem(); @@ -183,7 +183,7 @@ TArray FRawPageTexture::Get8BitPixels(bool alphatex) TArray Pixels(Width*Height, true); dest_p = Pixels.Data(); - const uint8_t *remap = ImageHelpers::GetRemap(alphatex); + const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance); // This does not handle the custom palette. // User maps are encouraged to use a real image format when replacing E2END and the original could never be used anywhere else. @@ -202,9 +202,9 @@ TArray FRawPageTexture::Get8BitPixels(bool alphatex) return Pixels; } -int FRawPageTexture::CopyPixels(FBitmap *bmp) +int FRawPageTexture::CopyPixels(FBitmap *bmp, int conversion) { - if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp); + if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp, conversion); else { FMemLump lump = Wads.ReadLump(SourceLump); diff --git a/src/textures/formats/shadertexture.cpp b/src/textures/formats/shadertexture.cpp index 6f34437989..0e79ad8c79 100644 --- a/src/textures/formats/shadertexture.cpp +++ b/src/textures/formats/shadertexture.cpp @@ -100,10 +100,10 @@ public: } } - TArray Get8BitPixels(bool alphatex) override + TArray GetPalettedPixels(int conversion) override { TArray Pix(512, true); - if (alphatex) + if (conversion == luminance) { memcpy(Pix.Data(), Pixels, 512); } @@ -120,7 +120,7 @@ public: return Pix; } - int CopyPixels(FBitmap *bmp) override + int CopyPixels(FBitmap *bmp, int conversion) override { bmp->CopyPixelData(0, 0, Pixels, Width, Height, Height, 1, 0, translationtables[TRANSLATION_Standard][8]->Palette); return 0; @@ -134,5 +134,6 @@ private: FTexture *CreateShaderTexture(bool vertical, bool reverse) { FStringf name("BarShader%c%c", vertical ? 'v' : 'h', reverse ? 'r' : 'f'); - auto tex = new FImageTexture(new FBarShader(vertical, reverse), name.GetChars()); + return new FImageTexture(new FBarShader(vertical, reverse), name.GetChars()); + } diff --git a/src/textures/formats/tgatexture.cpp b/src/textures/formats/tgatexture.cpp index 9725fe6d1f..9bc8500f8a 100644 --- a/src/textures/formats/tgatexture.cpp +++ b/src/textures/formats/tgatexture.cpp @@ -81,11 +81,11 @@ class FTGATexture : public FImageSource public: FTGATexture (int lumpnum, TGAHeader *); - int CopyPixels(FBitmap *bmp) override; + int CopyPixels(FBitmap *bmp, int conversion) override; protected: void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel); - TArray Get8BitPixels(bool alphatex) override; + TArray GetPalettedPixels(int conversion) override; }; //========================================================================== @@ -179,7 +179,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe // //========================================================================== -TArray FTGATexture::Get8BitPixels(bool alphatex) +TArray FTGATexture::GetPalettedPixels(int conversion) { uint8_t PaletteMap[256]; auto lump = Wads.OpenLumpReader (SourceLump); @@ -232,7 +232,7 @@ TArray FTGATexture::Get8BitPixels(bool alphatex) r=g=b=a=0; break; } - PaletteMap[i] = ImageHelpers::RGBToPalettePrecise(alphatex, r, g, b, a); + PaletteMap[i] = ImageHelpers::RGBToPalettePrecise(conversion == luminance, r, g, b, a); } } @@ -291,7 +291,7 @@ TArray FTGATexture::Get8BitPixels(bool alphatex) for(int x=0;x> 10) & 0x1f) * 8, ((v >> 5) & 0x1f) * 8, (v & 0x1f) * 8); + Pixels[x*Height + y] = ImageHelpers::RGBToPalette(conversion == luminance, ((v >> 10) & 0x1f) * 8, ((v >> 5) & 0x1f) * 8, (v & 0x1f) * 8); p+=step_x; } } @@ -303,7 +303,7 @@ TArray FTGATexture::Get8BitPixels(bool alphatex) uint8_t * p = ptr + y * Pitch; for(int x=0;x FTGATexture::Get8BitPixels(bool alphatex) uint8_t * p = ptr + y * Pitch; for(int x=0;x FTGATexture::Get8BitPixels(bool alphatex) uint8_t * p = ptr + y * Pitch; for(int x=0;x FTGATexture::Get8BitPixels(bool alphatex) case 3: // Grayscale { - auto remap = ImageHelpers::GetRemap(alphatex, true); + auto remap = ImageHelpers::GetRemap(conversion == luminance, true); switch (hdr.bpp) { case 8: @@ -388,7 +388,7 @@ TArray FTGATexture::Get8BitPixels(bool alphatex) // //=========================================================================== -int FTGATexture::CopyPixels(FBitmap *bmp) +int FTGATexture::CopyPixels(FBitmap *bmp, int conversion) { PalEntry pe[256]; auto lump = Wads.OpenLumpReader (SourceLump); diff --git a/src/textures/image.cpp b/src/textures/image.cpp index ac217d171d..20c457a966 100644 --- a/src/textures/image.cpp +++ b/src/textures/image.cpp @@ -45,7 +45,7 @@ // //=========================================================================== -TArray FImageSource::Get8BitPixels(bool alphatex) +TArray FImageSource::GetPalettedPixels(int conversion) { TArray Pixels(Width * Height, true); memset(Pixels.Data(), 0, Width * Height); @@ -65,11 +65,12 @@ TArray FImageSource::Get8BitPixels(bool alphatex) // //=========================================================================== -int FImageSource::CopyPixels(FBitmap *bmp) +int FImageSource::CopyPixels(FBitmap *bmp, int conversion) { + if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source. PalEntry *palette = screen->GetPalette(); for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values - auto ppix = Get8BitPixels(false); // should use composition cache + auto ppix = GetPalettedPixels(conversion); // should use composition cache bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, palette, nullptr); for(int i=1;i<256;i++) palette[i].a = 0; return 0; @@ -77,8 +78,7 @@ int FImageSource::CopyPixels(FBitmap *bmp) int FImageSource::CopyTranslatedPixels(FBitmap *bmp, PalEntry *remap) { - auto ppix = Get8BitPixels(false); // should use composition cache + auto ppix = GetPalettedPixels(false); // should use composition cache bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, remap, nullptr); return 0; } - diff --git a/src/textures/image.h b/src/textures/image.h index 7bcdb05102..88a04b0fb8 100644 --- a/src/textures/image.h +++ b/src/textures/image.h @@ -16,16 +16,14 @@ protected: int LeftOffset = 0, TopOffset = 0; // Offsets stored in the image. bool bUseGamePalette = false; // true if this is an image without its own color set. - // internal builder functions for true color textures. - public: bool bMasked = true; // Image (might) have holes (Assume true unless proven otherwise!) int8_t bTranslucent = -1; // Image has pixels with a non-0/1 value. (-1 means the user needs to do a real check) // Returns the whole texture, paletted and true color versions respectively. - virtual TArray Get8BitPixels(bool alphatex); - virtual int CopyPixels(FBitmap *bmp); + virtual TArray GetPalettedPixels(int conversion); // 'noremap0' will only be looked at by FPatchTexture and forwarded by FMultipatchTexture. + virtual int CopyPixels(FBitmap *bmp, int conversion); // This will always ignore 'luminance'. int CopyTranslatedPixels(FBitmap *bmp, PalEntry *remap); // Conversion option diff --git a/src/textures/imagetexture.cpp b/src/textures/imagetexture.cpp index 7cb45887e1..6a376551c5 100644 --- a/src/textures/imagetexture.cpp +++ b/src/textures/imagetexture.cpp @@ -49,7 +49,7 @@ //========================================================================== FImageTexture::FImageTexture(FImageSource *img, const char *name) -: FWorldTexture(name, img->LumpNum()) +: FTexture(name, img->LumpNum()) { mImage = img; Wads.GetLumpName (Name, img->LumpNum()); @@ -72,7 +72,7 @@ FImageTexture::FImageTexture(FImageSource *img, const char *name) int FImageTexture::CopyPixels(FBitmap *bmp) { - return mImage->CopyPixels(bmp); + return mImage->CopyPixels(bmp, bNoRemap0? FImageSource::noremap0 : FImageSource::normal); } //=========================================================================== @@ -83,7 +83,7 @@ int FImageTexture::CopyPixels(FBitmap *bmp) TArray FImageTexture::Get8BitPixels(bool alpha) { - return mImage->Get8BitPixels(alpha); + return mImage->GetPalettedPixels(alpha? alpha : bNoRemap0 ? FImageSource::noremap0 : FImageSource::normal); } //===========================================================================