From ccd39d6df75328d50832ffdc2b28ff9ca3bd4860 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 25 Aug 2023 20:05:52 +0200 Subject: [PATCH] - code cleanup --- src/common/fonts/font.cpp | 2 +- src/common/fonts/fontinternals.h | 2 -- src/common/textures/animlib.cpp | 2 +- src/common/textures/bitmap.cpp | 2 +- src/common/textures/bitmap.h | 16 ++++++------- .../textures/formats/brightmaptexture.cpp | 2 +- src/common/textures/formats/imgztexture.cpp | 4 ++-- src/common/textures/formats/patchtexture.cpp | 15 ++++++++++-- .../textures/formats/rawpagetexture.cpp | 12 +++++++++- src/common/textures/image.h | 24 +++++++++++-------- src/common/textures/m_png.cpp | 10 +++++++- src/common/textures/m_png.h | 1 - src/common/textures/textures.h | 1 - 13 files changed, 60 insertions(+), 33 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 1714d78b4..ed7b871c2 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -422,7 +422,7 @@ void FFont::ReadSheetFont(std::vector &folderdata, int wid FBitmap* sheetimg = &sheetBitmaps[sheetBitmaps.Reserve(1)]; sheetimg->Create(tex->GetTexelWidth(), tex->GetTexelHeight()); - tex->GetTexture()->GetImage()->CopyPixels(sheetimg, FImageSource::normal); + tex->GetTexture()->GetImage()->CopyPixels(sheetimg, FImageSource::normal, 0); for (int y = 0; y < numtex_y; y++) { diff --git a/src/common/fonts/fontinternals.h b/src/common/fonts/fontinternals.h index b74750c57..149f9ab9f 100644 --- a/src/common/fonts/fontinternals.h +++ b/src/common/fonts/fontinternals.h @@ -35,5 +35,3 @@ extern TArray TranslationLookup; extern TArray TranslationColors; class FImageSource; - -void RecordTextureColors (FImageSource *pic, uint32_t *usedcolors); diff --git a/src/common/textures/animlib.cpp b/src/common/textures/animlib.cpp index 1b31244f3..cc83f87ba 100644 --- a/src/common/textures/animlib.cpp +++ b/src/common/textures/animlib.cpp @@ -25,9 +25,9 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) */ //------------------------------------------------------------------------- +#include #include "animlib.h" #include "m_swap.h" -#include "m_alloc.h" //**************************************************************************** // diff --git a/src/common/textures/bitmap.cpp b/src/common/textures/bitmap.cpp index b685b0325..0a0553c3c 100644 --- a/src/common/textures/bitmap.cpp +++ b/src/common/textures/bitmap.cpp @@ -118,7 +118,7 @@ void iCopyColors(uint8_t *pout, const uint8_t *pin, int count, int step, FCopyIn a = TSrc::A(pin, tr, tg, tb); if (TBlend::ProcessAlpha0() || a) { - int gray = clamp(TSrc::Gray(pin),0,255); + int gray = std::clamp(TSrc::Gray(pin),0,255); PalEntry pe = cm->GrayscaleToColor[gray]; TBlend::OpC(pout[TDest::RED], pe.r , a, inf); diff --git a/src/common/textures/bitmap.h b/src/common/textures/bitmap.h index ae5ede88f..de9850c27 100644 --- a/src/common/textures/bitmap.h +++ b/src/common/textures/bitmap.h @@ -36,8 +36,6 @@ #ifndef __BITMAP_H__ #define __BITMAP_H__ -#include "basics.h" - #include "palentry.h" struct FCopyInfo; @@ -320,9 +318,9 @@ struct cCMYK struct cYCbCr { - static __forceinline unsigned char R(const unsigned char * p) { return clamp((int)(p[0] + 1.40200 * (int(p[2]) - 0x80)), 0, 255); } - static __forceinline unsigned char G(const unsigned char * p) { return clamp((int)(p[0] - 0.34414 * (int(p[1] - 0x80)) - 0.71414 * (int(p[2]) - 0x80)), 0, 255); } - static __forceinline unsigned char B(const unsigned char * p) { return clamp((int)(p[0] + 1.77200 * (int(p[1]) - 0x80)), 0, 255); } + static __forceinline unsigned char R(const unsigned char * p) { return std::clamp((int)(p[0] + 1.40200 * (int(p[2]) - 0x80)), 0, 255); } + static __forceinline unsigned char G(const unsigned char * p) { return std::clamp((int)(p[0] - 0.34414 * (int(p[1] - 0x80)) - 0.71414 * (int(p[2]) - 0x80)), 0, 255); } + static __forceinline unsigned char B(const unsigned char * p) { return std::clamp((int)(p[0] + 1.77200 * (int(p[1]) - 0x80)), 0, 255); } static __forceinline unsigned char A(const unsigned char * p, uint8_t x, uint8_t y, uint8_t z) { return 255; } static __forceinline int Gray(const unsigned char * p) { return (R(p) * 77 + G(p) * 143 + B(p) * 36) >> 8; } }; @@ -470,7 +468,7 @@ struct bCopyAlpha struct bOverlay { static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = (s*a + d*(255-a))/255; } - static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = max(s,d); } + static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = std::max(s,d); } static __forceinline bool ProcessAlpha0() { return false; } }; @@ -483,21 +481,21 @@ struct bBlend struct bAdd { - static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = min((d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 255); } + static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = std::min((d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 255); } static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; } static __forceinline bool ProcessAlpha0() { return false; } }; struct bSubtract { - static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = max((d*BLENDUNIT - s*i->alpha) >> BLENDBITS, 0); } + static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = std::max((d*BLENDUNIT - s*i->alpha) >> BLENDBITS, 0); } static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; } static __forceinline bool ProcessAlpha0() { return false; } }; struct bReverseSubtract { - static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = max((-d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 0); } + static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = std::max((-d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 0); } static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; } static __forceinline bool ProcessAlpha0() { return false; } }; diff --git a/src/common/textures/formats/brightmaptexture.cpp b/src/common/textures/formats/brightmaptexture.cpp index 43499f17e..262a520f6 100644 --- a/src/common/textures/formats/brightmaptexture.cpp +++ b/src/common/textures/formats/brightmaptexture.cpp @@ -67,7 +67,7 @@ FBrightmapTexture::FBrightmapTexture (FImageSource *source) int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion, int frame) { - SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette); + SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette, frame); return 0; } diff --git a/src/common/textures/formats/imgztexture.cpp b/src/common/textures/formats/imgztexture.cpp index b5deaccac..831733a2b 100644 --- a/src/common/textures/formats/imgztexture.cpp +++ b/src/common/textures/formats/imgztexture.cpp @@ -200,7 +200,7 @@ PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion, int frame) int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion, int frame) { - if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); - else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette); + if (!isalpha) return FImageSource::CopyPixels(bmp, conversion, frame); + else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette, frame); } diff --git a/src/common/textures/formats/patchtexture.cpp b/src/common/textures/formats/patchtexture.cpp index a6f70222f..0b6266a58 100644 --- a/src/common/textures/formats/patchtexture.cpp +++ b/src/common/textures/formats/patchtexture.cpp @@ -41,6 +41,17 @@ #include "m_swap.h" +// Doom patch format header +struct patch_t +{ + int16_t width; // bounding box size + int16_t height; + int16_t leftoffset; // pixels to the left of origin + int16_t topoffset; // pixels below the origin + uint32_t columnofs[1]; // only [width] used +}; + + // posts are runs of non masked source pixels struct column_t { @@ -266,8 +277,8 @@ PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion, int frame) int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion, int frame) { - if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); - else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette); + if (!isalpha) return FImageSource::CopyPixels(bmp, conversion, frame); + else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette, frame); } //========================================================================== diff --git a/src/common/textures/formats/rawpagetexture.cpp b/src/common/textures/formats/rawpagetexture.cpp index b185f5ffc..cca68dd07 100644 --- a/src/common/textures/formats/rawpagetexture.cpp +++ b/src/common/textures/formats/rawpagetexture.cpp @@ -40,6 +40,16 @@ #include "image.h" #include "m_swap.h" +// Doom patch format header +struct patch_t +{ + int16_t width; // bounding box size + int16_t height; + int16_t leftoffset; // pixels to the left of origin + int16_t topoffset; // pixels below the origin + uint32_t columnofs[1]; // only [width] used +}; + //========================================================================== // @@ -201,7 +211,7 @@ PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion, int frame) 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, frame); else { auto lump = fileSystem.ReadFile(SourceLump); diff --git a/src/common/textures/image.h b/src/common/textures/image.h index f9e761a20..72b5ca9df 100644 --- a/src/common/textures/image.h +++ b/src/common/textures/image.h @@ -5,20 +5,24 @@ #include "bitmap.h" #include "memarena.h" +#ifndef MAKE_ID +#ifndef __BIG_ENDIAN__ +#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24))) +#else +#define MAKE_ID(a,b,c,d) ((uint32_t)((d)|((c)<<8)|((b)<<16)|((a)<<24))) +#endif +#endif + +using std::min; +using std::max; +using std::clamp; + + class FImageSource; using PrecacheInfo = TMap>; extern FMemArena ImageArena; -// Doom patch format header -struct patch_t -{ - int16_t width; // bounding box size - int16_t height; - int16_t leftoffset; // pixels to the left of origin - int16_t topoffset; // pixels below the origin - uint32_t columnofs[1]; // only [width] used -}; - +// Pixel store wrapper that can either own the pixels itself or refer to an external store. struct PalettedPixels { friend class FImageSource; diff --git a/src/common/textures/m_png.cpp b/src/common/textures/m_png.cpp index 8467a5d42..07cc1ab74 100644 --- a/src/common/textures/m_png.cpp +++ b/src/common/textures/m_png.cpp @@ -42,11 +42,13 @@ #include // for alloca() #endif -#include "basics.h" #include "m_crc32.h" #include "m_swap.h" +#if __has_include("c_cvars.h") #include "c_cvars.h" +#endif #include "m_png.h" +#include "basics.h" // MACROS ------------------------------------------------------------------ @@ -103,6 +105,8 @@ static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const uint8_ // PUBLIC DATA DEFINITIONS ------------------------------------------------- +// allow this to compile without CVARs. +#if __has_include("c_cvars.h") CUSTOM_CVAR(Int, png_level, 5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) { if (self < 0) @@ -111,6 +115,10 @@ CUSTOM_CVAR(Int, png_level, 5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) self = 9; } CVAR(Float, png_gamma, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +#else +const int png_level = 5; +const float png_gamma = 0; +#endif // PRIVATE DATA DEFINITIONS ------------------------------------------------ diff --git a/src/common/textures/m_png.h b/src/common/textures/m_png.h index f65de4c0d..426e4d982 100644 --- a/src/common/textures/m_png.h +++ b/src/common/textures/m_png.h @@ -37,7 +37,6 @@ #include "zstring.h" #include "files.h" #include "palentry.h" -#include "basics.h" // Screenshot buffer image data types enum ESSType diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 164aa79b8..6aa6c84a5 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -45,7 +45,6 @@ #include "floatrect.h" #include "refcounted.h" -typedef TMap SpriteHits; class FImageSource; class FGameTexture; class IHardwareTexture;