From 03626107eb423c99e26b31f41c24aedd452c7eaf Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 8 Dec 2018 17:23:15 +0100 Subject: [PATCH] - changed multipatch texture composition to always composite off full 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. --- src/f_wipe.cpp | 4 +- src/posix/sdl/i_gui.cpp | 7 +-- src/r_data/models/models_voxel.cpp | 8 ++-- src/swrenderer/r_swscene.cpp | 2 +- src/swrenderer/textures/r_swtexture.cpp | 4 +- src/textures/bitmap.h | 41 +++++++++++------ src/textures/formats/brightmaptexture.cpp | 6 +-- src/textures/formats/buildtexture.cpp | 6 +-- src/textures/formats/ddstexture.cpp | 27 +++++------ src/textures/formats/imgztexture.cpp | 8 ++-- src/textures/formats/jpegtexture.cpp | 22 ++++----- src/textures/formats/multipatchtexture.cpp | 41 ++--------------- src/textures/formats/patchtexture.cpp | 8 ++-- src/textures/formats/pcxtexture.cpp | 10 ++-- src/textures/formats/pngtexture.cpp | 16 +++---- src/textures/formats/rawpagetexture.cpp | 8 ++-- src/textures/formats/shadertexture.cpp | 4 +- src/textures/formats/tgatexture.cpp | 20 ++++---- src/textures/hires/hirestex.cpp | 4 +- src/textures/skyboxtexture.cpp | 4 +- src/textures/skyboxtexture.h | 2 +- src/textures/texture.cpp | 41 +++++++++-------- src/textures/textures.h | 7 +-- src/win32/i_system.cpp | 53 +++++++++------------- 24 files changed, 161 insertions(+), 192 deletions(-) diff --git a/src/f_wipe.cpp b/src/f_wipe.cpp index cd8c48f40..6cfc737d1 100644 --- a/src/f_wipe.cpp +++ b/src/f_wipe.cpp @@ -41,9 +41,9 @@ public: 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; } diff --git a/src/posix/sdl/i_gui.cpp b/src/posix/sdl/i_gui.cpp index 1a895a676..8ad9c8b92 100644 --- a/src/posix/sdl/i_gui.cpp +++ b/src/posix/sdl/i_gui.cpp @@ -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; } @@ -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); diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index dca6a4cd8..5b8e82571 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -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 Get8BitPixels(bool alphatex) override; @@ -109,14 +109,14 @@ TArray 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]; @@ -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; } diff --git a/src/swrenderer/r_swscene.cpp b/src/swrenderer/r_swscene.cpp index c8b8da57c..bfdf86a11 100644 --- a/src/swrenderer/r_swscene.cpp +++ b/src/swrenderer/r_swscene.cpp @@ -51,7 +51,7 @@ public: 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++) diff --git a/src/swrenderer/textures/r_swtexture.cpp b/src/swrenderer/textures/r_swtexture.cpp index 8470227ce..ae8c0d1ce 100644 --- a/src/swrenderer/textures/r_swtexture.cpp +++ b/src/swrenderer/textures/r_swtexture.cpp @@ -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(); diff --git a/src/textures/bitmap.h b/src/textures/bitmap.h index 3219ecf34..1c86623ed 100644 --- a/src/textures/bitmap.h +++ b/src/textures/bitmap.h @@ -56,6 +56,22 @@ enum BLENDUNIT = (1<>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, diff --git a/src/textures/formats/brightmaptexture.cpp b/src/textures/formats/brightmaptexture.cpp index 314ac6f74..06cc29e90 100644 --- a/src/textures/formats/brightmaptexture.cpp +++ b/src/textures/formats/brightmaptexture.cpp @@ -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: @@ -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; } diff --git a/src/textures/formats/buildtexture.cpp b/src/textures/formats/buildtexture.cpp index 9d4fa2fdc..ed7bbe1f8 100644 --- a/src/textures/formats/buildtexture.cpp +++ b/src/textures/formats/buildtexture.cpp @@ -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 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; } @@ -96,10 +96,10 @@ TArray 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; } diff --git a/src/textures/formats/ddstexture.cpp b/src/textures/formats/ddstexture.cpp index 5a2007e66..d13733ccf 100644 --- a/src/textures/formats/ddstexture.cpp +++ b/src/textures/formats/ddstexture.cpp @@ -182,7 +182,7 @@ protected: void DecompressDXT3 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode); void DecompressDXT5 (FileReader &lump, bool premultiplied, uint8_t *buffer, int pixelmode); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); + int CopyPixels(FBitmap *bmp) override; bool UseBasePalette(); friend class FTexture; @@ -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; } @@ -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; } } @@ -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; } } @@ -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)]; } } @@ -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); @@ -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; } diff --git a/src/textures/formats/imgztexture.cpp b/src/textures/formats/imgztexture.cpp index 108baf4b9..1486fdedc 100644 --- a/src/textures/formats/imgztexture.cpp +++ b/src/textures/formats/imgztexture.cpp @@ -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 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. @@ -201,9 +201,9 @@ TArray 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); } diff --git a/src/textures/formats/jpegtexture.cpp b/src/textures/formats/jpegtexture.cpp index 8da8a6729..fd8a7beb7 100644 --- a/src/textures/formats/jpegtexture.cpp +++ b/src/textures/formats/jpegtexture.cpp @@ -184,7 +184,7 @@ public: 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 Get8BitPixels(bool alphatex) override; }; @@ -387,13 +387,13 @@ TArray 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]; @@ -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: diff --git a/src/textures/formats/multipatchtexture.cpp b/src/textures/formats/multipatchtexture.cpp index 7b0432bff..1def77b5b 100644 --- a/src/textures/formats/multipatchtexture.cpp +++ b/src/textures/formats/multipatchtexture.cpp @@ -156,7 +156,7 @@ public: bool UseBasePalette() override; virtual void SetFrontSkyLayer () override; - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override; + int CopyPixels(FBitmap *bmp) override; int GetSourceLump() override { return DefinitionLump; } FTexture *GetRedirect() override; FTexture *GetRawTexture() override; @@ -468,36 +468,13 @@ TArray FMultiPatchTexture::MakeTexture (bool alphatex) // //=========================================================================== -int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +int FMultiPatchTexture::CopyPixels(FBitmap *bmp) { int retv = -1; if (bRedirect) { // Redirect straight to the real texture's routine. - return Parts[0].Texture->CopyTrueColorPixels(bmp, x, y, rotate, inf); - } - - if (rotate != 0 || (inf != NULL && ((inf->op != OP_OVERWRITE && inf->op != OP_COPY) || inf->blend != BLEND_NONE))) - { // We are doing some sort of fancy stuff to the destination bitmap, so composite to - // a temporary bitmap, and copy that. - FBitmap tbmp; - if (tbmp.Create(Width, Height)) - { - retv = MAX(retv, CopyTrueColorPixels(&tbmp, 0, 0, 0)); - bmp->CopyPixelDataRGB(x, y, tbmp.GetPixels(), Width, Height, - 4, tbmp.GetPitch(), rotate, CF_BGRA, inf); - } - return retv; - } - - // When compositing a multipatch texture with multipatch parts, - // drawing must be restricted to the actual area which is covered by this texture. - FClipRect saved_cr = bmp->GetClipRect(); - bmp->IntersectClipRect(x, y, Width, Height); - - if (inf != NULL && inf->op == OP_OVERWRITE) - { - bmp->Zero(); + return Parts[0].Texture->CopyPixels(bmp); } for(int i = 0; i < NumParts; i++) @@ -536,20 +513,12 @@ int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rota } } - if (Parts[i].Translation != NULL) - { // Using a translation forces downconversion to the base palette - ret = Parts[i].Texture->CopyTrueColorTranslated(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate, Parts[i].Translation->Palette, &info); - } - else - { - ret = Parts[i].Texture->CopyTrueColorPixels(bmp, x+Parts[i].OriginX, y+Parts[i].OriginY, Parts[i].Rotate, &info); - } + auto Pixels = Parts[i].Texture->GetBgraBitmap(Parts[i].Translation ? Parts[i].Translation->Palette : nullptr, &ret); + bmp->Blit(Parts[i].OriginX, Parts[i].OriginY, Pixels, &info); // treat -1 (i.e. unknown) as absolute. We have no idea if this may have overwritten previous info so a real check needs to be done. if (ret == -1) retv = ret; else if (retv != -1 && ret > retv) retv = ret; } - // Restore previous clipping rectangle. - bmp->SetClipRect(saved_cr); return retv; } diff --git a/src/textures/formats/patchtexture.cpp b/src/textures/formats/patchtexture.cpp index 0b18f837f..5748bbce4 100644 --- a/src/textures/formats/patchtexture.cpp +++ b/src/textures/formats/patchtexture.cpp @@ -63,7 +63,7 @@ class FPatchTexture : public FWorldTexture public: FPatchTexture (int lumpnum, patch_t *header, bool isalphatex); TArray Get8BitPixels(bool alphatex) override; - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override; + int CopyPixels(FBitmap *bmp) override; void DetectBadPatches(); bool UseBasePalette() override { return !isalpha; } @@ -264,10 +264,10 @@ TArray FPatchTexture::Get8BitPixels(bool alphatex) // //========================================================================== -int FPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +int FPatchTexture::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); } //========================================================================== diff --git a/src/textures/formats/pcxtexture.cpp b/src/textures/formats/pcxtexture.cpp index f144e7d8f..fc9863f24 100644 --- a/src/textures/formats/pcxtexture.cpp +++ b/src/textures/formats/pcxtexture.cpp @@ -85,7 +85,7 @@ public: 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; protected: @@ -452,13 +452,13 @@ TArray FPCXTexture::Get8BitPixels(bool alphatex) //=========================================================================== // -// FPCXTexture::CopyTrueColorPixels +// FPCXTexture::CopyPixels // // Preserves the full color information (unlike software mode) // //=========================================================================== -int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +int FPCXTexture::CopyPixels(FBitmap *bmp) { PalEntry pe[256]; PCXHeader header; @@ -513,13 +513,13 @@ int FPCXTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo lump.Seek(sizeof(header), FileReader::SeekSet); ReadPCX8bits (Pixels, lump, &header); } - bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf); + bmp->CopyPixelData(0, 0, Pixels, Width, Height, 1, Width, 0, pe); } else { Pixels = new uint8_t[Width*Height * 3]; ReadPCX24bits (Pixels, lump, &header, 3); - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, Width*3, rotate, CF_RGB, inf); + bmp->CopyPixelDataRGB(0, 0, Pixels, Width, Height, 3, Width*3, 0, CF_RGB); } delete [] Pixels; return 0; diff --git a/src/textures/formats/pngtexture.cpp b/src/textures/formats/pngtexture.cpp index 5c77ce5de..0d1cd661c 100644 --- a/src/textures/formats/pngtexture.cpp +++ b/src/textures/formats/pngtexture.cpp @@ -53,7 +53,7 @@ public: ~FPNGTexture(); 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 Get8BitPixels(bool alphatex) override; @@ -529,11 +529,11 @@ TArray FPNGTexture::Get8BitPixels(bool alphatex) //=========================================================================== // -// FPNGTexture::CopyTrueColorPixels +// FPNGTexture::CopyPixels // //=========================================================================== -int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +int FPNGTexture::CopyPixels(FBitmap *bmp) { // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? PalEntry pe[256]; @@ -618,29 +618,29 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo { case 0: case 3: - bmp->CopyPixelData(x, y, Pixels, Width, Height, 1, Width, rotate, pe, inf); + bmp->CopyPixelData(0, 0, Pixels, Width, Height, 1, Width, 0, pe); break; case 2: if (!HaveTrans) { - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGB, inf); + bmp->CopyPixelDataRGB(0, 0, Pixels, Width, Height, 3, pixwidth, 0, CF_RGB); } else { - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGBT, inf, + bmp->CopyPixelDataRGB(0, 0, Pixels, Width, Height, 3, pixwidth, 0, CF_RGBT, nullptr, NonPaletteTrans[0], NonPaletteTrans[1], NonPaletteTrans[2]); transpal = true; } break; case 4: - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 2, pixwidth, rotate, CF_IA, inf); + bmp->CopyPixelDataRGB(0, 0, Pixels, Width, Height, 2, pixwidth, 0, CF_IA); transpal = -1; break; case 6: - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 4, pixwidth, rotate, CF_RGBA, inf); + bmp->CopyPixelDataRGB(0, 0, Pixels, Width, Height, 4, pixwidth, 0, CF_RGBA); transpal = -1; break; diff --git a/src/textures/formats/rawpagetexture.cpp b/src/textures/formats/rawpagetexture.cpp index 78b48cfac..901f23a41 100644 --- a/src/textures/formats/rawpagetexture.cpp +++ b/src/textures/formats/rawpagetexture.cpp @@ -53,7 +53,7 @@ class FRawPageTexture : public FWorldTexture public: FRawPageTexture (int lumpnum); TArray Get8BitPixels(bool alphatex) override; - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) override; + int CopyPixels(FBitmap *bmp) override; }; //========================================================================== @@ -203,9 +203,9 @@ TArray FRawPageTexture::Get8BitPixels(bool alphatex) return Pixels; } -int FRawPageTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +int FRawPageTexture::CopyPixels(FBitmap *bmp) { - if (mPaletteLump < 0) return FTexture::CopyTrueColorPixels(bmp, x, y, rotate, inf); + if (mPaletteLump < 0) return FTexture::CopyPixels(bmp); else { FMemLump lump = Wads.ReadLump(SourceLump); @@ -220,7 +220,7 @@ int FRawPageTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, pe.b = *psource++; pe.a = 255; } - bmp->CopyPixelData(x, y, source, 320, 200, 1, 320, 0, paldata, inf); + bmp->CopyPixelData(0, 0, source, 320, 200, 1, 320, 0, paldata); } return 0; } diff --git a/src/textures/formats/shadertexture.cpp b/src/textures/formats/shadertexture.cpp index e21bf4f24..9b5eddce1 100644 --- a/src/textures/formats/shadertexture.cpp +++ b/src/textures/formats/shadertexture.cpp @@ -119,9 +119,9 @@ public: return Pix; } - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL) override + int CopyPixels(FBitmap *bmp) override { - bmp->CopyPixelData(x, y, Pixels, Width, Height, Height, 1, rotate, translationtables[TRANSLATION_Standard][8]->Palette, inf); + bmp->CopyPixelData(0, 0, Pixels, Width, Height, Height, 1, 0, translationtables[TRANSLATION_Standard][8]->Palette); return 0; } diff --git a/src/textures/formats/tgatexture.cpp b/src/textures/formats/tgatexture.cpp index 9416f6398..111e3e473 100644 --- a/src/textures/formats/tgatexture.cpp +++ b/src/textures/formats/tgatexture.cpp @@ -80,7 +80,7 @@ public: FTGATexture (int lumpnum, TGAHeader *); 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; protected: @@ -396,11 +396,11 @@ TArray FTGATexture::Get8BitPixels(bool alphatex) //=========================================================================== // -// FTGATexture::CopyTrueColorPixels +// FTGATexture::CopyPixels // //=========================================================================== -int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +int FTGATexture::CopyPixels(FBitmap *bmp) { PalEntry pe[256]; auto lump = Wads.OpenLumpReader (SourceLump); @@ -490,7 +490,7 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo switch (hdr.img_type & 7) { case 1: // paletted - bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe, inf); + bmp->CopyPixelData(0, 0, ptr, Width, Height, step_x, Pitch, 0, pe); break; case 2: // RGB @@ -498,21 +498,21 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo { case 15: case 16: - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_RGB555, inf); + bmp->CopyPixelDataRGB(0, 0, ptr, Width, Height, step_x, Pitch, 0, CF_RGB555); break; case 24: - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR, inf); + bmp->CopyPixelDataRGB(0, 0, ptr, Width, Height, step_x, Pitch, 0, CF_BGR); break; case 32: if ((hdr.img_desc&15)!=8) // 32 bits without a valid alpha channel { - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGR, inf); + bmp->CopyPixelDataRGB(0, 0, ptr, Width, Height, step_x, Pitch, 0, CF_BGR); } else { - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_BGRA, inf); + bmp->CopyPixelDataRGB(0, 0, ptr, Width, Height, step_x, Pitch, 9, CF_BGRA); transval = -1; } break; @@ -527,11 +527,11 @@ int FTGATexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo { case 8: for(int i=0;i<256;i++) pe[i]=PalEntry(255,i,i,i); // gray map - bmp->CopyPixelData(x, y, ptr, Width, Height, step_x, Pitch, rotate, pe, inf); + bmp->CopyPixelData(0, 0, ptr, Width, Height, step_x, Pitch, 0, pe); break; case 16: - bmp->CopyPixelDataRGB(x, y, ptr, Width, Height, step_x, Pitch, rotate, CF_I16, inf); + bmp->CopyPixelDataRGB(0, 0, ptr, Width, Height, step_x, Pitch, 0, CF_I16); break; default: diff --git a/src/textures/hires/hirestex.cpp b/src/textures/hires/hirestex.cpp index dae7654a0..7f65341ea 100644 --- a/src/textures/hires/hirestex.cpp +++ b/src/textures/hires/hirestex.cpp @@ -381,8 +381,10 @@ unsigned char *FTexture::LoadHiresTexture(int *width, int *height) memset(buffer, 0, w * (h + 1) * 4); FBitmap bmp(buffer, w * 4, w, h); + int trans; + auto Pixels = HiresTexture->GetBgraBitmap(nullptr, &trans); + bmp.Blit(0, 0, Pixels); - int trans = HiresTexture->CopyTrueColorPixels(&bmp, 0, 0); HiresTexture->CheckTrans(buffer, w*h, trans); if (bHiresHasColorKey) diff --git a/src/textures/skyboxtexture.cpp b/src/textures/skyboxtexture.cpp index 6a3572b03..2d165d46c 100644 --- a/src/textures/skyboxtexture.cpp +++ b/src/textures/skyboxtexture.cpp @@ -60,9 +60,9 @@ TArray FSkyBox::Get8BitPixels(bool alphatex) // //----------------------------------------------------------------------------- -int FSkyBox::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +int FSkyBox::CopyPixels(FBitmap *bmp) { - if (faces[0]) return faces[0]->CopyTrueColorPixels(bmp, x, y, rotate, inf); + if (faces[0]) return faces[0]->CopyPixels(bmp); return 0; } diff --git a/src/textures/skyboxtexture.h b/src/textures/skyboxtexture.h index 0dec6aa54..cbdbdb0e6 100644 --- a/src/textures/skyboxtexture.h +++ b/src/textures/skyboxtexture.h @@ -17,7 +17,7 @@ public: FSkyBox(const char *name = nullptr); TArray Get8BitPixels(bool alphatex); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf); + int CopyPixels(FBitmap *bmp); bool UseBasePalette(); void Unload (); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index e1630a11c..87aa95c19 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -421,7 +421,7 @@ void FTexture::FlipNonSquareBlockRemap (uint8_t *dst, const uint8_t *src, int x, //=========================================================================== // -// FTexture::CopyTrueColorPixels +// FTexture::CopyPixels // // this is the generic case that can handle // any properly implemented texture for software rendering. @@ -431,29 +431,32 @@ void FTexture::FlipNonSquareBlockRemap (uint8_t *dst, const uint8_t *src, int x, // //=========================================================================== -int FTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf) +int FTexture::CopyPixels(FBitmap *bmp) { PalEntry *palette = screen->GetPalette(); for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values auto ppix = Get8BitPixels(false); // should use composition cache - bmp->CopyPixelData(x, y, ppix.Data(), Width, Height, Height, 1, rotate, palette, inf); + bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, palette, nullptr); for(int i=1;i<256;i++) palette[i].a = 0; return 0; } -int FTexture::CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf) +int FTexture::CopyTranslatedPixels(FBitmap *bmp, PalEntry *remap) { auto ppix = Get8BitPixels(false); // should use composition cache - bmp->CopyPixelData(x, y, ppix.Data(), Width, Height, Height, 1, rotate, remap, inf); + bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, remap, nullptr); return 0; } -FBitmap FTexture::GetBgraBitmap(PalEntry *remap) +FBitmap FTexture::GetBgraBitmap(PalEntry *remap, int *ptrans) { FBitmap bmp; + int trans; + bmp.Create(GetWidth(), GetHeight()); - if (!remap) CopyTrueColorPixels(&bmp, 0, 0, 0, nullptr); - else CopyTrueColorTranslated(&bmp, 0, 0, 0, remap, nullptr); + if (!remap) trans = CopyPixels(&bmp); + else trans = CopyTranslatedPixels(&bmp, remap); + if (ptrans) *ptrans = trans; return bmp; } @@ -532,11 +535,9 @@ PalEntry FTexture::GetSkyCapColor(bool bottom) { bSWSkyColorDone = true; - FBitmap bitmap; - bitmap.Create(GetWidth(), GetHeight()); - CopyTrueColorPixels(&bitmap, 0, 0); - int w = GetWidth(); - int h = GetHeight(); + FBitmap bitmap = GetBgraBitmap(nullptr); + int w = bitmap.GetWidth(); + int h = bitmap.GetHeight(); const uint32_t *buffer = (const uint32_t *)bitmap.GetPixels(); if (buffer) @@ -938,25 +939,25 @@ unsigned char * FTexture::CreateTexBuffer(int translation, int & w, int & h, int W = w = GetWidth() + 2 * exx; H = h = GetHeight() + 2 * exx; - buffer = new unsigned char[W*(H + 1) * 4]; memset(buffer, 0, W * (H + 1) * 4); + auto remap = translation <= 0? nullptr : FUniquePalette::GetPalette(translation); FBitmap bmp(buffer, W * 4, W, H); - if (translation <= 0) + int trans; + auto Pixels = GetBgraBitmap(remap, &trans); + bmp.Blit(exx, exx, Pixels); + + if (remap == nullptr) { - int trans = CopyTrueColorPixels(&bmp, exx, exx, 0, nullptr); CheckTrans(buffer, W*H, trans); isTransparent = bTranslucent; } else { - // When using translations everything must be mapped to the base palette. - // so use CopyTrueColorTranslated - CopyTrueColorTranslated(&bmp, exx, exx, 0, FUniquePalette::GetPalette(translation)); isTransparent = 0; - // This is not conclusive for setting the texture's transparency info. + // A translated image is not conclusive for setting the texture's transparency info. } if (flags & CTF_ProcessData) diff --git a/src/textures/textures.h b/src/textures/textures.h index 10caf1bac..ec609e641 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -301,7 +301,7 @@ public: // Returns the whole texture, stored in column-major order virtual TArray Get8BitPixels(bool alphatex); - /*virtual*/ FBitmap GetBgraBitmap(PalEntry *remap); + /*virtual*/ FBitmap GetBgraBitmap(PalEntry *remap, int *trans = nullptr); public: static void FlipSquareBlock (uint8_t *block, int x, int y); @@ -388,8 +388,9 @@ protected: // Returns true if GetPixelsBgra includes mipmaps virtual bool Mipmapped() { return true; } - virtual int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate=0, FCopyInfo *inf = NULL); - virtual int CopyTrueColorTranslated(FBitmap *bmp, int x, int y, int rotate, PalEntry *remap, FCopyInfo *inf = NULL); + virtual int CopyPixels(FBitmap *bmp); + int CopyTranslatedPixels(FBitmap *bmp, PalEntry *remap); + virtual bool UseBasePalette(); virtual FTexture *GetRedirect(); diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 6b6ce6aef..23876289e 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -105,8 +105,8 @@ extern void LayoutMainWindow(HWND hWnd, HWND pane); static void CalculateCPUSpeed(); -static HCURSOR CreateCompatibleCursor(FTexture *cursorpic); -static HCURSOR CreateAlphaCursor(FTexture *cursorpic); +static HCURSOR CreateCompatibleCursor(FBitmap &cursorpic, int leftofs, int topofs); +static HCURSOR CreateAlphaCursor(FBitmap &cursorpic, int leftofs, int topofs); static HCURSOR CreateBitmapCursor(int xhot, int yhot, HBITMAP and_mask, HBITMAP color_mask); static void DestroyCustomCursor(); @@ -917,19 +917,22 @@ bool I_SetCursor(FTexture *cursorpic) { HCURSOR cursor; -#if 0 - if (cursorpic != NULL && cursorpic->UseType != ETextureType::Null) + if (cursorpic != NULL && cursorpic->isValid()) { - // Must be no larger than 32x32. - if (cursorpic->GetWidth() > 32 || cursorpic->GetHeight() > 32) + auto image = cursorpic->GetBgraBitmap(nullptr); + // Must be no larger than 32x32. (is this still necessary? + if (image.GetWidth() > 32 || image.GetHeight() > 32) { return false; } + // Fixme: This should get a raw image, not a texture. (Once raw images get implemented.) + int lo = cursorpic->GetDisplayLeftOffset(); + int to = cursorpic->GetDisplayTopOffset(); - cursor = CreateAlphaCursor(cursorpic); + cursor = CreateAlphaCursor(image, lo, to); if (cursor == NULL) { - cursor = CreateCompatibleCursor(cursorpic); + cursor = CreateCompatibleCursor(image, lo, to); } if (cursor == NULL) { @@ -941,7 +944,6 @@ bool I_SetCursor(FTexture *cursorpic) atterm(DestroyCustomCursor); } else -#endif { DestroyCustomCursor(); cursor = LoadCursor(NULL, IDC_ARROW); @@ -975,11 +977,10 @@ bool I_SetCursor(FTexture *cursorpic) // //========================================================================== -static HCURSOR CreateCompatibleCursor(FTexture *cursorpic) +static HCURSOR CreateCompatibleCursor(FBitmap &bmp, int leftofs, int topofs) { -#if 0 - int picwidth = cursorpic->GetWidth(); - int picheight = cursorpic->GetHeight(); + int picwidth = bmp.GetWidth(); + int picheight = bmp.GetHeight(); // Create bitmap masks for the cursor from the texture. HDC dc = GetDC(NULL); @@ -1004,12 +1005,7 @@ static HCURSOR CreateCompatibleCursor(FTexture *cursorpic) SelectObject(xor_mask_dc, GetStockObject(BLACK_BRUSH)); Rectangle(xor_mask_dc, 0, 0, 32, 32); - FBitmap bmp; - const uint8_t *pixels; - - bmp.Create(picwidth, picheight); - cursorpic->CopyTrueColorPixels(&bmp, 0, 0); - pixels = bmp.GetPixels(); + const uint8_t *pixels = bmp.GetPixels(); // Copy color data from the source texture to the cursor bitmaps. for (int y = 0; y < picheight; ++y) @@ -1028,10 +1024,7 @@ static HCURSOR CreateCompatibleCursor(FTexture *cursorpic) DeleteDC(xor_mask_dc); // Create the cursor from the bitmaps. - return CreateBitmapCursor(cursorpic->GetLeftOffset(0), cursorpic->GetTopOffset(0), and_mask, xor_mask); -#else - return nullptr; -#endif + return CreateBitmapCursor(leftofs, topofs, and_mask, xor_mask); } //========================================================================== @@ -1042,9 +1035,8 @@ static HCURSOR CreateCompatibleCursor(FTexture *cursorpic) // //========================================================================== -static HCURSOR CreateAlphaCursor(FTexture *cursorpic) +static HCURSOR CreateAlphaCursor(FBitmap &source, int leftofs, int topofs) { -#if 0 HDC dc; BITMAPV5HEADER bi; HBITMAP color, mono; @@ -1093,11 +1085,11 @@ static HCURSOR CreateAlphaCursor(FTexture *cursorpic) // Copy cursor to the color bitmap. Note that GDI bitmaps are upside down compared // to normal conventions, so we create the FBitmap pointing at the last row and use - // a negative pitch so that CopyTrueColorPixels will use GDI's orientation. + // a negative pitch so that Blit will use GDI's orientation. if (scale == 1) { FBitmap bmp((uint8_t *)bits + 31 * 32 * 4, -32 * 4, 32, 32); - cursorpic->CopyTrueColorPixels(&bmp, 0, 0); + bmp.Blit(0, 0, source); } else { @@ -1105,7 +1097,7 @@ static HCURSOR CreateAlphaCursor(FTexture *cursorpic) unscaled.Resize(32 * 32); for (int i = 0; i < 32 * 32; i++) unscaled[i] = 0; FBitmap bmp((uint8_t *)&unscaled[0] + 31 * 32 * 4, -32 * 4, 32, 32); - cursorpic->CopyTrueColorPixels(&bmp, 0, 0); + bmp.Blit(0, 0, source); uint32_t *scaled = (uint32_t*)bits; for (int y = 0; y < 32 * scale; y++) { @@ -1116,10 +1108,7 @@ static HCURSOR CreateAlphaCursor(FTexture *cursorpic) } } - return CreateBitmapCursor(cursorpic->GetLeftOffset(0) * scale, cursorpic->GetTopOffset(0) * scale, mono, color); -#else - return nullptr; -#endif + return CreateBitmapCursor(leftofs * scale, topofs * scale, mono, color); } //==========================================================================