Coverage Report

Created: 2026-09-14 07:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
24
{
30
24
  parse_full_box_header(range);
31
32
24
  if (get_version() > 0) {
33
11
    return unsupported_version_error("prfr");
34
11
  }
35
36
13
  uint8_t projection_type = (range.read8() & 0x1F);
37
13
  m_projection = static_cast<heif_omaf_image_projection>(projection_type);
38
13
  return range.get_error();
39
24
}
40
41
std::string Box_prfr::dump(Indent& indent) const
42
0
{
43
0
  std::ostringstream sstr;
44
0
  sstr << Box::dump(indent);
45
0
  sstr << indent << "projection_type: ";
46
0
  switch (m_projection) {
47
0
    case heif_omaf_image_projection_equirectangular:
48
0
      sstr << "equirectangular\n";
49
0
      break;
50
0
    case heif_omaf_image_projection_cube_map:
51
0
      sstr << "cube-map\n";
52
0
      break;
53
0
    default:
54
0
      sstr << "unknown (" << m_projection << ")\n";
55
0
      break;
56
0
  }
57
0
  return sstr.str();
58
0
}
59
60
Error Box_prfr::write(StreamWriter& writer) const
61
0
{
62
0
  if (static_cast<uint32_t>(m_projection) >= 32) {
63
0
    return {
64
0
      heif_error_Invalid_input,
65
0
      heif_suberror_Unspecified,
66
0
      "Image projection value out of the 5-bit prfr range."
67
0
    };
68
0
  }
69
70
0
  size_t box_start = reserve_box_header_space(writer);
71
0
  writer.write8(static_cast<uint8_t>(m_projection) & 0x1F);
72
0
  prepend_header(writer, box_start);
73
0
  return Error::Ok;
74
0
}
75
76
Error Box_prfr::set_image_projection(heif_omaf_image_projection projection)
77
0
{
78
0
  if (static_cast<uint32_t>(projection) >= 32) {
79
0
    return {
80
0
      heif_error_Invalid_input,
81
0
      heif_suberror_Unspecified,
82
0
      "Image projection value out of the 5-bit prfr range."
83
0
    };
84
0
  }
85
86
0
  m_projection = projection;
87
0
  return Error::Ok;
88
0
}