/src/libheif/libheif/omaf_boxes.cc
Line | Count | Source |
1 | | /* |
2 | | * libheif OMAF (ISO/IEC 23090-2) |
3 | | * |
4 | | * Copyright (c) 2026 Brad Hards <bradh@frogmouth.net> |
5 | | * |
6 | | * This file is part of libheif. |
7 | | * |
8 | | * libheif is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as |
10 | | * published by the Free Software Foundation, either version 3 of |
11 | | * the License, or (at your option) any later version. |
12 | | * |
13 | | * libheif is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU Lesser General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with libheif. If not, see <http://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include "omaf_boxes.h" |
23 | | |
24 | | #include <memory> |
25 | | #include <string> |
26 | | |
27 | | |
28 | | Error Box_prfr::parse(BitstreamRange& range, const heif_security_limits* limits) |
29 | 878 | { |
30 | 878 | parse_full_box_header(range); |
31 | | |
32 | 878 | if (get_version() > 0) { |
33 | 100 | return unsupported_version_error("prfr"); |
34 | 100 | } |
35 | | |
36 | 778 | uint8_t projection_type = (range.read8() & 0x1F); |
37 | 778 | m_projection = static_cast<heif_omaf_image_projection>(projection_type); |
38 | 778 | return range.get_error(); |
39 | 878 | } |
40 | | |
41 | | void Box_prfr::dump(std::ostream& sstr, Indent& indent, bool full_log) const |
42 | 728 | { |
43 | 728 | Box::dump(sstr, indent, full_log); |
44 | 728 | sstr << indent << "projection_type: "; |
45 | 728 | switch (m_projection) { |
46 | 94 | case heif_omaf_image_projection_equirectangular: |
47 | 94 | sstr << "equirectangular\n"; |
48 | 94 | break; |
49 | 382 | case heif_omaf_image_projection_cube_map: |
50 | 382 | sstr << "cube-map\n"; |
51 | 382 | break; |
52 | 252 | default: |
53 | 252 | sstr << "unknown (" << m_projection << ")\n"; |
54 | 252 | break; |
55 | 728 | } |
56 | 728 | return; |
57 | 728 | } |
58 | | |
59 | | Error Box_prfr::write(StreamWriter& writer) const |
60 | 0 | { |
61 | 0 | if (static_cast<uint32_t>(m_projection) >= 32) { |
62 | 0 | return { |
63 | 0 | heif_error_Invalid_input, |
64 | 0 | heif_suberror_Unspecified, |
65 | 0 | "Image projection value out of the 5-bit prfr range." |
66 | 0 | }; |
67 | 0 | } |
68 | | |
69 | 0 | size_t box_start = reserve_box_header_space(writer); |
70 | 0 | writer.write8(static_cast<uint8_t>(m_projection) & 0x1F); |
71 | 0 | prepend_header(writer, box_start); |
72 | 0 | return Error::Ok; |
73 | 0 | } |
74 | | |
75 | | Error Box_prfr::set_image_projection(heif_omaf_image_projection projection) |
76 | 0 | { |
77 | 0 | if (static_cast<uint32_t>(projection) >= 32) { |
78 | 0 | return { |
79 | 0 | heif_error_Invalid_input, |
80 | 0 | heif_suberror_Unspecified, |
81 | 0 | "Image projection value out of the 5-bit prfr range." |
82 | 0 | }; |
83 | 0 | } |
84 | | |
85 | 0 | m_projection = projection; |
86 | 0 | return Error::Ok; |
87 | 0 | } |