Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_heif_import_tools.h
Go to the documentation of this file.
1
8#ifndef KIS_HEIF_IMPORT_TOOLS_H
9#define KIS_HEIF_IMPORT_TOOLS_H
10
11#include <cstdint>
12
13#include <KoColorSpace.h>
14#include <KoColorSpaceTraits.h>
16#include <kis_iterator_ng.h>
17
18namespace Gray
19{
20template<int luma>
22 const uint8_t *imgG,
23 int strideG,
24 int x,
25 int y)
26{
27 if (luma == 8) {
28 KoGrayU8Traits::setGray(it->rawData(), imgG[y * strideG + x]);
29 } else {
30 uint16_t source =
31 KoGrayU16Traits::nativeArray(imgG)[y * (strideG / 2) + (x)];
32
33 if (luma == 10) {
35 it->rawData(),
36 static_cast<uint16_t>(float(0x03ffu & (source))
38 } else if (luma == 12) {
40 it->rawData(),
41 static_cast<uint16_t>(float(0x0fffu & (source))
43 } else {
45 it->rawData(),
46 static_cast<uint16_t>(float(source) * multiplier16bit));
47 }
48 }
49}
50
51template<int luma, bool hasAlpha>
53 const uint8_t *imgA,
54 int strideA,
55 int x,
56 int y)
57{
58 if (hasAlpha) {
59 if (luma == 8) {
60 KoGrayU8Traits::setOpacity(it->rawData(),
61 quint8(imgA[y * strideA + x]),
62 1);
63 } else {
64 uint16_t source =
65 KoGrayU16Traits::nativeArray(imgA)[y * (strideA / 2) + x];
66 if (luma == 10) {
68 it->rawData(),
69 static_cast<qreal>(float(0x0fff & (source))
71 1);
72 } else if (luma == 12) {
74 it->rawData(),
75 static_cast<qreal>(float(0x0fff & (source))
77 1);
78 } else {
80 it->rawData(),
81 static_cast<qreal>(float(source) * multiplier16bit),
82 1);
83 }
84 }
85 } else {
86 if (luma == 8) {
88 } else {
90 }
91 }
92}
93
94template<int luma, bool hasAlpha>
95inline void readLayer(const int width,
96 const int height,
98 const uint8_t *imgG,
99 const uint8_t *imgA,
100 const int strideG,
101 const int strideA)
102{
103 for (int y = 0; y < height; y++) {
104 for (int x = 0; x < width; x++) {
105 applyValue<luma>(it, imgG, strideG, x, y);
106
107 applyAlpha<luma, hasAlpha>(it, imgA, strideA, x, y);
108 it->nextPixel();
109 }
110
111 it->nextRow();
112 }
113}
114
115template<int luma, typename... Args>
116inline auto readPlanarWithLuma(bool hasAlpha, Args &&...args)
117{
118 if (hasAlpha) {
119 return Gray::readLayer<luma, true>(std::forward<Args>(args)...);
120 } else {
121 return Gray::readLayer<luma, false>(std::forward<Args>(args)...);
122 }
123}
124
125template<typename... Args>
126inline auto readPlanarLayer(const int luma, Args &&...args)
127{
128 if (luma == 8) {
129 return readPlanarWithLuma<8>(std::forward<Args>(args)...);
130 } else if (luma == 10) {
131 return readPlanarWithLuma<10>(std::forward<Args>(args)...);
132 } else if (luma == 12) {
133 return readPlanarWithLuma<12>(std::forward<Args>(args)...);
134 } else {
135 return readPlanarWithLuma<16>(std::forward<Args>(args)...);
136 }
137}
138} // namespace Gray
139
140namespace SDR
141{
143 template<typename Arch>
144 static void create(LinearizePolicy policy,
145 bool applyOOTF,
146 bool hasAlpha,
147 const int width,
148 const int height,
149 const uint8_t *img,
150 const int stride,
152 float displayGamma,
153 const KoColorSpace *colorSpace);
154};
155} // namespace SDR
156
157namespace Planar
158{
160 template<typename Arch>
161 static void create(const int luma,
162 LinearizePolicy policy,
163 bool applyOOTF,
164 bool hasAlpha,
165 const int width,
166 const int height,
167 const uint8_t *imgR,
168 const int strideR,
169 const uint8_t *imgG,
170 const int strideG,
171 const uint8_t *imgB,
172 const int strideB,
173 const uint8_t *imgA,
174 const int strideA,
176 float displayGamma,
177 const KoColorSpace *colorSpace);
178};
179} // namespace Planar
180
181namespace HDR
182{
184 template<typename Arch>
185 static void create(const int luma,
186 LinearizePolicy linearizePolicy,
187 bool applyOOTF,
188 const int channels,
189 const int width,
190 const int height,
191 const uint8_t *img,
192 const int stride,
194 float displayGamma,
195 const KoColorSpace *colorSpace);
196};
197} // namespace HDR
198
199#endif // KIS_HEIF_IMPORT_TOOLS_H
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
const quint8 OPACITY_OPAQUE_U8
static constexpr float max16bit
LinearizePolicy
The KoColorTransferFunctions class.
static constexpr float multiplier12bit
static constexpr float multiplier10bit
static constexpr float multiplier16bit
auto readPlanarWithLuma(bool hasAlpha, Args &&...args)
void applyValue(const quint8 *data, uint8_t *ptrG, int strideG, int x, int y)
void readLayer(const int width, const int height, KisHLineIteratorSP it, const uint8_t *imgG, const uint8_t *imgA, const int strideG, const int strideA)
void applyAlpha(const quint8 *data, uint8_t *ptrA, const int strideA, int x, int y)
auto readPlanarLayer(const int luma, Args &&...args)
static void create(const int luma, LinearizePolicy linearizePolicy, bool applyOOTF, const int channels, const int width, const int height, const uint8_t *img, const int stride, KisHLineIteratorSP it, float displayGamma, const KoColorSpace *colorSpace)
static const channels_type * nativeArray(const quint8 *a)
static void setOpacity(quint8 *pixels, quint8 alpha, qint32 nPixels)
static void setGray(quint8 *data, channels_type nv)
Set the gray component.
static void create(const int luma, LinearizePolicy policy, bool applyOOTF, bool hasAlpha, const int width, const int height, const uint8_t *imgR, const int strideR, const uint8_t *imgG, const int strideG, const uint8_t *imgB, const int strideB, const uint8_t *imgA, const int strideA, KisHLineIteratorSP it, float displayGamma, const KoColorSpace *colorSpace)
static void create(LinearizePolicy policy, bool applyOOTF, bool hasAlpha, const int width, const int height, const uint8_t *img, const int stride, KisHLineIteratorSP it, float displayGamma, const KoColorSpace *colorSpace)