aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32/PlatWin.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 /win32/PlatWin.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 'win32/PlatWin.cxx')
-rw-r--r--win32/PlatWin.cxx27
1 files changed, 6 insertions, 21 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 3c5a5adf3..27d40fe22 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -784,15 +784,10 @@ void SurfaceGDI::DrawRGBAImage(PRectangle rc, int width, int height, const unsig
HBITMAP hbmOld = SelectBitmap(hMemDC, hbmMem);
for (int y=height-1; y>=0; y--) {
- for (int x=0; x<width; x++) {
- unsigned char *pixel = static_cast<unsigned char *>(image) + (y*width+x) * 4;
- const unsigned char alpha = pixelsImage[3];
- // Input is RGBA, output is BGRA with premultiplied alpha
- pixel[2] = static_cast<unsigned char>((*pixelsImage++) * alpha / 255);
- pixel[1] = static_cast<unsigned char>((*pixelsImage++) * alpha / 255);
- pixel[0] = static_cast<unsigned char>((*pixelsImage++) * alpha / 255);
- pixel[3] = *pixelsImage++;
- }
+ // Bits flipped vertically
+ unsigned char *pixel = static_cast<unsigned char *>(image) + RGBAImage::bytesPerPixel * y * width;
+ RGBAImage::BGRAFromRGBA(pixel, pixelsImage, width);
+ pixelsImage += RGBAImage::bytesPerPixel * width;
}
const BLENDFUNCTION merge = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
@@ -1436,18 +1431,8 @@ void SurfaceD2D::DrawRGBAImage(PRectangle rc, int width, int height, const unsig
rc.top += std::floor((rc.Height() - height) / 2);
rc.bottom = rc.top + height;
- std::vector<unsigned char> image(height * width * 4);
- for (int yPixel=0; yPixel<height; yPixel++) {
- for (int xPixel = 0; xPixel<width; xPixel++) {
- unsigned char *pixel = &image[0] + (yPixel*width + xPixel) * 4;
- const unsigned char alpha = pixelsImage[3];
- // Input is RGBA, output is BGRA with premultiplied alpha
- pixel[2] = (*pixelsImage++) * alpha / 255;
- pixel[1] = (*pixelsImage++) * alpha / 255;
- pixel[0] = (*pixelsImage++) * alpha / 255;
- pixel[3] = *pixelsImage++;
- }
- }
+ std::vector<unsigned char> image(RGBAImage::bytesPerPixel * height * width);
+ RGBAImage::BGRAFromRGBA(image.data(), pixelsImage, static_cast<ptrdiff_t>(height) * width);
ID2D1Bitmap *bitmap = nullptr;
const D2D1_SIZE_U size = D2D1::SizeU(width, height);