Commit c2ba6210d for imagemagick.org

commit c2ba6210d6b512e59f8de4de5cf9c46027c733e9
Author: Dirk Lemstra <dirk@lemstra.org>
Date:   Sun Oct 11 19:11:16 2026 +0200

    Fix HEIC source selection and primary image lookup

diff --git a/coders/heic.c b/coders/heic.c
index 0e40cda64..da6178697 100644
--- a/coders/heic.c
+++ b/coders/heic.c
@@ -1106,16 +1106,10 @@ static Image *ReadHEICImage(const ImageInfo *image_info,ExceptionInfo *exception
     }
 #if LIBHEIF_NUMERIC_VERSION >= HEIC_COMPUTE_NUMERIC_VERSION(1,20,0)
   /*
-    Check for image sequence (animated AVIF) and decode via track API.
+    Prefer the still image for major brand avif, even if a sequence exists.
   */
-  error=heif_context_get_primary_image_ID(heif_context,&primary_image_id);
-  if (error.code != heif_error_Ok)
-    primary_image_id=0;
-
-  if ((heif_context_has_sequence(heif_context) != 0) &&
-      ((primary_image_id == 0) ||
-       (heif_has_compatible_brand(magic,sizeof(magic),"avis") == 1 &&
-        heif_has_compatible_brand(magic,sizeof(magic),"avif") == 0)))
+  if ((heif_read_main_brand(magic,sizeof(magic)) != heif_brand2_avif) &&
+      (heif_context_has_sequence(heif_context) != 0))
     {
       status=ReadHEICSequenceFrames(image_info,image,heif_context,exception);
       heif_context_free(heif_context);
@@ -1124,6 +1118,12 @@ static Image *ReadHEICImage(const ImageInfo *image_info,ExceptionInfo *exception
       return(GetFirstImageInList(image));
     }
 #endif
+  error=heif_context_get_primary_image_ID(heif_context,&primary_image_id);
+  if (IsHEIFSuccess(image,&error,exception) == MagickFalse)
+    {
+      heif_context_free(heif_context);
+      return(DestroyImageList(image));
+    }
   error=heif_context_get_image_handle(heif_context,primary_image_id,
     &image_handle);
   if (IsHEIFSuccess(image,&error,exception) == MagickFalse)