- Convert the entire image backend infrastructure to be animation-friendly

This commit is contained in:
Cacodemon345 2023-08-22 11:33:06 +02:00 committed by Christoph Oelckers
parent 53d8a5bb2c
commit 7c90ea6b84
31 changed files with 145 additions and 128 deletions

View file

@ -109,8 +109,8 @@ class FHexFontChar : public FImageSource
public: public:
FHexFontChar(uint8_t *sourcedata, int swidth, int width, int height); FHexFontChar(uint8_t *sourcedata, int swidth, int width, int height);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap* bmp, int conversion); int CopyPixels(FBitmap* bmp, int conversion, int frame = 0);
protected: protected:
int SourceWidth; int SourceWidth;
@ -144,7 +144,7 @@ FHexFontChar::FHexFontChar (uint8_t *sourcedata, int swidth, int width, int heig
// //
//========================================================================== //==========================================================================
PalettedPixels FHexFontChar::CreatePalettedPixels(int) PalettedPixels FHexFontChar::CreatePalettedPixels(int, int)
{ {
int destSize = Width * Height; int destSize = Width * Height;
PalettedPixels Pixels(destSize); PalettedPixels Pixels(destSize);
@ -175,7 +175,7 @@ PalettedPixels FHexFontChar::CreatePalettedPixels(int)
return Pixels; return Pixels;
} }
int FHexFontChar::CopyPixels(FBitmap* bmp, int conversion) int FHexFontChar::CopyPixels(FBitmap* bmp, int conversion, int frame)
{ {
if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source. if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source.
PalEntry* palette = hexdata.ConsolePal; PalEntry* palette = hexdata.ConsolePal;
@ -190,8 +190,8 @@ class FHexFontChar2 : public FHexFontChar
public: public:
FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int height); FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int height);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap* bmp, int conversion); int CopyPixels(FBitmap* bmp, int conversion, int frame = 0);
}; };
@ -216,7 +216,7 @@ FHexFontChar2::FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int hei
// //
//========================================================================== //==========================================================================
PalettedPixels FHexFontChar2::CreatePalettedPixels(int) PalettedPixels FHexFontChar2::CreatePalettedPixels(int, int)
{ {
int destSize = Width * Height; int destSize = Width * Height;
PalettedPixels Pixels(destSize); PalettedPixels Pixels(destSize);
@ -255,7 +255,7 @@ PalettedPixels FHexFontChar2::CreatePalettedPixels(int)
return Pixels; return Pixels;
} }
int FHexFontChar2::CopyPixels(FBitmap* bmp, int conversion) int FHexFontChar2::CopyPixels(FBitmap* bmp, int conversion, int frame)
{ {
if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source. if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source.
PalEntry* palette = hexdata.SmallPal; PalEntry* palette = hexdata.SmallPal;

View file

@ -57,8 +57,8 @@ class FVoxelTexture : public FImageSource
public: public:
FVoxelTexture(FVoxel *voxel); FVoxelTexture(FVoxel *voxel);
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
protected: protected:
FVoxel *SourceVox; FVoxel *SourceVox;
@ -84,7 +84,7 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox)
// //
//=========================================================================== //===========================================================================
PalettedPixels FVoxelTexture::CreatePalettedPixels(int conversion) PalettedPixels FVoxelTexture::CreatePalettedPixels(int conversion, int frame)
{ {
// GetPixels gets called when a translated palette is used so we still need to implement it here. // GetPixels gets called when a translated palette is used so we still need to implement it here.
PalettedPixels Pixels(256); PalettedPixels Pixels(256);
@ -123,7 +123,7 @@ PalettedPixels FVoxelTexture::CreatePalettedPixels(int conversion)
// //
//=========================================================================== //===========================================================================
int FVoxelTexture::CopyPixels(FBitmap *bmp, int conversion) int FVoxelTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
PalEntry pe[256]; PalEntry pe[256];
uint8_t bitmap[256]; uint8_t bitmap[256];

View file

@ -51,8 +51,8 @@ class FAnmTexture : public FImageSource
public: public:
FAnmTexture (int lumpnum, int w, int h); FAnmTexture (int lumpnum, int w, int h);
void ReadFrame(uint8_t *buffer, uint8_t *palette); void ReadFrame(uint8_t *buffer, uint8_t *palette);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
}; };
@ -103,7 +103,7 @@ FAnmTexture::FAnmTexture (int lumpnum, int w, int h)
void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette) void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
{ {
auto lump = fileSystem.ReadFile (SourceLump); auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes(); auto source = lump.GetBytes();
anim_t anim; anim_t anim;
@ -127,7 +127,7 @@ void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
// //
//========================================================================== //==========================================================================
PalettedPixels FAnmTexture::CreatePalettedPixels(int conversion) PalettedPixels FAnmTexture::CreatePalettedPixels(int conversion, int frame)
{ {
PalettedPixels pixels(Width*Height); PalettedPixels pixels(Width*Height);
uint8_t buffer[64000]; uint8_t buffer[64000];
@ -149,7 +149,7 @@ PalettedPixels FAnmTexture::CreatePalettedPixels(int conversion)
// //
//========================================================================== //==========================================================================
int FAnmTexture::CopyPixels(FBitmap *bmp, int conversion) int FAnmTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
uint8_t buffer[64000]; uint8_t buffer[64000];
uint8_t palette[768]; uint8_t palette[768];

View file

@ -50,7 +50,7 @@ class FAutomapTexture : public FImageSource
{ {
public: public:
FAutomapTexture(int lumpnum); FAutomapTexture(int lumpnum);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
}; };
@ -89,7 +89,7 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
// //
//========================================================================== //==========================================================================
PalettedPixels FAutomapTexture::CreatePalettedPixels(int conversion) PalettedPixels FAutomapTexture::CreatePalettedPixels(int conversion, int frame)
{ {
int x, y; int x, y;
auto data = fileSystem.ReadFile (SourceLump); auto data = fileSystem.ReadFile (SourceLump);

View file

@ -43,7 +43,7 @@ class FBrightmapTexture : public FImageSource
public: public:
FBrightmapTexture (FImageSource *source); FBrightmapTexture (FImageSource *source);
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
protected: protected:
FImageSource *SourcePic; FImageSource *SourcePic;
@ -65,7 +65,7 @@ FBrightmapTexture::FBrightmapTexture (FImageSource *source)
bMasked = false; bMasked = false;
} }
int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion) int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette); SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette);
return 0; return 0;

View file

@ -55,7 +55,7 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8
TopOffset = top; TopOffset = top;
} }
PalettedPixels FBuildTexture::CreatePalettedPixels(int conversion) PalettedPixels FBuildTexture::CreatePalettedPixels(int conversion, int frame)
{ {
PalettedPixels Pixels(Width * Height); PalettedPixels Pixels(Width * Height);
FRemapTable *Remap = Translation; FRemapTable *Remap = Translation;
@ -67,7 +67,7 @@ PalettedPixels FBuildTexture::CreatePalettedPixels(int conversion)
return Pixels; return Pixels;
} }
int FBuildTexture::CopyPixels(FBitmap *bmp, int conversion) int FBuildTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
PalEntry *Remap = Translation->Palette; PalEntry *Remap = Translation->Palette;
bmp->CopyPixelData(0, 0, RawPixels, Width, Height, Height, 1, 0, Remap); bmp->CopyPixelData(0, 0, RawPixels, Width, Height, Height, 1, 0, Remap);

View file

@ -164,7 +164,7 @@ class FDDSTexture : public FImageSource
public: public:
FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc); FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
protected: protected:
uint32_t Format; uint32_t Format;
@ -183,7 +183,7 @@ protected:
void DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode); void DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode);
void DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode); void DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode);
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
friend class FTexture; friend class FTexture;
}; };
@ -372,7 +372,7 @@ void FDDSTexture::CalcBitShift (uint32_t mask, uint8_t *lshiftp, uint8_t *rshift
// //
//========================================================================== //==========================================================================
PalettedPixels FDDSTexture::CreatePalettedPixels(int conversion) PalettedPixels FDDSTexture::CreatePalettedPixels(int conversion, int frame)
{ {
auto lump = fileSystem.OpenFileReader (SourceLump); auto lump = fileSystem.OpenFileReader (SourceLump);
@ -781,7 +781,7 @@ void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t
// //
//=========================================================================== //===========================================================================
int FDDSTexture::CopyPixels(FBitmap *bmp, int conversion) int FDDSTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
auto lump = fileSystem.OpenFileReader (SourceLump); auto lump = fileSystem.OpenFileReader (SourceLump);

View file

@ -49,7 +49,7 @@ class FEmptyTexture : public FImageSource
{ {
public: public:
FEmptyTexture (int lumpnum); FEmptyTexture (int lumpnum);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
}; };
//========================================================================== //==========================================================================
@ -94,7 +94,7 @@ FEmptyTexture::FEmptyTexture (int lumpnum)
// //
//========================================================================== //==========================================================================
PalettedPixels FEmptyTexture::CreatePalettedPixels(int conversion) PalettedPixels FEmptyTexture::CreatePalettedPixels(int conversion, int frame)
{ {
static uint8_t p; static uint8_t p;
PalettedPixels Pixel(&p, 1); PalettedPixels Pixel(&p, 1);

View file

@ -48,7 +48,7 @@ class FFlatTexture : public FImageSource
{ {
public: public:
FFlatTexture (int lumpnum); FFlatTexture (int lumpnum);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
}; };
@ -102,7 +102,7 @@ FFlatTexture::FFlatTexture (int lumpnum)
// //
//========================================================================== //==========================================================================
PalettedPixels FFlatTexture::CreatePalettedPixels(int conversion) PalettedPixels FFlatTexture::CreatePalettedPixels(int conversion, int frame)
{ {
auto lump = fileSystem.OpenFileReader (SourceLump); auto lump = fileSystem.OpenFileReader (SourceLump);
PalettedPixels Pixels(Width*Height); PalettedPixels Pixels(Width*Height);

View file

@ -66,7 +66,7 @@ FFontChar2::FFontChar2(int sourcelump, int sourcepos, int width, int height, int
// //
//========================================================================== //==========================================================================
PalettedPixels FFontChar2::CreatePalettedPixels(int) PalettedPixels FFontChar2::CreatePalettedPixels(int, int)
{ {
auto lump = fileSystem.OpenFileReader(SourceLump); auto lump = fileSystem.OpenFileReader(SourceLump);
int destSize = Width * Height; int destSize = Width * Height;
@ -170,7 +170,7 @@ PalettedPixels FFontChar2::CreatePalettedPixels(int)
return Pixels; return Pixels;
} }
int FFontChar2::CopyPixels(FBitmap* bmp, int conversion) int FFontChar2::CopyPixels(FBitmap* bmp, int conversion, int frame)
{ {
if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source. if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source.
auto ppix = CreatePalettedPixels(conversion); auto ppix = CreatePalettedPixels(conversion);

View file

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

View file

@ -66,8 +66,8 @@ class FIMGZTexture : public FImageSource
public: public:
FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t, bool isalpha); FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t, bool isalpha);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
}; };
@ -118,7 +118,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
// //
//========================================================================== //==========================================================================
PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion) PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion, int frame)
{ {
auto lump = fileSystem.ReadFile (SourceLump); auto lump = fileSystem.ReadFile (SourceLump);
auto imgz = (const ImageHeader *)lump.GetMem(); auto imgz = (const ImageHeader *)lump.GetMem();
@ -198,7 +198,7 @@ PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion)
// //
//========================================================================== //==========================================================================
int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion) int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); if (!isalpha) return FImageSource::CopyPixels(bmp, conversion);
else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette); else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette);

View file

@ -185,8 +185,8 @@ class FJPEGTexture : public FImageSource
public: public:
FJPEGTexture (int lumpnum, int width, int height); FJPEGTexture (int lumpnum, int width, int height);
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
}; };
//========================================================================== //==========================================================================
@ -260,7 +260,7 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height)
// //
//========================================================================== //==========================================================================
PalettedPixels FJPEGTexture::CreatePalettedPixels(int conversion) PalettedPixels FJPEGTexture::CreatePalettedPixels(int conversion, int frame)
{ {
auto lump = fileSystem.OpenFileReader (SourceLump); auto lump = fileSystem.OpenFileReader (SourceLump);
JSAMPLE *buff = NULL; JSAMPLE *buff = NULL;
@ -401,7 +401,7 @@ PalettedPixels FJPEGTexture::CreatePalettedPixels(int conversion)
// //
//=========================================================================== //===========================================================================
int FJPEGTexture::CopyPixels(FBitmap *bmp, int conversion) int FJPEGTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
PalEntry pe[256]; PalEntry pe[256];

View file

@ -201,7 +201,7 @@ void FMultiPatchTexture::CopyToBlock(uint8_t *dest, int dwidth, int dheight, FIm
// //
//========================================================================== //==========================================================================
PalettedPixels FMultiPatchTexture::CreatePalettedPixels(int conversion) PalettedPixels FMultiPatchTexture::CreatePalettedPixels(int conversion, int frame)
{ {
int numpix = Width * Height; int numpix = Width * Height;
uint8_t blendwork[256]; uint8_t blendwork[256];
@ -278,7 +278,7 @@ PalettedPixels FMultiPatchTexture::CreatePalettedPixels(int conversion)
// //
//=========================================================================== //===========================================================================
int FMultiPatchTexture::CopyPixels(FBitmap *bmp, int conversion) int FMultiPatchTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
int retv = -1; int retv = -1;

View file

@ -74,8 +74,8 @@ protected:
TexPart *Parts; TexPart *Parts;
// The getters must optionally redirect if it's a simple one-patch texture. // The getters must optionally redirect if it's a simple one-patch texture.
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) 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 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; void CollectForPrecache(PrecacheInfo &info, bool requiretruecolor) override;

View file

@ -62,8 +62,8 @@ class FPatchTexture : public FImageSource
bool isalpha = false; bool isalpha = false;
public: public:
FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex); FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
bool SupportRemap0() override { return !badflag; } bool SupportRemap0() override { return !badflag; }
void DetectBadPatches(); void DetectBadPatches();
}; };
@ -167,7 +167,7 @@ FPatchTexture::FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool is
// //
//========================================================================== //==========================================================================
PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion) PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion, int frame)
{ {
uint8_t *remap, remaptable[256]; uint8_t *remap, remaptable[256];
int numspans; int numspans;
@ -264,7 +264,7 @@ PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion)
// //
//========================================================================== //==========================================================================
int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion) int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); if (!isalpha) return FImageSource::CopyPixels(bmp, conversion);
else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette); else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette);

View file

@ -84,7 +84,7 @@ class FPCXTexture : public FImageSource
public: public:
FPCXTexture (int lumpnum, PCXHeader &); FPCXTexture (int lumpnum, PCXHeader &);
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
protected: protected:
void ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr); void ReadPCX1bit (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
@ -92,7 +92,7 @@ protected:
void ReadPCX8bits (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); void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
}; };
@ -345,7 +345,7 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr
// //
//========================================================================== //==========================================================================
PalettedPixels FPCXTexture::CreatePalettedPixels(int conversion) PalettedPixels FPCXTexture::CreatePalettedPixels(int conversion, int frame)
{ {
uint8_t PaletteMap[256]; uint8_t PaletteMap[256];
PCXHeader header; PCXHeader header;
@ -433,7 +433,7 @@ PalettedPixels FPCXTexture::CreatePalettedPixels(int conversion)
// //
//=========================================================================== //===========================================================================
int FPCXTexture::CopyPixels(FBitmap *bmp, int conversion) int FPCXTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
PalEntry pe[256]; PalEntry pe[256];
PCXHeader header; PCXHeader header;

View file

@ -56,8 +56,8 @@ class FPNGTexture : public FImageSource
public: public:
FPNGTexture (FileReader &lump, int lumpnum, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace); 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; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
protected: protected:
void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap); void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap);
@ -412,7 +412,7 @@ void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap)
// //
//========================================================================== //==========================================================================
PalettedPixels FPNGTexture::CreatePalettedPixels(int conversion) PalettedPixels FPNGTexture::CreatePalettedPixels(int conversion, int frame)
{ {
FileReader *lump; FileReader *lump;
FileReader lfr; FileReader lfr;
@ -553,7 +553,7 @@ PalettedPixels FPNGTexture::CreatePalettedPixels(int conversion)
// //
//=========================================================================== //===========================================================================
int FPNGTexture::CopyPixels(FBitmap *bmp, int conversion) int FPNGTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
// Parse pre-IDAT chunks. I skip the CRCs. Is that bad? // Parse pre-IDAT chunks. I skip the CRCs. Is that bad?
PalEntry pe[256]; PalEntry pe[256];

View file

@ -51,8 +51,8 @@ class FQOITexture : public FImageSource
{ {
public: public:
FQOITexture(int lumpnum, QOIHeader& header); FQOITexture(int lumpnum, QOIHeader& header);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
}; };
FImageSource *QOIImage_TryCreate(FileReader &file, int lumpnum) FImageSource *QOIImage_TryCreate(FileReader &file, int lumpnum)
@ -89,7 +89,7 @@ FQOITexture::FQOITexture(int lumpnum, QOIHeader& header)
if (header.channels == 3) bMasked = bTranslucent = false; if (header.channels == 3) bMasked = bTranslucent = false;
} }
PalettedPixels FQOITexture::CreatePalettedPixels(int conversion) PalettedPixels FQOITexture::CreatePalettedPixels(int conversion, int frame)
{ {
FBitmap bitmap; FBitmap bitmap;
bitmap.Create(Width, Height); bitmap.Create(Width, Height);
@ -124,7 +124,7 @@ PalettedPixels FQOITexture::CreatePalettedPixels(int conversion)
return Pixels; return Pixels;
} }
int FQOITexture::CopyPixels(FBitmap *bmp, int conversion) int FQOITexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
enum enum
{ {

View file

@ -52,8 +52,8 @@ class FRawPageTexture : public FImageSource
int mPaletteLump = -1; int mPaletteLump = -1;
public: public:
FRawPageTexture (int lumpnum); FRawPageTexture (int lumpnum);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
}; };
//========================================================================== //==========================================================================
@ -170,7 +170,7 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
// //
//========================================================================== //==========================================================================
PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion) PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion, int frame)
{ {
auto lump = fileSystem.ReadFile (SourceLump); auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes(); auto source = lump.GetBytes();
@ -199,7 +199,7 @@ PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion)
return Pixels; return Pixels;
} }
int FRawPageTexture::CopyPixels(FBitmap *bmp, int conversion) int FRawPageTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp, conversion); if (mPaletteLump < 0) return FImageSource::CopyPixels(bmp, conversion);
else else

View file

@ -98,7 +98,7 @@ public:
} }
} }
PalettedPixels CreatePalettedPixels(int conversion) override PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override
{ {
PalettedPixels Pix(512); PalettedPixels Pix(512);
if (conversion == luminance) if (conversion == luminance)
@ -118,7 +118,7 @@ public:
return Pix; return Pix;
} }
int CopyPixels(FBitmap *bmp, int conversion) override int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override
{ {
bmp->CopyPixelData(0, 0, Pixels, Width, Height, Height, 1, 0, GPalette.GrayRamp.Palette); bmp->CopyPixelData(0, 0, Pixels, Width, Height, Height, 1, 0, GPalette.GrayRamp.Palette);
return 0; return 0;

View file

@ -60,7 +60,7 @@ public:
Height = srcdata.GetHeight(); Height = srcdata.GetHeight();
bUseGamePalette = false; bUseGamePalette = false;
} }
int CopyPixels(FBitmap* bmp, int conversion) int CopyPixels(FBitmap* bmp, int conversion, int frame = 0)
{ {
bmp->Blit(0, 0, info); bmp->Blit(0, 0, info);
return 0; return 0;

View file

@ -77,30 +77,30 @@ class FStartupTexture : public FImageSource
{ {
public: public:
FStartupTexture (int lumpnum); FStartupTexture (int lumpnum);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame) override;
}; };
class FNotchTexture : public FImageSource class FNotchTexture : public FImageSource
{ {
public: public:
FNotchTexture (int lumpnum, int width, int height); FNotchTexture (int lumpnum, int width, int height);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame) override;
}; };
class FStrifeStartupTexture : public FImageSource class FStrifeStartupTexture : public FImageSource
{ {
public: public:
FStrifeStartupTexture (int lumpnum, int w, int h); FStrifeStartupTexture (int lumpnum, int w, int h);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
}; };
class FStrifeStartupBackground : public FImageSource class FStrifeStartupBackground : public FImageSource
{ {
public: public:
FStrifeStartupBackground (int lumpnum); FStrifeStartupBackground (int lumpnum);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
}; };
//========================================================================== //==========================================================================
@ -231,7 +231,7 @@ void PlanarToChunky(T* dest, const uint8_t* src, const T* remap, int width, int
// //
//========================================================================== //==========================================================================
PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion) PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion, int frame)
{ {
auto lump = fileSystem.ReadFile (SourceLump); auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes(); auto source = lump.GetBytes();
@ -251,7 +251,7 @@ PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion)
// //
//========================================================================== //==========================================================================
int FStartupTexture::CopyPixels(FBitmap *bmp, int conversion) int FStartupTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
auto lump = fileSystem.ReadFile (SourceLump); auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes(); auto source = lump.GetBytes();
@ -279,7 +279,7 @@ FNotchTexture::FNotchTexture (int lumpnum, int width, int height)
// //
//========================================================================== //==========================================================================
PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion) PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion, int frame)
{ {
auto lump = fileSystem.ReadFile (SourceLump); auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes(); auto source = lump.GetBytes();
@ -302,7 +302,7 @@ PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion)
// //
//========================================================================== //==========================================================================
int FNotchTexture::CopyPixels(FBitmap *bmp, int conversion) int FNotchTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
auto lump = fileSystem.ReadFile (SourceLump); auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes(); auto source = lump.GetBytes();
@ -336,7 +336,7 @@ FStrifeStartupTexture::FStrifeStartupTexture (int lumpnum, int w, int h)
// //
//========================================================================== //==========================================================================
PalettedPixels FStrifeStartupTexture::CreatePalettedPixels(int conversion) PalettedPixels FStrifeStartupTexture::CreatePalettedPixels(int conversion, int frame)
{ {
auto lump = fileSystem.ReadFile (SourceLump); auto lump = fileSystem.ReadFile (SourceLump);
auto source = lump.GetBytes(); auto source = lump.GetBytes();
@ -366,7 +366,7 @@ FStrifeStartupBackground::FStrifeStartupBackground (int lumpnum)
// //
//========================================================================== //==========================================================================
PalettedPixels FStrifeStartupBackground::CreatePalettedPixels(int conversion) PalettedPixels FStrifeStartupBackground::CreatePalettedPixels(int conversion, int frame)
{ {
TArray<uint8_t> source(64000, true); TArray<uint8_t> source(64000, true);
memset(source.Data(), 0xF0, 64000); memset(source.Data(), 0xF0, 64000);

View file

@ -67,8 +67,8 @@ class FStbTexture : public FImageSource
public: public:
FStbTexture (int lumpnum, int w, int h); FStbTexture (int lumpnum, int w, int h);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
}; };
@ -117,7 +117,7 @@ FStbTexture::FStbTexture (int lumpnum, int w, int h)
// //
//========================================================================== //==========================================================================
PalettedPixels FStbTexture::CreatePalettedPixels(int conversion) PalettedPixels FStbTexture::CreatePalettedPixels(int conversion, int frame)
{ {
FBitmap bitmap; FBitmap bitmap;
bitmap.Create(Width, Height); bitmap.Create(Width, Height);
@ -156,7 +156,7 @@ PalettedPixels FStbTexture::CreatePalettedPixels(int conversion)
// //
//========================================================================== //==========================================================================
int FStbTexture::CopyPixels(FBitmap *bmp, int conversion) int FStbTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
auto lump = fileSystem.OpenFileReader (SourceLump); auto lump = fileSystem.OpenFileReader (SourceLump);
int x, y, chan; int x, y, chan;

View file

@ -80,11 +80,11 @@ class FTGATexture : public FImageSource
public: public:
FTGATexture (int lumpnum, TGAHeader *); FTGATexture (int lumpnum, TGAHeader *);
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
protected: protected:
void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel); void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
}; };
//========================================================================== //==========================================================================
@ -178,7 +178,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe
// //
//========================================================================== //==========================================================================
PalettedPixels FTGATexture::CreatePalettedPixels(int conversion) PalettedPixels FTGATexture::CreatePalettedPixels(int conversion, int frame)
{ {
uint8_t PaletteMap[256]; uint8_t PaletteMap[256];
auto lump = fileSystem.OpenFileReader (SourceLump); auto lump = fileSystem.OpenFileReader (SourceLump);
@ -385,7 +385,7 @@ PalettedPixels FTGATexture::CreatePalettedPixels(int conversion)
// //
//=========================================================================== //===========================================================================
int FTGATexture::CopyPixels(FBitmap *bmp, int conversion) int FTGATexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
PalEntry pe[256]; PalEntry pe[256];
auto lump = fileSystem.OpenFileReader (SourceLump); auto lump = fileSystem.OpenFileReader (SourceLump);

View file

@ -47,8 +47,8 @@ class FWebPTexture : public FImageSource
public: public:
FWebPTexture(int lumpnum, int w, int h, int xoff, int yoff); FWebPTexture(int lumpnum, int w, int h, int xoff, int yoff);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap *bmp, int conversion) override; int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
}; };
@ -94,10 +94,10 @@ FWebPTexture::FWebPTexture(int lumpnum, int w, int h, int xoff, int yoff)
TopOffset = yoff; TopOffset = yoff;
} }
PalettedPixels FWebPTexture::CreatePalettedPixels(int conversion) PalettedPixels FWebPTexture::CreatePalettedPixels(int conversion, int frame)
{ {
FBitmap bitmap; FBitmap bitmap;
bitmap.Create(Width, Height); bitmap.Create(Width, Height, frame);
CopyPixels(&bitmap, conversion); CopyPixels(&bitmap, conversion);
const uint8_t *data = bitmap.GetPixels(); const uint8_t *data = bitmap.GetPixels();
@ -127,7 +127,7 @@ PalettedPixels FWebPTexture::CreatePalettedPixels(int conversion)
return Pixels; return Pixels;
} }
int FWebPTexture::CopyPixels(FBitmap *bmp, int conversion) int FWebPTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
WebPDecoderConfig config; WebPDecoderConfig config;
auto bytes = fileSystem.ReadFile(SourceLump); auto bytes = fileSystem.ReadFile(SourceLump);

View file

@ -51,6 +51,7 @@ struct PrecacheDataPaletted
PalettedPixels Pixels; PalettedPixels Pixels;
int RefCount; int RefCount;
int ImageID; int ImageID;
int Frame;
}; };
struct PrecacheDataRgba struct PrecacheDataRgba
@ -59,6 +60,7 @@ struct PrecacheDataRgba
int TransInfo; int TransInfo;
int RefCount; int RefCount;
int ImageID; int ImageID;
int Frame;
}; };
// TMap doesn't handle this kind of data well. std::map neither. The linear search is still faster, even for a few 100 entries because it doesn't have to access the heap as often.. // TMap doesn't handle this kind of data well. std::map neither. The linear search is still faster, even for a few 100 entries because it doesn't have to access the heap as often..
@ -71,21 +73,21 @@ TArray<PrecacheDataRgba> precacheDataRgba;
// //
//=========================================================================== //===========================================================================
PalettedPixels FImageSource::CreatePalettedPixels(int conversion) PalettedPixels FImageSource::CreatePalettedPixels(int conversion, int frame)
{ {
PalettedPixels Pixels(Width * Height); PalettedPixels Pixels(Width * Height);
memset(Pixels.Data(), 0, Width * Height); memset(Pixels.Data(), 0, Width * Height);
return Pixels; return Pixels;
} }
PalettedPixels FImageSource::GetCachedPalettedPixels(int conversion) PalettedPixels FImageSource::GetCachedPalettedPixels(int conversion, int frame)
{ {
PalettedPixels ret; PalettedPixels ret;
auto imageID = ImageID; auto imageID = ImageID;
// Do we have this image in the cache? // Do we have this image in the cache?
unsigned index = conversion != normal? UINT_MAX : precacheDataPaletted.FindEx([=](PrecacheDataPaletted &entry) { return entry.ImageID == imageID; }); unsigned index = conversion != normal? UINT_MAX : precacheDataPaletted.FindEx([=](PrecacheDataPaletted &entry) { return entry.ImageID == imageID && entry.Frame == frame; });
if (index < precacheDataPaletted.Size()) if (index < precacheDataPaletted.Size())
{ {
auto cache = &precacheDataPaletted[index]; auto cache = &precacheDataPaletted[index];
@ -115,7 +117,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. // 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()); //Printf("returning fresh copy of %s\n", name.GetChars());
return CreatePalettedPixels(conversion); return CreatePalettedPixels(conversion, frame);
} }
else else
{ {
@ -126,16 +128,16 @@ PalettedPixels FImageSource::GetCachedPalettedPixels(int conversion)
pdp->ImageID = imageID; pdp->ImageID = imageID;
pdp->RefCount = info->second - 1; pdp->RefCount = info->second - 1;
info->second = 0; info->second = 0;
pdp->Pixels = CreatePalettedPixels(normal); pdp->Pixels = CreatePalettedPixels(normal, frame);
ret.Pixels.Set(pdp->Pixels.Data(), pdp->Pixels.Size()); ret.Pixels.Set(pdp->Pixels.Data(), pdp->Pixels.Size());
} }
} }
return ret; return ret;
} }
TArray<uint8_t> FImageSource::GetPalettedPixels(int conversion) TArray<uint8_t> FImageSource::GetPalettedPixels(int conversion, int frame)
{ {
auto pix = GetCachedPalettedPixels(conversion); auto pix = GetCachedPalettedPixels(conversion, frame);
if (pix.ownsPixels()) if (pix.ownsPixels())
{ {
// return the pixel store of the returned data directly if this was the last reference. // return the pixel store of the returned data directly if this was the last reference.
@ -165,19 +167,19 @@ TArray<uint8_t> FImageSource::GetPalettedPixels(int conversion)
// //
//=========================================================================== //===========================================================================
int FImageSource::CopyPixels(FBitmap *bmp, int conversion) int FImageSource::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source. if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source.
PalEntry *palette = GPalette.BaseColors; PalEntry *palette = GPalette.BaseColors;
auto ppix = CreatePalettedPixels(conversion); auto ppix = CreatePalettedPixels(conversion, frame);
bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, palette, nullptr); bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, palette, nullptr);
return 0; return 0;
} }
int FImageSource::CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap) int FImageSource::CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap, int frame)
{ {
auto ppix = CreatePalettedPixels(normal); auto ppix = CreatePalettedPixels(normal, frame);
bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, remap, nullptr); bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, remap, nullptr);
return 0; return 0;
} }
@ -188,26 +190,31 @@ int FImageSource::CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap)
// //
//========================================================================== //==========================================================================
FBitmap FImageSource::GetCachedBitmap(const PalEntry *remap, int conversion, int *ptrans) FBitmap FImageSource::GetCachedBitmap(const PalEntry *remap, int conversion, int *ptrans, int frame)
{ {
FBitmap ret; FBitmap ret;
int trans = -1; int trans = -1;
auto imageID = ImageID; auto imageID = ImageID;
if (NumOfFrames == 1 && frame == 1)
{
frame = 0;
}
if (remap != nullptr) if (remap != nullptr)
{ {
// Remapped images are never run through the cache because they would complicate matters too much for very little gain. // Remapped images are never run through the cache because they would complicate matters too much for very little gain.
// Translated images are normally sprites which normally just consist of a single image and use no composition. // Translated images are normally sprites which normally just consist of a single image and use no composition.
// Additionally, since translation requires the base palette, the really time consuming stuff will never be subjected to it. // Additionally, since translation requires the base palette, the really time consuming stuff will never be subjected to it.
ret.Create(Width, Height); ret.Create(Width, Height);
trans = CopyTranslatedPixels(&ret, remap); trans = CopyTranslatedPixels(&ret, remap, frame);
} }
else else
{ {
if (conversion == luminance) conversion = normal; // luminance has no meaning for true color. if (conversion == luminance) conversion = normal; // luminance has no meaning for true color.
// Do we have this image in the cache? // Do we have this image in the cache?
unsigned index = conversion != normal? UINT_MAX : precacheDataRgba.FindEx([=](PrecacheDataRgba &entry) { return entry.ImageID == imageID; }); unsigned index = conversion != normal? UINT_MAX : precacheDataRgba.FindEx([=](PrecacheDataRgba &entry) { return entry.ImageID == imageID && entry.Frame == frame; });
if (index < precacheDataRgba.Size()) if (index < precacheDataRgba.Size())
{ {
auto cache = &precacheDataRgba[index]; auto cache = &precacheDataRgba[index];
@ -230,7 +237,7 @@ FBitmap FImageSource::GetCachedBitmap(const PalEntry *remap, int conversion, int
// This should never happen if the function is implemented correctly // This should never happen if the function is implemented correctly
//Printf("something bad happened for %s, refcount = %d\n", name.GetChars(), cache->RefCount); //Printf("something bad happened for %s, refcount = %d\n", name.GetChars(), cache->RefCount);
ret.Create(Width, Height); ret.Create(Width, Height);
trans = CopyPixels(&ret, normal); trans = CopyPixels(&ret, normal, frame);
} }
} }
else else
@ -242,7 +249,7 @@ FBitmap FImageSource::GetCachedBitmap(const PalEntry *remap, int conversion, int
// 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. // 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()); //Printf("returning fresh copy of %s\n", name.GetChars());
ret.Create(Width, Height); ret.Create(Width, Height);
trans = CopyPixels(&ret, conversion); trans = CopyPixels(&ret, conversion, frame);
} }
else else
{ {
@ -251,10 +258,11 @@ FBitmap FImageSource::GetCachedBitmap(const PalEntry *remap, int conversion, int
PrecacheDataRgba *pdr = &precacheDataRgba[precacheDataRgba.Reserve(1)]; PrecacheDataRgba *pdr = &precacheDataRgba[precacheDataRgba.Reserve(1)];
pdr->ImageID = imageID; pdr->ImageID = imageID;
pdr->Frame = frame;
pdr->RefCount = info->first - 1; pdr->RefCount = info->first - 1;
info->first = 0; info->first = 0;
pdr->Pixels.Create(Width, Height); pdr->Pixels.Create(Width, Height);
trans = pdr->TransInfo = CopyPixels(&pdr->Pixels, normal); trans = pdr->TransInfo = CopyPixels(&pdr->Pixels, normal, frame);
ret.Copy(pdr->Pixels, false); ret.Copy(pdr->Pixels, false);
} }
} }

View file

@ -67,12 +67,13 @@ protected:
int LeftOffset = 0, TopOffset = 0; // Offsets stored in the image. int LeftOffset = 0, TopOffset = 0; // Offsets stored in the image.
bool bUseGamePalette = false; // true if this is an image without its own color set. bool bUseGamePalette = false; // true if this is an image without its own color set.
int ImageID = -1; int ImageID = -1;
int NumOfFrames = 1;
// Internal image creation functions. All external access should go through the cache interface, // Internal image creation functions. All external access should go through the cache interface,
// so that all code can benefit from future improvements to that. // so that all code can benefit from future improvements to that.
virtual PalettedPixels CreatePalettedPixels(int conversion); virtual PalettedPixels CreatePalettedPixels(int conversion, int frame = 0);
int CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap); int CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap, int frame = 0);
public: public:
@ -101,19 +102,25 @@ public:
// 'noremap0' will only be looked at by FPatchTexture and forwarded by FMultipatchTexture. // 'noremap0' will only be looked at by FPatchTexture and forwarded by FMultipatchTexture.
// Either returns a reference to the cache, or a newly created item. The return of this has to be considered transient. If you need to store the result, use GetPalettedPixels // Either returns a reference to the cache, or a newly created item. The return of this has to be considered transient. If you need to store the result, use GetPalettedPixels
PalettedPixels GetCachedPalettedPixels(int conversion); PalettedPixels GetCachedPalettedPixels(int conversion, int frame = 0);
// tries to get a buffer from the cache. If not available, create a new one. If further references are pending, create a copy. // tries to get a buffer from the cache. If not available, create a new one. If further references are pending, create a copy.
TArray<uint8_t> GetPalettedPixels(int conversion); TArray<uint8_t> GetPalettedPixels(int conversion, int frame = 0);
virtual int CopyPixels(FBitmap* bmp, int conversion); virtual int CopyPixels(FBitmap* bmp, int conversion, int frame = 0);
FBitmap GetCachedBitmap(const PalEntry *remap, int conversion, int *trans = nullptr); FBitmap GetCachedBitmap(const PalEntry *remap, int conversion, int *trans = nullptr, int frame = 0);
static void ClearImages() { ImageArena.FreeAll(); ImageForLump.Clear(); NextID = 0; } static void ClearImages() { ImageArena.FreeAll(); ImageForLump.Clear(); NextID = 0; }
static FImageSource * GetImage(int lumpnum, bool checkflat); static FImageSource * GetImage(int lumpnum, bool checkflat);
// Frame functions
// Gets number of frames.
int GetNumOfFrames() { return NumOfFrames; }
// Gets duration of frame in miliseconds.
virtual int GetDurationOfFrame(int frame) { return 1000; }
// Conversion option // Conversion option
enum EType enum EType
@ -180,8 +187,8 @@ class FBuildTexture : public FImageSource
{ {
public: public:
FBuildTexture(const FString& pathprefix, int tilenum, const uint8_t* pixels, FRemapTable* translation, int width, int height, int left, int top); FBuildTexture(const FString& pathprefix, int tilenum, const uint8_t* pixels, FRemapTable* translation, int width, int height, int left, int top);
PalettedPixels CreatePalettedPixels(int conversion) override; PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
int CopyPixels(FBitmap* bmp, int conversion) override; int CopyPixels(FBitmap* bmp, int conversion, int frame = 0) override;
protected: protected:
const uint8_t* RawPixels; const uint8_t* RawPixels;
@ -191,4 +198,4 @@ protected:
class FTexture; class FTexture;
FTexture* CreateImageTexture(FImageSource* img) noexcept; FTexture* CreateImageTexture(FImageSource* img, int frame = 0) noexcept;

View file

@ -47,10 +47,11 @@
// //
//========================================================================== //==========================================================================
FImageTexture::FImageTexture(FImageSource *img) noexcept FImageTexture::FImageTexture(FImageSource *img, int frame) noexcept
: FTexture(img? img->LumpNum() : 0) : FTexture(img? img->LumpNum() : 0)
{ {
mImage = img; mImage = img;
TexFrame = frame;
if (img != nullptr) if (img != nullptr)
{ {
SetFromImage(); SetFromImage();
@ -79,7 +80,7 @@ void FImageTexture::SetFromImage()
FBitmap FImageTexture::GetBgraBitmap(const PalEntry *p, int *trans) FBitmap FImageTexture::GetBgraBitmap(const PalEntry *p, int *trans)
{ {
return mImage->GetCachedBitmap(p, bNoRemap0? FImageSource::noremap0 : FImageSource::normal, trans); return mImage->GetCachedBitmap(p, bNoRemap0? FImageSource::noremap0 : FImageSource::normal, trans, TexFrame);
} }
//=========================================================================== //===========================================================================
@ -90,7 +91,7 @@ FBitmap FImageTexture::GetBgraBitmap(const PalEntry *p, int *trans)
TArray<uint8_t> FImageTexture::Get8BitPixels(bool alpha) TArray<uint8_t> FImageTexture::Get8BitPixels(bool alpha)
{ {
return mImage->GetPalettedPixels(alpha? FImageSource::luminance : bNoRemap0 ? FImageSource::noremap0 : FImageSource::normal); return mImage->GetPalettedPixels(alpha? FImageSource::luminance : bNoRemap0 ? FImageSource::noremap0 : FImageSource::normal, TexFrame);
} }
//=========================================================================== //===========================================================================
@ -113,8 +114,8 @@ bool FImageTexture::DetermineTranslucency()
} }
FTexture* CreateImageTexture(FImageSource* img) noexcept FTexture* CreateImageTexture(FImageSource* img, int frame) noexcept
{ {
return new FImageTexture(img); return new FImageTexture(img, frame);
} }

View file

@ -379,10 +379,11 @@ class FImageTexture : public FTexture
{ {
FImageSource* mImage; FImageSource* mImage;
bool bNoRemap0 = false; bool bNoRemap0 = false;
int TexFrame = 0;
protected: protected:
void SetFromImage(); void SetFromImage();
public: public:
FImageTexture(FImageSource* image) noexcept; FImageTexture(FImageSource* image, int frame = 0) noexcept;
~FImageTexture(); ~FImageTexture();
TArray<uint8_t> Get8BitPixels(bool alphatex) override; TArray<uint8_t> Get8BitPixels(bool alphatex) override;

View file

@ -48,7 +48,7 @@ public:
Height = 1; Height = 1;
} }
int CopyPixels(FBitmap *bmp, int conversion) override int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override
{ {
PalEntry *pe = (PalEntry*)bmp->GetPixels(); PalEntry *pe = (PalEntry*)bmp->GetPixels();
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)