Skip to content

Commit

Permalink
- allow specifying full palettes in translation definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Mar 15, 2020
1 parent 27b8284 commit 0c04cdd
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/gamedata/textures/texturemanager.cpp
Expand Up @@ -1549,7 +1549,7 @@ void FTextureManager::GenerateGlobalBrightmapFromColormap()
if (lump == -1) return;
FMemLump cmap = Wads.ReadLump(lump);
uint8_t palbuffer[768];
ReadPalette(Wads.CheckNumForName("PLAYPAL"), palbuffer);
ReadPalette(Wads.GetNumForName("PLAYPAL"), palbuffer);

const unsigned char *cmapdata = (const unsigned char *)cmap.GetMem();
const uint8_t *paldata = palbuffer;
Expand Down
2 changes: 1 addition & 1 deletion src/gamedata/w_wad.cpp
Expand Up @@ -500,7 +500,7 @@ int FWadCollection::GetNumForName (const char *name, int space)
i = CheckNumForName (name, space);

if (i == -1)
I_Error ("W_GetNumForName: %s not found!", name);
I_Error ("GetNumForName: %s not found!", name);

return i;
}
Expand Down
51 changes: 47 additions & 4 deletions src/r_data/r_translate.cpp
Expand Up @@ -770,6 +770,35 @@ bool FRemapTable::AddToTranslation(const char *range)
}
}

//----------------------------------------------------------------------------
//
// Adds raw colors to a given translation
//
//----------------------------------------------------------------------------

bool FRemapTable::AddColors(int start, int count, const uint8_t*colors)
{
int end = start + count;
if (IndexOutOfRange(start, end))
{
return false;
}

for (int i = start; i < end; ++i)
{
auto br = colors[0];
auto bg = colors[1];
auto bb = colors[2];
colors += 3;

int j = GPalette.Remap[i];
Palette[j] = PalEntry(j == 0 ? 0 : 255, br, bg, bb);
Remap[j] = ColorMatcher.Pick(Palette[j]);
}
return true;

}

//----------------------------------------------------------------------------
//
// Stores a copy of this translation in the DECORATE translation table
Expand Down Expand Up @@ -1521,16 +1550,30 @@ void R_ParseTrnslate()
do
{
sc.MustGetToken(TK_StringConst);

try
{
NewTranslation.AddToTranslation(sc.String);
int pallump = Wads.CheckNumForFullName(sc.String, true, ns_global);
if (pallump) //
{
int start = 0;
if (sc.CheckToken(','))
{
sc.MustGetValue(false);
start = sc.Number;
}
uint8_t palette[768];
int numcolors = ReadPalette(pallump, palette);
NewTranslation.AddColors(start, numcolors, palette);
}
else
{
NewTranslation.AddToTranslation(sc.String);
}
}
catch (CRecoverableError &err)
catch (CRecoverableError & err)
{
sc.ScriptMessage("Error in translation '%s':\n" TEXTCOLOR_YELLOW "%s\n", sc.String, err.GetMessage());
}

} while (sc.CheckToken(','));

int trans = NewTranslation.StoreTranslation(TRANSLATION_Custom);
Expand Down
1 change: 1 addition & 0 deletions src/r_data/r_translate.h
Expand Up @@ -78,6 +78,7 @@ struct FRemapTable
bool AddColourisation(int start, int end, int r, int g, int b);
bool AddTint(int start, int end, int r, int g, int b, int amount);
bool AddToTranslation(const char * range);
bool AddColors(int start, int count, const uint8_t*);
int StoreTranslation(int slot);
int GetUniqueIndex();

Expand Down
44 changes: 38 additions & 6 deletions src/r_data/v_palette.cpp
Expand Up @@ -48,6 +48,7 @@
#include "st_stuff.h"
#include "x86.h"
#include "g_levellocals.h"
#include "m_png.h"

uint32_t Col2RGB8[65][256];
uint32_t *Col2RGB8_LessPrecision[65];
Expand Down Expand Up @@ -277,20 +278,45 @@ static int sortforremap2 (const void *a, const void *b)
}
}

void ReadPalette(int lumpnum, uint8_t *buffer)
int ReadPalette(int lumpnum, uint8_t *buffer)
{
if (lumpnum < 0)
{
I_FatalError("Palette not found");
return 0;
}
FMemLump lump = Wads.ReadLump(lumpnum);
uint8_t *lumpmem = (uint8_t*)lump.GetMem();
memset(buffer, 0, 768);
if (memcmp(lumpmem, "JASC-PAL", 8))

FileReader fr;
fr.OpenMemory(lumpmem, lump.GetSize());
auto png = M_VerifyPNG(fr);
if (png)
{
memcpy(buffer, lumpmem, MIN<size_t>(768, lump.GetSize()));
uint32_t id, len;
fr.Seek(33, FileReader::SeekSet);
fr.Read(&len, 4);
fr.Read(&id, 4);
bool succeeded = false;
while (id != MAKE_ID('I', 'D', 'A', 'T') && id != MAKE_ID('I', 'E', 'N', 'D'))
{
len = BigLong((unsigned int)len);
if (id != MAKE_ID('P', 'L', 'T', 'E'))
fr.Seek(len, FileReader::SeekCur);
else
{
int PaletteSize = MIN<int>(len, 768);
fr.Read(buffer, PaletteSize);
return PaletteSize / 3;
}
fr.Seek(4, FileReader::SeekCur); // Skip CRC
fr.Read(&len, 4);
id = MAKE_ID('I', 'E', 'N', 'D');
fr.Read(&id, 4);
}
I_Error("%s contains no palette", Wads.GetLumpFullName(lumpnum));
}
else
if (memcmp(lumpmem, "JASC-PAL", 8) == 0)
{
FScanner sc;

Expand All @@ -308,6 +334,12 @@ void ReadPalette(int lumpnum, uint8_t *buffer)
}
buffer[i] = sc.Number;
}
return colors / 3;
}
else
{
memcpy(buffer, lumpmem, MIN<size_t>(768, lump.GetSize()));
return 256;
}
}

Expand Down Expand Up @@ -371,7 +403,7 @@ void InitPalette ()
{
uint8_t pal[768];

ReadPalette(Wads.CheckNumForName("PLAYPAL"), pal);
ReadPalette(Wads.GetNumForName("PLAYPAL"), pal);

GPalette.SetPalette (pal);
GPalette.MakeGoodRemap ();
Expand Down
2 changes: 1 addition & 1 deletion src/r_data/v_palette.h
Expand Up @@ -63,7 +63,7 @@ extern FPalette GPalette;
// The color overlay to use for depleted items
#define DIM_OVERLAY MAKEARGB(170,0,0,0)

void ReadPalette(int lumpnum, uint8_t *buffer);
int ReadPalette(int lumpnum, uint8_t *buffer);
void InitPalette ();

EXTERN_CVAR (Int, paletteflash)
Expand Down
2 changes: 1 addition & 1 deletion src/win32/st_start_util.cpp
Expand Up @@ -1031,7 +1031,7 @@ void ST_Util_BitmapColorsFromPlaypal(BitmapInfo* bitmap_info)
{
uint8_t playpal[768];

ReadPalette(Wads.CheckNumForName("PLAYPAL"), playpal);
ReadPalette(Wads.GetNumForName("PLAYPAL"), playpal);
for (int i = 0; i < 256; ++i)
{
bitmap_info->bmiColors[i].rgbBlue = playpal[i * 3 + 2];
Expand Down
2 changes: 2 additions & 0 deletions wadsrc/static/zscript/base.zs
Expand Up @@ -191,6 +191,8 @@ enum DrawTextureTags
DTA_Internal3,
DTA_Spacing, // Strings only: Additional spacing between characters
DTA_Monospace, // Strings only: Use a fixed distance between characters.

DTA_FullsceeenEx, // advanced fullscreen control.

This comment has been minimized.

Copy link
@Talon1024

Talon1024 Mar 15, 2020

Contributor

There's a typo on this line (3 'e's)

};

class Shape2DTransform : Object native
Expand Down

1 comment on commit 0c04cdd

@Talon1024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this commit implement the feature I requested here?

Is there any need for SPALDOOM or SPALHTIC anymore?

Please sign in to comment.