mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
FINALLY, COLORCUBIUM
This commit is contained in:
parent
228b29e23b
commit
4e814cd424
3 changed files with 54 additions and 34 deletions
|
@ -373,6 +373,9 @@ static void md2_loadTexture(md2_t *model)
|
|||
if (!grpatch->mipmap->downloaded && !grpatch->mipmap->grInfo.data)
|
||||
{
|
||||
int w = 0, h = 0;
|
||||
UINT32 size;
|
||||
RGBA_t *image;
|
||||
|
||||
#ifdef HAVE_PNG
|
||||
grpatch->mipmap->grInfo.format = PNG_Load(filename, &w, &h, grpatch);
|
||||
if (grpatch->mipmap->grInfo.format == 0)
|
||||
|
@ -389,6 +392,15 @@ static void md2_loadTexture(md2_t *model)
|
|||
grpatch->mipmap->width = (UINT16)w;
|
||||
grpatch->mipmap->height = (UINT16)h;
|
||||
|
||||
// Lactozilla: Apply colour cube
|
||||
image = grpatch->mipmap->grInfo.data;
|
||||
size = w*h;
|
||||
while (size--)
|
||||
{
|
||||
V_CubeApply(&image->s.red, &image->s.green, &image->s.blue);
|
||||
image++;
|
||||
}
|
||||
|
||||
#ifdef GLIDE_API_COMPATIBILITY
|
||||
// not correct!
|
||||
grpatch->mipmap->grInfo.smallLodLog2 = GR_LOD_LOG2_256;
|
||||
|
|
|
@ -95,6 +95,7 @@ Please check it out if you're trying to maintain this.
|
|||
toast 18/04/17
|
||||
*/
|
||||
float Cubepal[2][2][2][3];
|
||||
boolean Cubeapply = false;
|
||||
|
||||
// returns whether to apply cube, selectively avoiding expensive operations
|
||||
static boolean InitCube(void)
|
||||
|
@ -310,7 +311,7 @@ const UINT8 correctiontable[256] =
|
|||
// keep a copy of the palette so that we can get the RGB value for a color index at any time.
|
||||
static void LoadPalette(const char *lumpname)
|
||||
{
|
||||
boolean cube = InitCube();
|
||||
Cubeapply = InitCube();
|
||||
lumpnum_t lumpnum = W_GetNumForName(lumpname);
|
||||
size_t i, palsize = W_LumpLength(lumpnum)/3;
|
||||
UINT8 *pal;
|
||||
|
@ -336,13 +337,20 @@ static void LoadPalette(const char *lumpname)
|
|||
pMasterPalette[i].s.alpha = pLocalPalette[i].s.alpha = 0xFF;
|
||||
|
||||
// lerp of colour cubing! if you want, make it smoother yourself
|
||||
if (cube)
|
||||
{
|
||||
V_CubeApply(&pLocalPalette[i].s.red, &pLocalPalette[i].s.green, &pLocalPalette[i].s.blue);
|
||||
}
|
||||
}
|
||||
|
||||
void V_CubeApply(UINT8 *red, UINT8 *green, UINT8 *blue)
|
||||
{
|
||||
float working[4][3];
|
||||
float linear;
|
||||
UINT8 q;
|
||||
|
||||
linear = (pLocalPalette[i].s.red/255.0);
|
||||
if (!Cubeapply)
|
||||
return;
|
||||
|
||||
linear = (*red/255.0);
|
||||
#define dolerp(e1, e2) ((1 - linear)*e1 + linear*e2)
|
||||
for (q = 0; q < 3; q++)
|
||||
{
|
||||
|
@ -351,13 +359,13 @@ static void LoadPalette(const char *lumpname)
|
|||
working[2][q] = dolerp(Cubepal[0][0][1][q], Cubepal[1][0][1][q]);
|
||||
working[3][q] = dolerp(Cubepal[0][1][1][q], Cubepal[1][1][1][q]);
|
||||
}
|
||||
linear = (pLocalPalette[i].s.green/255.0);
|
||||
linear = (*green/255.0);
|
||||
for (q = 0; q < 3; q++)
|
||||
{
|
||||
working[0][q] = dolerp(working[0][q], working[1][q]);
|
||||
working[1][q] = dolerp(working[2][q], working[3][q]);
|
||||
}
|
||||
linear = (pLocalPalette[i].s.blue/255.0);
|
||||
linear = (*blue/255.0);
|
||||
for (q = 0; q < 3; q++)
|
||||
{
|
||||
working[0][q] = 255*dolerp(working[0][q], working[1][q]);
|
||||
|
@ -368,11 +376,9 @@ static void LoadPalette(const char *lumpname)
|
|||
}
|
||||
#undef dolerp
|
||||
|
||||
pLocalPalette[i].s.red = (UINT8)(working[0][0]);
|
||||
pLocalPalette[i].s.green = (UINT8)(working[0][1]);
|
||||
pLocalPalette[i].s.blue = (UINT8)(working[0][2]);
|
||||
}
|
||||
}
|
||||
*red = (UINT8)(working[0][0]);
|
||||
*green = (UINT8)(working[0][1]);
|
||||
*blue = (UINT8)(working[0][2]);
|
||||
}
|
||||
|
||||
const char *R_GetPalname(UINT16 num)
|
||||
|
|
|
@ -48,6 +48,8 @@ const char *GetPalette(void);
|
|||
extern RGBA_t *pLocalPalette;
|
||||
extern RGBA_t *pMasterPalette;
|
||||
|
||||
void V_CubeApply(UINT8 *red, UINT8 *green, UINT8 *blue);
|
||||
|
||||
// Retrieve the ARGB value from a palette color index
|
||||
#define V_GetColor(color) (pLocalPalette[color&0xFF])
|
||||
|
||||
|
|
Loading…
Reference in a new issue