GraphicsMagick: coders/bmp.c: Attempt to read BMP with 64bpp.

GraphicsMagick Commits <[email protected]> Sat, 30 Sep 2023 03:24:25 -0500
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.4978.1696062275.1370.graphicsmagick-commit@lists.sourceforge.net>
changeset a912997ee896 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=a912997ee896
summary: coders/bmp.c: Attempt to read BMP with 64bpp.

diffstat:

 ChangeLog    |   4 ++++
 coders/bmp.c |  45 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletions(-)

diffs (81 lines):

diff -r bb0790772c50 -r a912997ee896 ChangeLog
--- a/ChangeLog	Thu Sep 28 13:53:18 2023 -0500
+++ b/ChangeLog	Sat Sep 30 10:23:59 2023 +0200
@@ -1,3 +1,7 @@
+2023-09-30  Fojtik Jaroslav  <[email protected]>
+
+	* coders/bmp.c: Attempt to read BMP with 64bpp.
+
 2023-09-28  Bob Friesenhahn  <[email protected]>
 
 	* coders/bmp.c (StoreAlienBlob): Fix compilation warning in log
diff -r bb0790772c50 -r a912997ee896 coders/bmp.c
--- a/coders/bmp.c	Thu Sep 28 13:53:18 2023 -0500
+++ b/coders/bmp.c	Sat Sep 30 10:23:59 2023 +0200
@@ -1216,7 +1216,7 @@
                                 image);
       if ((bmp_info.bits_per_pixel != 1) && (bmp_info.bits_per_pixel != 2) && (bmp_info.bits_per_pixel != 4) &&
           (bmp_info.bits_per_pixel != 8) && (bmp_info.bits_per_pixel != 16) &&
-          (bmp_info.bits_per_pixel != 24) && (bmp_info.bits_per_pixel != 32))
+          (bmp_info.bits_per_pixel != 24) && (bmp_info.bits_per_pixel != 32) && (bmp_info.bits_per_pixel != 64))
         ThrowBMPReaderException(CorruptImageError,UnrecognizedBitsPerPixel,image);
       if (bmp_info.bits_per_pixel < 16)
         {
@@ -1232,7 +1232,14 @@
 
       image->columns=bmp_info.width;
       image->rows=AbsoluteValue(bmp_info.height);
+#if (QuantumDepth == 8)
       image->depth=8;
+#else
+      if(bmp_info.bits_per_pixel == 64)
+          image->depth=16;
+      else
+          image->depth=8;
+#endif
       /*
         Image has alpha channel if alpha mask is specified, or is
         uncompressed and 32-bits per pixel
@@ -1770,6 +1777,42 @@
             /* if(ZeroOpacity) image->matte = False; */
             break;
           }
+        case 64:
+          {
+            register magick_uint16_t *p16;
+            /*
+              Convert DirectColor scanline.
+            */
+            bytes_per_line = 4*((image->columns*64+31)/32);
+            for(y=(long) image->rows-1; y >= 0; y--)
+              {
+                p16 = pixels+(image->rows-y-1)*bytes_per_line;
+                q = SetImagePixels(image,0,y,image->columns,1);
+                if(q == (PixelPacket *) NULL)
+                  break;
+                for(x=0; x < (long) image->columns; x++)
+                  {
+                    q->blue=ScaleShortToQuantum(*p16++);
+                    q->green=ScaleShortToQuantum(*p16++);
+                    q->red=ScaleShortToQuantum(*p16++);
+                    p16++;	/* TODO: add alpha*/
+                    q++;
+                  }
+                if(!SyncImagePixels(image))
+                  break;
+                if(image->previous == (Image *) NULL)
+                  if(QuantumTick(y,image->rows))
+                    {
+                      status=MagickMonitorFormatted(image->rows-y-1,image->rows,
+                                                    exception,LoadImageText,
+                                                    image->filename,
+                                                    image->columns,image->rows);
+                      if(status == False)
+                        break;
+                    }
+              }
+            break;
+          }
         default:
           ThrowBMPReaderException(CorruptImageError,ImproperImageHeader,image)
             }