Bug 312921. The window pixels for translucent windows are already premultiplied, don't premultiply them again in Windows. r+sr=roc, patch by Dainis Jonitis

This commit is contained in:
roc+%cs.cmu.edu 2005-11-01 20:46:52 +00:00
parent a5f65bfee7
commit 934045dc2c
2 changed files with 11 additions and 22 deletions

View File

@ -681,6 +681,7 @@ class nsIWidget : public nsISupports {
* value for all pixels is 1, i.e., opaque.
* If the window is resized then the alpha channel values for
* all pixels are reset to 1.
* Pixel RGB color values are already premultiplied with alpha channel values.
* @param aTranslucent true if the window may have translucent
* or transparent pixels
*/
@ -698,6 +699,7 @@ class nsIWidget : public nsISupports {
* Update the alpha channel for some pixels of the top-level window
* that contains this widget.
* The window must have been made translucent using SetWindowTranslucency.
* Pixel RGB color values are already premultiplied with alpha channel values.
* @param aRect the rect to update
* @param aAlphas the alpha values, in w x h array, row-major order,
* in units of 1/255. nsBlender::GetAlphas is a good way to compute this array.

View File

@ -69,7 +69,6 @@
#include "nsIDeviceContext.h"
#include "nsIScreenManager.h"
#include "nsRect.h"
#include "nsColor.h"
#include "nsTransform2D.h"
#include "nsIEventQueue.h"
#include "imgIContainer.h"
@ -8329,7 +8328,7 @@ nsresult nsWindow::UpdateTranslucentWindow()
HDC hMemoryDC;
HBITMAP hAlphaBitmap;
PRBool needConversion = (depth != 32);
PRBool needConversion = (depth == 24);
if (needConversion)
{
@ -8355,8 +8354,7 @@ nsresult nsWindow::UpdateTranslucentWindow()
PRUint8* pPixel32 = pBits32;
PRUint8* pAlpha = mAlphaMask;
PRUint32 rasWidth = RASWIDTH(mBounds.width, depth);
PRInt32 bytesPerPixel = depth / 8;
PRUint32 rasWidth = RASWIDTH(mBounds.width, 24);
for (PRInt32 y = 0 ; y < mBounds.height ; y++)
{
@ -8364,15 +8362,10 @@ nsresult nsWindow::UpdateTranslucentWindow()
for (PRInt32 x = 0 ; x < mBounds.width ; x++)
{
// Each of the RGB components should be premultiplied with alpha and divided by 255
FAST_DIVIDE_BY_255(pPixel32 [0], *pAlpha * pPixel [0]);
FAST_DIVIDE_BY_255(pPixel32 [1], *pAlpha * pPixel [1]);
FAST_DIVIDE_BY_255(pPixel32 [2], *pAlpha * pPixel [2]);
pPixel32 [3] = *pAlpha;
pPixel += bytesPerPixel;
pPixel32 += 4;
pAlpha++;
*pPixel32++ = *pPixel++;
*pPixel32++ = *pPixel++;
*pPixel32++ = *pPixel++;
*pPixel32++ = *pAlpha++;
}
}
@ -8385,20 +8378,14 @@ nsresult nsWindow::UpdateTranslucentWindow()
if (hMemoryDC)
{
PRUint8* pPixel = w2k.mMemoryBits;
PRUint8* pPixel = w2k.mMemoryBits + 3; // Point to alpha component of pixel
PRUint8* pAlpha = mAlphaMask;
PRInt32 pixels = mBounds.width * mBounds.height;
for (PRInt32 cnt = 0 ; cnt < pixels ; cnt++)
{
// Each of the RGB components should be premultiplied with alpha and divided by 255
FAST_DIVIDE_BY_255(pPixel [0], *pAlpha * pPixel [0]);
FAST_DIVIDE_BY_255(pPixel [1], *pAlpha * pPixel [1]);
FAST_DIVIDE_BY_255(pPixel [2], *pAlpha * pPixel [2]);
pPixel [3] = *pAlpha;
*pPixel = *pAlpha++;
pPixel += 4;
pAlpha++;
}
rv = NS_OK;