Skip to content

Commit 7c0f877

Browse files
committed
extract new header heif_tiling.h from heif.h
1 parent 1539712 commit 7c0f877

File tree

5 files changed

+356
-320
lines changed

5 files changed

+356
-320
lines changed

libheif/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(libheif_headers
2323
api/libheif/heif_decoding.h
2424
api/libheif/heif_image_handle.h
2525
api/libheif/heif_context.h
26+
api/libheif/heif_tiling.h
2627
api/libheif/heif_cxx.h
2728
${CMAKE_CURRENT_BINARY_DIR}/heif_version.h)
2829

@@ -78,6 +79,7 @@ set(libheif_sources
7879
api/libheif/heif_decoding.cc
7980
api/libheif/heif_image_handle.cc
8081
api/libheif/heif_context.cc
82+
api/libheif/heif_tiling.cc
8183
codecs/decoder.h
8284
codecs/decoder.cc
8385
codecs/encoder.h

libheif/api/libheif/heif.cc

Lines changed: 0 additions & 251 deletions
Original file line numberDiff line numberDiff line change
@@ -18,261 +18,10 @@
1818
* along with libheif. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
#include "heif_plugin.h"
22-
#include "security_limits.h"
23-
#include "region.h"
24-
#include "common_utils.h"
25-
#include <cstdint>
2621
#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-
}
23422

23523

23624
void heif_pyramid_layer_info_release(struct heif_pyramid_layer_info* infos)
23725
{
23826
delete[] infos;
23927
}
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-
}

libheif/api/libheif/heif.h

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -21,80 +21,13 @@
2121
#ifndef LIBHEIF_HEIF_H
2222
#define LIBHEIF_HEIF_H
2323

24-
#ifdef __cplusplus
25-
extern "C" {
26-
#endif
27-
28-
/*! \file heif.h
29-
*
30-
* Public API for libheif.
31-
*/
32-
33-
#include <stddef.h>
34-
#include <stdint.h>
35-
3624
#include <libheif/heif_library.h>
3725
#include <libheif/heif_version.h>
3826
#include <libheif/heif_image.h>
3927
#include <libheif/heif_color.h>
4028
#include <libheif/heif_error.h>
4129
#include <libheif/heif_brands.h>
4230

43-
44-
struct heif_image_tiling
45-
{
46-
int version;
47-
48-
// --- version 1
49-
50-
uint32_t num_columns;
51-
uint32_t num_rows;
52-
uint32_t tile_width;
53-
uint32_t tile_height;
54-
55-
uint32_t image_width;
56-
uint32_t image_height;
57-
58-
// Position of the top left tile.
59-
// Usually, this is (0;0), but if a tiled image is rotated or cropped, it may be that the top left tile should be placed at a negative position.
60-
// The offsets define this negative shift.
61-
uint32_t top_offset;
62-
uint32_t left_offset;
63-
64-
uint8_t number_of_extra_dimensions; // 0 for normal images, 1 for volumetric (3D), ...
65-
uint32_t extra_dimension_size[8]; // size of extra dimensions (first 8 dimensions)
66-
};
67-
68-
69-
// If 'process_image_transformations' is true, this returns modified sizes.
70-
// If it is false, the top_offset and left_offset will always be (0;0).
71-
LIBHEIF_API
72-
struct heif_error heif_image_handle_get_image_tiling(const struct heif_image_handle* handle, int process_image_transformations, struct heif_image_tiling* out_tiling);
73-
74-
75-
// For grid images, return the image item ID of a specific grid tile.
76-
// If 'process_image_transformations' is true, the tile positions are given in the transformed image coordinate system and
77-
// are internally mapped to the original image tile positions.
78-
LIBHEIF_API
79-
struct heif_error heif_image_handle_get_grid_image_tile_id(const struct heif_image_handle* handle,
80-
int process_image_transformations,
81-
uint32_t tile_x, uint32_t tile_y,
82-
heif_item_id* out_tile_item_id);
83-
84-
85-
struct heif_decoding_options;
86-
87-
// The tile position is given in tile indices, not in pixel coordinates.
88-
// If the image transformations are processed (option->ignore_image_transformations==false), the tile position
89-
// is given in the transformed coordinates.
90-
LIBHEIF_API
91-
struct heif_error heif_image_handle_decode_image_tile(const struct heif_image_handle* in_handle,
92-
struct heif_image** out_img,
93-
enum heif_colorspace colorspace,
94-
enum heif_chroma chroma,
95-
const struct heif_decoding_options* options,
96-
uint32_t tile_x, uint32_t tile_y);
97-
9831
#include <libheif/heif_metadata.h>
9932
#include <libheif/heif_aux_images.h>
10033
#include <libheif/heif_entity_groups.h>
@@ -103,9 +36,10 @@ struct heif_error heif_image_handle_decode_image_tile(const struct heif_image_ha
10336
#include <libheif/heif_decoding.h>
10437
#include <libheif/heif_context.h>
10538
#include <libheif/heif_image_handle.h>
39+
#include <libheif/heif_tiling.h>
10640

107-
#ifdef __cplusplus
108-
}
41+
#if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_STANDALONE_WASM__)
42+
#include "heif_emscripten.h"
10943
#endif
11044

11145
#endif

0 commit comments

Comments
 (0)