Coverage Report

Created: 2026-06-14 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/image-items/avif.cc
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
#include "image/pixelimage.h"
22
#include "avif.h"
23
#include "codecs/avif_dec.h"
24
#include "codecs/avif_enc.h"
25
#include "codecs/avif_boxes.h"
26
#include "bitstream.h"
27
#include "common_utils.h"
28
#include "api_structs.h"
29
#include "file.h"
30
#include <iomanip>
31
#include <limits>
32
#include <string>
33
#include <cstring>
34
#include <utility>
35
36
// https://aomediacodec.github.io/av1-spec/av1-spec.pdf
37
38
39
7.13k
ImageItem_AVIF::ImageItem_AVIF(HeifContext* ctx, heif_item_id id) : ImageItem(ctx, id)
40
7.13k
{
41
7.13k
  m_encoder = std::make_shared<Encoder_AVIF>();
42
7.13k
}
43
44
0
ImageItem_AVIF::ImageItem_AVIF(HeifContext* ctx) : ImageItem(ctx)
45
0
{
46
0
  m_encoder = std::make_shared<Encoder_AVIF>();
47
0
}
48
49
50
Error ImageItem_AVIF::initialize_decoder()
51
6.82k
{
52
6.82k
  auto av1C_box = get_property<Box_av1C>();
53
6.82k
  if (!av1C_box) {
54
156
    return Error{heif_error_Invalid_input,
55
156
                 heif_suberror_No_av1C_box};
56
156
  }
57
58
6.66k
  m_decoder = std::make_shared<Decoder_AVIF>(av1C_box);
59
60
6.66k
  return Error::Ok;
61
6.82k
}
62
63
void ImageItem_AVIF::set_decoder_input_data()
64
6.66k
{
65
6.66k
  DataExtent extent;
66
6.66k
  extent.set_from_image_item(get_context()->get_heif_file(), get_id());
67
68
6.66k
  m_decoder->set_data_extent(std::move(extent));
69
6.66k
}
70
71
72
Result<std::vector<uint8_t>> ImageItem_AVIF::read_bitstream_configuration_data() const
73
0
{
74
0
  return m_decoder->read_bitstream_configuration_data();
75
0
}
76
77
78
Result<std::shared_ptr<Decoder>> ImageItem_AVIF::get_decoder() const
79
52.6k
{
80
52.6k
  return {m_decoder};
81
52.6k
}
82
83
84
std::shared_ptr<Encoder> ImageItem_AVIF::get_encoder() const
85
0
{
86
0
  return m_encoder;
87
0
}