GraphicsMagick: WritePCXImage(): Support writing uncompressed PC...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.38188.1672420633.1350.graphicsmagick-commit@lists.sourceforge.net>
changeset df23d5fab948 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=df23d5fab948
summary: WritePCXImage(): Support writing uncompressed PCX by default.  Use -compress RLE to enable RLE compression.

diffstat:

 ChangeLog          |   3 +++
 coders/pcx.c       |  53 ++++++++++++++++++++++++++++++++---------------------
 www/Changelog.html |   2 ++
 3 files changed, 37 insertions(+), 21 deletions(-)

diffs (132 lines):

diff -r d336319f317c -r df23d5fab948 ChangeLog
--- a/ChangeLog	Fri Dec 30 10:42:37 2022 -0600
+++ b/ChangeLog	Fri Dec 30 11:16:59 2022 -0600
@@ -1,5 +1,8 @@
 2022-12-30  Bob Friesenhahn  <[email protected]>
 
+	* coders/pcx.c (WritePCXImage): Support writing uncompressed PCX
+	by default.  Use -compress RLE to enable RLE compression.
+
 	* coders/sun.c (ReadSUNImage): Sense of monochrome images was
 	inverted.  Fix scanline size calculation.
 	(WriteSUNImage): Sense of monochrome images was inverted.
diff -r d336319f317c -r df23d5fab948 coders/pcx.c
--- a/coders/pcx.c	Fri Dec 30 10:42:37 2022 -0600
+++ b/coders/pcx.c	Fri Dec 30 11:16:59 2022 -0600
@@ -924,7 +924,7 @@
 %
 %
 */
-static MagickPassFail WriteRLEPixels(Image *image,
+static MagickPassFail WritePCXPixels(Image *image,
                                      PCXInfo *pcx_info,
                                      const unsigned char *pcx_row_pixels)
 {
@@ -945,16 +945,32 @@
   /* For each color plane ... */
   for (i=0; i < (long) pcx_info->planes; i++)
     {
-      previous=(*q++);
-      count=1;
-      /* For each column ... */
-      for (x=0; x < (long) (pcx_info->bytes_per_line-1); x++)
+      if (pcx_info->encoding == 0)
+        {
+          for (x=0; x < (long) pcx_info->bytes_per_line; x++)
+            (void) WriteBlobByte(image,(unsigned char) (*q++));
+        }
+      else
         {
-          packet=(*q++);
-          if ((packet == previous) && (count < 63))
+          previous=(*q++);
+          count=1;
+          /* For each column ... */
+          for (x=0; x < (long) (pcx_info->bytes_per_line-1); x++)
             {
-              count++;
-              continue;
+              packet=(*q++);
+              if ((packet == previous) && (count < 63))
+                {
+                  count++;
+                  continue;
+                }
+              if ((count > 1) || ((previous & 0xc0) == 0xc0))
+                {
+                  count|=0xc0;
+                  (void) WriteBlobByte(image,count);
+                }
+              (void) WriteBlobByte(image,previous);
+              previous=packet;
+              count=1;
             }
           if ((count > 1) || ((previous & 0xc0) == 0xc0))
             {
@@ -962,15 +978,7 @@
               (void) WriteBlobByte(image,count);
             }
           (void) WriteBlobByte(image,previous);
-          previous=packet;
-          count=1;
         }
-      if ((count > 1) || ((previous & 0xc0) == 0xc0))
-        {
-          count|=0xc0;
-          (void) WriteBlobByte(image,count);
-        }
-      (void) WriteBlobByte(image,previous);
     }
   return (MagickPass);
 }
@@ -1097,7 +1105,10 @@
     */
     pcx_info.identifier=0x0a;
     pcx_info.version=5;
-    pcx_info.encoding=1;
+    pcx_info.encoding=image->compression == RLECompression ? 1 : 0;
+    (void) LogMagickEvent(CoderEvent,GetMagickModule(),
+                          "Using %s compression",
+                          pcx_info.encoding == 1 ? "RLE" : "No");
     pcx_info.bits_per_pixel=8;
     if (characteristics.palette && characteristics.monochrome)
       pcx_info.bits_per_pixel=1;
@@ -1240,7 +1251,7 @@
                 }
               }
           }
-          if (WriteRLEPixels(image,&pcx_info,pcx_pixels) == MagickFail)
+          if (WritePCXPixels(image,&pcx_info,pcx_pixels) == MagickFail)
             break;
           if (QuantumTick(y,image->rows))
             if (!MagickMonitorFormatted(y,image->rows,&image->exception,
@@ -1265,7 +1276,7 @@
           /* For each column ... */
           for (x=0; x < (long) image->columns; x++)
             *q++=indexes[x];
-          if (WriteRLEPixels(image,&pcx_info,pcx_pixels) == MagickFail)
+          if (WritePCXPixels(image,&pcx_info,pcx_pixels) == MagickFail)
             break;
           if (image->previous == (Image *) NULL)
             if (QuantumTick(y,image->rows))
@@ -1315,7 +1326,7 @@
             }
             if (bit != 0)
               *q++=byte << (8-bit);
-            if (WriteRLEPixels(image,&pcx_info,pcx_pixels) == MagickFail)
+            if (WritePCXPixels(image,&pcx_info,pcx_pixels) == MagickFail)
             break;
             if (image->previous == (Image *) NULL)
               if (QuantumTick(y,image->rows))
diff -r d336319f317c -r df23d5fab948 www/Changelog.html
--- a/www/Changelog.html	Fri Dec 30 10:42:37 2022 -0600
+++ b/www/Changelog.html	Fri Dec 30 11:16:59 2022 -0600
@@ -40,6 +40,8 @@
 <p>2022-12-30  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 <blockquote>
 <ul class="simple">
+<li><p>coders/pcx.c (WritePCXImage): Support writing uncompressed PCX
+by default.  Use -compress RLE to enable RLE compression.</p></li>
 <li><p>coders/sun.c (ReadSUNImage): Sense of monochrome images was
 inverted.  Fix scanline size calculation.
 (WriteSUNImage): Sense of monochrome images was inverted.</p></li>
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.