Coverage Report

Created: 2026-05-16 07:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/codecs/hevc_dec.cc
Line
Count
Source
1
/*
2
 * HEIF codec.
3
 * Copyright (c) 2024 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
#include "hevc_dec.h"
22
#include "hevc_boxes.h"
23
#include "error.h"
24
#include "context.h"
25
#include "plugins/nalu_utils.h"
26
27
#include <string>
28
29
30
Result<std::vector<uint8_t>> Decoder_HEVC::read_bitstream_configuration_data() const
31
7.70k
{
32
7.70k
  std::vector<uint8_t> data;
33
7.70k
  if (!m_hvcC->get_header_nals(&data)) {
34
0
    return Error{heif_error_Invalid_input,
35
0
                 heif_suberror_No_item_data};
36
0
  }
37
38
7.70k
  return data;
39
7.70k
}
40
41
42
int Decoder_HEVC::get_luma_bits_per_pixel() const
43
19.3k
{
44
19.3k
  return m_hvcC->get_configuration().bit_depth_luma;
45
19.3k
}
46
47
48
int Decoder_HEVC::get_chroma_bits_per_pixel() const
49
11.9k
{
50
11.9k
  return m_hvcC->get_configuration().bit_depth_chroma;
51
11.9k
}
52
53
54
Result<std::optional<ImageSize>> Decoder_HEVC::get_coded_image_size_from_config() const
55
8.89k
{
56
8.89k
  const auto& nal_arrays = m_hvcC->get_configuration().m_nal_array;
57
58
22.6k
  for (const auto& arr : nal_arrays) {
59
22.6k
    if (arr.m_NAL_unit_type != HEVC_NAL_UNIT_SPS_NUT || arr.m_nal_units.empty()) {
60
18.6k
      continue;
61
18.6k
    }
62
63
4.01k
    const std::vector<uint8_t>& sps = arr.m_nal_units[0];
64
4.01k
    HEVCDecoderConfigurationRecord scratch = m_hvcC->get_configuration();
65
4.01k
    uint32_t cropped_w = 0, cropped_h = 0;
66
4.01k
    ImageSize coded{};
67
4.01k
    Error e = parse_sps_for_hvcC_configuration(sps.data(), sps.size(), &scratch,
68
4.01k
                                               &cropped_w, &cropped_h, &coded);
69
4.01k
    if (e) {
70
410
      return e;
71
410
    }
72
73
3.60k
    return std::optional<ImageSize>{coded};
74
4.01k
  }
75
76
4.88k
  return std::optional<ImageSize>{};
77
8.89k
}
78
79
80
Error Decoder_HEVC::get_coded_image_colorspace(heif_colorspace* out_colorspace, heif_chroma* out_chroma) const
81
19.3k
{
82
19.3k
  *out_chroma = (heif_chroma) (m_hvcC->get_configuration().chroma_format);
83
84
19.3k
  if (*out_chroma == heif_chroma_monochrome) {
85
10.4k
    *out_colorspace = heif_colorspace_monochrome;
86
10.4k
  }
87
8.91k
  else {
88
8.91k
    *out_colorspace = heif_colorspace_YCbCr;
89
8.91k
  }
90
91
19.3k
  return Error::Ok;
92
19.3k
}