Krita Source Code Documentation
Loading...
Searching...
No Matches
KisWaylandSurfaceColorimetry.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QDebug>
10
11namespace KisSurfaceColorimetry {
12
14{
16
17 // Map transfer function
18 if (this->tfNamed) {
19 switch (*this->tfNamed) {
20 case QtWayland::wp_color_manager_v1::transfer_function_bt1886:
22 break;
23 case QtWayland::wp_color_manager_v1::transfer_function_gamma22:
25 break;
26 case QtWayland::wp_color_manager_v1::transfer_function_gamma28:
28 break;
29 case QtWayland::wp_color_manager_v1::transfer_function_st240:
31 break;
32 case QtWayland::wp_color_manager_v1::transfer_function_ext_linear:
34 break;
35 case QtWayland::wp_color_manager_v1::transfer_function_log_100:
37 break;
38 case QtWayland::wp_color_manager_v1::transfer_function_log_316:
40 break;
41 case QtWayland::wp_color_manager_v1::transfer_function_xvycc:
43 break;
44 case QtWayland::wp_color_manager_v1::transfer_function_srgb:
46 break;
47 case QtWayland::wp_color_manager_v1::transfer_function_ext_srgb:
49 break;
50 case QtWayland::wp_color_manager_v1::transfer_function_st2084_pq:
52 break;
53 case QtWayland::wp_color_manager_v1::transfer_function_st428:
55 break;
56 case QtWayland::wp_color_manager_v1::transfer_function_hlg:
58 break;
59 }
60 } else if (this->tfGamma) {
61 description.colorSpace.transferFunction = *this->tfGamma;
62 }
63
64 // Map primaries
65 if (this->namedContainer) {
66 switch (*this->namedContainer) {
67 case QtWayland::wp_color_manager_v1::primaries_srgb:
69 break;
70 case QtWayland::wp_color_manager_v1::primaries_pal_m:
72 break;
73 case QtWayland::wp_color_manager_v1::primaries_pal:
75 break;
76 case QtWayland::wp_color_manager_v1::primaries_ntsc:
78 break;
79 case QtWayland::wp_color_manager_v1::primaries_generic_film:
81 break;
82 case QtWayland::wp_color_manager_v1::primaries_bt2020:
84 break;
85 case QtWayland::wp_color_manager_v1::primaries_cie1931_xyz:
87 break;
88 case QtWayland::wp_color_manager_v1::primaries_dci_p3:
90 break;
91 case QtWayland::wp_color_manager_v1::primaries_display_p3:
93 break;
94 case QtWayland::wp_color_manager_v1::primaries_adobe_rgb:
96 break;
97 }
98 } else if (this->container) {
99 description.colorSpace.primaries = this->container->toColorimetry();
100 }
101
102 // Map luminance
103 if (this->luminances) {
104 description.colorSpace.luminance = this->luminances;
105 }
106
107 // Map mastering info
108 if (this->target || this->masteringLuminance) {
110
111 if (this->target) {
112 masteringInfo.primaries = this->target->toColorimetry();
113 } else if (std::holds_alternative<KisSurfaceColorimetry::Colorimetry>(description.colorSpace.primaries)) {
114 masteringInfo.primaries = std::get<KisSurfaceColorimetry::Colorimetry>(description.colorSpace.primaries);
115 } else if (this->namedContainer) {
116 switch (*this->namedContainer) {
117 case QtWayland::wp_color_manager_v1::primaries_srgb:
119 break;
120 case QtWayland::wp_color_manager_v1::primaries_pal_m:
122 break;
123 case QtWayland::wp_color_manager_v1::primaries_pal:
125 break;
126 case QtWayland::wp_color_manager_v1::primaries_ntsc:
128 break;
129 case QtWayland::wp_color_manager_v1::primaries_generic_film:
131 break;
132 case QtWayland::wp_color_manager_v1::primaries_bt2020:
134 break;
135 case QtWayland::wp_color_manager_v1::primaries_cie1931_xyz:
137 break;
138 case QtWayland::wp_color_manager_v1::primaries_dci_p3:
140 break;
141 case QtWayland::wp_color_manager_v1::primaries_display_p3:
143 break;
144 case QtWayland::wp_color_manager_v1::primaries_adobe_rgb:
146 break;
147 }
148 }
149
150 if (this->masteringLuminance) {
151 masteringInfo.luminance = *this->masteringLuminance;
152 } else {
153 if (description.colorSpace.luminance) {
154 masteringInfo.luminance.fromLuminance(*description.colorSpace.luminance);
155 } else {
157 }
158 }
159
160 if (this->targetMaxCLL) {
161 masteringInfo.maxCll = *this->targetMaxCLL;
162 }
163 if (this->targetMaxFALL) {
164 masteringInfo.maxFall = *this->targetMaxFALL;
165 }
166
167 description.masteringInfo = masteringInfo;
168 }
169
170 return description;
171}
172
174{
176
177 using namespace KisColorimetryUtils;
178 using namespace KisSurfaceColorimetry;
179
180 if (std::holds_alternative<NamedPrimaries>(rhs.colorSpace.primaries)) {
181 desc.namedContainer = primariesKritaToWayland(std::get<NamedPrimaries>(rhs.colorSpace.primaries));
182 } else {
184 std::get<Colorimetry>(rhs.colorSpace.primaries));
185 }
186
187 if (std::holds_alternative<NamedTransferFunction>(rhs.colorSpace.transferFunction)) {
188 desc.tfNamed = transferFunctionKritaToWayland(std::get<NamedTransferFunction>(rhs.colorSpace.transferFunction));
189 } else {
190 desc.tfGamma = std::get<uint32_t>(rhs.colorSpace.transferFunction);
191 }
192
193 if (rhs.colorSpace.luminance) {
195 }
196
197 if (rhs.masteringInfo) {
199 desc.masteringLuminance = rhs.masteringInfo->luminance;
200
201 if (rhs.masteringInfo->maxCll) {
202 desc.targetMaxCLL = *rhs.masteringInfo->maxCll;
203 }
204
205 if (rhs.masteringInfo->maxFall) {
206 desc.targetMaxCLL = *rhs.masteringInfo->maxFall;
207 }
208 }
209
210 return desc;
211}
212
213QDebug operator<<(QDebug dbg, const WaylandPrimaries &points) {
214 dbg.nospace() << Qt::fixed << qSetRealNumberPrecision(5) << "KisColorPrimaries("
215 << "red: " << points.red << ", "
216 << "green: " << points.green << ", "
217 << "blue: " << points.blue << ", "
218 << "white: " << points.white
219 << ")";
220 dbg.resetFormat();
221 return dbg.space();
222}
223
224QDebug operator<<(QDebug dbg, const WaylandSurfaceDescription &data) {
225
226 dbg.nospace() << "WaylandSurfaceDescription(";
227
228 auto printOptionalTag = [&dbg](const char *tag, const auto &value) {
229 dbg.nospace() << tag << ": ";
230 if (value) {
231 dbg << *value << ", ";
232 } else {
233 dbg << "none" << ", ";
234 }
235 };
236
237 printOptionalTag("tfGamma", data.tfGamma);
238 printOptionalTag("tfNamed", data.tfNamed);
239 printOptionalTag("container", data.container);
240 printOptionalTag("namedContainer", data.namedContainer);
241 printOptionalTag("target", data.target);
242 printOptionalTag("luminances", data.luminances);
243 printOptionalTag("masteringLuminance", data.masteringLuminance);
244 printOptionalTag("targetMaxCLL", data.targetMaxCLL);
245 printOptionalTag("targetMaxFALL", data.targetMaxFALL);
246
247 dbg.nospace() << "iccFileIsPresent: " << data.iccFileIsPresent;
248
249 dbg.nospace() << ")";
250
251 return dbg.space();
252}
253
254QtWayland::wp_color_manager_v1::primaries primariesKritaToWayland(KisSurfaceColorimetry::NamedPrimaries primaries)
255{
256 using namespace KisSurfaceColorimetry;
257 using primaries_type = QtWayland::wp_color_manager_v1::primaries;
258
259 switch (primaries) {
261 return primaries_type::primaries_srgb;
263 return primaries_type::primaries_bt2020;
265 return primaries_type::primaries_dci_p3;
267 return primaries_type::primaries_display_p3;
269 return primaries_type::primaries_adobe_rgb;
271 Q_ASSERT(0 && "trying to set unknown named primary to the surface");
272 }
273 return primaries_type::primaries_srgb;
274}
275
276QtWayland::wp_color_manager_v1::transfer_function transferFunctionKritaToWayland(KisSurfaceColorimetry::NamedTransferFunction transferFunction)
277{
278 using namespace KisSurfaceColorimetry;
279 using transfer_function_type = QtWayland::wp_color_manager_v1::transfer_function;
280
281 switch (transferFunction) {
283 return transfer_function_type::transfer_function_bt1886;
285 return transfer_function_type::transfer_function_gamma22;
287 return transfer_function_type::transfer_function_gamma28;
289 return transfer_function_type::transfer_function_ext_linear;
291 return transfer_function_type::transfer_function_srgb;
293 return transfer_function_type::transfer_function_ext_srgb;
295 return transfer_function_type::transfer_function_st2084_pq;
297 return transfer_function_type::transfer_function_st428;
299 Q_ASSERT(0 && "trying to set unknown named transfer function to the surface");
300 }
301 return transfer_function_type::transfer_function_srgb;
302}
303
304QtWayland::wp_color_manager_v1::render_intent renderIntentKritaToWayland(KisSurfaceColorimetry::RenderIntent intent)
305{
306 using namespace KisSurfaceColorimetry;
307
308 switch (intent) {
310 return QtWayland::wp_color_manager_v1::render_intent::render_intent_perceptual;
312 return QtWayland::wp_color_manager_v1::render_intent::render_intent_relative;
314 return QtWayland::wp_color_manager_v1::render_intent::render_intent_saturation;
316 return QtWayland::wp_color_manager_v1::render_intent::render_intent_absolute;
318 return QtWayland::wp_color_manager_v1::render_intent::render_intent_relative_bpc;
319 default:
320 Q_ASSERT(false && "Unknown RenderIntent value");
321 return QtWayland::wp_color_manager_v1::render_intent::render_intent_perceptual; // Default fallback
322 }
323}
324
325} // namespace KisSurfaceColorimetry
326
332QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::primaries p)
333{
334 QDebugStateSaver saver(debug);
335 switch (p) {
336 case QtWayland::wp_color_manager_v1::primaries_srgb:
337 debug << "srgb";
338 break;
339 case QtWayland::wp_color_manager_v1::primaries_pal_m:
340 debug << "pal_m";
341 break;
342 case QtWayland::wp_color_manager_v1::primaries_pal:
343 debug << "pal";
344 break;
345 case QtWayland::wp_color_manager_v1::primaries_ntsc:
346 debug << "ntsc";
347 break;
348 case QtWayland::wp_color_manager_v1::primaries_generic_film:
349 debug << "generic_film";
350 break;
351 case QtWayland::wp_color_manager_v1::primaries_bt2020:
352 debug << "bt2020";
353 break;
354 case QtWayland::wp_color_manager_v1::primaries_cie1931_xyz:
355 debug << "cie1931_xyz";
356 break;
357 case QtWayland::wp_color_manager_v1::primaries_dci_p3:
358 debug << "dci_p3";
359 break;
360 case QtWayland::wp_color_manager_v1::primaries_display_p3:
361 debug << "display_p3";
362 break;
363 case QtWayland::wp_color_manager_v1::primaries_adobe_rgb:
364 debug << "adobe_rgb";
365 break;
366 default:
367 debug << "Unknown primaries:" << static_cast<int>(p);
368 break;
369 }
370 return debug;
371}
372
373QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::feature f)
374{
375 QDebugStateSaver saver(debug);
376 switch (f) {
377 case QtWayland::wp_color_manager_v1::feature_icc_v2_v4:
378 debug << "icc_v2_v4";
379 break;
380 case QtWayland::wp_color_manager_v1::feature_parametric:
381 debug << "parametric";
382 break;
383 case QtWayland::wp_color_manager_v1::feature_set_primaries:
384 debug << "set_primaries";
385 break;
386 case QtWayland::wp_color_manager_v1::feature_set_tf_power:
387 debug << "set_tf_power";
388 break;
389 case QtWayland::wp_color_manager_v1::feature_set_luminances:
390 debug << "set_luminances";
391 break;
392 case QtWayland::wp_color_manager_v1::feature_set_mastering_display_primaries:
393 debug << "set_mastering_display_primaries";
394 break;
395 case QtWayland::wp_color_manager_v1::feature_extended_target_volume:
396 debug << "extended_target_volume";
397 break;
398 case QtWayland::wp_color_manager_v1::feature_windows_scrgb:
399 debug << "windows_scrgb";
400 break;
401 default:
402 debug << "Unknown feature:" << static_cast<int>(f);
403 break;
404 }
405 return debug;
406}
407
408QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::render_intent ri)
409{
410 QDebugStateSaver saver(debug);
411 switch (ri) {
412 case QtWayland::wp_color_manager_v1::render_intent_perceptual:
413 debug << "perceptual";
414 break;
415 case QtWayland::wp_color_manager_v1::render_intent_relative:
416 debug << "relative";
417 break;
418 case QtWayland::wp_color_manager_v1::render_intent_saturation:
419 debug << "saturation";
420 break;
421 case QtWayland::wp_color_manager_v1::render_intent_absolute:
422 debug << "absolute";
423 break;
424 case QtWayland::wp_color_manager_v1::render_intent_relative_bpc:
425 debug << "relative_bpc";
426 break;
427 default:
428 debug << "Unknown render intent:" << static_cast<int>(ri);
429 break;
430 }
431 return debug;
432}
433
434QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::transfer_function tf)
435{
436 QDebugStateSaver saver(debug);
437 switch (tf) {
438 case QtWayland::wp_color_manager_v1::transfer_function_bt1886:
439 debug << "bt1886";
440 break;
441 case QtWayland::wp_color_manager_v1::transfer_function_gamma22:
442 debug << "gamma22";
443 break;
444 case QtWayland::wp_color_manager_v1::transfer_function_gamma28:
445 debug << "gamma28";
446 break;
447 case QtWayland::wp_color_manager_v1::transfer_function_st240:
448 debug << "st240";
449 break;
450 case QtWayland::wp_color_manager_v1::transfer_function_ext_linear:
451 debug << "ext_linear";
452 break;
453 case QtWayland::wp_color_manager_v1::transfer_function_log_100:
454 debug << "log_100";
455 break;
456 case QtWayland::wp_color_manager_v1::transfer_function_log_316:
457 debug << "log_316";
458 break;
459 case QtWayland::wp_color_manager_v1::transfer_function_xvycc:
460 debug << "xvycc";
461 break;
462 case QtWayland::wp_color_manager_v1::transfer_function_srgb:
463 debug << "srgb";
464 break;
465 case QtWayland::wp_color_manager_v1::transfer_function_ext_srgb:
466 debug << "ext_srgb";
467 break;
468 case QtWayland::wp_color_manager_v1::transfer_function_st2084_pq:
469 debug << "st2084_pq";
470 break;
471 case QtWayland::wp_color_manager_v1::transfer_function_st428:
472 debug << "st428";
473 break;
474 case QtWayland::wp_color_manager_v1::transfer_function_hlg:
475 debug << "hlg";
476 break;
477 default:
478 debug << "Unknown transfer function:" << static_cast<int>(tf);
479 break;
480 }
481 return debug;
482}
483
484/* KISSURFACECOLORIMETRY_H */
float value(const T *src, size_t ch)
const Params2D p
QDebug operator<<(QDebug debug, QtWayland::wp_color_manager_v1::primaries p)
static const Colorimetry GenericFilm
static const Colorimetry AdobeRGB
static const Colorimetry DisplayP3
QDebug operator<<(QDebug debug, const xy &value)
QtWayland::wp_color_manager_v1::render_intent renderIntentKritaToWayland(KisSurfaceColorimetry::RenderIntent intent)
QtWayland::wp_color_manager_v1::primaries primariesKritaToWayland(KisSurfaceColorimetry::NamedPrimaries primaries)
QtWayland::wp_color_manager_v1::transfer_function transferFunctionKritaToWayland(KisSurfaceColorimetry::NamedTransferFunction transferFunction)
std::optional< Luminance > luminance
std::variant< NamedPrimaries, Colorimetry > primaries
std::variant< NamedTransferFunction, uint32_t > transferFunction
static MasteringLuminance fromLuminance(const Luminance &rhs)
static WaylandPrimaries fromColorimetry(const Colorimetry &colorimetry)
std::optional< KisSurfaceColorimetry::Luminance > luminances
std::optional< KisSurfaceColorimetry::MasteringLuminance > masteringLuminance
static WaylandSurfaceDescription fromSurfaceDescription(const SurfaceDescription &desc)