]> granicus.if.org Git - imagemagick/commitdiff
https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=32848
authorCristy <urban-warrior@imagemagick.org>
Mon, 16 Oct 2017 23:41:54 +0000 (19:41 -0400)
committerCristy <urban-warrior@imagemagick.org>
Mon, 16 Oct 2017 23:41:54 +0000 (19:41 -0400)
coders/wpg.c

index 03937e06be6cfc513e4074a903579d4d1a6a9a2d..6fbfe42664b1e97dc80ec71860f0c0c3fa3cf6e7 100644 (file)
@@ -264,8 +264,8 @@ static void Rd_WP_DWORD(Image *image,size_t *d)
   return;
 }
 
-static void InsertRow(Image *image,unsigned char *p,ssize_t y,int bpp,
-  ExceptionInfo *exception)
+static MagickBooleanType InsertRow(Image *image,unsigned char *p,ssize_t y,
+  int bpp,ExceptionInfo *exception)
 {
   int
     bit;
@@ -279,13 +279,13 @@ static void InsertRow(Image *image,unsigned char *p,ssize_t y,int bpp,
   ssize_t
     x;
 
+  q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
+  if (q == (Quantum *) NULL)
+    return(MagickFalse);
   switch (bpp)
     {
     case 1:  /* Convert bitmap scanline. */
       {
-        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-        if (q == (Quantum *) NULL)
-          break;
         for (x=0; x < ((ssize_t) image->columns-7); x+=8)
         {
           for (bit=0; bit < 8; bit++)
@@ -308,15 +308,10 @@ static void InsertRow(Image *image,unsigned char *p,ssize_t y,int bpp,
             }
             p++;
           }
-        if (!SyncAuthenticPixels(image,exception))
-          break;
         break;
       }
     case 2:  /* Convert PseudoColor scanline. */
       {
-        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-        if (q == (Quantum *) NULL)
-          break;
         for (x=0; x < ((ssize_t) image->columns-3); x+=4)
         {
             index=ConstrainColormapIndex(image,(*p >> 6) & 0x3,exception);
@@ -360,16 +355,11 @@ static void InsertRow(Image *image,unsigned char *p,ssize_t y,int bpp,
               }
             p++;
           }
-        if (SyncAuthenticPixels(image,exception) == MagickFalse)
-          break;
         break;
       }
  
     case 4:  /* Convert PseudoColor scanline. */
       {
-        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-        if (q == (Quantum *) NULL)
-          break;
         for (x=0; x < ((ssize_t) image->columns-1); x+=2)
           { 
             index=ConstrainColormapIndex(image,(*p >> 4) & 0x0f,exception);
@@ -390,15 +380,10 @@ static void InsertRow(Image *image,unsigned char *p,ssize_t y,int bpp,
             p++;
             q+=GetPixelChannels(image);
           }
-        if (SyncAuthenticPixels(image,exception) == MagickFalse)
-          break;
         break;
       }
     case 8: /* Convert PseudoColor scanline. */
       {
-        q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-        if (q == (Quantum *) NULL) break;
-
         for (x=0; x < (ssize_t) image->columns; x++)
           {
             index=ConstrainColormapIndex(image,*p,exception);
@@ -407,15 +392,10 @@ static void InsertRow(Image *image,unsigned char *p,ssize_t y,int bpp,
             p++;
             q+=GetPixelChannels(image);
           }
-        if (SyncAuthenticPixels(image,exception) == MagickFalse)
-          break;
       }
       break;
      
     case 24:     /*  Convert DirectColor scanline.  */
-      q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
-      if (q == (Quantum *) NULL)
-        break;
       for (x=0; x < (ssize_t) image->columns; x++)
         {
           SetPixelRed(image,ScaleCharToQuantum(*p++),q);
@@ -423,10 +403,11 @@ static void InsertRow(Image *image,unsigned char *p,ssize_t y,int bpp,
           SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
           q+=GetPixelChannels(image);
         }
-      if (!SyncAuthenticPixels(image,exception))
-        break;
       break;
     }
+  if (!SyncAuthenticPixels(image,exception))
+    return(MagickFalse);
+  return(MagickTrue);
 }
 
 
@@ -437,10 +418,10 @@ static void InsertRow(Image *image,unsigned char *p,ssize_t y,int bpp,
   x++; \
   if((ssize_t) x>=ldblk) \
   { \
-    InsertRow(image,BImgBuff,(ssize_t) y,bpp,exception); \
+    if (InsertRow(image,BImgBuff,(ssize_t) y,bpp,exception) != MagickFalse) \
+      y++; \
     x=0; \
-    y++; \
-    } \
+  } \
 }
 /* WPG1 raster reader. */
 static int UnpackWPGRaster(Image *image,int bpp,ExceptionInfo *exception)
@@ -544,9 +525,9 @@ RestoreMSCWarning \
   x++; \
   if((ssize_t) x >= ldblk) \
   { \
-    InsertRow(image,BImgBuff,(ssize_t) y,bpp,exception); \
+    if (InsertRow(image,BImgBuff,(ssize_t) y,bpp,exception) != MagickFalse) \
+      y++; \
     x=0; \
-    y++; \
    } \
 }
 /* WPG2 raster reader. */
@@ -637,9 +618,9 @@ static int UnpackWPG2Raster(Image *image,int bpp,ExceptionInfo *exception)
             /* duplicate the previous row RunCount x */
             for(i=0;i<=RunCount;i++)
               {      
-                InsertRow(image,BImgBuff,(ssize_t) (image->rows >= y ? y : image->rows-1),
-                          bpp,exception);
-                y++;
+                if (InsertRow(image,BImgBuff,(ssize_t) (image->rows >= y ? y : image->rows-1),
+                          bpp,exception) != MagickFalse)
+                  y++;
               }    
           }
           break;