- changed return value of CreatePalettedPixels.

The new struct will allpw return of static pixel data without reallocation and copying.
This commit is contained in:
Christoph Oelckers 2023-01-07 17:55:55 +01:00
parent 4e4642d0ed
commit 1a0aa95ff4
24 changed files with 103 additions and 84 deletions

View file

@ -109,7 +109,7 @@ class FHexFontChar : public FImageSource
public:
FHexFontChar(uint8_t *sourcedata, int swidth, int width, int height);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap* bmp, int conversion);
protected:
@ -144,10 +144,10 @@ FHexFontChar::FHexFontChar (uint8_t *sourcedata, int swidth, int width, int heig
//
//==========================================================================
TArray<uint8_t> FHexFontChar::CreatePalettedPixels(int)
PalettedPixels FHexFontChar::CreatePalettedPixels(int)
{
int destSize = Width * Height;
TArray<uint8_t> Pixels(destSize, true);
PalettedPixels Pixels(destSize);
uint8_t *dest_p = Pixels.Data();
const uint8_t *src_p = SourceData;
@ -190,7 +190,7 @@ class FHexFontChar2 : public FHexFontChar
public:
FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int height);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap* bmp, int conversion);
};
@ -216,10 +216,10 @@ FHexFontChar2::FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int hei
//
//==========================================================================
TArray<uint8_t> FHexFontChar2::CreatePalettedPixels(int)
PalettedPixels FHexFontChar2::CreatePalettedPixels(int)
{
int destSize = Width * Height;
TArray<uint8_t> Pixels(destSize, true);
PalettedPixels Pixels(destSize);
uint8_t *dest_p = Pixels.Data();
assert(SourceData);

View file

@ -58,7 +58,7 @@ public:
FVoxelTexture(FVoxel *voxel);
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
protected:
FVoxel *SourceVox;
@ -84,10 +84,10 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox)
//
//===========================================================================
TArray<uint8_t> FVoxelTexture::CreatePalettedPixels(int conversion)
PalettedPixels FVoxelTexture::CreatePalettedPixels(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);
PalettedPixels Pixels(256);
uint8_t *pp = SourceVox->Palette.Data();
if(pp != NULL)

View file

@ -51,7 +51,7 @@ class FAnmTexture : public FImageSource
public:
FAnmTexture (int lumpnum, int w, int h);
void ReadFrame(uint8_t *buffer, uint8_t *palette);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -127,9 +127,9 @@ void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
//
//==========================================================================
TArray<uint8_t> FAnmTexture::CreatePalettedPixels(int conversion)
PalettedPixels FAnmTexture::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> pixels(Width*Height, true);
PalettedPixels pixels(Width*Height);
uint8_t buffer[64000];
uint8_t palette[768];
uint8_t remap[256];

View file

@ -50,7 +50,7 @@ class FAutomapTexture : public FImageSource
{
public:
FAutomapTexture(int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
@ -89,13 +89,13 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FAutomapTexture::CreatePalettedPixels(int conversion)
PalettedPixels FAutomapTexture::CreatePalettedPixels(int conversion)
{
int x, y;
FileData data = fileSystem.ReadFile (SourceLump);
const uint8_t *indata = (const uint8_t *)data.GetMem();
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
for (x = 0; x < Width; ++x)

View file

@ -55,9 +55,9 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8
TopOffset = top;
}
TArray<uint8_t> FBuildTexture::CreatePalettedPixels(int conversion)
PalettedPixels FBuildTexture::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
FRemapTable *Remap = Translation;
for (int i = 0; i < Width*Height; i++)
{

View file

@ -163,7 +163,7 @@ class FDDSTexture : public FImageSource
public:
FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
protected:
uint32_t Format;
@ -371,11 +371,11 @@ void FDDSTexture::CalcBitShift (uint32_t mask, uint8_t *lshiftp, uint8_t *rshift
//
//==========================================================================
TArray<uint8_t> FDDSTexture::CreatePalettedPixels(int conversion)
PalettedPixels FDDSTexture::CreatePalettedPixels(int conversion)
{
auto lump = fileSystem.OpenFileReader (SourceLump);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet);

View file

@ -49,7 +49,7 @@ class FEmptyTexture : public FImageSource
{
public:
FEmptyTexture (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
//==========================================================================
@ -94,10 +94,10 @@ FEmptyTexture::FEmptyTexture (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FEmptyTexture::CreatePalettedPixels(int conversion)
PalettedPixels FEmptyTexture::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> Pixel(1, true);
Pixel[0] = 0;
static uint8_t p;
PalettedPixels Pixel(&p, 1);
return Pixel;
}

View file

@ -48,7 +48,7 @@ class FFlatTexture : public FImageSource
{
public:
FFlatTexture (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
@ -102,10 +102,10 @@ FFlatTexture::FFlatTexture (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FFlatTexture::CreatePalettedPixels(int conversion)
PalettedPixels FFlatTexture::CreatePalettedPixels(int conversion)
{
auto lump = fileSystem.OpenFileReader (SourceLump);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
auto numread = lump.Read (Pixels.Data(), Width*Height);
if (numread < Width*Height)
{

View file

@ -66,7 +66,7 @@ FFontChar2::FFontChar2(int sourcelump, int sourcepos, int width, int height, int
//
//==========================================================================
TArray<uint8_t> FFontChar2::CreatePalettedPixels(int)
PalettedPixels FFontChar2::CreatePalettedPixels(int)
{
auto lump = fileSystem.OpenFileReader(SourceLump);
int destSize = Width * Height;
@ -96,7 +96,7 @@ TArray<uint8_t> FFontChar2::CreatePalettedPixels(int)
}
}
TArray<uint8_t> Pixels(destSize, true);
PalettedPixels Pixels(destSize);
int runlen = 0, setlen = 0;
uint8_t setval = 0; // Shut up, GCC!

View file

@ -6,7 +6,7 @@ class FFontChar2 : public FImageSource
public:
FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap* bmp, int conversion);
void SetSourceRemap(const PalEntry* sourceremap)

View file

@ -66,7 +66,7 @@ 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> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -118,7 +118,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
//
//==========================================================================
TArray<uint8_t> FIMGZTexture::CreatePalettedPixels(int conversion)
PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const ImageHeader *imgz = (const ImageHeader *)lump.GetMem();
@ -128,7 +128,7 @@ TArray<uint8_t> FIMGZTexture::CreatePalettedPixels(int conversion)
int dest_adv = Height;
int dest_rew = Width * Height - 1;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
dest_p = Pixels.Data();
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance, isalpha);

View file

@ -185,7 +185,7 @@ public:
FJPEGTexture (int lumpnum, int width, int height);
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
//==========================================================================
@ -259,7 +259,7 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height)
//
//==========================================================================
TArray<uint8_t> FJPEGTexture::CreatePalettedPixels(int conversion)
PalettedPixels FJPEGTexture::CreatePalettedPixels(int conversion)
{
auto lump = fileSystem.OpenFileReader (SourceLump);
JSAMPLE *buff = NULL;
@ -267,7 +267,7 @@ TArray<uint8_t> FJPEGTexture::CreatePalettedPixels(int conversion)
jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr;
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
memset (Pixels.Data(), 0xBA, Width * Height);
cinfo.err = jpeg_std_error(&jerr);

View file

@ -201,13 +201,13 @@ void FMultiPatchTexture::CopyToBlock(uint8_t *dest, int dwidth, int dheight, FIm
//
//==========================================================================
TArray<uint8_t> FMultiPatchTexture::CreatePalettedPixels(int conversion)
PalettedPixels FMultiPatchTexture::CreatePalettedPixels(int conversion)
{
int numpix = Width * Height;
uint8_t blendwork[256];
bool buildrgb = bComplex;
TArray<uint8_t> Pixels(numpix, true);
PalettedPixels Pixels(numpix);
memset (Pixels.Data(), 0, numpix);
if (conversion == luminance)

View file

@ -75,7 +75,7 @@ protected:
// The getters must optionally redirect if it's a simple one-patch texture.
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
void CopyToBlock(uint8_t *dest, int dwidth, int dheight, FImageSource *source, int xpos, int ypos, int rotate, const uint8_t *translation, int style);
void CollectForPrecache(PrecacheInfo &info, bool requiretruecolor) override;

View file

@ -61,7 +61,7 @@ class FPatchTexture : public FImageSource
bool isalpha = false;
public:
FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
bool SupportRemap0() override { return !badflag; }
void DetectBadPatches();
@ -166,7 +166,7 @@ FPatchTexture::FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool is
//
//==========================================================================
TArray<uint8_t> FPatchTexture::CreatePalettedPixels(int conversion)
PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion)
{
uint8_t *remap, remaptable[256];
int numspans;
@ -189,7 +189,7 @@ TArray<uint8_t> FPatchTexture::CreatePalettedPixels(int conversion)
if (badflag)
{
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
uint8_t *out;
// Draw the image to the buffer
@ -210,7 +210,7 @@ TArray<uint8_t> FPatchTexture::CreatePalettedPixels(int conversion)
numspans = Width;
TArray<uint8_t> Pixels(numpix, true);
PalettedPixels Pixels(numpix);
memset (Pixels.Data(), 0, numpix);
// Draw the image to the buffer

View file

@ -91,7 +91,7 @@ protected:
void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
@ -344,7 +344,7 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr
//
//==========================================================================
TArray<uint8_t> FPCXTexture::CreatePalettedPixels(int conversion)
PalettedPixels FPCXTexture::CreatePalettedPixels(int conversion)
{
uint8_t PaletteMap[256];
PCXHeader header;
@ -355,7 +355,7 @@ TArray<uint8_t> FPCXTexture::CreatePalettedPixels(int conversion)
lump.Read(&header, sizeof(header));
bitcount = header.bitsPerPixel * header.numColorPlanes;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
bool alphatex = conversion == luminance;
if (bitcount < 24)
@ -402,7 +402,7 @@ TArray<uint8_t> FPCXTexture::CreatePalettedPixels(int conversion)
}
else
{
TArray<uint8_t> newpix(Width*Height, true);
PalettedPixels newpix(Width*Height);
ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
return newpix;
}

View file

@ -56,7 +56,7 @@ public:
FPNGTexture (FileReader &lump, int lumpnum, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace);
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
protected:
void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap);
@ -411,7 +411,7 @@ void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap)
//
//==========================================================================
TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
PalettedPixels FPNGTexture::CreatePalettedPixels(int conversion)
{
FileReader *lump;
FileReader lfr;
@ -419,7 +419,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
lfr = fileSystem.OpenFileReader(SourceLump);
lump = &lfr;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
if (StartOfIDAT == 0)
{
memset (Pixels.Data(), 0x99, Width*Height);
@ -456,7 +456,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
}
else
{
TArray<uint8_t> newpix(Width*Height, true);
PalettedPixels newpix(Width*Height);
if (conversion != luminance)
{
if (!PaletteMap) SetupPalette(lfr);

View file

@ -51,7 +51,7 @@ class FRawPageTexture : public FImageSource
int mPaletteLump = -1;
public:
FRawPageTexture (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -170,14 +170,14 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FRawPageTexture::CreatePalettedPixels(int conversion)
PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem();
const uint8_t *source_p = source;
uint8_t *dest_p;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
dest_p = Pixels.Data();
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);

View file

@ -98,9 +98,9 @@ public:
}
}
TArray<uint8_t> CreatePalettedPixels(int conversion) override
PalettedPixels CreatePalettedPixels(int conversion) override
{
TArray<uint8_t> Pix(512, true);
PalettedPixels Pix(512);
if (conversion == luminance)
{
memcpy(Pix.Data(), Pixels, 512);

View file

@ -77,7 +77,7 @@ class FStartupTexture : public FImageSource
{
public:
FStartupTexture (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -85,7 +85,7 @@ class FNotchTexture : public FImageSource
{
public:
FNotchTexture (int lumpnum, int width, int height);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -93,14 +93,14 @@ class FStrifeStartupTexture : public FImageSource
{
public:
FStrifeStartupTexture (int lumpnum, int w, int h);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
class FStrifeStartupBackground : public FImageSource
{
public:
FStrifeStartupBackground (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
//==========================================================================
@ -231,7 +231,7 @@ void PlanarToChunky(T* dest, const uint8_t* src, const T* remap, int width, int
//
//==========================================================================
TArray<uint8_t> FStartupTexture::CreatePalettedPixels(int conversion)
PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem();
@ -239,7 +239,7 @@ TArray<uint8_t> FStartupTexture::CreatePalettedPixels(int conversion)
TArray<uint8_t> Work(Width*Height, true);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
PlanarToChunky(Work.Data(), source + 48, startuppalette8, Width, Height);
ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), Work.Data(), Width, Height, Width, remap);
return Pixels;
@ -279,14 +279,14 @@ FNotchTexture::FNotchTexture (int lumpnum, int width, int height)
//
//==========================================================================
TArray<uint8_t> FNotchTexture::CreatePalettedPixels(int conversion)
PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem();
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
TArray<uint8_t> Work(Width*Height, true);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
for(int i=0; i * Width * Height / 2; i++)
{
Work[i * 2] = startuppalette8[source[i] >> 4];
@ -336,11 +336,11 @@ FStrifeStartupTexture::FStrifeStartupTexture (int lumpnum, int w, int h)
//
//==========================================================================
TArray<uint8_t> FStrifeStartupTexture::CreatePalettedPixels(int conversion)
PalettedPixels FStrifeStartupTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem();
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), source, Width, Height, Width, remap);
return Pixels;
@ -366,7 +366,7 @@ FStrifeStartupBackground::FStrifeStartupBackground (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FStrifeStartupBackground::CreatePalettedPixels(int conversion)
PalettedPixels FStrifeStartupBackground::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> source(64000, true);
memset(source.Data(), 0xF0, 64000);
@ -374,7 +374,7 @@ TArray<uint8_t> FStrifeStartupBackground::CreatePalettedPixels(int conversion)
lumpr.Seek(57 * 320, FileReader::SeekSet);
lumpr.Read(source.Data() + 41 * 320, 95 * 320);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), source.Data(), Width, Height, Width, remap);
return Pixels;

View file

@ -67,7 +67,7 @@ class FStbTexture : public FImageSource
public:
FStbTexture (int lumpnum, int w, int h);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -117,7 +117,7 @@ FStbTexture::FStbTexture (int lumpnum, int w, int h)
//
//==========================================================================
TArray<uint8_t> FStbTexture::CreatePalettedPixels(int conversion)
PalettedPixels FStbTexture::CreatePalettedPixels(int conversion)
{
FBitmap bitmap;
bitmap.Create(Width, Height);
@ -128,7 +128,7 @@ TArray<uint8_t> FStbTexture::CreatePalettedPixels(int conversion)
int dest_adv = Height;
int dest_rew = Width * Height - 1;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
dest_p = Pixels.Data();
bool doalpha = conversion == luminance;

View file

@ -83,7 +83,7 @@ public:
protected:
void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
//==========================================================================
@ -177,7 +177,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe
//
//==========================================================================
TArray<uint8_t> FTGATexture::CreatePalettedPixels(int conversion)
PalettedPixels FTGATexture::CreatePalettedPixels(int conversion)
{
uint8_t PaletteMap[256];
auto lump = fileSystem.OpenFileReader (SourceLump);
@ -185,7 +185,7 @@ TArray<uint8_t> FTGATexture::CreatePalettedPixels(int conversion)
uint16_t w;
uint8_t r,g,b,a;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
lump.Read(&hdr, sizeof(hdr));
lump.Seek(hdr.id_len, FileReader::SeekCur);

View file

@ -48,7 +48,7 @@ static PrecacheInfo precacheInfo;
struct PrecacheDataPaletted
{
TArray<uint8_t> Pixels;
PalettedPixels Pixels;
int RefCount;
int ImageID;
};
@ -71,9 +71,9 @@ TArray<PrecacheDataRgba> precacheDataRgba;
//
//===========================================================================
TArray<uint8_t> FImageSource::CreatePalettedPixels(int conversion)
PalettedPixels FImageSource::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
memset(Pixels.Data(), 0, Width * Height);
return Pixels;
}
@ -99,8 +99,7 @@ PalettedPixels FImageSource::GetCachedPalettedPixels(int conversion)
else if (cache->Pixels.Size() > 0)
{
//Printf("returning contents of %s, refcount = %d\n", name.GetChars(), cache->RefCount);
ret.PixelStore = std::move(cache->Pixels);
ret.Pixels.Set(ret.PixelStore.Data(), ret.PixelStore.Size());
ret = std::move(cache->Pixels);
precacheDataPaletted.Delete(index);
}
else
@ -116,8 +115,7 @@ PalettedPixels FImageSource::GetCachedPalettedPixels(int conversion)
{
// This is either the only copy needed or some access outside the caching block. In these cases create a new one and directly return it.
//Printf("returning fresh copy of %s\n", name.GetChars());
ret.PixelStore = CreatePalettedPixels(conversion);
ret.Pixels.Set(ret.PixelStore.Data(), ret.PixelStore.Size());
return CreatePalettedPixels(conversion);
}
else
{
@ -171,6 +169,7 @@ int FImageSource::CopyPixels(FBitmap *bmp, int conversion)
{
if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source.
PalEntry *palette = GPalette.BaseColors;
auto ppix = CreatePalettedPixels(conversion);
bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, palette, nullptr);
return 0;
@ -178,7 +177,7 @@ int FImageSource::CopyPixels(FBitmap *bmp, int conversion)
int FImageSource::CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap)
{
auto ppix = CreatePalettedPixels(false);
auto ppix = CreatePalettedPixels(normal);
bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, remap, nullptr);
return 0;
}

View file

@ -26,10 +26,30 @@ struct PalettedPixels
private:
TArray<uint8_t> PixelStore;
public:
PalettedPixels() = default;
PalettedPixels(unsigned size)
{
PixelStore.Resize(size);
Pixels.Set(PixelStore.Data(), PixelStore.Size());
}
PalettedPixels(uint8_t* data, unsigned size)
{
Pixels.Set(data, size);
}
bool ownsPixels() const
{
return Pixels.Data() == PixelStore.Data();
}
uint8_t* Data() const { return Pixels.Data(); }
unsigned Size() const { return Pixels.Size(); }
uint8_t& operator[] (size_t index) const
{
assert(index < Size());
return Pixels[index];
}
};
// This represents a naked image. It has no high level logic attached to it.
@ -51,7 +71,7 @@ protected:
// Internal image creation functions. All external access should go through the cache interface,
// so that all code can benefit from future improvements to that.
virtual TArray<uint8_t> CreatePalettedPixels(int conversion);
virtual PalettedPixels CreatePalettedPixels(int conversion);
virtual int CopyPixels(FBitmap *bmp, int conversion); // This will always ignore 'luminance'.
int CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap);
@ -160,7 +180,7 @@ class FBuildTexture : public FImageSource
{
public:
FBuildTexture(const FString& pathprefix, int tilenum, const uint8_t* pixels, FRemapTable* translation, int width, int height, int left, int top);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap* bmp, int conversion) override;
protected: