Commit c4d4e0d6 for libheif

commit c4d4e0d62cf7ddd1c1e94f150c2349c37cb53fa4
Author: Dirk Farin <dirk.farin@gmail.com>
Date:   Thu May 14 19:56:27 2026 +0200

    remove add_channel() in favor of add_plane()

diff --git a/libheif/image/pixelimage.cc b/libheif/image/pixelimage.cc
index b9c12063..62c0a2cb 100644
--- a/libheif/image/pixelimage.cc
+++ b/libheif/image/pixelimage.cc
@@ -343,7 +343,8 @@ void HeifPixelImage::register_plane_descriptions(ImageComponent& plane,


 Error HeifPixelImage::add_plane(heif_channel channel, uint32_t width, uint32_t height, int bit_depth,
-                                const heif_security_limits* limits)
+                                const heif_security_limits* limits,
+                                heif_component_datatype datatype)
 {
   // for backwards compatibility, allow for 24/32 bits for RGB/RGBA interleaved chromas

@@ -360,23 +361,7 @@ Error HeifPixelImage::add_plane(heif_channel channel, uint32_t width, uint32_t h
   ImageComponent plane;
   plane.m_channel = channel;

-  if (auto err = plane.alloc(width, height, heif_component_datatype_unsigned_integer, bit_depth, num_interleaved_pixels, limits, m_memory_handle)) {
-    return err;
-  }
-
-  register_plane_descriptions(plane, map_channel_to_component_type(channel, m_chroma));
-  m_planes.push_back(std::move(plane));
-  return Error::Ok;
-}
-
-
-Error HeifPixelImage::add_channel(heif_channel channel, uint32_t width, uint32_t height, heif_component_datatype datatype, int bit_depth,
-                                  const heif_security_limits* limits)
-{
-  ImageComponent plane;
-  plane.m_channel = channel;
-
-  if (Error err = plane.alloc(width, height, datatype, bit_depth, 1, limits, m_memory_handle)) {
+  if (auto err = plane.alloc(width, height, datatype, bit_depth, num_interleaved_pixels, limits, m_memory_handle)) {
     return err;
   }

@@ -904,9 +889,9 @@ Error HeifPixelImage::copy_new_plane_from(const std::shared_ptr<const HeifPixelI
   assert(src_plane_ptr != nullptr);
   const auto& src_plane = *src_plane_ptr;

-  auto err = add_channel(dst_channel, width, height,
-                         src_plane.m_datatype,
-                         src_image->get_bits_per_pixel(src_channel), limits);
+  auto err = add_plane(dst_channel, width, height,
+                       src_image->get_bits_per_pixel(src_channel), limits,
+                       src_plane.m_datatype);
   if (err) {
     return err;
   }
diff --git a/libheif/image/pixelimage.h b/libheif/image/pixelimage.h
index 7785a04d..89b369ee 100644
--- a/libheif/image/pixelimage.h
+++ b/libheif/image/pixelimage.h
@@ -71,10 +71,9 @@ public:
   Error create_clone_image_at_new_size(const std::shared_ptr<const HeifPixelImage>& source, uint32_t w, uint32_t h,
                                        const heif_security_limits* limits);

-  Error add_plane(heif_channel channel, uint32_t width, uint32_t height, int bit_depth, const heif_security_limits* limits);
-
-  Error add_channel(heif_channel channel, uint32_t width, uint32_t height, heif_component_datatype datatype, int bit_depth,
-                    const heif_security_limits* limits);
+  Error add_plane(heif_channel channel, uint32_t width, uint32_t height, int bit_depth,
+                  const heif_security_limits* limits,
+                  heif_component_datatype datatype = heif_component_datatype_unsigned_integer);

   bool has_channel(heif_channel channel) const;

diff --git a/tests/pixel_data_types.cc b/tests/pixel_data_types.cc
index 5b6f78a6..6f3299c9 100644
--- a/tests/pixel_data_types.cc
+++ b/tests/pixel_data_types.cc
@@ -33,7 +33,7 @@ TEST_CASE( "uint32_t" )

   auto* limits = heif_get_global_security_limits();
   image.create(3,2, heif_colorspace_custom, heif_chroma_planar);
-  image.add_channel(heif_channel_Y, 3,2, heif_component_datatype_unsigned_integer, 32, limits);
+  image.add_plane(heif_channel_Y, 3,2, 32, limits, heif_component_datatype_unsigned_integer);

   size_t stride;
   uint32_t* data = image.get_channel<uint32_t>(heif_channel_Y, &stride);
@@ -132,7 +132,7 @@ TEST_CASE( "complex64_t" )

   auto* limits = heif_get_global_security_limits();
   image.create(3,2, heif_colorspace_custom, heif_chroma_planar);
-  image.add_channel(heif_channel_Y, 3,2, heif_component_datatype_complex_number, 128, limits);
+  image.add_plane(heif_channel_Y, 3,2, 128, limits, heif_component_datatype_complex_number);

   size_t stride;
   heif_complex64* data = image.get_channel<heif_complex64>(heif_channel_Y, &stride);