GraphicsMagick: coders/bmp.c Added support for BI_ALPHABITFIELDS...
GraphicsMagick Commits <[email protected]> Sun, 20 Aug 2023 05:24:46 -0500
| Newsgroups | gmane.comp.video.graphicsmagick.cvs |
|---|---|
| Message-ID | <mailman.10310.1692527098.1374.graphicsmagick-commit@lists.sourceforge.net> |
changeset 0b41c94e117f in /hg/GraphicsMagick details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=0b41c94e117f summary: coders/bmp.c Added support for BI_ALPHABITFIELDS compression. diffstat: ChangeLog | 7 +++++ coders/bmp.c | 73 +++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 57 insertions(+), 23 deletions(-) diffs (154 lines): diff -r a94c4fc24e8c -r 0b41c94e117f ChangeLog --- a/ChangeLog Sat Aug 19 15:12:22 2023 +0200 +++ b/ChangeLog Sun Aug 20 12:24:14 2023 +0200 @@ -1,3 +1,10 @@ +2023-08-20 Fojtik Jaroslav <[email protected]> + + * coders/bmp.c Added support for BI_ALPHABITFIELDS compression. + https://learn.microsoft.com/en-us/previous-versions/windows/embedded/aa452885(v=msdn.10) + Remove unwanted duplicite check condition of biCompression. + + 2023-08-19 Fojtik Jaroslav <[email protected]> * coders/bmp.c Reveal a contents of OS22XBITMAPHEADER. diff -r a94c4fc24e8c -r 0b41c94e117f coders/bmp.c --- a/coders/bmp.c Sat Aug 19 15:12:22 2023 +0200 +++ b/coders/bmp.c Sun Aug 20 12:24:14 2023 +0200 @@ -57,6 +57,9 @@ #define BI_JPEG 4 #undef BI_PNG #define BI_PNG 5 +#ifndef BI_ALPHABITFIELDS + #define BI_ALPHABITFIELDS 6 +#endif #if !defined(MSWINDOWS) || defined(__MINGW32__) #undef BI_RGB #define BI_RGB 0 @@ -805,6 +808,12 @@ " Compression: BI_JPEG"); break; } + case BI_ALPHABITFIELDS: + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " Compression: BI_ALPHABITFIELDS"); + break; + } default: { (void) LogMagickEvent(CoderEvent,GetMagickModule(), @@ -819,21 +828,21 @@ if(bmp_info.size==64) { /* OS22XBITMAPHEADER */ - magick_uint16_t Units; /* Type of units used to measure resolution */ - magick_uint16_t Reserved; /* Pad structure to 4-byte boundary */ - magick_uint16_t Recording; /* Recording algorithm */ - magick_uint16_t Rendering; /* Halftoning algorithm used */ - magick_uint32_t Size1; /* Reserved for halftoning algorithm use */ - magick_uint32_t Size2; /* Reserved for halftoning algorithm use */ - magick_uint32_t ColorEncoding; /* Color model used in bitmap */ + magick_uint16_t Units; /* Type of units used to measure resolution */ + magick_uint16_t Reserved; /* Pad structure to 4-byte boundary */ + magick_uint16_t Recording; /* Recording algorithm */ + magick_uint16_t Rendering; /* Halftoning algorithm used */ + magick_uint32_t Size1; /* Reserved for halftoning algorithm use */ + magick_uint32_t Size2; /* Reserved for halftoning algorithm use */ + magick_uint32_t ColorEncoding; /* Color model used in bitmap */ magick_uint32_t Identifier; /* Reserved for application use */ - Units = ReadBlobLSBShort(image); - Reserved = ReadBlobLSBShort(image); - Recording = ReadBlobLSBShort(image); - Rendering = ReadBlobLSBShort(image); - Size1 = ReadBlobLSBLong(image); - Size2 = ReadBlobLSBLong(image); - ColorEncoding = ReadBlobLSBLong(image); + Units = ReadBlobLSBShort(image); + Reserved = ReadBlobLSBShort(image); + Recording = ReadBlobLSBShort(image); + Rendering = ReadBlobLSBShort(image); + Size1 = ReadBlobLSBLong(image); + Size2 = ReadBlobLSBLong(image); + ColorEncoding = ReadBlobLSBLong(image); Identifier = ReadBlobLSBLong(image); if(logging) @@ -867,6 +876,9 @@ (void) LogMagickEvent(CoderEvent,GetMagickModule(), "Alpha Mask: 0x%04x", bmp_info.alpha_mask); + /* Discard alpha mask, if not BI_ALPHABITFIELDS is signalised. */ + if(bmp_info.compression != BI_ALPHABITFIELDS) + bmp_info.alpha_mask=0; if (bmp_info.size > 120) { @@ -1077,28 +1089,29 @@ if (bmp_info.number_colors > (1UL << bmp_info.bits_per_pixel)) ThrowBMPReaderException(CorruptImageError,UnrecognizedNumberOfColors,image); } - if (bmp_info.compression > 3) - ThrowBMPReaderException(CorruptImageError,UnrecognizedImageCompression,image); if ((bmp_info.compression == 1) && (bmp_info.bits_per_pixel != 8)) ThrowBMPReaderException(CorruptImageError,UnrecognizedBitsPerPixel,image); if ((bmp_info.compression == 2) && (bmp_info.bits_per_pixel != 4)) ThrowBMPReaderException(CorruptImageError,UnrecognizedBitsPerPixel,image); if ((bmp_info.compression == 3) && (bmp_info.bits_per_pixel < 16)) ThrowBMPReaderException(CorruptImageError,UnrecognizedBitsPerPixel,image); + // J.Fojtik - TEST IS DUPLICATED, PLEASE REMOVE! + //if (bmp_info.compression>BI_BITFIELDS && bmp_info.compression!=BI_ALPHABITFIELDS) + // ThrowBMPReaderException(CorruptImageError,UnrecognizedImageCompression,image); switch ((unsigned int) bmp_info.compression) { case BI_RGB: case BI_RLE8: case BI_RLE4: case BI_BITFIELDS: + case BI_ALPHABITFIELDS: break; case BI_JPEG: ThrowBMPReaderException(CoderError,JPEGCompressionNotSupported,image) case BI_PNG: ThrowBMPReaderException(CoderError,PNGCompressionNotSupported,image) default: - ThrowBMPReaderException(CorruptImageError,UnrecognizedImageCompression, - image) + ThrowBMPReaderException(CorruptImageError,UnrecognizedImageCompression,image) } image->columns=bmp_info.width; image->rows=AbsoluteValue(bmp_info.height); @@ -1317,14 +1330,28 @@ { if (bmp_info.bits_per_pixel == 16) /* USE BMP 565 */ { - bmp_info.red_mask=0x0000F800U; - bmp_info.green_mask=0x000007e0U; - bmp_info.blue_mask=0x0000001fU; + if(bmp_info.compression==BI_ALPHABITFIELDS) + { + image->matte = True; + bmp_info.alpha_mask=0x00008000U; + bmp_info.red_mask=0x00007c00U; + bmp_info.green_mask=0x000003e0U; + bmp_info.blue_mask=0x0000001fU; + } + else + { + bmp_info.red_mask=0x0000F800U; + bmp_info.green_mask=0x000007e0U; + bmp_info.blue_mask=0x0000001fU; + } } if ( bmp_info.bits_per_pixel == 32) { - image->matte = True; - bmp_info.alpha_mask=0xff000000U; + 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;