Coverage Report

Created: 2025-07-09 06:34

/src/libheif/libheif/image-items/iden.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * HEIF codec.
3
 * Copyright (c) 2024 Dirk Farin <dirk.farin@gmail.com>
4
 *
5
 * This file is part of libheif.
6
 *
7
 * libheif is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Lesser General Public License as
9
 * published by the Free Software Foundation, either version 3 of
10
 * the License, or (at your option) any later version.
11
 *
12
 * libheif is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with libheif.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "iden.h"
22
#include "context.h"
23
#include "file.h"
24
25
26
ImageItem_iden::ImageItem_iden(HeifContext* ctx)
27
0
    : ImageItem(ctx)
28
0
{
29
0
}
30
31
32
ImageItem_iden::ImageItem_iden(HeifContext* ctx, heif_item_id id)
33
62
    : ImageItem(ctx, id)
34
62
{
35
62
}
36
37
38
Result<std::shared_ptr<HeifPixelImage>> ImageItem_iden::decode_compressed_image(const struct heif_decoding_options& options,
39
                                                                                bool decode_tile_only, uint32_t tile_x0, uint32_t tile_y0) const
40
81
{
41
81
  std::shared_ptr<HeifPixelImage> img;
42
43
  // find the ID of the image this image is derived from
44
45
81
  auto iref_box = get_file()->get_iref_box();
46
47
81
  if (!iref_box) {
48
36
    return Error(heif_error_Invalid_input,
49
36
                 heif_suberror_No_iref_box,
50
36
                 "No iref box available, but needed for iden image");
51
36
  }
52
53
45
  std::vector<heif_item_id> image_references = iref_box->get_references(get_id(), fourcc("dimg"));
54
55
45
  if ((int) image_references.size() != 1) {
56
45
    return Error(heif_error_Invalid_input,
57
45
                 heif_suberror_Unspecified,
58
45
                 "'iden' image with more than one reference image");
59
45
  }
60
61
62
0
  heif_item_id reference_image_id = image_references[0];
63
64
0
  if (reference_image_id == get_id()) {
65
0
    return Error(heif_error_Invalid_input,
66
0
                 heif_suberror_Unspecified,
67
0
                 "'iden' image referring to itself");
68
0
  }
69
70
0
  std::shared_ptr<const ImageItem> imgitem = get_context()->get_image(reference_image_id, true);
71
0
  if (!imgitem) {
72
0
    return Error(heif_error_Invalid_input,
73
0
                 heif_suberror_Unspecified,
74
0
                 "'iden' image references unavailable image");
75
0
  }
76
0
  if (auto error = imgitem->get_item_error()) {
77
0
    return error;
78
0
  }
79
80
0
  return imgitem->decode_image(options, decode_tile_only, tile_x0, tile_y0);
81
0
}
82
83
84
Error ImageItem_iden::get_coded_image_colorspace(heif_colorspace* out_colorspace, heif_chroma* out_chroma) const
85
0
{
86
0
  heif_item_id child;
87
0
  Error err = get_context()->get_id_of_non_virtual_child_image(get_id(), child);
88
0
  if (err) {
89
0
    return err;
90
0
  }
91
92
0
  auto image = get_context()->get_image(child, true);
93
0
  if (!image) {
94
0
    return Error{heif_error_Invalid_input,
95
0
                 heif_suberror_Nonexisting_item_referenced};
96
0
  }
97
98
0
  return image->get_coded_image_colorspace(out_colorspace, out_chroma);
99
0
}
100
101
102
int ImageItem_iden::get_luma_bits_per_pixel() const
103
0
{
104
0
  heif_item_id child;
105
0
  Error err = get_context()->get_id_of_non_virtual_child_image(get_id(), child);
106
0
  if (err) {
107
0
    return -1;
108
0
  }
109
110
0
  auto image = get_context()->get_image(child, true);
111
0
  if (!image) {
112
0
    return -1;
113
0
  }
114
115
0
  return image->get_luma_bits_per_pixel();
116
0
}
117
118
119
int ImageItem_iden::get_chroma_bits_per_pixel() const
120
0
{
121
0
  heif_item_id child;
122
0
  Error err = get_context()->get_id_of_non_virtual_child_image(get_id(), child);
123
0
  if (err) {
124
0
    return -1;
125
0
  }
126
127
0
  auto image = get_context()->get_image(child, true);
128
0
  if (!image) {
129
0
    return -1;
130
0
  }
131
132
0
  return image->get_chroma_bits_per_pixel();
133
0
}
134
135
heif_brand2 ImageItem_iden::get_compatible_brand() const
136
0
{
137
0
  assert(false);
138
0
  return 0; // TODO (we never write 'iden' images)
139
0
}