@img/sharp-libvips-dev 1.2.0-rc.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/include/fontconfig/fontconfig.h +12 -2
  2. package/include/glib-2.0/girepository/girepository.h +3 -0
  3. package/include/glib-2.0/glib/gmarkup.h +4 -0
  4. package/include/libheif/heif.h +16 -2603
  5. package/include/libheif/heif_aux_images.h +182 -0
  6. package/include/libheif/heif_brands.h +373 -0
  7. package/include/libheif/heif_color.h +357 -0
  8. package/include/libheif/heif_context.h +329 -0
  9. package/include/libheif/heif_cxx.h +6 -6
  10. package/include/libheif/heif_decoding.h +162 -0
  11. package/include/libheif/heif_encoding.h +391 -0
  12. package/include/libheif/heif_entity_groups.h +60 -0
  13. package/include/libheif/heif_error.h +302 -0
  14. package/include/libheif/heif_image.h +352 -0
  15. package/include/libheif/heif_image_handle.h +120 -0
  16. package/include/libheif/heif_items.h +45 -45
  17. package/include/libheif/heif_library.h +216 -0
  18. package/include/libheif/heif_metadata.h +133 -0
  19. package/include/libheif/heif_plugin.h +53 -41
  20. package/include/libheif/heif_properties.h +73 -36
  21. package/include/libheif/heif_regions.h +95 -95
  22. package/include/libheif/heif_security.h +102 -0
  23. package/include/libheif/heif_sequences.h +577 -0
  24. package/include/libheif/heif_tai_timestamps.h +202 -0
  25. package/include/libheif/heif_tiling.h +137 -0
  26. package/include/libheif/heif_uncompressed.h +109 -0
  27. package/include/libheif/heif_version.h +2 -2
  28. package/include/libpng16/png.h +7 -7
  29. package/include/libpng16/pngconf.h +1 -1
  30. package/include/libpng16/pnglibconf.h +1 -1
  31. package/include/pango-1.0/pango/pango-attributes.h +1 -1
  32. package/include/pango-1.0/pango/pango-features.h +2 -2
  33. package/include/png.h +7 -7
  34. package/include/pngconf.h +1 -1
  35. package/include/pnglibconf.h +1 -1
  36. package/include/vips/version.h +4 -4
  37. package/package.json +1 -1
  38. package/versions.json +5 -5
@@ -0,0 +1,357 @@
1
+ /*
2
+ * HEIF codec.
3
+ * Copyright (c) 2017-2023 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
+ #ifndef LIBHEIF_HEIF_COLOR_H
22
+ #define LIBHEIF_HEIF_COLOR_H
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ #include <libheif/heif_library.h>
29
+
30
+ // forward declaration from other header files
31
+ typedef struct heif_image heif_image;
32
+
33
+
34
+ enum heif_chroma_downsampling_algorithm
35
+ {
36
+ heif_chroma_downsampling_nearest_neighbor = 1,
37
+ heif_chroma_downsampling_average = 2,
38
+
39
+ // Combine with 'heif_chroma_upsampling_bilinear' for best quality.
40
+ // Makes edges look sharper when using YUV 420 with bilinear chroma upsampling.
41
+ heif_chroma_downsampling_sharp_yuv = 3
42
+ };
43
+
44
+ enum heif_chroma_upsampling_algorithm
45
+ {
46
+ heif_chroma_upsampling_nearest_neighbor = 1,
47
+ heif_chroma_upsampling_bilinear = 2
48
+ };
49
+
50
+
51
+ typedef struct heif_color_conversion_options
52
+ {
53
+ // 'version' must be 1.
54
+ uint8_t version;
55
+
56
+ // --- version 1 options
57
+
58
+ enum heif_chroma_downsampling_algorithm preferred_chroma_downsampling_algorithm;
59
+ enum heif_chroma_upsampling_algorithm preferred_chroma_upsampling_algorithm;
60
+
61
+ // When set to 'false' libheif may also use a different algorithm if the preferred one is not available
62
+ // or using a different algorithm is computationally less complex. Note that currently (v1.17.0) this
63
+ // means that for RGB input it will usually choose nearest-neighbor sampling because this is computationally
64
+ // the simplest.
65
+ // Set this field to 'true' if you want to make sure that the specified algorithm is used even
66
+ // at the cost of slightly higher computation times.
67
+ uint8_t only_use_preferred_chroma_algorithm;
68
+
69
+ // --- Note that we cannot extend this struct because it is embedded in
70
+ // other structs (heif_decoding_options and heif_encoding_options).
71
+ } heif_color_conversion_options;
72
+
73
+
74
+ enum heif_alpha_composition_mode
75
+ {
76
+ heif_alpha_composition_mode_none,
77
+ heif_alpha_composition_mode_solid_color,
78
+ heif_alpha_composition_mode_checkerboard,
79
+ };
80
+
81
+
82
+ typedef struct heif_color_conversion_options_ext
83
+ {
84
+ uint8_t version;
85
+
86
+ // --- version 1 options
87
+
88
+ enum heif_alpha_composition_mode alpha_composition_mode;
89
+
90
+ // color values should be specified in the range [0, 65535]
91
+ uint16_t background_red, background_green, background_blue;
92
+ uint16_t secondary_background_red, secondary_background_green, secondary_background_blue;
93
+ uint16_t checkerboard_square_size;
94
+ } heif_color_conversion_options_ext;
95
+
96
+
97
+ // Assumes that it is a version=1 struct.
98
+ LIBHEIF_API
99
+ void heif_color_conversion_options_set_defaults(heif_color_conversion_options*);
100
+
101
+ LIBHEIF_API
102
+ heif_color_conversion_options_ext* heif_color_conversion_options_ext_alloc(void);
103
+
104
+ LIBHEIF_API
105
+ void heif_color_conversion_options_ext_copy(heif_color_conversion_options_ext* dst,
106
+ const heif_color_conversion_options_ext* src);
107
+
108
+ LIBHEIF_API
109
+ void heif_color_conversion_options_ext_free(heif_color_conversion_options_ext*);
110
+
111
+
112
+ // ------------------------- color profiles -------------------------
113
+
114
+ enum heif_color_profile_type
115
+ {
116
+ heif_color_profile_type_not_present = 0,
117
+ heif_color_profile_type_nclx = heif_fourcc('n', 'c', 'l', 'x'),
118
+ heif_color_profile_type_rICC = heif_fourcc('r', 'I', 'C', 'C'),
119
+ heif_color_profile_type_prof = heif_fourcc('p', 'r', 'o', 'f')
120
+ };
121
+
122
+
123
+ // Returns 'heif_color_profile_type_not_present' if there is no color profile.
124
+ // If there is an ICC profile and an NCLX profile, the ICC profile is returned.
125
+ // TODO: we need a new API for this function as images can contain both NCLX and ICC at the same time.
126
+ // However, you can still use heif_image_handle_get_raw_color_profile() and
127
+ // heif_image_handle_get_nclx_color_profile() to access both profiles.
128
+ LIBHEIF_API
129
+ enum heif_color_profile_type heif_image_handle_get_color_profile_type(const heif_image_handle* handle);
130
+
131
+ LIBHEIF_API
132
+ size_t heif_image_handle_get_raw_color_profile_size(const heif_image_handle* handle);
133
+
134
+ // Returns 'heif_error_Color_profile_does_not_exist' when there is no ICC profile.
135
+ LIBHEIF_API
136
+ struct heif_error heif_image_handle_get_raw_color_profile(const heif_image_handle* handle,
137
+ void* out_data);
138
+
139
+
140
+ enum heif_color_primaries
141
+ {
142
+ heif_color_primaries_ITU_R_BT_709_5 = 1, // g=0.3;0.6, b=0.15;0.06, r=0.64;0.33, w=0.3127,0.3290
143
+ heif_color_primaries_unspecified = 2,
144
+ heif_color_primaries_ITU_R_BT_470_6_System_M = 4,
145
+ heif_color_primaries_ITU_R_BT_470_6_System_B_G = 5,
146
+ heif_color_primaries_ITU_R_BT_601_6 = 6,
147
+ heif_color_primaries_SMPTE_240M = 7,
148
+ heif_color_primaries_generic_film = 8,
149
+ heif_color_primaries_ITU_R_BT_2020_2_and_2100_0 = 9,
150
+ heif_color_primaries_SMPTE_ST_428_1 = 10,
151
+ heif_color_primaries_SMPTE_RP_431_2 = 11,
152
+ heif_color_primaries_SMPTE_EG_432_1 = 12,
153
+ heif_color_primaries_EBU_Tech_3213_E = 22
154
+ };
155
+
156
+ enum heif_transfer_characteristics
157
+ {
158
+ heif_transfer_characteristic_ITU_R_BT_709_5 = 1,
159
+ heif_transfer_characteristic_unspecified = 2,
160
+ heif_transfer_characteristic_ITU_R_BT_470_6_System_M = 4,
161
+ heif_transfer_characteristic_ITU_R_BT_470_6_System_B_G = 5,
162
+ heif_transfer_characteristic_ITU_R_BT_601_6 = 6,
163
+ heif_transfer_characteristic_SMPTE_240M = 7,
164
+ heif_transfer_characteristic_linear = 8,
165
+ heif_transfer_characteristic_logarithmic_100 = 9,
166
+ heif_transfer_characteristic_logarithmic_100_sqrt10 = 10,
167
+ heif_transfer_characteristic_IEC_61966_2_4 = 11,
168
+ heif_transfer_characteristic_ITU_R_BT_1361 = 12,
169
+ heif_transfer_characteristic_IEC_61966_2_1 = 13,
170
+ heif_transfer_characteristic_ITU_R_BT_2020_2_10bit = 14,
171
+ heif_transfer_characteristic_ITU_R_BT_2020_2_12bit = 15,
172
+ heif_transfer_characteristic_ITU_R_BT_2100_0_PQ = 16,
173
+ heif_transfer_characteristic_SMPTE_ST_428_1 = 17,
174
+ heif_transfer_characteristic_ITU_R_BT_2100_0_HLG = 18
175
+ };
176
+
177
+ enum heif_matrix_coefficients
178
+ {
179
+ heif_matrix_coefficients_RGB_GBR = 0,
180
+ heif_matrix_coefficients_ITU_R_BT_709_5 = 1, // TODO: or 709-6 according to h.273
181
+ heif_matrix_coefficients_unspecified = 2,
182
+ heif_matrix_coefficients_US_FCC_T47 = 4,
183
+ heif_matrix_coefficients_ITU_R_BT_470_6_System_B_G = 5,
184
+ heif_matrix_coefficients_ITU_R_BT_601_6 = 6, // TODO: or 601-7 according to h.273
185
+ heif_matrix_coefficients_SMPTE_240M = 7,
186
+ heif_matrix_coefficients_YCgCo = 8,
187
+ heif_matrix_coefficients_ITU_R_BT_2020_2_non_constant_luminance = 9,
188
+ heif_matrix_coefficients_ITU_R_BT_2020_2_constant_luminance = 10,
189
+ heif_matrix_coefficients_SMPTE_ST_2085 = 11,
190
+ heif_matrix_coefficients_chromaticity_derived_non_constant_luminance = 12,
191
+ heif_matrix_coefficients_chromaticity_derived_constant_luminance = 13,
192
+ heif_matrix_coefficients_ICtCp = 14
193
+ };
194
+
195
+ typedef struct heif_color_profile_nclx
196
+ {
197
+ // === version 1 fields
198
+
199
+ uint8_t version;
200
+
201
+ enum heif_color_primaries color_primaries;
202
+ enum heif_transfer_characteristics transfer_characteristics;
203
+ enum heif_matrix_coefficients matrix_coefficients;
204
+ uint8_t full_range_flag;
205
+
206
+ // --- decoded values (not used when saving nclx)
207
+
208
+ float color_primary_red_x, color_primary_red_y;
209
+ float color_primary_green_x, color_primary_green_y;
210
+ float color_primary_blue_x, color_primary_blue_y;
211
+ float color_primary_white_x, color_primary_white_y;
212
+ } heif_color_profile_nclx;
213
+
214
+ LIBHEIF_API
215
+ heif_error heif_nclx_color_profile_set_color_primaries(heif_color_profile_nclx* nclx, uint16_t cp);
216
+
217
+ LIBHEIF_API
218
+ heif_error heif_nclx_color_profile_set_transfer_characteristics(heif_color_profile_nclx* nclx, uint16_t transfer_characteristics);
219
+
220
+ LIBHEIF_API
221
+ heif_error heif_nclx_color_profile_set_matrix_coefficients(heif_color_profile_nclx* nclx, uint16_t matrix_coefficients);
222
+
223
+ // Returns 'heif_error_Color_profile_does_not_exist' when there is no NCLX profile.
224
+ // TODO: This function does currently not return an NCLX profile if it is stored in the image bitstream.
225
+ // Only NCLX profiles stored as colr boxes are returned. This may change in the future.
226
+ LIBHEIF_API
227
+ heif_error heif_image_handle_get_nclx_color_profile(const heif_image_handle* handle,
228
+ heif_color_profile_nclx** out_data);
229
+
230
+ // Returned color profile has 'version' field set to the maximum allowed.
231
+ // Do not fill values for higher versions as these might be outside the allocated structure size.
232
+ // May return NULL.
233
+ LIBHEIF_API
234
+ heif_color_profile_nclx* heif_nclx_color_profile_alloc(void);
235
+
236
+ LIBHEIF_API
237
+ void heif_nclx_color_profile_free(heif_color_profile_nclx* nclx_profile);
238
+
239
+ // Note: in early versions of HEIF, there could only be one color profile per image. However, this has been changed.
240
+ // This function will now return ICC if one is present and NCLX only if there is no ICC.
241
+ // You may better avoid this function and simply query for NCLX and ICC directly.
242
+ LIBHEIF_API
243
+ enum heif_color_profile_type heif_image_get_color_profile_type(const heif_image* image);
244
+
245
+ // Returns the size of the ICC profile if one is assigned to the image. Otherwise, it returns 0.
246
+ LIBHEIF_API
247
+ size_t heif_image_get_raw_color_profile_size(const heif_image* image);
248
+
249
+ // Returns the ICC profile if one is assigned to the image. Otherwise, it returns an error.
250
+ LIBHEIF_API
251
+ heif_error heif_image_get_raw_color_profile(const heif_image* image,
252
+ void* out_data);
253
+
254
+ LIBHEIF_API
255
+ heif_error heif_image_get_nclx_color_profile(const heif_image* image,
256
+ heif_color_profile_nclx** out_data);
257
+
258
+
259
+ // The color profile is not attached to the image handle because we might need it
260
+ // for color space transform and encoding.
261
+ LIBHEIF_API
262
+ heif_error heif_image_set_raw_color_profile(heif_image* image,
263
+ const char* profile_type_fourcc_string,
264
+ const void* profile_data,
265
+ const size_t profile_size);
266
+
267
+ LIBHEIF_API
268
+ heif_error heif_image_set_nclx_color_profile(heif_image* image,
269
+ const heif_color_profile_nclx* color_profile);
270
+
271
+
272
+ // TODO: this function does not make any sense yet, since we currently cannot modify existing HEIF files.
273
+ //LIBHEIF_API
274
+ //void heif_image_remove_color_profile(struct heif_image* image);
275
+
276
+
277
+ // --- content light level ---
278
+
279
+ // Note: a value of 0 for any of these values indicates that the value is undefined.
280
+ // The unit of these values is Candelas per square meter.
281
+ typedef struct heif_content_light_level
282
+ {
283
+ uint16_t max_content_light_level;
284
+ uint16_t max_pic_average_light_level;
285
+ } heif_content_light_level;
286
+
287
+ LIBHEIF_API
288
+ int heif_image_has_content_light_level(const heif_image*);
289
+
290
+ LIBHEIF_API
291
+ void heif_image_get_content_light_level(const heif_image*, heif_content_light_level* out);
292
+
293
+ // Returns whether the image has 'content light level' information. If 0 is returned, the output is not filled.
294
+ LIBHEIF_API
295
+ int heif_image_handle_get_content_light_level(const heif_image_handle*, heif_content_light_level* out);
296
+
297
+ LIBHEIF_API
298
+ void heif_image_set_content_light_level(const heif_image*, const heif_content_light_level* in);
299
+
300
+
301
+ // --- mastering display colour volume ---
302
+
303
+ // Note: color coordinates are defined according to the CIE 1931 definition of x as specified in ISO 11664-1 (see also ISO 11664-3 and CIE 15).
304
+ typedef struct heif_mastering_display_colour_volume
305
+ {
306
+ uint16_t display_primaries_x[3];
307
+ uint16_t display_primaries_y[3];
308
+ uint16_t white_point_x;
309
+ uint16_t white_point_y;
310
+ uint32_t max_display_mastering_luminance;
311
+ uint32_t min_display_mastering_luminance;
312
+ } heif_mastering_display_colour_volume;
313
+
314
+ // The units for max_display_mastering_luminance and min_display_mastering_luminance is Candelas per square meter.
315
+ typedef struct heif_decoded_mastering_display_colour_volume
316
+ {
317
+ float display_primaries_x[3];
318
+ float display_primaries_y[3];
319
+ float white_point_x;
320
+ float white_point_y;
321
+ double max_display_mastering_luminance;
322
+ double min_display_mastering_luminance;
323
+ } heif_decoded_mastering_display_colour_volume;
324
+
325
+ typedef struct heif_ambient_viewing_environment
326
+ {
327
+ uint32_t ambient_illumination;
328
+ uint16_t ambient_light_x;
329
+ uint16_t ambient_light_y;
330
+ } heif_ambient_viewing_environment;
331
+
332
+ LIBHEIF_API
333
+ int heif_image_has_mastering_display_colour_volume(const heif_image*);
334
+
335
+ LIBHEIF_API
336
+ void heif_image_get_mastering_display_colour_volume(const heif_image*, heif_mastering_display_colour_volume* out);
337
+
338
+ // Returns whether the image has 'mastering display colour volume' information. If 0 is returned, the output is not filled.
339
+ LIBHEIF_API
340
+ int heif_image_handle_get_mastering_display_colour_volume(const heif_image_handle*, heif_mastering_display_colour_volume* out);
341
+
342
+ LIBHEIF_API
343
+ void heif_image_set_mastering_display_colour_volume(const heif_image*, const heif_mastering_display_colour_volume* in);
344
+
345
+
346
+ // Converts the internal numeric representation of heif_mastering_display_colour_volume to the
347
+ // normalized values, collected in heif_decoded_mastering_display_colour_volume.
348
+ // Values that are out-of-range are decoded to 0, indicating an undefined value (as specified in ISO/IEC 23008-2).
349
+ LIBHEIF_API
350
+ struct heif_error heif_mastering_display_colour_volume_decode(const heif_mastering_display_colour_volume* in,
351
+ heif_decoded_mastering_display_colour_volume* out);
352
+
353
+ #ifdef __cplusplus
354
+ }
355
+ #endif
356
+
357
+ #endif
@@ -0,0 +1,329 @@
1
+ /*
2
+ * HEIF codec.
3
+ * Copyright (c) 2017-2025 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
+ #ifndef LIBHEIF_HEIF_CONTEXT_H
22
+ #define LIBHEIF_HEIF_CONTEXT_H
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ #include <stddef.h>
29
+ #include <stdint.h>
30
+
31
+ #include <libheif/heif_library.h>
32
+ #include <libheif/heif_error.h>
33
+
34
+
35
+ /**
36
+ * libheif known compression formats.
37
+ */
38
+ enum heif_compression_format
39
+ {
40
+ /**
41
+ * Unspecified / undefined compression format.
42
+ *
43
+ * This is used to mean "no match" or "any decoder" for some parts of the
44
+ * API. It does not indicate a specific compression format.
45
+ */
46
+ heif_compression_undefined = 0,
47
+ /**
48
+ * HEVC compression, used for HEIC images.
49
+ *
50
+ * This is equivalent to H.265.
51
+ */
52
+ heif_compression_HEVC = 1,
53
+ /**
54
+ * AVC compression. (Currently unused in libheif.)
55
+ *
56
+ * The compression is defined in ISO/IEC 14496-10. This is equivalent to H.264.
57
+ *
58
+ * The encapsulation is defined in ISO/IEC 23008-12:2022 Annex E.
59
+ */
60
+ heif_compression_AVC = 2,
61
+ /**
62
+ * JPEG compression.
63
+ *
64
+ * The compression format is defined in ISO/IEC 10918-1. The encapsulation
65
+ * of JPEG is specified in ISO/IEC 23008-12:2022 Annex H.
66
+ */
67
+ heif_compression_JPEG = 3,
68
+ /**
69
+ * AV1 compression, used for AVIF images.
70
+ *
71
+ * The compression format is provided at https://aomediacodec.github.io/av1-spec/
72
+ *
73
+ * The encapsulation is defined in https://aomediacodec.github.io/av1-avif/
74
+ */
75
+ heif_compression_AV1 = 4,
76
+ /**
77
+ * VVC compression.
78
+ *
79
+ * The compression format is defined in ISO/IEC 23090-3. This is equivalent to H.266.
80
+ *
81
+ * The encapsulation is defined in ISO/IEC 23008-12:2022 Annex L.
82
+ */
83
+ heif_compression_VVC = 5,
84
+ /**
85
+ * EVC compression. (Currently unused in libheif.)
86
+ *
87
+ * The compression format is defined in ISO/IEC 23094-1.
88
+ *
89
+ * The encapsulation is defined in ISO/IEC 23008-12:2022 Annex M.
90
+ */
91
+ heif_compression_EVC = 6,
92
+ /**
93
+ * JPEG 2000 compression.
94
+ *
95
+ * The encapsulation of JPEG 2000 is specified in ISO/IEC 15444-16:2021.
96
+ * The core encoding is defined in ISO/IEC 15444-1, or ITU-T T.800.
97
+ */
98
+ heif_compression_JPEG2000 = 7,
99
+ /**
100
+ * Uncompressed encoding.
101
+ *
102
+ * This is defined in ISO/IEC 23001-17:2024.
103
+ */
104
+ heif_compression_uncompressed = 8,
105
+ /**
106
+ * Mask image encoding.
107
+ *
108
+ * See ISO/IEC 23008-12:2022 Section 6.10.2
109
+ */
110
+ heif_compression_mask = 9,
111
+ /**
112
+ * High Throughput JPEG 2000 (HT-J2K) compression.
113
+ *
114
+ * The encapsulation of HT-J2K is specified in ISO/IEC 15444-16:2021.
115
+ * The core encoding is defined in ISO/IEC 15444-15, or ITU-T T.814.
116
+ */
117
+ heif_compression_HTJ2K = 10
118
+ };
119
+
120
+
121
+ // ========================= heif_context =========================
122
+ // A heif_context represents a HEIF file that has been read.
123
+ // In the future, you will also be able to add pictures to a heif_context
124
+ // and write it into a file again.
125
+
126
+
127
+ // Allocate a new context for reading HEIF files.
128
+ // Has to be freed again with heif_context_free().
129
+ LIBHEIF_API
130
+ heif_context* heif_context_alloc(void);
131
+
132
+ // Free a previously allocated HEIF context. You should not free a context twice.
133
+ LIBHEIF_API
134
+ void heif_context_free(heif_context*);
135
+
136
+
137
+ typedef struct heif_reading_options heif_reading_options;
138
+
139
+ enum heif_reader_grow_status
140
+ {
141
+ heif_reader_grow_status_size_reached, // requested size has been reached, we can read until this point
142
+ heif_reader_grow_status_timeout, // size has not been reached yet, but it may still grow further (deprecated)
143
+ heif_reader_grow_status_size_beyond_eof, // size has not been reached and never will. The file has grown to its full size
144
+ heif_reader_grow_status_error // an error has occurred
145
+ };
146
+
147
+
148
+ typedef struct heif_reader_range_request_result
149
+ {
150
+ enum heif_reader_grow_status status; // should not return 'heif_reader_grow_status_timeout'
151
+
152
+ // Indicates up to what position the file has been read.
153
+ // If we cannot read the whole file range (status == 'heif_reader_grow_status_size_beyond_eof'), this is the actual end position.
154
+ // On the other hand, it may be that the reader was reading more data than requested. In that case, it should indicate the full size here
155
+ // and libheif may decide to make use of the additional data (e.g. for filling 'tili' offset tables).
156
+ uint64_t range_end;
157
+
158
+ // for status == 'heif_reader_grow_status_error'
159
+ int reader_error_code; // a reader specific error code
160
+ const char* reader_error_msg; // libheif will call heif_reader.release_error_msg on this if it is not NULL
161
+ } heif_reader_range_request_result;
162
+
163
+
164
+ typedef struct heif_reader
165
+ {
166
+ // API version supported by this reader
167
+ int reader_api_version;
168
+
169
+ // --- version 1 functions ---
170
+ int64_t (* get_position)(void* userdata);
171
+
172
+ // The functions read(), and seek() return 0 on success.
173
+ // Generally, libheif will make sure that we do not read past the file size.
174
+ int (* read)(void* data,
175
+ size_t size,
176
+ void* userdata);
177
+
178
+ int (* seek)(int64_t position,
179
+ void* userdata);
180
+
181
+ // When calling this function, libheif wants to make sure that it can read the file
182
+ // up to 'target_size'. This is useful when the file is currently downloaded and may
183
+ // grow with time. You may, for example, extract the image sizes even before the actual
184
+ // compressed image data has been completely downloaded.
185
+ //
186
+ // Even if your input files will not grow, you will have to implement at least
187
+ // detection whether the target_size is above the (fixed) file length
188
+ // (in this case, return 'size_beyond_eof').
189
+ enum heif_reader_grow_status (* wait_for_file_size)(int64_t target_size, void* userdata);
190
+
191
+ // --- version 2 functions ---
192
+
193
+ // These two functions are for applications that want to stream HEIF files on demand.
194
+ // For example, a large HEIF file that is served over HTTPS and we only want to download
195
+ // it partially to decode individual tiles.
196
+ // If you do not have this use case, you do not have to implement these functions and
197
+ // you can set them to NULL. For simple linear loading, you may use the 'wait_for_file_size'
198
+ // function above instead.
199
+
200
+ // If this function is defined, libheif will often request a file range before accessing it.
201
+ // The purpose of this function is that libheif will usually read very small chunks of data with the
202
+ // read() callback above. However, it is inefficient to request such a small chunk of data over a network
203
+ // and the network delay will significantly increase the decoding time.
204
+ // Thus, libheif will call request_range() with a larger block of data that should be preloaded and the
205
+ // subsequent read() calls will work within the requested ranges.
206
+ //
207
+ // Note: `end_pos` is one byte after the last position to be read.
208
+ // You should return
209
+ // - 'heif_reader_grow_status_size_reached' if the requested range is available, or
210
+ // - 'heif_reader_grow_status_size_beyond_eof' if the requested range exceeds the file size
211
+ // (the valid part of the range has been read).
212
+ heif_reader_range_request_result (* request_range)(uint64_t start_pos, uint64_t end_pos, void* userdata);
213
+
214
+ // libheif might issue hints when it assumes that a file range might be needed in the future.
215
+ // This may happen, for example, when your are doing selective tile accesses and libheif proposes
216
+ // to preload offset pointer tables.
217
+ // Another difference to request_file_range() is that this call should be non-blocking.
218
+ // If you preload any data, do this in a background thread.
219
+ void (* preload_range_hint)(uint64_t start_pos, uint64_t end_pos, void* userdata);
220
+
221
+ // If libheif does not need access to a file range anymore, it may call this function to
222
+ // give a hint to the reader that it may release the range from a cache.
223
+ // If you do not maintain a file cache that wants to reduce its size dynamically, you do not
224
+ // need to implement this function.
225
+ void (* release_file_range)(uint64_t start_pos, uint64_t end_pos, void* userdata);
226
+
227
+ // Release an error message that was returned by heif_reader in an earlier call.
228
+ // If this function is NULL, the error message string will not be released.
229
+ // This is a viable option if you are only returning static strings.
230
+ void (* release_error_msg)(const char* msg);
231
+ } heif_reader;
232
+
233
+
234
+ // Read a HEIF file from a named disk file.
235
+ // The heif_reading_options should currently be set to NULL.
236
+ LIBHEIF_API
237
+ heif_error heif_context_read_from_file(heif_context*, const char* filename,
238
+ const heif_reading_options*);
239
+
240
+ // Read a HEIF file stored completely in memory.
241
+ // The heif_reading_options should currently be set to NULL.
242
+ // DEPRECATED: use heif_context_read_from_memory_without_copy() instead.
243
+ LIBHEIF_API
244
+ heif_error heif_context_read_from_memory(heif_context*,
245
+ const void* mem, size_t size,
246
+ const heif_reading_options*);
247
+
248
+ // Same as heif_context_read_from_memory() except that the provided memory is not copied.
249
+ // That means, you will have to keep the memory area alive as long as you use the heif_context.
250
+ LIBHEIF_API
251
+ heif_error heif_context_read_from_memory_without_copy(heif_context*,
252
+ const void* mem, size_t size,
253
+ const heif_reading_options*);
254
+
255
+ LIBHEIF_API
256
+ heif_error heif_context_read_from_reader(heif_context*,
257
+ const heif_reader* reader,
258
+ void* userdata,
259
+ const heif_reading_options*);
260
+
261
+ // Number of top-level images in the HEIF file. This does not include the thumbnails or the
262
+ // tile images that are composed to an image grid. You can get access to the thumbnails via
263
+ // the main image handle.
264
+ LIBHEIF_API
265
+ int heif_context_get_number_of_top_level_images(heif_context* ctx);
266
+
267
+ LIBHEIF_API
268
+ int heif_context_is_top_level_image_ID(heif_context* ctx, heif_item_id id);
269
+
270
+ // Fills in image IDs into the user-supplied int-array 'ID_array', preallocated with 'count' entries.
271
+ // Function returns the total number of IDs filled into the array.
272
+ LIBHEIF_API
273
+ int heif_context_get_list_of_top_level_image_IDs(heif_context* ctx,
274
+ heif_item_id* ID_array,
275
+ int count);
276
+
277
+ LIBHEIF_API
278
+ heif_error heif_context_get_primary_image_ID(heif_context* ctx, heif_item_id* id);
279
+
280
+ // Get a handle to the primary image of the HEIF file.
281
+ // This is the image that should be displayed primarily when there are several images in the file.
282
+ LIBHEIF_API
283
+ heif_error heif_context_get_primary_image_handle(heif_context* ctx,
284
+ heif_image_handle**);
285
+
286
+ // Get the image handle for a known image ID.
287
+ LIBHEIF_API
288
+ heif_error heif_context_get_image_handle(heif_context* ctx,
289
+ heif_item_id id,
290
+ heif_image_handle**);
291
+
292
+ // Print information about the boxes of a HEIF file to file descriptor.
293
+ // This is for debugging and informational purposes only. You should not rely on
294
+ // the output having a specific format. At best, you should not use this at all.
295
+ LIBHEIF_API
296
+ void heif_context_debug_dump_boxes_to_file(heif_context* ctx, int fd);
297
+
298
+ // ====================================================================================================
299
+ // Write the heif_context to a HEIF file
300
+
301
+ LIBHEIF_API
302
+ heif_error heif_context_write_to_file(heif_context*,
303
+ const char* filename);
304
+
305
+ typedef struct heif_writer
306
+ {
307
+ // API version supported by this writer
308
+ int writer_api_version;
309
+
310
+ // --- version 1 functions ---
311
+
312
+ // On success, the returned heif_error may have a NULL message. It will automatically be replaced with a "Success" string.
313
+ heif_error (* write)(heif_context* ctx, // TODO: why do we need this parameter?
314
+ const void* data,
315
+ size_t size,
316
+ void* userdata);
317
+ } heif_writer;
318
+
319
+
320
+ LIBHEIF_API
321
+ heif_error heif_context_write(heif_context*,
322
+ heif_writer* writer,
323
+ void* userdata);
324
+
325
+ #ifdef __cplusplus
326
+ }
327
+ #endif
328
+
329
+ #endif