diff --git a/webrtc/modules/desktop_capture/win/cursor.cc b/webrtc/modules/desktop_capture/win/cursor.cc index 2c32c0cad..76eed7742 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);