bug 168839 r=pavlov sr=tor share functions between ico and bmp decoder, making them non-member functions

git-svn-id: svn://10.0.0.236/trunk@129753 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
cbiesinger%web.de
2002-09-16 21:49:41 +00:00
parent a43827cf5e
commit a61c87f678
4 changed files with 56 additions and 99 deletions

View File

@@ -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;
}

View File

@@ -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<imgIDecoderObserver> 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

View File

@@ -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;
}

View File

@@ -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();