Coverage Report

Created: 2026-06-10 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/codecs/encoder.h
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
#ifndef HEIF_ENCODER_H
22
#define HEIF_ENCODER_H
23
24
#include "libheif/heif.h"
25
#include "error.h"
26
#include "libheif/heif_plugin.h"
27
28
#include <memory>
29
#include <string>
30
#include <utility>
31
#include <vector>
32
#include "sequences/seq_boxes.h"
33
34
class HeifPixelImage;
35
36
class Box;
37
38
39
class Encoder {
40
public:
41
0
  virtual ~Encoder() = default;
42
43
  struct CodedImageData {
44
    std::vector<std::shared_ptr<Box>> properties;
45
    std::vector<uint8_t> bitstream;
46
    CodingConstraints codingConstraints;
47
48
    // If 0, the encoded size is unknown.
49
    uint32_t encoded_image_width = 0;
50
    uint32_t encoded_image_height = 0;
51
52
    bool is_sync_frame = true; // TODO: set in encoder
53
    uintptr_t frame_nr = 0;
54
55
    void append(const uint8_t* data, size_t size);
56
57
    void append_with_4bytes_size(const uint8_t* data, size_t size);
58
  };
59
60
  // If the output format requires a specific nclx (like JPEG), return this. Otherwise, return NULL.
61
0
  virtual const heif_color_profile_nclx* get_forced_output_nclx() const { return nullptr; }
62
63
  Result<std::shared_ptr<HeifPixelImage>> convert_colorspace_for_encoding(const std::shared_ptr<HeifPixelImage>& image,
64
                                                                          heif_encoder* encoder,
65
                                                                          const heif_color_profile_nclx* user_requested_output_nclx,
66
                                                                          const heif_color_conversion_options* color_conversion_options,
67
                                                                          const heif_security_limits* security_limits);
68
69
  virtual Result<CodedImageData> encode(const std::shared_ptr<HeifPixelImage>& image,
70
                                        heif_encoder* encoder,
71
                                        const heif_encoding_options& options,
72
0
                                        heif_image_input_class input_class) { return {}; }
73
74
  // --- encode sequence
75
76
0
  virtual bool encode_sequence_started() const { return false; }
77
78
  virtual Error encode_sequence_frame(const std::shared_ptr<HeifPixelImage>& image,
79
                                      heif_encoder* encoder,
80
                                      const heif_sequence_encoding_options& options,
81
                                      heif_image_input_class input_class,
82
                                      uint32_t framerate_num, uint32_t framerate_denom,
83
0
                                      uintptr_t frame_number) { return {}; }
84
85
0
  virtual Error encode_sequence_flush(heif_encoder* encoder) { return {}; }
86
87
0
  virtual std::optional<CodedImageData> encode_sequence_get_data() { return std::nullopt; }
88
89
0
  virtual std::shared_ptr<Box_VisualSampleEntry> get_sample_description_box(const CodedImageData&) const { return {}; }
90
};
91
92
93
#endif