diff --git a/userspace/libraries/LibImage/Image.cpp b/userspace/libraries/LibImage/Image.cpp index fe37af06..1809baac 100644 --- a/userspace/libraries/LibImage/Image.cpp +++ b/userspace/libraries/LibImage/Image.cpp @@ -7,7 +7,6 @@ #include #include -#include #include namespace LibImage @@ -87,9 +86,9 @@ namespace LibImage constexpr Image::Color as_color() const { return Image::Color { - .r = static_cast(r < 0.0 ? 0.0 : r > 255.0 ? 255.0 : r), - .g = static_cast(g < 0.0 ? 0.0 : g > 255.0 ? 255.0 : g), .b = static_cast(b < 0.0 ? 0.0 : b > 255.0 ? 255.0 : b), + .g = static_cast(g < 0.0 ? 0.0 : g > 255.0 ? 255.0 : g), + .r = static_cast(r < 0.0 ? 0.0 : r > 255.0 ? 255.0 : r), .a = static_cast(a < 0.0 ? 0.0 : a > 255.0 ? 255.0 : a), }; } diff --git a/userspace/libraries/LibImage/PNG.cpp b/userspace/libraries/LibImage/PNG.cpp index 7138865e..5d71dbdc 100644 --- a/userspace/libraries/LibImage/PNG.cpp +++ b/userspace/libraries/LibImage/PNG.cpp @@ -560,52 +560,47 @@ namespace LibImage const auto extract_color = [&](auto& bit_buffer) -> Image::Color { - uint8_t tmp; + Image::Color color; switch (ihdr.colour_type) { case ColourType::Greyscale: - tmp = extract_channel(bit_buffer); - return Image::Color { - .r = tmp, - .g = tmp, - .b = tmp, - .a = 0xFF - }; + color.r = extract_channel(bit_buffer); + color.g = color.r; + color.b = color.r; + color.a = 0xFF; + break; case ColourType::Truecolour: - return Image::Color { - .r = extract_channel(bit_buffer), - .g = extract_channel(bit_buffer), - .b = extract_channel(bit_buffer), - .a = 0xFF - }; + color.r = extract_channel(bit_buffer); + color.g = extract_channel(bit_buffer); + color.b = extract_channel(bit_buffer); + color.a = 0xFF; + break; case ColourType::IndexedColour: - return palette[MUST(bit_buffer.get_bits(bits_per_channel))]; + color = palette[MUST(bit_buffer.get_bits(bits_per_channel))]; + break; case ColourType::GreyscaleAlpha: - tmp = extract_channel(bit_buffer); - return Image::Color { - .r = tmp, - .g = tmp, - .b = tmp, - .a = extract_channel(bit_buffer) - }; + color.r = extract_channel(bit_buffer); + color.g = color.r; + color.b = color.r; + color.a = extract_channel(bit_buffer); + break; case ColourType::TruecolourAlpha: - return Image::Color { - .r = extract_channel(bit_buffer), - .g = extract_channel(bit_buffer), - .b = extract_channel(bit_buffer), - .a = extract_channel(bit_buffer) - }; + color.r = extract_channel(bit_buffer); + color.g = extract_channel(bit_buffer); + color.b = extract_channel(bit_buffer); + color.a = extract_channel(bit_buffer); + break; } - ASSERT_NOT_REACHED(); + return color; }; constexpr auto paeth_predictor = [](int16_t a, int16_t b, int16_t c) -> uint8_t { - int16_t p = a + b - c; - int16_t pa = BAN::Math::abs(p - a); - int16_t pb = BAN::Math::abs(p - b); - int16_t pc = BAN::Math::abs(p - c); + const int16_t p = a + b - c; + const int16_t pa = BAN::Math::abs(p - a); + const int16_t pb = BAN::Math::abs(p - b); + const int16_t pc = BAN::Math::abs(p - c); if (pa <= pb && pa <= pc) return a; if (pb <= pc) diff --git a/userspace/libraries/LibImage/include/LibImage/Image.h b/userspace/libraries/LibImage/include/LibImage/Image.h index 02b2e38f..b0a60d98 100644 --- a/userspace/libraries/LibImage/include/LibImage/Image.h +++ b/userspace/libraries/LibImage/include/LibImage/Image.h @@ -13,9 +13,9 @@ namespace LibImage public: struct Color { - uint8_t r; - uint8_t g; uint8_t b; + uint8_t g; + uint8_t r; uint8_t a; // Calculate weighted average of colors @@ -25,14 +25,14 @@ namespace LibImage const double b_mult = weight < 0.0 ? 0.0 : weight > 1.0 ? 1.0 : weight; const double a_mult = 1.0 - b_mult; return Color { - .r = static_cast(a.r * a_mult + b.r * b_mult), - .g = static_cast(a.g * a_mult + b.g * b_mult), .b = static_cast(a.b * a_mult + b.b * b_mult), + .g = static_cast(a.g * a_mult + b.g * b_mult), + .r = static_cast(a.r * a_mult + b.r * b_mult), .a = static_cast(a.a * a_mult + b.a * b_mult), }; } - uint32_t as_rgba() const + uint32_t as_argb() const { return ((uint32_t)a << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; } diff --git a/userspace/programs/WindowServer/WindowServer.cpp b/userspace/programs/WindowServer/WindowServer.cpp index 7a49494d..0bd6c03e 100644 --- a/userspace/programs/WindowServer/WindowServer.cpp +++ b/userspace/programs/WindowServer/WindowServer.cpp @@ -330,7 +330,7 @@ void WindowServer::invalidate(Rectangle area) ASSERT(m_background_image->height() == (uint64_t)m_framebuffer.height); for (int32_t y = area.y; y < area.y + area.height; y++) for (int32_t x = area.x; x < area.x + area.width; x++) - m_framebuffer.mmap[y * m_framebuffer.width + x] = m_background_image->get_color(x, y).as_rgba(); + m_framebuffer.mmap[y * m_framebuffer.width + x] = m_background_image->get_color(x, y).as_argb(); } else {