Coverage Report

Created: 2026-01-20 07:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/sequences/track_visual.h
Line
Count
Source
1
/*
2
 * HEIF image base codec.
3
 * Copyright (c) 2025 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 LIBHEIF_TRACK_VISUAL_H
22
#define LIBHEIF_TRACK_VISUAL_H
23
24
#include "track.h"
25
#include <string>
26
#include <memory>
27
#include <vector>
28
#include <map>
29
30
31
class Track_Visual : public Track {
32
public:
33
  //Track(HeifContext* ctx);
34
35
  Track_Visual(HeifContext* ctx, uint32_t track_id, uint16_t width, uint16_t height,
36
               const TrackOptions* options, uint32_t handler_type);
37
38
  Track_Visual(HeifContext* ctx);
39
40
  ~Track_Visual() override;
41
42
  // load track from file
43
  Error load(const std::shared_ptr<Box_trak>&) override;
44
45
  [[nodiscard]] Error initialize_after_parsing(HeifContext* ctx, const std::vector<std::shared_ptr<Track>>& all_tracks) override;
46
47
0
  uint16_t get_width() const { return m_width; }
48
49
0
  uint16_t get_height() const { return m_height; }
50
51
  bool has_alpha_channel() const override;
52
53
  Result<std::shared_ptr<HeifPixelImage>> decode_next_image_sample(const heif_decoding_options& options);
54
55
  Error encode_image(std::shared_ptr<HeifPixelImage> image,
56
                     heif_encoder* encoder,
57
                     const heif_sequence_encoding_options* options,
58
                     heif_image_input_class image_class);
59
60
  Error encode_end_of_sequence(heif_encoder* encoder);
61
62
  Error finalize_track() override;
63
64
  heif_brand2 get_compatible_brand() const;
65
66
private:
67
  uint16_t m_width = 0;
68
  uint16_t m_height = 0;
69
  heif_image_input_class m_image_class;
70
71
  uintptr_t m_current_frame_nr = 0;
72
  bool m_generated_sample_description_box = false;
73
74
  struct FrameUserData
75
  {
76
    int sample_duration = 0;
77
78
    std::optional<std::string> gimi_content_id;
79
    heif_tai_timestamp_packet* tai_timestamp = nullptr;
80
81
    void release()
82
0
    {
83
0
      heif_tai_timestamp_packet_release(tai_timestamp);
84
0
      tai_timestamp = nullptr;
85
0
    }
86
  };
87
88
  // map frame number to user data
89
  std::map<uintptr_t, FrameUserData> m_frame_user_data;
90
91
  int m_sample_duration = 0; // TODO: pass this through encoder or handle it correctly with frame reordering
92
93
  // If there is an alpha-channel track associated with this color track, we reference it from here
94
  std::shared_ptr<Track_Visual> m_aux_alpha_track;
95
96
  heif_encoder* m_active_encoder = nullptr;
97
  std::unique_ptr<heif_encoder> m_alpha_track_encoder;
98
99
  Result<bool> process_encoded_data(heif_encoder* encoder);
100
};
101
102
103
104
#endif //LIBHEIF_TRACK_VISUAL_H