From bebf3995ce76fb262e04cf0ede791b3c2c19020a Mon Sep 17 00:00:00 2001 From: "alexeypa@chromium.org" Date: Thu, 5 Sep 2013 19:32:46 +0000 Subject: [PATCH] Pre-multiply images for MouseCursorShape. BUG=chromium:267270 R=sergeyu@chromium.org Review URL: https://webrtc-codereview.appspot.com/2173004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4685 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/desktop_capture/win/cursor.cc | 28 ++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/webrtc/modules/desktop_capture/win/cursor.cc b/webrtc/modules/desktop_capture/win/cursor.cc index 2c32c0cad3..76eed77423 100644 --- a/webrtc/modules/desktop_capture/win/cursor.cc +++ b/webrtc/modules/desktop_capture/win/cursor.cc @@ -74,19 +74,21 @@ void AddCursorOutline(int width, int height, uint32_t* data) { } } -// Premultiplies RGB components of a pixel by its alpha component. -uint32_t AlphaMul(uint32_t pixel) { +// Premultiplies RGB components of the pixel data in the given image by +// the corresponding alpha components. +void AlphaMul(uint32_t* data, int width, int height) { COMPILE_ASSERT(sizeof(uint32_t) == kBytesPerPixel); - RGBQUAD from = *reinterpret_cast(&pixel); - RGBQUAD to = { - (static_cast(from.rgbBlue) * from.rgbReserved) / 0xff, - (static_cast(from.rgbGreen) * from.rgbReserved) / 0xff, - (static_cast(from.rgbRed) * from.rgbReserved) / 0xff, - from.rgbReserved - }; - - return *reinterpret_cast(&to); + for (uint32_t* data_end = data + width * height; data != data_end; ++data) { + RGBQUAD* from = reinterpret_cast(data); + RGBQUAD* to = reinterpret_cast(data); + to->rgbBlue = + (static_cast(from->rgbBlue) * from->rgbReserved) / 0xff; + to->rgbGreen = + (static_cast(from->rgbGreen) * from->rgbReserved) / 0xff; + to->rgbRed = + (static_cast(from->rgbRed) * from->rgbReserved) / 0xff; + } } // Scans a 32bpp bitmap looking for any pixels with non-zero alpha component. @@ -244,6 +246,10 @@ MouseCursorShape* CreateMouseCursorShapeFromCursor(HDC dc, HCURSOR cursor) { } } + // Pre-multiply the resulting pixels since MouseCursorShape uses premultiplied + // images. + AlphaMul(color_plane, width, height); + scoped_ptr result(new MouseCursorShape()); result->data.assign(reinterpret_cast(color_plane), height * width * kBytesPerPixel);