Skip to content

Commit

Permalink
- changed multipatch texture composition to always composite off full…
Browse files Browse the repository at this point in the history
… source images and not do it recursively.

Previously it tried to copy all patches of composite sub-images directly onto the main image.
This caused massive complications throughout the entire true color texture code and made any attempt of caching the source data for composition next to impossible because the entire composition process operated on the raw data read from the texture and not some cacheable image. While this may cause more pixel data to be processed, this will be easily offset by being able to reuse patches for multiple textures, once a caching system is in place, which even for the IWADs happens quite frequently.

Removing the now unneeded arguments from the implementation also makes things a lot easier to handle.
  • Loading branch information
coelckers committed Dec 8, 2018
1 parent 1e070d2 commit 0362610
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 192 deletions.
4 changes: 2 additions & 2 deletions src/f_wipe.cpp
Expand Up @@ -41,9 +41,9 @@ class FBurnTexture : public FTexture
Height = h;
}

int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override
int CopyPixels(FBitmap *bmp) override
{
bmp->CopyPixelDataRGB(x, y, (uint8_t*)WorkBuffer.Data(), Width, Height, 4, Width*4, rotate, CF_RGBA, inf);
bmp->CopyPixelDataRGB(0, 0, (uint8_t*)WorkBuffer.Data(), Width, Height, 4, Width*4, 0, CF_RGBA, nullptr);
return 0;
}

Expand Down
7 changes: 4 additions & 3 deletions src/posix/sdl/i_gui.cpp
Expand Up @@ -44,10 +44,11 @@ bool I_SetCursor(FTexture *cursorpic)
static SDL_Cursor *cursor;
static SDL_Surface *cursorSurface;

if (cursorpic != NULL && cursorpic->UseType != ETextureType::Null)
if (cursorpic != NULL && cursorpic->isValid())
{
auto src = cursorpic->GetBgraBitmap(nullptr);
// Must be no larger than 32x32.
if (cursorpic->GetWidth() > 32 || cursorpic->GetHeight() > 32)
if (src.GetWidth() > 32 || src.GetHeight() > 32)
{
return false;
}
Expand All @@ -59,7 +60,7 @@ bool I_SetCursor(FTexture *cursorpic)
uint8_t buffer[32*32*4];
memset(buffer, 0, 32*32*4);
FBitmap bmp(buffer, 32*4, 32, 32);
cursorpic->CopyTrueColorPixels(&bmp, 0, 0);
bmp.Blit(0, 0, src); // expand to 32*32
memcpy(cursorSurface->pixels, bmp.GetPixels(), 32*32*4);
SDL_UnlockSurface(cursorSurface);

Expand Down
8 changes: 4 additions & 4 deletions src/r_data/models/models_voxel.cpp
Expand Up @@ -51,7 +51,7 @@ class FVoxelTexture : public FWorldTexture
public:
FVoxelTexture(FVoxel *voxel);

int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
int CopyPixels(FBitmap *bmp) override;
bool UseBasePalette() override { return false; }
TArray<uint8_t> Get8BitPixels(bool alphatex) override;

Expand Down Expand Up @@ -109,14 +109,14 @@ TArray<uint8_t> FVoxelTexture::Get8BitPixels(bool alphatex)

//===========================================================================
//
// FVoxelTexture::CopyTrueColorPixels
// FVoxelTexture::CopyPixels
//
// This creates a dummy 16x16 paletted bitmap and converts that using the
// voxel palette
//
//===========================================================================

int FVoxelTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
int FVoxelTexture::CopyPixels(FBitmap *bmp)
{
PalEntry pe[256];
uint8_t bitmap[256];
Expand All @@ -142,7 +142,7 @@ int FVoxelTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, F
pe[i].a = 255;
}
}
bmp->CopyPixelData(x, y, bitmap, Width, Height, 1, 16, rotate, pe, inf);
bmp->CopyPixelData(0, 0, bitmap, Width, Height, 1, 16, 0, pe);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/swrenderer/r_swscene.cpp
Expand Up @@ -51,7 +51,7 @@ class FSWPaletteTexture : public FTexture
UseType = ETextureType::MiscPatch;
}

int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
int CopyPixels(FBitmap *bmp)
{
PalEntry *pe = (PalEntry*)bmp->GetPixels();
for (int i = 0; i < 256; i++)
Expand Down
4 changes: 1 addition & 3 deletions src/swrenderer/textures/r_swtexture.cpp
Expand Up @@ -108,9 +108,7 @@ const uint32_t *FSoftwareTexture::GetPixelsBgra()
{
if (PixelsBgra.Size() == 0 || CheckModified(2))
{
FBitmap bitmap;
bitmap.Create(GetWidth(), GetHeight());
mTexture->CopyTrueColorPixels(&bitmap, 0, 0);
FBitmap bitmap = mTexture->GetBgraBitmap(nullptr);
GenerateBgraFromBitmap(bitmap);
}
return PixelsBgra.Data();
Expand Down
41 changes: 26 additions & 15 deletions src/textures/bitmap.h
Expand Up @@ -56,6 +56,22 @@ enum
BLENDUNIT = (1<<BLENDBITS)
};

enum ColorType
{
CF_RGB,
CF_RGBT,
CF_RGBA,
CF_IA,
CF_CMYK,
CF_YCbCr,
CF_BGR,
CF_BGRA,
CF_I16,
CF_RGB555,
CF_PalEntry
};


class FBitmap
{
protected:
Expand Down Expand Up @@ -201,6 +217,16 @@ class FBitmap
int step_x, int step_y, int rotate, PalEntry * palette, FCopyInfo *inf = NULL);


void Blit(int originx, int originy, const FBitmap &src, int width, int height, int rotate = 0, FCopyInfo *inf = NULL)
{
CopyPixelDataRGB(originx, originy, src.GetPixels(), width, height, 4, src.GetWidth()*4, rotate, CF_BGRA, inf);
}

void Blit(int originx, int originy, const FBitmap &src, FCopyInfo *inf = NULL)
{
CopyPixelDataRGB(originx, originy, src.GetPixels(), src.GetWidth(), src.GetHeight(), 4, src.GetWidth()*4, 0, CF_BGRA, inf);
}

};

bool ClipCopyPixelRect(const FClipRect *cr, int &originx, int &originy,
Expand Down Expand Up @@ -342,21 +368,6 @@ struct cPalEntry
static __forceinline int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; }
};

enum ColorType
{
CF_RGB,
CF_RGBT,
CF_RGBA,
CF_IA,
CF_CMYK,
CF_YCbCr,
CF_BGR,
CF_BGRA,
CF_I16,
CF_RGB555,
CF_PalEntry
};

enum EBlend
{
BLEND_NONE = 0,
Expand Down
6 changes: 3 additions & 3 deletions src/textures/formats/brightmaptexture.cpp
Expand Up @@ -45,7 +45,7 @@ class FBrightmapTexture : public FWorldTexture
public:
FBrightmapTexture (FTexture *source);

int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
int CopyPixels(FBitmap *bmp) override;
bool UseBasePalette() override { return false; }

protected:
Expand Down Expand Up @@ -73,9 +73,9 @@ FBrightmapTexture::FBrightmapTexture (FTexture *source)
SourceLump = -1;
}

int FBrightmapTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
int FBrightmapTexture::CopyPixels(FBitmap *bmp)
{
SourcePic->CopyTrueColorTranslated(bmp, x, y, rotate, TexMan.GlobalBrightmap.Palette);
SourcePic->CopyTranslatedPixels(bmp, TexMan.GlobalBrightmap.Palette);
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions src/textures/formats/buildtexture.cpp
Expand Up @@ -57,7 +57,7 @@ class FBuildTexture : public FWorldTexture
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 CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
int CopyPixels(FBitmap *bmp) override;
bool UseBasePalette() override { return false; }
FTextureFormat GetFormat() override { return TEX_RGB; }

Expand Down Expand Up @@ -96,10 +96,10 @@ TArray<uint8_t> FBuildTexture::Get8BitPixels(bool alphatex)
return Pixels;
}

int FBuildTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
int FBuildTexture::CopyPixels(FBitmap *bmp)
{
PalEntry *Remap = translationtables[TRANSLATION_Standard][Translation]->Palette;
bmp->CopyPixelData(x, y, RawPixels, Width, Height, Height, 1, rotate, Remap, inf);
bmp->CopyPixelData(0, 0, RawPixels, Width, Height, Height, 1, 0, Remap);
return -1;

}
Expand Down
27 changes: 12 additions & 15 deletions src/textures/formats/ddstexture.cpp
Expand Up @@ -182,7 +182,7 @@ class FDDSTexture : public FWorldTexture
void DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode);
void DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode);

int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL);
int CopyPixels(FBitmap *bmp) override;
bool UseBasePalette();

friend class FTexture;
Expand Down Expand Up @@ -485,9 +485,9 @@ void FDDSTexture::ReadRGB (FileReader &lump, uint8_t *buffer, int pixelmode)
uint32_t g = (c & GMask) << GShiftL; g |= g >> GShiftR;
uint32_t b = (c & BMask) << BShiftL; b |= b >> BShiftR;
uint32_t a = (c & AMask) << AShiftL; a |= a >> AShiftR;
pixelp[0] = (uint8_t)(r>>24);
pixelp[0] = (uint8_t)(b>>24);
pixelp[1] = (uint8_t)(g>>24);
pixelp[2] = (uint8_t)(b>>24);
pixelp[2] = (uint8_t)(r>>24);
pixelp[3] = (uint8_t)(a>>24);
pixelp+=4;
}
Expand Down Expand Up @@ -580,9 +580,9 @@ void FDDSTexture::DecompressDXT1 (FileReader &lump, uint8_t *buffer, int pixelmo
else
{
uint8_t * tcp = &buffer[(ox + x)*4 + (oy + y) * Width*4];
tcp[0] = color[ci].r;
tcp[0] = color[ci].b;
tcp[1] = color[ci].g;
tcp[2] = color[ci].b;
tcp[2] = color[ci].r;
tcp[3] = color[ci].a;
}
}
Expand Down Expand Up @@ -669,9 +669,9 @@ void FDDSTexture::DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t
{
uint8_t * tcp = &buffer[(ox + x)*4 + (oy + y) * Width*4];
int c = (yslice >> (x + x)) & 3;
tcp[0] = color[c].r;
tcp[0] = color[c].b;
tcp[1] = color[c].g;
tcp[2] = color[c].b;
tcp[2] = color[c].r;
tcp[3] = ((yalphaslice >> (x * 4)) & 15) * 0x11;
}
}
Expand Down Expand Up @@ -788,9 +788,9 @@ void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t
{
uint8_t * tcp = &buffer[(ox + x)*4 + (oy + y) * Width*4];
int c = (yslice >> (x + x)) & 3;
tcp[0] = color[c].r;
tcp[0] = color[c].b;
tcp[1] = color[c].g;
tcp[2] = color[c].b;
tcp[2] = color[c].r;
tcp[3] = alpha[((yalphaslice >> (x*3)) & 7)];
}
}
Expand All @@ -803,15 +803,15 @@ void FDDSTexture::DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t

//===========================================================================
//
// FDDSTexture::CopyTrueColorPixels
// FDDSTexture::CopyPixels
//
//===========================================================================

int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
int FDDSTexture::CopyPixels(FBitmap *bmp)
{
auto lump = Wads.OpenLumpReader (SourceLump);

uint8_t *TexBuffer = new uint8_t[4*Width*Height];
uint8_t *TexBuffer = bmp->GetPixels();

lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet);

Expand All @@ -832,9 +832,6 @@ int FDDSTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo
DecompressDXT5 (lump, Format == ID_DXT4, TexBuffer, PIX_ARGB);
}

// All formats decompress to RGBA.
bmp->CopyPixelDataRGB(x, y, TexBuffer, Width, Height, 4, Width*4, rotate, CF_RGBA, inf);
delete [] TexBuffer;
return -1;
}

Expand Down
8 changes: 4 additions & 4 deletions src/textures/formats/imgztexture.cpp
Expand Up @@ -67,7 +67,7 @@ class FIMGZTexture : public FWorldTexture
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 CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override;
int CopyPixels(FBitmap *bmp) override;

bool UseBasePalette() override { return !isalpha; }
FTextureFormat GetFormat() override { return isalpha ? TEX_RGB : TEX_Pal; } // should be TEX_Gray instead of TEX_RGB. Maybe later when all is working.
Expand Down Expand Up @@ -201,9 +201,9 @@ TArray<uint8_t> FIMGZTexture::Get8BitPixels(bool alphatex)
//
//==========================================================================

int FIMGZTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
int FIMGZTexture::CopyPixels(FBitmap *bmp)
{
if (!isalpha) return FTexture::CopyTrueColorPixels(bmp, x, y, rotate, inf);
else return CopyTrueColorTranslated(bmp, x, y, rotate, translationtables[TRANSLATION_Standard][STD_Grayscale]->Palette, inf);
if (!isalpha) return FTexture::CopyPixels(bmp);
else return CopyTranslatedPixels(bmp, translationtables[TRANSLATION_Standard][STD_Grayscale]->Palette);
}

22 changes: 11 additions & 11 deletions src/textures/formats/jpegtexture.cpp
Expand Up @@ -184,7 +184,7 @@ class FJPEGTexture : public FWorldTexture
FJPEGTexture (int lumpnum, int width, int height);

FTextureFormat GetFormat () override;
int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override;
int CopyPixels(FBitmap *bmp) override;
bool UseBasePalette() override;
TArray<uint8_t> Get8BitPixels(bool alphatex) override;
};
Expand Down Expand Up @@ -387,13 +387,13 @@ TArray<uint8_t> FJPEGTexture::Get8BitPixels(bool doalpha)

//===========================================================================
//
// FJPEGTexture::CopyTrueColorPixels
// FJPEGTexture::CopyPixels
//
// Preserves the full color information (unlike software mode)
//
//===========================================================================

int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf)
int FJPEGTexture::CopyPixels(FBitmap *bmp)
{
PalEntry pe[256];

Expand Down Expand Up @@ -438,24 +438,24 @@ int FJPEGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FC
switch (cinfo.out_color_space)
{
case JCS_RGB:
bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height,
3, cinfo.output_width * cinfo.output_components, rotate, CF_RGB, inf);
bmp->CopyPixelDataRGB(0, 0, buff, cinfo.output_width, cinfo.output_height,
3, cinfo.output_width * cinfo.output_components, 0, CF_RGB);
break;

case JCS_GRAYSCALE:
for (int i = 0; i < 256; i++) pe[i] = PalEntry(255, i, i, i); // default to a gray map
bmp->CopyPixelData(x, y, buff, cinfo.output_width, cinfo.output_height,
1, cinfo.output_width, rotate, pe, inf);
bmp->CopyPixelData(0, 0, buff, cinfo.output_width, cinfo.output_height,
1, cinfo.output_width, 0, pe);
break;

case JCS_CMYK:
bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height,
4, cinfo.output_width * cinfo.output_components, rotate, CF_CMYK, inf);
bmp->CopyPixelDataRGB(0, 0, buff, cinfo.output_width, cinfo.output_height,
4, cinfo.output_width * cinfo.output_components, 0, CF_CMYK);
break;

case JCS_YCbCr:
bmp->CopyPixelDataRGB(x, y, buff, cinfo.output_width, cinfo.output_height,
4, cinfo.output_width * cinfo.output_components, rotate, CF_YCbCr, inf);
bmp->CopyPixelDataRGB(0, 0, buff, cinfo.output_width, cinfo.output_height,
4, cinfo.output_width * cinfo.output_components, 0, CF_YCbCr);
break;

default:
Expand Down

0 comments on commit 0362610

Please sign in to comment.