Mozilla not decoding 31x39 .ICO file correctly
This commit is contained in:
cbiesinger%web.de 2002-09-27 10:22:53 +00:00
Родитель 97e8c79f28
Коммит 0c481db11c
2 изменённых файлов: 46 добавлений и 10 удалений

Просмотреть файл

@ -64,24 +64,60 @@ NS_IMPL_ISUPPORTS1(nsICODecoder, imgIDecoder)
// Actual Data Processing // Actual Data Processing
// ---------------------------------------- // ----------------------------------------
inline nsresult nsICODecoder::SetImageData() nsresult nsICODecoder::SetImageData()
{ {
PRUint32 bpr; PRUint32 bpr;
mFrame->GetImageBytesPerRow(&bpr); mFrame->GetImageBytesPerRow(&bpr);
for (PRUint32 offset = 0, i = 0; i < mDirEntry.mHeight; ++i, offset += bpr)
mFrame->SetImageData(mDecodedBuffer+offset, bpr, offset); // Since the ICO is decoded into an exact sized array, the frame may use
// more bytes per row of pixels than the decoding array.
#if defined(XP_MAC) || defined(XP_MACOSX)
PRUint32 decodedLineLen = mDirEntry.mWidth * 4;
#else
PRUint32 decodedLineLen = mDirEntry.mWidth * 3;
#endif
PRUint8* decodeBufferPos = mDecodedBuffer;
PRUint32 frameOffset = 0;
for (PRUint32 i = 0;
i < mDirEntry.mHeight;
++i, frameOffset += bpr, decodeBufferPos += decodedLineLen) {
mFrame->SetImageData(decodeBufferPos, decodedLineLen, frameOffset);
}
return NS_OK; return NS_OK;
} }
inline nsresult nsICODecoder::SetAlphaData() nsresult nsICODecoder::SetAlphaData()
{ {
PRUint32 bpr; PRUint32 bpr;
mFrame->GetAlphaBytesPerRow(&bpr); mFrame->GetAlphaBytesPerRow(&bpr);
for (PRUint32 offset = 0, i = 0; i < mDirEntry.mHeight; ++i, offset += bpr)
mFrame->SetAlphaData(mAlphaBuffer+offset, bpr, offset); PRUint32 decoderRowSize = CalcAlphaRowSize();
// In case the decoder and frame have different sized alpha buffers, we
// take the smaller of the two row length values as the row length to copy.
PRUint32 rowCopyLen = PR_MIN(bpr, decoderRowSize);
PRUint8* alphaBufferPos = mAlphaBuffer;
PRUint32 frameOffset = 0;
for (PRUint32 i = 0;
i < mDirEntry.mHeight;
++i, frameOffset += bpr, alphaBufferPos += decoderRowSize) {
mFrame->SetAlphaData(alphaBufferPos, rowCopyLen, frameOffset);
}
return NS_OK; return NS_OK;
} }
PRUint32 nsICODecoder::CalcAlphaRowSize()
{
PRUint32 rowSize = (mDirEntry.mWidth + 7) / 8; // +7 to round up
if (rowSize % 4)
rowSize += (4 - (rowSize % 4)); // Pad to DWORD Boundary
return rowSize;
}
nsICODecoder::nsICODecoder() nsICODecoder::nsICODecoder()
{ {
NS_INIT_ISUPPORTS(); NS_INIT_ISUPPORTS();
@ -401,9 +437,7 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) {
} }
if (mDecodingAndMask) { if (mDecodingAndMask) {
PRUint32 rowSize = (mDirEntry.mWidth + 7) / 8; // +7 to round up PRUint32 rowSize = CalcAlphaRowSize();
if (rowSize % 4)
rowSize += (4 - (rowSize % 4)); // Pad to DWORD Boundary
if (mPos == (1 + mImageOffset + BITMAPINFOSIZE + mNumColors*4)) { if (mPos == (1 + mImageOffset + BITMAPINFOSIZE + mNumColors*4)) {
mPos++; mPos++;

Просмотреть файл

@ -93,6 +93,8 @@ private:
nsresult SetImageData(); nsresult SetImageData();
nsresult SetAlphaData(); nsresult SetAlphaData();
PRUint32 CalcAlphaRowSize();
private: private:
nsCOMPtr<imgIDecoderObserver> mObserver; nsCOMPtr<imgIDecoderObserver> mObserver;
nsCOMPtr<imgIContainer> mImage; nsCOMPtr<imgIContainer> mImage;