From 0ebe98d1e0140ea52ea1ea20261cad871d6768a2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Mar 2017 12:16:42 +0100 Subject: [PATCH] - added support for reading JASC palette files. I hope it's correct, considering I have no such files to test. The format should be simple enough, though. --- src/d_net.cpp | 2 +- src/gl/textures/gl_texture.cpp | 6 +++-- src/intermission/intermission.cpp | 5 +++-- src/v_palette.cpp | 37 +++++++++++++++++++++++++++++-- src/v_palette.h | 1 + src/win32/st_start.cpp | 9 +++----- 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/d_net.cpp b/src/d_net.cpp index 80755c90e0..0af1bd9c10 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2210,7 +2210,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player) case DEM_SETINV: s = ReadString(stream); i = ReadLong(stream); - cht_SetInv(&players[player], s, i, ReadByte(stream)); + cht_SetInv(&players[player], s, i, !!ReadByte(stream)); break; case DEM_WARPCHEAT: diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index cc24f054d8..539a7c8ff4 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -133,9 +133,11 @@ void gl_GenerateGlobalBrightmapFromColormap() if (lump == -1) lump = Wads.CheckNumForName("COLORMAP", ns_colormaps); if (lump == -1) return; FMemLump cmap = Wads.ReadLump(lump); - FMemLump palette = Wads.ReadLump("PLAYPAL"); + uint8_t palbuffer[768]; + ReadPalette(Wads.CheckNumForName("PLAYPAL"), palbuffer); + const unsigned char *cmapdata = (const unsigned char *)cmap.GetMem(); - const unsigned char *paldata = (const unsigned char *)palette.GetMem(); + const uint8_t *paldata = palbuffer; const int black = 0; const int white = ColorMatcher.Pick(255,255,255); diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index 0143b3e401..916d1c24d5 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -124,12 +124,13 @@ void DIntermissionScreen::Init(FIntermissionAction *desc, bool first) if (desc->mPalette.IsNotEmpty() && (lumpnum = Wads.CheckNumForFullName(desc->mPalette, true)) > 0) { PalEntry *palette; + uint8_t palbuffer[768]; const uint8_t *orgpal; FMemLump lump; int i; - lump = Wads.ReadLump (lumpnum); - orgpal = (uint8_t *)lump.GetMem(); + ReadPalette(lumpnum, palbuffer); + orgpal = (uint8_t *)palbuffer; palette = screen->GetPalette (); for (i = 256; i > 0; i--, orgpal += 3) { diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 1c13446a85..07d8af86da 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -306,6 +306,40 @@ static int sortforremap2 (const void *a, const void *b) } } +void ReadPalette(int lumpnum, uint8_t *buffer) +{ + if (lumpnum < 0) + { + I_FatalError("Palette not found"); + } + FMemLump lump = Wads.ReadLump(lumpnum); + uint8_t *lumpmem = (uint8_t*)lump.GetMem(); + memset(buffer, 0, 768); + if (memcmp(lumpmem, "JASC-PAL", 8)) + { + memcpy(buffer, lumpmem, MIN(768, lump.GetSize())); + } + else + { + FScanner sc; + + sc.OpenMem(Wads.GetLumpFullName(lumpnum), (char*)lumpmem, lump.GetSize()); + sc.MustGetString(); + sc.MustGetNumber(); // version - ignore + sc.MustGetNumber(); + int colors = MIN(256, sc.Number) * 3; + for (int i = 0; i < colors; i++) + { + sc.MustGetNumber(); + if (sc.Number < 0 || sc.Number > 255) + { + sc.ScriptError("Color %d value out of range.", sc.Number); + } + buffer[i] = sc.Number; + } + } +} + static bool FixBuildPalette (uint8_t *opal, int lump, bool blood) { if (Wads.LumpLength (lump) < 768) @@ -354,8 +388,7 @@ void InitPalette () if (!usingBuild) { - FWadLump palump = Wads.OpenLumpName ("PLAYPAL"); - palump.Read (pal, 768); + ReadPalette(Wads.CheckNumForName("PLAYPAL"), pal); } GPalette.SetPalette (pal); diff --git a/src/v_palette.h b/src/v_palette.h index 28ced55f3f..3f8f000399 100644 --- a/src/v_palette.h +++ b/src/v_palette.h @@ -73,6 +73,7 @@ extern FPalette GPalette; int BestColor (const uint32_t *pal, int r, int g, int b, int first=1, int num=255); void DoBlending (const PalEntry *from, PalEntry *to, int count, int r, int g, int b, int a); +void ReadPalette(int lumpnum, uint8_t *buffer); void InitPalette (); // V_SetBlend() diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp index c1556f0023..0fb89d5816 100644 --- a/src/win32/st_start.cpp +++ b/src/win32/st_start.cpp @@ -52,6 +52,7 @@ #include "s_sound.h" #include "m_argv.h" #include "d_main.h" +#include "v_palette.h" // MACROS ------------------------------------------------------------------ @@ -1452,13 +1453,9 @@ void ST_Util_FreeBitmap (BITMAPINFO *bitmap_info) void ST_Util_BitmapColorsFromPlaypal (BITMAPINFO *bitmap_info) { uint8_t playpal[768]; - int i; - { - FWadLump lumpr = Wads.OpenLumpName ("PLAYPAL"); - lumpr.Read (playpal, 768); - } - for (i = 0; i < 256; ++i) + ReadPalette(Wads.CheckNumForName("PLAYPAL"), playpal); + for (int i = 0; i < 256; ++i) { bitmap_info->bmiColors[i].rgbBlue = playpal[i*3+2]; bitmap_info->bmiColors[i].rgbGreen = playpal[i*3+1];