pylibheif 1.21.2__cp312-cp312-macosx_14_0_arm64.whl

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.

Potentially problematic release.


This version of pylibheif might be problematic. Click here for more details.

Files changed (41) hide show
  1. include/libheif/heif.h +41 -0
  2. include/libheif/heif_aux_images.h +182 -0
  3. include/libheif/heif_brands.h +376 -0
  4. include/libheif/heif_color.h +363 -0
  5. include/libheif/heif_context.h +329 -0
  6. include/libheif/heif_cxx.h +1390 -0
  7. include/libheif/heif_decoding.h +172 -0
  8. include/libheif/heif_encoding.h +395 -0
  9. include/libheif/heif_entity_groups.h +60 -0
  10. include/libheif/heif_error.h +304 -0
  11. include/libheif/heif_image.h +355 -0
  12. include/libheif/heif_image_handle.h +129 -0
  13. include/libheif/heif_items.h +260 -0
  14. include/libheif/heif_library.h +219 -0
  15. include/libheif/heif_metadata.h +136 -0
  16. include/libheif/heif_plugin.h +378 -0
  17. include/libheif/heif_properties.h +235 -0
  18. include/libheif/heif_regions.h +868 -0
  19. include/libheif/heif_security.h +107 -0
  20. include/libheif/heif_sequences.h +644 -0
  21. include/libheif/heif_tai_timestamps.h +202 -0
  22. include/libheif/heif_text.h +161 -0
  23. include/libheif/heif_tiling.h +137 -0
  24. include/libheif/heif_uncompressed.h +109 -0
  25. include/libheif/heif_version.h +38 -0
  26. lib/cmake/libheif/libheif-config-release.cmake +19 -0
  27. lib/cmake/libheif/libheif-config-version.cmake +83 -0
  28. lib/cmake/libheif/libheif-config.cmake +108 -0
  29. lib/libheif.a +0 -0
  30. lib/pkgconfig/libheif.pc +15 -0
  31. pylibheif-1.21.2.dist-info/METADATA +409 -0
  32. pylibheif-1.21.2.dist-info/RECORD +41 -0
  33. pylibheif-1.21.2.dist-info/WHEEL +5 -0
  34. pylibheif-1.21.2.dist-info/licenses/LICENSE +165 -0
  35. pylibheif.cpython-312-darwin.so +0 -0
  36. pylibheif.dylibs/libaom.3.13.1.dylib +0 -0
  37. pylibheif.dylibs/libdav1d.7.dylib +0 -0
  38. pylibheif.dylibs/libde265.0.dylib +0 -0
  39. pylibheif.dylibs/libopenjp2.2.5.4.dylib +0 -0
  40. pylibheif.dylibs/libvmaf.3.dylib +0 -0
  41. pylibheif.dylibs/libx265.215.dylib +0 -0
@@ -0,0 +1,1390 @@
1
+ /*
2
+ * C++ interface to libheif
3
+ *
4
+ * MIT License
5
+ *
6
+ * Copyright (c) 2018 Dirk Farin <dirk.farin@gmail.com>
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+
27
+ #ifndef LIBHEIF_HEIF_CXX_H
28
+ #define LIBHEIF_HEIF_CXX_H
29
+
30
+ #include <memory>
31
+ #include <string>
32
+ #include <vector>
33
+ #include <cassert>
34
+
35
+ extern "C" {
36
+ #include <libheif/heif.h>
37
+ }
38
+
39
+
40
+ namespace heif {
41
+
42
+ class Error
43
+ {
44
+ public:
45
+ Error()
46
+ {
47
+ m_code = heif_error_Ok;
48
+ m_subcode = heif_suberror_Unspecified;
49
+ m_message = "Ok";
50
+ }
51
+
52
+ Error(const heif_error& err)
53
+ {
54
+ assert(err.message);
55
+
56
+ m_code = err.code;
57
+ m_subcode = err.subcode;
58
+ m_message = err.message;
59
+ }
60
+
61
+ Error(heif_error_code code, heif_suberror_code subcode, const std::string& msg)
62
+ {
63
+ m_code = code;
64
+ m_subcode = subcode;
65
+ m_message = msg;
66
+ }
67
+
68
+ const std::string& get_message() const
69
+ { return m_message; }
70
+
71
+ heif_error_code get_code() const
72
+ { return m_code; }
73
+
74
+ heif_suberror_code get_subcode() const
75
+ { return m_subcode; }
76
+
77
+ operator bool() const
78
+ { return m_code != heif_error_Ok; }
79
+
80
+ private:
81
+ heif_error_code m_code;
82
+ heif_suberror_code m_subcode;
83
+ std::string m_message;
84
+ };
85
+
86
+
87
+ class ImageHandle;
88
+
89
+ class Image;
90
+
91
+ class Encoder;
92
+
93
+ class EncoderParameter;
94
+
95
+ class EncoderDescriptor;
96
+
97
+
98
+ class Context
99
+ {
100
+ public:
101
+ Context();
102
+
103
+ class ReadingOptions
104
+ {
105
+ };
106
+
107
+ // throws Error
108
+ void read_from_file(const std::string& filename, const ReadingOptions& opts = ReadingOptions());
109
+
110
+ // DEPRECATED. Use read_from_memory_without_copy() instead.
111
+ // throws Error
112
+ void read_from_memory(const void* mem, size_t size, const ReadingOptions& opts = ReadingOptions());
113
+
114
+ // throws Error
115
+ void read_from_memory_without_copy(const void* mem, size_t size, const ReadingOptions& opts = ReadingOptions());
116
+
117
+ class Reader
118
+ {
119
+ public:
120
+ virtual ~Reader() = default;
121
+
122
+ virtual int64_t get_position() const = 0;
123
+
124
+ virtual int read(void* data, size_t size) = 0;
125
+
126
+ virtual int seek(int64_t position) = 0;
127
+
128
+ virtual heif_reader_grow_status wait_for_file_size(int64_t target_size) = 0;
129
+ };
130
+
131
+ // throws Error
132
+ void read_from_reader(Reader&, const ReadingOptions& opts = ReadingOptions());
133
+
134
+ int get_number_of_top_level_images() const noexcept;
135
+
136
+ bool is_top_level_image_ID(heif_item_id id) const noexcept;
137
+
138
+ std::vector<heif_item_id> get_list_of_top_level_image_IDs() const noexcept;
139
+
140
+ // throws Error
141
+ heif_item_id get_primary_image_ID() const;
142
+
143
+ // throws Error
144
+ ImageHandle get_primary_image_handle() const;
145
+
146
+ ImageHandle get_image_handle(heif_item_id id) const;
147
+
148
+
149
+ class EncodingOptions : public heif_encoding_options
150
+ {
151
+ public:
152
+ EncodingOptions();
153
+ };
154
+
155
+ // throws Error
156
+ ImageHandle encode_image(const Image& img, Encoder& encoder,
157
+ const EncodingOptions& options = EncodingOptions());
158
+
159
+ // throws Error
160
+ void set_primary_image(ImageHandle& new_primary_image_handle);
161
+
162
+ // throws Error
163
+ ImageHandle encode_thumbnail(const Image& image,
164
+ const ImageHandle& master_image,
165
+ Encoder& encoder,
166
+ const EncodingOptions&,
167
+ int bbox_size);
168
+
169
+ // throws Error
170
+ void assign_thumbnail(const ImageHandle& thumbnail_image,
171
+ const ImageHandle& master_image);
172
+
173
+ // throws Error
174
+ void add_exif_metadata(const ImageHandle& master_image,
175
+ const void* data, int size);
176
+
177
+ // throws Error
178
+ void add_XMP_metadata(const ImageHandle& master_image,
179
+ const void* data, int size);
180
+
181
+ class Writer
182
+ {
183
+ public:
184
+ virtual ~Writer() = default;
185
+
186
+ virtual heif_error write(const void* data, size_t size) = 0;
187
+ };
188
+
189
+ // throws Error
190
+ void write(Writer&);
191
+
192
+ // throws Error
193
+ void write_to_file(const std::string& filename) const;
194
+
195
+ private:
196
+ std::shared_ptr<heif_context> m_context;
197
+
198
+ friend struct ::heif_error heif_writer_trampoline_write(struct heif_context* ctx,
199
+ const void* data,
200
+ size_t size,
201
+ void* userdata);
202
+
203
+ //static Context wrap_without_releasing(heif_context*); // internal use in friend function only
204
+ };
205
+
206
+
207
+ class ImageHandle
208
+ {
209
+ public:
210
+ ImageHandle() = default;
211
+
212
+ ImageHandle(heif_image_handle* handle);
213
+
214
+ bool empty() const noexcept
215
+ { return !m_image_handle; }
216
+
217
+ bool is_primary_image() const noexcept;
218
+
219
+ int get_width() const noexcept;
220
+
221
+ int get_height() const noexcept;
222
+
223
+ bool has_alpha_channel() const noexcept;
224
+
225
+ bool is_premultiplied_alpha() const noexcept;
226
+
227
+ int get_luma_bits_per_pixel() const noexcept;
228
+
229
+ int get_chroma_bits_per_pixel() const noexcept;
230
+
231
+ int get_ispe_width() const noexcept;
232
+
233
+ int get_ispe_height() const noexcept;
234
+
235
+ // ------------------------- depth images -------------------------
236
+
237
+ // TODO
238
+
239
+ // ------------------------- thumbnails -------------------------
240
+
241
+ int get_number_of_thumbnails() const noexcept;
242
+
243
+ std::vector<heif_item_id> get_list_of_thumbnail_IDs() const noexcept;
244
+
245
+ // throws Error
246
+ ImageHandle get_thumbnail(heif_item_id id);
247
+
248
+ // ------------------------- metadata (Exif / XMP) -------------------------
249
+
250
+ // Can optionally be filtered by type ("Exif" / "XMP")
251
+ std::vector<heif_item_id> get_list_of_metadata_block_IDs(const char* type_filter = nullptr) const noexcept;
252
+
253
+ std::string get_metadata_type(heif_item_id metadata_id) const noexcept;
254
+
255
+ std::string get_metadata_content_type(heif_item_id metadata_id) const noexcept;
256
+
257
+ // throws error
258
+ std::vector<uint8_t> get_metadata(heif_item_id) const;
259
+
260
+
261
+ class DecodingOptions
262
+ {
263
+ };
264
+
265
+ // throws Error
266
+ Image decode_image(heif_colorspace colorspace, heif_chroma chroma,
267
+ const DecodingOptions& options = DecodingOptions());
268
+
269
+
270
+ heif_image_handle* get_raw_image_handle() noexcept
271
+ { return m_image_handle.get(); }
272
+
273
+ const heif_image_handle* get_raw_image_handle() const noexcept
274
+ { return m_image_handle.get(); }
275
+
276
+ private:
277
+ std::shared_ptr<heif_image_handle> m_image_handle;
278
+ };
279
+
280
+
281
+ class ColorProfile_nclx
282
+ {
283
+ public:
284
+ ColorProfile_nclx();
285
+
286
+ ~ColorProfile_nclx() = default;
287
+
288
+ heif_color_primaries get_color_primaries() const;
289
+
290
+ heif_transfer_characteristics get_transfer_characteristics() const;
291
+
292
+ heif_matrix_coefficients get_matrix_coefficients() const;
293
+
294
+ bool is_full_range() const;
295
+
296
+ void set_color_primaries(heif_color_primaries cp);
297
+
298
+ // DEPRECATED: typo in function name. Use set_color_primaries() instead.
299
+ void set_color_primaties(heif_color_primaries cp);
300
+
301
+ void set_transfer_characteristics(heif_transfer_characteristics tc);
302
+
303
+ void set_matrix_coefficients(heif_matrix_coefficients mc);
304
+
305
+ void set_full_range_flag(bool is_full_range);
306
+
307
+ private:
308
+ ColorProfile_nclx(heif_color_profile_nclx* nclx);
309
+
310
+ std::shared_ptr<heif_color_profile_nclx> mProfile;
311
+
312
+ friend class Image;
313
+ };
314
+
315
+
316
+ class Image
317
+ {
318
+ public:
319
+ Image() = default;
320
+
321
+ Image(heif_image* image);
322
+
323
+
324
+ // throws Error
325
+ void create(int width, int height,
326
+ enum heif_colorspace colorspace,
327
+ enum heif_chroma chroma);
328
+
329
+ // throws Error
330
+ void add_plane(enum heif_channel channel,
331
+ int width, int height, int bit_depth);
332
+
333
+ heif_colorspace get_colorspace() const noexcept;
334
+
335
+ heif_chroma get_chroma_format() const noexcept;
336
+
337
+ int get_width(enum heif_channel channel) const noexcept;
338
+
339
+ int get_height(enum heif_channel channel) const noexcept;
340
+
341
+ int get_bits_per_pixel(enum heif_channel channel) const noexcept;
342
+
343
+ int get_bits_per_pixel_range(enum heif_channel channel) const noexcept;
344
+
345
+ bool has_channel(enum heif_channel channel) const noexcept;
346
+
347
+ // DEPRECATED
348
+ const uint8_t* get_plane(enum heif_channel channel, int* out_stride) const noexcept;
349
+
350
+ // DEPRECATED
351
+ uint8_t* get_plane(enum heif_channel channel, int* out_stride) noexcept;
352
+
353
+ const uint8_t* get_plane2(enum heif_channel channel, size_t* out_stride) const noexcept;
354
+
355
+ uint8_t* get_plane2(enum heif_channel channel, size_t* out_stride) noexcept;
356
+
357
+ // throws Error
358
+ void set_nclx_color_profile(const ColorProfile_nclx&);
359
+
360
+ // throws Error
361
+ ColorProfile_nclx get_nclx_color_profile() const;
362
+
363
+ heif_color_profile_type get_color_profile_type() const;
364
+
365
+ // throws Error
366
+ std::vector<uint8_t> get_raw_color_profile() const;
367
+
368
+ void set_raw_color_profile(heif_color_profile_type type,
369
+ const std::vector<uint8_t>& data);
370
+
371
+ bool is_premultiplied_alpha() const noexcept;
372
+
373
+ void set_premultiplied_alpha(bool is_premultiplied_alpha) noexcept;
374
+
375
+ class ScalingOptions
376
+ {
377
+ };
378
+
379
+ // throws Error
380
+ Image scale_image(int width, int height,
381
+ const ScalingOptions& options = ScalingOptions()) const;
382
+
383
+ private:
384
+ std::shared_ptr<heif_image> m_image;
385
+
386
+ friend class Context;
387
+ };
388
+
389
+
390
+ class EncoderDescriptor
391
+ {
392
+ public:
393
+ static std::vector<EncoderDescriptor>
394
+ get_encoder_descriptors(enum heif_compression_format format_filter,
395
+ const char* name_filter) noexcept;
396
+
397
+ std::string get_name() const noexcept;
398
+
399
+ std::string get_id_name() const noexcept;
400
+
401
+ enum heif_compression_format get_compression_format() const noexcept;
402
+
403
+ // DEPRECATED: typo in function name
404
+ bool supportes_lossy_compression() const noexcept;
405
+
406
+ // DEPRECATED: typo in function name
407
+ bool supportes_lossless_compression() const noexcept;
408
+
409
+
410
+ // throws Error
411
+ Encoder get_encoder() const;
412
+
413
+ bool supports_lossy_compression() const noexcept;
414
+
415
+ bool supports_lossless_compression() const noexcept;
416
+
417
+ private:
418
+ EncoderDescriptor(const struct heif_encoder_descriptor* descr) : m_descriptor(descr)
419
+ {}
420
+
421
+ const struct heif_encoder_descriptor* m_descriptor = nullptr;
422
+ };
423
+
424
+
425
+ class EncoderParameter
426
+ {
427
+ public:
428
+ std::string get_name() const noexcept;
429
+
430
+ enum heif_encoder_parameter_type get_type() const noexcept;
431
+
432
+ bool is_integer() const noexcept;
433
+
434
+ // Returns 'true' if the integer range is limited.
435
+ bool get_valid_integer_range(int& out_minimum, int& out_maximum);
436
+
437
+ bool is_boolean() const noexcept;
438
+
439
+ bool is_string() const noexcept;
440
+
441
+ std::vector<std::string> get_valid_string_values() const;
442
+
443
+ private:
444
+ EncoderParameter(const heif_encoder_parameter*);
445
+
446
+ const struct heif_encoder_parameter* m_parameter;
447
+
448
+ friend class Encoder;
449
+ };
450
+
451
+
452
+ class Encoder
453
+ {
454
+ public:
455
+ // throws Error
456
+ Encoder(enum heif_compression_format format);
457
+
458
+ // throws Error
459
+ void set_lossy_quality(int quality);
460
+
461
+ // throws Error
462
+ void set_lossless(bool enable_lossless);
463
+
464
+ std::vector<EncoderParameter> list_parameters() const noexcept;
465
+
466
+ void set_integer_parameter(const std::string& parameter_name, int value);
467
+
468
+ int get_integer_parameter(const std::string& parameter_name) const;
469
+
470
+ void set_boolean_parameter(const std::string& parameter_name, bool value);
471
+
472
+ bool get_boolean_parameter(const std::string& parameter_name) const;
473
+
474
+ void set_string_parameter(const std::string& parameter_name, const std::string& value);
475
+
476
+ std::string get_string_parameter(const std::string& parameter_name) const;
477
+
478
+ void set_parameter(const std::string& parameter_name, const std::string& parameter_value);
479
+
480
+ std::string get_parameter(const std::string& parameter_name) const;
481
+
482
+ private:
483
+ Encoder(struct heif_encoder*) noexcept;
484
+
485
+ std::shared_ptr<heif_encoder> m_encoder;
486
+
487
+ friend class EncoderDescriptor;
488
+
489
+ friend class Context;
490
+ };
491
+
492
+
493
+ // ==========================================================================================
494
+ // IMPLEMENTATION
495
+ // ==========================================================================================
496
+
497
+ inline Context::Context()
498
+ {
499
+ heif_context* ctx = heif_context_alloc();
500
+ m_context = std::shared_ptr<heif_context>(ctx,
501
+ [](heif_context* c) { heif_context_free(c); });
502
+ }
503
+
504
+ inline void Context::read_from_file(const std::string& filename, const ReadingOptions& /*opts*/)
505
+ {
506
+ Error err = Error(heif_context_read_from_file(m_context.get(), filename.c_str(), NULL));
507
+ if (err) {
508
+ throw err;
509
+ }
510
+ }
511
+
512
+ inline void Context::read_from_memory(const void* mem, size_t size, const ReadingOptions& /*opts*/)
513
+ {
514
+ Error err = Error(heif_context_read_from_memory(m_context.get(), mem, size, NULL));
515
+ if (err) {
516
+ throw err;
517
+ }
518
+ }
519
+
520
+ inline void Context::read_from_memory_without_copy(const void* mem, size_t size, const ReadingOptions& /*opts*/)
521
+ {
522
+ Error err = Error(heif_context_read_from_memory_without_copy(m_context.get(), mem, size, NULL));
523
+ if (err) {
524
+ throw err;
525
+ }
526
+ }
527
+
528
+
529
+ inline int64_t heif_reader_trampoline_get_position(void* userdata)
530
+ {
531
+ Context::Reader* reader = (Context::Reader*) userdata;
532
+ return reader->get_position();
533
+ }
534
+
535
+ inline int heif_reader_trampoline_read(void* data, size_t size, void* userdata)
536
+ {
537
+ Context::Reader* reader = (Context::Reader*) userdata;
538
+ return reader->read(data, size);
539
+ }
540
+
541
+ inline int heif_reader_trampoline_seek(int64_t position, void* userdata)
542
+ {
543
+ Context::Reader* reader = (Context::Reader*) userdata;
544
+ return reader->seek(position);
545
+ }
546
+
547
+ inline heif_reader_grow_status heif_reader_trampoline_wait_for_file_size(int64_t target_size, void* userdata)
548
+ {
549
+ Context::Reader* reader = (Context::Reader*) userdata;
550
+ return reader->wait_for_file_size(target_size);
551
+ }
552
+
553
+
554
+ static struct heif_reader heif_reader_trampoline =
555
+ {
556
+ 1,
557
+ heif_reader_trampoline_get_position,
558
+ heif_reader_trampoline_read,
559
+ heif_reader_trampoline_seek,
560
+ heif_reader_trampoline_wait_for_file_size,
561
+ NULL,
562
+ NULL,
563
+ NULL,
564
+ NULL,
565
+ };
566
+
567
+ inline void Context::read_from_reader(Reader& reader, const ReadingOptions& /*opts*/)
568
+ {
569
+ Error err = Error(heif_context_read_from_reader(m_context.get(), &heif_reader_trampoline,
570
+ &reader, NULL));
571
+ if (err) {
572
+ throw err;
573
+ }
574
+ }
575
+
576
+
577
+ inline int Context::get_number_of_top_level_images() const noexcept
578
+ {
579
+ return heif_context_get_number_of_top_level_images(m_context.get());
580
+ }
581
+
582
+ inline bool Context::is_top_level_image_ID(heif_item_id id) const noexcept
583
+ {
584
+ return heif_context_is_top_level_image_ID(m_context.get(), id);
585
+ }
586
+
587
+ inline std::vector<heif_item_id> Context::get_list_of_top_level_image_IDs() const noexcept
588
+ {
589
+ int num = get_number_of_top_level_images();
590
+ std::vector<heif_item_id> IDs(num);
591
+ heif_context_get_list_of_top_level_image_IDs(m_context.get(), IDs.data(), num);
592
+ return IDs;
593
+ }
594
+
595
+ inline heif_item_id Context::get_primary_image_ID() const
596
+ {
597
+ heif_item_id id;
598
+ Error err = Error(heif_context_get_primary_image_ID(m_context.get(), &id));
599
+ if (err) {
600
+ throw err;
601
+ }
602
+ return id;
603
+ }
604
+
605
+ inline ImageHandle Context::get_primary_image_handle() const
606
+ {
607
+ heif_image_handle* handle;
608
+ Error err = Error(heif_context_get_primary_image_handle(m_context.get(), &handle));
609
+ if (err) {
610
+ throw err;
611
+ }
612
+
613
+ return ImageHandle(handle);
614
+ }
615
+
616
+ inline ImageHandle Context::get_image_handle(heif_item_id id) const
617
+ {
618
+ struct heif_image_handle* handle;
619
+ Error err = Error(heif_context_get_image_handle(m_context.get(), id, &handle));
620
+ if (err) {
621
+ throw err;
622
+ }
623
+ return ImageHandle(handle);
624
+ }
625
+
626
+ #if 0
627
+ inline Context Context::wrap_without_releasing(heif_context* ctx) {
628
+ Context context;
629
+ context.m_context = std::shared_ptr<heif_context>(ctx,
630
+ [] (heif_context*) { /* NOP */ });
631
+ return context;
632
+ }
633
+ #endif
634
+
635
+ inline struct ::heif_error heif_writer_trampoline_write(struct heif_context* ctx,
636
+ const void* data,
637
+ size_t size,
638
+ void* userdata)
639
+ {
640
+ Context::Writer* writer = (Context::Writer*) userdata;
641
+
642
+ (void) ctx;
643
+
644
+ //Context context = Context::wrap_without_releasing(ctx);
645
+ //return writer->write(context, data, size);
646
+ return writer->write(data, size);
647
+ }
648
+
649
+ static struct heif_writer heif_writer_trampoline =
650
+ {
651
+ 1,
652
+ &heif_writer_trampoline_write
653
+ };
654
+
655
+ inline void Context::write(Writer& writer)
656
+ {
657
+ Error err = Error(heif_context_write(m_context.get(), &heif_writer_trampoline, &writer));
658
+ if (err) {
659
+ throw err;
660
+ }
661
+ }
662
+
663
+ inline void Context::write_to_file(const std::string& filename) const
664
+ {
665
+ Error err = Error(heif_context_write_to_file(m_context.get(), filename.c_str()));
666
+ if (err) {
667
+ throw err;
668
+ }
669
+ }
670
+
671
+
672
+ inline ImageHandle::ImageHandle(heif_image_handle* handle)
673
+ {
674
+ if (handle != nullptr) {
675
+ m_image_handle = std::shared_ptr<heif_image_handle>(handle,
676
+ [](heif_image_handle* h) { heif_image_handle_release(h); });
677
+ }
678
+ }
679
+
680
+ inline bool ImageHandle::is_primary_image() const noexcept
681
+ {
682
+ return heif_image_handle_is_primary_image(m_image_handle.get()) != 0;
683
+ }
684
+
685
+ inline int ImageHandle::get_width() const noexcept
686
+ {
687
+ return heif_image_handle_get_width(m_image_handle.get());
688
+ }
689
+
690
+ inline int ImageHandle::get_height() const noexcept
691
+ {
692
+ return heif_image_handle_get_height(m_image_handle.get());
693
+ }
694
+
695
+ inline bool ImageHandle::has_alpha_channel() const noexcept
696
+ {
697
+ return heif_image_handle_has_alpha_channel(m_image_handle.get()) != 0;
698
+ }
699
+
700
+ inline bool ImageHandle::is_premultiplied_alpha() const noexcept
701
+ {
702
+ return heif_image_handle_is_premultiplied_alpha(m_image_handle.get()) != 0;
703
+ }
704
+
705
+ inline int ImageHandle::get_luma_bits_per_pixel() const noexcept
706
+ {
707
+ return heif_image_handle_get_luma_bits_per_pixel(m_image_handle.get());
708
+ }
709
+
710
+ inline int ImageHandle::get_chroma_bits_per_pixel() const noexcept
711
+ {
712
+ return heif_image_handle_get_chroma_bits_per_pixel(m_image_handle.get());
713
+ }
714
+
715
+ inline int ImageHandle::get_ispe_width() const noexcept
716
+ {
717
+ return heif_image_handle_get_ispe_width(m_image_handle.get());
718
+ }
719
+
720
+ inline int ImageHandle::get_ispe_height() const noexcept
721
+ {
722
+ return heif_image_handle_get_ispe_height(m_image_handle.get());
723
+ }
724
+
725
+ // ------------------------- depth images -------------------------
726
+
727
+ // TODO
728
+
729
+ // ------------------------- thumbnails -------------------------
730
+
731
+ inline int ImageHandle::get_number_of_thumbnails() const noexcept
732
+ {
733
+ return heif_image_handle_get_number_of_thumbnails(m_image_handle.get());
734
+ }
735
+
736
+ inline std::vector<heif_item_id> ImageHandle::get_list_of_thumbnail_IDs() const noexcept
737
+ {
738
+ int num = get_number_of_thumbnails();
739
+ std::vector<heif_item_id> IDs(num);
740
+ heif_image_handle_get_list_of_thumbnail_IDs(m_image_handle.get(), IDs.data(), num);
741
+ return IDs;
742
+ }
743
+
744
+ inline ImageHandle ImageHandle::get_thumbnail(heif_item_id id)
745
+ {
746
+ heif_image_handle* handle;
747
+ Error err = Error(heif_image_handle_get_thumbnail(m_image_handle.get(), id, &handle));
748
+ if (err) {
749
+ throw err;
750
+ }
751
+
752
+ return ImageHandle(handle);
753
+ }
754
+
755
+ inline Image ImageHandle::decode_image(heif_colorspace colorspace, heif_chroma chroma,
756
+ const DecodingOptions& /*options*/)
757
+ {
758
+ heif_image* out_img;
759
+ Error err = Error(heif_decode_image(m_image_handle.get(),
760
+ &out_img,
761
+ colorspace,
762
+ chroma,
763
+ nullptr)); //const struct heif_decoding_options* options);
764
+ if (err) {
765
+ throw err;
766
+ }
767
+
768
+ return Image(out_img);
769
+ }
770
+
771
+
772
+ inline std::vector<heif_item_id> ImageHandle::get_list_of_metadata_block_IDs(const char* type_filter) const noexcept
773
+ {
774
+ int nBlocks = heif_image_handle_get_number_of_metadata_blocks(m_image_handle.get(),
775
+ type_filter);
776
+ std::vector<heif_item_id> ids(nBlocks);
777
+ int n = heif_image_handle_get_list_of_metadata_block_IDs(m_image_handle.get(),
778
+ type_filter,
779
+ ids.data(), nBlocks);
780
+ (void) n;
781
+ //assert(n==nBlocks);
782
+ return ids;
783
+ }
784
+
785
+ inline std::string ImageHandle::get_metadata_type(heif_item_id metadata_id) const noexcept
786
+ {
787
+ return heif_image_handle_get_metadata_type(m_image_handle.get(), metadata_id);
788
+ }
789
+
790
+ inline std::string ImageHandle::get_metadata_content_type(heif_item_id metadata_id) const noexcept
791
+ {
792
+ return heif_image_handle_get_metadata_content_type(m_image_handle.get(), metadata_id);
793
+ }
794
+
795
+ inline std::vector<uint8_t> ImageHandle::get_metadata(heif_item_id metadata_id) const
796
+ {
797
+ size_t data_size = heif_image_handle_get_metadata_size(m_image_handle.get(),
798
+ metadata_id);
799
+
800
+ std::vector<uint8_t> data(data_size);
801
+
802
+ Error err = Error(heif_image_handle_get_metadata(m_image_handle.get(),
803
+ metadata_id,
804
+ data.data()));
805
+ if (err) {
806
+ throw err;
807
+ }
808
+
809
+ return data;
810
+ }
811
+
812
+
813
+ inline ColorProfile_nclx::ColorProfile_nclx()
814
+ {
815
+ auto profile = heif_nclx_color_profile_alloc();
816
+ mProfile = std::shared_ptr<heif_color_profile_nclx>(profile,
817
+ [](heif_color_profile_nclx* p) { heif_nclx_color_profile_free(p); });
818
+ }
819
+
820
+ inline ColorProfile_nclx::ColorProfile_nclx(heif_color_profile_nclx* nclx)
821
+ {
822
+ mProfile = std::shared_ptr<heif_color_profile_nclx>(nclx,
823
+ [](heif_color_profile_nclx* p) { heif_nclx_color_profile_free(p); });
824
+ }
825
+
826
+ inline heif_color_primaries ColorProfile_nclx::get_color_primaries() const
827
+ { return mProfile->color_primaries; }
828
+
829
+ inline heif_transfer_characteristics ColorProfile_nclx::get_transfer_characteristics() const
830
+ { return mProfile->transfer_characteristics; }
831
+
832
+ inline heif_matrix_coefficients ColorProfile_nclx::get_matrix_coefficients() const
833
+ { return mProfile->matrix_coefficients; }
834
+
835
+ inline bool ColorProfile_nclx::is_full_range() const
836
+ { return mProfile->full_range_flag; }
837
+
838
+ inline void ColorProfile_nclx::set_color_primaries(heif_color_primaries cp)
839
+ { mProfile->color_primaries = cp; }
840
+
841
+ inline void ColorProfile_nclx::set_color_primaties(heif_color_primaries cp)
842
+ { set_color_primaries(cp); }
843
+
844
+ inline void ColorProfile_nclx::set_transfer_characteristics(heif_transfer_characteristics tc)
845
+ { mProfile->transfer_characteristics = tc; }
846
+
847
+ inline void ColorProfile_nclx::set_matrix_coefficients(heif_matrix_coefficients mc)
848
+ { mProfile->matrix_coefficients = mc; }
849
+
850
+ inline void ColorProfile_nclx::set_full_range_flag(bool is_full_range)
851
+ { mProfile->full_range_flag = is_full_range; }
852
+
853
+
854
+ inline Image::Image(heif_image* image)
855
+ {
856
+ m_image = std::shared_ptr<heif_image>(image,
857
+ [](heif_image* h) { heif_image_release(h); });
858
+ }
859
+
860
+
861
+ inline void Image::create(int width, int height,
862
+ enum heif_colorspace colorspace,
863
+ enum heif_chroma chroma)
864
+ {
865
+ heif_image* image;
866
+ Error err = Error(heif_image_create(width, height, colorspace, chroma, &image));
867
+ if (err) {
868
+ m_image.reset();
869
+ throw err;
870
+ }
871
+ else {
872
+ m_image = std::shared_ptr<heif_image>(image,
873
+ [](heif_image* h) { heif_image_release(h); });
874
+ }
875
+ }
876
+
877
+ inline void Image::add_plane(enum heif_channel channel,
878
+ int width, int height, int bit_depth)
879
+ {
880
+ Error err = Error(heif_image_add_plane(m_image.get(), channel, width, height, bit_depth));
881
+ if (err) {
882
+ throw err;
883
+ }
884
+ }
885
+
886
+ inline heif_colorspace Image::get_colorspace() const noexcept
887
+ {
888
+ return heif_image_get_colorspace(m_image.get());
889
+ }
890
+
891
+ inline heif_chroma Image::get_chroma_format() const noexcept
892
+ {
893
+ return heif_image_get_chroma_format(m_image.get());
894
+ }
895
+
896
+ inline int Image::get_width(enum heif_channel channel) const noexcept
897
+ {
898
+ return heif_image_get_width(m_image.get(), channel);
899
+ }
900
+
901
+ inline int Image::get_height(enum heif_channel channel) const noexcept
902
+ {
903
+ return heif_image_get_height(m_image.get(), channel);
904
+ }
905
+
906
+ inline int Image::get_bits_per_pixel(enum heif_channel channel) const noexcept
907
+ {
908
+ return heif_image_get_bits_per_pixel(m_image.get(), channel);
909
+ }
910
+
911
+ inline int Image::get_bits_per_pixel_range(enum heif_channel channel) const noexcept
912
+ {
913
+ return heif_image_get_bits_per_pixel_range(m_image.get(), channel);
914
+ }
915
+
916
+ inline bool Image::has_channel(enum heif_channel channel) const noexcept
917
+ {
918
+ return heif_image_has_channel(m_image.get(), channel);
919
+ }
920
+
921
+ inline const uint8_t* Image::get_plane(enum heif_channel channel, int* out_stride) const noexcept
922
+ {
923
+ return heif_image_get_plane_readonly(m_image.get(), channel, out_stride);
924
+ }
925
+
926
+ inline uint8_t* Image::get_plane(enum heif_channel channel, int* out_stride) noexcept
927
+ {
928
+ return heif_image_get_plane(m_image.get(), channel, out_stride);
929
+ }
930
+
931
+ inline const uint8_t* Image::get_plane2(enum heif_channel channel, size_t* out_stride) const noexcept
932
+ {
933
+ return heif_image_get_plane_readonly2(m_image.get(), channel, out_stride);
934
+ }
935
+
936
+ inline uint8_t* Image::get_plane2(enum heif_channel channel, size_t* out_stride) noexcept
937
+ {
938
+ return heif_image_get_plane2(m_image.get(), channel, out_stride);
939
+ }
940
+
941
+ inline void Image::set_nclx_color_profile(const ColorProfile_nclx& nclx)
942
+ {
943
+ Error err = Error(heif_image_set_nclx_color_profile(m_image.get(), nclx.mProfile.get()));
944
+ if (err) {
945
+ throw err;
946
+ }
947
+ }
948
+
949
+ // throws Error
950
+ inline ColorProfile_nclx Image::get_nclx_color_profile() const
951
+ {
952
+ heif_color_profile_nclx* nclx = nullptr;
953
+ Error err = Error(heif_image_get_nclx_color_profile(m_image.get(), &nclx));
954
+ if (err) {
955
+ throw err;
956
+ }
957
+
958
+ return ColorProfile_nclx(nclx);
959
+ }
960
+
961
+
962
+ inline heif_color_profile_type Image::get_color_profile_type() const
963
+ {
964
+ return heif_image_get_color_profile_type(m_image.get());
965
+ }
966
+
967
+ // throws Error
968
+ inline std::vector<uint8_t> Image::get_raw_color_profile() const
969
+ {
970
+ auto size = heif_image_get_raw_color_profile_size(m_image.get());
971
+ std::vector<uint8_t> profile(size);
972
+ heif_image_get_raw_color_profile(m_image.get(), profile.data());
973
+ return profile;
974
+ }
975
+
976
+ inline void Image::set_raw_color_profile(heif_color_profile_type type,
977
+ const std::vector<uint8_t>& data)
978
+ {
979
+ const char* profile_type = nullptr;
980
+ switch (type) {
981
+ case heif_color_profile_type_prof:
982
+ profile_type = "prof";
983
+ break;
984
+ case heif_color_profile_type_rICC:
985
+ profile_type = "rICC";
986
+ break;
987
+ default:
988
+ throw Error(heif_error_code::heif_error_Usage_error,
989
+ heif_suberror_Unspecified,
990
+ "invalid raw color profile type");
991
+ break;
992
+ }
993
+
994
+ Error err = Error(heif_image_set_raw_color_profile(m_image.get(), profile_type,
995
+ data.data(), data.size()));
996
+ if (err) {
997
+ throw err;
998
+ }
999
+ }
1000
+
1001
+ inline bool Image::is_premultiplied_alpha() const noexcept
1002
+ {
1003
+ return heif_image_is_premultiplied_alpha(m_image.get()) != 0;
1004
+ }
1005
+
1006
+ inline void Image::set_premultiplied_alpha(bool is_premultiplied_alpha) noexcept
1007
+ {
1008
+ heif_image_set_premultiplied_alpha(m_image.get(), is_premultiplied_alpha);
1009
+ }
1010
+
1011
+ inline Image Image::scale_image(int width, int height,
1012
+ const ScalingOptions&) const
1013
+ {
1014
+ heif_image* img;
1015
+ Error err = Error(heif_image_scale_image(m_image.get(), &img, width, height,
1016
+ nullptr)); // TODO: scaling options not defined yet
1017
+ if (err) {
1018
+ throw err;
1019
+ }
1020
+
1021
+ return Image(img);
1022
+ }
1023
+
1024
+
1025
+ inline std::vector<EncoderDescriptor>
1026
+ EncoderDescriptor::get_encoder_descriptors(enum heif_compression_format format_filter,
1027
+ const char* name_filter) noexcept
1028
+ {
1029
+ int maxDescriptors = 10;
1030
+ int nDescriptors;
1031
+ for (;;) {
1032
+ const struct heif_encoder_descriptor** descriptors;
1033
+ descriptors = new const heif_encoder_descriptor* [maxDescriptors];
1034
+
1035
+ nDescriptors = heif_context_get_encoder_descriptors(nullptr,
1036
+ format_filter,
1037
+ name_filter,
1038
+ descriptors,
1039
+ maxDescriptors);
1040
+ if (nDescriptors < maxDescriptors) {
1041
+ std::vector<EncoderDescriptor> outDescriptors;
1042
+ outDescriptors.reserve(nDescriptors);
1043
+ for (int i = 0; i < nDescriptors; i++) {
1044
+ outDescriptors.push_back(EncoderDescriptor(descriptors[i]));
1045
+ }
1046
+
1047
+ delete[] descriptors;
1048
+
1049
+ return outDescriptors;
1050
+ }
1051
+ else {
1052
+ delete[] descriptors;
1053
+ maxDescriptors *= 2;
1054
+ }
1055
+ }
1056
+ }
1057
+
1058
+
1059
+ inline std::string EncoderDescriptor::get_name() const noexcept
1060
+ {
1061
+ return heif_encoder_descriptor_get_name(m_descriptor);
1062
+ }
1063
+
1064
+ inline std::string EncoderDescriptor::get_id_name() const noexcept
1065
+ {
1066
+ return heif_encoder_descriptor_get_id_name(m_descriptor);
1067
+ }
1068
+
1069
+ inline enum heif_compression_format EncoderDescriptor::get_compression_format() const noexcept
1070
+ {
1071
+ return heif_encoder_descriptor_get_compression_format(m_descriptor);
1072
+ }
1073
+
1074
+ inline bool EncoderDescriptor::supportes_lossy_compression() const noexcept
1075
+ {
1076
+ return heif_encoder_descriptor_supports_lossy_compression(m_descriptor);
1077
+ }
1078
+
1079
+ inline bool EncoderDescriptor::supports_lossy_compression() const noexcept
1080
+ {
1081
+ return heif_encoder_descriptor_supports_lossy_compression(m_descriptor);
1082
+ }
1083
+
1084
+ inline bool EncoderDescriptor::supportes_lossless_compression() const noexcept
1085
+ {
1086
+ return heif_encoder_descriptor_supports_lossless_compression(m_descriptor);
1087
+ }
1088
+
1089
+ inline bool EncoderDescriptor::supports_lossless_compression() const noexcept
1090
+ {
1091
+ return heif_encoder_descriptor_supports_lossless_compression(m_descriptor);
1092
+ }
1093
+
1094
+ inline Encoder EncoderDescriptor::get_encoder() const
1095
+ {
1096
+ heif_encoder* encoder;
1097
+ Error err = Error(heif_context_get_encoder(nullptr, m_descriptor, &encoder));
1098
+ if (err) {
1099
+ throw err;
1100
+ }
1101
+
1102
+ return Encoder(encoder);
1103
+ }
1104
+
1105
+
1106
+ inline Encoder::Encoder(enum heif_compression_format format)
1107
+ {
1108
+ heif_encoder* encoder;
1109
+ Error err = Error(heif_context_get_encoder_for_format(nullptr, format, &encoder));
1110
+ if (err) {
1111
+ throw err;
1112
+ }
1113
+
1114
+ m_encoder = std::shared_ptr<heif_encoder>(encoder,
1115
+ [](heif_encoder* e) { heif_encoder_release(e); });
1116
+ }
1117
+
1118
+ inline Encoder::Encoder(struct heif_encoder* encoder) noexcept
1119
+ {
1120
+ m_encoder = std::shared_ptr<heif_encoder>(encoder,
1121
+ [](heif_encoder* e) { heif_encoder_release(e); });
1122
+ }
1123
+
1124
+
1125
+ inline EncoderParameter::EncoderParameter(const heif_encoder_parameter* param)
1126
+ : m_parameter(param)
1127
+ {
1128
+ }
1129
+
1130
+ inline std::string EncoderParameter::get_name() const noexcept
1131
+ {
1132
+ return heif_encoder_parameter_get_name(m_parameter);
1133
+ }
1134
+
1135
+ inline enum heif_encoder_parameter_type EncoderParameter::get_type() const noexcept
1136
+ {
1137
+ return heif_encoder_parameter_get_type(m_parameter);
1138
+ }
1139
+
1140
+ inline bool EncoderParameter::is_integer() const noexcept
1141
+ {
1142
+ return get_type() == heif_encoder_parameter_type_integer;
1143
+ }
1144
+
1145
+ inline bool EncoderParameter::get_valid_integer_range(int& out_minimum, int& out_maximum)
1146
+ {
1147
+ int have_minimum_maximum;
1148
+ Error err = Error(heif_encoder_parameter_get_valid_integer_range(m_parameter,
1149
+ &have_minimum_maximum,
1150
+ &out_minimum, &out_maximum));
1151
+ if (err) {
1152
+ throw err;
1153
+ }
1154
+
1155
+ return have_minimum_maximum;
1156
+ }
1157
+
1158
+ inline bool EncoderParameter::is_boolean() const noexcept
1159
+ {
1160
+ return get_type() == heif_encoder_parameter_type_boolean;
1161
+ }
1162
+
1163
+ inline bool EncoderParameter::is_string() const noexcept
1164
+ {
1165
+ return get_type() == heif_encoder_parameter_type_string;
1166
+ }
1167
+
1168
+ inline std::vector<std::string> EncoderParameter::get_valid_string_values() const
1169
+ {
1170
+ const char* const* stringarray;
1171
+ Error err = Error(heif_encoder_parameter_get_valid_string_values(m_parameter,
1172
+ &stringarray));
1173
+ if (err) {
1174
+ throw err;
1175
+ }
1176
+
1177
+ std::vector<std::string> values;
1178
+ for (int i = 0; stringarray[i]; i++) {
1179
+ values.push_back(stringarray[i]);
1180
+ }
1181
+
1182
+ return values;
1183
+ }
1184
+
1185
+ inline std::vector<EncoderParameter> Encoder::list_parameters() const noexcept
1186
+ {
1187
+ std::vector<EncoderParameter> parameters;
1188
+
1189
+ for (const struct heif_encoder_parameter* const* params = heif_encoder_list_parameters(m_encoder.get());
1190
+ *params;
1191
+ params++) {
1192
+ parameters.push_back(EncoderParameter(*params));
1193
+ }
1194
+
1195
+ return parameters;
1196
+ }
1197
+
1198
+
1199
+ inline void Encoder::set_lossy_quality(int quality)
1200
+ {
1201
+ Error err = Error(heif_encoder_set_lossy_quality(m_encoder.get(), quality));
1202
+ if (err) {
1203
+ throw err;
1204
+ }
1205
+ }
1206
+
1207
+ inline void Encoder::set_lossless(bool enable_lossless)
1208
+ {
1209
+ Error err = Error(heif_encoder_set_lossless(m_encoder.get(), enable_lossless));
1210
+ if (err) {
1211
+ throw err;
1212
+ }
1213
+ }
1214
+
1215
+ inline void Encoder::set_integer_parameter(const std::string& parameter_name, int value)
1216
+ {
1217
+ Error err = Error(heif_encoder_set_parameter_integer(m_encoder.get(), parameter_name.c_str(), value));
1218
+ if (err) {
1219
+ throw err;
1220
+ }
1221
+ }
1222
+
1223
+ inline int Encoder::get_integer_parameter(const std::string& parameter_name) const
1224
+ {
1225
+ int value;
1226
+ Error err = Error(heif_encoder_get_parameter_integer(m_encoder.get(), parameter_name.c_str(), &value));
1227
+ if (err) {
1228
+ throw err;
1229
+ }
1230
+ return value;
1231
+ }
1232
+
1233
+ inline void Encoder::set_boolean_parameter(const std::string& parameter_name, bool value)
1234
+ {
1235
+ Error err = Error(heif_encoder_set_parameter_boolean(m_encoder.get(), parameter_name.c_str(), value));
1236
+ if (err) {
1237
+ throw err;
1238
+ }
1239
+ }
1240
+
1241
+ inline bool Encoder::get_boolean_parameter(const std::string& parameter_name) const
1242
+ {
1243
+ int value;
1244
+ Error err = Error(heif_encoder_get_parameter_boolean(m_encoder.get(), parameter_name.c_str(), &value));
1245
+ if (err) {
1246
+ throw err;
1247
+ }
1248
+ return value;
1249
+ }
1250
+
1251
+ inline void Encoder::set_string_parameter(const std::string& parameter_name, const std::string& value)
1252
+ {
1253
+ Error err = Error(heif_encoder_set_parameter_string(m_encoder.get(), parameter_name.c_str(), value.c_str()));
1254
+ if (err) {
1255
+ throw err;
1256
+ }
1257
+ }
1258
+
1259
+ inline std::string Encoder::get_string_parameter(const std::string& parameter_name) const
1260
+ {
1261
+ const int max_size = 250;
1262
+ char value[max_size];
1263
+ Error err = Error(heif_encoder_get_parameter_string(m_encoder.get(), parameter_name.c_str(),
1264
+ value, max_size));
1265
+ if (err) {
1266
+ throw err;
1267
+ }
1268
+ return value;
1269
+ }
1270
+
1271
+ inline void Encoder::set_parameter(const std::string& parameter_name, const std::string& parameter_value)
1272
+ {
1273
+ Error err = Error(heif_encoder_set_parameter(m_encoder.get(), parameter_name.c_str(),
1274
+ parameter_value.c_str()));
1275
+ if (err) {
1276
+ throw err;
1277
+ }
1278
+ }
1279
+
1280
+ inline std::string Encoder::get_parameter(const std::string& parameter_name) const
1281
+ {
1282
+ const int max_size = 250;
1283
+ char value[max_size];
1284
+ Error err = Error(heif_encoder_get_parameter(m_encoder.get(), parameter_name.c_str(),
1285
+ value, max_size));
1286
+ if (err) {
1287
+ throw err;
1288
+ }
1289
+ return value;
1290
+ }
1291
+
1292
+ inline void Context::set_primary_image(ImageHandle& new_primary_image_handle)
1293
+ {
1294
+ Error err = Error(heif_context_set_primary_image(m_context.get(),
1295
+ new_primary_image_handle.get_raw_image_handle()));
1296
+ if (err) {
1297
+ throw err;
1298
+ }
1299
+ }
1300
+
1301
+
1302
+ inline Context::EncodingOptions::EncodingOptions()
1303
+ {
1304
+ // TODO: this is a bit hacky. It would be better to have an API function to set
1305
+ // the options to default values. But I do not see any reason for that apart from
1306
+ // this use-case.
1307
+
1308
+ struct heif_encoding_options* default_options = heif_encoding_options_alloc();
1309
+ *static_cast<heif_encoding_options*>(this) = *default_options; // copy over all options
1310
+ heif_encoding_options_free(default_options);
1311
+ }
1312
+
1313
+
1314
+ inline ImageHandle Context::encode_image(const Image& img, Encoder& encoder,
1315
+ const EncodingOptions& options)
1316
+ {
1317
+ struct heif_image_handle* image_handle;
1318
+
1319
+ Error err = Error(heif_context_encode_image(m_context.get(),
1320
+ img.m_image.get(),
1321
+ encoder.m_encoder.get(),
1322
+ &options,
1323
+ &image_handle));
1324
+ if (err) {
1325
+ throw err;
1326
+ }
1327
+
1328
+ return ImageHandle(image_handle);
1329
+ }
1330
+
1331
+
1332
+ inline ImageHandle Context::encode_thumbnail(const Image& image,
1333
+ const ImageHandle& master_image_handle,
1334
+ Encoder& encoder,
1335
+ const EncodingOptions& options,
1336
+ int bbox_size)
1337
+ {
1338
+ struct heif_image_handle* thumb_image_handle;
1339
+
1340
+ Error err = Error(heif_context_encode_thumbnail(m_context.get(),
1341
+ image.m_image.get(),
1342
+ master_image_handle.get_raw_image_handle(),
1343
+ encoder.m_encoder.get(),
1344
+ &options,
1345
+ bbox_size,
1346
+ &thumb_image_handle));
1347
+ if (err) {
1348
+ throw err;
1349
+ }
1350
+
1351
+ return ImageHandle(thumb_image_handle);
1352
+ }
1353
+
1354
+
1355
+ inline void Context::assign_thumbnail(const ImageHandle& thumbnail_image,
1356
+ const ImageHandle& master_image)
1357
+ {
1358
+ Error err = Error(heif_context_assign_thumbnail(m_context.get(),
1359
+ thumbnail_image.get_raw_image_handle(),
1360
+ master_image.get_raw_image_handle()));
1361
+ if (err) {
1362
+ throw err;
1363
+ }
1364
+ }
1365
+
1366
+ inline void Context::add_exif_metadata(const ImageHandle& master_image,
1367
+ const void* data, int size)
1368
+ {
1369
+ Error err = Error(heif_context_add_exif_metadata(m_context.get(),
1370
+ master_image.get_raw_image_handle(),
1371
+ data, size));
1372
+ if (err) {
1373
+ throw err;
1374
+ }
1375
+ }
1376
+
1377
+ inline void Context::add_XMP_metadata(const ImageHandle& master_image,
1378
+ const void* data, int size)
1379
+ {
1380
+ Error err = Error(heif_context_add_XMP_metadata(m_context.get(),
1381
+ master_image.get_raw_image_handle(),
1382
+ data, size));
1383
+ if (err) {
1384
+ throw err;
1385
+ }
1386
+ }
1387
+ }
1388
+
1389
+
1390
+ #endif