GraphicsMagick: coders/wpg.c Fixed bug in RLE compression algori...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.2128.1673795330.1727.graphicsmagick-commit@lists.sourceforge.net>
changeset e45959c63388 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=e45959c63388
summary: coders/wpg.c Fixed bug in RLE compression algorithm.

diffstat:

 coders/wpg.c |  20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diffs (69 lines):

diff -r 1beca50cc2b8 -r e45959c63388 coders/wpg.c
--- a/coders/wpg.c	Sun Jan 15 12:48:46 2023 +0100
+++ b/coders/wpg.c	Sun Jan 15 16:07:49 2023 +0100
@@ -1797,6 +1797,7 @@
 	unsigned char buf[254];
 } WPG_RLE_packer;
 
+//FILE *DebugRLE = NULL;
 
 static void WPG_RLE_Flush(WPG_RLE_packer *WPG_RLE, Image *image, unsigned char n)
 {
@@ -1804,6 +1805,7 @@
   if(n>0x7F) n=0x7F;
   if(n>0)
   {
+    //if(DebugRLE) fprintf(DebugRLE," size=%X",n);
     WriteBlobByte(image,n);
     WriteBlob(image, n, WPG_RLE->buf);
     WPG_RLE->pos -= n;
@@ -1819,6 +1821,13 @@
 {
   WPG_RLE->buf[WPG_RLE->pos++] = b;
 
+/*  if(DebugRLE)
+  {
+    fprintf(DebugRLE,"\n%u",b);
+    if(WPG_RLE->pos>=0x7E)
+	fprintf(DebugRLE," *%u %X", WPG_RLE->pos, WPG_RLE->pos);
+  } */
+
   if(WPG_RLE->pos>1)
   {
     if(WPG_RLE->count==0x7E || WPG_RLE->buf[WPG_RLE->pos-2]!=b)
@@ -1829,6 +1838,7 @@
         WPG_RLE_Flush(WPG_RLE, image, WPG_RLE->pos-1-WPG_RLE->count);
         WriteBlobByte(image, WPG_RLE->count|0x80);
         WriteBlobByte(image, WPG_RLE->buf[0]);
+        //if(DebugRLE) fprintf(DebugRLE," count=%X, val=%X",WPG_RLE->count,WPG_RLE->buf[0]);
         WPG_RLE->pos = 1;
         WPG_RLE->buf[0] = b;
       }
@@ -1838,11 +1848,16 @@
       WPG_RLE->count++;
   }
 
-  if(WPG_RLE->pos>=254)
+  if(WPG_RLE->pos-WPG_RLE->count>0x7E)	// We have uncompressible block with size 0x7F.
   {
     WPG_RLE_Flush(WPG_RLE, image, 0x7F);
     return;
   }
+  if(WPG_RLE->pos>0x7E && WPG_RLE->count>=1)
+  {
+    WPG_RLE_Flush(WPG_RLE, image, WPG_RLE->pos-1-WPG_RLE->count);
+    return;
+  }
 }
 
 
@@ -2028,6 +2043,9 @@
   */
   for(y=0; y<(long)image->rows; y++)
   {
+    //if(y==1310 && DebugRLE==NULL) DebugRLE=fopen("o:\\temp\\14\\debug.txt","wb");
+    //if(y>1310 && DebugRLE) {fclose(DebugRLE);DebugRLE=NULL;}
+
     if(AcquireImagePixels(image,0,y,image->columns,1,&image->exception) == (const PixelPacket *)NULL)
     {
       status = MagickFail;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.