• R/O
  • SSH

GM: Commit

Main GraphicsMagick source repository


Commit MetaInfo

Revision743f1bcf3052910b4ee5cdd231d7598255f3f0d2 (tree)
Time2022-01-17 02:57:59
AuthorBob Friesenhahn <bfriesen@Grap...>
CommiterBob Friesenhahn

Log Message

HEIF: Take row stride into account when reading pixel rows. Add support for 'ping' mode. Add header magic detection. Add module aliases. Add useful traces.

Change Summary

Incremental Difference

diff -r 6ca5dbc2fb4f -r 743f1bcf3052 ChangeLog
--- a/ChangeLog Sat Jan 15 17:09:46 2022 -0600
+++ b/ChangeLog Sun Jan 16 11:57:59 2022 -0600
@@ -1,3 +1,9 @@
1+2022-01-16 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
2+
3+ * coders/heif.c (ReadHEIFImage): Take row stride into account when
4+ reading pixel rows. Add support for 'ping' mode. Add header magic
5+ detection. Add module aliases. Add useful traces.
6+
17 2022-01-15 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
28
39 * coders/jxl.c: Added preliminary JPEG XL support written by
diff -r 6ca5dbc2fb4f -r 743f1bcf3052 VisualMagick/installer/inc/version.isx
--- a/VisualMagick/installer/inc/version.isx Sat Jan 15 17:09:46 2022 -0600
+++ b/VisualMagick/installer/inc/version.isx Sun Jan 16 11:57:59 2022 -0600
@@ -10,5 +10,5 @@
1010
1111 #define public MagickPackageName "GraphicsMagick"
1212 #define public MagickPackageVersion "1.4"
13-#define public MagickPackageVersionAddendum ".020220115"
14-#define public MagickPackageReleaseDate "snapshot-20220115"
13+#define public MagickPackageVersionAddendum ".020220116"
14+#define public MagickPackageReleaseDate "snapshot-20220116"
diff -r 6ca5dbc2fb4f -r 743f1bcf3052 coders/heif.c
--- a/coders/heif.c Sat Jan 15 17:09:46 2022 -0600
+++ b/coders/heif.c Sun Jan 16 11:57:59 2022 -0600
@@ -34,7 +34,50 @@
3434
3535 #if defined(HasHEIF)
3636 #include <libheif/heif.h>
37+
38+/*
39+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40+% %
41+% %
42+% %
43+% I s H E I F %
44+% %
45+% %
46+% %
47+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48+%
49+% Method IsHEIF returns True if the image format type, identified by the
50+% magick string, is supported by this HEIF reader.
51+%
52+% The format of the IsHEIF method is:
53+%
54+% unsigned int IsHEIF(const unsigned char *magick,const size_t length)
55+%
56+% A description of each parameter follows:
57+%
58+% o status: Method IsHEIF returns True if the image format type is HEIF.
59+%
60+% o magick: This string is generally the first few bytes of an image file
61+% or blob.
62+%
63+% o length: Specifies the length of the magick string.
64+%
65+%
66+*/
67+static unsigned int IsHEIF(const unsigned char *magick,const size_t length)
68+{
69+ enum heif_filetype_result
70+ heif_filetype;
3771
72+ if (length < 12)
73+ return(False);
74+
75+ heif_filetype = heif_check_filetype(magick, (int) length);
76+ if (heif_filetype == heif_filetype_yes_supported)
77+ return True;
78+
79+ return(False);
80+}
3881 /*
3982 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4083 % %
@@ -109,6 +152,11 @@
109152 unsigned char*
110153 profile;
111154
155+ if (image->logging)
156+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
157+ "Profile \"%s\" with size %" MAGICK_SIZE_T_F "u bytes",
158+ profile_name, (MAGICK_SIZE_T) profile_size);
159+
112160 profile=MagickAllocateResourceLimitedArray(unsigned char*,profile_size,
113161 sizeof(*profile));
114162 if (profile == (unsigned char*) NULL)
@@ -121,6 +169,10 @@
121169
122170 if (err.code != heif_error_Ok)
123171 {
172+ if (image->logging)
173+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
174+ "heif_image_handle_get_metadata() reports error \"%s\"",
175+ err.message);
124176 MagickFreeResourceLimitedMemory(profile);
125177 MagickFreeResourceLimitedMemory(ids);
126178 ThrowReaderException(CorruptImageError,
@@ -210,7 +262,13 @@
210262 || heif_status.code == heif_error_Unsupported_feature)
211263 ThrowHEIFReaderException(CoderError, ImageTypeNotSupported, image);
212264 if (heif_status.code != heif_error_Ok)
213- ThrowHEIFReaderException(CorruptImageError, AnErrorHasOccurredReadingFromFile, image);
265+ {
266+ if (image->logging)
267+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
268+ "heif_context_read_from_memory() reports error \"%s\"",
269+ heif_status.message);
270+ ThrowHEIFReaderException(CorruptImageError, AnErrorHasOccurredReadingFromFile, image);
271+ }
214272
215273 /* no support for reading multiple images but could be added */
216274 if (heif_context_get_number_of_top_level_images(heif) != 1)
@@ -220,30 +278,68 @@
220278 if (heif_status.code == heif_error_Memory_allocation_error)
221279 ThrowHEIFReaderException(ResourceLimitError,MemoryAllocationFailed,image);
222280 if (heif_status.code != heif_error_Ok)
223- ThrowHEIFReaderException(CorruptImageError, AnErrorHasOccurredReadingFromFile, image);
281+ {
282+ if (image->logging)
283+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
284+ "heif_context_get_primary_image_handle() reports error \"%s\"",
285+ heif_status.message);
286+ ThrowHEIFReaderException(CorruptImageError, AnErrorHasOccurredReadingFromFile, image);
287+ }
224288
225289 image->columns=heif_image_handle_get_width(heif_image_handle);
226290 image->rows=heif_image_handle_get_height(heif_image_handle);
227291 if (heif_image_handle_has_alpha_channel(heif_image_handle))
228292 image->matte=MagickTrue;
229293
294+ if (image->logging)
295+ {
296+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
297+ "Geometry: %lux%lu", image->columns, image->rows);
298+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
299+ "Matte: %s", image->matte ? "True" : "False");
300+ }
301+
230302 if (!ReadMetadata(heif_image_handle, image, exception))
231303 {
232304 HEIFReadCleanup();
233305 return NULL;
234306 }
235307
308+ if (image_info->ping)
309+ {
310+ image->depth = 8;
311+ HEIFReadCleanup();
312+ CloseBlob(image);
313+ return image;
314+ }
315+
316+ if (CheckImagePixelLimits(image, exception) != MagickPass)
317+ ThrowHEIFReaderException(ResourceLimitError,ImagePixelLimitExceeded,image);
318+
319+ /* FIXME: Add decoding options support such as a progress monitor */
236320 heif_status=heif_decode_image(heif_image_handle, &heif_image,
237321 heif_colorspace_RGB, image->matte ? heif_chroma_interleaved_RGBA :
238- heif_chroma_interleaved_RGB, NULL);
322+ heif_chroma_interleaved_RGB,
323+ /* const struct heif_decoding_options* */ NULL );
239324 if (heif_status.code == heif_error_Memory_allocation_error)
240325 ThrowHEIFReaderException(ResourceLimitError,MemoryAllocationFailed,image);
241326 if (heif_status.code != heif_error_Ok)
242- ThrowHEIFReaderException(CorruptImageError, AnErrorHasOccurredReadingFromFile, image);
327+ {
328+ if (image->logging)
329+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
330+ "heif_decode_image() reports error \"%s\"",
331+ heif_status.message);
332+ ThrowHEIFReaderException(CorruptImageError, AnErrorHasOccurredReadingFromFile, image);
333+ }
243334
244335 image->depth=heif_image_get_bits_per_pixel(heif_image, heif_channel_interleaved);
245336 /* the requested channel is interleaved there depth is a sum of all channels
246337 split it up again: */
338+ if (image->logging)
339+ {
340+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
341+ "heif_image_get_bits_per_pixel: bits_per_pixel=%u", image->depth);
342+ }
247343 if (image->depth == 32 && image->matte)
248344 image->depth = 8;
249345 else if (image->depth == 24 && !image->matte)
@@ -255,18 +351,26 @@
255351 if (!pixels)
256352 ThrowHEIFReaderException(CoderError, NoDataReturned, image);
257353
354+ if (image->logging)
355+ (void) LogMagickEvent(CoderEvent,GetMagickModule(),
356+ "heif_image_get_plane_readonly: bytes-per-line=%d",
357+ row_stride);
358+
359+ /* Transfer pixels to image, using row stride to find start of each row. */
258360 for (y=0; y < (long)image->rows; y++)
259361 {
362+ const uint8_t *line;
260363 q=SetImagePixelsEx(image,0,y,image->columns,1,exception);
261364 if (q == (PixelPacket *) NULL)
262365 ThrowHEIFReaderException(ResourceLimitError,MemoryAllocationFailed,image);
366+ line=pixels+y*row_stride;
263367 for (x=0; x < (long)image->columns; x++)
264368 {
265- SetRedSample(q,ScaleCharToQuantum(*pixels++));
266- SetGreenSample(q,ScaleCharToQuantum(*pixels++));
267- SetBlueSample(q,ScaleCharToQuantum(*pixels++));
369+ SetRedSample(q,ScaleCharToQuantum(*line++));
370+ SetGreenSample(q,ScaleCharToQuantum(*line++));
371+ SetBlueSample(q,ScaleCharToQuantum(*line++));
268372 if (image->matte) {
269- SetOpacitySample(q,MaxRGB-ScaleCharToQuantum(*pixels++));
373+ SetOpacitySample(q,MaxRGB-ScaleCharToQuantum(*line++));
270374 } else {
271375 SetOpacitySample(q,OpaqueOpacity);
272376 }
@@ -332,6 +436,7 @@
332436 entry=SetMagickInfo("HEIF");
333437 #if defined(HasHEIF)
334438 entry->decoder=(DecoderHandler) ReadHEIFImage;
439+ entry->magick=(MagickHandler) IsHEIF;
335440 #endif
336441 entry->description=description;
337442 entry->adjoin=False;
@@ -345,6 +450,7 @@
345450 entry=SetMagickInfo("HEIC");
346451 #if defined(HasHEIF)
347452 entry->decoder=(DecoderHandler) ReadHEIFImage;
453+ entry->magick=(MagickHandler) IsHEIF;
348454 #endif
349455 entry->description=description;
350456 entry->adjoin=False;
diff -r 6ca5dbc2fb4f -r 743f1bcf3052 cscope.files
--- a/cscope.files Sat Jan 15 17:09:46 2022 -0600
+++ b/cscope.files Sun Jan 16 11:57:59 2022 -0600
@@ -27,6 +27,7 @@
2727 coders/gif.c
2828 coders/gradient.c
2929 coders/gray.c
30+coders/heif.c
3031 coders/histogram.c
3132 coders/hrz.c
3233 coders/html.c
@@ -35,6 +36,7 @@
3536 coders/info.c
3637 coders/jbig.c
3738 coders/jnx.c
39+coders/jpx.c
3840 coders/jp2.c
3941 coders/jpeg.c
4042 coders/label.c
diff -r 6ca5dbc2fb4f -r 743f1bcf3052 magick/magic.c
--- a/magick/magic.c Sat Jan 15 17:09:46 2022 -0600
+++ b/magick/magic.c Sun Jan 16 11:57:59 2022 -0600
@@ -60,6 +60,7 @@
6060 {
6161 #define MAGIC(name,offset,magic) {name,(const unsigned char * const)magic,sizeof(magic)-1,offset}
6262 MAGIC("WEBP", 8, "WEBP"),
63+ MAGIC("AVIF", 4, "ftypavif"),
6364 /* MAGIC("AVI", 0, "RIFF"), */
6465 MAGIC("8BIMWTEXT", 0, "8\000B\000I\000M\000#"),
6566 MAGIC("8BIMTEXT", 0, "8BIM#"),
@@ -90,6 +91,9 @@
9091 MAGIC("FITS", 0, "SIMPLE"),
9192 MAGIC("FPX", 0, "\320\317\021\340"),
9293 MAGIC("GIF", 0, "GIF8"),
94+ MAGIC("HEIC", 4, "ftypheic"),
95+ MAGIC("HEIC", 4, "ftypheix"),
96+ MAGIC("HEIC", 4, "ftypmif1"),
9397 MAGIC("HDF", 1, "HDF"),
9498 MAGIC("HPGL", 0, "IN;"),
9599 MAGIC("HTML", 1, "HTML"),
diff -r 6ca5dbc2fb4f -r 743f1bcf3052 magick/module_aliases.h
--- a/magick/module_aliases.h Sat Jan 15 17:09:46 2022 -0600
+++ b/magick/module_aliases.h Sun Jan 16 11:57:59 2022 -0600
@@ -35,6 +35,7 @@
3535 MODULEALIAS("APP1","META"),
3636 MODULEALIAS("APP1JPEG","META"),
3737 MODULEALIAS("ARW","DCRAW"),
38+ MODULEALIAS("AVIF","HEIF"),
3839 MODULEALIAS("B","GRAY"),
3940 MODULEALIAS("BIE","JBIG"),
4041 MODULEALIAS("BIGTIFF","TIFF"),
@@ -72,9 +73,9 @@
7273 MODULEALIAS("GRAYA","GRAY"),
7374 MODULEALIAS("GROUP4RAW","TIFF"),
7475 MODULEALIAS("H","LOGO"),
76+ MODULEALIAS("HEIC","HEIF"),
7577 MODULEALIAS("HTM","HTML"),
7678 MODULEALIAS("HTTP","URL"),
77- MODULEALIAS("HEIC","HEIF"),
7879 MODULEALIAS("ICB","TGA"),
7980 MODULEALIAS("ICC","META"),
8081 MODULEALIAS("ICM","META"),
diff -r 6ca5dbc2fb4f -r 743f1bcf3052 magick/version.h
--- a/magick/version.h Sat Jan 15 17:09:46 2022 -0600
+++ b/magick/version.h Sun Jan 16 11:57:59 2022 -0600
@@ -38,8 +38,8 @@
3838 #define MagickLibVersion 0x262300
3939 #define MagickLibVersionText "1.4"
4040 #define MagickLibVersionNumber 26,23,0
41-#define MagickChangeDate "20220115"
42-#define MagickReleaseDate "snapshot-20220115"
41+#define MagickChangeDate "20220116"
42+#define MagickReleaseDate "snapshot-20220116"
4343
4444 /*
4545 The MagickLibInterfaceNewest and MagickLibInterfaceOldest defines
diff -r 6ca5dbc2fb4f -r 743f1bcf3052 www/Changelog.html
--- a/www/Changelog.html Sat Jan 15 17:09:46 2022 -0600
+++ b/www/Changelog.html Sun Jan 16 11:57:59 2022 -0600
@@ -35,6 +35,11 @@
3535 <div class="document">
3636
3737
38+<p>2022-01-16 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>
39+<blockquote>
40+* coders/heif.c (ReadHEIFImage): Take row stride into account when
41+reading pixel rows. Add support for 'ping' mode. Add header magic
42+detection. Add module aliases. Add useful traces.</blockquote>
3843 <p>2022-01-15 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>
3944 <blockquote>
4045 <p>* coders/jxl.c: Added preliminary JPEG XL support written by
Show on old repository browser