Skip to content

Commit

Permalink
(cleanup)
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 6, 2024
1 parent 7354b2a commit 0b3b415
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions libheif/image-items/image_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,33 +428,19 @@ Error ImageItem::postprocess_coded_image_colorspace(heif_colorspace* inout_color
}


// TODO: when all decoders are implemented, this function should just forward to the Decoder object.
Error ImageItem::get_coded_image_colorspace(heif_colorspace* out_colorspace, heif_chroma* out_chroma) const
{
heif_item_id id;
Error err = m_heif_context->get_id_of_non_virtual_child_image(m_id, id);
if (err) {
return err;
}
auto decoder = get_decoder();
assert(decoder);

// TODO: should we use this or maybe use this just as an additional check that pixi and coded colorspace match?
auto pixi = m_heif_context->get_heif_file()->get_property<Box_pixi>(id);
if (pixi && pixi->get_num_channels() == 1) {
*out_colorspace = heif_colorspace_monochrome;
*out_chroma = heif_chroma_monochrome;
Error err = decoder->get_coded_image_colorspace(out_colorspace, out_chroma);
if (err) {
return err;
}

auto nclx = get_color_profile_nclx();
if (nclx && nclx->get_matrix_coefficients() == 0) {
*out_colorspace = heif_colorspace_RGB;
*out_chroma = heif_chroma_444;
return err;
}
postprocess_coded_image_colorspace(out_colorspace, out_chroma);

auto decoder = get_decoder();
assert(decoder);
return decoder->get_coded_image_colorspace(out_colorspace, out_chroma);
return Error::Ok;
}


Expand Down Expand Up @@ -698,6 +684,9 @@ Result<std::shared_ptr<HeifPixelImage>> ImageItem::decode_image(const struct hei
}
}


// --- transform tile position

if (decode_tile_only && options.ignore_transformations == false) {
Result<std::vector<std::shared_ptr<Box>>> propertiesResult = get_properties();
if (propertiesResult.error) {
Expand Down Expand Up @@ -1046,6 +1035,9 @@ Error ImageItem::process_image_transformations_on_tiling(heif_image_tiling& tili
uint32_t bottom_excess = tiling.image_height % tiling.tile_height;

for (const auto& property : properties) {

// --- rotation

if (auto rot = std::dynamic_pointer_cast<Box_irot>(property)) {
int angle = rot->get_rotation_ccw();
if (angle == 90 || angle == 270) {
Expand Down Expand Up @@ -1083,6 +1075,8 @@ Error ImageItem::process_image_transformations_on_tiling(heif_image_tiling& tili
}
}

// --- mirror

if (auto mirror = std::dynamic_pointer_cast<Box_imir>(property)) {
switch (mirror->get_mirror_direction()) {
case heif_transform_mirror_direction_horizontal:
Expand All @@ -1097,6 +1091,8 @@ Error ImageItem::process_image_transformations_on_tiling(heif_image_tiling& tili
}
}

// --- crop

if (auto clap = std::dynamic_pointer_cast<Box_clap>(property)) {
std::shared_ptr<HeifPixelImage> clap_img;

Expand Down

0 comments on commit 0b3b415

Please sign in to comment.