diff options
author | peter1138 <peter1138@openttd.org> | 2014-04-13 19:22:23 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2014-04-13 19:22:23 +0000 |
commit | 209d3e2e9e95a0d096fd2c18b0d95597edab78f2 (patch) | |
tree | 4f4738577099ef79d94e703764277961efd7db6c /src | |
parent | 5fe053988f5b6060a68244096e385dcbe01fc9db (diff) | |
download | openttd-209d3e2e9e95a0d096fd2c18b0d95597edab78f2.tar.xz |
(svn r26463) -Fix (r10190ish): Add special handling for PALETTE_CRASH to work for non-8bpp-mapped sprites.
Diffstat (limited to 'src')
-rw-r--r-- | src/blitter/32bpp_anim.cpp | 41 | ||||
-rw-r--r-- | src/blitter/32bpp_anim_sse4.cpp | 20 | ||||
-rw-r--r-- | src/blitter/32bpp_base.hpp | 13 | ||||
-rw-r--r-- | src/blitter/32bpp_optimized.cpp | 35 | ||||
-rw-r--r-- | src/blitter/32bpp_simple.cpp | 11 | ||||
-rw-r--r-- | src/blitter/32bpp_sse_func.hpp | 24 | ||||
-rw-r--r-- | src/blitter/8bpp_optimized.cpp | 3 | ||||
-rw-r--r-- | src/blitter/8bpp_simple.cpp | 1 | ||||
-rw-r--r-- | src/blitter/base.hpp | 1 | ||||
-rw-r--r-- | src/gfx.cpp | 4 |
10 files changed, 147 insertions, 6 deletions
diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp index 7681d25ed..80ec54da4 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -133,6 +133,46 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel } break; + case BM_CRASH_REMAP: + if (src_px->a == 255) { + do { + uint m = *src_n; + if (m == 0) { + uint8 g = MakeDark(src_px->r, src_px->g, src_px->b); + *dst = ComposeColourRGBA(g, g, g, src_px->a, *dst); + *anim = 0; + } else { + uint r = remap[GB(m, 0, 8)]; + *anim = r | (m & 0xFF00); + if (r != 0) *dst = this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)); + } + anim++; + dst++; + src_px++; + src_n++; + } while (--n != 0); + } else { + do { + uint m = *src_n; + if (m == 0) { + if (src_px->a != 0) { + uint8 g = MakeDark(src_px->r, src_px->g, src_px->b); + *dst = ComposeColourRGBA(g, g, g, src_px->a, *dst); + *anim = 0; + } + } else { + uint r = remap[GB(m, 0, 8)]; + *anim = 0; + if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)), src_px->a, *dst); + } + anim++; + 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: @@ -208,6 +248,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_CRASH_REMAP: Draw<BM_CRASH_REMAP> (bp, zoom); return; } } diff --git a/src/blitter/32bpp_anim_sse4.cpp b/src/blitter/32bpp_anim_sse4.cpp index 004e32076..d456da22d 100644 --- a/src/blitter/32bpp_anim_sse4.cpp +++ b/src/blitter/32bpp_anim_sse4.cpp @@ -313,6 +313,25 @@ bmcr_alpha_blend_single: if (src[0].a) anim[0] = 0; } break; + + case BM_CRASH_REMAP: + for (uint x = (uint) bp->width; x > 0; x--) { + if (src_mv->m == 0) { + if (src->a != 0) { + uint8 g = MakeDark(src->r, src->g, src->b); + *dst = ComposeColourRGBA(g, g, g, src->a, *dst); + *anim = 0; + } + } else { + uint r = remap[src_mv->m]; + if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), src_mv->v), src->a, *dst); + } + src_mv++; + dst++; + src++; + anim++; + } + break; } next_line: @@ -373,6 +392,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; } } diff --git a/src/blitter/32bpp_base.hpp b/src/blitter/32bpp_base.hpp index ca58f0353..26c3dee3f 100644 --- a/src/blitter/32bpp_base.hpp +++ b/src/blitter/32bpp_base.hpp @@ -113,6 +113,19 @@ public: } /** + * Make a colour dark grey, for specialized 32bpp remapping. + * @param r red component + * @param g green component + * @param b blue component + * @return the brightness value of the new colour, now dark grey. + */ + static inline uint8 MakeDark(uint8 r, uint8 g, uint8 b) + { + /* Magic-numbers are ~66% of those used in MakeGrey() */ + return ((r * 13063) + (g * 25647) + (b * 4981)) / 65536; + } + + /** * Make a colour grey - based. * @param colour the colour to make grey. * @return the new colour, now grey. diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp index 4911e8314..5d2332883 100644 --- a/src/blitter/32bpp_optimized.cpp +++ b/src/blitter/32bpp_optimized.cpp @@ -141,6 +141,40 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL } break; + case BM_CRASH_REMAP: + if (src_px->a == 255) { + do { + uint m = *src_n; + if (m == 0) { + uint8 g = MakeDark(src_px->r, src_px->g, src_px->b); + *dst = ComposeColourRGBA(g, g, g, src_px->a, *dst); + } else { + uint r = remap[GB(m, 0, 8)]; + if (r != 0) *dst = this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)); + } + dst++; + src_px++; + src_n++; + } while (--n != 0); + } else { + do { + uint m = *src_n; + if (m == 0) { + if (src_px->a != 0) { + uint8 g = MakeDark(src_px->r, src_px->g, src_px->b); + *dst = ComposeColourRGBA(g, g, g, src_px->a, *dst); + } + } else { + uint r = remap[GB(m, 0, 8)]; + if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)), src_px->a, *dst); + } + 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: @@ -204,6 +238,7 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, 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_CRASH_REMAP: Draw<BM_CRASH_REMAP> (bp, zoom); return; } } diff --git a/src/blitter/32bpp_simple.cpp b/src/blitter/32bpp_simple.cpp index 4a9036a13..30443c50b 100644 --- a/src/blitter/32bpp_simple.cpp +++ b/src/blitter/32bpp_simple.cpp @@ -45,6 +45,17 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo } break; + case BM_CRASH_REMAP: + if (src->m == 0) { + if (src->a != 0) { + uint8 g = MakeDark(src->r, src->g, src->b); + *dst = ComposeColourRGBA(g, g, g, src->a, *dst); + } + } else { + if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->AdjustBrightness(this->LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst); + } + 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 f0469d66e..6b60ba664 100644 --- a/src/blitter/32bpp_sse_func.hpp +++ b/src/blitter/32bpp_sse_func.hpp @@ -238,13 +238,13 @@ inline void Blitter_32bppSSE4::Draw(const Blitter::BlitterParams *bp, ZoomLevel for (int y = bp->height; y != 0; y--) { Colour *dst = dst_line; const Colour *src = src_rgba_line + META_LENGTH; - if (mode == BM_COLOUR_REMAP) src_mv = src_mv_line; + if (mode == BM_COLOUR_REMAP || mode == BM_CRASH_REMAP) src_mv = src_mv_line; if (read_mode == RM_WITH_MARGIN) { assert(bt_last == BT_NONE); // or you must ensure block type is preserved src += src_rgba_line[0].data; dst += src_rgba_line[0].data; - if (mode == BM_COLOUR_REMAP) src_mv += src_rgba_line[0].data; + if (mode == BM_COLOUR_REMAP || mode == BM_CRASH_REMAP) src_mv += src_rgba_line[0].data; const int width_diff = si->sprite_width - bp->width; effective_width = bp->width - (int) src_rgba_line[0].data; const int delta_diff = (int) src_rgba_line[1].data - width_diff; @@ -377,10 +377,27 @@ bmcr_alpha_blend_single: dst->data = _mm_cvtsi128_si32(DarkenTwoPixels(srcABCD, dstABCD, DARKEN_PARAM_1, DARKEN_PARAM_2)); } break; + + case BM_CRASH_REMAP: + for (uint x = (uint) bp->width; x > 0; x--) { + if (src_mv->m == 0) { + if (src->a != 0) { + uint8 g = MakeDark(src->r, src->g, src->b); + *dst = ComposeColourRGBA(g, g, g, src->a, *dst); + } + } else { + uint r = remap[src_mv->m]; + if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), src_mv->v), src->a, *dst); + } + src_mv++; + dst++; + src++; + } + break; } next_line: - if (mode == BM_COLOUR_REMAP) src_mv_line += si->sprite_width; + if (mode == BM_COLOUR_REMAP || mode == BM_CRASH_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; } @@ -429,6 +446,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_CRASH_REMAP: Draw<BM_CRASH_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 c84e7aea7..31661c360 100644 --- a/src/blitter/8bpp_optimized.cpp +++ b/src/blitter/8bpp_optimized.cpp @@ -83,7 +83,8 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z width -= pixels; switch (mode) { - case BM_COLOUR_REMAP: { + case BM_COLOUR_REMAP: + case BM_CRASH_REMAP: { const uint8 *remap = bp->remap; do { uint m = remap[*src]; diff --git a/src/blitter/8bpp_simple.cpp b/src/blitter/8bpp_simple.cpp index d1bd316bb..d98cff1c9 100644 --- a/src/blitter/8bpp_simple.cpp +++ b/src/blitter/8bpp_simple.cpp @@ -37,6 +37,7 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom switch (mode) { case BM_COLOUR_REMAP: + case BM_CRASH_REMAP: colour = bp->remap[*src]; break; diff --git a/src/blitter/base.hpp b/src/blitter/base.hpp index 00851eeef..3314eddfe 100644 --- a/src/blitter/base.hpp +++ b/src/blitter/base.hpp @@ -20,6 +20,7 @@ enum BlitterMode { BM_NORMAL, ///< Perform the simple blitting. BM_COLOUR_REMAP, ///< Perform a colour remapping. BM_TRANSPARENT, ///< Perform transparency colour remapping. + BM_CRASH_REMAP, ///< Perform a crash remapping. }; /** diff --git a/src/gfx.cpp b/src/gfx.cpp index a6ab37a23..40cea78c0 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -788,7 +788,7 @@ void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSpri GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite); } else if (pal != PAL_NONE) { _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1; - GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_COLOUR_REMAP, sub, real_sprite); + GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, pal == PALETTE_CRASH ? BM_CRASH_REMAP : BM_COLOUR_REMAP, sub, real_sprite); } else { GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite); } @@ -811,7 +811,7 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom); } else if (pal != PAL_NONE) { _colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1; - GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_COLOUR_REMAP, sub, real_sprite, zoom); + GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, pal == PALETTE_CRASH ? BM_CRASH_REMAP : BM_COLOUR_REMAP, sub, real_sprite, zoom); } else { GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom); } |