digiKam
box.h
Go to the documentation of this file.
1 /*
2  * HEIF codec.
3  * Copyright (c) 2017 struktur AG, Dirk Farin <farin@struktur.de>
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_BOX_H
22 #define LIBHEIF_BOX_H
23 
24 #if defined(HAVE_CONFIG_H)
25 #include "config.h"
26 #endif
27 
28 #include <cinttypes>
29 #include <cstddef>
30 
31 #include <vector>
32 #include <string>
33 #include <memory>
34 #include <limits>
35 #include <istream>
36 #include <bitset>
37 
38 #include "error.h"
39 #include "heif.h"
40 #include "logging.h"
41 #include "bitstream.h"
42 
43 #if !defined(__EMSCRIPTEN__) && !defined(_MSC_VER)
44 // std::array<bool> is not supported on some older compilers.
45 #define HAS_BOOL_ARRAY 1
46 #endif
47 
48 namespace heif {
49 
50 #define fourcc(id) (((uint32_t)(id[0])<<24) | (id[1]<<16) | (id[2]<<8) | (id[3]))
51 
52  /*
53  constexpr uint32_t fourcc(const char* string)
54  {
55  return ((string[0]<<24) |
56  (string[1]<<16) |
57  (string[2]<< 8) |
58  (string[3]));
59  }
60  */
61 
62 
63  class Fraction {
64  public:
65  Fraction() { }
66  Fraction(int32_t num,int32_t den);
67 
68  Fraction operator+(const Fraction&) const;
69  Fraction operator-(const Fraction&) const;
70  Fraction operator-(int) const;
71  Fraction operator/(int) const;
72 
73  int32_t round_down() const;
74  int32_t round_up() const;
75  int32_t round() const;
76 
77  bool is_valid() const;
78 
79  int32_t numerator = 0;
80  int32_t denominator = 1;
81  };
82 
83 
84  class BoxHeader {
85  public:
87  virtual ~BoxHeader() { }
88 
89  constexpr static uint64_t size_until_end_of_file = 0;
90 
91  uint64_t get_box_size() const { return m_size; }
92 
93  uint32_t get_header_size() const { return m_header_size; }
94 
95  uint32_t get_short_type() const { return m_type; }
96 
97  std::vector<uint8_t> get_type() const;
98 
99  std::string get_type_string() const;
100 
101  void set_short_type(uint32_t type) { m_type = type; }
102 
103 
105 
106  virtual std::string dump(Indent&) const;
107 
108 
109  // --- full box
110 
112 
113  uint8_t get_version() const { return m_version; }
114 
115  void set_version(uint8_t version) { m_version=version; }
116 
117  uint32_t get_flags() const { return m_flags; }
118 
119  void set_flags(uint32_t flags) { m_flags = flags; }
120 
121  void set_is_full_box(bool flag=true) { m_is_full_box=flag; }
122 
123  bool is_full_box_header() const { return m_is_full_box; }
124 
125 
126  // --- writing
127 
128  size_t reserve_box_header_space(StreamWriter& writer) const;
129  Error prepend_header(StreamWriter&, size_t box_start) const;
130 
131  private:
132  uint64_t m_size = 0;
133  uint32_t m_header_size = 0;
134 
135  uint32_t m_type = 0;
136  std::vector<uint8_t> m_uuid_type;
137 
138 
139  bool m_is_full_box = false;
140 
141  uint8_t m_version = 0;
142  uint32_t m_flags = 0;
143  };
144 
145 
146 
147  class Box : public BoxHeader {
148  public:
149  Box() { }
150  Box(const BoxHeader& hdr) : BoxHeader(hdr) { }
151 
152  static Error read(BitstreamRange& range, std::shared_ptr<heif::Box>* box);
153 
154  virtual Error write(StreamWriter& writer) const;
155 
156  // check, which box version is required and set this in the (full) box header
157  virtual void derive_box_version() { set_version(0); }
158 
160 
161  virtual std::string dump(Indent&) const;
162 
163  std::shared_ptr<Box> get_child_box(uint32_t short_type) const;
164  std::vector<std::shared_ptr<Box>> get_child_boxes(uint32_t short_type) const;
165 
166  const std::vector<std::shared_ptr<Box>>& get_all_child_boxes() const { return m_children; }
167 
168  int append_child_box(std::shared_ptr<Box> box) {
169  m_children.push_back(box);
170  return (int)m_children.size()-1;
171  }
172 
173  protected:
174  virtual Error parse(BitstreamRange& range);
175 
176  std::vector<std::shared_ptr<Box>> m_children;
177 
178  const static int READ_CHILDREN_ALL = -1;
179 
181 
183 
184  std::string dump_children(Indent&) const;
185  };
186 
187 
188  class Box_ftyp : public Box {
189  public:
191  Box_ftyp(const BoxHeader& hdr) : Box(hdr) { }
192 
193  std::string dump(Indent&) const override;
194 
195  bool has_compatible_brand(uint32_t brand) const;
196 
197 
198  void set_major_brand(uint32_t major_brand) { m_major_brand=major_brand; }
199  void set_minor_version(uint32_t minor_version) { m_minor_version=minor_version; }
200 
201  void clear_compatible_brands() { m_compatible_brands.clear(); }
202  void add_compatible_brand(uint32_t brand);
203 
204  Error write(StreamWriter& writer) const override;
205 
206  protected:
207  Error parse(BitstreamRange& range) override;
208 
209  private:
210  uint32_t m_major_brand = 0;
211  uint32_t m_minor_version = 0;
212  std::vector<uint32_t> m_compatible_brands;
213  };
214 
215 
216  class Box_meta : public Box {
217  public:
219  Box_meta(const BoxHeader& hdr) : Box(hdr) { }
220 
221  std::string dump(Indent&) const override;
222 
223  protected:
224  Error parse(BitstreamRange& range) override;
225  };
226 
227 
228  class Box_hdlr : public Box {
229  public:
231  Box_hdlr(const BoxHeader& hdr) : Box(hdr) { }
232 
233  std::string dump(Indent&) const override;
234 
235  uint32_t get_handler_type() const { return m_handler_type; }
236 
237  void set_handler_type(uint32_t handler) { m_handler_type = handler; }
238 
239  Error write(StreamWriter& writer) const override;
240 
241  protected:
242  Error parse(BitstreamRange& range) override;
243 
244  private:
245  uint32_t m_pre_defined = 0;
246  uint32_t m_handler_type = fourcc("pict");
247  uint32_t m_reserved[3] = {0, };
248  std::string m_name;
249  };
250 
251 
252  class Box_pitm : public Box {
253  public:
255  Box_pitm(const BoxHeader& hdr) : Box(hdr) { }
256 
257  std::string dump(Indent&) const override;
258 
259  heif_item_id get_item_ID() const { return m_item_ID; }
260 
261  void set_item_ID(heif_item_id id) { m_item_ID = id; }
262 
263  void derive_box_version() override;
264 
265  Error write(StreamWriter& writer) const override;
266 
267  protected:
268  Error parse(BitstreamRange& range) override;
269 
270  private:
271  heif_item_id m_item_ID = 0;
272  };
273 
274 
275  class Box_iloc : public Box {
276  public:
278  Box_iloc(const BoxHeader& hdr) : Box(hdr) { }
279 
280  std::string dump(Indent&) const override;
281 
282  struct Extent {
283  uint64_t index = 0;
284  uint64_t offset = 0;
285  uint64_t length = 0;
286 
287  std::vector<uint8_t> data; // only used when writing data
288  };
289 
290  struct Item {
292  uint8_t construction_method = 0; // >= version 1
293  uint16_t data_reference_index = 0;
294  uint64_t base_offset = 0;
295 
296  std::vector<Extent> extents;
297  };
298 
299  const std::vector<Item>& get_items() const { return m_items; }
300 
301  Error read_data(const Item& item,
302  std::shared_ptr<StreamReader> istr,
303  const std::shared_ptr<class Box_idat>&,
304  std::vector<uint8_t>* dest) const;
305 
306  void set_min_version(uint8_t min_version) { m_user_defined_min_version=min_version; }
307 
308  // append bitstream data that will be written later (after iloc box)
310  const std::vector<uint8_t>& data,
311  uint8_t construction_method=0);
312 
313  // append bitstream data that already has been written (before iloc box)
314  // Error write_mdat_before_iloc(heif_image_id item_ID,
315  // std::vector<uint8_t>& data)
316 
317  // reserve data entry that will be written later
318  // Error reserve_mdat_item(heif_image_id item_ID,
319  // uint8_t construction_method,
320  // uint32_t* slot_ID);
321  // void patch_mdat_slot(uint32_t slot_ID, size_t start, size_t length);
322 
323  void derive_box_version() override;
324 
325  Error write(StreamWriter& writer) const override;
326 
328 
329  protected:
330  Error parse(BitstreamRange& range) override;
331 
332  private:
333  std::vector<Item> m_items;
334 
335  mutable size_t m_iloc_box_start = 0;
336  uint8_t m_user_defined_min_version = 0;
337  uint8_t m_offset_size = 0;
338  uint8_t m_length_size = 0;
339  uint8_t m_base_offset_size = 0;
340  uint8_t m_index_size = 0;
341 
342  void patch_iloc_header(StreamWriter& writer) const;
343  };
344 
345 
346  class Box_infe : public Box {
347  public:
349  Box_infe(const BoxHeader& hdr) : Box(hdr) { }
350 
351  std::string dump(Indent&) const override;
352 
353  bool is_hidden_item() const { return m_hidden_item; }
354 
355  void set_hidden_item(bool hidden);
356 
357  heif_item_id get_item_ID() const { return m_item_ID; }
358 
359  void set_item_ID(heif_item_id id) { m_item_ID = id; }
360 
361  std::string get_item_type() const { return m_item_type; }
362 
363  void set_item_type(std::string type) { m_item_type = type; }
364 
365  void set_item_name(std::string name) { m_item_name = name; }
366 
367  std::string get_content_type() const { return m_content_type; }
368 
369  void set_content_type(std::string content_type) { m_content_type = content_type; }
370 
371  void derive_box_version() override;
372 
373  Error write(StreamWriter& writer) const override;
374 
375  protected:
376  Error parse(BitstreamRange& range) override;
377 
378  private:
379  heif_item_id m_item_ID = 0;
380  uint16_t m_item_protection_index = 0;
381 
382  std::string m_item_type;
383  std::string m_item_name;
384  std::string m_content_type;
385  std::string m_content_encoding;
386  std::string m_item_uri_type;
387 
388  // if set, this item should not be part of the presentation (i.e. hidden)
389  bool m_hidden_item = false;
390  };
391 
392 
393  class Box_iinf : public Box {
394  public:
396  Box_iinf(const BoxHeader& hdr) : Box(hdr) { }
397 
398  std::string dump(Indent&) const override;
399 
400  void derive_box_version() override;
401  Error write(StreamWriter& writer) const override;
402 
403  protected:
404  Error parse(BitstreamRange& range) override;
405 
406  private:
407  //std::vector< std::shared_ptr<Box_infe> > m_iteminfos;
408  };
409 
410 
411  class Box_iprp : public Box {
412  public:
414  Box_iprp(const BoxHeader& hdr) : Box(hdr) { }
415 
416  std::string dump(Indent&) const override;
417 
418  protected:
419  Error parse(BitstreamRange& range) override;
420  };
421 
422 
423  class Box_ipco : public Box {
424  public:
426  Box_ipco(const BoxHeader& hdr) : Box(hdr) { }
427 
428  struct Property {
429  bool essential;
430  std::shared_ptr<Box> property;
431  };
432 
434  const std::shared_ptr<class Box_ipma>&,
435  std::vector<Property>& out_properties) const;
436 
437  std::shared_ptr<Box> get_property_for_item_ID(heif_item_id itemID,
438  const std::shared_ptr<class Box_ipma>&,
439  uint32_t property_box_type) const;
440 
441  std::string dump(Indent&) const override;
442 
443  protected:
444  Error parse(BitstreamRange& range) override;
445  };
446 
447 
448  class Box_ispe : public Box {
449  public:
451  Box_ispe(const BoxHeader& hdr) : Box(hdr) { }
452 
453  uint32_t get_width() const { return m_image_width; }
454  uint32_t get_height() const { return m_image_height; }
455 
456  void set_size(uint32_t width, uint32_t height) {
457  m_image_width = width;
458  m_image_height = height;
459  }
460 
461  std::string dump(Indent&) const override;
462 
463  Error write(StreamWriter& writer) const override;
464 
465  protected:
466  Error parse(BitstreamRange& range) override;
467 
468  private:
469  uint32_t m_image_width = 0;
470  uint32_t m_image_height = 0;
471  };
472 
473 
474  class Box_ipma : public Box {
475  public:
477  Box_ipma(const BoxHeader& hdr) : Box(hdr) { }
478 
479  std::string dump(Indent&) const override;
480 
482  bool essential;
483  uint16_t property_index;
484  };
485 
486  const std::vector<PropertyAssociation>* get_properties_for_item_ID(heif_item_id itemID) const;
487 
489  PropertyAssociation assoc);
490 
491  void derive_box_version() override;
492 
493  Error write(StreamWriter& writer) const override;
494 
495  protected:
496  Error parse(BitstreamRange& range) override;
497 
498  struct Entry {
500  std::vector<PropertyAssociation> associations;
501  };
502 
503  std::vector<Entry> m_entries;
504  };
505 
506 
507  class Box_auxC : public Box {
508  public:
510  Box_auxC(const BoxHeader& hdr) : Box(hdr) { }
511 
512  std::string get_aux_type() const { return m_aux_type; }
513  void set_aux_type(std::string type) { m_aux_type = type; }
514 
515  std::vector<uint8_t> get_subtypes() const { return m_aux_subtypes; }
516 
517  std::string dump(Indent&) const override;
518 
519  protected:
520  Error parse(BitstreamRange& range) override;
521  Error write(StreamWriter& writer) const override;
522 
523  private:
524  std::string m_aux_type;
525  std::vector<uint8_t> m_aux_subtypes;
526  };
527 
528 
529  class Box_irot : public Box {
530  public:
531  Box_irot(const BoxHeader& hdr) : Box(hdr) { }
532 
533  std::string dump(Indent&) const override;
534 
535  int get_rotation() const { return m_rotation; }
536 
537  protected:
538  Error parse(BitstreamRange& range) override;
539 
540  private:
541  int m_rotation = 0; // in degrees (CCW)
542  };
543 
544 
545  class Box_imir : public Box {
546  public:
547  Box_imir(const BoxHeader& hdr) : Box(hdr) { }
548 
549  enum class MirrorAxis : uint8_t {
550  Vertical = 0,
551  Horizontal = 1
552  };
553 
554  MirrorAxis get_mirror_axis() const { return m_axis; }
555 
556  std::string dump(Indent&) const override;
557 
558  protected:
559  Error parse(BitstreamRange& range) override;
560 
561  private:
563  };
564 
565 
566  class Box_clap : public Box {
567  public:
568  Box_clap(const BoxHeader& hdr) : Box(hdr) { }
569 
570  std::string dump(Indent&) const override;
571 
572  int left_rounded(int image_width) const; // first column
573  int right_rounded(int image_width) const; // last column that is part of the cropped image
574  int top_rounded(int image_height) const; // first row
575  int bottom_rounded(int image_height) const; // last row included in the cropped image
576 
577  int get_width_rounded() const;
578  int get_height_rounded() const;
579 
580  protected:
581  Error parse(BitstreamRange& range) override;
582 
583  private:
584  Fraction m_clean_aperture_width;
585  Fraction m_clean_aperture_height;
586  Fraction m_horizontal_offset;
587  Fraction m_vertical_offset;
588  };
589 
590 
591  class Box_iref : public Box {
592  public:
594  Box_iref(const BoxHeader& hdr) : Box(hdr) { }
595 
596  struct Reference {
598 
600  std::vector<heif_item_id> to_item_ID;
601  };
602 
603 
604  std::string dump(Indent&) const override;
605 
606  bool has_references(heif_item_id itemID) const;
607 
608  std::vector<heif_item_id> get_references(heif_item_id itemID, uint32_t ref_type) const;
609 
610  std::vector<Reference> get_references_from(heif_item_id itemID) const;
611 
612  void add_reference(heif_item_id from_id, uint32_t type, std::vector<heif_item_id> to_ids);
613 
614  protected:
615  Error parse(BitstreamRange& range) override;
616  Error write(StreamWriter& writer) const override;
617 
618  void derive_box_version() override;
619 
620  private:
621  std::vector<Reference> m_references;
622  };
623 
624 
625  class Box_hvcC : public Box {
626  public:
628  Box_hvcC(const BoxHeader& hdr) : Box(hdr) { }
629 
630  struct configuration {
636 
637  static const int NUM_CONSTRAINT_INDICATOR_FLAGS = 48;
638  std::bitset<NUM_CONSTRAINT_INDICATOR_FLAGS> general_constraint_indicator_flags;
639 
641 
644  uint8_t chroma_format;
645  uint8_t bit_depth_luma;
647  uint16_t avg_frame_rate;
648 
652  };
653 
654 
655  std::string dump(Indent&) const override;
656 
657  bool get_headers(std::vector<uint8_t>* dest) const;
658 
659  void set_configuration(const configuration& config) { m_configuration=config; }
660 
661  configuration get_configuration() const { return m_configuration; }
662 
663  void append_nal_data(const std::vector<uint8_t>& nal);
664  void append_nal_data(const uint8_t* data, size_t size);
665 
666  Error write(StreamWriter& writer) const override;
667 
668  protected:
669  Error parse(BitstreamRange& range) override;
670 
671  private:
672  struct NalArray {
673  uint8_t m_array_completeness;
674  uint8_t m_NAL_unit_type;
675 
676  std::vector< std::vector<uint8_t> > m_nal_units;
677  };
678 
679  configuration m_configuration;
680  uint8_t m_length_size = 4; // default: 4 bytes for NAL unit lengths
681 
682  std::vector<NalArray> m_nal_array;
683  };
684 
685 
686  class Box_idat : public Box {
687  public:
688  Box_idat(const BoxHeader& hdr) : Box(hdr) { }
689 
690  std::string dump(Indent&) const override;
691 
692  Error read_data(std::shared_ptr<StreamReader> istr,
693  uint64_t start, uint64_t length,
694  std::vector<uint8_t>& out_data) const;
695 
696  protected:
697  Error parse(BitstreamRange& range) override;
698 
699  std::streampos m_data_start_pos;
700  };
701 
702 
703  class Box_grpl : public Box {
704  public:
705  Box_grpl(const BoxHeader& hdr) : Box(hdr) { }
706 
707  std::string dump(Indent&) const override;
708 
709  protected:
710  Error parse(BitstreamRange& range) override;
711 
712  struct EntityGroup {
714  uint32_t group_id;
715 
716  std::vector<heif_item_id> entity_ids;
717  };
718 
719  std::vector<EntityGroup> m_entity_groups;
720  };
721 
722 
723  class Box_dinf : public Box {
724  public:
725  Box_dinf(const BoxHeader& hdr) : Box(hdr) { }
726 
727  std::string dump(Indent&) const override;
728 
729  protected:
730  Error parse(BitstreamRange& range) override;
731  };
732 
733 
734  class Box_dref : public Box {
735  public:
736  Box_dref(const BoxHeader& hdr) : Box(hdr) { }
737 
738  std::string dump(Indent&) const override;
739 
740  protected:
741  Error parse(BitstreamRange& range) override;
742  };
743 
744 
745  class Box_url : public Box {
746  public:
747  Box_url(const BoxHeader& hdr) : Box(hdr) { }
748 
749  std::string dump(Indent&) const override;
750 
751  protected:
752  Error parse(BitstreamRange& range) override;
753 
754  std::string m_location;
755  };
756 
757  class Box_pixi : public Box {
758  public:
760  Box_pixi(const BoxHeader& hdr) : Box(hdr) { }
761 
762  int get_num_channels() const { return (int)m_bits_per_channel.size(); }
763 
764  int get_bits_per_channel(int channel) const { return m_bits_per_channel[channel]; }
765 
766  std::string dump(Indent&) const override;
767 
768  Error write(StreamWriter& writer) const override;
769  protected:
770  Error parse(BitstreamRange& range) override;
771  private:
772  std::vector<uint8_t> m_bits_per_channel;
773  };
774 
775 
777  {
778  public:
779  virtual ~color_profile() { }
780  virtual uint32_t get_type() const = 0;
781  virtual std::string dump(Indent&) const = 0;
782  virtual Error write(StreamWriter& writer) const = 0;
783  };
784 
786  {
787  public:
788  color_profile_raw(uint32_t type, std::vector<uint8_t> data)
789  : m_type(type), m_data(data) { }
790 
791  uint32_t get_type() const override { return m_type; }
792 
793  std::vector<uint8_t> get_data() const { return m_data; }
794 
795  std::string dump(Indent&) const override;
796 
797  Error write(StreamWriter& writer) const override;
798 
799  private:
800  uint32_t m_type;
801  std::vector<uint8_t> m_data;
802  };
803 
804 
806  {
807  public:
809 
810  uint32_t get_type() const override { return fourcc("nclx"); }
811 
812  std::string dump(Indent&) const override;
813 
815  Error write(StreamWriter& writer) const override;
816 
817  uint16_t get_colour_primaries() const {return m_colour_primaries;}
818  uint16_t get_transfer_characteristics() const {return m_transfer_characteristics;}
819  uint16_t get_matrix_coefficients() const {return m_matrix_coefficients;}
820  bool get_full_range_flag() const {return m_full_range_flag;}
821 
822  void set_colour_primaries(uint16_t primaries) { m_colour_primaries = primaries; }
823  void set_transfer_characteristics(uint16_t characteristics) { m_transfer_characteristics = characteristics; }
824  void set_matrix_coefficients(uint16_t coefficients) { m_matrix_coefficients = coefficients; }
825  void set_full_range_flag(bool full_range) { m_full_range_flag=full_range; }
826 
827  private:
828  uint16_t m_colour_primaries = 0;
829  uint16_t m_transfer_characteristics = 0;
830  uint16_t m_matrix_coefficients = 0;
831  bool m_full_range_flag = true;
832  };
833 
834 
835  class Box_colr : public Box {
836  public:
838  Box_colr(const BoxHeader& hdr) : Box(hdr) { }
839 
840  std::string dump(Indent&) const override;
841  uint32_t get_color_profile_type() const { return m_color_profile->get_type(); }
842 
843  std::shared_ptr<const color_profile> get_color_profile() const { return m_color_profile; }
844  void set_color_profile(std::shared_ptr<const color_profile> prof) { m_color_profile = prof; }
845 
846 
847  Error write(StreamWriter& writer) const override;
848 
849  protected:
850  Error parse(BitstreamRange& range) override;
851 
852  private:
853  std::shared_ptr<const color_profile> m_color_profile;
854  };
855 
856 }
857 
858 #endif
#define fourcc(id)
Definition: box.h:50
Definition: bitstream.h:134
Definition: box.h:84
size_t reserve_box_header_space(StreamWriter &writer) const
void set_short_type(uint32_t type)
Definition: box.h:101
virtual ~BoxHeader()
Definition: box.h:87
uint32_t get_flags() const
Definition: box.h:117
Error prepend_header(StreamWriter &, size_t box_start) const
constexpr static uint64_t size_until_end_of_file
Definition: box.h:89
Error parse(BitstreamRange &range)
void set_is_full_box(bool flag=true)
Definition: box.h:121
uint32_t get_short_type() const
Definition: box.h:95
uint64_t get_box_size() const
Definition: box.h:91
uint32_t get_header_size() const
Definition: box.h:93
virtual std::string dump(Indent &) const
void set_version(uint8_t version)
Definition: box.h:115
std::vector< uint8_t > get_type() const
uint8_t get_version() const
Definition: box.h:113
void set_flags(uint32_t flags)
Definition: box.h:119
Error parse_full_box_header(BitstreamRange &range)
bool is_full_box_header() const
Definition: box.h:123
std::string get_type_string() const
Definition: box.h:507
Error write(StreamWriter &writer) const override
Error parse(BitstreamRange &range) override
std::string get_aux_type() const
Definition: box.h:512
std::string dump(Indent &) const override
void set_aux_type(std::string type)
Definition: box.h:513
Box_auxC()
Definition: box.h:509
std::vector< uint8_t > get_subtypes() const
Definition: box.h:515
Box_auxC(const BoxHeader &hdr)
Definition: box.h:510
Definition: box.h:566
int bottom_rounded(int image_height) const
int right_rounded(int image_width) const
int left_rounded(int image_width) const
Box_clap(const BoxHeader &hdr)
Definition: box.h:568
std::string dump(Indent &) const override
int top_rounded(int image_height) const
int get_height_rounded() const
int get_width_rounded() const
Error parse(BitstreamRange &range) override
Definition: box.h:835
Box_colr(const BoxHeader &hdr)
Definition: box.h:838
Error write(StreamWriter &writer) const override
std::shared_ptr< const color_profile > get_color_profile() const
Definition: box.h:843
void set_color_profile(std::shared_ptr< const color_profile > prof)
Definition: box.h:844
Error parse(BitstreamRange &range) override
uint32_t get_color_profile_type() const
Definition: box.h:841
Box_colr()
Definition: box.h:837
std::string dump(Indent &) const override
Definition: box.h:723
Error parse(BitstreamRange &range) override
std::string dump(Indent &) const override
Box_dinf(const BoxHeader &hdr)
Definition: box.h:725
Definition: box.h:734
std::string dump(Indent &) const override
Error parse(BitstreamRange &range) override
Box_dref(const BoxHeader &hdr)
Definition: box.h:736
Definition: box.h:188
Error parse(BitstreamRange &range) override
Error write(StreamWriter &writer) const override
void add_compatible_brand(uint32_t brand)
void set_minor_version(uint32_t minor_version)
Definition: box.h:199
void clear_compatible_brands()
Definition: box.h:201
void set_major_brand(uint32_t major_brand)
Definition: box.h:198
std::string dump(Indent &) const override
bool has_compatible_brand(uint32_t brand) const
Box_ftyp(const BoxHeader &hdr)
Definition: box.h:191
Box_ftyp()
Definition: box.h:190
Definition: box.h:703
std::string dump(Indent &) const override
Error parse(BitstreamRange &range) override
Box_grpl(const BoxHeader &hdr)
Definition: box.h:705
std::vector< EntityGroup > m_entity_groups
Definition: box.h:719
Definition: box.h:228
uint32_t get_handler_type() const
Definition: box.h:235
Box_hdlr(const BoxHeader &hdr)
Definition: box.h:231
Error parse(BitstreamRange &range) override
std::string dump(Indent &) const override
Box_hdlr()
Definition: box.h:230
Error write(StreamWriter &writer) const override
void set_handler_type(uint32_t handler)
Definition: box.h:237
Definition: box.h:625
Error write(StreamWriter &writer) const override
std::string dump(Indent &) const override
Box_hvcC()
Definition: box.h:627
Box_hvcC(const BoxHeader &hdr)
Definition: box.h:628
void append_nal_data(const std::vector< uint8_t > &nal)
bool get_headers(std::vector< uint8_t > *dest) const
void append_nal_data(const uint8_t *data, size_t size)
void set_configuration(const configuration &config)
Definition: box.h:659
configuration get_configuration() const
Definition: box.h:661
Error parse(BitstreamRange &range) override
Definition: box.h:686
Box_idat(const BoxHeader &hdr)
Definition: box.h:688
Error read_data(std::shared_ptr< StreamReader > istr, uint64_t start, uint64_t length, std::vector< uint8_t > &out_data) const
std::streampos m_data_start_pos
Definition: box.h:699
Error parse(BitstreamRange &range) override
std::string dump(Indent &) const override
Definition: box.h:393
Box_iinf(const BoxHeader &hdr)
Definition: box.h:396
Error write(StreamWriter &writer) const override
Error parse(BitstreamRange &range) override
std::string dump(Indent &) const override
void derive_box_version() override
Box_iinf()
Definition: box.h:395
Definition: box.h:275
const std::vector< Item > & get_items() const
Definition: box.h:299
Error write_mdat_after_iloc(StreamWriter &writer)
std::string dump(Indent &) const override
Error parse(BitstreamRange &range) override
void derive_box_version() override
Error write(StreamWriter &writer) const override
Error append_data(heif_item_id item_ID, const std::vector< uint8_t > &data, uint8_t construction_method=0)
Error read_data(const Item &item, std::shared_ptr< StreamReader > istr, const std::shared_ptr< class Box_idat > &, std::vector< uint8_t > *dest) const
Box_iloc(const BoxHeader &hdr)
Definition: box.h:278
Box_iloc()
Definition: box.h:277
void set_min_version(uint8_t min_version)
Definition: box.h:306
Definition: box.h:545
Error parse(BitstreamRange &range) override
MirrorAxis
Definition: box.h:549
Box_imir(const BoxHeader &hdr)
Definition: box.h:547
std::string dump(Indent &) const override
MirrorAxis get_mirror_axis() const
Definition: box.h:554
Definition: box.h:346
bool is_hidden_item() const
Definition: box.h:353
void set_hidden_item(bool hidden)
void derive_box_version() override
Box_infe(const BoxHeader &hdr)
Definition: box.h:349
std::string dump(Indent &) const override
Error parse(BitstreamRange &range) override
Error write(StreamWriter &writer) const override
std::string get_content_type() const
Definition: box.h:367
Box_infe()
Definition: box.h:348
void set_item_ID(heif_item_id id)
Definition: box.h:359
heif_item_id get_item_ID() const
Definition: box.h:357
std::string get_item_type() const
Definition: box.h:361
void set_item_name(std::string name)
Definition: box.h:365
void set_item_type(std::string type)
Definition: box.h:363
void set_content_type(std::string content_type)
Definition: box.h:369
Definition: box.h:423
std::string dump(Indent &) const override
Error get_properties_for_item_ID(heif_item_id itemID, const std::shared_ptr< class Box_ipma > &, std::vector< Property > &out_properties) const
Box_ipco(const BoxHeader &hdr)
Definition: box.h:426
Error parse(BitstreamRange &range) override
Box_ipco()
Definition: box.h:425
std::shared_ptr< Box > get_property_for_item_ID(heif_item_id itemID, const std::shared_ptr< class Box_ipma > &, uint32_t property_box_type) const
Definition: box.h:474
Box_ipma(const BoxHeader &hdr)
Definition: box.h:477
Box_ipma()
Definition: box.h:476
const std::vector< PropertyAssociation > * get_properties_for_item_ID(heif_item_id itemID) const
Error parse(BitstreamRange &range) override
void derive_box_version() override
std::string dump(Indent &) const override
std::vector< Entry > m_entries
Definition: box.h:503
void add_property_for_item_ID(heif_item_id itemID, PropertyAssociation assoc)
Error write(StreamWriter &writer) const override
Definition: box.h:411
Box_iprp(const BoxHeader &hdr)
Definition: box.h:414
std::string dump(Indent &) const override
Box_iprp()
Definition: box.h:413
Error parse(BitstreamRange &range) override
Definition: box.h:591
Box_iref()
Definition: box.h:593
void add_reference(heif_item_id from_id, uint32_t type, std::vector< heif_item_id > to_ids)
bool has_references(heif_item_id itemID) const
Error write(StreamWriter &writer) const override
Error parse(BitstreamRange &range) override
std::vector< Reference > get_references_from(heif_item_id itemID) const
std::string dump(Indent &) const override
Box_iref(const BoxHeader &hdr)
Definition: box.h:594
std::vector< heif_item_id > get_references(heif_item_id itemID, uint32_t ref_type) const
void derive_box_version() override
Definition: box.h:529
Error parse(BitstreamRange &range) override
int get_rotation() const
Definition: box.h:535
Box_irot(const BoxHeader &hdr)
Definition: box.h:531
std::string dump(Indent &) const override
Definition: box.h:448
std::string dump(Indent &) const override
Box_ispe(const BoxHeader &hdr)
Definition: box.h:451
uint32_t get_height() const
Definition: box.h:454
uint32_t get_width() const
Definition: box.h:453
Box_ispe()
Definition: box.h:450
Error parse(BitstreamRange &range) override
Error write(StreamWriter &writer) const override
void set_size(uint32_t width, uint32_t height)
Definition: box.h:456
Definition: box.h:216
Box_meta(const BoxHeader &hdr)
Definition: box.h:219
Error parse(BitstreamRange &range) override
Box_meta()
Definition: box.h:218
std::string dump(Indent &) const override
Definition: box.h:252
std::string dump(Indent &) const override
Box_pitm()
Definition: box.h:254
void set_item_ID(heif_item_id id)
Definition: box.h:261
Error parse(BitstreamRange &range) override
Box_pitm(const BoxHeader &hdr)
Definition: box.h:255
Error write(StreamWriter &writer) const override
void derive_box_version() override
heif_item_id get_item_ID() const
Definition: box.h:259
Definition: box.h:757
int get_num_channels() const
Definition: box.h:762
Error write(StreamWriter &writer) const override
std::string dump(Indent &) const override
int get_bits_per_channel(int channel) const
Definition: box.h:764
Box_pixi(const BoxHeader &hdr)
Definition: box.h:760
Box_pixi()
Definition: box.h:759
Error parse(BitstreamRange &range) override
Definition: box.h:745
std::string m_location
Definition: box.h:754
Error parse(BitstreamRange &range) override
Box_url(const BoxHeader &hdr)
Definition: box.h:747
std::string dump(Indent &) const override
Definition: box.h:147
virtual Error write(StreamWriter &writer) const
static Error read(BitstreamRange &range, std::shared_ptr< heif::Box > *box)
static const int READ_CHILDREN_ALL
Definition: box.h:178
virtual std::string dump(Indent &) const
const std::vector< std::shared_ptr< Box > > & get_all_child_boxes() const
Definition: box.h:166
Box(const BoxHeader &hdr)
Definition: box.h:150
std::string dump_children(Indent &) const
std::shared_ptr< Box > get_child_box(uint32_t short_type) const
int append_child_box(std::shared_ptr< Box > box)
Definition: box.h:168
virtual void derive_box_version()
Definition: box.h:157
Error write_children(StreamWriter &writer) const
void derive_box_version_recursive()
std::vector< std::shared_ptr< Box > > m_children
Definition: box.h:176
std::vector< std::shared_ptr< Box > > get_child_boxes(uint32_t short_type) const
virtual Error parse(BitstreamRange &range)
Error read_children(BitstreamRange &range, int number=READ_CHILDREN_ALL)
Box()
Definition: box.h:149
Definition: error.h:75
Definition: box.h:63
int32_t denominator
Definition: box.h:80
bool is_valid() const
Fraction operator+(const Fraction &) const
Fraction()
Definition: box.h:65
Fraction operator/(int) const
int32_t round_up() const
Fraction operator-(int) const
int32_t round_down() const
int32_t round() const
Fraction(int32_t num, int32_t den)
int32_t numerator
Definition: box.h:79
Fraction operator-(const Fraction &) const
Definition: logging.h:40
Definition: bitstream.h:256
Definition: box.h:806
uint16_t get_transfer_characteristics() const
Definition: box.h:818
uint32_t get_type() const override
Definition: box.h:810
void set_colour_primaries(uint16_t primaries)
Definition: box.h:822
std::string dump(Indent &) const override
void set_full_range_flag(bool full_range)
Definition: box.h:825
uint16_t get_colour_primaries() const
Definition: box.h:817
color_profile_nclx()
Definition: box.h:808
Error write(StreamWriter &writer) const override
void set_transfer_characteristics(uint16_t characteristics)
Definition: box.h:823
bool get_full_range_flag() const
Definition: box.h:820
Error parse(BitstreamRange &range)
void set_matrix_coefficients(uint16_t coefficients)
Definition: box.h:824
uint16_t get_matrix_coefficients() const
Definition: box.h:819
Definition: box.h:786
color_profile_raw(uint32_t type, std::vector< uint8_t > data)
Definition: box.h:788
std::vector< uint8_t > get_data() const
Definition: box.h:793
std::string dump(Indent &) const override
uint32_t get_type() const override
Definition: box.h:791
Error write(StreamWriter &writer) const override
Definition: box.h:777
virtual uint32_t get_type() const =0
virtual std::string dump(Indent &) const =0
virtual ~color_profile()
Definition: box.h:779
virtual Error write(StreamWriter &writer) const =0
uint32_t heif_item_id
Definition: heif.h:276
Definition: bitstream.h:41
Definition: box.h:712
std::vector< heif_item_id > entity_ids
Definition: box.h:716
uint32_t group_id
Definition: box.h:714
BoxHeader header
Definition: box.h:713
Definition: box.h:630
bool general_tier_flag
Definition: box.h:633
uint32_t general_profile_compatibility_flags
Definition: box.h:635
uint8_t bit_depth_chroma
Definition: box.h:646
std::bitset< NUM_CONSTRAINT_INDICATOR_FLAGS > general_constraint_indicator_flags
Definition: box.h:638
uint8_t chroma_format
Definition: box.h:644
uint8_t temporal_id_nested
Definition: box.h:651
uint8_t parallelism_type
Definition: box.h:643
uint8_t configuration_version
Definition: box.h:631
uint16_t min_spatial_segmentation_idc
Definition: box.h:642
uint8_t general_profile_idc
Definition: box.h:634
uint8_t general_profile_space
Definition: box.h:632
uint8_t constant_frame_rate
Definition: box.h:649
uint8_t general_level_idc
Definition: box.h:640
uint8_t bit_depth_luma
Definition: box.h:645
uint8_t num_temporal_layers
Definition: box.h:650
uint16_t avg_frame_rate
Definition: box.h:647
static const int NUM_CONSTRAINT_INDICATOR_FLAGS
Definition: box.h:637
Definition: box.h:282
std::vector< uint8_t > data
Definition: box.h:287
uint64_t offset
Definition: box.h:284
uint64_t index
Definition: box.h:283
uint64_t length
Definition: box.h:285
Definition: box.h:290
uint16_t data_reference_index
Definition: box.h:293
heif_item_id item_ID
Definition: box.h:291
uint64_t base_offset
Definition: box.h:294
uint8_t construction_method
Definition: box.h:292
std::vector< Extent > extents
Definition: box.h:296
Definition: box.h:428
bool essential
Definition: box.h:429
std::shared_ptr< Box > property
Definition: box.h:430
Definition: box.h:498
std::vector< PropertyAssociation > associations
Definition: box.h:500
heif_item_id item_ID
Definition: box.h:499
uint16_t property_index
Definition: box.h:483
bool essential
Definition: box.h:482
Definition: box.h:596
std::vector< heif_item_id > to_item_ID
Definition: box.h:600
heif_item_id from_item_ID
Definition: box.h:599
BoxHeader header
Definition: box.h:597