diff options
author | crupest <crupest@outlook.com> | 2022-06-09 21:07:51 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-06-09 21:07:51 +0800 |
commit | fb8454cc993871715fbb556e6cf63f07e698b4a7 (patch) | |
tree | 92a2a6d6608c31a5fa665ac17f44ff61f64ca7a2 | |
parent | 7f830b907aa7e9056b37b5655faae6ec0bf9ac02 (diff) | |
download | cru-fb8454cc993871715fbb556e6cf63f07e698b4a7.tar.gz cru-fb8454cc993871715fbb556e6cf63f07e698b4a7.tar.bz2 cru-fb8454cc993871715fbb556e6cf63f07e698b4a7.zip |
...
-rw-r--r-- | src/platform/graphics/cairo/CairoImageFactory.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/platform/graphics/cairo/CairoImageFactory.cpp b/src/platform/graphics/cairo/CairoImageFactory.cpp index 9691add2..c2ebe8b0 100644 --- a/src/platform/graphics/cairo/CairoImageFactory.cpp +++ b/src/platform/graphics/cairo/CairoImageFactory.cpp @@ -87,15 +87,20 @@ std::unique_ptr<CairoImage> DecodePng(CairoGraphicsFactory* factory, return cairo_image; } -inline std::uint32_t Mul(std::uint32_t v, float a) { return v * a; } +std::uint32_t Div(std::uint32_t v, float a) { + if (a == 0.f) return 255; + std::uint32_t result = static_cast<std::uint32_t>(v / a); + if (result > 255) result = 255; + return result; +} std::uint32_t ConvertPargbToRgba(std::uint32_t source) { std::uint32_t result = 0; result |= (source & 0xFF000000) >> 24; float a = 1.f - result / 255.f; - result |= Mul((source & 0x00FF0000) >> 16, a) << 24; - result |= Mul((source & 0x0000FF00) >> 8, a) << 16; - result |= Mul(source & 0x000000FF, a) << 8; + result |= Div((source & 0x00FF0000) >> 16, a) << 24; + result |= Div((source & 0x0000FF00) >> 8, a) << 16; + result |= Div(source & 0x000000FF, a) << 8; return result; } |