diff --git a/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.cpp b/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.cpp index 8c399042b15..a2fce56a0d1 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.cpp +++ b/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.cpp @@ -141,46 +141,7 @@ NS_IMETHODIMP nsBMPDecoder::WriteFrom(nsIInputStream *aInStr, PRUint32 aCount, P // Actual Data Processing // ---------------------------------------- -inline nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 idx) -{ - PRUint8 red, green, blue; - red = mColors[idx].red; - green = mColors[idx].green; - blue = mColors[idx].blue; - return SetPixel(aDecoded, red, green, blue); -} - -inline nsresult nsBMPDecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue) -{ -#if defined(XP_MAC) || defined(XP_MACOSX) - *aDecoded++ = 0; // Mac needs this padding byte -#endif -#ifdef USE_RGB - *aDecoded++ = aRed; - *aDecoded++ = aGreen; - *aDecoded++ = aBlue; -#else - *aDecoded++ = aBlue; - *aDecoded++ = aGreen; - *aDecoded++ = aRed; -#endif - return NS_OK; -} - -inline nsresult nsBMPDecoder::Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PRUint32& aPos) -{ - PRUint8 idx = aData >> 4; - nsresult rv = SetPixel(aDecoded, idx); - if ((++aPos >= mBIH.width) || NS_FAILED(rv)) - return rv; - - idx = aData & 0xF; - rv = SetPixel(aDecoded, idx); - ++aPos; - return rv; -} - -inline nsresult nsBMPDecoder::SetData(PRUint8* aData) +nsresult nsBMPDecoder::SetData(PRUint8* aData) { PRUint32 bpr; nsresult rv; @@ -394,7 +355,7 @@ NS_METHOD nsBMPDecoder::ProcessData(const char* aBuffer, PRUint32 aCount) if (lpos >= mBIH.width) break; idx = (*p >> bit) & 1; - SetPixel(d, idx); + SetPixel(d, idx, mColors); ++lpos; } ++p; @@ -402,13 +363,13 @@ NS_METHOD nsBMPDecoder::ProcessData(const char* aBuffer, PRUint32 aCount) break; case 4: while (lpos < mBIH.width) { - Set4BitPixel(d, *p, lpos); + Set4BitPixel(d, *p, lpos, mBIH.width, mColors); ++p; } break; case 8: while (lpos < mBIH.width) { - SetPixel(d, *p); + SetPixel(d, *p, mColors); ++lpos; ++p; } diff --git a/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.h b/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.h index 6a75747f001..b40772a9000 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.h +++ b/mozilla/modules/libpr0n/decoders/bmp/nsBMPDecoder.h @@ -133,22 +133,10 @@ private: * @oaram count Number of bytes in mBuffer */ NS_METHOD ProcessData(const char* aBuffer, PRUint32 aCount); - /** Sets the pixel data in aDecoded to the given values. - * The variable passed in as aDecoded will be moved on 3 bytes! */ - inline nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aIdx); - inline nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue); - - /** Sets one or two pixels; it is ensured that aPos is <= mBIH.width - * @param aDecoded where the data is stored. Will be moved 3 or 6 bytes, - * depending on whether one or two pixels are written. - * @param aData The values for the two pixels - * @param aPos Current position. Is incremented by one or two. */ - inline nsresult Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PRUint32& aPos); - /** Sets the image data at specified position. mCurLine is used * to get the row * @param aData The data */ - inline nsresult SetData(PRUint8* aData); + nsresult SetData(PRUint8* aData); nsCOMPtr mObserver; @@ -176,5 +164,53 @@ private: void ProcessInfoHeader(); }; +/** Sets the pixel data in aDecoded to the given values. + * The variable passed in as aDecoded will be moved on 3 bytes! */ +inline nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue) +{ +#if defined(XP_MAC) || defined(XP_MACOSX) + *aDecoded++ = 0; // Mac needs this padding byte +#endif +#ifdef USE_RGB + *aDecoded++ = aRed; + *aDecoded++ = aGreen; + *aDecoded++ = aBlue; +#else + *aDecoded++ = aBlue; + *aDecoded++ = aGreen; + *aDecoded++ = aRed; +#endif + return NS_OK; +} + +inline nsresult SetPixel(PRUint8*& aDecoded, PRUint8 idx, colorTable* aColors) +{ + PRUint8 red, green, blue; + red = aColors[idx].red; + green = aColors[idx].green; + blue = aColors[idx].blue; + return SetPixel(aDecoded, red, green, blue); +} + +/** Sets one or two pixels; it is ensured that aPos is <= mBIH.width + * @param aDecoded where the data is stored. Will be moved 3 or 6 bytes, + * depending on whether one or two pixels are written. + * @param aData The values for the two pixels + * @param aPos Current position. Is incremented by one or two. */ +inline nsresult Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, + PRUint32& aPos, PRUint32 aMaxWidth, colorTable* aColors) +{ + PRUint8 idx = aData >> 4; + nsresult rv = SetPixel(aDecoded, idx, aColors); + if ((++aPos >= aMaxWidth) || NS_FAILED(rv)) + return rv; + + idx = aData & 0xF; + rv = SetPixel(aDecoded, idx, aColors); + ++aPos; + return rv; +} + + #endif diff --git a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp index 302b1beaf91..bbb68f1b9a5 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp +++ b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.cpp @@ -64,43 +64,6 @@ NS_IMPL_ISUPPORTS1(nsICODecoder, imgIDecoder) // Actual Data Processing // ---------------------------------------- -inline nsresult nsICODecoder::SetPixel(PRUint8*& aDecoded, PRUint8 idx) { - PRUint8 red, green, blue; - red = mColors[idx].red; - green = mColors[idx].green; - blue = mColors[idx].blue; - return SetPixel(aDecoded, red, green, blue); -} - -inline nsresult nsICODecoder::SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue) { -#if defined(XP_MAC) || defined(XP_MACOSX) - *aDecoded++ = 0; // Mac needs this padding byte -#endif -#ifdef USE_RGBA1 - *aDecoded++ = aRed; - *aDecoded++ = aGreen; - *aDecoded++ = aBlue; -#else - *aDecoded++ = aBlue; - *aDecoded++ = aGreen; - *aDecoded++ = aRed; -#endif - return NS_OK; -} - -inline nsresult nsICODecoder::Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PRUint32& aPos) -{ - PRUint8 idx = aData >> 4; - nsresult rv = SetPixel(aDecoded, idx); - if ((++aPos >= mDirEntry.mWidth) || NS_FAILED(rv)) - return rv; - - idx = aData & 0xF; - rv = SetPixel(aDecoded, idx); - ++aPos; - return rv; -} - inline nsresult nsICODecoder::SetImageData() { PRUint32 bpr; @@ -383,7 +346,7 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) { if (lpos >= mDirEntry.mWidth) break; idx = (*p >> bit) & 1; - SetPixel(d, idx); + SetPixel(d, idx, mColors); ++lpos; } ++p; @@ -391,13 +354,13 @@ nsresult nsICODecoder::ProcessData(const char* aBuffer, PRUint32 aCount) { break; case 4: while (lpos < mDirEntry.mWidth) { - Set4BitPixel(d, *p, lpos); + Set4BitPixel(d, *p, lpos, mDirEntry.mWidth, mColors); ++p; } break; case 8: while (lpos < mDirEntry.mWidth) { - SetPixel(d, *p); + SetPixel(d, *p, mColors); ++lpos; ++p; } diff --git a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.h b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.h index b7d16d40053..27be55313bc 100644 --- a/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.h +++ b/mozilla/modules/libpr0n/decoders/bmp/nsICODecoder.h @@ -90,9 +90,6 @@ private: void ProcessDirEntry(IconDirEntry& aTarget); void ProcessInfoHeader(); - nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aIdx); - nsresult SetPixel(PRUint8*& aDecoded, PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue); - nsresult Set4BitPixel(PRUint8*& aDecoded, PRUint8 aData, PRUint32& aPos); nsresult SetImageData(); nsresult SetAlphaData();