From 109e88735cb82a5bf0bee51f32c9bed25bba85f8 Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Wed, 23 Jul 2003 18:39:11 +0000 Subject: [PATCH] bug 198293 r=tor sr=scott@scott-macgregor.org support ICOs with alpha channel git-svn-id: svn://10.0.0.236/trunk@145120 18797224-902f-48f8-a5cc-f745e15eee43 --- .../libpr0n/decoders/bmp/nsICODecoder.cpp | 35 +++++++++++++++---- .../libpr0n/decoders/bmp/nsICODecoder.h | 2 ++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp index 5c0a6610948..add4c6ca890 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp +++ b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * David Hyatt (Original Author) + * Christian Biesinger * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -47,6 +48,8 @@ #include "imgILoad.h" +#include "nsAutoPtr.h" + NS_IMPL_ISUPPORTS1(nsICODecoder, imgIDecoder) #define ICONCOUNTOFFSET 4 @@ -90,6 +93,10 @@ nsresult nsICODecoder::SetImageData() nsresult nsICODecoder::SetAlphaData() { + // Alpha data was already set if bpp == 32 + if (mBIH.bpp == 32) + return NS_OK; + PRUint32 bpr; mFrame->GetAlphaBytesPerRow(&bpr); @@ -303,7 +310,10 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) { if (!mRow) return NS_ERROR_OUT_OF_MEMORY; - rv = mFrame->Init(0, 0, mDirEntry.mWidth, mDirEntry.mHeight, GFXFORMATALPHA, 24); + if (mBIH.bpp == 32) + rv = mFrame->Init(0, 0, mDirEntry.mWidth, mDirEntry.mHeight, GFXFORMATALPHA8, 24); + else + rv = mFrame->Init(0, 0, mDirEntry.mWidth, mDirEntry.mHeight, GFXFORMATALPHA, 24); NS_ENSURE_SUCCESS(rv, rv); rv = mImage->AppendFrame(mFrame); NS_ENSURE_SUCCESS(rv, rv); @@ -338,8 +348,8 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) { } if (!mDecodingAndMask && (mPos >= (mImageOffset + BITMAPINFOSIZE + mNumColors*4))) { - // Increment mPos to avoid reprocessing the info header. if (mPos == (mImageOffset + BITMAPINFOSIZE + mNumColors*4)) { + // Increment mPos to avoid reprocessing the info header. mPos++; #if defined(XP_MAC) || defined(XP_MACOSX) mDecodedBuffer = new PRUint8[mDirEntry.mHeight*mDirEntry.mWidth*4]; @@ -349,6 +359,14 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) { if (!mDecodedBuffer) return NS_ERROR_OUT_OF_MEMORY; } + PRUint32 alphaRowSize; + mFrame->GetAlphaBytesPerRow(&alphaRowSize); + nsAutoArrayPtr alphaRow; // Will only be used if bpp == 32 + if (mBIH.bpp == 32) { + alphaRow = new PRUint8[alphaRowSize]; + if (!alphaRow) + return NS_ERROR_OUT_OF_MEMORY; + } PRUint32 rowSize = (mBIH.bpp * mDirEntry.mWidth + 7) / 8; // +7 to round up if (rowSize % 4) @@ -369,6 +387,7 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) { PRUint8* decoded = mDecodedBuffer + (mCurLine * mDirEntry.mWidth * GFXBYTESPERPIXEL); PRUint8* p = mRow; PRUint8* d = decoded; + PRUint8* alphaPos = alphaRow; // only used if bpp == 32 PRUint32 lpos = mDirEntry.mWidth; switch (mBIH.bpp) { case 1: @@ -411,11 +430,10 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) { case 24: while (lpos > 0) { SetPixel(d, p[2], p[1], p[0]); - p += 2; + p += 3; --lpos; if (mBIH.bpp == 32) - p++; // Padding byte - ++p; + *alphaPos++ = *p++; // Alpha value } break; default: @@ -427,11 +445,16 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) { mDecodingAndMask = PR_TRUE; mRowBytes = 0; + + // If 32 bit image, gotta set the alpha data here + if (mBIH.bpp == 32) + mFrame->SetAlphaData(alphaRow, alphaRowSize, mCurLine * alphaRowSize); } } while (!mDecodingAndMask && aCount > 0); + } - if (mDecodingAndMask) { + if (mDecodingAndMask && mBIH.bpp != 32) { PRUint32 rowSize = CalcAlphaRowSize(); if (mPos == (1 + mImageOffset + BITMAPINFOSIZE + mNumColors*4)) { diff --git a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.h b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.h index d14d2726a5c..d394059e448 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.h +++ b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.h @@ -53,9 +53,11 @@ #if defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS) || defined(MOZ_WIDGET_PHOTON) #define GFXFORMATALPHA gfxIFormats::BGR_A1 +#define GFXFORMATALPHA8 gfxIFormats::BGR_A8 #else #define USE_RGBA1 #define GFXFORMATALPHA gfxIFormats::RGB_A1 +#define GFXFORMATALPHA8 gfxIFormats::RGB_A8 #endif struct IconDirEntry