Coverage Report

Created: 2026-03-31 06:56

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
23
{
30
23
  parse_full_box_header(range);
31
32
23
  if (get_version() > 0) {
33
12
    return unsupported_version_error("prfr");
34
12
  }
35
36
11
  uint8_t projection_type = (range.read8() & 0x1F);
37
11
  switch (projection_type)
38
11
  {
39
2
  case 0x00:
40
2
    m_projection = heif_omaf_image_projection::heif_omaf_image_projection_equirectangular;
41
2
    break;
42
2
  case 0x01:
43
2
    m_projection = heif_omaf_image_projection::heif_omaf_image_projection_cube_map;
44
2
    break;
45
7
  default:
46
7
    m_projection = heif_omaf_image_projection::heif_omaf_image_projection_unknown;
47
7
    break;
48
11
  }
49
11
  return range.get_error();
50
11
}
51
52
std::string Box_prfr::dump(Indent& indent) const
53
0
{
54
0
  std::ostringstream sstr;
55
0
  sstr << Box::dump(indent);
56
0
  sstr << indent << "projection_type: ";
57
0
  switch (m_projection) {
58
0
    case heif_omaf_image_projection_equirectangular:
59
0
      sstr << "equirectangular\n";
60
0
      break;
61
0
    case heif_omaf_image_projection_cube_map:
62
0
      sstr << "cube-map\n";
63
0
      break;
64
0
    default:
65
0
      sstr << "unknown (" << m_projection << ")\n";
66
0
      break;
67
0
  }
68
0
  return sstr.str();
69
0
}
70
71
Error Box_prfr::write(StreamWriter& writer) const
72
0
{
73
0
  size_t box_start = reserve_box_header_space(writer);
74
0
  switch (m_projection) {
75
0
    case heif_omaf_image_projection::heif_omaf_image_projection_equirectangular:
76
0
      writer.write8(0x00);
77
0
      break;
78
0
    case heif_omaf_image_projection::heif_omaf_image_projection_cube_map:
79
0
      writer.write8(0x01);
80
0
      break;
81
0
    default:
82
0
      return {
83
0
        heif_error_Invalid_input,
84
0
        heif_suberror_Unspecified,
85
0
        "Unsupported image projection value."
86
0
    };
87
0
  }
88
0
  prepend_header(writer, box_start);
89
0
  return Error::Ok;
90
0
}
91
92
Error Box_prfr::set_image_projection(heif_omaf_image_projection projection)
93
0
{
94
0
  if ((projection == heif_omaf_image_projection::heif_omaf_image_projection_equirectangular) || (projection == heif_omaf_image_projection::heif_omaf_image_projection_cube_map)) {
95
0
    m_projection = projection;
96
0
    return Error::Ok;
97
0
  } else {
98
0
    return {
99
0
      heif_error_Invalid_input,
100
0
      heif_suberror_Unspecified,
101
0
      "Unsupported image projection value."
102
0
    };
103
0
  }
104
0
}