From 7354b2ae09f0e981a546d4ebe405b64a41575c75 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Sun, 6 Oct 2024 16:53:33 +0200 Subject: [PATCH] for tile decoding, skip the 'clap' transform --- libheif/image-items/image_item.cc | 54 ++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/libheif/image-items/image_item.cc b/libheif/image-items/image_item.cc index 6668f6a742..15766e92da 100644 --- a/libheif/image-items/image_item.cc +++ b/libheif/image-items/image_item.cc @@ -767,8 +767,6 @@ Result> ImageItem::decode_image(const struct hei Error error; - // TODO: for tile decoding, we should require that all transformations are ignored or processed - if (options.ignore_transformations == false) { Result>> propertiesResult = get_properties(); if (propertiesResult.error) { @@ -797,37 +795,41 @@ Result> ImageItem::decode_image(const struct hei } - if (auto clap = std::dynamic_pointer_cast(property)) { - std::shared_ptr clap_img; + if (!decode_tile_only) { + // For tiles decoding, we do not process the 'clap' because this is handled by a shift of the tiling grid. - uint32_t img_width = img->get_width(); - uint32_t img_height = img->get_height(); - assert(img_width >= 0); - assert(img_height >= 0); + if (auto clap = std::dynamic_pointer_cast(property)) { + std::shared_ptr clap_img; - int left = clap->left_rounded(img_width); - int right = clap->right_rounded(img_width); - int top = clap->top_rounded(img_height); - int bottom = clap->bottom_rounded(img_height); + uint32_t img_width = img->get_width(); + uint32_t img_height = img->get_height(); + assert(img_width >= 0); + assert(img_height >= 0); - if (left < 0) { left = 0; } - if (top < 0) { top = 0; } + int left = clap->left_rounded(img_width); + int right = clap->right_rounded(img_width); + int top = clap->top_rounded(img_height); + int bottom = clap->bottom_rounded(img_height); - if ((uint32_t)right >= img_width) { right = img_width - 1; } - if ((uint32_t)bottom >= img_height) { bottom = img_height - 1; } + if (left < 0) { left = 0; } + if (top < 0) { top = 0; } - if (left > right || - top > bottom) { - return Error(heif_error_Invalid_input, - heif_suberror_Invalid_clean_aperture); - } + if ((uint32_t) right >= img_width) { right = img_width - 1; } + if ((uint32_t) bottom >= img_height) { bottom = img_height - 1; } - auto cropResult = img->crop(left, right, top, bottom); - if (error) { - return error; - } + if (left > right || + top > bottom) { + return Error(heif_error_Invalid_input, + heif_suberror_Invalid_clean_aperture); + } + + auto cropResult = img->crop(left, right, top, bottom); + if (error) { + return error; + } - img = cropResult.value; + img = cropResult.value; + } } } }