Introducing pMasterPalette.

Used instead of pLocalPalette when attempting to determine objective truths, such as "the colours of this gif without color profile modification" and "what indicies should this colormap remap to".

Also, made f_wipe.c's paldiv only get calculated once.

(cherry picked from commit d669a4e84a)
This commit is contained in:
toasterbabe 2017-04-29 16:40:07 +01:00 committed by James R
parent e8c37067ed
commit 2fb599661e
6 changed files with 67 additions and 55 deletions

View file

@ -157,7 +157,7 @@ static fademask_t *F_GetFadeMask(UINT8 masknum, UINT8 scrnnum) {
while (lsize--)
{
// Determine pixel to use from fademask
pcolor = &pLocalPalette[*lump++];
pcolor = &pMasterPalette[*lump++];
*mask++ = FixedDiv((pcolor->s.red+1)<<FRACBITS, paldiv)>>FRACBITS;
}

View file

@ -427,21 +427,16 @@ static void GIF_headwrite(void)
WRITEUINT8(p, 0x00);
// write color table
if (cv_screenshot_colorprofile.value)
{
RGBA_t *pal = ((cv_screenshot_colorprofile.value)
? pLocalPalette
: pMasterPalette);
for (i = 0; i < 256; i++)
{
WRITEUINT8(p, pLocalPalette[i].s.red);
WRITEUINT8(p, pLocalPalette[i].s.green);
WRITEUINT8(p, pLocalPalette[i].s.blue);
}
}
else
{
const UINT8 *pal = (UINT8 *)W_CacheLumpName(GetPalette(), PU_CACHE);
for (i = 0; i < 256*3; i++)
{
WRITEUINT8(p, *pal); pal++;
WRITEUINT8(p, pal[i].s.red);
WRITEUINT8(p, pal[i].s.green);
WRITEUINT8(p, pal[i].s.blue);
}
}

View file

@ -663,25 +663,18 @@ static void M_PNGhdr(png_structp png_ptr, png_infop png_info_ptr, PNG_CONST png_
{
png_colorp png_PLTE = png_malloc(png_ptr, sizeof(png_color)*256); //palette
png_uint_16 i;
if (cv_screenshot_colorprofile.value)
RGBA_t *pal = ((cv_screenshot_colorprofile.value)
? pLocalPalette
: pMasterPalette);
for (i = 0; i < 256; i++)
{
for (i = 0; i < 256; i++)
{
png_PLTE[i].red = pLocalPalette[i].s.red;
png_PLTE[i].green = pLocalPalette[i].s.green;
png_PLTE[i].blue = pLocalPalette[i].s.blue;
}
}
else
{
const png_byte *pal = (png_byte *)W_CacheLumpName(GetPalette(), PU_CACHE);
for (i = 0; i < 256; i++)
{
png_PLTE[i].red = *pal++;
png_PLTE[i].green = *pal++;
png_PLTE[i].blue = *pal++;
}
png_PLTE[i].red = pal[i].s.red;
png_PLTE[i].green = pal[i].s.green;
png_PLTE[i].blue = pal[i].s.blue;
}
png_set_IHDR(png_ptr, png_info_ptr, width, height, 8, PNG_COLOR_TYPE_PALETTE,
png_interlace, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info_before_PLTE(png_ptr, png_info_ptr);
@ -1411,21 +1404,16 @@ static boolean WritePCXfile(const char *filename, const UINT8 *data, int width,
*pack++ = 0x0c; // palette ID byte
// write color table
if (cv_screenshot_colorprofile.value)
{
RGBA_t *pal = ((cv_screenshot_colorprofile.value)
? pLocalPalette
: pMasterPalette);
for (i = 0; i < 256; i++)
{
*pack++ = pLocalPalette[i].s.red;
*pack++ = pLocalPalette[i].s.green;
*pack++ = pLocalPalette[i].s.blue;
}
}
else
{
const UINT8 *pal = (UINT8 *)W_CacheLumpName(GetPalette(), PU_CACHE);
for (i = 0; i < 256*3; i++)
{
*pack++ = *pal++;
*pack++ = pal[i].s.red;
*pack++ = pal[i].s.green;
*pack++ = pal[i].s.blue;
}
}

View file

@ -22,7 +22,7 @@
#include "w_wad.h"
#include "z_zone.h"
#include "p_setup.h" // levelflats
#include "v_video.h" // pLocalPalette
#include "v_video.h" // pMasterPalette
#include "dehacked.h"
#if defined (_WIN32) || defined (_WIN32_WCE)
@ -1192,7 +1192,7 @@ void R_MakeInvertmap(void)
INT32 R_CreateColormap(char *p1, char *p2, char *p3)
{
double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb;
double maskamt = 0, othermask = 0;
double r, g, b, cbrightness, maskamt = 0, othermask = 0;
int mask, fog = 0;
size_t mapnum = num_extra_colormaps;
size_t i;
@ -1300,6 +1300,32 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3)
num_extra_colormaps++;
if (rendermode == render_soft)
{
for (i = 0; i < 256; i++)
{
r = pMasterPalette[i].s.red;
g = pMasterPalette[i].s.green;
b = pMasterPalette[i].s.blue;
cbrightness = sqrt((r*r) + (g*g) + (b*b));
map[i][0] = (cbrightness * cmaskr) + (r * othermask);
if (map[i][0] > 255.0l)
map[i][0] = 255.0l;
deltas[i][0] = (map[i][0] - cdestr) / (double)fadedist;
map[i][1] = (cbrightness * cmaskg) + (g * othermask);
if (map[i][1] > 255.0l)
map[i][1] = 255.0l;
deltas[i][1] = (map[i][1] - cdestg) / (double)fadedist;
map[i][2] = (cbrightness * cmaskb) + (b * othermask);
if (map[i][2] > 255.0l)
map[i][2] = 255.0l;
deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist;
}
}
foundcolormaps[mapnum] = LUMPERROR;
// aligned on 8 bit for asm code
@ -1313,7 +1339,6 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3)
if (rendermode == render_soft)
{
double r, g, b, cbrightness;
int p;
lighttable_t *colormap_p;
@ -1324,9 +1349,9 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3)
// map[i]'s values are decremented by after each use
for (i = 0; i < 256; i++)
{
r = pLocalPalette[i].s.red;
g = pLocalPalette[i].s.green;
b = pLocalPalette[i].s.blue;
r = pMasterPalette[i].s.red;
g = pMasterPalette[i].s.green;
b = pMasterPalette[i].s.blue;
cbrightness = sqrt((r*r) + (g*g) + (b*b));
map[i][0] = (cbrightness * cmaskr) + (r * othermask);
@ -1409,9 +1434,9 @@ UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b)
for (i = 0; i < 256; i++)
{
dr = r - pLocalPalette[i].s.red;
dg = g - pLocalPalette[i].s.green;
db = b - pLocalPalette[i].s.blue;
dr = r - pMasterPalette[i].s.red;
dg = g - pMasterPalette[i].s.green;
db = b - pMasterPalette[i].s.blue;
distortion = dr*dr + dg*dg + db*db;
if (distortion < bestdistortion)
{

View file

@ -112,6 +112,7 @@ consvar_t cv_grspritebillboarding = {"gr_spritebillboarding", "On", CV_SAVE, CV_
// local copy of the palette for V_GetColor()
RGBA_t *pLocalPalette = NULL;
RGBA_t *pMasterPalette = NULL;
/*
The following was an extremely helpful resource when developing my Colour Cube LUT.
@ -338,16 +339,18 @@ static void LoadPalette(const char *lumpname)
UINT8 *pal;
Z_Free(pLocalPalette);
Z_Free(pMasterPalette);
pLocalPalette = Z_Malloc(sizeof (*pLocalPalette)*palsize, PU_STATIC, NULL);
pMasterPalette = Z_Malloc(sizeof (*pMasterPalette)*palsize, PU_STATIC, NULL);
pal = W_CacheLumpNum(lumpnum, PU_CACHE);
for (i = 0; i < palsize; i++)
{
pLocalPalette[i].s.red = correctiontable[*pal++];
pLocalPalette[i].s.green = correctiontable[*pal++];
pLocalPalette[i].s.blue = correctiontable[*pal++];
pLocalPalette[i].s.alpha = 0xFF;
pMasterPalette[i].s.red = pLocalPalette[i].s.red = correctiontable[*pal++];
pMasterPalette[i].s.green = pLocalPalette[i].s.green = correctiontable[*pal++];
pMasterPalette[i].s.blue = pLocalPalette[i].s.blue = correctiontable[*pal++];
pMasterPalette[i].s.alpha = pLocalPalette[i].s.alpha = 0xFF;
// lerp of colour cubing!
if (cube)

View file

@ -45,6 +45,7 @@ const char *R_GetPalname(UINT16 num);
const char *GetPalette(void);
extern RGBA_t *pLocalPalette;
extern RGBA_t *pMasterPalette;
extern UINT8 hudtrans;