From accdab0c14d56d36dc6d94ab574016943e78d276 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Thu, 21 Nov 2024 13:02:09 +0100 Subject: [PATCH] Op_YCbCr_to_RGB: handle case where alpha bit depth != color bit depth (#1404) --- libheif/color-conversion/yuv2rgb.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libheif/color-conversion/yuv2rgb.cc b/libheif/color-conversion/yuv2rgb.cc index 8c689a57c2..586ae80583 100644 --- a/libheif/color-conversion/yuv2rgb.cc +++ b/libheif/color-conversion/yuv2rgb.cc @@ -148,10 +148,10 @@ Op_YCbCr_to_RGB::convert_colorspace(const std::shared_ptrget_plane(heif_channel_Y, &in_y_stride); @@ -161,9 +161,14 @@ Op_YCbCr_to_RGB::convert_colorspace(const std::shared_ptrget_plane(heif_channel_G, &out_g_stride); out_b = (Pixel*) outimg->get_plane(heif_channel_B, &out_b_stride); + + // We only copy the alpha, do not access it as 16 bit + const uint8_t* in_a; + uint8_t* out_a; + if (has_alpha) { - in_a = (const Pixel*) input->get_plane(heif_channel_Alpha, &in_a_stride); - out_a = (Pixel*) outimg->get_plane(heif_channel_Alpha, &out_a_stride); + in_a = input->get_plane(heif_channel_Alpha, &in_a_stride); + out_a = outimg->get_plane(heif_channel_Alpha, &out_a_stride); } else { in_a = nullptr; @@ -183,11 +188,9 @@ Op_YCbCr_to_RGB::convert_colorspace(const std::shared_ptr::convert_colorspace(const std::shared_ptr8 ? width * 2 : width); + memcpy(&out_a[y * out_a_stride], &in_a[y * in_a_stride], alphaCopyWidth); } }