From 937d60f239641ee65580dacf1de55bb3d14860f3 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Tue, 2 Mar 2021 20:55:39 +0100 Subject: Fix #8774: Black screenshots when using 40bpp-blitter. (#8791) This affected all screenshot types that render to an off-screen buffer and don't copy the actual screen contents. --- src/blitter/32bpp_optimized.cpp | 62 ++++++++++++++++++++++++++++------------- src/blitter/32bpp_optimized.hpp | 3 +- src/blitter/40bpp_anim.cpp | 2 +- 3 files changed, 45 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/blitter/32bpp_optimized.cpp b/src/blitter/32bpp_optimized.cpp index 1f8e0bbd2..fa1f0bb38 100644 --- a/src/blitter/32bpp_optimized.cpp +++ b/src/blitter/32bpp_optimized.cpp @@ -24,7 +24,7 @@ static FBlitter_32bppOptimized iFBlitter_32bppOptimized; * @param bp further blitting parameters * @param zoom zoom level at which we are drawing */ -template +template inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom) { const SpriteData *src = (const SpriteData *)bp->sprite; @@ -209,18 +209,29 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL default: if (src_px->a == 255) { /* faster than memcpy(), n is usually low */ - src_n += n; do { - *dst = src_px->data; + if (Tpal_to_rgb && *src_n != 0) { + /* Convert the mapping channel to a RGB value */ + *dst = this->AdjustBrightness(this->LookupColourInPalette(GB(*src_n, 0, 8)), GB(*src_n, 8, 8)).data; + } else { + *dst = src_px->data; + } dst++; src_px++; + src_n++; } while (--n != 0); } else { - src_n += n; do { - *dst = ComposeColourRGBANoCheck(src_px->r, src_px->g, src_px->b, src_px->a, *dst); + if (Tpal_to_rgb && *src_n != 0) { + /* Convert the mapping channel to a RGB value */ + Colour colour = this->AdjustBrightness(this->LookupColourInPalette(GB(*src_n, 0, 8)), GB(*src_n, 8, 8)); + *dst = ComposeColourRGBANoCheck(colour.r, colour.g, colour.b, 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; @@ -233,6 +244,22 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL } } +template +void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) +{ + switch (mode) { + default: NOT_REACHED(); + case BM_NORMAL: Draw(bp, zoom); return; + case BM_COLOUR_REMAP: Draw(bp, zoom); return; + case BM_TRANSPARENT: Draw(bp, zoom); return; + case BM_CRASH_REMAP: Draw(bp, zoom); return; + case BM_BLACK_REMAP: Draw(bp, zoom); return; + } +} + +template void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); +template void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); + /** * Draws a sprite to a (screen) buffer. Calls adequate templated function. * @@ -242,14 +269,7 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL */ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) { - switch (mode) { - default: NOT_REACHED(); - case BM_NORMAL: Draw (bp, zoom); return; - case BM_COLOUR_REMAP: Draw(bp, zoom); return; - case BM_TRANSPARENT: Draw (bp, zoom); return; - case BM_CRASH_REMAP: Draw (bp, zoom); return; - case BM_BLACK_REMAP: Draw (bp, zoom); return; - } + this->Draw(bp, mode, zoom); } template Sprite *Blitter_32bppOptimized::EncodeInternal(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator) @@ -322,19 +342,21 @@ template Sprite *Blitter_32bppOptimized::EncodeInternal(const if (a != 0) { dst_px->a = a; *dst_n = src->m; - if (Tpal_to_rgb && src->m != 0) { + if (src->m != 0) { /* Get brightest value */ - uint8 rgb_max = std::max({src->r, src->g, src->b}); + uint8 rgb_max = std::max({ src->r, 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 */ - Colour colour = this->AdjustBrightness(this->LookupColourInPalette(src->m), rgb_max); - dst_px->r = colour.r; - dst_px->g = colour.g; - dst_px->b = colour.b; + if (Tpal_to_rgb) { + /* Pre-convert the mapping channel to a RGB value */ + Colour colour = this->AdjustBrightness(this->LookupColourInPalette(src->m), rgb_max); + dst_px->r = colour.r; + dst_px->g = colour.g; + dst_px->b = colour.b; + } } else { dst_px->r = src->r; dst_px->g = src->g; diff --git a/src/blitter/32bpp_optimized.hpp b/src/blitter/32bpp_optimized.hpp index 9bee600b1..f0de770b6 100644 --- a/src/blitter/32bpp_optimized.hpp +++ b/src/blitter/32bpp_optimized.hpp @@ -26,9 +26,10 @@ public: const char *GetName() override { return "32bpp-optimized"; } - template void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); + template void Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom); protected: + template void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom); template Sprite *EncodeInternal(const SpriteLoader::Sprite *sprite, AllocatorProc *allocator); }; diff --git a/src/blitter/40bpp_anim.cpp b/src/blitter/40bpp_anim.cpp index aaca817fc..d29b34a17 100644 --- a/src/blitter/40bpp_anim.cpp +++ b/src/blitter/40bpp_anim.cpp @@ -315,7 +315,7 @@ void Blitter_40bppAnim::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL if (_screen_disable_anim || VideoDriver::GetInstance()->GetAnimBuffer() == nullptr) { /* This means our output is not to the screen, so we can't be doing any animation stuff, so use our parent Draw() */ - Blitter_32bppOptimized::Draw(bp, mode, zoom); + Blitter_32bppOptimized::Draw(bp, mode, zoom); return; } -- cgit v1.2.3-70-g09d2