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 float displayNits,
154 const KoColorSpace *colorSpace);
155};
156} // namespace SDR
157
158namespace Planar
159{
161 template<typename Arch>
162 static void create(const int luma,
163 LinearizePolicy policy,
164 bool applyOOTF,
165 bool hasAlpha,
166 const int width,
167 const int height,
168 const uint8_t *imgR,
169 const int strideR,
170 const uint8_t *imgG,
171 const int strideG,
172 const uint8_t *imgB,
173 const int strideB,
174 const uint8_t *imgA,
175 const int strideA,
177 float displayGamma,
178 float displayNits,
179 const KoColorSpace *colorSpace);
180};
181} // namespace Planar
182
183namespace HDR
184{
186 template<typename Arch>
187 static void create(const int luma,
188 LinearizePolicy linearizePolicy,
189 bool applyOOTF,
190 const int channels,
191 const int width,
192 const int height,
193 const uint8_t *img,
194 const int stride,
196 float displayGamma,
197 float displayNits,
198 const KoColorSpace *colorSpace);
199};
200} // namespace HDR
201
202#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, float displayNits, 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, float displayNits, 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, float displayNits, const KoColorSpace *colorSpace)