- code cleanup

This commit is contained in:
Christoph Oelckers 2023-08-25 20:05:52 +02:00
parent afecb1ca0f
commit ccd39d6df7
13 changed files with 60 additions and 33 deletions

View file

@ -422,7 +422,7 @@ void FFont::ReadSheetFont(std::vector<FileSys::FolderEntry> &folderdata, int wid
FBitmap* sheetimg = &sheetBitmaps[sheetBitmaps.Reserve(1)]; FBitmap* sheetimg = &sheetBitmaps[sheetBitmaps.Reserve(1)];
sheetimg->Create(tex->GetTexelWidth(), tex->GetTexelHeight()); 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++) for (int y = 0; y < numtex_y; y++)
{ {

View file

@ -35,5 +35,3 @@ extern TArray<TranslationMap> TranslationLookup;
extern TArray<PalEntry> TranslationColors; extern TArray<PalEntry> TranslationColors;
class FImageSource; class FImageSource;
void RecordTextureColors (FImageSource *pic, uint32_t *usedcolors);

View file

@ -25,9 +25,9 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
*/ */
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
#include <string.h>
#include "animlib.h" #include "animlib.h"
#include "m_swap.h" #include "m_swap.h"
#include "m_alloc.h"
//**************************************************************************** //****************************************************************************
// //

View file

@ -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); a = TSrc::A(pin, tr, tg, tb);
if (TBlend::ProcessAlpha0() || a) if (TBlend::ProcessAlpha0() || a)
{ {
int gray = clamp<int>(TSrc::Gray(pin),0,255); int gray = std::clamp<int>(TSrc::Gray(pin),0,255);
PalEntry pe = cm->GrayscaleToColor[gray]; PalEntry pe = cm->GrayscaleToColor[gray];
TBlend::OpC(pout[TDest::RED], pe.r , a, inf); TBlend::OpC(pout[TDest::RED], pe.r , a, inf);

View file

@ -36,8 +36,6 @@
#ifndef __BITMAP_H__ #ifndef __BITMAP_H__
#define __BITMAP_H__ #define __BITMAP_H__
#include "basics.h"
#include "palentry.h" #include "palentry.h"
struct FCopyInfo; struct FCopyInfo;
@ -320,9 +318,9 @@ struct cCMYK
struct cYCbCr 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 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 clamp((int)(p[0] - 0.34414 * (int(p[1] - 0x80)) - 0.71414 * (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 clamp((int)(p[0] + 1.77200 * (int(p[1]) - 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 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; } 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 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 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; } static __forceinline bool ProcessAlpha0() { return false; }
}; };
@ -483,21 +481,21 @@ struct bBlend
struct bAdd struct bAdd
{ {
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = min<int>((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<int>((d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 255); }
static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; } static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; }
static __forceinline bool ProcessAlpha0() { return false; } static __forceinline bool ProcessAlpha0() { return false; }
}; };
struct bSubtract struct bSubtract
{ {
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = max<int>((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<int>((d*BLENDUNIT - s*i->alpha) >> BLENDBITS, 0); }
static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; } static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; }
static __forceinline bool ProcessAlpha0() { return false; } static __forceinline bool ProcessAlpha0() { return false; }
}; };
struct bReverseSubtract struct bReverseSubtract
{ {
static __forceinline void OpC(uint8_t &d, uint8_t s, uint8_t a, FCopyInfo *i) { d = max<int>((-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<int>((-d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 0); }
static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; } static __forceinline void OpA(uint8_t &d, uint8_t s, FCopyInfo *i) { d = s; }
static __forceinline bool ProcessAlpha0() { return false; } static __forceinline bool ProcessAlpha0() { return false; }
}; };

View file

@ -67,7 +67,7 @@ FBrightmapTexture::FBrightmapTexture (FImageSource *source)
int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion, int frame) int FBrightmapTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette); SourcePic->CopyTranslatedPixels(bmp, GPalette.GlobalBrightmap.Palette, frame);
return 0; return 0;
} }

View file

@ -200,7 +200,7 @@ PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion, int frame)
int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion, int frame) int FIMGZTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); if (!isalpha) return FImageSource::CopyPixels(bmp, conversion, frame);
else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette); else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette, frame);
} }

View file

@ -41,6 +41,17 @@
#include "m_swap.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
};
// posts are runs of non masked source pixels // posts are runs of non masked source pixels
struct column_t struct column_t
{ {
@ -266,8 +277,8 @@ PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion, int frame)
int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion, int frame) int FPatchTexture::CopyPixels(FBitmap *bmp, int conversion, int frame)
{ {
if (!isalpha) return FImageSource::CopyPixels(bmp, conversion); if (!isalpha) return FImageSource::CopyPixels(bmp, conversion, frame);
else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette); else return CopyTranslatedPixels(bmp, GPalette.GrayscaleMap.Palette, frame);
} }
//========================================================================== //==========================================================================

View file

@ -40,6 +40,16 @@
#include "image.h" #include "image.h"
#include "m_swap.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) 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 else
{ {
auto lump = fileSystem.ReadFile(SourceLump); auto lump = fileSystem.ReadFile(SourceLump);

View file

@ -5,20 +5,24 @@
#include "bitmap.h" #include "bitmap.h"
#include "memarena.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; class FImageSource;
using PrecacheInfo = TMap<int, std::pair<int, int>>; using PrecacheInfo = TMap<int, std::pair<int, int>>;
extern FMemArena ImageArena; extern FMemArena ImageArena;
// Doom patch format header // Pixel store wrapper that can either own the pixels itself or refer to an external store.
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
};
struct PalettedPixels struct PalettedPixels
{ {
friend class FImageSource; friend class FImageSource;

View file

@ -42,11 +42,13 @@
#include <malloc.h> // for alloca() #include <malloc.h> // for alloca()
#endif #endif
#include "basics.h"
#include "m_crc32.h" #include "m_crc32.h"
#include "m_swap.h" #include "m_swap.h"
#if __has_include("c_cvars.h")
#include "c_cvars.h" #include "c_cvars.h"
#endif
#include "m_png.h" #include "m_png.h"
#include "basics.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
@ -103,6 +105,8 @@ static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const uint8_
// PUBLIC DATA DEFINITIONS ------------------------------------------------- // 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) CUSTOM_CVAR(Int, png_level, 5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{ {
if (self < 0) if (self < 0)
@ -111,6 +115,10 @@ CUSTOM_CVAR(Int, png_level, 5, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
self = 9; self = 9;
} }
CVAR(Float, png_gamma, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) 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 ------------------------------------------------ // PRIVATE DATA DEFINITIONS ------------------------------------------------

View file

@ -37,7 +37,6 @@
#include "zstring.h" #include "zstring.h"
#include "files.h" #include "files.h"
#include "palentry.h" #include "palentry.h"
#include "basics.h"
// Screenshot buffer image data types // Screenshot buffer image data types
enum ESSType enum ESSType

View file

@ -45,7 +45,6 @@
#include "floatrect.h" #include "floatrect.h"
#include "refcounted.h" #include "refcounted.h"
typedef TMap<int, bool> SpriteHits;
class FImageSource; class FImageSource;
class FGameTexture; class FGameTexture;
class IHardwareTexture; class IHardwareTexture;