aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/XPM.cxx15
-rw-r--r--src/XPM.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/src/XPM.cxx b/src/XPM.cxx
index f95580403..380ae14c4 100644
--- a/src/XPM.cxx
+++ b/src/XPM.cxx
@@ -264,6 +264,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) {
}
diff --git a/src/XPM.h b/src/XPM.h
index b7b895cdd..f8c908ecb 100644
--- a/src/XPM.h
+++ b/src/XPM.h
@@ -50,6 +50,7 @@ class RGBAImage {
float scale;
std::vector<unsigned char> pixelBytes;
public:
+ static constexpr size_t bytesPerPixel = 4;
RGBAImage(int width_, int height_, float scale_, const unsigned char *pixels_);
explicit RGBAImage(const XPM &xpm);
RGBAImage(const RGBAImage &) = default;
@@ -65,6 +66,7 @@ public:
int CountBytes() const;
const unsigned char *Pixels() const;
void SetPixel(int x, int y, ColourDesired colour, int alpha);
+ static void BGRAFromRGBA(unsigned char *pixelsBGRA, const unsigned char *pixelsRGBA, size_t count) noexcept;
};
/**