|
18 | 18 | * along with libheif. If not, see <http://www.gnu.org/licenses/>.
|
19 | 19 | */
|
20 | 20 |
|
21 |
| -#include "heif_plugin.h" |
22 |
| -#include "security_limits.h" |
23 |
| -#include "region.h" |
24 |
| -#include "common_utils.h" |
25 |
| -#include <cstdint> |
26 | 21 | #include "heif.h"
|
27 |
| -#include "file.h" |
28 |
| -#include "pixelimage.h" |
29 |
| -#include "api_structs.h" |
30 |
| -#include "context.h" |
31 |
| -#include "plugin_registry.h" |
32 |
| -#include "error.h" |
33 |
| -#include "bitstream.h" |
34 |
| -#include "init.h" |
35 |
| -#include "image-items/grid.h" |
36 |
| -#include "image-items/overlay.h" |
37 |
| -#include "image-items/tiled.h" |
38 |
| -#include <set> |
39 |
| -#include <limits> |
40 |
| - |
41 |
| -#if WITH_UNCOMPRESSED_CODEC |
42 |
| -#include "image-items/unc_image.h" |
43 |
| -#endif |
44 |
| - |
45 |
| -#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_STANDALONE_WASM__) |
46 |
| -#include "heif_emscripten.h" |
47 |
| -#endif |
48 |
| - |
49 |
| -#include <algorithm> |
50 |
| -#include <iostream> |
51 |
| -#include <fstream> |
52 |
| -#include <memory> |
53 |
| -#include <string> |
54 |
| -#include <utility> |
55 |
| -#include <vector> |
56 |
| -#include <cstring> |
57 |
| -#include <array> |
58 |
| - |
59 |
| -#ifdef _WIN32 |
60 |
| -// for _write |
61 |
| -#include <io.h> |
62 |
| -#else |
63 |
| - |
64 |
| -#include <unistd.h> |
65 |
| - |
66 |
| -#endif |
67 |
| - |
68 |
| -#include <cassert> |
69 |
| - |
70 |
| - |
71 |
| -const struct heif_error heif_error_success = {heif_error_Ok, heif_suberror_Unspecified, Error::kSuccess}; |
72 |
| -static struct heif_error error_null_parameter = {heif_error_Usage_error, |
73 |
| - heif_suberror_Null_pointer_argument, |
74 |
| - "NULL passed"}; |
75 |
| - |
76 |
| - |
77 |
| - |
78 |
| -heif_error heif_image_handle_get_image_tiling(const struct heif_image_handle* handle, int process_image_transformations, struct heif_image_tiling* tiling) |
79 |
| -{ |
80 |
| - if (!handle || !tiling) { |
81 |
| - return {heif_error_Usage_error, |
82 |
| - heif_suberror_Null_pointer_argument, |
83 |
| - "NULL passed to heif_image_handle_get_image_tiling()"}; |
84 |
| - } |
85 |
| - |
86 |
| - *tiling = handle->image->get_heif_image_tiling(); |
87 |
| - |
88 |
| - if (process_image_transformations) { |
89 |
| - Error error = handle->image->process_image_transformations_on_tiling(*tiling); |
90 |
| - if (error) { |
91 |
| - return error.error_struct(handle->context.get()); |
92 |
| - } |
93 |
| - } |
94 |
| - |
95 |
| - return heif_error_ok; |
96 |
| -} |
97 |
| - |
98 |
| - |
99 |
| -struct heif_error heif_image_handle_get_grid_image_tile_id(const struct heif_image_handle* handle, |
100 |
| - int process_image_transformations, |
101 |
| - uint32_t tile_x, uint32_t tile_y, |
102 |
| - heif_item_id* tile_item_id) |
103 |
| -{ |
104 |
| - if (!handle || !tile_item_id) { |
105 |
| - return { heif_error_Usage_error, |
106 |
| - heif_suberror_Null_pointer_argument }; |
107 |
| - } |
108 |
| - |
109 |
| - std::shared_ptr<ImageItem_Grid> gridItem = std::dynamic_pointer_cast<ImageItem_Grid>(handle->image); |
110 |
| - if (!gridItem) { |
111 |
| - return { heif_error_Usage_error, |
112 |
| - heif_suberror_Unspecified, |
113 |
| - "Image is no grid image" }; |
114 |
| - } |
115 |
| - |
116 |
| - const ImageGrid& gridspec = gridItem->get_grid_spec(); |
117 |
| - if (tile_x >= gridspec.get_columns() || tile_y >= gridspec.get_rows()) { |
118 |
| - return { heif_error_Usage_error, |
119 |
| - heif_suberror_Unspecified, |
120 |
| - "Grid tile index out of range" }; |
121 |
| - } |
122 |
| - |
123 |
| - if (process_image_transformations) { |
124 |
| - gridItem->transform_requested_tile_position_to_original_tile_position(tile_x, tile_y); |
125 |
| - } |
126 |
| - |
127 |
| - *tile_item_id = gridItem->get_grid_tiles()[tile_y * gridspec.get_columns() + tile_x]; |
128 |
| - |
129 |
| - return heif_error_ok; |
130 |
| -} |
131 |
| - |
132 |
| - |
133 |
| -#if 0 |
134 |
| -// TODO: do we need this ? This does not handle rotations. We can use heif_image_handle_get_image_tiling() to get the same information. |
135 |
| -struct heif_error heif_image_handle_get_tile_size(const struct heif_image_handle* handle, |
136 |
| - uint32_t* tile_width, uint32_t* tile_height) |
137 |
| -{ |
138 |
| - if (!handle) { |
139 |
| - return error_null_parameter; |
140 |
| - } |
141 |
| - |
142 |
| - |
143 |
| - uint32_t w,h; |
144 |
| - |
145 |
| - handle->image->get_tile_size(w,h); |
146 |
| - |
147 |
| - if (tile_width) { |
148 |
| - *tile_width = w; |
149 |
| - } |
150 |
| - |
151 |
| - if (tile_height) { |
152 |
| - *tile_height = h; |
153 |
| - } |
154 |
| - |
155 |
| - return heif_error_success; |
156 |
| -} |
157 |
| -#endif |
158 |
| - |
159 |
| - |
160 |
| -struct heif_error heif_context_add_pyramid_entity_group(struct heif_context* ctx, |
161 |
| - const heif_item_id* layer_item_ids, |
162 |
| - size_t num_layers, |
163 |
| - /* |
164 |
| - uint16_t tile_width, |
165 |
| - uint16_t tile_height, |
166 |
| - uint32_t num_layers, |
167 |
| - const heif_pyramid_layer_info* in_layers, |
168 |
| - */ |
169 |
| - heif_item_id* out_group_id) |
170 |
| -{ |
171 |
| - if (!layer_item_ids) { |
172 |
| - return error_null_parameter; |
173 |
| - } |
174 |
| - |
175 |
| - if (num_layers == 0) { |
176 |
| - return {heif_error_Usage_error, heif_suberror_Invalid_parameter_value, "Number of layers cannot be 0."}; |
177 |
| - } |
178 |
| - |
179 |
| - std::vector<heif_item_id> layers(num_layers); |
180 |
| - for (size_t i = 0; i < num_layers; i++) { |
181 |
| - layers[i] = layer_item_ids[i]; |
182 |
| - } |
183 |
| - |
184 |
| - Result<heif_item_id> result = ctx->context->add_pyramid_group(layers); |
185 |
| - |
186 |
| - if (result) { |
187 |
| - if (out_group_id) { |
188 |
| - *out_group_id = result.value; |
189 |
| - } |
190 |
| - return heif_error_success; |
191 |
| - } |
192 |
| - else { |
193 |
| - return result.error.error_struct(ctx->context.get()); |
194 |
| - } |
195 |
| -} |
196 |
| - |
197 |
| - |
198 |
| -struct heif_pyramid_layer_info* heif_context_get_pyramid_entity_group_info(struct heif_context* ctx, heif_entity_group_id id, int* out_num_layers) |
199 |
| -{ |
200 |
| - if (!out_num_layers) { |
201 |
| - return nullptr; |
202 |
| - } |
203 |
| - |
204 |
| - std::shared_ptr<Box_EntityToGroup> groupBox = ctx->context->get_heif_file()->get_entity_group(id); |
205 |
| - if (!groupBox) { |
206 |
| - return nullptr; |
207 |
| - } |
208 |
| - |
209 |
| - const auto pymdBox = std::dynamic_pointer_cast<Box_pymd>(groupBox); |
210 |
| - if (!pymdBox) { |
211 |
| - return nullptr; |
212 |
| - } |
213 |
| - |
214 |
| - const std::vector<Box_pymd::LayerInfo> pymd_layers = pymdBox->get_layers(); |
215 |
| - if (pymd_layers.empty()) { |
216 |
| - return nullptr; |
217 |
| - } |
218 |
| - |
219 |
| - auto items = pymdBox->get_item_ids(); |
220 |
| - assert(items.size() == pymd_layers.size()); |
221 |
| - |
222 |
| - auto* layerInfo = new heif_pyramid_layer_info[pymd_layers.size()]; |
223 |
| - for (size_t i=0; i<pymd_layers.size(); i++) { |
224 |
| - layerInfo[i].layer_image_id = items[i]; |
225 |
| - layerInfo[i].layer_binning = pymd_layers[i].layer_binning; |
226 |
| - layerInfo[i].tile_rows_in_layer = pymd_layers[i].tiles_in_layer_row_minus1 + 1; |
227 |
| - layerInfo[i].tile_columns_in_layer = pymd_layers[i].tiles_in_layer_column_minus1 + 1; |
228 |
| - } |
229 |
| - |
230 |
| - *out_num_layers = static_cast<int>(pymd_layers.size()); |
231 |
| - |
232 |
| - return layerInfo; |
233 |
| -} |
234 | 22 |
|
235 | 23 |
|
236 | 24 | void heif_pyramid_layer_info_release(struct heif_pyramid_layer_info* infos)
|
237 | 25 | {
|
238 | 26 | delete[] infos;
|
239 | 27 | }
|
240 |
| - |
241 |
| - |
242 |
| - |
243 |
| - |
244 |
| - |
245 |
| -struct heif_error heif_image_handle_decode_image_tile(const struct heif_image_handle* in_handle, |
246 |
| - struct heif_image** out_img, |
247 |
| - enum heif_colorspace colorspace, |
248 |
| - enum heif_chroma chroma, |
249 |
| - const struct heif_decoding_options* input_options, |
250 |
| - uint32_t x0, uint32_t y0) |
251 |
| -{ |
252 |
| - if (!in_handle) { |
253 |
| - return error_null_parameter; |
254 |
| - } |
255 |
| - |
256 |
| - heif_item_id id = in_handle->image->get_id(); |
257 |
| - |
258 |
| - heif_decoding_options* dec_options = heif_decoding_options_alloc(); |
259 |
| - heif_decoding_options_copy(dec_options, input_options); |
260 |
| - |
261 |
| - Result<std::shared_ptr<HeifPixelImage>> decodingResult = in_handle->context->decode_image(id, |
262 |
| - colorspace, |
263 |
| - chroma, |
264 |
| - *dec_options, |
265 |
| - true, x0,y0); |
266 |
| - heif_decoding_options_free(dec_options); |
267 |
| - |
268 |
| - if (decodingResult.error.error_code != heif_error_Ok) { |
269 |
| - return decodingResult.error.error_struct(in_handle->image.get()); |
270 |
| - } |
271 |
| - |
272 |
| - std::shared_ptr<HeifPixelImage> img = decodingResult.value; |
273 |
| - |
274 |
| - *out_img = new heif_image(); |
275 |
| - (*out_img)->image = std::move(img); |
276 |
| - |
277 |
| - return Error::Ok.error_struct(in_handle->image.get()); |
278 |
| -} |
0 commit comments