- backend update from GZDoom.

This commit is contained in:
Christoph Oelckers 2023-01-07 19:30:49 +01:00
parent 5952b79af5
commit 905a9bfeae
44 changed files with 360 additions and 130 deletions

View file

@ -683,7 +683,7 @@ void FSerializer::ReadObjects(bool hubtravel)
{
r->mObjects.Clamp(size); // close all inner objects.
// In case something in here throws an error, let's continue and deal with it later.
Printf(PRINT_NONOTIFY, TEXTCOLOR_RED "'%s'\n while restoring %s\n", err.GetMessage(), obj ? obj->GetClass()->TypeName.GetChars() : "invalid object");
Printf(PRINT_NONOTIFY | PRINT_BOLD, TEXTCOLOR_RED "'%s'\n while restoring %s\n", err.GetMessage(), obj ? obj->GetClass()->TypeName.GetChars() : "invalid object");
mErrors++;
}
}

View file

@ -1696,6 +1696,6 @@ CCMD(fs_dir)
auto fnid = fileSystem.GetResourceId(i);
auto length = fileSystem.FileLength(i);
bool hidden = fileSystem.FindFile(fn1) != i;
Printf(PRINT_NONOTIFY, "%s%-64s %-15s (%5d) %10d %s %s\n", hidden ? TEXTCOLOR_RED : TEXTCOLOR_UNTRANSLATED, fn1, fns, fnid, length, container, hidden ? "(h)" : "");
Printf(PRINT_HIGH | PRINT_NONOTIFY, "%s%-64s %-15s (%5d) %10d %s %s\n", hidden ? TEXTCOLOR_RED : TEXTCOLOR_UNTRANSLATED, fn1, fns, fnid, length, container, hidden ? "(h)" : "");
}
}

View file

@ -59,6 +59,7 @@
#include "fontinternals.h"
TArray<FBitmap> sheetBitmaps;
//==========================================================================
@ -367,10 +368,32 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
}
}
class FSheetTexture : public FImageSource
{
unsigned baseSheet;
int X, Y;
public:
FSheetTexture(unsigned source, int x, int y, int width, int height)
{
baseSheet = source;
Width = width;
Height = height;
X = x;
Y = y;
}
int CopyPixels(FBitmap* dest, int conversion)
{
auto& pic = sheetBitmaps[baseSheet];
dest->CopyPixelDataRGB(0, 0, pic.GetPixels() + 4 * (X + pic.GetWidth() * Y), Width, Height, 4, pic.GetWidth() * 4, 0, CF_BGRA);
return 0;
}
};
void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
{
// all valid lumps must be named with a hex number that represents the Unicode character index for its first character,
TArray<TexPartBuild> part(1, true);
TMap<int, FGameTexture*> charMap;
int minchar = INT_MAX;
int maxchar = INT_MIN;
@ -391,14 +414,15 @@ void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height
if (minchar > position) minchar = int(position);
if (maxchar < maxinsheet) maxchar = maxinsheet;
FBitmap* sheetimg = &sheetBitmaps[sheetBitmaps.Reserve(1)];
sheetimg->Create(tex->GetTexelWidth(), tex->GetTexelHeight());
tex->GetTexture()->GetImage()->CopyPixels(sheetimg, FImageSource::normal);
for (int y = 0; y < numtex_y; y++)
{
for (int x = 0; x < numtex_x; x++)
{
part[0].OriginX = -width * x;
part[0].OriginY = -height * y;
part[0].TexImage = static_cast<FImageTexture*>(tex->GetTexture());
FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false);
auto image = new FSheetTexture(sheetBitmaps.Size() - 1, x * width, y * width, width, height);
FImageTexture *imgtex = new FImageTexture(image);
auto gtex = MakeGameTexture(imgtex, nullptr, ETextureType::FontChar);
gtex->SetWorldPanning(true);

View file

@ -109,7 +109,7 @@ class FHexFontChar : public FImageSource
public:
FHexFontChar(uint8_t *sourcedata, int swidth, int width, int height);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap* bmp, int conversion);
protected:
@ -144,10 +144,10 @@ FHexFontChar::FHexFontChar (uint8_t *sourcedata, int swidth, int width, int heig
//
//==========================================================================
TArray<uint8_t> FHexFontChar::CreatePalettedPixels(int)
PalettedPixels FHexFontChar::CreatePalettedPixels(int)
{
int destSize = Width * Height;
TArray<uint8_t> Pixels(destSize, true);
PalettedPixels Pixels(destSize);
uint8_t *dest_p = Pixels.Data();
const uint8_t *src_p = SourceData;
@ -190,7 +190,7 @@ class FHexFontChar2 : public FHexFontChar
public:
FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int height);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap* bmp, int conversion);
};
@ -216,10 +216,10 @@ FHexFontChar2::FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int hei
//
//==========================================================================
TArray<uint8_t> FHexFontChar2::CreatePalettedPixels(int)
PalettedPixels FHexFontChar2::CreatePalettedPixels(int)
{
int destSize = Width * Height;
TArray<uint8_t> Pixels(destSize, true);
PalettedPixels Pixels(destSize);
uint8_t *dest_p = Pixels.Data();
assert(SourceData);

View file

@ -73,6 +73,7 @@ static int TranslationMapCompare (const void *a, const void *b);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern int PrintColors[];
extern TArray<FBitmap> sheetBitmaps;
// PUBLIC DATA DEFINITIONS -------------------------------------------------
FFont* SmallFont, * SmallFont2, * BigFont, * BigUpper, * ConFont, * IntermissionFont, * NewConsoleFont, * NewSmallFont,
@ -863,6 +864,7 @@ EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int
void V_InitFonts()
{
sheetBitmaps.Clear();
CreateLuminosityTranslationRanges();
V_InitCustomFonts();
@ -929,6 +931,7 @@ void V_ClearFonts()
}
FFont::FirstFont = nullptr;
AlternativeSmallFont = OriginalSmallFont = CurrentConsoleFont = NewSmallFont = NewConsoleFont = SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = nullptr;
sheetBitmaps.Clear();
}
//==========================================================================

View file

@ -208,7 +208,6 @@ protected:
friend void V_InitFonts();
};
extern FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont, *OriginalSmallFont, *AlternativeSmallFont, *OriginalBigFont, *AlternativeBigFont;
void V_InitFonts();

View file

@ -925,7 +925,7 @@ void M_Init (void)
catch (CVMAbortException &err)
{
err.MaybePrintMessage();
Printf(PRINT_NONOTIFY, "%s", err.stacktrace.GetChars());
Printf(PRINT_NONOTIFY | PRINT_BOLD, "%s", err.stacktrace.GetChars());
I_FatalError("Failed to initialize menus");
}
M_CreateMenus();

View file

@ -35,7 +35,6 @@ public:
{
mDataLump = -1;
mAnivLump = -1;
mDataLoaded = false;
dhead = NULL;
dpolys = NULL;
ahead = NULL;
@ -49,7 +48,6 @@ public:
private:
int mDataLump, mAnivLump;
bool mDataLoaded;
// raw data structures
struct d3dhead
@ -105,9 +103,10 @@ private:
int numFrames;
int numPolys;
int numGroups;
TArray<int> specialPolys; // for future model attachment support, unused for now
bool hasWeaponTriangle;
TArray<UE1Vertex> verts;
TArray<UE1Poly> polys;
TArray<UE1Group> groups;
//TArray<TRS> weapondata; // pseudo-bone generated from weapon triangle (not yet implemented)
};

View file

@ -165,13 +165,17 @@ void FUE1Model::LoadGeometry()
// populate poly groups (subdivided by texture number and type)
// this method minimizes searches in the group list as much as possible
// while still doing a single pass through the poly list
groups.Reset();
int curgroup = -1;
UE1Group Group;
hasWeaponTriangle = false;
int weapontri = -1;
for ( int i=0; i<numPolys; i++ )
{
// while we're at it, look for attachment triangles
// technically only one should exist, but we ain't following the specs 100% here
if ( dpolys[i].type&PT_WeaponTriangle ) specialPolys.Push(i);
// while we're at it, look for a weapon triangle
// (technically only one should exist)
if ( dpolys[i].type&PT_WeaponTriangle )
weapontri = i;
if ( curgroup == -1 )
{
// no group, create it
@ -201,25 +205,24 @@ void FUE1Model::LoadGeometry()
groups[curgroup].P.Push(i);
groups[curgroup].numPolys++;
}
// ... and it's finally done
mDataLoaded = true;
if ( weapontri != -1 )
{
// TODO: generate TRS array from special poly to interface as a pseudo-bone
hasWeaponTriangle = true;
}
}
void FUE1Model::UnloadGeometry()
{
mDataLoaded = false;
specialPolys.Reset();
numVerts = 0;
numFrames = 0;
numPolys = 0;
numGroups = 0;
for ( unsigned i=0; i<verts.Size(); i++ )
verts[i].P.Reset();
verts.Reset();
for ( int i=0; i<numPolys; i++ )
for ( unsigned i=0; i<polys.Size(); i++ )
polys[i].Normals.Reset();
polys.Reset();
for ( int i=0; i<numGroups; i++ )
for ( unsigned i=0; i<groups.Size(); i++ )
groups[i].P.Reset();
groups.Reset();
// do not unload groups themselves, they're needed for rendering
}
int FUE1Model::FindFrame(const char* name, bool nodefault)
@ -272,8 +275,7 @@ void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer )
{
if (GetVertexBuffer(renderer->GetType()))
return;
if ( !mDataLoaded )
LoadGeometry();
LoadGeometry();
int vsize = 0;
for ( int i=0; i<numGroups; i++ )
vsize += groups[i].numPolys*3;
@ -306,6 +308,7 @@ void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer )
}
}
vbuf->UnlockVertexBuffer();
UnloadGeometry(); // don't forget this, save precious RAM
}
void FUE1Model::AddSkins( uint8_t *hitlist, const FTextureID* surfaceskinids)
@ -320,5 +323,5 @@ void FUE1Model::AddSkins( uint8_t *hitlist, const FTextureID* surfaceskinids)
FUE1Model::~FUE1Model()
{
UnloadGeometry();
groups.Reset();
}

View file

@ -58,7 +58,7 @@ public:
FVoxelTexture(FVoxel *voxel);
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
protected:
FVoxel *SourceVox;
@ -84,10 +84,10 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox)
//
//===========================================================================
TArray<uint8_t> FVoxelTexture::CreatePalettedPixels(int conversion)
PalettedPixels FVoxelTexture::CreatePalettedPixels(int conversion)
{
// GetPixels gets called when a translated palette is used so we still need to implement it here.
TArray<uint8_t> Pixels(256, true);
PalettedPixels Pixels(256);
uint8_t *pp = SourceVox->Palette.Data();
if(pp != NULL)

View file

@ -548,7 +548,7 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE nothing, LPWSTR cmdline, int
_CrtSetDbgFlag (_CrtSetDbgFlag(0) | _CRTDBG_LEAK_CHECK_DF);
// Use this to break at a specific allocation number.
_crtBreakAlloc = 380659;
//_crtBreakAlloc = 227524;
#endif
int ret = DoMain (hInstance);

View file

@ -2718,6 +2718,75 @@ ExpEmit FxMultiAssign::Emit(VMFunctionBuilder *build)
return LocalVarContainer->Emit(build);
}
//==========================================================================
//
//
//
//==========================================================================
FxMultiAssignDecl::FxMultiAssignDecl(FArgumentList &base, FxExpression *right, const FScriptPosition &pos)
:FxExpression(EFX_MultiAssignDecl, pos)
{
Base = std::move(base);
Right = right;
}
//==========================================================================
//
//
//
//==========================================================================
FxMultiAssignDecl::~FxMultiAssignDecl()
{
SAFE_DELETE(Right);
}
//==========================================================================
//
//
//
//==========================================================================
FxExpression *FxMultiAssignDecl::Resolve(FCompileContext &ctx)
{
CHECKRESOLVED();
SAFE_RESOLVE(Right, ctx);
if (Right->ExprType != EFX_VMFunctionCall)
{
Right->ScriptPosition.Message(MSG_ERROR, "Function call expected on right side of multi-assigment");
delete this;
return nullptr;
}
auto VMRight = static_cast<FxVMFunctionCall *>(Right);
auto rets = VMRight->GetReturnTypes();
if (Base.Size() == 1)
{
Right->ScriptPosition.Message(MSG_ERROR, "Multi-assignment with only one element in function %s", VMRight->Function->SymbolName.GetChars());
delete this;
return nullptr;
}
if (rets.Size() < Base.Size())
{
Right->ScriptPosition.Message(MSG_ERROR, "Insufficient returns in function %s", VMRight->Function->SymbolName.GetChars());
delete this;
return nullptr;
}
FxSequence * DeclAndAssign = new FxSequence(ScriptPosition);
const unsigned int n = Base.Size();
for (unsigned int i = 0; i < n; i++)
{
assert(Base[i]->ExprType == EFX_Identifier);
DeclAndAssign->Add(new FxLocalVariableDeclaration(rets[i], ((FxIdentifier*)Base[i])->Identifier, nullptr, 0, Base[i]->ScriptPosition));
}
DeclAndAssign->Add(new FxMultiAssign(Base, Right, ScriptPosition));
Right = nullptr;
delete this;
return DeclAndAssign->Resolve(ctx);
}
//==========================================================================
//
//

View file

@ -294,6 +294,7 @@ enum EFxType
EFX_Super,
EFX_StackVariable,
EFX_MultiAssign,
EFX_MultiAssignDecl,
EFX_StaticArray,
EFX_StaticArrayVariable,
EFX_CVar,
@ -904,6 +905,17 @@ public:
ExpEmit Emit(VMFunctionBuilder *build);
};
class FxMultiAssignDecl : public FxExpression
{
FArgumentList Base;
FxExpression *Right;
public:
FxMultiAssignDecl(FArgumentList &base, FxExpression *right, const FScriptPosition &pos);
~FxMultiAssignDecl();
FxExpression *Resolve(FCompileContext&);
//ExpEmit Emit(VMFunctionBuilder *build); This node is transformed into Declarations + FxMultiAssign , so it won't ever be emitted itself
};
//==========================================================================
//
// FxAssignSelf

View file

@ -816,6 +816,15 @@ static void PrintAssignStmt(FLispString &out, const ZCC_TreeNode *node)
out.Close();
}
static void PrintAssignDeclStmt(FLispString &out, const ZCC_TreeNode *node)
{
ZCC_AssignDeclStmt *snode = (ZCC_AssignDeclStmt *)node;
out.Open("assign-stmt-decl");
PrintNodes(out, snode->Dests);
PrintNodes(out, snode->Sources);
out.Close();
}
static void PrintLocalVarStmt(FLispString &out, const ZCC_TreeNode *node)
{
ZCC_LocalVarStmt *snode = (ZCC_LocalVarStmt *)node;
@ -989,6 +998,7 @@ static const NodePrinterFunc TreeNodePrinter[] =
PrintSwitchStmt,
PrintCaseStmt,
PrintAssignStmt,
PrintAssignDeclStmt,
PrintLocalVarStmt,
PrintFuncParamDecl,
PrintConstantDef,

View file

@ -1840,6 +1840,7 @@ statement(X) ::= iteration_statement(X).
statement(X) ::= array_iteration_statement(X).
statement(X) ::= jump_statement(X).
statement(X) ::= assign_statement(A) SEMICOLON. { X = A; /*X-overwrites-A*/ }
statement(X) ::= assign_decl_statement(A) SEMICOLON.{ X = A; /*X-overwrites-A*/ }
statement(X) ::= local_var(A) SEMICOLON. { X = A; /*X-overwrites-A*/ }
statement(X) ::= error SEMICOLON. { X = NULL; }
statement(X) ::= staticarray_statement(A). { X = A; /*X-overwrites-A*/ }
@ -2098,6 +2099,17 @@ assign_statement(X) ::= LBRACKET expr_list(A) RBRACKET EQ expr(B). [EQ]
X = stmt;
}
%type assign_decl_statement{ZCC_AssignDeclStmt *}
assign_decl_statement(X) ::= LET LBRACKET identifier_list(A) RBRACKET EQ expr(B). [EQ]
{
NEW_AST_NODE(AssignDeclStmt,stmt,A);
stmt->AssignOp = ZCC_EQ;
stmt->Dests = A;
stmt->Sources = B;
X = stmt;
}
/*----- Local Variable Definition "Statements" -----*/
%type local_var{ZCC_LocalVarStmt *}

View file

@ -3350,6 +3350,28 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast, bool substitute)
return new FxMultiAssign(args, ConvertNode(ass->Sources), *ast);
}
case AST_AssignDeclStmt:
{
auto ass = static_cast<ZCC_AssignDeclStmt *>(ast);
FArgumentList args;
{
ZCC_TreeNode *n = ass->Dests;
if(n) do
{
args.Push(new FxIdentifier(static_cast<ZCC_Identifier*>(n)->Id,*n));
n = n->SiblingNext;
} while(n != ass->Dests);
}
assert(ass->Sources->SiblingNext == ass->Sources); // right side should be a single function call - nothing else
if (ass->Sources->NodeType != AST_ExprFuncCall)
{
// don't let this through to the code generator. This node is only used to assign multiple returns of a function to more than one variable.
Error(ass, "Right side of multi-assignment must be a function call");
return new FxNop(*ast); // allow compiler to continue looking for errors.
}
return new FxMultiAssignDecl(args, ConvertNode(ass->Sources), *ast);
}
default:
break;
}

View file

@ -1195,6 +1195,18 @@ ZCC_TreeNode *TreeNodeDeepCopy_Internal(ZCC_AST *ast, ZCC_TreeNode *orig, bool c
break;
}
case AST_AssignDeclStmt:
{
TreeNodeDeepCopy_Start(AssignDeclStmt);
// ZCC_AssignDeclStmt
copy->Dests = static_cast<ZCC_Identifier *>(TreeNodeDeepCopy_Internal(ast, origCasted->Dests, true, copiedNodesList));
copy->Sources = static_cast<ZCC_Expression *>(TreeNodeDeepCopy_Internal(ast, origCasted->Sources, true, copiedNodesList));
copy->AssignOp = origCasted->AssignOp;
break;
}
case AST_LocalVarStmt:
{
TreeNodeDeepCopy_Start(LocalVarStmt);

View file

@ -122,6 +122,7 @@ enum EZCCTreeNodeType
AST_SwitchStmt,
AST_CaseStmt,
AST_AssignStmt,
AST_AssignDeclStmt,
AST_LocalVarStmt,
AST_FuncParamDecl,
AST_ConstantDef,
@ -533,6 +534,13 @@ struct ZCC_AssignStmt : ZCC_Statement
int AssignOp;
};
struct ZCC_AssignDeclStmt : ZCC_Statement
{
ZCC_Identifier *Dests;
ZCC_Expression *Sources;
int AssignOp;
};
struct ZCC_LocalVarStmt : ZCC_Statement
{
ZCC_Type *Type;

View file

@ -578,6 +578,34 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripRight, StringStripRight)
return 0;
}
static void StringStripLeft(FString* self, const FString& junk)
{
if (junk.IsNotEmpty()) self->StripLeft(junk);
else self->StripLeft();
}
DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripLeft, StringStripLeft)
{
PARAM_SELF_STRUCT_PROLOGUE(FString);
PARAM_STRING(junk);
StringStripLeft(self, junk);
return 0;
}
static void StringStripLeftRight(FString* self, const FString& junk)
{
if (junk.IsNotEmpty()) self->StripLeftRight(junk);
else self->StripLeftRight();
}
DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripLeftRight, StringStripLeftRight)
{
PARAM_SELF_STRUCT_PROLOGUE(FString);
PARAM_STRING(junk);
StringStripLeftRight(self, junk);
return 0;
}
static void StringSplit(FString* self, TArray<FString>* tokens, const FString& delimiter, int keepEmpty)
{
self->Split(*tokens, delimiter, static_cast<FString::EmptyTokenType>(keepEmpty));

View file

@ -824,6 +824,10 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret)
assert(b < f->NumRegF);
::new(param) VMValue(&reg.f[b]);
break;
case REGT_FLOAT | REGT_MULTIREG2 | REGT_ADDROF:
case REGT_FLOAT | REGT_MULTIREG3 | REGT_ADDROF:
case REGT_FLOAT | REGT_MULTIREG4 | REGT_ADDROF:
I_Error("REGT_ADDROF not implemented for vectors\n");
case REGT_FLOAT | REGT_KONST:
assert(b < sfunc->NumKonstF);
::new(param) VMValue(konstf[b]);

View file

@ -682,7 +682,7 @@ void CVMAbortException::MaybePrintMessage()
auto m = GetMessage();
if (m != nullptr)
{
Printf(PRINT_NONOTIFY, TEXTCOLOR_RED "%s\n", m);
Printf(PRINT_NONOTIFY | PRINT_BOLD, TEXTCOLOR_RED "%s\n", m);
SetMessage("");
}
}

View file

@ -51,7 +51,7 @@ class FAnmTexture : public FImageSource
public:
FAnmTexture (int lumpnum, int w, int h);
void ReadFrame(uint8_t *buffer, uint8_t *palette);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -127,9 +127,9 @@ void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette)
//
//==========================================================================
TArray<uint8_t> FAnmTexture::CreatePalettedPixels(int conversion)
PalettedPixels FAnmTexture::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> pixels(Width*Height, true);
PalettedPixels pixels(Width*Height);
uint8_t buffer[64000];
uint8_t palette[768];
uint8_t remap[256];

View file

@ -50,7 +50,7 @@ class FAutomapTexture : public FImageSource
{
public:
FAutomapTexture(int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
@ -89,13 +89,13 @@ FAutomapTexture::FAutomapTexture (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FAutomapTexture::CreatePalettedPixels(int conversion)
PalettedPixels FAutomapTexture::CreatePalettedPixels(int conversion)
{
int x, y;
FileData data = fileSystem.ReadFile (SourceLump);
const uint8_t *indata = (const uint8_t *)data.GetMem();
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
for (x = 0; x < Width; ++x)

View file

@ -55,9 +55,9 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8
TopOffset = top;
}
TArray<uint8_t> FBuildTexture::CreatePalettedPixels(int conversion)
PalettedPixels FBuildTexture::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
FRemapTable *Remap = Translation;
for (int i = 0; i < Width*Height; i++)
{

View file

@ -163,7 +163,7 @@ class FDDSTexture : public FImageSource
public:
FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
protected:
uint32_t Format;
@ -371,11 +371,11 @@ void FDDSTexture::CalcBitShift (uint32_t mask, uint8_t *lshiftp, uint8_t *rshift
//
//==========================================================================
TArray<uint8_t> FDDSTexture::CreatePalettedPixels(int conversion)
PalettedPixels FDDSTexture::CreatePalettedPixels(int conversion)
{
auto lump = fileSystem.OpenFileReader (SourceLump);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet);

View file

@ -49,7 +49,7 @@ class FEmptyTexture : public FImageSource
{
public:
FEmptyTexture (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
//==========================================================================
@ -94,10 +94,10 @@ FEmptyTexture::FEmptyTexture (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FEmptyTexture::CreatePalettedPixels(int conversion)
PalettedPixels FEmptyTexture::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> Pixel(1, true);
Pixel[0] = 0;
static uint8_t p;
PalettedPixels Pixel(&p, 1);
return Pixel;
}

View file

@ -48,7 +48,7 @@ class FFlatTexture : public FImageSource
{
public:
FFlatTexture (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
@ -102,10 +102,10 @@ FFlatTexture::FFlatTexture (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FFlatTexture::CreatePalettedPixels(int conversion)
PalettedPixels FFlatTexture::CreatePalettedPixels(int conversion)
{
auto lump = fileSystem.OpenFileReader (SourceLump);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
auto numread = lump.Read (Pixels.Data(), Width*Height);
if (numread < Width*Height)
{

View file

@ -66,7 +66,7 @@ FFontChar2::FFontChar2(int sourcelump, int sourcepos, int width, int height, int
//
//==========================================================================
TArray<uint8_t> FFontChar2::CreatePalettedPixels(int)
PalettedPixels FFontChar2::CreatePalettedPixels(int)
{
auto lump = fileSystem.OpenFileReader(SourceLump);
int destSize = Width * Height;
@ -96,7 +96,7 @@ TArray<uint8_t> FFontChar2::CreatePalettedPixels(int)
}
}
TArray<uint8_t> Pixels(destSize, true);
PalettedPixels Pixels(destSize);
int runlen = 0, setlen = 0;
uint8_t setval = 0; // Shut up, GCC!

View file

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

View file

@ -66,7 +66,7 @@ class FIMGZTexture : public FImageSource
public:
FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t, bool isalpha);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -118,7 +118,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1
//
//==========================================================================
TArray<uint8_t> FIMGZTexture::CreatePalettedPixels(int conversion)
PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const ImageHeader *imgz = (const ImageHeader *)lump.GetMem();
@ -128,7 +128,7 @@ TArray<uint8_t> FIMGZTexture::CreatePalettedPixels(int conversion)
int dest_adv = Height;
int dest_rew = Width * Height - 1;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
dest_p = Pixels.Data();
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance, isalpha);

View file

@ -185,7 +185,7 @@ public:
FJPEGTexture (int lumpnum, int width, int height);
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
//==========================================================================
@ -259,7 +259,7 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height)
//
//==========================================================================
TArray<uint8_t> FJPEGTexture::CreatePalettedPixels(int conversion)
PalettedPixels FJPEGTexture::CreatePalettedPixels(int conversion)
{
auto lump = fileSystem.OpenFileReader (SourceLump);
JSAMPLE *buff = NULL;
@ -267,7 +267,7 @@ TArray<uint8_t> FJPEGTexture::CreatePalettedPixels(int conversion)
jpeg_decompress_struct cinfo;
jpeg_error_mgr jerr;
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
memset (Pixels.Data(), 0xBA, Width * Height);
cinfo.err = jpeg_std_error(&jerr);

View file

@ -201,13 +201,13 @@ void FMultiPatchTexture::CopyToBlock(uint8_t *dest, int dwidth, int dheight, FIm
//
//==========================================================================
TArray<uint8_t> FMultiPatchTexture::CreatePalettedPixels(int conversion)
PalettedPixels FMultiPatchTexture::CreatePalettedPixels(int conversion)
{
int numpix = Width * Height;
uint8_t blendwork[256];
bool buildrgb = bComplex;
TArray<uint8_t> Pixels(numpix, true);
PalettedPixels Pixels(numpix);
memset (Pixels.Data(), 0, numpix);
if (conversion == luminance)

View file

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

View file

@ -61,7 +61,7 @@ class FPatchTexture : public FImageSource
bool isalpha = false;
public:
FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
bool SupportRemap0() override { return !badflag; }
void DetectBadPatches();
@ -166,7 +166,7 @@ FPatchTexture::FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool is
//
//==========================================================================
TArray<uint8_t> FPatchTexture::CreatePalettedPixels(int conversion)
PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion)
{
uint8_t *remap, remaptable[256];
int numspans;
@ -189,7 +189,7 @@ TArray<uint8_t> FPatchTexture::CreatePalettedPixels(int conversion)
if (badflag)
{
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
uint8_t *out;
// Draw the image to the buffer
@ -210,7 +210,7 @@ TArray<uint8_t> FPatchTexture::CreatePalettedPixels(int conversion)
numspans = Width;
TArray<uint8_t> Pixels(numpix, true);
PalettedPixels Pixels(numpix);
memset (Pixels.Data(), 0, numpix);
// Draw the image to the buffer

View file

@ -91,7 +91,7 @@ protected:
void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr);
void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
@ -344,7 +344,7 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr
//
//==========================================================================
TArray<uint8_t> FPCXTexture::CreatePalettedPixels(int conversion)
PalettedPixels FPCXTexture::CreatePalettedPixels(int conversion)
{
uint8_t PaletteMap[256];
PCXHeader header;
@ -355,7 +355,7 @@ TArray<uint8_t> FPCXTexture::CreatePalettedPixels(int conversion)
lump.Read(&header, sizeof(header));
bitcount = header.bitsPerPixel * header.numColorPlanes;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
bool alphatex = conversion == luminance;
if (bitcount < 24)
@ -402,7 +402,7 @@ TArray<uint8_t> FPCXTexture::CreatePalettedPixels(int conversion)
}
else
{
TArray<uint8_t> newpix(Width*Height, true);
PalettedPixels newpix(Width*Height);
ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap);
return newpix;
}

View file

@ -56,7 +56,7 @@ public:
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;
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
protected:
void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap);
@ -411,7 +411,7 @@ void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap)
//
//==========================================================================
TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
PalettedPixels FPNGTexture::CreatePalettedPixels(int conversion)
{
FileReader *lump;
FileReader lfr;
@ -419,7 +419,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
lfr = fileSystem.OpenFileReader(SourceLump);
lump = &lfr;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
if (StartOfIDAT == 0)
{
memset (Pixels.Data(), 0x99, Width*Height);
@ -456,7 +456,7 @@ TArray<uint8_t> FPNGTexture::CreatePalettedPixels(int conversion)
}
else
{
TArray<uint8_t> newpix(Width*Height, true);
PalettedPixels newpix(Width*Height);
if (conversion != luminance)
{
if (!PaletteMap) SetupPalette(lfr);

View file

@ -51,7 +51,7 @@ class FRawPageTexture : public FImageSource
int mPaletteLump = -1;
public:
FRawPageTexture (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -62,7 +62,7 @@ public:
//
//==========================================================================
bool CheckIfRaw(FileReader & data, int desiredsize)
bool CheckIfRaw(FileReader & data, unsigned desiredsize)
{
if (data.GetLength() != desiredsize) return false;
@ -94,7 +94,7 @@ bool CheckIfRaw(FileReader & data, int desiredsize)
{
gapAtStart = false;
}
else if (ofs >= 64000-1) // Need one byte for an empty column
else if (ofs >= desiredsize-1) // Need one byte for an empty column
{
return true;
}
@ -102,7 +102,7 @@ bool CheckIfRaw(FileReader & data, int desiredsize)
{
// Ensure this column does not extend beyond the end of the patch
const uint8_t *foo2 = (const uint8_t *)foo;
while (ofs < 64000)
while (ofs < desiredsize)
{
if (foo2[ofs] == 255)
{
@ -110,7 +110,7 @@ bool CheckIfRaw(FileReader & data, int desiredsize)
}
ofs += foo2[ofs+1] + 4;
}
if (ofs >= 64000)
if (ofs >= desiredsize)
{
return true;
}
@ -170,14 +170,14 @@ FRawPageTexture::FRawPageTexture (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FRawPageTexture::CreatePalettedPixels(int conversion)
PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem();
const uint8_t *source_p = source;
uint8_t *dest_p;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
dest_p = Pixels.Data();
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);

View file

@ -98,9 +98,9 @@ public:
}
}
TArray<uint8_t> CreatePalettedPixels(int conversion) override
PalettedPixels CreatePalettedPixels(int conversion) override
{
TArray<uint8_t> Pix(512, true);
PalettedPixels Pix(512);
if (conversion == luminance)
{
memcpy(Pix.Data(), Pixels, 512);

View file

@ -77,7 +77,7 @@ class FStartupTexture : public FImageSource
{
public:
FStartupTexture (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -85,7 +85,7 @@ class FNotchTexture : public FImageSource
{
public:
FNotchTexture (int lumpnum, int width, int height);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -93,14 +93,14 @@ class FStrifeStartupTexture : public FImageSource
{
public:
FStrifeStartupTexture (int lumpnum, int w, int h);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
class FStrifeStartupBackground : public FImageSource
{
public:
FStrifeStartupBackground (int lumpnum);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
//==========================================================================
@ -109,7 +109,7 @@ public:
//
//==========================================================================
bool CheckIfRaw(FileReader & data, int desiredsize);
bool CheckIfRaw(FileReader & data, unsigned desiredsize);
//==========================================================================
//
@ -231,7 +231,7 @@ void PlanarToChunky(T* dest, const uint8_t* src, const T* remap, int width, int
//
//==========================================================================
TArray<uint8_t> FStartupTexture::CreatePalettedPixels(int conversion)
PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem();
@ -239,7 +239,7 @@ TArray<uint8_t> FStartupTexture::CreatePalettedPixels(int conversion)
TArray<uint8_t> Work(Width*Height, true);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
PlanarToChunky(Work.Data(), source + 48, startuppalette8, Width, Height);
ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), Work.Data(), Width, Height, Width, remap);
return Pixels;
@ -279,14 +279,14 @@ FNotchTexture::FNotchTexture (int lumpnum, int width, int height)
//
//==========================================================================
TArray<uint8_t> FNotchTexture::CreatePalettedPixels(int conversion)
PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem();
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
TArray<uint8_t> Work(Width*Height, true);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
for(int i=0; i * Width * Height / 2; i++)
{
Work[i * 2] = startuppalette8[source[i] >> 4];
@ -336,11 +336,11 @@ FStrifeStartupTexture::FStrifeStartupTexture (int lumpnum, int w, int h)
//
//==========================================================================
TArray<uint8_t> FStrifeStartupTexture::CreatePalettedPixels(int conversion)
PalettedPixels FStrifeStartupTexture::CreatePalettedPixels(int conversion)
{
FileData lump = fileSystem.ReadFile (SourceLump);
const uint8_t *source = (const uint8_t *)lump.GetMem();
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), source, Width, Height, Width, remap);
return Pixels;
@ -366,7 +366,7 @@ FStrifeStartupBackground::FStrifeStartupBackground (int lumpnum)
//
//==========================================================================
TArray<uint8_t> FStrifeStartupBackground::CreatePalettedPixels(int conversion)
PalettedPixels FStrifeStartupBackground::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> source(64000, true);
memset(source.Data(), 0xF0, 64000);
@ -374,7 +374,7 @@ TArray<uint8_t> FStrifeStartupBackground::CreatePalettedPixels(int conversion)
lumpr.Seek(57 * 320, FileReader::SeekSet);
lumpr.Read(source.Data() + 41 * 320, 95 * 320);
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance);
ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), source.Data(), Width, Height, Width, remap);
return Pixels;

View file

@ -67,7 +67,7 @@ class FStbTexture : public FImageSource
public:
FStbTexture (int lumpnum, int w, int h);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap *bmp, int conversion) override;
};
@ -117,7 +117,7 @@ FStbTexture::FStbTexture (int lumpnum, int w, int h)
//
//==========================================================================
TArray<uint8_t> FStbTexture::CreatePalettedPixels(int conversion)
PalettedPixels FStbTexture::CreatePalettedPixels(int conversion)
{
FBitmap bitmap;
bitmap.Create(Width, Height);
@ -128,7 +128,7 @@ TArray<uint8_t> FStbTexture::CreatePalettedPixels(int conversion)
int dest_adv = Height;
int dest_rew = Width * Height - 1;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
dest_p = Pixels.Data();
bool doalpha = conversion == luminance;

View file

@ -83,7 +83,7 @@ public:
protected:
void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
};
//==========================================================================
@ -177,7 +177,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe
//
//==========================================================================
TArray<uint8_t> FTGATexture::CreatePalettedPixels(int conversion)
PalettedPixels FTGATexture::CreatePalettedPixels(int conversion)
{
uint8_t PaletteMap[256];
auto lump = fileSystem.OpenFileReader (SourceLump);
@ -185,7 +185,7 @@ TArray<uint8_t> FTGATexture::CreatePalettedPixels(int conversion)
uint16_t w;
uint8_t r,g,b,a;
TArray<uint8_t> Pixels(Width*Height, true);
PalettedPixels Pixels(Width*Height);
lump.Read(&hdr, sizeof(hdr));
lump.Seek(hdr.id_len, FileReader::SeekCur);

View file

@ -48,7 +48,7 @@ static PrecacheInfo precacheInfo;
struct PrecacheDataPaletted
{
TArray<uint8_t> Pixels;
PalettedPixels Pixels;
int RefCount;
int ImageID;
};
@ -71,9 +71,9 @@ TArray<PrecacheDataRgba> precacheDataRgba;
//
//===========================================================================
TArray<uint8_t> FImageSource::CreatePalettedPixels(int conversion)
PalettedPixels FImageSource::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> Pixels(Width * Height, true);
PalettedPixels Pixels(Width * Height);
memset(Pixels.Data(), 0, Width * Height);
return Pixels;
}
@ -99,8 +99,7 @@ PalettedPixels FImageSource::GetCachedPalettedPixels(int conversion)
else if (cache->Pixels.Size() > 0)
{
//Printf("returning contents of %s, refcount = %d\n", name.GetChars(), cache->RefCount);
ret.PixelStore = std::move(cache->Pixels);
ret.Pixels.Set(ret.PixelStore.Data(), ret.PixelStore.Size());
ret = std::move(cache->Pixels);
precacheDataPaletted.Delete(index);
}
else
@ -116,8 +115,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.
//Printf("returning fresh copy of %s\n", name.GetChars());
ret.PixelStore = CreatePalettedPixels(conversion);
ret.Pixels.Set(ret.PixelStore.Data(), ret.PixelStore.Size());
return CreatePalettedPixels(conversion);
}
else
{
@ -171,6 +169,7 @@ int FImageSource::CopyPixels(FBitmap *bmp, int conversion)
{
if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source.
PalEntry *palette = GPalette.BaseColors;
auto ppix = CreatePalettedPixels(conversion);
bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, palette, nullptr);
return 0;
@ -178,7 +177,7 @@ int FImageSource::CopyPixels(FBitmap *bmp, int conversion)
int FImageSource::CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap)
{
auto ppix = CreatePalettedPixels(false);
auto ppix = CreatePalettedPixels(normal);
bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, remap, nullptr);
return 0;
}

View file

@ -26,10 +26,30 @@ struct PalettedPixels
private:
TArray<uint8_t> PixelStore;
public:
PalettedPixels() = default;
PalettedPixels(unsigned size)
{
PixelStore.Resize(size);
Pixels.Set(PixelStore.Data(), PixelStore.Size());
}
PalettedPixels(uint8_t* data, unsigned size)
{
Pixels.Set(data, size);
}
bool ownsPixels() const
{
return Pixels.Data() == PixelStore.Data();
}
uint8_t* Data() const { return Pixels.Data(); }
unsigned Size() const { return Pixels.Size(); }
uint8_t& operator[] (size_t index) const
{
assert(index < Size());
return Pixels[index];
}
};
// This represents a naked image. It has no high level logic attached to it.
@ -51,8 +71,7 @@ protected:
// Internal image creation functions. All external access should go through the cache interface,
// so that all code can benefit from future improvements to that.
virtual TArray<uint8_t> CreatePalettedPixels(int conversion);
virtual int CopyPixels(FBitmap *bmp, int conversion); // This will always ignore 'luminance'.
virtual PalettedPixels CreatePalettedPixels(int conversion);
int CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap);
@ -87,7 +106,8 @@ public:
// 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);
// Unlile for paletted images there is no variant here that returns a persistent bitmap, because all users have to process the returned image into another format.
virtual int CopyPixels(FBitmap* bmp, int conversion);
FBitmap GetCachedBitmap(const PalEntry *remap, int conversion, int *trans = nullptr);
static void ClearImages() { ImageArena.FreeAll(); ImageForLump.Clear(); NextID = 0; }
@ -160,7 +180,7 @@ class FBuildTexture : public FImageSource
{
public:
FBuildTexture(const FString& pathprefix, int tilenum, const uint8_t* pixels, FRemapTable* translation, int width, int height, int left, int top);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
PalettedPixels CreatePalettedPixels(int conversion) override;
int CopyPixels(FBitmap* bmp, int conversion) override;
protected:

View file

@ -51,7 +51,7 @@ public:
bTranslucent = false;
}
virtual uint8_t* GetRawData() = 0;
virtual TArray<uint8_t> CreatePalettedPixels(int conversion);
virtual PalettedPixels CreatePalettedPixels(int conversion);
virtual int CopyPixels(FBitmap* bmp, int conversion); // This will always ignore 'luminance'.
};
@ -186,13 +186,19 @@ int FTileTexture::CopyPixels(FBitmap* bmp, int conversion)
return 0;
}
TArray<uint8_t> FTileTexture::CreatePalettedPixels(int conversion)
// 'conversion' is meaningless here becazse we do not have to bother with a software renderer.
PalettedPixels FTileTexture::CreatePalettedPixels(int conversion)
{
TArray<uint8_t> buffer(Width * Height, true);
auto p = GetRawData();
if (p) memcpy(buffer.Data(), p, buffer.Size());
else memset(buffer.Data(), 0, buffer.Size());
return buffer;
if (GetRawData())
{
return PalettedPixels(GetRawData(), Width * Height);
}
else
{
PalettedPixels buffer(Width * Height);
memset(buffer.Data(), 0, buffer.Size());
return buffer;
}
}
//==========================================================================