Skip to content

Commit

Permalink
- made some changes to the FImageSource interface that allows forward…
Browse files Browse the repository at this point in the history
…ing the bRemap0 flag, but do it so that it doesn't permanently alter how the image looks.

In ZDoom this would affect everything using a patch that got used in a front sky layer, even if the texture was totally unrelated. It is only owed to the low usability of such patches for other purposes that this hasn't caused problems.
  • Loading branch information
coelckers committed Dec 9, 2018
1 parent 583a740 commit 91f7121
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 105 deletions.
10 changes: 5 additions & 5 deletions src/r_data/models/models_voxel.cpp
Expand Up @@ -52,8 +52,8 @@ class FVoxelTexture : public FImageSource
public:
FVoxelTexture(FVoxel *voxel);

int CopyPixels(FBitmap *bmp) override;
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;

protected:
FVoxel *SourceVox;
Expand All @@ -79,7 +79,7 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox)
//
//===========================================================================

TArray<uint8_t> FVoxelTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FVoxelTexture::GetPalettedPixels(int conversion)
{
// GetPixels gets called when a translated palette is used so we still need to implement it here.
TArray<uint8_t> Pixels(256, true);
Expand All @@ -94,7 +94,7 @@ TArray<uint8_t> 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
Expand All @@ -116,7 +116,7 @@ TArray<uint8_t> FVoxelTexture::Get8BitPixels(bool alphatex)
//
//===========================================================================

int FVoxelTexture::CopyPixels(FBitmap *bmp)
int FVoxelTexture::CopyPixels(FBitmap *bmp, int conversion)
{
PalEntry pe[256];
uint8_t bitmap[256];
Expand Down
6 changes: 3 additions & 3 deletions src/textures/formats/automaptexture.cpp
Expand Up @@ -52,7 +52,7 @@ class FAutomapTexture : public FImageSource
{
public:
FAutomapTexture(int lumpnum);
TArray<uint8_t> Get8BitPixels(bool alphatex);
TArray<uint8_t> GetPalettedPixels(int conversion) override;
};


Expand Down Expand Up @@ -91,15 +91,15 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
//
//==========================================================================

TArray<uint8_t> FAutomapTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FAutomapTexture::GetPalettedPixels(int conversion)
{
int x, y;
FMemLump data = Wads.ReadLump (SourceLump);
const uint8_t *indata = (const uint8_t *)data.GetMem();

TArray<uint8_t> 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)
Expand Down
4 changes: 2 additions & 2 deletions src/textures/formats/brightmaptexture.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/textures/formats/buildtexture.cpp
Expand Up @@ -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<uint8_t> Get8BitPixels(bool alphatex) override;
int CopyPixels(FBitmap *bmp) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;

protected:
const uint8_t *RawPixels;
Expand All @@ -81,19 +81,19 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8
TopOffset = top;
}

TArray<uint8_t> FBuildTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FBuildTexture::GetPalettedPixels(int conversion)
{
TArray<uint8_t> 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);
Expand Down
10 changes: 5 additions & 5 deletions src/textures/formats/ddstexture.cpp
Expand Up @@ -164,7 +164,7 @@ class FDDSTexture : public FImageSource
public:
FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc);

TArray<uint8_t> Get8BitPixels(bool alphatex) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;

protected:
uint32_t Format;
Expand All @@ -183,7 +183,7 @@ class FDDSTexture : public FImageSource
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;
Expand Down Expand Up @@ -373,15 +373,15 @@ void FDDSTexture::CalcBitShift (uint32_t mask, uint8_t *lshiftp, uint8_t *rshift
//
//==========================================================================

TArray<uint8_t> FDDSTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FDDSTexture::GetPalettedPixels(int conversion)
{
auto lump = Wads.OpenLumpReader (SourceLump);

TArray<uint8_t> Pixels(Width*Height, true);

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);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/textures/formats/emptytexture.cpp
Expand Up @@ -51,7 +51,7 @@ class FEmptyTexture : public FImageSource
{
public:
FEmptyTexture (int lumpnum);
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;
};

//==========================================================================
Expand Down Expand Up @@ -91,7 +91,7 @@ FEmptyTexture::FEmptyTexture (int lumpnum)
//
//==========================================================================

TArray<uint8_t> FEmptyTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FEmptyTexture::GetPalettedPixels(int conversion)
{
TArray<uint8_t> Pixel(1, true);
Pixel[0] = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/textures/formats/flattexture.cpp
Expand Up @@ -50,7 +50,7 @@ class FFlatTexture : public FImageSource
{
public:
FFlatTexture (int lumpnum);
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;
};


Expand Down Expand Up @@ -104,7 +104,7 @@ FFlatTexture::FFlatTexture (int lumpnum)
//
//==========================================================================

TArray<uint8_t> FFlatTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FFlatTexture::GetPalettedPixels(int conversion)
{
auto lump = Wads.OpenLumpReader (SourceLump);
TArray<uint8_t> Pixels(Width*Height, true);
Expand All @@ -113,7 +113,7 @@ TArray<uint8_t> 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;
}

12 changes: 6 additions & 6 deletions src/textures/formats/imgztexture.cpp
Expand Up @@ -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<uint8_t> Get8BitPixels(bool alphatex) override;
int CopyPixels(FBitmap *bmp) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};


Expand Down Expand Up @@ -120,7 +120,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
//
//==========================================================================

TArray<uint8_t> FIMGZTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FIMGZTexture::GetPalettedPixels(int conversion)
{
FMemLump lump = Wads.ReadLump (SourceLump);
const ImageHeader *imgz = (const ImageHeader *)lump.GetMem();
Expand All @@ -133,7 +133,7 @@ TArray<uint8_t> FIMGZTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> 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)
Expand Down Expand Up @@ -200,9 +200,9 @@ TArray<uint8_t> 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);
}

9 changes: 5 additions & 4 deletions src/textures/formats/jpegtexture.cpp
Expand Up @@ -185,8 +185,8 @@ class FJPEGTexture : public FImageSource
public:
FJPEGTexture (int lumpnum, int width, int height);

int CopyPixels(FBitmap *bmp) override;
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;
};

//==========================================================================
Expand Down Expand Up @@ -260,7 +260,7 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height)
//
//==========================================================================

TArray<uint8_t> FJPEGTexture::Get8BitPixels(bool doalpha)
TArray<uint8_t> FJPEGTexture::GetPalettedPixels(int conversion)
{
auto lump = Wads.OpenLumpReader (SourceLump);
JSAMPLE *buff = NULL;
Expand All @@ -279,6 +279,7 @@ TArray<uint8_t> 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) ||
Expand Down Expand Up @@ -381,7 +382,7 @@ TArray<uint8_t> FJPEGTexture::Get8BitPixels(bool doalpha)
//
//===========================================================================

int FJPEGTexture::CopyPixels(FBitmap *bmp)
int FJPEGTexture::CopyPixels(FBitmap *bmp, int conversion)
{
PalEntry pe[256];

Expand Down
15 changes: 7 additions & 8 deletions src/textures/formats/patchtexture.cpp
Expand Up @@ -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<uint8_t> Get8BitPixels(bool alphatex) override;
int CopyPixels(FBitmap *bmp) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
void DetectBadPatches();
};

Expand Down Expand Up @@ -164,7 +163,7 @@ FPatchTexture::FPatchTexture (int lumpnum, patch_t * header, bool isalphatex)
//
//==========================================================================

TArray<uint8_t> FPatchTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FPatchTexture::GetPalettedPixels(int conversion)
{
uint8_t *remap, remaptable[256];
int numspans;
Expand All @@ -176,9 +175,9 @@ TArray<uint8_t> 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;
Expand Down Expand Up @@ -261,9 +260,9 @@ TArray<uint8_t> 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);
}

Expand Down
9 changes: 5 additions & 4 deletions src/textures/formats/pcxtexture.cpp
Expand Up @@ -85,15 +85,15 @@ 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);
void ReadPCX4bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes);

TArray<uint8_t> Get8BitPixels(bool alphatex) override;
TArray<uint8_t> GetPalettedPixels(int conversion) override;
};


Expand Down Expand Up @@ -358,7 +358,7 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr
//
//==========================================================================

TArray<uint8_t> FPCXTexture::Get8BitPixels(bool alphatex)
TArray<uint8_t> FPCXTexture::GetPalettedPixels(int conversion)
{
uint8_t PaletteMap[256];
PCXHeader header;
Expand All @@ -371,6 +371,7 @@ TArray<uint8_t> FPCXTexture::Get8BitPixels(bool alphatex)
bitcount = header.bitsPerPixel * header.numColorPlanes;
TArray<uint8_t> Pixels(Width*Height, true);

bool alphatex = conversion == luminance;
if (bitcount < 24)
{
if (bitcount < 8)
Expand Down Expand Up @@ -446,7 +447,7 @@ TArray<uint8_t> FPCXTexture::Get8BitPixels(bool alphatex)
//
//===========================================================================

int FPCXTexture::CopyPixels(FBitmap *bmp)
int FPCXTexture::CopyPixels(FBitmap *bmp, int conversion)
{
PalEntry pe[256];
PCXHeader header;
Expand Down

0 comments on commit 91f7121

Please sign in to comment.