Bug 723453 - Split cases for ConvertHostARGB - r=joe, a=akeybl
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 10 Feb 2012 15:41:24 -0800
changeset 88696 6e53f939f79514bc4a0980b2212ce3b5fea58992
parent 88695 1117e4172a90e59d6de484be81d546cb50eba3e6
child 88697 75bd6549d1ce609974f866cb7671aec4103377ef
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersjoe, akeybl
bugs723453
milestone12.0
Bug 723453 - Split cases for ConvertHostARGB - r=joe, a=akeybl
image/encoders/bmp/nsBMPEncoder.cpp
--- a/image/encoders/bmp/nsBMPEncoder.cpp
+++ b/image/encoders/bmp/nsBMPEncoder.cpp
@@ -432,27 +432,36 @@ NS_IMETHODIMP nsBMPEncoder::CloseWithSta
 //
 //    Our colors are stored with premultiplied alphas, but we need
 //    an output with no alpha in machine-independent byte order.
 //
 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);
+
+  if (mBMPInfoHeader.bpp == 32) {
+    for (PRUint32 x = 0; x < aPixelWidth; x++) {
+      const PRUint32& pixelIn = ((const PRUint32*)(aSrc))[x];
+      PRUint8 *pixelOut = &aDest[x * bytes];
 
-    PRUint8 alpha = (pixelIn & 0xff000000) >> 24;
-    pixelOut[0] = (((pixelIn & 0xff0000) >> 16));
-    pixelOut[1] = (((pixelIn & 0x00ff00) >>  8));
-    pixelOut[2] = (((pixelIn & 0x0000ff) >>  0));
+      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];
 
-    if (mBMPInfoHeader.bpp == 32) {
-      pixelOut[3] = alpha;
+      pixelOut[0] = (pixelIn & 0xff0000) >> 16;
+      pixelOut[1] = (pixelIn & 0x00ff00) >>  8;
+      pixelOut[2] = (pixelIn & 0x0000ff) >>  0;
     }
   }
 }
 
 // nsBMPEncoder::StripAlpha
 //
 //    Input is RGBA, output is RGB
 void