GraphicsMagick: 2 new changesets

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.11767.1682893128.1830.graphicsmagick-commit@lists.sourceforge.net>
changeset 80ee010ff0da in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=80ee010ff0da
summary: HEIF: Fix reading images with rotation/transformation; added option to ignore them

changeset 3316416208d1 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=3316416208d1
summary: Use C99 comment syntax

diffstat:

 coders/heif.c |  37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diffs (83 lines):

diff -r 6fbaa24a0978 -r 3316416208d1 coders/heif.c
--- a/coders/heif.c	Sun Apr 30 17:05:33 2023 -0500
+++ b/coders/heif.c	Sun Apr 30 17:18:35 2023 -0500
@@ -461,6 +461,12 @@
   PixelPacket
     *q;
 
+  const char
+    *value;
+
+  MagickBool
+    ignore_transformations;
+
   assert(image_info != (const ImageInfo *) NULL);
   assert(image_info->signature == MagickSignature);
   assert(exception != (ExceptionInfo *) NULL);
@@ -484,6 +490,11 @@
   if (ReadBlob(image,in_len,in_buf) != in_len)
     ThrowHEIFReaderException(CorruptImageError, UnexpectedEndOfFile, image);
 
+  ignore_transformations = MagickFalse;
+  if ((value=AccessDefinition(image_info,"heic","ignore_transformations")))
+    if (LocaleCompare(value,"TRUE") == 0)
+      ignore_transformations = MagickTrue;
+
   /* Init HEIF-Decoder handles */
   heif=heif_context_alloc();
 
@@ -516,6 +527,10 @@
       ThrowHEIFReaderException(CorruptImageError, AnErrorHasOccurredReadingFromFile, image);
     }
 
+  /*
+    Note: Those values are preliminary but likely the upper bound
+    The real image values might be rotated or cropped due to transformations
+  */
   image->columns=heif_image_handle_get_width(heif_image_handle);
   image->rows=heif_image_handle_get_height(heif_image_handle);
   if (heif_image_handle_has_alpha_channel(heif_image_handle))
@@ -543,7 +558,11 @@
       return NULL;
     }
 
-  if (image_info->ping)
+  /*
+    When apply transformations (the default) the whole image has to be
+    read to get the real dimensions.
+  */
+  if (image_info->ping && ignore_transformations)
     {
       image->depth = 8;
       HEIFReadCleanup();
@@ -565,7 +584,7 @@
   progress_user_data.progress = 0;
 
   /* version 1 options */
-  decode_options->ignore_transformations = 0;
+  decode_options->ignore_transformations = ignore_transformations == MagickTrue ? 1 : 0;
 #if HEIF_ENABLE_PROGRESS_MONITOR
   decode_options->start_progress = start_progress;
   decode_options->on_progress = on_progress;
@@ -600,8 +619,20 @@
       ThrowHEIFReaderException(CorruptImageError, AnErrorHasOccurredReadingFromFile, image);
     }
 
+  /* Update with final values, see preliminary note above */
+  image->columns=heif_image_get_primary_width(heif_image);
+  image->rows=heif_image_get_primary_height(heif_image);
+
+  if (image_info->ping)
+    {
+      image->depth = 8;
+      HEIFReadCleanup();
+      CloseBlob(image);
+      return image;
+    }
+
   image->depth=heif_image_get_bits_per_pixel(heif_image, heif_channel_interleaved);
-  /* the requested channel is interleaved there depth is a sum of all channels
+  /* The requested channel is interleaved there depth is a sum of all channels
      split it up again: */
   if (image->logging)
     {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.