Coverage Report

Created: 2026-09-28 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/api_structs.h
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
#ifndef HEIF_API_STRUCTS_H
22
#define HEIF_API_STRUCTS_H
23
24
#include "image/pixelimage.h"
25
#include "context.h"
26
#include "error.h"
27
28
#include <memory>
29
#include <vector>
30
#include <string>
31
#include <exception>
32
#include <new>
33
#include <stdexcept>
34
#include "image-items/image_item.h"
35
36
37
// Run a C API entry point body and translate any escaping C++ exception into a
38
// heif_error. No exception may cross the extern "C" boundary (that is undefined
39
// behaviour for C callers), and an out-of-memory condition must not abort the
40
// process (GHSA-7p2q-crf9-xm46). The returned errors have string-literal messages,
41
// so reporting them never touches the allocator that is already failing.
42
template <typename F>
43
static inline heif_error exception_guard(F&& body) noexcept
44
19.6k
{
45
19.6k
  try {
46
19.6k
    return body();
47
19.6k
  }
48
19.6k
  catch (const std::bad_alloc&) {
49
0
    return heif_error_out_of_memory;
50
0
  }
51
19.6k
  catch (const std::length_error&) {
52
    // e.g. a std::vector/std::string asked to exceed max_size()
53
0
    return heif_error_out_of_memory;
54
0
  }
55
19.6k
  catch (const std::exception&) {
56
0
    return heif_error_internal_exception;
57
0
  }
58
19.6k
  catch (...) {
59
0
    return heif_error_internal_exception;
60
0
  }
61
19.6k
}
Unexecuted instantiation: heif_sequences.cc:heif_error exception_guard<heif_track_get_next_raw_sequence_sample2(heif_track*, heif_raw_sequence_sample**, heif_decoding_options const*)::$_0>(heif_track_get_next_raw_sequence_sample2(heif_track*, heif_raw_sequence_sample**, heif_decoding_options const*)::$_0&&)
Unexecuted instantiation: heif_sequences.cc:heif_error exception_guard<heif_track_decode_next_image::$_0>(heif_track_decode_next_image::$_0&&)
heif_decoding.cc:heif_error exception_guard<heif_decode_image::$_0>(heif_decode_image::$_0&&)
Line
Count
Source
44
6.66k
{
45
6.66k
  try {
46
6.66k
    return body();
47
6.66k
  }
48
6.66k
  catch (const std::bad_alloc&) {
49
0
    return heif_error_out_of_memory;
50
0
  }
51
6.66k
  catch (const std::length_error&) {
52
    // e.g. a std::vector/std::string asked to exceed max_size()
53
0
    return heif_error_out_of_memory;
54
0
  }
55
6.66k
  catch (const std::exception&) {
56
0
    return heif_error_internal_exception;
57
0
  }
58
6.66k
  catch (...) {
59
0
    return heif_error_internal_exception;
60
0
  }
61
6.66k
}
heif_context.cc:heif_error exception_guard<heif_context_read_from_file::$_0>(heif_context_read_from_file::$_0&&)
Line
Count
Source
44
12.9k
{
45
12.9k
  try {
46
12.9k
    return body();
47
12.9k
  }
48
12.9k
  catch (const std::bad_alloc&) {
49
0
    return heif_error_out_of_memory;
50
0
  }
51
12.9k
  catch (const std::length_error&) {
52
    // e.g. a std::vector/std::string asked to exceed max_size()
53
0
    return heif_error_out_of_memory;
54
0
  }
55
12.9k
  catch (const std::exception&) {
56
0
    return heif_error_internal_exception;
57
0
  }
58
12.9k
  catch (...) {
59
0
    return heif_error_internal_exception;
60
0
  }
61
12.9k
}
Unexecuted instantiation: heif_context.cc:heif_error exception_guard<heif_context_read_from_memory::$_0>(heif_context_read_from_memory::$_0&&)
Unexecuted instantiation: heif_context.cc:heif_error exception_guard<heif_context_read_from_memory_without_copy::$_0>(heif_context_read_from_memory_without_copy::$_0&&)
Unexecuted instantiation: heif_context.cc:heif_error exception_guard<heif_context_read_from_reader::$_0>(heif_context_read_from_reader::$_0&&)
62
63
struct heif_image_handle
64
{
65
  std::shared_ptr<ImageItem> image;
66
67
  // store reference to keep the context alive while we are using the handle (issue #147)
68
  std::shared_ptr<HeifContext> context;
69
};
70
71
72
struct heif_track
73
{
74
  std::shared_ptr<Track> track;
75
76
  // store reference to keep the context alive while we are using the handle (issue #147)
77
  std::shared_ptr<HeifContext> context;
78
};
79
80
struct heif_raw_sequence_sample
81
{
82
  ~heif_raw_sequence_sample()
83
0
  {
84
0
    heif_tai_timestamp_packet_release(timestamp);
85
0
  }
86
87
  std::vector<uint8_t> data;
88
  uint32_t duration = 0;
89
90
  heif_tai_timestamp_packet* timestamp = nullptr;
91
  std::string gimi_sample_content_id;
92
};
93
94
95
struct heif_image
96
{
97
  std::shared_ptr<HeifPixelImage> image;
98
};
99
100
101
struct heif_context
102
{
103
  std::shared_ptr<HeifContext> context;
104
};
105
106
107
struct heif_encoder
108
{
109
  explicit heif_encoder(const heif_encoder_plugin* plugin);
110
111
  ~heif_encoder();
112
113
  heif_error alloc();
114
115
  void release();
116
117
  void copy_parameters_from(const heif_encoder& src);
118
119
120
  const struct heif_encoder_plugin* plugin;
121
  void* encoder = nullptr;
122
};
123
124
125
struct heif_region_item
126
{
127
  std::shared_ptr<HeifContext> context;
128
  std::shared_ptr<RegionItem> region_item;
129
};
130
131
132
struct heif_region
133
{
134
  std::shared_ptr<HeifContext> context; // we need this to perform coordinate transformation
135
  //heif_item_id parent_region_item_id; // we need this to perform coordinate transformation
136
  std::shared_ptr<RegionItem> region_item;
137
  std::shared_ptr<RegionGeometry> region;
138
};
139
140
struct heif_text_item
141
{
142
  std::shared_ptr<HeifContext> context;
143
  std::shared_ptr<TextItem> text_item;
144
};
145
146
147
#endif