Commit b4326c42 for libheif

commit b4326c427c1269b11c8ed8fac8b194e9ff75023b
Author: Dirk Farin <dirk.farin@gmail.com>
Date:   Fri Feb 13 00:10:36 2026 +0100

    unci: map component type to heif_channel

diff --git a/libheif/api/libheif/heif_image.h b/libheif/api/libheif/heif_image.h
index 32a11628..7de5780e 100644
--- a/libheif/api/libheif/heif_image.h
+++ b/libheif/api/libheif/heif_image.h
@@ -90,7 +90,8 @@ typedef enum heif_channel
   heif_channel_interleaved = 10,
   heif_channel_filter_array = 11,
   heif_channel_depth = 12,
-  heif_channel_disparity = 13
+  heif_channel_disparity = 13,
+  heif_channel_unknown = 65535
 } heif_channel;


diff --git a/libheif/codecs/uncompressed/unc_codec.cc b/libheif/codecs/uncompressed/unc_codec.cc
index c522cab4..354456b0 100644
--- a/libheif/codecs/uncompressed/unc_codec.cc
+++ b/libheif/codecs/uncompressed/unc_codec.cc
@@ -158,40 +158,8 @@ bool map_uncompressed_component_to_channel(const std::shared_ptr<const Box_cmpd>
   uint16_t component_index = component.component_index;
   uint16_t component_type = cmpd->get_components()[component_index].component_type;

-  switch (component_type) {
-    case component_type_monochrome:
-      *channel = heif_channel_Y;
-      return true;
-    case component_type_Y:
-      *channel = heif_channel_Y;
-      return true;
-    case component_type_Cb:
-      *channel = heif_channel_Cb;
-      return true;
-    case component_type_Cr:
-      *channel = heif_channel_Cr;
-      return true;
-    case component_type_red:
-      *channel = heif_channel_R;
-      return true;
-    case component_type_green:
-      *channel = heif_channel_G;
-      return true;
-    case component_type_blue:
-      *channel = heif_channel_B;
-      return true;
-    case component_type_alpha:
-      *channel = heif_channel_Alpha;
-      return true;
-    case component_type_filter_array:
-      // TODO: this is just a temporary hack
-      *channel = heif_channel_Y;
-      return true;
-    case component_type_padded:
-      return false;
-    default:
-      return false;
-  }
+  *channel = map_uncompressed_component_to_channel(component_type);
+  return true;
 }


diff --git a/libheif/codecs/uncompressed/unc_codec.h b/libheif/codecs/uncompressed/unc_codec.h
index 71f2ea79..8d722068 100644
--- a/libheif/codecs/uncompressed/unc_codec.h
+++ b/libheif/codecs/uncompressed/unc_codec.h
@@ -44,6 +44,7 @@ bool map_uncompressed_component_to_channel(const std::shared_ptr<const Box_cmpd>
                                            Box_uncC::Component component,
                                            heif_channel *channel);

+
 class UncompressedImageCodec
 {
 public:
diff --git a/libheif/codecs/uncompressed/unc_decoder_legacybase.h b/libheif/codecs/uncompressed/unc_decoder_legacybase.h
index b5ba191b..db88f064 100644
--- a/libheif/codecs/uncompressed/unc_decoder_legacybase.h
+++ b/libheif/codecs/uncompressed/unc_decoder_legacybase.h
@@ -70,7 +70,7 @@ public:
         uint32_t padding = pixel_size - bytes_in_pixel;
         skip_bytes(padding);
       }
-      if (pixel_size == bytes_in_pixel) {
+      else if (pixel_size == bytes_in_pixel) {
         // NOP
       }
       else {
diff --git a/libheif/pixelimage.cc b/libheif/pixelimage.cc
index 3ba8a39c..9b2b608e 100644
--- a/libheif/pixelimage.cc
+++ b/libheif/pixelimage.cc
@@ -30,6 +30,8 @@
 #include <algorithm>
 #include <color-conversion/colorconversion.h>

+#include "codecs/uncompressed/unc_types.h"
+

 heif_chroma chroma_from_subsampling(int h, int v)
 {
@@ -91,6 +93,39 @@ uint32_t channel_height(uint32_t h, heif_chroma chroma, heif_channel channel)
 }


+heif_channel map_uncompressed_component_to_channel(uint16_t component_type)
+{
+  switch (component_type) {
+    case component_type_monochrome:
+    case component_type_Y:
+      return heif_channel_Y;
+    case component_type_Cb:
+      return heif_channel_Cb;
+    case component_type_Cr:
+      return heif_channel_Cr;
+    case component_type_red:
+      return heif_channel_R;
+    case component_type_green:
+      return heif_channel_G;
+    case component_type_blue:
+      return heif_channel_B;
+    case component_type_alpha:
+      return heif_channel_Alpha;
+    case component_type_filter_array:
+      return heif_channel_filter_array;
+    case component_type_depth:
+      return heif_channel_depth;
+    case component_type_disparity:
+      return heif_channel_disparity;
+
+    case component_type_padded:
+    default:
+      return heif_channel_unknown;
+  }
+}
+
+
+
 ImageExtraData::~ImageExtraData()
 {
   heif_tai_timestamp_packet_release(m_tai_timestamp);
@@ -1947,7 +1982,7 @@ Result<uint32_t> HeifPixelImage::add_component(uint32_t width, uint32_t height,
                                                const heif_security_limits* limits)
 {
   ImageComponent plane;
-  plane.m_channel = heif_channel_Y;
+  plane.m_channel = map_uncompressed_component_to_channel(component_type);
   plane.m_component_type = component_type;
   if (Error err = plane.alloc(width, height, datatype, bit_depth, 1, limits, m_memory_handle)) {
     return err;
diff --git a/libheif/pixelimage.h b/libheif/pixelimage.h
index 7e8f9744..33342052 100644
--- a/libheif/pixelimage.h
+++ b/libheif/pixelimage.h
@@ -204,6 +204,9 @@ protected:
 };


+heif_channel map_uncompressed_component_to_channel(uint16_t component_type);
+
+
 class HeifPixelImage : public std::enable_shared_from_this<HeifPixelImage>,
                        public ImageExtraData,
                        public ErrorBuffer