digiKam
heif_colorconversion.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 #include "heif_image.h"
23 #include <memory>
24 #include <vector>
25 
26 
27 namespace heif {
28 
29 struct ColorState
30 {
33  bool has_alpha = false;
34  int bits_per_pixel = 8;
35 
36  ColorState() = default;
39 
40  bool operator==(const ColorState&) const;
41 };
42 
43 
45  Speed,
46  Quality,
47  Memory,
48  Balanced
49 };
50 
51 
53  ColorConversionCosts() = default;
54 
55  ColorConversionCosts(float _speed, float _quality, float _memory) {
56  speed = _speed;
57  quality = _quality;
58  memory = _memory;
59  }
60 
61  float speed = 0;
62  float quality = 0;
63  float memory = 0;
64 
66  return { speed + b.speed,
67  quality + b.quality,
68  memory + b.memory };
69  }
70 
72  return speed * 0.3f + quality * 0.6f + memory * 0.1f;
73  }
74 };
75 
76 
78 {
80 };
81 
82 
84 {
87 };
88 
89 
91 {
92  public:
93  virtual ~ColorConversionOperation() = default;
94 
95  // We specify the target state to control the conversion into a direction that is most
96  // suitable for reaching the target state. That allows one conversion operation to
97  // provide a range of conversion options.
98  // Also returns the cost for this conversion.
99  virtual std::vector<ColorStateWithCost>
101  ColorState target_state,
103 
104  virtual std::shared_ptr<HeifPixelImage>
105  convert_colorspace(const std::shared_ptr<const HeifPixelImage>& input,
106  ColorState target_state,
108 };
109 
110 
112 {
113  public:
114  bool construct_pipeline(ColorState input_state,
115  ColorState target_state,
117 
118  std::shared_ptr<HeifPixelImage>
119  convert_image(const std::shared_ptr<HeifPixelImage>& input);
120 
121  void debug_dump_pipeline() const;
122 
123  private:
124  std::vector<std::shared_ptr<ColorConversionOperation>> m_operations;
125  ColorState m_target_state;
126  ColorConversionOptions m_options;
127 };
128 
129 }
Definition: heif_colorconversion.h:91
virtual std::vector< ColorStateWithCost > state_after_conversion(ColorState input_state, ColorState target_state, ColorConversionOptions options=ColorConversionOptions())=0
virtual std::shared_ptr< HeifPixelImage > convert_colorspace(const std::shared_ptr< const HeifPixelImage > &input, ColorState target_state, ColorConversionOptions options=ColorConversionOptions())=0
virtual ~ColorConversionOperation()=default
Definition: heif_colorconversion.h:112
std::shared_ptr< HeifPixelImage > convert_image(const std::shared_ptr< HeifPixelImage > &input)
bool construct_pipeline(ColorState input_state, ColorState target_state, ColorConversionOptions options=ColorConversionOptions())
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
Definition: bitstream.h:41
ColorConversionCriterion
Definition: heif_colorconversion.h:44
Definition: heif_colorconversion.h:52
ColorConversionCosts operator+(const ColorConversionCosts &b) const
Definition: heif_colorconversion.h:65
float quality
Definition: heif_colorconversion.h:62
float memory
Definition: heif_colorconversion.h:63
ColorConversionCosts(float _speed, float _quality, float _memory)
Definition: heif_colorconversion.h:55
float total(ColorConversionCriterion) const
Definition: heif_colorconversion.h:71
float speed
Definition: heif_colorconversion.h:61
Definition: heif_colorconversion.h:78
ColorConversionCriterion criterion
Definition: heif_colorconversion.h:79
Definition: heif_colorconversion.h:84
ColorState color_state
Definition: heif_colorconversion.h:85
ColorConversionCosts costs
Definition: heif_colorconversion.h:86
Definition: heif_colorconversion.h:30
ColorState(heif_colorspace colorspace, heif_chroma chroma, bool has_alpha, int bits_per_pixel)
Definition: heif_colorconversion.h:37
ColorState()=default
heif_chroma chroma
Definition: heif_colorconversion.h:32
int bits_per_pixel
Definition: heif_colorconversion.h:34
bool has_alpha
Definition: heif_colorconversion.h:33
bool operator==(const ColorState &) const
heif_colorspace colorspace
Definition: heif_colorconversion.h:31