Coverage Report

Created: 2025-07-23 08:18

/src/libheif/libheif/image-items/avif.cc
Line
Count
Source (jump to first uncovered line)
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 "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
31.0k
ImageItem_AVIF::ImageItem_AVIF(HeifContext* ctx, heif_item_id id) : ImageItem(ctx, id)
40
31.0k
{
41
31.0k
  m_encoder = std::make_shared<Encoder_AVIF>();
42
31.0k
}
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
30.9k
{
52
30.9k
  auto av1C_box = get_property<Box_av1C>();
53
30.9k
  if (!av1C_box) {
54
44
    return Error{heif_error_Invalid_input,
55
44
                 heif_suberror_No_av1C_box};
56
44
  }
57
58
30.9k
  m_decoder = std::make_shared<Decoder_AVIF>(av1C_box);
59
60
30.9k
  return Error::Ok;
61
30.9k
}
62
63
void ImageItem_AVIF::set_decoder_input_data()
64
30.9k
{
65
30.9k
  DataExtent extent;
66
30.9k
  extent.set_from_image_item(get_context()->get_heif_file(), get_id());
67
68
30.9k
  m_decoder->set_data_extent(std::move(extent));
69
30.9k
}
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<class Decoder>> ImageItem_AVIF::get_decoder() const
79
58.2k
{
80
58.2k
  return {m_decoder};
81
58.2k
}
82
83
84
std::shared_ptr<class Encoder> ImageItem_AVIF::get_encoder() const
85
0
{
86
0
  return m_encoder;
87
0
}