aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtk/PlatGTK.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
commitb82a2f50548c33bc6727a54e193a2cccaf4e12f7 (patch)
treecab786fc8fdce3580a68bd38e7dd5946e8def1aa /gtk/PlatGTK.cxx
parent0eb0a3e5746f7d94c23337b24db9aa2d4871b739 (diff)
downloadscintilla-mirror-b82a2f50548c33bc6727a54e193a2cccaf4e12f7.tar.gz
Extract image conversion from RGBA to BGRA premultiplied into common function.
Diffstat (limited to 'gtk/PlatGTK.cxx')
-rwxr-xr-xgtk/PlatGTK.cxx15
1 files changed, 5 insertions, 10 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index a319e31ba..2947ffa11 100755
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -601,18 +601,13 @@ void SurfaceImpl::DrawRGBAImage(PRectangle rc, int width, int height, const unsi
rc.top += (rc.Height() - height) / 2;
rc.bottom = rc.top + height;
- int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
+ const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
const int ucs = stride * height;
std::vector<unsigned char> image(ucs);
- for (int iy=0; iy<height; iy++) {
- for (int ix=0; ix<width; ix++) {
- unsigned char *pixel = &image[0] + iy*stride + ix * 4;
- const unsigned char alpha = pixelsImage[3];
- pixel[2] = (*pixelsImage++) * alpha / 255;
- pixel[1] = (*pixelsImage++) * alpha / 255;
- pixel[0] = (*pixelsImage++) * alpha / 255;
- pixel[3] = *pixelsImage++;
- }
+ for (ptrdiff_t iy=0; iy<height; iy++) {
+ unsigned char *pixel = &image[0] + iy*stride;
+ RGBAImage::BGRAFromRGBA(pixel, pixelsImage, width);
+ pixelsImage += RGBAImage::bytesPerPixel * width;
}
cairo_surface_t *psurfImage = cairo_image_surface_create_for_data(&image[0], CAIRO_FORMAT_ARGB32, width, height, stride);