diff options
author | Neil <nyamatongwe@gmail.com> | 2023-01-09 13:34:54 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2023-01-09 13:34:54 +1100 |
commit | c51ace6d35a7dd068560871727bfb5474bab3be0 (patch) | |
tree | 2c7a3b581620d7d76b70436d1604ce985e0f50e5 | |
parent | f1b8ae2bc9ebcd534052fc1b81a10f24bf0630f6 (diff) | |
download | scintilla-mirror-c51ace6d35a7dd068560871727bfb5474bab3be0.tar.gz |
Hoist common calculation into function.
Use logical and to stop conversion warning.
-rw-r--r-- | src/XPM.cxx | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/XPM.cxx b/src/XPM.cxx index 31d87a06d..42c4dd96a 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -264,15 +264,23 @@ void RGBAImage::SetPixel(int x, int y, ColourRGBA colour) noexcept { pixel[3] = colour.GetAlpha(); } +namespace { + +unsigned char AlphaMultiplied(unsigned char value, unsigned char alpha) { + return (value * alpha / UCHAR_MAX) & 0xffU; +} + +} + // Transform a block of pixels from RGBA to BGRA with premultiplied alpha. // Used for DrawRGBAImage on some platforms. void RGBAImage::BGRAFromRGBA(unsigned char *pixelsBGRA, const unsigned char *pixelsRGBA, size_t count) noexcept { for (size_t i = 0; i < count; i++) { const unsigned char alpha = pixelsRGBA[3]; // Input is RGBA, output is BGRA with premultiplied alpha - pixelsBGRA[2] = pixelsRGBA[0] * alpha / UCHAR_MAX; - pixelsBGRA[1] = pixelsRGBA[1] * alpha / UCHAR_MAX; - pixelsBGRA[0] = pixelsRGBA[2] * alpha / UCHAR_MAX; + pixelsBGRA[2] = AlphaMultiplied(pixelsRGBA[0], alpha); + pixelsBGRA[1] = AlphaMultiplied(pixelsRGBA[1], alpha); + pixelsBGRA[0] = AlphaMultiplied(pixelsRGBA[2], alpha); pixelsBGRA[3] = alpha; pixelsRGBA += bytesPerPixel; pixelsBGRA += bytesPerPixel; |