Skip to content

Commit

Permalink
access tiles in rotated image items
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 6, 2024
1 parent eeb1afb commit e83e36c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions libheif/image-items/image_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <limits>
#include <cassert>
#include <cstring>
#include <ranges>

#if WITH_UNCOMPRESSED_CODEC
#include "image-items/unc_image.h"
Expand Down Expand Up @@ -697,6 +698,58 @@ Result<std::shared_ptr<HeifPixelImage>> ImageItem::decode_image(const struct hei
}
}

if (decode_tile_only && options.ignore_transformations == false) {
Result<std::vector<std::shared_ptr<Box>>> propertiesResult = get_properties();
if (propertiesResult.error) {
return propertiesResult.error;
}

heif_image_tiling tiling = get_heif_image_tiling();

for (auto& prop : std::ranges::reverse_view(propertiesResult.value)) {
if (auto irot = std::dynamic_pointer_cast<Box_irot>(prop)) {
switch (irot->get_rotation_ccw()) {
case 90: {
uint32_t tx0 = tiling.num_columns - 1 - tile_y0;
uint32_t ty0 = tile_x0; //tiling.num_rows - 1 - tile_x0;
tile_y0 = ty0;
tile_x0 = tx0;
break;
}
case 270: {
uint32_t tx0 = tile_y0;
uint32_t ty0 = tiling.num_rows - 1 - tile_x0;
tile_y0 = ty0;
tile_x0 = tx0;
break;
}
case 180: {
tile_x0 = tiling.num_columns - 1 - tile_x0;
tile_y0 = tiling.num_rows - 1 - tile_y0;
break;
}
default:
assert(false);
break;
}
}

if (auto imir = std::dynamic_pointer_cast<Box_imir>(prop)) {
switch (imir->get_mirror_direction()) {
case heif_transform_mirror_direction_horizontal:
tile_x0 = tiling.num_columns - 1 - tile_x0;
break;
case heif_transform_mirror_direction_vertical:
tile_y0 = tiling.num_rows - 1 - tile_y0;
break;
default:
assert(false);
break;
}
}
}
}

// --- decode image

Result<std::shared_ptr<HeifPixelImage>> decodingResult = decode_compressed_image(options, decode_tile_only, tile_x0, tile_y0);
Expand Down

0 comments on commit e83e36c

Please sign in to comment.