Change: Support custom transparency remaps with 32bpp blitters.

This closes a 15 year old TODO...
This commit is contained in:
Peter Nelson
2023-12-22 16:01:33 +00:00
committed by Peter Nelson
parent 0bc22dd310
commit 9ce1626bb4
10 changed files with 114 additions and 24 deletions

View File

@@ -10,6 +10,7 @@
#include "../stdafx.h"
#include "../zoom_func.h"
#include "../settings_type.h"
#include "../palette_func.h"
#include "32bpp_optimized.hpp"
#include "../safeguards.h"
@@ -185,10 +186,6 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL
break;
case BM_TRANSPARENT:
/* TODO -- We make an assumption here that the remap in fact is transparency, not some colour.
* This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
* we produce a result the newgrf maker didn't expect ;) */
/* Make the current colour a bit more black, so it looks like this image is transparent */
src_n += n;
if (src_px->a == 255) {
@@ -206,6 +203,21 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL
}
break;
case BM_TRANSPARENT_REMAP:
/* Apply custom transparency remap. */
src_n += n;
if (src_px->a != 0) {
src_px += n;
do {
*dst = this->LookupColourInPalette(bp->remap[GetNearestColourIndex(*dst)]);
dst++;
} while (--n != 0);
} else {
dst += n;
src_px += n;
}
break;
default:
if (src_px->a == 255) {
/* faster than memcpy(), n is usually low */
@@ -252,6 +264,7 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode,
case BM_NORMAL: Draw<BM_NORMAL, Tpal_to_rgb>(bp, zoom); return;
case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP, Tpal_to_rgb>(bp, zoom); return;
case BM_TRANSPARENT: Draw<BM_TRANSPARENT, Tpal_to_rgb>(bp, zoom); return;
case BM_TRANSPARENT_REMAP: Draw<BM_TRANSPARENT_REMAP, Tpal_to_rgb>(bp, zoom); return;
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP, Tpal_to_rgb>(bp, zoom); return;
case BM_BLACK_REMAP: Draw<BM_BLACK_REMAP, Tpal_to_rgb>(bp, zoom); return;
}