/src/libheif/libheif/image-items/unc_image.h
Line | Count | Source |
1 | | /* |
2 | | * HEIF codec. |
3 | | * Copyright (c) 2023 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 | | |
22 | | #ifndef LIBHEIF_UNC_IMAGE_H |
23 | | #define LIBHEIF_UNC_IMAGE_H |
24 | | |
25 | | #include "image/pixelimage.h" |
26 | | #include "file.h" |
27 | | #include "context.h" |
28 | | #include "libheif/heif_uncompressed.h" |
29 | | |
30 | | #include <cstdint> |
31 | | #include <string> |
32 | | #include <vector> |
33 | | #include <memory> |
34 | | #include <set> |
35 | | #include "codecs/uncompressed/unc_encoder.h" |
36 | | |
37 | | class unc_encoder; |
38 | | class HeifContext; |
39 | | |
40 | | |
41 | | class ImageItem_uncompressed : public ImageItem |
42 | | { |
43 | | public: |
44 | | ImageItem_uncompressed(HeifContext* ctx, heif_item_id id); |
45 | | |
46 | | ImageItem_uncompressed(HeifContext* ctx); |
47 | | |
48 | 200 | uint32_t get_infe_type() const override { return fourcc("unci"); } |
49 | | |
50 | 0 | heif_compression_format get_compression_format() const override { return heif_compression_uncompressed; } |
51 | | |
52 | | // Instead of storing alpha in a separate unci, this is put into the main image item |
53 | 0 | const char* get_auxC_alpha_channel_type() const override { return nullptr; } |
54 | | |
55 | | bool has_coded_alpha_channel() const override; |
56 | | |
57 | | // const heif_color_profile_nclx* get_forced_output_nclx() const override { return nullptr; } |
58 | | |
59 | 0 | bool is_ispe_essential() const override { return true; } |
60 | | |
61 | | void get_tile_size(uint32_t& w, uint32_t& h) const override; |
62 | | |
63 | | // Walk the cmpd / uncC / cpat property boxes and populate |
64 | | // ImageDescription::m_components with one ComponentDescription per uncC |
65 | | // component plus one (has_data_plane=false) per extra cpat reference |
66 | | // component. Called once from ImageItem::set_properties(). |
67 | | void populate_component_descriptions() override; |
68 | | |
69 | | // Code from encode_uncompressed_image() has been moved to here. |
70 | | |
71 | | Result<std::shared_ptr<HeifPixelImage>> decode_compressed_image(const heif_decoding_options& options, |
72 | | bool decode_tile_only, uint32_t tile_x0, uint32_t tile_y0, |
73 | | DecodeTraversalState decode_state) const override; |
74 | | |
75 | | heif_image_tiling get_heif_image_tiling() const override; |
76 | | |
77 | | Error initialize_decoder() override; |
78 | | |
79 | | void set_decoder_input_data() override; |
80 | | |
81 | | heif_brand2 get_compatible_brand() const override; |
82 | | |
83 | | public: |
84 | | |
85 | | // --- encoding |
86 | | |
87 | | Result<Encoder::CodedImageData> encode(const std::shared_ptr<HeifPixelImage>& image, |
88 | | heif_encoder* encoder, |
89 | | const heif_encoding_options& options, |
90 | | heif_image_input_class input_class) override; |
91 | | |
92 | | static Result<std::shared_ptr<ImageItem_uncompressed> > add_unci_item(HeifContext* ctx, |
93 | | const heif_unci_image_parameters* parameters, |
94 | | const heif_encoding_options* encoding_options, |
95 | | const std::shared_ptr<const HeifPixelImage>& prototype); |
96 | | |
97 | | Error add_image_tile(uint32_t tile_x, uint32_t tile_y, const std::shared_ptr<const HeifPixelImage>& image, bool save_alpha); |
98 | | |
99 | | protected: |
100 | | Result<std::shared_ptr<Decoder>> get_decoder() const override; |
101 | | |
102 | | std::shared_ptr<Encoder> get_encoder() const override; |
103 | | |
104 | | private: |
105 | | // The tiling that is exposed through the API. This is the uncC tiling, unless its |
106 | | // tiles cannot be decoded independently because of the generic compression. In that |
107 | | // case, the image is exposed as a single tile and false is returned. |
108 | | bool get_exposed_tiling(uint32_t& num_columns, uint32_t& num_rows) const; |
109 | | |
110 | | std::shared_ptr<class Decoder_uncompressed> m_decoder; |
111 | | std::shared_ptr<class Encoder_uncompressed> m_encoder; |
112 | | |
113 | | std::unique_ptr<const unc_encoder> m_unc_encoder; |
114 | | heif_encoding_options m_tile_encoding_options; |
115 | | |
116 | | /* |
117 | | Result<ImageItem::CodedImageData> generate_headers(const std::shared_ptr<const HeifPixelImage>& src_image, |
118 | | const heif_unci_image_parameters* parameters, |
119 | | const struct heif_encoding_options* options); |
120 | | */ |
121 | | |
122 | | uint64_t m_next_tile_write_pos = 0; |
123 | | }; |
124 | | |
125 | | #endif //LIBHEIF_UNC_IMAGE_H |