]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - palette.c
reworked transparency in palettes, made palette_complete be strictly opaque, added...
[xonotic/darkplaces.git] / palette.c
index 67bcd0cccbac6a26b3b2ff34e2392f9780b89f18..c536b332e90b1891dd1bcd60c76ac6fd9bf21214 100644 (file)
--- a/palette.c
+++ b/palette.c
@@ -2,14 +2,15 @@
 #include "quakedef.h"
 
 unsigned int palette_complete[256];
+unsigned int palette_font[256];
+unsigned int palette_alpha[256];
+unsigned int palette_nocolormap[256];
+unsigned int palette_nocolormapnofullbrights[256];
 unsigned int palette_nofullbrights[256];
 unsigned int palette_onlyfullbrights[256];
-unsigned int palette_nocolormapnofullbrights[256];
-unsigned int palette_nocolormap[256];
 unsigned int palette_pantsaswhite[256];
 unsigned int palette_shirtaswhite[256];
-unsigned int palette_alpha[256];
-unsigned int palette_font[256];
+unsigned int palette_transparent[256];
 
 // John Carmack said the quake palette.lmp can be considered public domain because it is not an important asset to id, so I include it here as a fallback if no external palette file is found.
 unsigned char host_quakepal[768] =
@@ -29,10 +30,12 @@ void Palette_SetupSpecialPalettes(void)
        int pants_start, pants_end;
        int shirt_start, shirt_end;
        int reversed_start, reversed_end;
+       int transparentcolor;
        unsigned char *colormap;
+       fs_offset_t filesize;
 
-       colormap = FS_LoadFile("gfx/colormap.lmp", tempmempool, true);
-       if (colormap && fs_filesize >= 16385)
+       colormap = FS_LoadFile("gfx/colormap.lmp", tempmempool, true, &filesize);
+       if (colormap && filesize >= 16385)
                fullbright_start = 256 - colormap[16384];
        else
                fullbright_start = 256;
@@ -45,18 +48,21 @@ void Palette_SetupSpecialPalettes(void)
        shirt_end = 32;
        reversed_start = 128;
        reversed_end = 224;
+       transparentcolor = 255;
+
+       for (i = 0;i < 256;i++)
+               palette_transparent[i] = palette_complete[i];
+       palette_transparent[transparentcolor] = 0;
 
        for (i = 0;i < fullbright_start;i++)
                palette_nofullbrights[i] = palette_complete[i];
-       for (i = fullbright_start;i < 255;i++)
+       for (i = fullbright_start;i < fullbright_end;i++)
                palette_nofullbrights[i] = palette_complete[0];
-       palette_nofullbrights[255] = 0;
 
        for (i = 0;i < 256;i++)
                palette_onlyfullbrights[i] = palette_complete[0];
        for (i = fullbright_start;i < fullbright_end;i++)
                palette_onlyfullbrights[i] = palette_complete[i];
-       palette_onlyfullbrights[255] = 0;
 
        for (i = 0;i < 256;i++)
                palette_nocolormapnofullbrights[i] = palette_complete[i];
@@ -66,7 +72,6 @@ void Palette_SetupSpecialPalettes(void)
                palette_nocolormapnofullbrights[i] = palette_complete[0];
        for (i = fullbright_start;i < fullbright_end;i++)
                palette_nocolormapnofullbrights[i] = palette_complete[0];
-       palette_nocolormapnofullbrights[255] = 0;
 
        for (i = 0;i < 256;i++)
                palette_nocolormap[i] = palette_complete[i];
@@ -74,7 +79,6 @@ void Palette_SetupSpecialPalettes(void)
                palette_nocolormap[i] = palette_complete[0];
        for (i = shirt_start;i < shirt_end;i++)
                palette_nocolormap[i] = palette_complete[0];
-       palette_nocolormap[255] = 0;
 
        for (i = 0;i < 256;i++)
                palette_pantsaswhite[i] = palette_complete[0];
@@ -96,14 +100,13 @@ void Palette_SetupSpecialPalettes(void)
                        palette_shirtaswhite[i] = palette_complete[i - shirt_start];
        }
 
-       for (i = 0;i < 255;i++)
+       for (i = 0;i < 256;i++)
                palette_alpha[i] = 0xFFFFFFFF;
-       palette_alpha[255] = 0;
+       palette_alpha[transparentcolor] = 0;
 
-       palette_font[0] = 0;
-       for (i = 1;i < 255;i++)
+       for (i = 0;i < 256;i++)
                palette_font[i] = palette_complete[i];
-       palette_font[255] = 0;
+       palette_font[0] = 0;
 }
 
 void BuildGammaTable8(float prescale, float gamma, float scale, float base, unsigned char *out)
@@ -164,6 +167,7 @@ void Palette_Init(void)
 {
        int i;
        float gamma, scale, base;
+       fs_offset_t filesize;
        unsigned char *in, *out, *palfile;
        unsigned char texturegammaramp[256];
 
@@ -188,8 +192,8 @@ void Palette_Init(void)
 
        BuildGammaTable8(1.0f, gamma, scale, base, texturegammaramp);
 
-       palfile = (unsigned char *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false);
-       if (palfile && fs_filesize >= 768)
+       palfile = (unsigned char *)FS_LoadFile ("gfx/palette.lmp", tempmempool, false, &filesize);
+       if (palfile && filesize >= 768)
                in = palfile;
        else
        {
@@ -197,14 +201,13 @@ void Palette_Init(void)
                in = host_quakepal;
        }
        out = (unsigned char *) palette_complete; // palette is accessed as 32bit for speed reasons, but is created as 8bit bytes
-       for (i = 0;i < 255;i++)
+       for (i = 0;i < 256;i++)
        {
                *out++ = texturegammaramp[*in++];
                *out++ = texturegammaramp[*in++];
                *out++ = texturegammaramp[*in++];
                *out++ = 255;
        }
-       palette_complete[255] = 0; // completely transparent black
        if (palfile)
                Mem_Free(palfile);