GraphicsMagick: coders/bmp.c BMP with 2bpp is a legal BMP variant

GraphicsMagick Commits <[email protected]> Thu, 31 Aug 2023 03:29:21 -0500
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.13039.1693470574.1374.graphicsmagick-commit@lists.sourceforge.net>
changeset 492601effd79 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=492601effd79
summary: coders/bmp.c BMP with 2bpp is a legal BMP variant

diffstat:

 ChangeLog    |  8 ++++++++
 coders/bmp.c |  6 ++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diffs (45 lines):

diff -r 9ca1ad7cc387 -r 492601effd79 ChangeLog
--- a/ChangeLog	Mon Aug 28 19:24:29 2023 -0500
+++ b/ChangeLog	Thu Aug 31 10:29:05 2023 +0200
@@ -1,3 +1,11 @@
+2023-08-31  Fojtik Jaroslav  <[email protected]>
+
+	* coders/bmp.c BMP with 2bpp is a legal BMP variant.
+	https://en.wikipedia.org/wiki/BMP_file_format
+	Quote: "The 2-bit per pixel (2bpp) format supports 4 distinct colors and stores 
+        4 pixels per 1 byte, the left-most pixel being in the two most significant bits 
+        (Windows CE only)."
+
 2023-08-29  Fojtik Jaroslav  <[email protected]>
 
 	* coders/bmp.c First attempt to read BMP with BI_JPEG compression 
diff -r 9ca1ad7cc387 -r 492601effd79 coders/bmp.c
--- a/coders/bmp.c	Mon Aug 28 19:24:29 2023 -0500
+++ b/coders/bmp.c	Thu Aug 31 10:29:05 2023 +0200
@@ -546,9 +546,6 @@
         Image *image2;
         ImageInfo *clone_info;
 
-        //FILE *F = fopen("o:\\temp\\27\\pokus.jpg","wb");
-        //if(F) {fwrite(blob,alloc_size,1,F);fclose(F);}
-
         clone_info = CloneImageInfo(image_info);
 
               /* BlobToFile("/tmp/jnx-tile.jpg", blob,alloc_size,exception); */
@@ -1153,7 +1150,7 @@
       if (bmp_info.planes != 1)
         ThrowBMPReaderException(CorruptImageError,StaticPlanesValueNotEqualToOne,
                                 image);
-      if ((bmp_info.bits_per_pixel != 1) && (bmp_info.bits_per_pixel != 4) &&
+      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))
         ThrowBMPReaderException(CorruptImageError,UnrecognizedBitsPerPixel,image);
@@ -1479,6 +1476,7 @@
               }
             break;
           }
+        case 2:
         case 4:
           {
             /*