diff --git a/image/encoders/bmp/nsBMPEncoder.cpp b/image/encoders/bmp/nsBMPEncoder.cpp index ade37621afc..fe1f84bebb6 100644 --- a/image/encoders/bmp/nsBMPEncoder.cpp +++ b/image/encoders/bmp/nsBMPEncoder.cpp @@ -437,17 +437,26 @@ void nsBMPEncoder::ConvertHostARGBRow(const PRUint8* aSrc, PRUint8* aDest, PRUint32 aPixelWidth) { - for (PRUint32 x = 0; x < aPixelWidth; x ++) { - const PRUint32& pixelIn = ((const PRUint32*)(aSrc))[x]; - PRUint8 *pixelOut = &aDest[x * BytesPerPixel(mBMPInfoHeader.bpp)]; + int bytes = BytesPerPixel(mBMPInfoHeader.bpp); - PRUint8 alpha = (pixelIn & 0xff000000) >> 24; - pixelOut[0] = (((pixelIn & 0xff0000) >> 16)); - pixelOut[1] = (((pixelIn & 0x00ff00) >> 8)); - pixelOut[2] = (((pixelIn & 0x0000ff) >> 0)); + if (mBMPInfoHeader.bpp == 32) { + for (PRUint32 x = 0; x < aPixelWidth; x++) { + const PRUint32& pixelIn = ((const PRUint32*)(aSrc))[x]; + PRUint8 *pixelOut = &aDest[x * bytes]; - if (mBMPInfoHeader.bpp == 32) { - pixelOut[3] = alpha; + pixelOut[0] = (pixelIn & 0x00ff0000) >> 16; + pixelOut[1] = (pixelIn & 0x0000ff00) >> 8; + pixelOut[2] = (pixelIn & 0x000000ff) >> 0; + pixelOut[3] = (pixelIn & 0xff000000) >> 24; + } + } else { + for (PRUint32 x = 0; x < aPixelWidth; x++) { + const PRUint32& pixelIn = ((const PRUint32*)(aSrc))[x]; + PRUint8 *pixelOut = &aDest[x * bytes]; + + pixelOut[0] = (pixelIn & 0xff0000) >> 16; + pixelOut[1] = (pixelIn & 0x00ff00) >> 8; + pixelOut[2] = (pixelIn & 0x0000ff) >> 0; } } }