Add color indexes to 32bpp sprites to make color remaps work

This commit is contained in:
dP
2020-08-09 21:23:49 +03:00
parent bc4ce66ee2
commit 44a331c926
6 changed files with 31 additions and 7 deletions

View File

@@ -36,7 +36,7 @@ public:
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override; void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override;
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override { Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override {
return Blitter_32bppSSE_Base::Encode(sprite, allocator); return Blitter_32bppSSE_Base::Encode(sprite, allocator, this);
} }
const char *GetName() override { return "32bpp-sse4-anim"; } const char *GetName() override { return "32bpp-sse4-anim"; }
}; };

View File

@@ -154,6 +154,28 @@ public:
return ReallyAdjustBrightness(colour, brightness); return ReallyAdjustBrightness(colour, brightness);
} }
/* CM */
uint8 cm_mdict[64*64*64] = {0};
uint8 CM_GetMForRGB(uint8 r, uint8 g, uint8 b) {
r &= 252; g &= 252; b &= 252;
auto key = (r << 10) | (g << 4) | (b >> 2);
auto m = this->cm_mdict[key];
if (m != 0) return m;
uint md = UINT_MAX;
for (uint8 i = 1; i < 0xc0; i++) {
auto c = this->LookupColourInPalette(i);
auto dist = ((uint)c.r - r) * ((uint)c.r - r) + ((uint)c.g - g) * ((uint)c.g - g) + ((uint)c.b - b) * ((uint)c.b - b);
if (dist < md) {
md = dist;
m = i;
}
}
this->cm_mdict[key] = m;
return m;
}
}; };
#endif /* BLITTER_32BPP_BASE_HPP */ #endif /* BLITTER_32BPP_BASE_HPP */

View File

@@ -339,6 +339,7 @@ Sprite *Blitter_32bppOptimized::Encode(const SpriteLoader::Sprite *sprite, Alloc
dst_px->r = src->r; dst_px->r = src->r;
dst_px->g = src->g; dst_px->g = src->g;
dst_px->b = src->b; dst_px->b = src->b;
*dst_n = this->CM_GetMForRGB(src->r, src->g, src->b) | (DEFAULT_BRIGHTNESS << 8);
} }
dst_px++; dst_px++;
dst_n++; dst_n++;

View File

@@ -84,7 +84,6 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal) void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
{ {
Colour *udst = (Colour *)dst; Colour *udst = (Colour *)dst;
if (pal == PALETTE_TO_TRANSPARENT) { if (pal == PALETTE_TO_TRANSPARENT) {
do { do {
for (int i = 0; i != width; i++) { for (int i = 0; i != width; i++) {
@@ -128,8 +127,8 @@ Sprite *Blitter_32bppSimple::Encode(const SpriteLoader::Sprite *sprite, Allocato
dst[i].g = src->g; dst[i].g = src->g;
dst[i].b = src->b; dst[i].b = src->b;
dst[i].a = src->a; dst[i].a = src->a;
dst[i].m = 0; dst[i].m = this->CM_GetMForRGB(src->r, src->g, src->b);
dst[i].v = 0; dst[i].v = DEFAULT_BRIGHTNESS;
} else { } else {
/* Get brightest value */ /* Get brightest value */
uint8 rgb_max = max(src->r, max(src->g, src->b)); uint8 rgb_max = max(src->r, max(src->g, src->b));

View File

@@ -20,7 +20,7 @@
/** Instantiation of the SSE2 32bpp blitter factory. */ /** Instantiation of the SSE2 32bpp blitter factory. */
static FBlitter_32bppSSE2 iFBlitter_32bppSSE2; static FBlitter_32bppSSE2 iFBlitter_32bppSSE2;
Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator, Blitter_32bppSimple *base_blitter)
{ {
/* First uint32 of a line = the number of transparent pixels from the left. /* First uint32 of a line = the number of transparent pixels from the left.
* Second uint32 of a line = the number of transparent pixels from the right. * Second uint32 of a line = the number of transparent pixels from the right.
@@ -89,9 +89,11 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, Alloca
dst_rgba->g = colour.g; dst_rgba->g = colour.g;
dst_rgba->b = colour.b; dst_rgba->b = colour.b;
} else { } else {
has_remap = true;
dst_rgba->r = src->r; dst_rgba->r = src->r;
dst_rgba->g = src->g; dst_rgba->g = src->g;
dst_rgba->b = src->b; dst_rgba->b = src->b;
dst_mv->m = base_blitter->CM_GetMForRGB(src->r, src->g, src->b);
dst_mv->v = Blitter_32bppBase::DEFAULT_BRIGHTNESS; dst_mv->v = Blitter_32bppBase::DEFAULT_BRIGHTNESS;
} }
} else { } else {

View File

@@ -72,7 +72,7 @@ public:
byte data[]; ///< Data, all zoomlevels. byte data[]; ///< Data, all zoomlevels.
}; };
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator); Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator, Blitter_32bppSimple *base_blitter);
}; };
DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags); DECLARE_ENUM_AS_BIT_SET(Blitter_32bppSSE_Base::SpriteFlags);
@@ -85,7 +85,7 @@ public:
void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom);
Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override { Sprite *Encode(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) override {
return Blitter_32bppSSE_Base::Encode(sprite, allocator); return Blitter_32bppSSE_Base::Encode(sprite, allocator, this);
} }
const char *GetName() override { return "32bpp-sse2"; } const char *GetName() override { return "32bpp-sse2"; }