From 6f238c0d1a1cbacdc07b030a5b1b47d8c4de1ec0 Mon Sep 17 00:00:00 2001 From: Patryk Obara Date: Sat, 21 Mar 2020 03:38:37 +0100 Subject: [PATCH] Fix splash screen for surface output All rendering backends except output=surface assume input buffer row with the same length as output buffer row. Surface is "special" and in fullscreen uses pitch equal to *screen* width instead. Padding the output rows with black pixels is necessary for splash screen to show up correctly. --- src/gui/sdlmain.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index bc455d19..552214f1 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -1748,21 +1748,30 @@ static void DisplaySplash(uint32_t time_ms) if (!GFX_StartUpdate(out, pitch)) E_Exit("%s", SDL_GetError()); + uint32_t *pixels = reinterpret_cast(out); + assertm(pixels, "GFX_StartUpdate is supposed to give us buffer."); + const int buf_width = pitch / 4; + assertm(buf_width >= src_w, "Row length needs to be big enough."); + std::array splash; GIMP_IMAGE_RUN_LENGTH_DECODE(splash.data(), gimp_image.rle_pixel_data, src_w * src_h, src_bpp); - - assertm(out, "GFX_StartUpdate is supposed to give us buffer."); - uint32_t *pixels = reinterpret_cast(out); - size_t i = 0; size_t j = 0; + static_assert(splash.size() % 3 == 0, "Reading 3 bytes at a time."); - while (i < splash.size()) { - const uint32_t r = splash[i++]; - const uint32_t g = splash[i++]; - const uint32_t b = splash[i++]; - pixels[j++] = (r << 16) | (g << 8) | b; + for (int y = 0; y < src_h; y++) { + // copy a row of pixels to output buffer + for (int x = 0; x < src_w; x++) { + const uint32_t r = splash[i++]; + const uint32_t g = splash[i++]; + const uint32_t b = splash[i++]; + pixels[j++] = (r << 16) | (g << 8) | b; + } + // pad with black until the end of row + // only output=surface actually needs this + for (int x = src_w; x < buf_width; x++) + pixels[j++] = 0; } const uint16_t lines[2] = {0, src_h}; // output=surface won't work otherwise