/src/libheif/libheif/codecs/avif_boxes.h
Line | Count | Source |
1 | | /* |
2 | | * HEIF codec. |
3 | | * Copyright (c) 2017 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 HEIF_AVIF_BOXES_H |
22 | | #define HEIF_AVIF_BOXES_H |
23 | | |
24 | | #include <cassert> |
25 | | #include <cmath> |
26 | | #include <memory> |
27 | | #include <string> |
28 | | #include <vector> |
29 | | |
30 | | #include "libheif/heif.h" |
31 | | #include "box.h" |
32 | | #include "error.h" |
33 | | #include "image-items/image_item.h" |
34 | | #include "sequences/seq_boxes.h" |
35 | | |
36 | | |
37 | | class Box_av1C : public Box |
38 | | { |
39 | | |
40 | | // allow access to protected parse() method |
41 | | friend class Box_mini; |
42 | | |
43 | | public: |
44 | | Box_av1C() |
45 | 1.00k | { |
46 | 1.00k | set_short_type(fourcc("av1C")); |
47 | 1.00k | } |
48 | | |
49 | 0 | bool is_essential() const override { return true; } |
50 | | |
51 | | struct configuration |
52 | | { |
53 | | //unsigned int (1) marker = 1; |
54 | | uint8_t version = 1; |
55 | | uint8_t seq_profile = 0; |
56 | | uint8_t seq_level_idx_0 = 0; |
57 | | uint8_t seq_tier_0 = 0; |
58 | | uint8_t high_bitdepth = 0; |
59 | | uint8_t twelve_bit = 0; |
60 | | uint8_t monochrome = 0; |
61 | | uint8_t chroma_subsampling_x = 0; // (minus 1) that is: either 0 or 1 |
62 | | uint8_t chroma_subsampling_y = 0; // (minus 1) |
63 | | uint8_t chroma_sample_position = 0; |
64 | | //uint8_t reserved = 0; |
65 | | |
66 | | uint8_t initial_presentation_delay_present = 0; |
67 | | uint8_t initial_presentation_delay_minus_one = 0; |
68 | | |
69 | | //unsigned int (8)[] configOBUs; |
70 | | |
71 | 243 | heif_chroma get_heif_chroma() const { |
72 | 243 | if (monochrome) { |
73 | 81 | return heif_chroma_monochrome; |
74 | 81 | } |
75 | 162 | else if (chroma_subsampling_x==1 && chroma_subsampling_y==1) { |
76 | 59 | return heif_chroma_420; |
77 | 59 | } |
78 | 103 | else if (chroma_subsampling_x==1 && chroma_subsampling_y==0) { |
79 | 17 | return heif_chroma_422; |
80 | 17 | } |
81 | 86 | else if (chroma_subsampling_x==0 && chroma_subsampling_y==0) { |
82 | 77 | return heif_chroma_444; |
83 | 77 | } |
84 | 9 | else { |
85 | 9 | return heif_chroma_undefined; |
86 | 9 | } |
87 | 243 | } |
88 | | }; |
89 | | |
90 | | |
91 | | std::string dump(Indent&) const override; |
92 | | |
93 | | bool get_headers(std::vector<uint8_t>* dest) const |
94 | 0 | { |
95 | 0 | *dest = m_config_OBUs; |
96 | 0 | return true; |
97 | 0 | } |
98 | | |
99 | 0 | void set_configuration(const configuration& config) { m_configuration = config; } |
100 | | |
101 | 488 | const configuration& get_configuration() const { return m_configuration; } |
102 | | |
103 | | //void append_nal_data(const std::vector<uint8_t>& nal); |
104 | | //void append_nal_data(const uint8_t* data, size_t size); |
105 | | |
106 | | Error write(StreamWriter& writer) const override; |
107 | | |
108 | | protected: |
109 | | Error parse(BitstreamRange& range, const heif_security_limits* limits) override; |
110 | | |
111 | | private: |
112 | | configuration m_configuration; |
113 | | |
114 | | std::vector<uint8_t> m_config_OBUs; |
115 | | }; |
116 | | |
117 | | |
118 | | class Box_av01 : public Box_VisualSampleEntry |
119 | | { |
120 | | public: |
121 | | Box_av01() |
122 | 4 | { |
123 | 4 | set_short_type(fourcc("av01")); |
124 | 4 | } |
125 | | }; |
126 | | |
127 | | class Box_a1op : public Box |
128 | | { |
129 | | public: |
130 | | Box_a1op() |
131 | 31 | { |
132 | 31 | set_short_type(fourcc("a1op")); |
133 | 31 | } |
134 | | |
135 | | uint8_t op_index = 0; |
136 | | |
137 | | std::string dump(Indent&) const override; |
138 | | |
139 | | Error write(StreamWriter& writer) const override; |
140 | | |
141 | | protected: |
142 | | Error parse(BitstreamRange& range, const heif_security_limits* limits) override; |
143 | | }; |
144 | | |
145 | | |
146 | | class Box_a1lx : public Box |
147 | | { |
148 | | public: |
149 | | Box_a1lx() |
150 | 25 | { |
151 | 25 | set_short_type(fourcc("a1lx")); |
152 | 25 | } |
153 | | |
154 | | uint32_t layer_size[3]{}; |
155 | | |
156 | | std::string dump(Indent&) const override; |
157 | | |
158 | | Error write(StreamWriter& writer) const override; |
159 | | |
160 | | protected: |
161 | | Error parse(BitstreamRange& range, const heif_security_limits* limits) override; |
162 | | }; |
163 | | |
164 | | |
165 | | class HeifPixelImage; |
166 | | |
167 | | Error fill_av1C_configuration(Box_av1C::configuration* inout_config, const std::shared_ptr<HeifPixelImage>& image); |
168 | | |
169 | | bool fill_av1C_configuration_from_stream(Box_av1C::configuration* out_config, const uint8_t* data, int dataSize); |
170 | | |
171 | | #endif |