- 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.

SVN r1867 (trunk)
This commit is contained in:
Christoph Oelckers 2009-09-22 08:06:52 +00:00
parent d502655866
commit 9cc67f565c
6 changed files with 85 additions and 27 deletions

View file

@ -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

View file

@ -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<APowerup *>(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<APowerup *>(GetDefaultByType (types[i]))->BlendColor = 0;
}
}
}
else

View file

@ -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>(int(sc.Float*255), 1, 254);
if (sc.Float > 0.f)
part.Blend.a = clamp<int>(int(sc.Float*255), 1, 254);
else
part.Blend = 0;
}
else part.Blend.a = 255;
}

View file

@ -1601,7 +1601,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(powerup, color, C_f, Inventory)
else alpha = 255/3;
alpha=clamp<int>(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;
}

View file

@ -35,6 +35,7 @@
#include <stddef.h>
#include <string.h>
#include <math.h>
#include <float.h>
#ifdef _WIN32
#include <io.h>
#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; i<SpecialColormaps.Size(); i++)
{
if (SpecialColormaps[i].ColorizeStart[0] == r1 &&
SpecialColormaps[i].ColorizeStart[1] == g1 &&
SpecialColormaps[i].ColorizeStart[2] == b1 &&
SpecialColormaps[i].ColorizeEnd[0] == r2 &&
SpecialColormaps[i].ColorizeEnd[1] == g2 &&
SpecialColormaps[i].ColorizeEnd[2] == b2)
// Avoid precision issues here when trying to find a proper match.
if (fabs(SpecialColormaps[i].ColorizeStart[0]- r1) < FLT_EPSILON &&
fabs(SpecialColormaps[i].ColorizeStart[1]- g1) < FLT_EPSILON &&
fabs(SpecialColormaps[i].ColorizeStart[2]- b1) < FLT_EPSILON &&
fabs(SpecialColormaps[i].ColorizeEnd[0]- r2) < FLT_EPSILON &&
fabs(SpecialColormaps[i].ColorizeEnd[1]- g2) < FLT_EPSILON &&
fabs(SpecialColormaps[i].ColorizeEnd[2]- b2) < FLT_EPSILON)
{
return i; // The map already exists
}
@ -412,7 +414,12 @@ int AddSpecialColormap(double r1, double g1, double b1, double r2, double g2, do
cm->Colormap[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;
}

View file

@ -106,7 +106,7 @@ struct FSpecialColormap
extern TArray<FSpecialColormap> 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);