Coverage Report

Created: 2025-09-08 07:52

/src/libheif/libheif/codecs/decoder.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef HEIF_DECODER_H
22
#define HEIF_DECODER_H
23
24
#include "libheif/heif.h"
25
#include "box.h"
26
#include "error.h"
27
#include "file.h"
28
29
#include <memory>
30
#include <string>
31
#include <utility>
32
#include <vector>
33
#include "image-items/hevc.h"
34
35
36
// Specifies the input data for decoding.
37
// For images, this points to the iloc extents.
38
// For sequences, this points to the track data.
39
struct DataExtent
40
{
41
  std::shared_ptr<HeifFile> m_file;
42
  enum class Source : uint8_t { Raw, Image, FileRange } m_source = Source::Raw;
43
44
  // --- raw data
45
  mutable std::vector<uint8_t> m_raw; // also for cached data
46
47
  // --- image
48
  heif_item_id m_item_id = 0;
49
50
  // --- file range
51
  uint64_t m_offset = 0;
52
  uint32_t m_size = 0;
53
54
  void set_from_image_item(std::shared_ptr<HeifFile> file, heif_item_id item);
55
56
  void set_file_range(std::shared_ptr<HeifFile> file, uint64_t offset, uint32_t size);
57
58
  Result<std::vector<uint8_t>*> read_data() const;
59
60
  Result<std::vector<uint8_t>> read_data(uint64_t offset, uint64_t size) const;
61
};
62
63
64
class Decoder
65
{
66
public:
67
  static std::shared_ptr<Decoder> alloc_for_infe_type(const ImageItem* item);
68
69
  static std::shared_ptr<Decoder> alloc_for_sequence_sample_description_box(std::shared_ptr<const class Box_VisualSampleEntry> sample_description_box);
70
71
72
  virtual ~Decoder();
73
74
  virtual heif_compression_format get_compression_format() const = 0;
75
76
33.4k
  void set_data_extent(DataExtent extent) { m_data_extent = std::move(extent); }
77
78
0
  const DataExtent& get_data_extent() const { return m_data_extent; }
79
80
  // --- information about the image format
81
82
  [[nodiscard]] virtual int get_luma_bits_per_pixel() const = 0;
83
84
  [[nodiscard]] virtual int get_chroma_bits_per_pixel() const = 0;
85
86
  [[nodiscard]] virtual Error get_coded_image_colorspace(heif_colorspace*, heif_chroma*) const = 0;
87
88
  // --- raw data access
89
90
  [[nodiscard]] virtual Result<std::vector<uint8_t>> read_bitstream_configuration_data() const = 0;
91
92
  Result<std::vector<uint8_t>> get_compressed_data() const;
93
94
  // --- decoding
95
96
  virtual Result<std::shared_ptr<HeifPixelImage>>
97
  decode_single_frame_from_compressed_data(const struct heif_decoding_options& options,
98
                                           const struct heif_security_limits* limits);
99
100
private:
101
  DataExtent m_data_extent;
102
103
  const struct heif_decoder_plugin* m_decoder_plugin = nullptr;
104
  void* m_decoder = nullptr;
105
};
106
107
#endif