mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
Change: Support custom transparency remaps with 32bpp blitters.
This closes a 15 year old TODO...
This commit is contained in:
parent
0bc22dd310
commit
9ce1626bb4
@ -9,6 +9,7 @@
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../video/video_driver.hpp"
|
||||
#include "../palette_func.h"
|
||||
#include "32bpp_anim.hpp"
|
||||
#include "common.hpp"
|
||||
|
||||
@ -190,10 +191,6 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
|
||||
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) {
|
||||
@ -215,6 +212,24 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
|
||||
}
|
||||
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)]);
|
||||
*anim = 0;
|
||||
anim++;
|
||||
dst++;
|
||||
} while (--n != 0);
|
||||
} else {
|
||||
dst += n;
|
||||
anim += n;
|
||||
src_px += n;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (src_px->a == 255) {
|
||||
do {
|
||||
@ -264,6 +279,7 @@ void Blitter_32bppAnim::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL
|
||||
case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom); return;
|
||||
case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP>(bp, zoom); return;
|
||||
case BM_TRANSPARENT: Draw<BM_TRANSPARENT> (bp, zoom); return;
|
||||
case BM_TRANSPARENT_REMAP: Draw<BM_TRANSPARENT_REMAP>(bp, zoom); return;
|
||||
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP> (bp, zoom); return;
|
||||
case BM_BLACK_REMAP: Draw<BM_BLACK_REMAP> (bp, zoom); return;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
/** @file 32bpp_anim_sse4.cpp Implementation of the SSE4 32 bpp blitter with animation support. */
|
||||
|
||||
#include "palette_func.h"
|
||||
#ifdef WITH_SSE
|
||||
|
||||
#include "../stdafx.h"
|
||||
@ -317,6 +318,21 @@ bmcr_alpha_blend_single:
|
||||
}
|
||||
break;
|
||||
|
||||
case BM_TRANSPARENT_REMAP:
|
||||
/* Apply custom transparency remap. */
|
||||
for (uint x = (uint) bp->width; x > 0; x--) {
|
||||
if (src->a != 0) {
|
||||
*dst = this->LookupColourInPalette(bp->remap[GetNearestColourIndex(*dst)]);
|
||||
*anim = 0;
|
||||
}
|
||||
src_mv++;
|
||||
dst++;
|
||||
src++;
|
||||
anim++;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case BM_CRASH_REMAP:
|
||||
for (uint x = (uint) bp->width; x > 0; x--) {
|
||||
if (src_mv->m == 0) {
|
||||
@ -351,7 +367,7 @@ bmcr_alpha_blend_single:
|
||||
}
|
||||
|
||||
next_line:
|
||||
if (mode != BM_TRANSPARENT) src_mv_line += si->sprite_width;
|
||||
if (mode != BM_TRANSPARENT && mode != BM_TRANSPARENT_REMAP) src_mv_line += si->sprite_width;
|
||||
src_rgba_line = (const Colour*) ((const byte*) src_rgba_line + si->sprite_line_size);
|
||||
dst_line += bp->pitch;
|
||||
anim_line += this->anim_buf_pitch;
|
||||
@ -414,6 +430,7 @@ bm_normal:
|
||||
}
|
||||
break;
|
||||
case BM_TRANSPARENT: Draw<BM_TRANSPARENT, RM_NONE, BT_NONE, true, true>(bp, zoom); return;
|
||||
case BM_TRANSPARENT_REMAP: Draw<BM_TRANSPARENT_REMAP, RM_NONE, BT_NONE, true, true>(bp, zoom); return;
|
||||
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP, RM_NONE, BT_NONE, true, true>(bp, zoom); return;
|
||||
case BM_BLACK_REMAP: Draw<BM_BLACK_REMAP, RM_NONE, BT_NONE, true, true>(bp, zoom); return;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../zoom_func.h"
|
||||
#include "../palette_func.h"
|
||||
#include "32bpp_simple.hpp"
|
||||
|
||||
#include "../table/sprites.h"
|
||||
@ -63,12 +64,17 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
|
||||
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 */
|
||||
if (src->a != 0) *dst = MakeTransparent(*dst, 192);
|
||||
if (src->a != 0) {
|
||||
*dst = MakeTransparent(*dst, 192);
|
||||
}
|
||||
break;
|
||||
|
||||
case BM_TRANSPARENT_REMAP:
|
||||
/* Apply custom transparency remap. */
|
||||
if (src->a != 0) {
|
||||
*dst = this->LookupColourInPalette(bp->remap[GetNearestColourIndex(*dst)]);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -392,6 +392,18 @@ bmcr_alpha_blend_single:
|
||||
}
|
||||
break;
|
||||
|
||||
case BM_TRANSPARENT_REMAP:
|
||||
/* Apply custom transparency remap. */
|
||||
for (uint x = (uint) bp->width; x > 0; x--) {
|
||||
if (src->a != 0) {
|
||||
*dst = this->LookupColourInPalette(bp->remap[GetNearestColourIndex(*dst)]);
|
||||
}
|
||||
src_mv++;
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
break;
|
||||
|
||||
case BM_CRASH_REMAP:
|
||||
for (uint x = (uint) bp->width; x > 0; x--) {
|
||||
if (src_mv->m == 0) {
|
||||
@ -471,6 +483,7 @@ bm_normal:
|
||||
Draw<BM_COLOUR_REMAP, RM_WITH_MARGIN, BT_NONE, true>(bp, zoom); return;
|
||||
}
|
||||
case BM_TRANSPARENT: Draw<BM_TRANSPARENT, RM_NONE, BT_NONE, true>(bp, zoom); return;
|
||||
case BM_TRANSPARENT_REMAP: Draw<BM_TRANSPARENT_REMAP, RM_NONE, BT_NONE, true>(bp, zoom); return;
|
||||
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP, RM_NONE, BT_NONE, true>(bp, zoom); return;
|
||||
case BM_BLACK_REMAP: Draw<BM_BLACK_REMAP, RM_NONE, BT_NONE, true>(bp, zoom); return;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "../zoom_func.h"
|
||||
#include "../settings_type.h"
|
||||
#include "../video/video_driver.hpp"
|
||||
#include "../palette_func.h"
|
||||
#include "40bpp_anim.hpp"
|
||||
#include "common.hpp"
|
||||
|
||||
@ -234,10 +235,6 @@ inline void Blitter_40bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
|
||||
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) {
|
||||
@ -263,6 +260,28 @@ inline void Blitter_40bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
|
||||
}
|
||||
break;
|
||||
|
||||
case BM_TRANSPARENT_REMAP:
|
||||
/* Apply custom transparency remap. */
|
||||
src_n += n;
|
||||
if (src_px->a != 0) {
|
||||
src_px += n;
|
||||
do {
|
||||
if (*anim != 0) {
|
||||
*anim = bp->remap[*anim];
|
||||
} else {
|
||||
*dst = this->LookupColourInPalette(bp->remap[GetNearestColourIndex(*dst)]);
|
||||
*anim = 0;
|
||||
}
|
||||
anim++;
|
||||
dst++;
|
||||
} while (--n != 0);
|
||||
} else {
|
||||
dst += n;
|
||||
anim += n;
|
||||
src_px += n;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (src_px->a == 255) {
|
||||
do {
|
||||
@ -323,6 +342,7 @@ void Blitter_40bppAnim::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL
|
||||
case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom); return;
|
||||
case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP>(bp, zoom); return;
|
||||
case BM_TRANSPARENT: Draw<BM_TRANSPARENT> (bp, zoom); return;
|
||||
case BM_TRANSPARENT_REMAP: Draw<BM_TRANSPARENT_REMAP>(bp, zoom); return;
|
||||
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP> (bp, zoom); return;
|
||||
case BM_BLACK_REMAP: Draw<BM_BLACK_REMAP> (bp, zoom); return;
|
||||
}
|
||||
|
@ -100,7 +100,8 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
|
||||
dst += pixels;
|
||||
break;
|
||||
|
||||
case BM_TRANSPARENT: {
|
||||
case BM_TRANSPARENT:
|
||||
case BM_TRANSPARENT_REMAP: {
|
||||
const uint8_t *remap = bp->remap;
|
||||
src += pixels;
|
||||
do {
|
||||
|
@ -42,6 +42,7 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
|
||||
break;
|
||||
|
||||
case BM_TRANSPARENT:
|
||||
case BM_TRANSPARENT_REMAP:
|
||||
if (*src != 0) colour = bp->remap[*dst];
|
||||
break;
|
||||
|
||||
|
@ -17,7 +17,8 @@
|
||||
enum BlitterMode {
|
||||
BM_NORMAL, ///< Perform the simple blitting.
|
||||
BM_COLOUR_REMAP, ///< Perform a colour remapping.
|
||||
BM_TRANSPARENT, ///< Perform transparency colour remapping.
|
||||
BM_TRANSPARENT, ///< Perform transparency darkening remapping.
|
||||
BM_TRANSPARENT_REMAP, ///< Perform transparency colour remapping.
|
||||
BM_CRASH_REMAP, ///< Perform a crash remapping.
|
||||
BM_BLACK_REMAP, ///< Perform remapping to a completely blackened sprite
|
||||
};
|
||||
|
10
src/gfx.cpp
10
src/gfx.cpp
@ -978,8 +978,9 @@ void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSpri
|
||||
{
|
||||
SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
|
||||
if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
|
||||
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
|
||||
GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_TRANSPARENT, sub, real_sprite);
|
||||
pal = GB(pal, 0, PALETTE_WIDTH);
|
||||
_colour_remap_ptr = GetNonSprite(pal, SpriteType::Recolour) + 1;
|
||||
GfxMainBlitterViewport(GetSprite(real_sprite, SpriteType::Normal), x, y, pal == PALETTE_TO_TRANSPARENT ? BM_TRANSPARENT : BM_TRANSPARENT_REMAP, sub, real_sprite);
|
||||
} else if (pal != PAL_NONE) {
|
||||
if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
|
||||
SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
|
||||
@ -1005,8 +1006,9 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub,
|
||||
{
|
||||
SpriteID real_sprite = GB(img, 0, SPRITE_WIDTH);
|
||||
if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
|
||||
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), SpriteType::Recolour) + 1;
|
||||
GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
|
||||
pal = GB(pal, 0, PALETTE_WIDTH);
|
||||
_colour_remap_ptr = GetNonSprite(pal, SpriteType::Recolour) + 1;
|
||||
GfxMainBlitter(GetSprite(real_sprite, SpriteType::Normal), x, y, pal == PALETTE_TO_TRANSPARENT ? BM_TRANSPARENT : BM_TRANSPARENT_REMAP, sub, real_sprite, zoom);
|
||||
} else if (pal != PAL_NONE) {
|
||||
if (HasBit(pal, PALETTE_TEXT_RECOLOUR)) {
|
||||
SetColourRemap((TextColour)GB(pal, 0, PALETTE_WIDTH));
|
||||
|
Loading…
Reference in New Issue
Block a user