Bug 408288 - "This particular animated gif looks distorted at the right side" (Really do the clipping in the right way) [p=alfredkayser@nl.ibm.com (Alfred Kayser) r=stuart a=blocking1.9+]
authorreed@reedloden.com
Fri, 21 Dec 2007 03:41:59 -0800
changeset 9592 bcfa892b38ee96b0d83902416c19cad3be070162
parent 9591 459e478900b1537f9fc60f5d2b647187e480c0a2
child 9593 7d9372acf0430e6f0bf5bb94c118b68e36b3463c
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersstuart, blocking1.9
bugs408288
milestone1.9b3pre
Bug 408288 - "This particular animated gif looks distorted at the right side" (Really do the clipping in the right way) [p=alfredkayser@nl.ibm.com (Alfred Kayser) r=stuart a=blocking1.9+]
modules/libpr0n/src/imgContainer.cpp
--- a/modules/libpr0n/src/imgContainer.cpp
+++ b/modules/libpr0n/src/imgContainer.cpp
@@ -1118,18 +1118,18 @@ nsresult imgContainer::DrawFrameTo(gfxII
   gfx_format format;
   aSrc->GetFormat(&format);
   if (format == gfxIFormats::PAL || format == gfxIFormats::PAL_A1) {
     // Outside the destination frame, skip it
     if ((aDstRect.x > dstRect.width) || (aDstRect.y > dstRect.height)) {
       return NS_OK;
     }
     // Larger than the destination frame, clip it
-    PRUint32 width = (PRUint32)aDstRect.width;
-    PRUint32 height = (PRUint32)aDstRect.height;
+    PRInt32 width = (PRUint32)aDstRect.width;
+    PRInt32 height = (PRUint32)aDstRect.height;
     if (aDstRect.x + aDstRect.width > dstRect.width) {
       width = dstRect.width - aDstRect.x;
     }
     if (aDstRect.y + aDstRect.height > dstRect.height) {
       height = dstRect.height - aDstRect.y;
     }
     // dstRect must fully fit within destination image 
     NS_ASSERTION((aDstRect.x >= 0) && (aDstRect.y >= 0) &&
@@ -1155,32 +1155,35 @@ nsresult imgContainer::DrawFrameTo(gfxII
     if (!srcPixels || !dstPixels || !colormap) {
       aDst->UnlockImageData();
       return NS_ERROR_FAILURE;
     }
 
     // Skip to the right offset
     dstPixels += aDstRect.x + (aDstRect.y * dstRect.width);
     if (format == gfxIFormats::PAL) {
-      for (PRUint32 r = height; r > 0; --r) {
-        for (PRUint32 c = width; c > 0; --c) {
-          *dstPixels++ = colormap[*srcPixels++];
+      for (PRInt32 r = height; r > 0; --r) {
+        for (PRInt32 c = 0; c < width; c++) {
+          dstPixels[c] = colormap[srcPixels[c]];
         }
-        dstPixels += dstRect.width - width;
+        // Go to the next row in the source resp. destination image
+        srcPixels += srcRect.width;
+        dstPixels += dstRect.width;
       }
     } else {
       // With transparent source, skip transparent pixels
-      for (PRUint32 r = height; r > 0; --r) {
-        for (PRUint32 c = width; c > 0; --c) {
-          const PRUint32 color = colormap[*srcPixels++];
+      for (PRInt32 r = height; r > 0; --r) {
+        for (PRInt32 c = 0; c < width; c++) {
+          const PRUint32 color = colormap[srcPixels[c]];
           if (color)
-            *dstPixels = color;
-          dstPixels ++;
+            dstPixels[c] = color;
         }
-        dstPixels += dstRect.width - width;
+        // Go to the next row in the source resp. destination image
+        srcPixels += srcRect.width;
+        dstPixels += dstRect.width;
       }
     }
     aDst->UnlockImageData();
     return NS_OK;
   }
 
   nsCOMPtr<nsIImage> srcImg(do_GetInterface(aSrc));
   nsRefPtr<gfxASurface> srcSurf;