GraphicsMagick: coders/bmp.c After some investigations it seems ...
GraphicsMagick Commits <[email protected]> Mon, 04 Sep 2023 17:09:18 -0500
| Newsgroups | gmane.comp.video.graphicsmagick.cvs |
|---|---|
| Message-ID | <mailman.13861.1693865365.1761.graphicsmagick-commit@lists.sourceforge.net> |
changeset 1b6ccfd977e9 in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=1b6ccfd977e9 summary: coders/bmp.c After some investigations it seems that bit field masks are behind header when BI_SIZE=40. diffstat: ChangeLog | 6 ++++++ coders/bmp.c | 49 +++++++++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 20 deletions(-) diffs (99 lines): diff -r 97b9da97526a -r 1b6ccfd977e9 ChangeLog --- a/ChangeLog Mon Sep 04 09:05:06 2023 -0500 +++ b/ChangeLog Tue Sep 05 00:08:47 2023 +0200 @@ -1,3 +1,9 @@ +2023-09-05 Fojtik Jaroslav <[email protected]> + + * coders/bmp.c Sorry for previous commit. After some + investigations it seems that bit fieal masks are behind header + when BI_SIZE=40. + 2023-09-04 Fojtik Jaroslav <[email protected]> * coders/bmp.c Default bit split for older BMPs with 32bpp and diff -r 97b9da97526a -r 1b6ccfd977e9 coders/bmp.c --- a/coders/bmp.c Mon Sep 04 09:05:06 2023 -0500 +++ b/coders/bmp.c Tue Sep 05 00:08:47 2023 +0200 @@ -910,7 +910,6 @@ " Identifier: %u", Units, Reserved, Recording, Rendering, Size1, Size2, ColorEncoding, Identifier); - } if (bmp_info.size>=52 && bmp_info.size!=64) @@ -1131,12 +1130,32 @@ // ThrowBMPReaderException(CorruptImageError,UnrecognizedImageCompression,image); switch ((unsigned int) bmp_info.compression) { + case BI_BITFIELDS: + if(bmp_info.size==40) + { + /* TODO: check for gap size >=12*/ + bmp_info.red_mask=ReadBlobLSBLong(image); + bmp_info.green_mask=ReadBlobLSBLong(image); + bmp_info.blue_mask=ReadBlobLSBLong(image); + } + break; + case BI_ALPHABITFIELDS: + if(bmp_info.size==40) + { + /* TODO: check for gap size >=12*/ + bmp_info.red_mask=ReadBlobLSBLong(image); + bmp_info.green_mask=ReadBlobLSBLong(image); + bmp_info.blue_mask=ReadBlobLSBLong(image); + /* TODO: check for gap size >=16*/ + bmp_info.alpha_mask=ReadBlobLSBLong(image); + } + break; + case BI_RGB: case BI_RLE8: case BI_RLE4: - case BI_BITFIELDS: - case BI_ALPHABITFIELDS: break; + case BI_JPEG: offset = start_position + 14 + bmp_info.size; if(logging) @@ -1238,7 +1257,7 @@ image->colormap[i].green=ScaleCharToQuantum(*p++); image->colormap[i].red=ScaleCharToQuantum(*p++); if (packet_size == 4) - p++; + p++; } MagickFreeResourceLimitedMemory(bmp_colormap); } @@ -1416,24 +1435,14 @@ } if ( bmp_info.bits_per_pixel == 32) { - if(bmp_info.size<=52 && bmp_info.compression==BI_BITFIELDS) - { - bmp_info.blue_mask=0xFF0000; - bmp_info.green_mask=0xFF0; /* This is crazy :(. */ - bmp_info.red_mask=0xFF000000; - /*bmp_info.alpha_mask=0x0; */ - } - else + if(bmp_info.compression==BI_RGB || bmp_info.compression==BI_ALPHABITFIELDS) { - if(bmp_info.compression==BI_RGB || bmp_info.compression==BI_ALPHABITFIELDS) - { - image->matte = True; - bmp_info.alpha_mask=0xff000000U; - } - bmp_info.red_mask=0x00ff0000U; - bmp_info.green_mask=0x0000ff00U; - bmp_info.blue_mask=0x000000ffU; + image->matte = True; + bmp_info.alpha_mask=0xff000000U; } + bmp_info.red_mask=0x00ff0000U; + bmp_info.green_mask=0x0000ff00U; + bmp_info.blue_mask=0x000000ffU; } }