digiKam
heif_file.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_HEIF_FILE_H
22 #define LIBHEIF_HEIF_FILE_H
23 
24 #if defined(HAVE_CONFIG_H)
25 #include "config.h"
26 #endif
27 
28 #include "box.h"
29 
30 #include <map>
31 #include <memory>
32 #include <string>
33 #include <map>
34 #include <vector>
35 
36 #if ENABLE_PARALLEL_TILE_DECODING
37 #include <mutex>
38 #endif
39 
40 
41 namespace heif {
42 
43  class HeifPixelImage;
44  class HeifImage;
45 
46 
47  class HeifFile {
48  public:
51 
52  Error read(std::shared_ptr<StreamReader> reader);
53  Error read_from_file(const char* input_filename);
54  Error read_from_memory(const void* data, size_t size, bool copy);
55 
57 
58  void write(StreamWriter& writer);
59 
60  int get_num_images() const { return static_cast<int>(m_infe_boxes.size()); }
61 
62  heif_item_id get_primary_image_ID() const { return m_pitm_box->get_item_ID(); }
63 
64  std::vector<heif_item_id> get_item_IDs() const;
65 
66  bool image_exists(heif_item_id ID) const;
67 
68  std::string get_item_type(heif_item_id ID) const;
69 
70  std::string get_content_type(heif_item_id ID) const;
71 
72  Error get_compressed_image_data(heif_item_id ID, std::vector<uint8_t>* out_data) const;
73 
74 
75 
76  std::shared_ptr<Box_infe> get_infe_box(heif_item_id imageID) {
77  auto iter = m_infe_boxes.find(imageID);
78  if (iter == m_infe_boxes.end()) {
79  return nullptr;
80  }
81 
82  return iter->second;
83  }
84 
85  std::shared_ptr<Box_iref> get_iref_box() { return m_iref_box; }
86 
87  std::shared_ptr<Box_ipco> get_ipco_box() { return m_ipco_box; }
88 
89  std::shared_ptr<Box_ipma> get_ipma_box() { return m_ipma_box; }
90 
92  std::vector<Box_ipco::Property>& properties) const;
93 
95 
97 
99 
100  std::string debug_dump_boxes() const;
101 
102 
103  // --- writing ---
104 
106 
107  heif_item_id add_new_image(const char* item_type);
108  std::shared_ptr<Box_infe> add_new_infe_box(const char* item_type);
109 
111  Error append_hvcC_nal_data(heif_item_id id, const std::vector<uint8_t>& data);
112  Error append_hvcC_nal_data(heif_item_id id, const uint8_t* data, size_t size);
114 
115  void add_ispe_property(heif_item_id id, uint32_t width, uint32_t height);
116 
117  void append_iloc_data(heif_item_id id, const std::vector<uint8_t>& nal_packets);
118  void append_iloc_data_with_4byte_size(heif_item_id id, const uint8_t* data, size_t size);
119 
121 
122  void add_iref_reference(heif_item_id from, uint32_t type,
123  std::vector<heif_item_id> to);
124 
125  void set_auxC_property(heif_item_id id, std::string type);
126 
127  void set_color_profile(heif_item_id id, const std::shared_ptr<const color_profile> profile);
128 
129  private:
130 #if ENABLE_PARALLEL_TILE_DECODING
131  mutable std::mutex m_read_mutex;
132 #endif
133 
134  std::shared_ptr<StreamReader> m_input_stream;
135 
136  std::vector<std::shared_ptr<Box> > m_top_level_boxes;
137 
138  std::shared_ptr<Box_ftyp> m_ftyp_box;
139  std::shared_ptr<Box_hdlr> m_hdlr_box;
140  std::shared_ptr<Box_meta> m_meta_box;
141 
142  std::shared_ptr<Box_ipco> m_ipco_box;
143  std::shared_ptr<Box_ipma> m_ipma_box;
144  std::shared_ptr<Box_iloc> m_iloc_box;
145  std::shared_ptr<Box_idat> m_idat_box;
146  std::shared_ptr<Box_iref> m_iref_box;
147  std::shared_ptr<Box_pitm> m_pitm_box;
148  std::shared_ptr<Box_iinf> m_iinf_box;
149 
150  std::shared_ptr<Box_iprp> m_iprp_box;
151 
152  std::map<heif_item_id, std::shared_ptr<Box_infe> > m_infe_boxes;
153 
154  // list of image items (does not include hidden images or Exif data)
155  //std::vector<heif_item_id> m_valid_image_IDs;
156 
157 
158  Error parse_heif_file(BitstreamRange& bitstream);
159 
160  std::shared_ptr<Box_infe> get_infe(heif_item_id ID) const;
161  };
162 
163 }
164 
165 #endif
Definition: bitstream.h:134
Definition: error.h:75
Definition: heif_file.h:47
Error read_from_memory(const void *data, size_t size, bool copy)
int get_num_images() const
Definition: heif_file.h:60
std::shared_ptr< Box_infe > add_new_infe_box(const char *item_type)
std::string debug_dump_boxes() const
std::string get_content_type(heif_item_id ID) const
void add_hvcC_property(heif_item_id id)
Error get_compressed_image_data(heif_item_id ID, std::vector< uint8_t > *out_data) const
Error append_hvcC_nal_data(heif_item_id id, const uint8_t *data, size_t size)
int get_chroma_bits_per_pixel_from_configuration(heif_item_id imageID) const
void add_iref_reference(heif_item_id from, uint32_t type, std::vector< heif_item_id > to)
heif_item_id add_new_image(const char *item_type)
std::shared_ptr< Box_iref > get_iref_box()
Definition: heif_file.h:85
std::string get_item_type(heif_item_id ID) const
int get_luma_bits_per_pixel_from_configuration(heif_item_id imageID) const
heif_item_id get_primary_image_ID() const
Definition: heif_file.h:62
std::shared_ptr< Box_ipco > get_ipco_box()
Definition: heif_file.h:87
void append_iloc_data_with_4byte_size(heif_item_id id, const uint8_t *data, size_t size)
Error read_from_file(const char *input_filename)
void set_auxC_property(heif_item_id id, std::string type)
void append_iloc_data(heif_item_id id, const std::vector< uint8_t > &nal_packets)
void set_primary_item_id(heif_item_id id)
Error read(std::shared_ptr< StreamReader > reader)
void write(StreamWriter &writer)
void set_color_profile(heif_item_id id, const std::shared_ptr< const color_profile > profile)
void new_empty_file()
Error append_hvcC_nal_data(heif_item_id id, const std::vector< uint8_t > &data)
std::shared_ptr< Box_ipma > get_ipma_box()
Definition: heif_file.h:89
void add_ispe_property(heif_item_id id, uint32_t width, uint32_t height)
Error get_properties(heif_item_id imageID, std::vector< Box_ipco::Property > &properties) const
heif_item_id get_unused_item_id() const
bool image_exists(heif_item_id ID) const
Error set_hvcC_configuration(heif_item_id id, const Box_hvcC::configuration &config)
std::vector< heif_item_id > get_item_IDs() const
heif_chroma get_image_chroma_from_configuration(heif_item_id imageID) const
std::shared_ptr< Box_infe > get_infe_box(heif_item_id imageID)
Definition: heif_file.h:76
Definition: bitstream.h:256
heif_chroma
Definition: heif.h:722
uint32_t heif_item_id
Definition: heif.h:276
Definition: bitstream.h:41
Definition: box.h:630