diff --git a/docs/rh-log.txt b/docs/rh-log.txt index d53617049..6b287c387 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,16 @@ +September 22, 2009 (Changes by Graf Zahl) +- Added a check to Dehacked code which tries to set the blend color. + It must set it to 0 if the alpha is 0 to avoid problems with special + colormap detection. +- Changed SPECIALCOLORMAP_MASK again so that it does not interfere with + any valid setting. It must use a value with a 0-alpha because these + are guaranteed not to be produced by the DECORATE code elsewhere. +- Fixed precision issues with AddFixedColormap's search for identical colormaps. +- Added custom colormap support to texture composition code. +- Fixed initialization of FSpecialColormap::GrayscaleToColor. This is not + a mapping from the palette but from a [0,255] grayscale ramp and used to + apply colormaps to true color images for texture composition. + September 21, 2009 - For hardware 2D, apply fixed colormaps when copying to video memory instead of doing it directly during the rendering, in order to improve visual diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 1ac3ff287..b4901bc8a 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -1793,7 +1793,7 @@ static int PatchMisc (int dummy) { Printf ("Bad powerup color description \"%s\" for %s\n", Line2, Line1); } - else + else if (a > 0) { static_cast(GetDefaultByType (types[i]))->BlendColor = PalEntry( BYTE(clamp(a,0.f,1.f)*255.f), @@ -1801,6 +1801,10 @@ static int PatchMisc (int dummy) clamp(g,0,255), clamp(b,0,255)); } + else + { + static_cast(GetDefaultByType (types[i]))->BlendColor = 0; + } } } else diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index a52bd2e37..4b9bd5e1b 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -423,19 +423,19 @@ const BYTE *FMultiPatchTexture::GetColumn (unsigned int column, const Span **spa BYTE *GetBlendMap(PalEntry blend, BYTE *blendwork) { - switch (blend.a==0 ? blend.r : -1) + switch (blend.a==0 ? int(blend) : -1) { case BLEND_ICEMAP: return TranslationToTable(TRANSLATION(TRANSLATION_Standard, 7))->Remap; default: - if (blend.r >= BLEND_SPECIALCOLORMAP1) + if (blend >= BLEND_SPECIALCOLORMAP1) { - return SpecialColormaps[blend.r - BLEND_SPECIALCOLORMAP1].Colormap; + return SpecialColormaps[blend - BLEND_SPECIALCOLORMAP1].Colormap; } - else if (blend.r >= BLEND_DESATURATE1 && blend.r <= BLEND_DESATURATE31) + else if (blend >= BLEND_DESATURATE1 && blend <= BLEND_DESATURATE31) { - return DesaturateColormap[blend.r - BLEND_DESATURATE1]; + return DesaturateColormap[blend - BLEND_DESATURATE1]; } else { @@ -1048,17 +1048,17 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part) match = sc.MatchString(maps); if (match >= 0) { - part.Blend.r = BLEND_SPECIALCOLORMAP1 + match; + part.Blend = BLEND_SPECIALCOLORMAP1 + match; } else if (sc.Compare("ICE")) { - part.Blend.r = BLEND_ICEMAP; + part.Blend = BLEND_ICEMAP; } else if (sc.Compare("DESATURATE")) { sc.MustGetStringName(","); sc.MustGetNumber(); - part.Blend.r = BLEND_DESATURATE1 + clamp(sc.Number-1, 0, 30); + part.Blend = BLEND_DESATURATE1 + clamp(sc.Number-1, 0, 30); } else { @@ -1074,6 +1074,36 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part) } } + else if (sc.Compare("Colormap")) + { + float r1,g1,b1; + float r2,g2,b2; + + sc.MustGetFloat(); + r1 = (float)sc.Float; + sc.MustGetStringName(","); + sc.MustGetFloat(); + g1 = (float)sc.Float; + sc.MustGetStringName(","); + sc.MustGetFloat(); + b1 = (float)sc.Float; + if (!sc.CheckString(",")) + { + part.Blend = AddSpecialColormap(0,0,0, r1, g1, b1); + } + else + { + sc.MustGetFloat(); + r2 = (float)sc.Float; + sc.MustGetStringName(","); + sc.MustGetFloat(); + g2 = (float)sc.Float; + sc.MustGetStringName(","); + sc.MustGetFloat(); + b2 = (float)sc.Float; + part.Blend = AddSpecialColormap(r1, g1, b1, r2, g2, b2); + } + } else if (sc.Compare("Blend")) { bComplex = true; @@ -1100,10 +1130,14 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part) sc.MustGetStringName(","); part.Blend = MAKERGB(r, g, b); } + // Blend.a may never be 0 here. if (sc.CheckString(",")) { sc.MustGetFloat(); - part.Blend.a = clamp(int(sc.Float*255), 1, 254); + if (sc.Float > 0.f) + part.Blend.a = clamp(int(sc.Float*255), 1, 254); + else + part.Blend = 0; } else part.Blend.a = 255; } diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 2a32d3160..155a8942c 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -1601,7 +1601,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(powerup, color, C_f, Inventory) else alpha = 255/3; alpha=clamp(alpha, 0, 255); - if (alpha!=0) *pBlendColor = MAKEARGB(alpha, 0, 0, 0) | color; + if (alpha != 0) *pBlendColor = MAKEARGB(alpha, 0, 0, 0) | color; else *pBlendColor = 0; } diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 043e006fa..fa7a09bc5 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #ifdef _WIN32 #include #else @@ -360,24 +361,25 @@ static bool FixBuildPalette (BYTE *opal, int lump, bool blood) return true; } -int AddSpecialColormap(double r1, double g1, double b1, double r2, double g2, double b2) +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.0, 2.0); - g1 = clamp(g1, 0.0, 2.0); - b1 = clamp(b1, 0.0, 2.0); - r2 = clamp(r2, 0.0, 2.0); - g2 = clamp(g2, 0.0, 2.0); - b2 = clamp(b2, 0.0, 2.0); + 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; iColormap[c] = ColorMatcher.Pick(pe); // This table is used by the texture composition code - cm->GrayscaleToColor[c] = pe; + 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; } diff --git a/src/v_palette.h b/src/v_palette.h index 30bc9e8cf..453365d53 100644 --- a/src/v_palette.h +++ b/src/v_palette.h @@ -106,7 +106,7 @@ struct FSpecialColormap extern TArray SpecialColormaps; // some utility functions to store special colormaps in powerup blends -#define SPECIALCOLORMAP_MASK 0xBEEF0000 +#define SPECIALCOLORMAP_MASK 0x00b60000 inline int MakeSpecialColormap(int index) { @@ -124,7 +124,7 @@ inline int GetSpecialColormap(int blend) return IsSpecialColormap(blend) ? blend & 0xFFFF : NOFIXEDCOLORMAP; } -int AddSpecialColormap(double r1, double g1, double b1, double r2, double g2, double b2); +int AddSpecialColormap(float r1, float g1, float b1, float r2, float g2, float b2);