diff options
author | peter1138 <peter1138@openttd.org> | 2011-12-24 23:33:45 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2011-12-24 23:33:45 +0000 |
commit | 3ef77e55c5d552a58555f3d5eb7b7079b537fff3 (patch) | |
tree | 4a5d1131661b9fb4e94bf9409f089dae84f65f6e /src/blitter | |
parent | dc497258d68ebcd19f4e2512e7255aca344bfff0 (diff) | |
download | openttd-3ef77e55c5d552a58555f3d5eb7b7079b537fff3.tar.xz |
(svn r23670) -Feature: Add ability to adjust brightness of colour after remapping for 32bpp sprites
Diffstat (limited to 'src/blitter')
-rw-r--r-- | src/blitter/32bpp_anim.cpp | 85 | ||||
-rw-r--r-- | src/blitter/32bpp_anim.hpp | 2 | ||||
-rw-r--r-- | src/blitter/32bpp_base.hpp | 28 | ||||
-rw-r--r-- | src/blitter/32bpp_optimized.cpp | 37 | ||||
-rw-r--r-- | src/blitter/32bpp_simple.cpp | 36 | ||||
-rw-r--r-- | src/blitter/32bpp_simple.hpp | 8 |
6 files changed, 130 insertions, 66 deletions
diff --git a/src/blitter/32bpp_anim.cpp b/src/blitter/32bpp_anim.cpp index bb14d4608..c35713058 100644 --- a/src/blitter/32bpp_anim.cpp +++ b/src/blitter/32bpp_anim.cpp @@ -25,27 +25,27 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel const SpriteData *src = (const SpriteData *)bp->sprite; const Colour *src_px = (const Colour *)(src->data + src->offset[zoom][0]); - const uint8 *src_n = (const uint8 *)(src->data + src->offset[zoom][1]); + const uint16 *src_n = (const uint16 *)(src->data + src->offset[zoom][1]); for (uint i = bp->skip_top; i != 0; i--) { src_px = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px); - src_n += *(const uint32 *)src_n; + src_n = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n); } uint32 *dst = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left; - uint8 *anim = this->anim_buf + ((uint32 *)bp->dst - (uint32 *)_screen.dst_ptr) + bp->top * this->anim_buf_width + bp->left; + uint16 *anim = this->anim_buf + ((uint32 *)bp->dst - (uint32 *)_screen.dst_ptr) + bp->top * this->anim_buf_width + bp->left; const byte *remap = bp->remap; // store so we don't have to access it via bp everytime for (int y = 0; y < bp->height; y++) { uint32 *dst_ln = dst + bp->pitch; - uint8 *anim_ln = anim + this->anim_buf_width; + uint16 *anim_ln = anim + this->anim_buf_width; const Colour *src_px_ln = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px); src_px++; - const uint8 *src_n_ln = src_n + *(const uint32 *)src_n; - src_n += 4; + const uint16 *src_n_ln = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n); + src_n += 2; uint32 *dst_end = dst + bp->skip_left; @@ -106,9 +106,9 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel *dst = src_px->data; *anim = 0; } else { - uint r = remap[m]; - *anim = r; - if (r != 0) *dst = this->LookupColourInPalette(r); + 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++; @@ -122,9 +122,9 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel *dst = ComposeColourRGBANoCheck(src_px->r, src_px->g, src_px->b, src_px->a, *dst); *anim = 0; } else { - uint r = remap[m]; + uint r = remap[GB(m, 0, 8)]; *anim = 0; - if (r != 0) *dst = ComposeColourPANoCheck(this->LookupColourInPalette(r), src_px->a, *dst); + if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)), src_px->a, *dst); } anim++; dst++; @@ -145,14 +145,14 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel src_px += n; do { *dst = MakeTransparent(*dst, 3, 4); - *anim = remap[*anim]; + *anim = 0; anim++; dst++; } while (--n != 0); } else { do { *dst = MakeTransparent(*dst, (256 * 4 - src_px->a), 256 * 4); - *anim = remap[*anim]; + *anim = 0; anim++; dst++; src_px++; @@ -164,23 +164,25 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel if (src_px->a == 255) { do { /* Compiler assumes pointer aliasing, can't optimise this on its own */ - uint m = *src_n++; + uint m = GB(*src_n, 0, 8); /* Above PALETTE_ANIM_START is palette animation */ - *anim++ = m; - *dst++ = (m >= PALETTE_ANIM_START) ? this->LookupColourInPalette(m) : src_px->data; + *anim++ = *src_n; + *dst++ = (m >= PALETTE_ANIM_START) ? this->AdjustBrightness(this->LookupColourInPalette(m), GB(*src_n, 8, 8)) : src_px->data; src_px++; + src_n++; } while (--n != 0); } else { do { - uint m = *src_n++; + uint m = GB(*src_n, 0, 8); *anim++ = 0; if (m >= PALETTE_ANIM_START) { - *dst = ComposeColourPANoCheck(this->LookupColourInPalette(m), src_px->a, *dst); + *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(m), GB(*src_n, 8, 8)), src_px->a, *dst); } else { *dst = ComposeColourRGBANoCheck(src_px->r, src_px->g, src_px->b, src_px->a, *dst); } dst++; src_px++; + src_n++; } while (--n != 0); } break; @@ -219,7 +221,7 @@ void Blitter_32bppAnim::DrawColourMappingRect(void *dst, int width, int height, } uint32 *udst = (uint32 *)dst; - uint8 *anim; + uint16 *anim; anim = this->anim_buf + ((uint32 *)dst - (uint32 *)_screen.dst_ptr); @@ -259,7 +261,7 @@ void Blitter_32bppAnim::SetPixel(void *video, int x, int y, uint8 colour) /* Set the colour in the anim-buffer too, if we are rendering to the screen */ if (_screen_disable_anim) return; - this->anim_buf[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y * this->anim_buf_width] = colour; + this->anim_buf[((uint32 *)video - (uint32 *)_screen.dst_ptr) + x + y * this->anim_buf_width] = colour | (DEFAULT_BRIGHTNESS << 8); } void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 colour) @@ -271,18 +273,18 @@ void Blitter_32bppAnim::DrawRect(void *video, int width, int height, uint8 colou } uint32 colour32 = LookupColourInPalette(colour); - uint8 *anim_line; + uint16 *anim_line; anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf; do { uint32 *dst = (uint32 *)video; - uint8 *anim = anim_line; + uint16 *anim = anim_line; for (int i = width; i > 0; i--) { *dst = colour32; /* Set the colour in the anim-buffer too */ - *anim = colour; + *anim = colour | (DEFAULT_BRIGHTNESS << 8); dst++; anim++; } @@ -297,19 +299,19 @@ void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width, assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch); uint32 *dst = (uint32 *)video; const uint32 *usrc = (const uint32 *)src; - uint8 *anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf; + uint16 *anim_line = ((uint32 *)video - (uint32 *)_screen.dst_ptr) + this->anim_buf; for (; height > 0; height--) { /* We need to keep those for palette animation. */ uint32 *dst_pal = dst; - uint8 *anim_pal = anim_line; + uint16 *anim_pal = anim_line; memcpy(dst, usrc, width * sizeof(uint32)); usrc += width; dst += _screen.pitch; /* Copy back the anim-buffer */ - memcpy(anim_line, usrc, width * sizeof(uint8)); - usrc = (const uint32 *)((const uint8 *)usrc + width); + memcpy(anim_line, usrc, width * sizeof(uint16)); + usrc = (const uint32 *)((const uint16 *)usrc + width); anim_line += this->anim_buf_width; /* Okay, it is *very* likely that the image we stored is using @@ -320,10 +322,10 @@ void Blitter_32bppAnim::CopyFromBuffer(void *video, const void *src, int width, * for just the cursor. This just copies the implementation of * palette animation, much cheaper though slightly nastier. */ for (int i = 0; i < width; i++) { - uint colour = *anim_pal; + uint colour = GB(*anim_pal, 0, 8); if (IsInsideBS(colour, PALETTE_ANIM_START, PALETTE_ANIM_SIZE)) { /* Update this pixel */ - *dst_pal = LookupColourInPalette(colour); + *dst_pal = this->AdjustBrightness(LookupColourInPalette(colour), GB(*anim_pal, 8, 8)); } dst_pal++; anim_pal++; @@ -337,7 +339,7 @@ void Blitter_32bppAnim::CopyToBuffer(const void *video, void *dst, int width, in assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch); uint32 *udst = (uint32 *)dst; const uint32 *src = (const uint32 *)video; - const uint8 *anim_line; + const uint16 *anim_line; if (this->anim_buf == NULL) return; @@ -348,8 +350,8 @@ void Blitter_32bppAnim::CopyToBuffer(const void *video, void *dst, int width, in src += _screen.pitch; udst += width; /* Copy the anim-buffer */ - memcpy(udst, anim_line, width * sizeof(uint8)); - udst = (uint32 *)((uint8 *)udst + width); + memcpy(udst, anim_line, width * sizeof(uint16)); + udst = (uint32 *)((uint16 *)udst + width); anim_line += this->anim_buf_width; } } @@ -358,7 +360,7 @@ void Blitter_32bppAnim::ScrollBuffer(void *video, int &left, int &top, int &widt { assert(!_screen_disable_anim); assert(video >= _screen.dst_ptr && video <= (uint32 *)_screen.dst_ptr + _screen.width + _screen.height * _screen.pitch); - uint8 *dst, *src; + uint16 *dst, *src; /* We need to scroll the anim-buffer too */ if (scroll_y > 0) { @@ -375,7 +377,7 @@ void Blitter_32bppAnim::ScrollBuffer(void *video, int &left, int &top, int &widt uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x); uint th = height - scroll_y; for (; th > 0; th--) { - memcpy(dst, src, tw * sizeof(uint8)); + memcpy(dst, src, tw * sizeof(uint16)); src -= this->anim_buf_width; dst -= this->anim_buf_width; } @@ -396,7 +398,7 @@ void Blitter_32bppAnim::ScrollBuffer(void *video, int &left, int &top, int &widt uint tw = width + (scroll_x >= 0 ? -scroll_x : scroll_x); uint th = height + scroll_y; for (; th > 0; th--) { - memmove(dst, src, tw * sizeof(uint8)); + memmove(dst, src, tw * sizeof(uint16)); src += this->anim_buf_width; dst += this->anim_buf_width; } @@ -407,7 +409,7 @@ void Blitter_32bppAnim::ScrollBuffer(void *video, int &left, int &top, int &widt int Blitter_32bppAnim::BufferSize(int width, int height) { - return width * height * (sizeof(uint32) + sizeof(uint8)); + return width * height * (sizeof(uint32) + sizeof(uint16)); } void Blitter_32bppAnim::PaletteAnimate(const Palette &palette) @@ -421,16 +423,19 @@ void Blitter_32bppAnim::PaletteAnimate(const Palette &palette) this->palette.count_dirty--; } - const uint8 *anim = this->anim_buf; + this->palette.first_dirty = 1; + this->palette.count_dirty = 255; + + const uint16 *anim = this->anim_buf; uint32 *dst = (uint32 *)_screen.dst_ptr; /* Let's walk the anim buffer and try to find the pixels */ for (int y = this->anim_buf_height; y != 0 ; y--) { for (int x = this->anim_buf_width; x != 0 ; x--) { - uint colour = *anim; + uint colour = GB(*anim, 0, 8); if (IsInsideBS(colour, this->palette.first_dirty, this->palette.count_dirty)) { /* Update this pixel */ - *dst = LookupColourInPalette(colour); + *dst = this->AdjustBrightness(LookupColourInPalette(colour), GB(*anim, 8, 8)); } dst++; anim++; @@ -452,7 +457,7 @@ void Blitter_32bppAnim::PostResize() if (_screen.width != this->anim_buf_width || _screen.height != this->anim_buf_height) { /* The size of the screen changed; we can assume we can wipe all data from our buffer */ free(this->anim_buf); - this->anim_buf = CallocT<uint8>(_screen.width * _screen.height); + this->anim_buf = CallocT<uint16>(_screen.width * _screen.height); this->anim_buf_width = _screen.width; this->anim_buf_height = _screen.height; } diff --git a/src/blitter/32bpp_anim.hpp b/src/blitter/32bpp_anim.hpp index b1a5da5b4..73cabb90d 100644 --- a/src/blitter/32bpp_anim.hpp +++ b/src/blitter/32bpp_anim.hpp @@ -17,7 +17,7 @@ /** The optimised 32 bpp blitter with palette animation. */ class Blitter_32bppAnim FINAL : public Blitter_32bppOptimized { private: - uint8 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation + uint16 *anim_buf; ///< In this buffer we keep track of the 8bpp indexes so we can do palette animation int anim_buf_width; ///< The width of the animation buffer. int anim_buf_height; ///< The height of the animation buffer. Palette palette; ///< The current palette. diff --git a/src/blitter/32bpp_base.hpp b/src/blitter/32bpp_base.hpp index 1e7a22aad..686677caf 100644 --- a/src/blitter/32bpp_base.hpp +++ b/src/blitter/32bpp_base.hpp @@ -14,6 +14,7 @@ #include "base.hpp" #include "../core/bitmath_func.hpp" +#include "../core/math_func.hpp" #include "../gfx_func.h" /** Base for all 32bpp blitters. */ @@ -134,6 +135,33 @@ public: return ComposeColour(0xFF, colour, colour, colour); } + + static const int DEFAULT_BRIGHTNESS = 64; + + static inline uint32 AdjustBrightness(uint32 colour, uint8 brightness) + { + /* Shortcut for normal brightness */ + if (brightness == DEFAULT_BRIGHTNESS) return colour; + + uint16 ob = 0; + uint16 r = GB(colour, 16, 8) * brightness / DEFAULT_BRIGHTNESS; + uint16 g = GB(colour, 8, 8) * brightness / DEFAULT_BRIGHTNESS; + uint16 b = GB(colour, 0, 8) * brightness / DEFAULT_BRIGHTNESS; + + /* Sum overbright */ + if (r > 255) ob += r - 255; + if (g > 255) ob += g - 255; + if (b > 255) ob += b - 255; + + if (ob == 0) return ComposeColour(GB(colour, 24, 8), r, g, b); + + /* Reduce overbright strength */ + ob /= 2; + return ComposeColour(GB(colour, 24, 8), + r >= 255 ? 255 : min(r + ob * (255 - r) / 256, 255), + g >= 255 ? 255 : min(g + ob * (255 - g) / 256, 255), + b >= 255 ? 255 : min(b + ob * (255 - b) / 256, 255)); + } }; #endif /* BLITTER_32BPP_BASE_HPP */ diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp index b7d252721..20335a7b0 100644 --- a/src/blitter/32bpp_optimized.cpp +++ b/src/blitter/32bpp_optimized.cpp @@ -36,12 +36,12 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL /* src_n : each line begins with uint32 n = 'number of bytes in this line', * then interleaved stream of 'm' and 'n' channels. 'm' is remap, * 'n' is number of bytes with the same alpha channel class */ - const uint8 *src_n = (const uint8 *)(src->data + src->offset[zoom][1]); + const uint16 *src_n = (const uint16 *)(src->data + src->offset[zoom][1]); /* skip upper lines in src_px and src_n */ for (uint i = bp->skip_top; i != 0; i--) { src_px = (const Colour *)((const byte *)src_px + *(const uint32 *)src_px); - src_n += *(const uint32 *)src_n; + src_n = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n); } /* skip lines in dst */ @@ -59,8 +59,8 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL src_px++; /* next src_n line begins here */ - const uint8 *src_n_ln = src_n + *(const uint32 *)src_n; - src_n += 4; + const uint16 *src_n_ln = (const uint16 *)((const byte *)src_n + *(const uint32 *)src_n); + src_n += 2; /* we will end this line when we reach this point */ uint32 *dst_end = dst + bp->skip_left; @@ -119,8 +119,8 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL if (m == 0) { *dst = src_px->data; } else { - uint r = remap[m]; - if (r != 0) *dst = this->LookupColourInPalette(r); + uint r = remap[GB(m, 0, 8)]; + if (r != 0) *dst = this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)); } dst++; src_px++; @@ -132,8 +132,8 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL if (m == 0) { *dst = ComposeColourRGBANoCheck(src_px->r, src_px->g, src_px->b, src_px->a, *dst); } else { - uint r = remap[m]; - if (r != 0) *dst = ComposeColourPANoCheck(this->LookupColourInPalette(r), src_px->a, *dst); + 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++; @@ -270,7 +270,7 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr * * it has to be stored in one stream so fewer registers are used - * x86 has problems with register allocation even with this solution */ - uint8 *dst_n_orig[ZOOM_LVL_COUNT]; + uint16 *dst_n_orig[ZOOM_LVL_COUNT]; /* lengths of streams */ uint32 lengths[ZOOM_LVL_COUNT][2]; @@ -293,7 +293,7 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr uint size = src_orig->height * src_orig->width; dst_px_orig[z] = CallocT<Colour>(size + src_orig->height * 2); - dst_n_orig[z] = CallocT<uint8>(size * 2 + src_orig->height * 4 * 2); + dst_n_orig[z] = CallocT<uint16>(size * 2 + src_orig->height * 4 * 2); uint32 *dst_px_ln = (uint32 *)dst_px_orig[z]; uint32 *dst_n_ln = (uint32 *)dst_n_orig[z]; @@ -302,9 +302,9 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr for (uint y = src_orig->height; y > 0; y--) { Colour *dst_px = (Colour *)(dst_px_ln + 1); - uint8 *dst_n = (uint8 *)(dst_n_ln + 1); + uint16 *dst_n = (uint16 *)(dst_n_ln + 1); - uint8 *dst_len = dst_n++; + uint16 *dst_len = dst_n++; uint last = 3; int len = 0; @@ -313,7 +313,7 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr uint8 a = src->a; uint t = a > 0 && a < 255 ? 1 : a; - if (last != t || len == 255) { + if (last != t || len == 65535) { if (last != 3) { *dst_len = len; dst_len = dst_n++; @@ -328,8 +328,15 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr dst_px->a = a; *dst_n = src->m; if (src->m != 0) { + /* Get brightest value */ + uint8 rgb_max = max(src->r, max(src->g, src->b)); + + /* Black pixel (8bpp or old 32bpp image), so use default value */ + if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS; + *dst_n |= rgb_max << 8; + /* Pre-convert the mapping channel to a RGB value */ - uint32 colour = this->LookupColourInPalette(src->m); + uint32 colour = this->AdjustBrightness(this->LookupColourInPalette(src->m), rgb_max); dst_px->r = GB(colour, 16, 8); dst_px->g = GB(colour, 8, 8); dst_px->b = GB(colour, 0, 8); @@ -354,7 +361,7 @@ Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, AllocatorPr } dst_px = (Colour *)AlignPtr(dst_px, 4); - dst_n = (uint8 *)AlignPtr(dst_n, 4); + dst_n = (uint16 *)AlignPtr(dst_n, 4); *dst_px_ln = (uint8 *)dst_px - (uint8 *)dst_px_ln; *dst_n_ln = (uint8 *)dst_n - (uint8 *)dst_n_ln; diff --git a/src/blitter/32bpp_simple.cpp b/src/blitter/32bpp_simple.cpp index 43b31dd3c..fa6155d74 100644 --- a/src/blitter/32bpp_simple.cpp +++ b/src/blitter/32bpp_simple.cpp @@ -20,11 +20,11 @@ static FBlitter_32bppSimple iFBlitter_32bppSimple; void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) { - const SpriteLoader::CommonPixel *src, *src_line; + const Blitter_32bppSimple::Pixel *src, *src_line; uint32 *dst, *dst_line; /* Find where to start reading in the source sprite */ - src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom); + src_line = (const Blitter_32bppSimple::Pixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom); dst_line = (uint32 *)bp->dst + bp->top * bp->pitch + bp->left; for (int y = 0; y < bp->height; y++) { @@ -41,7 +41,7 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo if (src->m == 0) { if (src->a != 0) *dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst); } else { - if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst); + if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->AdjustBrightness(this->LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst); } break; @@ -94,26 +94,42 @@ void Blitter_32bppSimple::DrawColourMappingRect(void *dst, int width, int height Sprite *Blitter_32bppSimple::Encode(SpriteLoader::Sprite *sprite, AllocatorProc *allocator) { - Sprite *dest_sprite; - SpriteLoader::CommonPixel *dst; - dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel)); + Blitter_32bppSimple::Pixel *dst; + Sprite *dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(*dst)); dest_sprite->height = sprite->height; dest_sprite->width = sprite->width; dest_sprite->x_offs = sprite->x_offs; dest_sprite->y_offs = sprite->y_offs; - dst = (SpriteLoader::CommonPixel *)dest_sprite->data; + dst = (Blitter_32bppSimple::Pixel *)dest_sprite->data; + SpriteLoader::CommonPixel *src = (SpriteLoader::CommonPixel *)sprite->data; - memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel)); for (int i = 0; i < sprite->height * sprite->width; i++) { - if (dst[i].m != 0) { + if (src->m == 0) { + dst[i].r = src->r; + dst[i].g = src->g; + dst[i].b = src->b; + dst[i].a = src->a; + dst[i].m = 0; + dst[i].v = 0; + } else { + /* Get brightest value */ + uint8 rgb_max = max(src->r, max(src->g, src->b)); + + /* Black pixel (8bpp or old 32bpp image), so use default value */ + if (rgb_max == 0) rgb_max = DEFAULT_BRIGHTNESS; + dst[i].v = rgb_max; + /* Pre-convert the mapping channel to a RGB value */ - uint colour = this->LookupColourInPalette(dst[i].m); + uint colour = this->AdjustBrightness(this->LookupColourInPalette(src[i].m), dst[i].v); dst[i].r = GB(colour, 16, 8); dst[i].g = GB(colour, 8, 8); dst[i].b = GB(colour, 0, 8); + dst[i].a = src->a; + dst[i].m = src->m; } + src++; } return dest_sprite; diff --git a/src/blitter/32bpp_simple.hpp b/src/blitter/32bpp_simple.hpp index 501cf4c26..f09920d0e 100644 --- a/src/blitter/32bpp_simple.hpp +++ b/src/blitter/32bpp_simple.hpp @@ -17,6 +17,14 @@ /** The most trivial 32 bpp blitter (without palette animation). */ class Blitter_32bppSimple : public Blitter_32bppBase { + struct Pixel { + uint8 r; ///< Red-channel + uint8 g; ///< Green-channel + uint8 b; ///< Blue-channel + uint8 a; ///< Alpha-channel + uint8 m; ///< Remap-channel + uint8 v; ///< Brightness-channel + }; public: /* virtual */ void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); /* virtual */ void DrawColourMappingRect(void *dst, int width, int height, PaletteID pal); |