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
This commit is contained in:
parent
31b4a5ac82
commit
bebf3995ce
@ -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<RGBQUAD*>(&pixel);
|
||||
RGBQUAD to = {
|
||||
(static_cast<uint16_t>(from.rgbBlue) * from.rgbReserved) / 0xff,
|
||||
(static_cast<uint16_t>(from.rgbGreen) * from.rgbReserved) / 0xff,
|
||||
(static_cast<uint16_t>(from.rgbRed) * from.rgbReserved) / 0xff,
|
||||
from.rgbReserved
|
||||
};
|
||||
|
||||
return *reinterpret_cast<uint32_t*>(&to);
|
||||
for (uint32_t* data_end = data + width * height; data != data_end; ++data) {
|
||||
RGBQUAD* from = reinterpret_cast<RGBQUAD*>(data);
|
||||
RGBQUAD* to = reinterpret_cast<RGBQUAD*>(data);
|
||||
to->rgbBlue =
|
||||
(static_cast<uint16_t>(from->rgbBlue) * from->rgbReserved) / 0xff;
|
||||
to->rgbGreen =
|
||||
(static_cast<uint16_t>(from->rgbGreen) * from->rgbReserved) / 0xff;
|
||||
to->rgbRed =
|
||||
(static_cast<uint16_t>(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<MouseCursorShape> result(new MouseCursorShape());
|
||||
result->data.assign(reinterpret_cast<char*>(color_plane),
|
||||
height * width * kBytesPerPixel);
|
||||
|
Loading…
Reference in New Issue
Block a user