Bug 775793 - Clarify BMP decoding for unexpected alpha pixels - r=bbondy

This commit is contained in:
Jeff Gilbert 2012-07-23 13:20:57 -07:00
parent e17334f920
commit 63ff1a9c10
2 changed files with 13 additions and 10 deletions

View File

@ -71,11 +71,11 @@ nsBMPDecoder::GetWidth() const
return mBIH.width;
}
// Obtains the height from the internal BIH header
// Obtains the abs-value of the height from the internal BIH header
PRInt32
nsBMPDecoder::GetHeight() const
{
return mBIH.height;
return abs(mBIH.height);
}
// Obtains the internal output image buffer
@ -104,7 +104,7 @@ nsBMPDecoder::GetCompressedImageSize() const
// The height should be the absolute value of what the height is in the BIH.
// If positive the bitmap is stored bottom to top, otherwise top to bottom
PRInt32 pixelArraySize = rowSize * abs(mBIH.height);
PRInt32 pixelArraySize = rowSize * GetHeight();
return pixelArraySize;
}
@ -130,7 +130,7 @@ nsBMPDecoder::FinishInternal()
if (!IsSizeDecode() && (GetFrameCount() == 1)) {
// Invalidate
nsIntRect r(0, 0, mBIH.width, mBIH.height);
nsIntRect r(0, 0, mBIH.width, GetHeight());
PostInvalidation(r);
PostFrameStop();
@ -238,7 +238,7 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
return;
}
PRUint32 real_height = (mBIH.height > 0) ? mBIH.height : -mBIH.height;
PRUint32 real_height = GetHeight();
// Post our size to the superclass
PostSize(mBIH.width, real_height);
@ -480,9 +480,12 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
// 4 has been right all along. And we know it
// has been set to 0 the whole time, so that
// means that everything is transparent so far.
memset(mImageData + (mCurLine - 1) * GetWidth(), 0,
(GetHeight() - mCurLine + 1) *
GetWidth() * sizeof(PRUint32));
PRUint32* start = mImageData + GetWidth() * (mCurLine - 1);
PRUint32 heightDifference = GetHeight() - mCurLine + 1;
PRUint32 pixelCount = GetWidth() * heightDifference;
memset(start, 0, pixelCount * sizeof(PRUint32));
mHaveAlphaData = true;
}
SetPixel(d, p[2], p[1], p[0], mHaveAlphaData ? p[3] : 0xFF);

View File

@ -36,7 +36,7 @@ public:
PRInt32 GetBitsPerPixel() const;
// Obtains the width from the internal BIH header
PRInt32 GetWidth() const;
// Obtains the height from the internal BIH header
// Obtains the abs-value of the height from the internal BIH header
PRInt32 GetHeight() const;
// Obtains the internal output image buffer
PRUint32* GetImageData();
@ -71,7 +71,7 @@ private:
PRUint32 *mImageData; ///< Pointer to the image data for the frame
PRUint8 *mRow; ///< Holds one raw line of the image
PRUint32 mRowBytes; ///< How many bytes of the row were already received
PRInt32 mCurLine; ///< Index of the line of the image that's currently being decoded
PRInt32 mCurLine; ///< Index of the line of the image that's currently being decoded: [height,1]
PRInt32 mOldLine; ///< Previous index of the line
PRInt32 mCurPos; ///< Index in the current line of the image