diff --git a/libheif/codecs/uncompressed/unc_codec.cc b/libheif/codecs/uncompressed/unc_codec.cc index eee2dc9f5b..ec9d016e4f 100644 --- a/libheif/codecs/uncompressed/unc_codec.cc +++ b/libheif/codecs/uncompressed/unc_codec.cc @@ -988,12 +988,14 @@ Error fill_cmpd_and_uncC(std::shared_ptr& cmpd, } int bpp = image->get_bits_per_pixel(heif_channel_Y); - Box_uncC::Component component0 = {0, (uint8_t) (bpp), component_format_unsigned, 0}; + heif_uncompressed_component_format format = to_unc_component_format(image, heif_channel_Y); + Box_uncC::Component component0 = {0, (uint8_t) (bpp), (uint8_t) format, 0}; uncC->add_component(component0); if (save_alpha_channel && image->has_channel(heif_channel_Alpha)) { + heif_uncompressed_component_format format_alpha = to_unc_component_format(image, heif_channel_Alpha); bpp = image->get_bits_per_pixel(heif_channel_Alpha); - Box_uncC::Component component1 = {1, (uint8_t) (bpp), component_format_unsigned, 0}; + Box_uncC::Component component1 = {1, (uint8_t) (bpp), (uint8_t) format_alpha, 0}; uncC->add_component(component1); } @@ -1018,3 +1020,29 @@ Error fill_cmpd_and_uncC(std::shared_ptr& cmpd, } return Error::Ok; } + +heif_uncompressed_component_format to_unc_component_format(heif_channel_datatype channel_datatype) +{ + switch (channel_datatype) { + case heif_channel_datatype_signed_integer: + return component_format_signed; + + case heif_channel_datatype_floating_point: + return component_format_float; + + case heif_channel_datatype_complex_number: + return component_format_complex; + + case heif_channel_datatype_unsigned_integer: + case heif_channel_datatype_undefined: + default: + return component_format_unsigned; + } +} + +heif_uncompressed_component_format to_unc_component_format(const std::shared_ptr& image, heif_channel channel) +{ + heif_channel_datatype datatype = image->get_datatype(channel); + heif_uncompressed_component_format component_format = to_unc_component_format(datatype); + return component_format; +} \ No newline at end of file diff --git a/libheif/codecs/uncompressed/unc_codec.h b/libheif/codecs/uncompressed/unc_codec.h index c31f061af4..21e8f7d7ae 100644 --- a/libheif/codecs/uncompressed/unc_codec.h +++ b/libheif/codecs/uncompressed/unc_codec.h @@ -53,6 +53,9 @@ bool map_uncompressed_component_to_channel(const std::shared_ptr Box_uncC::Component component, heif_channel *channel); +heif_uncompressed_component_format to_unc_component_format(heif_channel_datatype); + +heif_uncompressed_component_format to_unc_component_format(const std::shared_ptr&, heif_channel); class UncompressedImageCodec {