From 4e5f6f01a1b8dfd2dc07f760e79a0ced6d4836a5 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 15 Feb 2020 12:47:29 +1100 Subject: Backport: Extract image conversion from RGBA to BGRA premultiplied into common function. Backport of changeset 7987:beeac488af4d. --- src/XPM.cxx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/XPM.cxx') diff --git a/src/XPM.cxx b/src/XPM.cxx index f2565bf83..9ce82a6f6 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -263,6 +263,21 @@ void RGBAImage::SetPixel(int x, int y, ColourDesired colour, int alpha) { pixel[3] = static_cast(alpha); } +// 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 / 255; + pixelsBGRA[1] = pixelsRGBA[1] * alpha / 255; + pixelsBGRA[0] = pixelsRGBA[2] * alpha / 255; + pixelsBGRA[3] = alpha; + pixelsRGBA += bytesPerPixel; + pixelsBGRA += bytesPerPixel; + } +} + RGBAImageSet::RGBAImageSet() : height(-1), width(-1) { } -- cgit v1.2.3