summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-10-06 18:45:51 +0000
committerrubidium <rubidium@openttd.org>2014-10-06 18:45:51 +0000
commit9c31ffd893efd0310e1276d179150ba2e9c2c4aa (patch)
tree9a71a2e1445452b4d96fbfc548a535d94c83c30f
parente5a92d7093ff354cac1101354e5e89e584b24bb4 (diff)
downloadopenttd-9c31ffd893efd0310e1276d179150ba2e9c2c4aa.tar.xz
(svn r26969) -Fix (r26869): black palette didn't work very well with unmasked 32bpp sprites
-rw-r--r--src/blitter/32bpp_anim.cpp11
-rw-r--r--src/blitter/32bpp_anim_sse4.cpp14
-rw-r--r--src/blitter/32bpp_optimized.cpp10
-rw-r--r--src/blitter/32bpp_simple.cpp6
-rw-r--r--src/blitter/32bpp_sse_func.hpp12
-rw-r--r--src/blitter/8bpp_optimized.cpp8
-rw-r--r--src/blitter/8bpp_simple.cpp4
-rw-r--r--src/blitter/base.hpp1
-rw-r--r--src/gfx.cpp19
9 files changed, 82 insertions, 3 deletions
diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp
index 6127ff3a0..353afa14a 100644
--- a/src/blitter/32bpp_anim.cpp
+++ b/src/blitter/32bpp_anim.cpp
@@ -175,6 +175,16 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
}
break;
+
+ case BM_BLACK_REMAP:
+ do {
+ *dst++ = Colour(0, 0, 0);
+ *anim++ = 0;
+ anim++;
+ dst++;
+ } while (--n != 0);
+ 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:
@@ -251,6 +261,7 @@ void Blitter_32bppAnim::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL
case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP>(bp, zoom); return;
case BM_TRANSPARENT: Draw<BM_TRANSPARENT> (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;
}
}
diff --git a/src/blitter/32bpp_anim_sse4.cpp b/src/blitter/32bpp_anim_sse4.cpp
index f25683a10..7d4b66fca 100644
--- a/src/blitter/32bpp_anim_sse4.cpp
+++ b/src/blitter/32bpp_anim_sse4.cpp
@@ -334,6 +334,19 @@ bmcr_alpha_blend_single:
anim++;
}
break;
+
+ case BM_BLACK_REMAP:
+ for (uint x = (uint) bp->width; x > 0; x--) {
+ if (src->a != 0) {
+ *dst = Colour(0, 0, 0);
+ *anim = 0;
+ }
+ src_mv++;
+ dst++;
+ src++;
+ anim++;
+ }
+ break;
}
next_line:
@@ -395,6 +408,7 @@ bm_normal:
break;
case BM_TRANSPARENT: Draw<BM_TRANSPARENT, 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;
}
}
diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp
index 9b7d7115c..cc056f5b5 100644
--- a/src/blitter/32bpp_optimized.cpp
+++ b/src/blitter/32bpp_optimized.cpp
@@ -177,6 +177,15 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL
}
break;
+ case BM_BLACK_REMAP:
+ do {
+ *dst = Colour(0, 0, 0);
+ dst++;
+ src_px++;
+ src_n++;
+ } while (--n != 0);
+ 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:
@@ -241,6 +250,7 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode,
case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP>(bp, zoom); return;
case BM_TRANSPARENT: Draw<BM_TRANSPARENT> (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;
}
}
diff --git a/src/blitter/32bpp_simple.cpp b/src/blitter/32bpp_simple.cpp
index 0ad7418db..92375be16 100644
--- a/src/blitter/32bpp_simple.cpp
+++ b/src/blitter/32bpp_simple.cpp
@@ -58,6 +58,12 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
}
break;
+ case BM_BLACK_REMAP:
+ if (src->a != 0) {
+ *dst = Colour(0, 0, 0);
+ }
+ 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:
diff --git a/src/blitter/32bpp_sse_func.hpp b/src/blitter/32bpp_sse_func.hpp
index 6b60ba664..69d951cd2 100644
--- a/src/blitter/32bpp_sse_func.hpp
+++ b/src/blitter/32bpp_sse_func.hpp
@@ -394,6 +394,17 @@ bmcr_alpha_blend_single:
src++;
}
break;
+
+ case BM_BLACK_REMAP:
+ for (uint x = (uint) bp->width; x > 0; x--) {
+ if (src->a != 0) {
+ *dst = Colour(0, 0, 0);
+ }
+ src_mv++;
+ dst++;
+ src++;
+ }
+ break;
}
next_line:
@@ -447,6 +458,7 @@ bm_normal:
}
case BM_TRANSPARENT: Draw<BM_TRANSPARENT, 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;
}
}
#endif /* FULL_ANIMATION */
diff --git a/src/blitter/8bpp_optimized.cpp b/src/blitter/8bpp_optimized.cpp
index bcd8dc282..0f07e7c7b 100644
--- a/src/blitter/8bpp_optimized.cpp
+++ b/src/blitter/8bpp_optimized.cpp
@@ -13,6 +13,7 @@
#include "../zoom_func.h"
#include "../settings_type.h"
#include "../core/math_func.hpp"
+#include "../core/mem_func.hpp"
#include "8bpp_optimized.hpp"
#include "../safeguards.h"
@@ -96,6 +97,11 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
break;
}
+ case BM_BLACK_REMAP:
+ MemSetT(dst, 0, pixels);
+ dst += pixels;
+ break;
+
case BM_TRANSPARENT: {
const uint8 *remap = bp->remap;
src += pixels;
@@ -107,7 +113,7 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
}
default:
- memcpy(dst, src, pixels);
+ MemCpyT(dst, src, pixels);
dst += pixels; src += pixels;
break;
}
diff --git a/src/blitter/8bpp_simple.cpp b/src/blitter/8bpp_simple.cpp
index d24d8caac..ed5dd3f7a 100644
--- a/src/blitter/8bpp_simple.cpp
+++ b/src/blitter/8bpp_simple.cpp
@@ -47,6 +47,10 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
if (*src != 0) colour = bp->remap[*dst];
break;
+ case BM_BLACK_REMAP:
+ colour = 0;
+ break;
+
default:
colour = *src;
break;
diff --git a/src/blitter/base.hpp b/src/blitter/base.hpp
index 3314eddfe..a9403b339 100644
--- a/src/blitter/base.hpp
+++ b/src/blitter/base.hpp
@@ -21,6 +21,7 @@ enum BlitterMode {
BM_COLOUR_REMAP, ///< Perform a colour remapping.
BM_TRANSPARENT, ///< Perform transparency colour remapping.
BM_CRASH_REMAP, ///< Perform a crash remapping.
+ BM_BLACK_REMAP, ///< Perform remapping to a completely blackened sprite
};
/**
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 5a1f75abc..f6d9e0b98 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -783,6 +783,21 @@ Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
}
/**
+ * Helper function to get the blitter mode for different types of palettes.
+ * @param pal The palette to get the blitter mode for.
+ * @return The blitter mode associated with the palette.
+ */
+static BlitterMode GetBlitterMode(PaletteID pal)
+{
+ switch (pal) {
+ case PAL_NONE: return BM_NORMAL;
+ case PALETTE_CRASH: return BM_CRASH_REMAP;
+ case PALETTE_ALL_BLACK: return BM_BLACK_REMAP;
+ default: return BM_COLOUR_REMAP;
+ }
+}
+
+/**
* Draw a sprite in a viewport.
* @param img Image number to draw
* @param pal Palette to use.
@@ -802,7 +817,7 @@ void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSpri
} else {
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
}
- GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, pal == PALETTE_CRASH ? BM_CRASH_REMAP : BM_COLOUR_REMAP, sub, real_sprite);
+ GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite);
} else {
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite);
}
@@ -829,7 +844,7 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub,
} else {
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
}
- GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, pal == PALETTE_CRASH ? BM_CRASH_REMAP : BM_COLOUR_REMAP, sub, real_sprite, zoom);
+ GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, GetBlitterMode(pal), sub, real_sprite, zoom);
} else {
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom);
}