From 4626492f50f311d67f2b660c88b19487d07e7401 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 3 Jul 2011 10:47:35 +0000 Subject: [PATCH] - separated all colormap related code from v_palette.cpp and r_data.cpp into its own file. SVN r3245 (trunk) --- src/CMakeLists.txt | 1 + src/am_map.cpp | 1 + src/fragglescript/t_func.cpp | 1 + src/g_game.cpp | 1 + src/g_level.cpp | 1 + src/g_shared/a_artifacts.cpp | 1 + src/p_3dfloors.cpp | 2 +- src/p_buildmap.cpp | 2 +- src/p_lnspec.cpp | 1 + src/p_mobj.cpp | 1 + src/p_saveg.cpp | 1 + src/p_sectors.cpp | 2 +- src/p_setup.cpp | 1 + src/p_udmf.cpp | 1 + src/r_bsp.cpp | 1 + src/r_data.cpp | 274 +---------- src/r_data.h | 6 - src/r_draw.cpp | 1 + src/r_main.cpp | 1 + src/r_plane.cpp | 1 + src/r_polymost.cpp | 1 + src/r_segs.cpp | 1 + src/r_things.cpp | 1 + src/r_translate.cpp | 1 + src/resources/colormaps.cpp | 666 +++++++++++++++++++++++++++ src/resources/colormaps.h | 89 ++++ src/sdl/sdlvideo.cpp | 2 - src/textures/bitmap.cpp | 1 + src/textures/multipatchtexture.cpp | 1 + src/thingdef/thingdef_properties.cpp | 1 + src/v_draw.cpp | 1 + src/v_palette.cpp | 299 +----------- src/v_palette.h | 73 +-- src/win32/fb_d3d9.cpp | 1 + zdoom.vcproj | 204 ++++---- 35 files changed, 898 insertions(+), 745 deletions(-) create mode 100644 src/resources/colormaps.cpp create mode 100644 src/resources/colormaps.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d1b302ef68..98d0000d39 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -904,6 +904,7 @@ add_executable( zdoom WIN32 fragglescript/t_spec.cpp fragglescript/t_variable.cpp fragglescript/t_cmd.cpp + resources/colormaps.cpp autozend.cpp ) diff --git a/src/am_map.cpp b/src/am_map.cpp index f669b4c904..4fa8149ae1 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -63,6 +63,7 @@ #include "a_artifacts.h" #include "po_man.h" #include "a_keys.h" +#include "resources/colormaps.h" //============================================================================= // diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 120db9bd0a..5315134eeb 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -65,6 +65,7 @@ #include "g_level.h" #include "v_palette.h" #include "v_font.h" +#include "resources/colormaps.h" static FRandom pr_script("FScript"); diff --git a/src/g_game.cpp b/src/g_game.cpp index 6c07d618e5..12c7af4409 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -79,6 +79,7 @@ #include "d_event.h" #include "p_acs.h" #include "m_joy.h" +#include "resources/colormaps.h" #include diff --git a/src/g_level.cpp b/src/g_level.cpp index 187c7b1aac..20611fc354 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -79,6 +79,7 @@ #include "v_palette.h" #include "menu/menu.h" #include "a_strifeglobal.h" +#include "resources/colormaps.h" #include "gi.h" diff --git a/src/g_shared/a_artifacts.cpp b/src/g_shared/a_artifacts.cpp index 0370e226c4..98f93ebc3d 100644 --- a/src/g_shared/a_artifacts.cpp +++ b/src/g_shared/a_artifacts.cpp @@ -19,6 +19,7 @@ #include "g_level.h" #include "doomstat.h" #include "v_palette.h" +#include "resources/colormaps.h" static FRandom pr_torch ("Torch"); diff --git a/src/p_3dfloors.cpp b/src/p_3dfloors.cpp index efc42361c8..e538b747c1 100644 --- a/src/p_3dfloors.cpp +++ b/src/p_3dfloors.cpp @@ -40,8 +40,8 @@ #include "p_lnspec.h" #include "w_wad.h" #include "sc_man.h" -#include "v_palette.h" #include "g_level.h" +#include "resources/colormaps.h" #ifdef _3DFLOORS diff --git a/src/p_buildmap.cpp b/src/p_buildmap.cpp index cde9cdb2f3..a8c66bb77b 100644 --- a/src/p_buildmap.cpp +++ b/src/p_buildmap.cpp @@ -9,7 +9,6 @@ #include "p_local.h" #include "m_swap.h" -#include "v_palette.h" #include "w_wad.h" #include "templates.h" #include "r_sky.h" @@ -17,6 +16,7 @@ #include "r_defs.h" #include "p_setup.h" #include "g_level.h" +#include "resources/colormaps.h" // MACROS ------------------------------------------------------------------ diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index 7f21756a52..d0506f071a 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -56,6 +56,7 @@ #include "p_3dmidtex.h" #include "d_net.h" #include "d_event.h" +#include "resources/colormaps.h" #define FUNC(a) static int a (line_t *ln, AActor *it, bool backSide, \ int arg0, int arg1, int arg2, int arg3, int arg4) diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index abaf52fb80..457c647110 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -61,6 +61,7 @@ #include "v_palette.h" #include "p_enemy.h" #include "gstrings.h" +#include "resources/colormaps.h" // MACROS ------------------------------------------------------------------ diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index b3baf359b2..b26e0f2444 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -48,6 +48,7 @@ #include "g_level.h" #include "po_man.h" #include "p_setup.h" +#include "resources/colormaps.h" static void CopyPlayer (player_t *dst, player_t *src, const char *name); static void ReadOnePlayer (FArchive &arc, bool skipload); diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 600bf168d6..cff2329282 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -25,7 +25,7 @@ #include "p_spec.h" #include "c_cvars.h" #include "doomstat.h" -#include "v_palette.h" +#include "resources/colormaps.h" // [RH] diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 3db2f99bef..149b7a5199 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -66,6 +66,7 @@ #include "md5.h" #include "compatibility.h" #include "po_man.h" +#include "resources/colormaps.h" #include "fragglescript/t_fs.h" diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp index d8a15595d9..e856265daf 100644 --- a/src/p_udmf.cpp +++ b/src/p_udmf.cpp @@ -43,6 +43,7 @@ #include "g_level.h" #include "v_palette.h" #include "p_udmf.h" +#include "resources/colormaps.h" //=========================================================================== // diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index c7d552e46c..6aab9d645c 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -54,6 +54,7 @@ #include "v_palette.h" #include "r_sky.h" #include "po_man.h" +#include "resources/colormaps.h" int WallMost (short *mostbuf, const secplane_t &plane); diff --git a/src/r_data.cpp b/src/r_data.cpp index edd5e6992e..35225a850a 100644 --- a/src/r_data.cpp +++ b/src/r_data.cpp @@ -46,281 +46,9 @@ #include "r_bsp.h" #include "r_segs.h" #include "v_palette.h" +#include "resources/colormaps.h" -static int R_CountTexturesX (); -static int R_CountLumpTextures (int lumpnum); -static bool R_CheckForFixedLights(const BYTE *colormaps); - -extern void R_DeinitBuildTiles(); -extern int R_CountBuildTiles(); - -struct FakeCmap -{ - char name[8]; - PalEntry blend; - int lump; -}; - -TArray fakecmaps; -BYTE *realcolormaps; -size_t numfakecmaps; - -//========================================================================== -// -// R_SetDefaultColormap -// -//========================================================================== - -void R_SetDefaultColormap (const char *name) -{ - if (strnicmp (fakecmaps[0].name, name, 8) != 0) - { - int lump, i, j; - BYTE map[256]; - BYTE unremap[256]; - BYTE remap[256]; - - // [RH] If using BUILD's palette, generate the colormap - if (Wads.CheckNumForFullName("palette.dat") >= 0 || Wads.CheckNumForFullName("blood.pal") >= 0) - { - Printf ("Make colormap\n"); - FDynamicColormap foo; - - foo.Color = 0xFFFFFF; - foo.Fade = 0; - foo.Maps = realcolormaps; - foo.Desaturate = 0; - foo.Next = NULL; - foo.BuildLights (); - } - else - { - lump = Wads.CheckNumForName (name, ns_colormaps); - if (lump == -1) - lump = Wads.CheckNumForName (name, ns_global); - FWadLump lumpr = Wads.OpenLumpNum (lump); - - // [RH] The colormap may not have been designed for the specific - // palette we are using, so remap it to match the current palette. - memcpy (remap, GPalette.Remap, 256); - memset (unremap, 0, 256); - for (i = 0; i < 256; ++i) - { - unremap[remap[i]] = i; - } - // Mapping to color 0 is okay, because the colormap won't be used to - // produce a masked texture. - remap[0] = 0; - for (i = 0; i < NUMCOLORMAPS; ++i) - { - BYTE *map2 = &realcolormaps[i*256]; - lumpr.Read (map, 256); - for (j = 0; j < 256; ++j) - { - map2[j] = remap[map[unremap[j]]]; - } - } - } - - uppercopy (fakecmaps[0].name, name); - fakecmaps[0].blend = 0; - } -} - -//========================================================================== -// -// R_DeinitColormaps -// -//========================================================================== - -void R_DeinitColormaps () -{ - fakecmaps.Clear(); - if (realcolormaps != NULL) - { - delete[] realcolormaps; - realcolormaps = NULL; - } -} - -//========================================================================== -// -// R_InitColormaps -// -//========================================================================== - -void R_InitColormaps () -{ - // [RH] Try and convert BOOM colormaps into blending values. - // This is a really rough hack, but it's better than - // not doing anything with them at all (right?) - - FakeCmap cm; - - R_DeinitColormaps(); - - cm.name[0] = 0; - cm.blend = 0; - fakecmaps.Push(cm); - - DWORD NumLumps = Wads.GetNumLumps(); - - for (DWORD i = 0; i < NumLumps; i++) - { - if (Wads.GetLumpNamespace(i) == ns_colormaps) - { - char name[9]; - name[8] = 0; - Wads.GetLumpName (name, i); - - if (Wads.CheckNumForName (name, ns_colormaps) == (int)i) - { - strncpy(cm.name, name, 8); - cm.blend = 0; - cm.lump = i; - fakecmaps.Push(cm); - } - } - } - realcolormaps = new BYTE[256*NUMCOLORMAPS*fakecmaps.Size()]; - R_SetDefaultColormap ("COLORMAP"); - - if (fakecmaps.Size() > 1) - { - BYTE unremap[256], remap[256], mapin[256]; - int i; - unsigned j; - - memcpy (remap, GPalette.Remap, 256); - memset (unremap, 0, 256); - for (i = 0; i < 256; ++i) - { - unremap[remap[i]] = i; - } - remap[0] = 0; - for (j = 1; j < fakecmaps.Size(); j++) - { - if (Wads.LumpLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256) - { - int k, r, g, b; - FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump); - BYTE *const map = realcolormaps + NUMCOLORMAPS*256*j; - - for (k = 0; k < NUMCOLORMAPS; ++k) - { - BYTE *map2 = &map[k*256]; - lump.Read (mapin, 256); - map2[0] = 0; - for (r = 1; r < 256; ++r) - { - map2[r] = remap[mapin[unremap[r]]]; - } - } - - r = g = b = 0; - - for (k = 0; k < 256; k++) - { - r += GPalette.BaseColors[map[k]].r; - g += GPalette.BaseColors[map[k]].g; - b += GPalette.BaseColors[map[k]].b; - } - fakecmaps[j].blend = PalEntry (255, r/256, g/256, b/256); - } - } - } - NormalLight.Maps = realcolormaps; - NormalLightHasFixedLights = R_CheckForFixedLights(realcolormaps); - numfakecmaps = fakecmaps.Size(); -} - -//========================================================================== -// -// R_CheckForFixedLights -// -// Returns true if there are any entries in the colormaps that are the -// same for every colormap and not the fade color. -// -//========================================================================== - -static bool R_CheckForFixedLights(const BYTE *colormaps) -{ - const BYTE *lastcolormap = colormaps + (NUMCOLORMAPS - 1) * 256; - BYTE freq[256]; - int i, j; - - // Count the frequencies of different colors in the final colormap. - // If they occur more than X amount of times, we ignore them as a - // potential fixed light. - - memset(freq, 0, sizeof(freq)); - for (i = 0; i < 256; ++i) - { - freq[lastcolormap[i]]++; - } - - // Now check the colormaps for fixed lights that are uncommon in the - // final coloramp. - for (i = 255; i >= 0; --i) - { - BYTE color = lastcolormap[i]; - if (freq[color] > 10) // arbitrary number to decide "common" colors - { - continue; - } - // It's rare in the final colormap. See if it's the same for all colormaps. - for (j = 0; j < NUMCOLORMAPS - 1; ++j) - { - if (colormaps[j * 256 + i] != color) - break; - } - if (j == NUMCOLORMAPS - 1) - { // It was the same all the way across. - return true; - } - } - return false; -} - -//========================================================================== -// -// [RH] Returns an index into realcolormaps. Multiply it by -// 256*NUMCOLORMAPS to find the start of the colormap to use. -// WATERMAP is an exception and returns a blending value instead. -// -//========================================================================== - -DWORD R_ColormapNumForName (const char *name) -{ - if (strnicmp (name, "COLORMAP", 8)) - { // COLORMAP always returns 0 - for(int i=fakecmaps.Size()-1; i > 0; i--) - { - if (!strnicmp(name, fakecmaps[i].name, 8)) - { - return i; - } - } - - if (!strnicmp (name, "WATERMAP", 8)) - return MAKEARGB (128,0,0x4f,0xa5); - } - return 0; -} - -//========================================================================== -// -// R_BlendForColormap -// -//========================================================================== - -DWORD R_BlendForColormap (DWORD map) -{ - return APART(map) ? map : - map < fakecmaps.Size() ? DWORD(fakecmaps[map].blend) : 0; -} - //========================================================================== // // R_InitData diff --git a/src/r_data.h b/src/r_data.h index d2f25dfa97..d0fabccd20 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -136,12 +136,6 @@ void R_PrecacheLevel (void); // Retrieval. -DWORD R_ColormapNumForName(const char *name); // killough 4/4/98 -void R_SetDefaultColormap (const char *name); // [RH] change normal fadetable -DWORD R_BlendForColormap (DWORD map); // [RH] return calculated blend for a colormap -extern BYTE *realcolormaps; // [RH] make the colormaps externally visible -extern size_t numfakecmaps; - int R_FindSkin (const char *name, int pclass); // [RH] Find a skin FVoxel *R_LoadKVX(int lumpnum); diff --git a/src/r_draw.cpp b/src/r_draw.cpp index bbf16b3b3a..918a7bcdb4 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -38,6 +38,7 @@ #include "g_level.h" #include "r_translate.h" #include "v_palette.h" +#include "resources/colormaps.h" #include "gi.h" #include "stats.h" diff --git a/src/r_main.cpp b/src/r_main.cpp index 226480009b..6e0927bb83 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -52,6 +52,7 @@ #include "r_3dfloors.h" #include "v_palette.h" #include "po_man.h" +#include "resources/colormaps.h" // MACROS ------------------------------------------------------------------ diff --git a/src/r_plane.cpp b/src/r_plane.cpp index b7db7082f8..f5e9b571a8 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -57,6 +57,7 @@ #include "r_segs.h" #include "r_3dfloors.h" #include "v_palette.h" +#include "resources/colormaps.h" #ifdef _MSC_VER #pragma warning(disable:4244) diff --git a/src/r_polymost.cpp b/src/r_polymost.cpp index d9e245b896..6832bddbea 100644 --- a/src/r_polymost.cpp +++ b/src/r_polymost.cpp @@ -81,6 +81,7 @@ Low priority: #include "r_bsp.h" #include "v_palette.h" #include "v_font.h" +#include "resources/colormaps.h" EXTERN_CVAR (Int, r_polymost) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 053be097ba..3eac266e41 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -51,6 +51,7 @@ #include "r_segs.h" #include "r_3dfloors.h" #include "v_palette.h" +#include "resources/colormaps.h" #define WALLYREPEAT 8 diff --git a/src/r_things.cpp b/src/r_things.cpp index e49046c62f..86b517626b 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -59,6 +59,7 @@ #include "r_3dfloors.h" #include "v_palette.h" #include "r_translate.h" +#include "resources/colormaps.h" extern fixed_t globaluclip, globaldclip; diff --git a/src/r_translate.cpp b/src/r_translate.cpp index d7e42384e6..fc3d1274ed 100644 --- a/src/r_translate.cpp +++ b/src/r_translate.cpp @@ -47,6 +47,7 @@ #include "doomerrors.h" #include "i_system.h" #include "w_wad.h" +#include "resources/colormaps.h" #include "gi.h" #include "stats.h" diff --git a/src/resources/colormaps.cpp b/src/resources/colormaps.cpp new file mode 100644 index 0000000000..7b36e387da --- /dev/null +++ b/src/resources/colormaps.cpp @@ -0,0 +1,666 @@ +/* +** r_data.cpp +** +**--------------------------------------------------------------------------- +** Copyright 1998-2008 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include +#include +#include +#include + +#include "i_system.h" +#include "w_wad.h" +#include "doomdef.h" +#include "r_local.h" +#include "r_sky.h" +#include "c_dispatch.h" +#include "r_data.h" +#include "sc_man.h" +#include "v_text.h" +#include "st_start.h" +#include "doomstat.h" +#include "r_bsp.h" +#include "r_segs.h" +#include "v_palette.h" +#include "colormatcher.h" +#include "colormaps.h" + +static bool R_CheckForFixedLights(const BYTE *colormaps); + + +extern "C" { +FDynamicColormap NormalLight; +} +bool NormalLightHasFixedLights; + + +struct FakeCmap +{ + char name[8]; + PalEntry blend; + int lump; +}; + +TArray fakecmaps; +BYTE *realcolormaps; +size_t numfakecmaps; + + + +TArray SpecialColormaps; +BYTE DesaturateColormap[31][256]; + +struct FSpecialColormapParameters +{ + float Start[3], End[3]; +}; + +static FSpecialColormapParameters SpecialColormapParms[] = +{ + // Doom invulnerability is an inverted grayscale. + // Strife uses it when firing the Sigil + { { 1, 1, 1 }, { 0, 0, 0 } }, + + // Heretic invulnerability is a golden shade. + { { 0, 0, 0 }, { 1.5, 0.75, 0 }, }, + + // [BC] Build the Doomsphere colormap. It is red! + { { 0, 0, 0 }, { 1.5, 0, 0 } }, + + // [BC] Build the Guardsphere colormap. It's a greenish-white kind of thing. + { { 0, 0, 0 }, { 1.25, 1.5, 1 } }, + + // Build a blue colormap. + { { 0, 0, 0 }, { 0, 0, 1.5 } }, +}; + +static void FreeSpecialLights(); + + + +//========================================================================== +// +// +// +//========================================================================== + +int AddSpecialColormap(float r1, float g1, float b1, float r2, float g2, float b2) +{ + // Clamp these in range for the hardware shader. + r1 = clamp(r1, 0.0f, 2.0f); + g1 = clamp(g1, 0.0f, 2.0f); + b1 = clamp(b1, 0.0f, 2.0f); + r2 = clamp(r2, 0.0f, 2.0f); + g2 = clamp(g2, 0.0f, 2.0f); + b2 = clamp(b2, 0.0f, 2.0f); + + for(unsigned i=0; iColorizeStart[0] = float(r1); + cm->ColorizeStart[1] = float(g1); + cm->ColorizeStart[2] = float(b1); + cm->ColorizeEnd[0] = float(r2); + cm->ColorizeEnd[1] = float(g2); + cm->ColorizeEnd[2] = float(b2); + + r2 -= r1; + g2 -= g1; + b2 -= b1; + r1 *= 255; + g1 *= 255; + b1 *= 255; + + for (int c = 0; c < 256; c++) + { + double intensity = (GPalette.BaseColors[c].r * 77 + + GPalette.BaseColors[c].g * 143 + + GPalette.BaseColors[c].b * 37) / 256.0; + + PalEntry pe = PalEntry( MIN(255, int(r1 + intensity*r2)), + MIN(255, int(g1 + intensity*g2)), + MIN(255, int(b1 + intensity*b2))); + + cm->Colormap[c] = ColorMatcher.Pick(pe); + } + + // This table is used by the texture composition code + for(int i = 0;i < 256; i++) + { + cm->GrayscaleToColor[i] = PalEntry( MIN(255, int(r1 + i*r2)), + MIN(255, int(g1 + i*g2)), + MIN(255, int(b1 + i*b2))); + } + return SpecialColormaps.Size() - 1; +} + + +//========================================================================== +// +// Colored Lighting Stuffs +// +//========================================================================== + +FDynamicColormap *GetSpecialLights (PalEntry color, PalEntry fade, int desaturate) +{ + FDynamicColormap *colormap; + + // If this colormap has already been created, just return it + for (colormap = &NormalLight; colormap != NULL; colormap = colormap->Next) + { + if (color == colormap->Color && + fade == colormap->Fade && + desaturate == colormap->Desaturate) + { + return colormap; + } + } + + // Not found. Create it. + colormap = new FDynamicColormap; + colormap->Next = NormalLight.Next; + colormap->Color = color; + colormap->Fade = fade; + colormap->Desaturate = desaturate; + NormalLight.Next = colormap; + + if (screen->UsesColormap()) + { + colormap->Maps = new BYTE[NUMCOLORMAPS*256]; + colormap->BuildLights (); + } + else colormap->Maps = NULL; + + return colormap; +} + +//========================================================================== +// +// Free all lights created with GetSpecialLights +// +//========================================================================== + +static void FreeSpecialLights() +{ + FDynamicColormap *colormap, *next; + + for (colormap = NormalLight.Next; colormap != NULL; colormap = next) + { + next = colormap->Next; + delete[] colormap->Maps; + delete colormap; + } + NormalLight.Next = NULL; +} + +//========================================================================== +// +// Builds NUMCOLORMAPS colormaps lit with the specified color +// +//========================================================================== + +void FDynamicColormap::BuildLights () +{ + int l, c; + int lr, lg, lb, ld, ild; + PalEntry colors[256], basecolors[256]; + BYTE *shade; + + if (Maps == NULL) + return; + + // Scale light to the range 0-256, so we can avoid + // dividing by 255 in the bottom loop. + lr = Color.r*256/255; + lg = Color.g*256/255; + lb = Color.b*256/255; + ld = Desaturate*256/255; + if (ld < 0) // No negative desaturations, please. + { + ld = -ld; + } + ild = 256-ld; + + if (ld == 0) + { + memcpy (basecolors, GPalette.BaseColors, sizeof(basecolors)); + } + else + { + // Desaturate the palette before lighting it. + for (c = 0; c < 256; c++) + { + int r = GPalette.BaseColors[c].r; + int g = GPalette.BaseColors[c].g; + int b = GPalette.BaseColors[c].b; + int intensity = ((r * 77 + g * 143 + b * 37) >> 8) * ld; + basecolors[c].r = (r*ild + intensity) >> 8; + basecolors[c].g = (g*ild + intensity) >> 8; + basecolors[c].b = (b*ild + intensity) >> 8; + basecolors[c].a = 0; + } + } + + // build normal (but colored) light mappings + for (l = 0; l < NUMCOLORMAPS; l++) + { + DoBlending (basecolors, colors, 256, + Fade.r, Fade.g, Fade.b, l * (256 / NUMCOLORMAPS)); + + shade = Maps + 256*l; + if ((DWORD)Color == MAKERGB(255,255,255)) + { // White light, so we can just pick the colors directly + for (c = 0; c < 256; c++) + { + *shade++ = ColorMatcher.Pick (colors[c].r, colors[c].g, colors[c].b); + } + } + else + { // Colored light, so do the (slightly) slower thing + for (c = 0; c < 256; c++) + { + *shade++ = ColorMatcher.Pick ( + (colors[c].r*lr)>>8, + (colors[c].g*lg)>>8, + (colors[c].b*lb)>>8); + } + } + } +} + +//========================================================================== +// +// +// +//========================================================================== + +void FDynamicColormap::ChangeColor (PalEntry lightcolor, int desaturate) +{ + if (lightcolor != Color || desaturate != Desaturate) + { + Color = lightcolor; + // [BB] desaturate must be in [0,255] + Desaturate = clamp(desaturate, 0, 255); + if (Maps) BuildLights (); + } +} + +//========================================================================== +// +// +// +//========================================================================== + +void FDynamicColormap::ChangeFade (PalEntry fadecolor) +{ + if (fadecolor != Fade) + { + Fade = fadecolor; + if (Maps) BuildLights (); + } +} + +//========================================================================== +// +// +// +//========================================================================== + +void FDynamicColormap::ChangeColorFade (PalEntry lightcolor, PalEntry fadecolor) +{ + if (lightcolor != Color || fadecolor != Fade) + { + Color = lightcolor; + Fade = fadecolor; + if (Maps) BuildLights (); + } +} + +//========================================================================== +// +// +// +//========================================================================== + +void FDynamicColormap::RebuildAllLights() +{ + if (screen->UsesColormap()) + { + FDynamicColormap *cm; + + for (cm = &NormalLight; cm != NULL; cm = cm->Next) + { + if (cm->Maps == NULL) + { + cm->Maps = new BYTE[NUMCOLORMAPS*256]; + cm->BuildLights (); + } + } + } +} + +//========================================================================== +// +// R_SetDefaultColormap +// +//========================================================================== + +void R_SetDefaultColormap (const char *name) +{ + if (strnicmp (fakecmaps[0].name, name, 8) != 0) + { + int lump, i, j; + BYTE map[256]; + BYTE unremap[256]; + BYTE remap[256]; + + // [RH] If using BUILD's palette, generate the colormap + if (Wads.CheckNumForFullName("palette.dat") >= 0 || Wads.CheckNumForFullName("blood.pal") >= 0) + { + Printf ("Make colormap\n"); + FDynamicColormap foo; + + foo.Color = 0xFFFFFF; + foo.Fade = 0; + foo.Maps = realcolormaps; + foo.Desaturate = 0; + foo.Next = NULL; + foo.BuildLights (); + } + else + { + lump = Wads.CheckNumForName (name, ns_colormaps); + if (lump == -1) + lump = Wads.CheckNumForName (name, ns_global); + FWadLump lumpr = Wads.OpenLumpNum (lump); + + // [RH] The colormap may not have been designed for the specific + // palette we are using, so remap it to match the current palette. + memcpy (remap, GPalette.Remap, 256); + memset (unremap, 0, 256); + for (i = 0; i < 256; ++i) + { + unremap[remap[i]] = i; + } + // Mapping to color 0 is okay, because the colormap won't be used to + // produce a masked texture. + remap[0] = 0; + for (i = 0; i < NUMCOLORMAPS; ++i) + { + BYTE *map2 = &realcolormaps[i*256]; + lumpr.Read (map, 256); + for (j = 0; j < 256; ++j) + { + map2[j] = remap[map[unremap[j]]]; + } + } + } + + uppercopy (fakecmaps[0].name, name); + fakecmaps[0].blend = 0; + } +} + +//========================================================================== +// +// R_DeinitColormaps +// +//========================================================================== + +void R_DeinitColormaps () +{ + SpecialColormaps.Clear(); + fakecmaps.Clear(); + if (realcolormaps != NULL) + { + delete[] realcolormaps; + realcolormaps = NULL; + } + FreeSpecialLights(); +} + +//========================================================================== +// +// R_InitColormaps +// +//========================================================================== + +void R_InitColormaps () +{ + // [RH] Try and convert BOOM colormaps into blending values. + // This is a really rough hack, but it's better than + // not doing anything with them at all (right?) + + FakeCmap cm; + + R_DeinitColormaps(); + + cm.name[0] = 0; + cm.blend = 0; + fakecmaps.Push(cm); + + DWORD NumLumps = Wads.GetNumLumps(); + + for (DWORD i = 0; i < NumLumps; i++) + { + if (Wads.GetLumpNamespace(i) == ns_colormaps) + { + char name[9]; + name[8] = 0; + Wads.GetLumpName (name, i); + + if (Wads.CheckNumForName (name, ns_colormaps) == (int)i) + { + strncpy(cm.name, name, 8); + cm.blend = 0; + cm.lump = i; + fakecmaps.Push(cm); + } + } + } + realcolormaps = new BYTE[256*NUMCOLORMAPS*fakecmaps.Size()]; + R_SetDefaultColormap ("COLORMAP"); + + if (fakecmaps.Size() > 1) + { + BYTE unremap[256], remap[256], mapin[256]; + int i; + unsigned j; + + memcpy (remap, GPalette.Remap, 256); + memset (unremap, 0, 256); + for (i = 0; i < 256; ++i) + { + unremap[remap[i]] = i; + } + remap[0] = 0; + for (j = 1; j < fakecmaps.Size(); j++) + { + if (Wads.LumpLength (fakecmaps[j].lump) >= (NUMCOLORMAPS+1)*256) + { + int k, r, g, b; + FWadLump lump = Wads.OpenLumpNum (fakecmaps[j].lump); + BYTE *const map = realcolormaps + NUMCOLORMAPS*256*j; + + for (k = 0; k < NUMCOLORMAPS; ++k) + { + BYTE *map2 = &map[k*256]; + lump.Read (mapin, 256); + map2[0] = 0; + for (r = 1; r < 256; ++r) + { + map2[r] = remap[mapin[unremap[r]]]; + } + } + + r = g = b = 0; + + for (k = 0; k < 256; k++) + { + r += GPalette.BaseColors[map[k]].r; + g += GPalette.BaseColors[map[k]].g; + b += GPalette.BaseColors[map[k]].b; + } + fakecmaps[j].blend = PalEntry (255, r/256, g/256, b/256); + } + } + } + NormalLight.Color = PalEntry (255, 255, 255); + NormalLight.Fade = 0; + NormalLight.Maps = realcolormaps; + NormalLightHasFixedLights = R_CheckForFixedLights(realcolormaps); + numfakecmaps = fakecmaps.Size(); + + // build default special maps (e.g. invulnerability) + + for (unsigned i = 0; i < countof(SpecialColormapParms); ++i) + { + AddSpecialColormap(SpecialColormapParms[i].Start[0], SpecialColormapParms[i].Start[1], + SpecialColormapParms[i].Start[2], SpecialColormapParms[i].End[0], + SpecialColormapParms[i].End[1], SpecialColormapParms[i].End[2]); + } + // desaturated colormaps. These are used for texture composition + for(int m = 0; m < 31; m++) + { + BYTE *shade = DesaturateColormap[m]; + for (int c = 0; c < 256; c++) + { + int intensity = (GPalette.BaseColors[c].r * 77 + + GPalette.BaseColors[c].g * 143 + + GPalette.BaseColors[c].b * 37) / 256; + + int r = (GPalette.BaseColors[c].r * (31-m) + intensity *m) / 31; + int g = (GPalette.BaseColors[c].g * (31-m) + intensity *m) / 31; + int b = (GPalette.BaseColors[c].b * (31-m) + intensity *m) / 31; + shade[c] = ColorMatcher.Pick(r, g, b); + } + } +} + +//========================================================================== +// +// R_CheckForFixedLights +// +// Returns true if there are any entries in the colormaps that are the +// same for every colormap and not the fade color. +// +//========================================================================== + +static bool R_CheckForFixedLights(const BYTE *colormaps) +{ + const BYTE *lastcolormap = colormaps + (NUMCOLORMAPS - 1) * 256; + BYTE freq[256]; + int i, j; + + // Count the frequencies of different colors in the final colormap. + // If they occur more than X amount of times, we ignore them as a + // potential fixed light. + + memset(freq, 0, sizeof(freq)); + for (i = 0; i < 256; ++i) + { + freq[lastcolormap[i]]++; + } + + // Now check the colormaps for fixed lights that are uncommon in the + // final coloramp. + for (i = 255; i >= 0; --i) + { + BYTE color = lastcolormap[i]; + if (freq[color] > 10) // arbitrary number to decide "common" colors + { + continue; + } + // It's rare in the final colormap. See if it's the same for all colormaps. + for (j = 0; j < NUMCOLORMAPS - 1; ++j) + { + if (colormaps[j * 256 + i] != color) + break; + } + if (j == NUMCOLORMAPS - 1) + { // It was the same all the way across. + return true; + } + } + return false; +} + +//========================================================================== +// +// [RH] Returns an index into realcolormaps. Multiply it by +// 256*NUMCOLORMAPS to find the start of the colormap to use. +// WATERMAP is an exception and returns a blending value instead. +// +//========================================================================== + +DWORD R_ColormapNumForName (const char *name) +{ + if (strnicmp (name, "COLORMAP", 8)) + { // COLORMAP always returns 0 + for(int i=fakecmaps.Size()-1; i > 0; i--) + { + if (!strnicmp(name, fakecmaps[i].name, 8)) + { + return i; + } + } + + if (!strnicmp (name, "WATERMAP", 8)) + return MAKEARGB (128,0,0x4f,0xa5); + } + return 0; +} + +//========================================================================== +// +// R_BlendForColormap +// +//========================================================================== + +DWORD R_BlendForColormap (DWORD map) +{ + return APART(map) ? map : + map < fakecmaps.Size() ? DWORD(fakecmaps[map].blend) : 0; +} \ No newline at end of file diff --git a/src/resources/colormaps.h b/src/resources/colormaps.h new file mode 100644 index 0000000000..ba55410a82 --- /dev/null +++ b/src/resources/colormaps.h @@ -0,0 +1,89 @@ +#ifndef __RES_CMAP_H +#define __RES_CMAP_H + +void R_InitColormaps (); +void R_DeinitColormaps (); + +DWORD R_ColormapNumForName(const char *name); // killough 4/4/98 +void R_SetDefaultColormap (const char *name); // [RH] change normal fadetable +DWORD R_BlendForColormap (DWORD map); // [RH] return calculated blend for a colormap +extern BYTE *realcolormaps; // [RH] make the colormaps externally visible +extern size_t numfakecmaps; + + + +struct FDynamicColormap +{ + void ChangeFade (PalEntry fadecolor); + void ChangeColor (PalEntry lightcolor, int desaturate); + void ChangeColorFade (PalEntry lightcolor, PalEntry fadecolor); + void BuildLights (); + static void RebuildAllLights(); + + BYTE *Maps; + PalEntry Color; + PalEntry Fade; + int Desaturate; + FDynamicColormap *Next; +}; + +// For hardware-accelerated weapon sprites in colored sectors +struct FColormapStyle +{ + PalEntry Color; + PalEntry Fade; + int Desaturate; + float FadeLevel; +}; + +enum +{ + NOFIXEDCOLORMAP = -1, + INVERSECOLORMAP, // the inverse map is used explicitly in a few places. +}; + + +struct FSpecialColormap +{ + float ColorizeStart[3]; + float ColorizeEnd[3]; + BYTE Colormap[256]; + PalEntry GrayscaleToColor[256]; +}; + +extern TArray SpecialColormaps; + +// some utility functions to store special colormaps in powerup blends +#define SPECIALCOLORMAP_MASK 0x00b60000 + +inline int MakeSpecialColormap(int index) +{ + assert(index >= 0 && index < 65536); + return index | SPECIALCOLORMAP_MASK; +} + +inline bool IsSpecialColormap(int map) +{ + return (map & 0xFFFF0000) == SPECIALCOLORMAP_MASK; +} + +inline int GetSpecialColormap(int blend) +{ + return IsSpecialColormap(blend) ? blend & 0xFFFF : NOFIXEDCOLORMAP; +} + +int AddSpecialColormap(float r1, float g1, float b1, float r2, float g2, float b2); + + + +extern BYTE DesaturateColormap[31][256]; +extern "C" +{ +extern FDynamicColormap NormalLight; +} +extern bool NormalLightHasFixedLights; + +FDynamicColormap *GetSpecialLights (PalEntry lightcolor, PalEntry fadecolor, int desaturate); + + +#endif \ No newline at end of file diff --git a/src/sdl/sdlvideo.cpp b/src/sdl/sdlvideo.cpp index efff947057..a61efa5ab7 100644 --- a/src/sdl/sdlvideo.cpp +++ b/src/sdl/sdlvideo.cpp @@ -69,8 +69,6 @@ struct MiniModeInfo // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- -void DoBlending (const PalEntry *from, PalEntry *to, int count, int r, int g, int b, int a); - // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // EXTERNAL DATA DECLARATIONS ---------------------------------------------- diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index 26ca3b8e26..beec0d3fb0 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -36,6 +36,7 @@ #include "templates.h" #include "r_translate.h" #include "v_palette.h" +#include "resources/colormaps.h" //=========================================================================== diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index 32cee3aae7..725490127d 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -47,6 +47,7 @@ #include "bitmap.h" #include "colormatcher.h" #include "v_palette.h" +#include "resources/colormaps.h" // On the Alpha, accessing the shorts directly if they aren't aligned on a // 4-byte boundary causes unaligned access warnings. Why it does this at diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 4c3301a138..925c2a6c3f 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -68,6 +68,7 @@ #include "a_morph.h" #include "colormatcher.h" #include "teaminfo.h" +#include "resources/colormaps.h" //========================================================================== diff --git a/src/v_draw.cpp b/src/v_draw.cpp index f22c9c9284..abbf827881 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -52,6 +52,7 @@ #include "templates.h" #include "d_net.h" #include "colormatcher.h" +#include "resources/colormaps.h" // [RH] Stretch values to make a 320x200 image best fit the screen // without using fractional steppings diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 0d6c06f57f..605a57fa7d 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -57,41 +57,9 @@ #include "x86.h" #include "colormatcher.h" #include "v_palette.h" +#include "resources/colormaps.h" -extern "C" { -FDynamicColormap NormalLight; -} -bool NormalLightHasFixedLights; FPalette GPalette; -TArray SpecialColormaps; -BYTE DesaturateColormap[31][256]; - -struct FSpecialColormapParameters -{ - float Start[3], End[3]; -}; - -static FSpecialColormapParameters SpecialColormapParms[] = -{ - // Doom invulnerability is an inverted grayscale. - // Strife uses it when firing the Sigil - { { 1, 1, 1 }, { 0, 0, 0 } }, - - // Heretic invulnerability is a golden shade. - { { 0, 0, 0 }, { 1.5, 0.75, 0 }, }, - - // [BC] Build the Doomsphere colormap. It is red! - { { 0, 0, 0 }, { 1.5, 0, 0 } }, - - // [BC] Build the Guardsphere colormap. It's a greenish-white kind of thing. - { { 0, 0, 0 }, { 1.25, 1.5, 1 } }, - - // Build a blue colormap. - {{ 0, 0, 0 }, { 0, 0, 1.5 } }, -}; - -static void FreeSpecialLights(); - FColorMatcher ColorMatcher; /* Current color blending values */ @@ -377,79 +345,12 @@ static bool FixBuildPalette (BYTE *opal, int lump, bool blood) return true; } -int AddSpecialColormap(float r1, float g1, float b1, float r2, float g2, float b2) -{ - // Clamp these in range for the hardware shader. - r1 = clamp(r1, 0.0f, 2.0f); - g1 = clamp(g1, 0.0f, 2.0f); - b1 = clamp(b1, 0.0f, 2.0f); - r2 = clamp(r2, 0.0f, 2.0f); - g2 = clamp(g2, 0.0f, 2.0f); - b2 = clamp(b2, 0.0f, 2.0f); - - for(unsigned i=0; iColorizeStart[0] = float(r1); - cm->ColorizeStart[1] = float(g1); - cm->ColorizeStart[2] = float(b1); - cm->ColorizeEnd[0] = float(r2); - cm->ColorizeEnd[1] = float(g2); - cm->ColorizeEnd[2] = float(b2); - - r2 -= r1; - g2 -= g1; - b2 -= b1; - r1 *= 255; - g1 *= 255; - b1 *= 255; - - for (int c = 0; c < 256; c++) - { - double intensity = (GPalette.BaseColors[c].r * 77 + - GPalette.BaseColors[c].g * 143 + - GPalette.BaseColors[c].b * 37) / 256.0; - - PalEntry pe = PalEntry( MIN(255, int(r1 + intensity*r2)), - MIN(255, int(g1 + intensity*g2)), - MIN(255, int(b1 + intensity*b2))); - - cm->Colormap[c] = ColorMatcher.Pick(pe); - } - - // This table is used by the texture composition code - for(int i = 0;i < 256; i++) - { - cm->GrayscaleToColor[i] = PalEntry( MIN(255, int(r1 + i*r2)), - MIN(255, int(g1 + i*g2)), - MIN(255, int(b1 + i*b2))); - } - return SpecialColormaps.Size() - 1; -} - void InitPalette () { BYTE pal[768]; - int c; bool usingBuild = false; int lump; - atterm (FreeSpecialLights); - FreeSpecialLights(); - if ((lump = Wads.CheckNumForFullName ("palette.dat")) >= 0 && Wads.LumpLength (lump) >= 768) { usingBuild = FixBuildPalette (pal, lump, false); @@ -478,37 +379,6 @@ void InitPalette () GPalette.BaseColors[0].r, GPalette.BaseColors[0].g, GPalette.BaseColors[0].b, 1, 255); } } - - NormalLight.Color = PalEntry (255, 255, 255); - NormalLight.Fade = 0; - // NormalLight.Maps is set by R_InitColormaps() - - // build default special maps (e.g. invulnerability) - SpecialColormaps.Clear(); - - for (unsigned i = 0; i < countof(SpecialColormapParms); ++i) - { - AddSpecialColormap(SpecialColormapParms[i].Start[0], SpecialColormapParms[i].Start[1], - SpecialColormapParms[i].Start[2], SpecialColormapParms[i].End[0], - SpecialColormapParms[i].End[1], SpecialColormapParms[i].End[2]); - } - // desaturated colormaps - for(int m = 0; m < 31; m++) - { - BYTE *shade = DesaturateColormap[m]; - for (c = 0; c < 256; c++) - { - int intensity = (GPalette.BaseColors[c].r * 77 + - GPalette.BaseColors[c].g * 143 + - GPalette.BaseColors[c].b * 37) / 256; - - int r = (GPalette.BaseColors[c].r * (31-m) + intensity *m) / 31; - int g = (GPalette.BaseColors[c].g * (31-m) + intensity *m) / 31; - int b = (GPalette.BaseColors[c].b * (31-m) + intensity *m) / 31; - shade[c] = ColorMatcher.Pick(r, g, b); - } - } - } extern "C" void STACK_ARGS DoBlending_MMX (const PalEntry *from, PalEntry *to, int count, int r, int g, int b, int a); @@ -736,173 +606,6 @@ void HSVtoRGB (float *r, float *g, float *b, float h, float s, float v) } } -/****** Colored Lighting Stuffs ******/ - -FDynamicColormap *GetSpecialLights (PalEntry color, PalEntry fade, int desaturate) -{ - FDynamicColormap *colormap; - - // If this colormap has already been created, just return it - for (colormap = &NormalLight; colormap != NULL; colormap = colormap->Next) - { - if (color == colormap->Color && - fade == colormap->Fade && - desaturate == colormap->Desaturate) - { - return colormap; - } - } - - // Not found. Create it. - colormap = new FDynamicColormap; - colormap->Next = NormalLight.Next; - colormap->Color = color; - colormap->Fade = fade; - colormap->Desaturate = desaturate; - NormalLight.Next = colormap; - - if (screen->UsesColormap()) - { - colormap->Maps = new BYTE[NUMCOLORMAPS*256]; - colormap->BuildLights (); - } - else colormap->Maps = NULL; - - return colormap; -} - -// Free all lights created with GetSpecialLights -static void FreeSpecialLights() -{ - FDynamicColormap *colormap, *next; - - for (colormap = NormalLight.Next; colormap != NULL; colormap = next) - { - next = colormap->Next; - delete[] colormap->Maps; - delete colormap; - } - NormalLight.Next = NULL; -} - -// Builds NUMCOLORMAPS colormaps lit with the specified color -void FDynamicColormap::BuildLights () -{ - int l, c; - int lr, lg, lb, ld, ild; - PalEntry colors[256], basecolors[256]; - BYTE *shade; - - if (Maps == NULL) - return; - - // Scale light to the range 0-256, so we can avoid - // dividing by 255 in the bottom loop. - lr = Color.r*256/255; - lg = Color.g*256/255; - lb = Color.b*256/255; - ld = Desaturate*256/255; - if (ld < 0) // No negative desaturations, please. - { - ld = -ld; - } - ild = 256-ld; - - if (ld == 0) - { - memcpy (basecolors, GPalette.BaseColors, sizeof(basecolors)); - } - else - { - // Desaturate the palette before lighting it. - for (c = 0; c < 256; c++) - { - int r = GPalette.BaseColors[c].r; - int g = GPalette.BaseColors[c].g; - int b = GPalette.BaseColors[c].b; - int intensity = ((r * 77 + g * 143 + b * 37) >> 8) * ld; - basecolors[c].r = (r*ild + intensity) >> 8; - basecolors[c].g = (g*ild + intensity) >> 8; - basecolors[c].b = (b*ild + intensity) >> 8; - basecolors[c].a = 0; - } - } - - // build normal (but colored) light mappings - for (l = 0; l < NUMCOLORMAPS; l++) - { - DoBlending (basecolors, colors, 256, - Fade.r, Fade.g, Fade.b, l * (256 / NUMCOLORMAPS)); - - shade = Maps + 256*l; - if ((DWORD)Color == MAKERGB(255,255,255)) - { // White light, so we can just pick the colors directly - for (c = 0; c < 256; c++) - { - *shade++ = ColorMatcher.Pick (colors[c].r, colors[c].g, colors[c].b); - } - } - else - { // Colored light, so do the (slightly) slower thing - for (c = 0; c < 256; c++) - { - *shade++ = ColorMatcher.Pick ( - (colors[c].r*lr)>>8, - (colors[c].g*lg)>>8, - (colors[c].b*lb)>>8); - } - } - } -} - -void FDynamicColormap::ChangeColor (PalEntry lightcolor, int desaturate) -{ - if (lightcolor != Color || desaturate != Desaturate) - { - Color = lightcolor; - // [BB] desaturate must be in [0,255] - Desaturate = clamp(desaturate, 0, 255); - if (Maps) BuildLights (); - } -} - -void FDynamicColormap::ChangeFade (PalEntry fadecolor) -{ - if (fadecolor != Fade) - { - Fade = fadecolor; - if (Maps) BuildLights (); - } -} - -void FDynamicColormap::ChangeColorFade (PalEntry lightcolor, PalEntry fadecolor) -{ - if (lightcolor != Color || fadecolor != Fade) - { - Color = lightcolor; - Fade = fadecolor; - if (Maps) BuildLights (); - } -} - -void FDynamicColormap::RebuildAllLights() -{ - if (screen->UsesColormap()) - { - FDynamicColormap *cm; - - for (cm = &NormalLight; cm != NULL; cm = cm->Next) - { - if (cm->Maps == NULL) - { - cm->Maps = new BYTE[NUMCOLORMAPS*256]; - cm->BuildLights (); - } - } - } -} - - CCMD (testcolor) { FString colorstring; diff --git a/src/v_palette.h b/src/v_palette.h index 8d97d9b3fe..5af99f6b78 100644 --- a/src/v_palette.h +++ b/src/v_palette.h @@ -64,80 +64,13 @@ struct FPalette void MakeRemap (const DWORD *colors, BYTE *remap, const BYTE *useful, int numcolors) const; }; -struct FDynamicColormap -{ - void ChangeFade (PalEntry fadecolor); - void ChangeColor (PalEntry lightcolor, int desaturate); - void ChangeColorFade (PalEntry lightcolor, PalEntry fadecolor); - void BuildLights (); - static void RebuildAllLights(); - - BYTE *Maps; - PalEntry Color; - PalEntry Fade; - int Desaturate; - FDynamicColormap *Next; -}; - -// For hardware-accelerated weapon sprites in colored sectors -struct FColormapStyle -{ - PalEntry Color; - PalEntry Fade; - int Desaturate; - float FadeLevel; -}; - -enum -{ - NOFIXEDCOLORMAP = -1, - INVERSECOLORMAP, // the inverse map is used explicitly in a few places. -}; - - -struct FSpecialColormap -{ - float ColorizeStart[3]; - float ColorizeEnd[3]; - BYTE Colormap[256]; - PalEntry GrayscaleToColor[256]; -}; - -extern TArray SpecialColormaps; - -// some utility functions to store special colormaps in powerup blends -#define SPECIALCOLORMAP_MASK 0x00b60000 - -inline int MakeSpecialColormap(int index) -{ - assert(index >= 0 && index < 65536); - return index | SPECIALCOLORMAP_MASK; -} - -inline bool IsSpecialColormap(int map) -{ - return (map & 0xFFFF0000) == SPECIALCOLORMAP_MASK; -} - -inline int GetSpecialColormap(int blend) -{ - return IsSpecialColormap(blend) ? blend & 0xFFFF : NOFIXEDCOLORMAP; -} - -int AddSpecialColormap(float r1, float g1, float b1, float r2, float g2, float b2); - - - -extern BYTE DesaturateColormap[31][256]; extern FPalette GPalette; -extern "C" { -extern FDynamicColormap NormalLight; -} -extern bool NormalLightHasFixedLights; + // The color overlay to use for depleted items #define DIM_OVERLAY MAKEARGB(170,0,0,0) int BestColor (const uint32 *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 InitPalette (); @@ -162,6 +95,4 @@ void V_ForceBlend (int blendr, int blendg, int blendb, int blenda); void RGBtoHSV (float r, float g, float b, float *h, float *s, float *v); void HSVtoRGB (float *r, float *g, float *b, float h, float s, float v); -FDynamicColormap *GetSpecialLights (PalEntry lightcolor, PalEntry fadecolor, int desaturate); - #endif //__V_PALETTE_H__ diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index 2c29ac6efa..48c6423e38 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -71,6 +71,7 @@ #include "doomstat.h" #include "v_palette.h" #include "w_wad.h" +#include "resources/colormaps.h" // MACROS ------------------------------------------------------------------ diff --git a/zdoom.vcproj b/zdoom.vcproj index 3b59d535d0..be3edbd756 100644 --- a/zdoom.vcproj +++ b/zdoom.vcproj @@ -2440,98 +2440,6 @@ > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +