digiKam
heif_image.h
Go to the documentation of this file.
1 /*
2  * HEIF codec.
3  * Copyright (c) 2017 struktur AG, Dirk Farin <farin@struktur.de>
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_HEIF_IMAGE_H
23 #define LIBHEIF_HEIF_IMAGE_H
24 
25 #include "heif.h"
26 #include "error.h"
27 #include "box.h" // only for color_profile, TODO: maybe move the color_profiles to its own header
28 
29 #include <vector>
30 #include <memory>
31 #include <map>
32 #include <set>
33 
34 
35 namespace heif {
36 
39 
40 class HeifPixelImage : public std::enable_shared_from_this<HeifPixelImage>,
41  public ErrorBuffer
42 {
43  public:
44  explicit HeifPixelImage();
46 
47  void create(int width,int height, heif_colorspace colorspace, heif_chroma chroma);
48 
49  bool add_plane(heif_channel channel, int width, int height, int bit_depth);
50 
51  bool has_channel(heif_channel channel) const;
52 
53  // Has alpha information either as a separate channel or in the interleaved format.
54  bool has_alpha() const;
55 
56  int get_width() const { return m_width; }
57 
58  int get_height() const { return m_height; }
59 
60  int get_width(enum heif_channel channel) const;
61 
62  int get_height(enum heif_channel channel) const;
63 
64  heif_chroma get_chroma_format() const { return m_chroma; }
65 
66  heif_colorspace get_colorspace() const { return m_colorspace; }
67 
68  std::set<enum heif_channel> get_channel_set() const;
69 
70  int get_storage_bits_per_pixel(enum heif_channel channel) const;
71 
72  int get_bits_per_pixel(enum heif_channel channel) const;
73 
74  uint8_t* get_plane(enum heif_channel channel, int* out_stride);
75  const uint8_t* get_plane(enum heif_channel channel, int* out_stride) const;
76 
77  void copy_new_plane_from(const std::shared_ptr<const HeifPixelImage>& src_image,
78  heif_channel src_channel,
79  heif_channel dst_channel);
80  void fill_new_plane(heif_channel dst_channel, uint8_t value, int width, int height);
81 
82  void transfer_plane_from_image_as(std::shared_ptr<HeifPixelImage> source,
83  heif_channel src_channel,
84  heif_channel dst_channel);
85 
86  Error rotate_ccw(int angle_degrees,
87  std::shared_ptr<HeifPixelImage>& out_img);
88 
89  Error mirror_inplace(bool horizontal);
90 
91  Error crop(int left,int right,int top,int bottom,
92  std::shared_ptr<HeifPixelImage>& out_img) const;
93 
94  Error fill_RGB_16bit(uint16_t r, uint16_t g, uint16_t b, uint16_t a);
95 
96  Error overlay(std::shared_ptr<HeifPixelImage>& overlay, int dx,int dy);
97 
98  Error scale_nearest_neighbor(std::shared_ptr<HeifPixelImage>& output, int width,int height) const;
99 
100  void set_color_profile(std::shared_ptr<const color_profile> profile) { m_color_profile = profile; }
101 
102  std::shared_ptr<const color_profile> get_color_profile() { return m_color_profile; }
103 
104  private:
105  struct ImagePlane {
106  int width;
107  int height;
108  int bit_depth;
109 
110  uint8_t* mem; // aligned memory start
111  uint8_t* allocated_mem = nullptr; // unaligned memory we allocated
112  int stride;
113  };
114 
115  int m_width = 0;
116  int m_height = 0;
119  std::shared_ptr<const color_profile> m_color_profile;
120 
121  std::map<heif_channel, ImagePlane> m_planes;
122 };
123 
124 
125  std::shared_ptr<HeifPixelImage> convert_colorspace(const std::shared_ptr<HeifPixelImage>& input,
126  heif_colorspace colorspace,
127  heif_chroma chroma);
128 }
129 
130 #endif
Definition: error.h:50
Definition: error.h:75
Definition: heif_image.h:42
Error mirror_inplace(bool horizontal)
int get_height() const
Definition: heif_image.h:58
int get_width(enum heif_channel channel) const
int get_storage_bits_per_pixel(enum heif_channel channel) const
void transfer_plane_from_image_as(std::shared_ptr< HeifPixelImage > source, heif_channel src_channel, heif_channel dst_channel)
Error scale_nearest_neighbor(std::shared_ptr< HeifPixelImage > &output, int width, int height) const
Error rotate_ccw(int angle_degrees, std::shared_ptr< HeifPixelImage > &out_img)
void set_color_profile(std::shared_ptr< const color_profile > profile)
Definition: heif_image.h:100
heif_colorspace get_colorspace() const
Definition: heif_image.h:66
bool add_plane(heif_channel channel, int width, int height, int bit_depth)
heif_chroma get_chroma_format() const
Definition: heif_image.h:64
void copy_new_plane_from(const std::shared_ptr< const HeifPixelImage > &src_image, heif_channel src_channel, heif_channel dst_channel)
int get_bits_per_pixel(enum heif_channel channel) const
std::set< enum heif_channel > get_channel_set() const
std::shared_ptr< const color_profile > get_color_profile()
Definition: heif_image.h:102
int get_height(enum heif_channel channel) const
int get_width() const
Definition: heif_image.h:56
void fill_new_plane(heif_channel dst_channel, uint8_t value, int width, int height)
bool has_channel(heif_channel channel) const
uint8_t * get_plane(enum heif_channel channel, int *out_stride)
const uint8_t * get_plane(enum heif_channel channel, int *out_stride) const
bool has_alpha() const
Error crop(int left, int right, int top, int bottom, std::shared_ptr< HeifPixelImage > &out_img) const
void create(int width, int height, heif_colorspace colorspace, heif_chroma chroma)
Error fill_RGB_16bit(uint16_t r, uint16_t g, uint16_t b, uint16_t a)
Error overlay(std::shared_ptr< HeifPixelImage > &overlay, int dx, int dy)
heif_channel
Definition: heif.h:748
heif_colorspace
Definition: heif.h:741
@ heif_colorspace_undefined
Definition: heif.h:742
heif_chroma
Definition: heif.h:722
@ heif_chroma_undefined
Definition: heif.h:723
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: bitstream.h:41
int chroma_h_subsampling(heif_chroma c)
std::shared_ptr< HeifPixelImage > convert_colorspace(const std::shared_ptr< HeifPixelImage > &input, heif_colorspace colorspace, heif_chroma chroma)
int chroma_v_subsampling(heif_chroma c)