aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/XPM.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2020-02-15 12:47:29 +1100
committerNeil <nyamatongwe@gmail.com>2020-02-15 12:47:29 +1100
commit4e5f6f01a1b8dfd2dc07f760e79a0ced6d4836a5 (patch)
treec4d3d8e22e930a5b1a1e9acb227d6b80bc1d90c8 /src/XPM.cxx
parentfbae4fb7ebd024048ac899e2fb6c56f33e8d69b5 (diff)
downloadscintilla-mirror-4e5f6f01a1b8dfd2dc07f760e79a0ced6d4836a5.tar.gz
Backport: Extract image conversion from RGBA to BGRA premultiplied into common function.
Backport of changeset 7987:beeac488af4d.
Diffstat (limited to 'src/XPM.cxx')
-rw-r--r--src/XPM.cxx15
1 files changed, 15 insertions, 0 deletions
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<unsigned char>(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) {
}