Commit 620a7402 for libheif

commit 620a74029868340a924606ec5bb007be4678756c
Author: Dirk Farin <dirk.farin@gmail.com>
Date:   Fri May 15 01:21:17 2026 +0200

    Return 0 instead of 65535 for a missing channel in get_bits_per_pixel

diff --git a/libheif/api/libheif/heif_image.cc b/libheif/api/libheif/heif_image.cc
index 04bc0772..f766969b 100644
--- a/libheif/api/libheif/heif_image.cc
+++ b/libheif/api/libheif/heif_image.cc
@@ -125,13 +125,19 @@ heif_error heif_image_extract_area(const heif_image* srcimg,

 int heif_image_get_bits_per_pixel(const heif_image* img, heif_channel channel)
 {
-  return img->image->get_storage_bits_per_pixel(channel);
+  // get_storage_bits_per_pixel() returns 0 for a non-existing channel;
+  // the public API documents -1 for that case.
+  uint16_t bpp = img->image->get_storage_bits_per_pixel(channel);
+  return bpp == 0 ? -1 : bpp;
 }


 int heif_image_get_bits_per_pixel_range(const heif_image* img, heif_channel channel)
 {
-  return img->image->get_bits_per_pixel(channel);
+  // get_bits_per_pixel() returns 0 for a non-existing channel;
+  // keep the public API's -1 result for that case.
+  uint16_t bpp = img->image->get_bits_per_pixel(channel);
+  return bpp == 0 ? -1 : bpp;
 }


diff --git a/libheif/image/pixelimage.cc b/libheif/image/pixelimage.cc
index 7ec8ccdc..862e0c10 100644
--- a/libheif/image/pixelimage.cc
+++ b/libheif/image/pixelimage.cc
@@ -780,7 +780,10 @@ uint16_t HeifPixelImage::get_storage_bits_per_pixel(enum heif_channel channel) c
 {
   auto* comp = find_storage_for_channel(channel);
   if (!comp) {
-    return -1;
+    // Channel not present. The return type is unsigned, so the historical
+    // `return -1` actually yielded 65535; use 0 as an unambiguous
+    // "not present" value (no real channel has 0 bits per pixel).
+    return 0;
   }

   uint32_t bpp = comp->get_bytes_per_pixel() * 8;
@@ -793,7 +796,8 @@ uint16_t HeifPixelImage::get_bits_per_pixel(enum heif_channel channel) const
 {
   auto* comp = find_storage_for_channel(channel);
   if (!comp) {
-    return -1;
+    // Channel not present -- see get_storage_bits_per_pixel().
+    return 0;
   }

   return comp->m_bit_depth;