Krita Source Code Documentation
Loading...
Searching...
No Matches
JPEGXLExport.cpp
Go to the documentation of this file.
1
2/*
3 * SPDX-FileCopyrightText: 2021 the JPEG XL Project Authors
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * SPDX-FileCopyrightText: 2022 L. E. Segovia <amy@amyspark.me>
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#include "JPEGXLExport.h"
11
13
14#include <jxl/version.h>
15#include <jxl/color_encoding.h>
16#include <jxl/encode_cxx.h>
17#include <jxl/resizable_parallel_runner_cxx.h>
18#include <kpluginfactory.h>
19
20#include <QBuffer>
21#include <algorithm>
22#include <array>
23#include <cstdint>
24#include <cstring>
25
26#include <KisDocument.h>
29#include <KoAlwaysInline.h>
31#include <KoColorProfile.h>
32#include <KoColorProfileQuery.h>
33#include <KoColorSpace.h>
35#include <KoConfig.h>
36#include <KoDocumentInfo.h>
37#include <KoProperties.h>
38#include <KoUpdater.h>
39#include <filter/kis_filter.h>
42#include <kis_assert.h>
43#include <kis_debug.h>
46#include <kis_iterator_ng.h>
47#include <kis_layer.h>
48#include <kis_layer_utils.h>
50#include <kis_meta_data_entry.h>
54#include <kis_meta_data_store.h>
55#include <kis_meta_data_value.h>
57#include <kis_time_span.h>
58
61
62K_PLUGIN_FACTORY_WITH_JSON(ExportFactory, "krita_jxl_export.json", registerPlugin<JPEGXLExport>();)
63
64JPEGXLExport::JPEGXLExport(QObject *parent, const QVariantList &)
65 : KisImportExportFilter(parent)
66{
67}
68
70{
72
73 dbgFile << QString("libjxl version: %1.%2.%3")
74 .arg(JPEGXL_MAJOR_VERSION)
75 .arg(JPEGXL_MINOR_VERSION)
76 .arg(JPEGXL_PATCH_VERSION);
77
78 KisImageSP image = document->savingImage();
79 const QRect bounds = image->bounds();
80
81 const bool cfgFlattenLayer = cfg->getBool("flattenLayers", true);
82 const bool cfgHaveAnimation = cfg->getBool("haveAnimation", false);
83 const bool cfgMultiLayer = cfg->getBool("multiLayer", false);
84 const bool cfgMultiPage = cfg->getBool("multiPage", false);
85
86 auto enc = JxlEncoderMake(nullptr);
87 auto runner = JxlResizableParallelRunnerMake(nullptr);
88 if (JXL_ENC_SUCCESS != JxlEncoderSetParallelRunner(enc.get(), JxlResizableParallelRunner, runner.get())) {
89 errFile << "JxlEncoderSetParallelRunner failed";
91 }
92
93 JxlResizableParallelRunnerSetThreads(runner.get(),
94 JxlResizableParallelRunnerSuggestThreads(static_cast<uint64_t>(bounds.width()), static_cast<uint64_t>(bounds.height())));
95
96 const KoColorSpace *cs = image->colorSpace();
98 bool convertToRec2020 = false;
99
100 if (cs->hasHighDynamicRange() && cs->colorModelId() != GrayAColorModelID) {
101 const QString conversionOption = (cfg->getString("floatingPointConversionOption", "Rec2100PQ"));
102 if (conversionOption == "Rec2100PQ") {
103 convertToRec2020 = true;
104 conversionPolicy = ConversionPolicy::ApplyPQ;
105 } else if (conversionOption == "Rec2100HLG") {
106 convertToRec2020 = true;
107 conversionPolicy = ConversionPolicy::ApplyHLG;
108 } else if (conversionOption == "ApplyPQ") {
109 conversionPolicy = ConversionPolicy::ApplyPQ;
110 } else if (conversionOption == "ApplyHLG") {
111 conversionPolicy = ConversionPolicy::ApplyHLG;
112 } else if (conversionOption == "ApplySMPTE428") {
113 conversionPolicy = ConversionPolicy::ApplySMPTE428;
114 }
115 }
116
117 if (cs->hasHighDynamicRange() && convertToRec2020) {
118 const KoColorProfile *linear =
120 KIS_ASSERT_RECOVER(linear)
121 {
122 errFile << "Unable to find a working profile for Rec. 2020";
124 }
125 const KoColorSpace *linearRec2020 =
127 image->convertImageColorSpace(linearRec2020,
130
131 image->waitForDone();
132 cs = image->colorSpace();
133 }
134
135 const float hlgGamma = cfg->getFloat("HLGgamma", 1.2f);
136 const bool removeHGLOOTF = false;
137
138 const bool hasPrimaries = cs->profile()->hasColorants();
140 static constexpr std::array<TransferCharacteristics, 14> supportedTRC = {TRC_LINEAR,
153 TRC_A98};
154 const bool isSupportedTRC = std::find(supportedTRC.begin(), supportedTRC.end(), gamma) != supportedTRC.end();
155
156#if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 10, 1)
157 JXLExpTool::JxlOutputProcessor processor(io);
158 if (JXL_ENC_SUCCESS != JxlEncoderSetOutputProcessor(enc.get(), processor.getOutputProcessor())) {
159 errFile << "JxlEncoderSetOutputProcessor failed";
161 }
162#endif
163
164 const JxlPixelFormat pixelFormat = [&]() {
165 JxlPixelFormat pixelFormat{};
167 pixelFormat.data_type = JXL_TYPE_UINT8;
168 } else if (conversionPolicy != ConversionPolicy::KeepTheSame
170 pixelFormat.data_type = JXL_TYPE_UINT16;
171#ifdef HAVE_OPENEXR
172 } else if (cs->colorDepthId() == Float16BitsColorDepthID) {
173 pixelFormat.data_type = JXL_TYPE_FLOAT16;
174#endif
175 } else if (cs->colorDepthId() == Float32BitsColorDepthID) {
176 pixelFormat.data_type = JXL_TYPE_FLOAT;
177 }
178 if (cs->colorModelId() == RGBAColorModelID) {
179 pixelFormat.num_channels = 4;
180 } else if (cs->colorModelId() == GrayAColorModelID) {
181 pixelFormat.num_channels = 2;
182 } else if (cs->colorModelId() == CMYKAColorModelID) {
183 pixelFormat.num_channels = 3;
184 }
185 return pixelFormat;
186 }();
187
188 if (JXL_ENC_SUCCESS != JxlEncoderUseBoxes(enc.get())) {
189 errFile << "JxlEncoderUseBoxes failed";
191 }
192
193 const auto basicInfo = [&]() {
194 auto info{std::make_unique<JxlBasicInfo>()};
195 JxlEncoderInitBasicInfo(info.get());
196 info->xsize = static_cast<uint32_t>(bounds.width());
197 info->ysize = static_cast<uint32_t>(bounds.height());
198 {
199 if (pixelFormat.data_type == JXL_TYPE_UINT8) {
200 info->bits_per_sample = 8;
201 info->exponent_bits_per_sample = 0;
202 info->alpha_bits = 8;
203 info->alpha_exponent_bits = 0;
204 } else if (pixelFormat.data_type == JXL_TYPE_UINT16) {
205 info->bits_per_sample = 16;
206 info->exponent_bits_per_sample = 0;
207 info->alpha_bits = 16;
208 info->alpha_exponent_bits = 0;
209#ifdef HAVE_OPENEXR
210 } else if (pixelFormat.data_type == JXL_TYPE_FLOAT16) {
211 info->bits_per_sample = 16;
212 info->exponent_bits_per_sample = 5;
213 info->alpha_bits = 16;
214 info->alpha_exponent_bits = 5;
215#endif
216 } else if (pixelFormat.data_type == JXL_TYPE_FLOAT) {
217 info->bits_per_sample = 32;
218 info->exponent_bits_per_sample = 8;
219 info->alpha_bits = 32;
220 info->alpha_exponent_bits = 8;
221 }
222 }
223 if (cs->colorModelId() == RGBAColorModelID) {
224 info->num_color_channels = 3;
225 info->num_extra_channels = 1;
226 } else if (cs->colorModelId() == GrayAColorModelID) {
227 info->num_color_channels = 1;
228 info->num_extra_channels = 1;
229 } else if (cs->colorModelId() == CMYKAColorModelID) {
230 info->num_color_channels = 3;
231 info->num_extra_channels = 2;
232 }
233 // Use original profile on lossless, non-matrix profile or unsupported transfer curve.
234 if (cfg->getBool("lossless") || (!hasPrimaries && !(cs->colorModelId() == GrayAColorModelID))
235 || !isSupportedTRC) {
236 info->uses_original_profile = JXL_TRUE;
237 dbgFile << "JXL use original profile";
238 } else {
239 info->uses_original_profile = JXL_FALSE;
240 dbgFile << "JXL use internal XYB profile";
241 }
242 if (image->animationInterface()->hasAnimation() && cfgHaveAnimation) {
243 info->have_animation = JXL_TRUE;
244 info->animation.have_timecodes = JXL_FALSE;
245 info->animation.num_loops = 0;
246 // Unlike WebP, JXL does allow for setting proper frame rates.
247 info->animation.tps_numerator =
248 static_cast<uint32_t>(image->animationInterface()->framerate());
249 info->animation.tps_denominator = 1;
250 } else if (cfgMultiPage) {
251 info->have_animation = JXL_TRUE;
252 info->animation.have_timecodes = JXL_FALSE;
253 info->animation.num_loops = 0;
254 info->animation.tps_numerator = 1;
255 info->animation.tps_denominator = 1;
256 }
257 return info;
258 }();
259
260 if (JXL_ENC_SUCCESS != JxlEncoderSetBasicInfo(enc.get(), basicInfo.get())) {
261 errFile << "JxlEncoderSetBasicInfo failed";
263 }
264
265 // CMYKA extra channel info
266 if (cs->colorModelId() == CMYKAColorModelID) {
267 const auto blackInfo = [&]() {
268 auto black{std::make_unique<JxlExtraChannelInfo>()};
269 JxlEncoderInitExtraChannelInfo(JXL_CHANNEL_BLACK, black.get());
270 black->bits_per_sample = basicInfo->bits_per_sample;
271 black->exponent_bits_per_sample = basicInfo->exponent_bits_per_sample;
272 return black;
273 }();
274 const auto alphaInfo = [&]() {
275 auto alpha{std::make_unique<JxlExtraChannelInfo>()};
276 JxlEncoderInitExtraChannelInfo(JXL_CHANNEL_ALPHA, alpha.get());
277 alpha->bits_per_sample = basicInfo->bits_per_sample;
278 alpha->exponent_bits_per_sample = basicInfo->exponent_bits_per_sample;
279 return alpha;
280 }();
281
282 if (JXL_ENC_SUCCESS != JxlEncoderSetExtraChannelInfo(enc.get(), 0, blackInfo.get())) {
283 errFile << "JxlEncoderSetBasicInfo Key failed";
285 }
286 if (JXL_ENC_SUCCESS != JxlEncoderSetExtraChannelInfo(enc.get(), 1, alphaInfo.get())) {
287 errFile << "JxlEncoderSetBasicInfo Alpha failed";
289 }
290 }
291
292 {
293 JxlColorEncoding cicpDescription{};
294
295 switch (conversionPolicy) {
297 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_PQ;
298 break;
300 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_HLG;
301 break;
303 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_DCI;
304 break;
306 default: {
307 switch (gamma) {
308 case TRC_LINEAR:
309 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
310 break;
314 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_709;
315 break;
317 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
318 cicpDescription.gamma = 1.0 / 2.2;
319 break;
321 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
322 cicpDescription.gamma = 1.0 / 2.8;
323 break;
325 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_SRGB;
326 break;
328 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_PQ;
329 break;
331 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_DCI;
332 break;
334 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_HLG;
335 break;
336 case TRC_GAMMA_1_8:
337 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
338 cicpDescription.gamma = 1.0 / 1.8;
339 break;
340 case TRC_GAMMA_2_4:
341 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
342 cicpDescription.gamma = 1.0 / 2.4;
343 break;
344 case TRC_PROPHOTO:
345 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
346 cicpDescription.gamma = 1.0 / 1.8;
347 break;
348 case TRC_A98:
349 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_GAMMA;
350 cicpDescription.gamma = 256.0 / 563.0;
351 break;
354 case TRC_SMPTE_240M:
358 case TRC_LAB_L:
359 case TRC_UNSPECIFIED:
360 if (cs->profile()->isLinear()) {
361 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_LINEAR;
362 } else {
363 dbgFile << "JXL CICP cannot describe the current transfer function" << gamma
364 << ", falling back to ICC";
365 cicpDescription.transfer_function = JXL_TRANSFER_FUNCTION_UNKNOWN;
366 }
367 break;
368 }
369 } break;
370 }
371
372 const ColorPrimaries primaries = cs->profile()->getColorPrimaries();
373
374 if ((cfg->getBool("lossless") && conversionPolicy == ConversionPolicy::KeepTheSame
375 && !cfg->getBool("forceCicpLossless"))
376 || (!hasPrimaries && !(cs->colorModelId() == GrayAColorModelID)) || !isSupportedTRC) {
377 const QByteArray profile = cs->profile()->rawData();
378
379 dbgFile << "Saving with ICC profile";
380
381 if (JXL_ENC_SUCCESS
382 != JxlEncoderSetICCProfile(enc.get(), reinterpret_cast<const uint8_t *>(profile.constData()), static_cast<size_t>(profile.size()))) {
383 errFile << "JxlEncoderSetICCProfile failed";
385 }
386 } else {
387 dbgFile << "Saving with CICP profile";
388
389 if (cs->colorModelId() == GrayAColorModelID) {
390 // XXX: JXL can't parse custom white point for grayscale (yet) and returned as linear on roundtrip so
391 // let's use default D65 as whitepoint instead...
392 //
393 // See: https://github.com/libjxl/libjxl/issues/1933
394 warnFile << "Using workaround for libjxl grayscale whitepoint";
395 cicpDescription.white_point = JXL_WHITE_POINT_D65;
396 cicpDescription.color_space = JXL_COLOR_SPACE_GRAY;
397 } else {
398 switch (primaries) {
400 cicpDescription.primaries = JXL_PRIMARIES_SRGB;
401 break;
403 cicpDescription.primaries = JXL_PRIMARIES_2100;
404 break;
406 cicpDescription.primaries = JXL_PRIMARIES_P3;
407 break;
408 default:
409 warnFile << "Writing possibly non-roundtrip primaries!";
411 cicpDescription.primaries = JXL_PRIMARIES_CUSTOM;
412 cicpDescription.primaries_red_xy[0] = colorants[0].x;
413 cicpDescription.primaries_red_xy[1] = colorants[0].y;
414 cicpDescription.primaries_green_xy[0] = colorants[1].x;
415 cicpDescription.primaries_green_xy[1] = colorants[1].y;
416 cicpDescription.primaries_blue_xy[0] = colorants[2].x;
417 cicpDescription.primaries_blue_xy[1] = colorants[2].y;
418 break;
419 }
420
421 // Unfortunately, Wolthera never wrote an enum for white points...
422 const KoColorimetryUtils::xyY whitePoint = image->colorSpace()->profile()->getWhitePointxyY();
423 cicpDescription.white_point = JXL_WHITE_POINT_CUSTOM;
424 cicpDescription.white_point_xy[0] = whitePoint.x;
425 cicpDescription.white_point_xy[1] = whitePoint.y;
426 }
427
428 if (JXL_ENC_SUCCESS != JxlEncoderSetColorEncoding(enc.get(), &cicpDescription)) {
429 errFile << "JxlEncoderSetColorEncoding failed";
431 }
432 }
433 }
434
435 if (cfg->getBool("storeMetaData", false)) {
436 auto metaDataStore = [&]() -> std::unique_ptr<KisMetaData::Store> {
437 KisExifInfoVisitor exivInfoVisitor;
438 exivInfoVisitor.visit(image->rootLayer().data());
439 if (exivInfoVisitor.metaDataCount() == 1) {
440 return std::make_unique<KisMetaData::Store>(*exivInfoVisitor.exifInfo());
441 } else if (cfg->getBool("storeAuthor", true)) {
442 return std::make_unique<KisMetaData::Store>();
443 } else {
444 return {};
445 }
446 }();
447
448 if (metaDataStore && !metaDataStore->isEmpty()) {
450 model.setEnabledFilters(cfg->getString("filters").split(","));
451 metaDataStore->applyFilters(model.enabledFilters());
452 }
453
454 const KisMetaData::Schema *dcSchema =
456 Q_ASSERT(dcSchema);
457
458 if (cfg->getBool("storeAuthor", true)) {
459 QString author = document->documentInfo()->authorInfo("creator");
460 if (!author.isEmpty()) {
461 if (!document->documentInfo()->authorContactInfo().isEmpty()) {
462 QString contact = document->documentInfo()->authorContactInfo().at(0);
463 if (!contact.isEmpty()) {
464 author = author + "(" + contact + ")";
465 }
466 }
467 if (metaDataStore->containsEntry("creator")) {
468 metaDataStore->removeEntry("creator");
469 }
470 metaDataStore->addEntry(KisMetaData::Entry(dcSchema, "creator", KisMetaData::Value(QVariant(author))));
471 }
472 }
473
474 if (metaDataStore && cfg->getBool("exif", true)) {
476
477 QBuffer ioDevice;
478
479 // Inject the data as any other IOBackend
480 io->saveTo(metaDataStore.get(), &ioDevice);
481
482 if (JXL_ENC_SUCCESS
483 != JxlEncoderAddBox(enc.get(),
484 "Exif",
485 reinterpret_cast<const uint8_t *>(ioDevice.data().constData()),
486 static_cast<size_t>(ioDevice.size()),
487 cfg->getBool("lossless") ? JXL_FALSE : JXL_TRUE)) {
488 errFile << "JxlEncoderAddBox for EXIF failed";
490 }
491 }
492
493 if (metaDataStore && cfg->getBool("xmp", true)) {
495
496 QBuffer ioDevice;
497
498 // Inject the data as any other IOBackend
499 io->saveTo(metaDataStore.get(), &ioDevice);
500
501 if (JXL_ENC_SUCCESS
502 != JxlEncoderAddBox(enc.get(),
503 "xml ",
504 reinterpret_cast<const uint8_t *>(ioDevice.data().constData()),
505 static_cast<size_t>(ioDevice.size()),
506 cfg->getBool("lossless") ? JXL_FALSE : JXL_TRUE)) {
507 errFile << "JxlEncoderAddBox for XMP failed";
509 }
510 }
511
512 if (metaDataStore && cfg->getBool("iptc", true)) {
514
515 QBuffer ioDevice;
516
517 // Inject the data as any other IOBackend
518 io->saveTo(metaDataStore.get(), &ioDevice);
519
520 if (JXL_ENC_SUCCESS
521 != JxlEncoderAddBox(enc.get(),
522 "xml ",
523 reinterpret_cast<const uint8_t *>(ioDevice.data().constData()),
524 static_cast<size_t>(ioDevice.size()),
525 cfg->getBool("lossless") ? JXL_FALSE : JXL_TRUE)) {
526 errFile << "JxlEncoderAddBox for IPTC failed";
528 }
529 }
530 }
531
532 auto *frameSettings = JxlEncoderFrameSettingsCreate(enc.get(), nullptr);
533 {
534 const auto setFrameLossless = [&](bool v) {
535 if (JxlEncoderSetFrameLossless(frameSettings, v ? JXL_TRUE : JXL_FALSE) != JXL_ENC_SUCCESS) {
536 errFile << "JxlEncoderSetFrameLossless failed";
537 return false;
538 }
539 return true;
540 };
541
542 const auto setSetting = [&](JxlEncoderFrameSettingId id, int v) {
543 // https://github.com/libjxl/libjxl/issues/1210
544 if (id == JXL_ENC_FRAME_SETTING_RESAMPLING && v == -1)
545 return true;
546 if (JxlEncoderFrameSettingsSetOption(frameSettings, id, v) != JXL_ENC_SUCCESS) {
547 errFile << "JxlEncoderFrameSettingsSetOption failed";
548 return false;
549 }
550 return true;
551 };
552
553 // Using cjxl quality mapping that translates from arbitrary quality value to JPEG-XL distance
554 const auto setDistance = [&](float v) {
555 const float distance = cfg->getBool("lossless") ? 0.0
556 : v >= 30 ? 0.1 + (100 - v) * 0.09
557 : 53.0 / 3000.0 * v * v - 23.0 / 20.0 * v + 25.0;
558 dbgFile << "libjxl distance equivalent: " << distance;
559 if (JxlEncoderSetFrameDistance(frameSettings, distance) != JXL_ENC_SUCCESS) {
560 errFile << "JxlEncoderSetFrameDistance failed";
561 return false;
562 }
563#if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 9, 0)
564 // Lossless alpha (extra channel), only available on libjxl 0.9.0+
565 if (!cfg->getBool("lossless")) {
566 if (cfg->getBool("losslessAlpha")) {
567 if (JxlEncoderSetExtraChannelDistance(frameSettings,
568 (cs->colorModelId() == CMYKAColorModelID) ? 1 : 0,
569 0)
570 != JXL_ENC_SUCCESS) {
571 errFile << "JxlEncoderSetExtraChannelDistance failed";
572 return false;
573 }
574 } else {
575 if (JxlEncoderSetExtraChannelDistance(frameSettings,
576 (cs->colorModelId() == CMYKAColorModelID) ? 1 : 0,
577 distance)
578 != JXL_ENC_SUCCESS) {
579 errFile << "JxlEncoderSetExtraChannelDistance failed";
580 return false;
581 }
582 }
583 }
584#endif
585 return true;
586 };
587
588 // XXX: Workaround for a buggy lossy F32.
589 //
590 // See: https://github.com/libjxl/libjxl/issues/2064
591 //
592 // Update: It's not the modular mode that caused the bug, but the progressive/responsive setting
593 // that didn't work well with F32. So let's disable it on F32 instead.
594 const int setResponsive = [&]() -> int {
595 if (pixelFormat.data_type == JXL_TYPE_FLOAT && !cfg->getBool("lossless")) {
596 warnFile << "Using workaround for lossy 32-bit float, disabling progressive option";
597 return 0;
598 }
599 return cfg->getInt("responsive", -1);
600 }();
601
602 // XXX: Workaround for a buggy lossless patches. Set to disable instead.
603 // Patch only for libjxl under v0.9.0
604 //
605 // See: https://github.com/libjxl/libjxl/issues/2463
606 const int setPatches = [&]() -> int {
607#if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0, 9, 0)
608 if ((cfg->getInt("effort", 7) > 4) && cfgFlattenLayer) {
609 warnFile << "Using workaround for layer exports, disabling patches option on effort > 4";
610 return 0;
611 }
612#endif
613 return cfg->getInt("patches", -1);
614 }();
615
616 if (!setFrameLossless(cfg->getBool("lossless"))
617 || !setSetting(JXL_ENC_FRAME_SETTING_EFFORT, cfg->getInt("effort", 7))
618 || !setSetting(JXL_ENC_FRAME_SETTING_DECODING_SPEED, cfg->getInt("decodingSpeed", 0))
619 || !setSetting(JXL_ENC_FRAME_SETTING_RESAMPLING, cfg->getInt("resampling", -1))
620 || !setSetting(JXL_ENC_FRAME_SETTING_EXTRA_CHANNEL_RESAMPLING, cfg->getInt("extraChannelResampling", -1))
621 || !setSetting(JXL_ENC_FRAME_SETTING_DOTS, cfg->getInt("dots", -1))
622 || !setSetting(JXL_ENC_FRAME_SETTING_PATCHES, setPatches)
623 || !setSetting(JXL_ENC_FRAME_SETTING_EPF, cfg->getInt("epf", -1))
624 || !setSetting(JXL_ENC_FRAME_SETTING_GABORISH, cfg->getInt("gaborish", -1))
625 || !setSetting(JXL_ENC_FRAME_SETTING_MODULAR, cfg->getInt("modular", -1))
626 || !setSetting(JXL_ENC_FRAME_SETTING_KEEP_INVISIBLE, cfg->getInt("keepInvisible", -1))
627 || !setSetting(JXL_ENC_FRAME_SETTING_GROUP_ORDER, cfg->getInt("groupOrder", -1))
628 || !setSetting(JXL_ENC_FRAME_SETTING_RESPONSIVE, setResponsive)
629 || !setSetting(JXL_ENC_FRAME_SETTING_PROGRESSIVE_AC, cfg->getInt("progressiveAC", -1))
630 || !setSetting(JXL_ENC_FRAME_SETTING_QPROGRESSIVE_AC, cfg->getInt("qProgressiveAC", -1))
631 || !setSetting(JXL_ENC_FRAME_SETTING_PROGRESSIVE_DC, cfg->getInt("progressiveDC", -1))
632 || !setSetting(JXL_ENC_FRAME_SETTING_PALETTE_COLORS, cfg->getInt("paletteColors", -1))
633 || !setSetting(JXL_ENC_FRAME_SETTING_LOSSY_PALETTE, cfg->getInt("lossyPalette", -1))
634 || !setSetting(JXL_ENC_FRAME_SETTING_MODULAR_GROUP_SIZE, cfg->getInt("modularGroupSize", -1))
635 || !setSetting(JXL_ENC_FRAME_SETTING_MODULAR_PREDICTOR, cfg->getInt("modularPredictor", -1))
636 || !setSetting(JXL_ENC_FRAME_SETTING_JPEG_RECON_CFL, cfg->getInt("jpegReconCFL", -1))
637 || !setDistance(cfg->getInt("lossyQuality", 100))) {
639 }
640 }
641
642 {
643 const auto setSettingFloat = [&](JxlEncoderFrameSettingId id, float v) {
644 if (JxlEncoderFrameSettingsSetFloatOption(frameSettings, id, v) != JXL_ENC_SUCCESS) {
645 errFile << "JxlEncoderFrameSettingsSetFloatOption failed";
646 return false;
647 }
648 return true;
649 };
650
651 if (!setSettingFloat(JXL_ENC_FRAME_SETTING_PHOTON_NOISE, cfg->getFloat("photonNoise", 0))
652 || !setSettingFloat(JXL_ENC_FRAME_SETTING_CHANNEL_COLORS_GLOBAL_PERCENT,
653 cfg->getFloat("channelColorsGlobalPercent", -1))
654 || !setSettingFloat(JXL_ENC_FRAME_SETTING_CHANNEL_COLORS_GROUP_PERCENT,
655 cfg->getFloat("channelColorsGroupPercent", -1))
656 || !setSettingFloat(JXL_ENC_FRAME_SETTING_MODULAR_MA_TREE_LEARNING_PERCENT,
657 cfg->getFloat("modularMATreeLearningPercent", -1))) {
659 }
660 }
661
662 {
663 const bool isAnimated = [&]() {
664 if (image->animationInterface()->hasAnimation() && cfgHaveAnimation) {
665 KisLayerUtils::flattenImage(image, nullptr);
666 image->waitForDone();
667
668 const KisNodeSP projection = image->rootLayer()->firstChild();
669 return projection->isAnimated() && projection->hasEditablePaintDevice();
670 }
671 return false;
672 }();
673
674 if (isAnimated) {
675 // Flatten the image, projections don't have keyframes.
676 KisLayerUtils::flattenImage(image, nullptr);
677 image->waitForDone();
678
679 const KisNodeSP projection = image->rootLayer()->firstChild();
680 KIS_ASSERT(projection->isAnimated());
681 KIS_ASSERT(projection->hasEditablePaintDevice());
682
683 const auto *frames = projection->paintDevice()->keyframeChannel();
684 const auto times = [&]() {
685 QList<int> t;
686 QSet<int> s = frames->allKeyframeTimes();
687 t = QList<int>(s.begin(), s.end());
688 std::sort(t.begin(), t.end());
689 return t;
690 }();
691
692 auto frameHeader = []() {
693 auto header = std::make_unique<JxlFrameHeader>();
694 JxlEncoderInitFrameHeader(header.get());
695 return header;
696 }();
697
698 int frameNum = 0;
699 for (const auto i : times) {
700 frameHeader->duration = [&]() {
701 const auto nextKeyframe = frames->nextKeyframeTime(i);
702 if (nextKeyframe == -1) {
703 return static_cast<uint32_t>(
705 - i + 1);
706 } else {
707 return static_cast<uint32_t>(frames->nextKeyframeTime(i) - i);
708 }
709 }();
710 frameHeader->is_last = 0;
711
712 if (JxlEncoderSetFrameHeader(frameSettings, frameHeader.get()) != JXL_ENC_SUCCESS) {
713 errFile << "JxlEncoderSetFrameHeader failed";
715 }
716
717 const QByteArray pixels = [&]() {
718 const auto frameData = frames->keyframeAt<KisRasterKeyframe>(i);
719 KisPaintDeviceSP dev =
721 frameData->writeFrameToDevice(dev);
722
723 const KoID colorModel = cs->colorModelId();
724
725 if (colorModel != RGBAColorModelID) {
726 // blast it wholesale
727 QByteArray p;
728 p.resize(bounds.width() * bounds.height() * static_cast<int>(cs->pixelSize()));
729 dev->readBytes(reinterpret_cast<quint8 *>(p.data()), bounds);
730 return p;
731 } else {
732 KisHLineConstIteratorSP it = dev->createHLineConstIteratorNG(0, 0, bounds.width());
733
734 // detect traits based on depth
735 // if u8 or u16, also trigger swap
736 return HDR::writeLayer(cs->colorDepthId(),
737 convertToRec2020,
738 cs->profile()->isLinear(),
739 conversionPolicy,
740 removeHGLOOTF,
741 bounds.width(),
742 bounds.height(),
743 it,
744 hlgGamma,
745 cs);
746 }
747 }();
748
749 if (JxlEncoderAddImageFrame(frameSettings,
750 &pixelFormat,
751 pixels.data(),
752 static_cast<size_t>(pixels.size()))
753 != JXL_ENC_SUCCESS) {
754 errFile << "JxlEncoderAddImageFrame @" << i << "failed";
756 }
757
758#if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 10, 1)
759 if (updater() && updater()->interrupted()) {
760 warnFile << "Save cancelled";
762 }
763 const int progress = (frameNum * 100) / times.size();
764 setProgress(progress);
765 frameNum++;
766 if (frames->nextKeyframeTime(i) == -1) {
767 JxlEncoderCloseInput(enc.get());
768 }
769 if (JxlEncoderFlushInput(enc.get()) != JXL_ENC_SUCCESS) {
770 errFile << "JxlEncoderFlushInput failed";
772 }
773#endif
774 }
775 } else {
776 auto frameHeader = std::make_unique<JxlFrameHeader>();
777
778 // (On layered export) Convert group layer to paint layer to preserve
779 // out-of-bound pixels so that it won't get clipped to canvas size
780 quint32 lastValidLayer = 0;
781 if (cfgMultiLayer || cfgMultiPage) {
782 for (quint32 pos = 0; pos < image->root()->childCount(); pos++) {
783 KisNodeSP node = image->root()->at(pos);
784 KisLayer *layer = qobject_cast<KisLayer *>(node.data());
785 if (layer && (layer->inherits("KisGroupLayer") || layer->childCount() > 0 || layer->layerStyle())
786 && layer->visible()) {
787 dbgFile << "Flattening layer" << node->name();
788 KisLayerUtils::flattenLayer(image, layer);
789 }
790 if (node && node->visible() && !node->isFakeNode()) {
791 lastValidLayer = pos;
792 }
793 }
794 image->waitForDone();
795 }
796
797 // Iterate through the layers (non-recursively)
798 for (quint32 pos = 0; pos < image->root()->childCount(); pos++) {
799 KisNodeSP node = image->root()->at(pos);
800 // Skip invalid and invisible layers
801 if ((cfgMultiLayer || cfgMultiPage) && (!node || !node->visible() || node->isFakeNode())) {
802 dbgFile << "Skipping hidden layer" << node->name();
803 continue;
804 }
805 const bool isFirstLayer = (node == image->root()->firstChild());
806
807 if (cfgMultiLayer || cfgMultiPage) {
808 dbgFile << "Visiting on layer" << node->name();
809
810 if (!node->inherits("KisPaintLayer")) {
811 std::future<KisNodeSP> convertedNode = KisLayerUtils::convertToPaintLayer(image, node);
812 node = convertedNode.get();
813 }
814
815 const KoColorSpace *lcs = node->colorSpace();
816 if (lcs && (lcs != cs)) {
817 node->paintDevice()->convertTo(cs);
818 // Kampidh: Do I also need to call waitForDone() here?
819 }
820 } else {
821 dbgFile << "Saving flattened image";
822 }
823
824 const QRect layerBounds = [&]() {
825 if (node->exactBounds().isEmpty() || cfgFlattenLayer) {
826 return image->bounds();
827 }
828 return node->exactBounds();
829 }();
830
832 if (cfgFlattenLayer) {
833 dev = image->projection();
834 } else {
835 dev = node->projection();
836 }
837
838 if (cs->colorModelId() == CMYKAColorModelID) {
839 // Inverting colors for CMYK
840 const KisFilterSP f = KisFilterRegistry::instance()->value("invert");
841 KIS_ASSERT(f);
842 const KisFilterConfigurationSP kfc =
843 f->defaultConfiguration(KisGlobalResourcesInterface::instance());
844 KIS_ASSERT(kfc);
845 f->process(dev, layerBounds, kfc->cloneWithResourcesSnapshot());
846 }
847
848 const QByteArray pixels = [&]() {
849 const KoID colorModel = cs->colorModelId();
850 const KoID colorDepth = cs->colorDepthId();
851
852 if (colorModel != RGBAColorModelID
853 || (colorDepth != Integer8BitsColorDepthID && colorDepth != Integer16BitsColorDepthID
854 && conversionPolicy == ConversionPolicy::KeepTheSame)) {
855 // CMYK
856 if (colorModel == CMYKAColorModelID) {
858 dev->createHLineConstIteratorNG(layerBounds.x(), layerBounds.y(), layerBounds.width());
859
860 // interleaved CMY buffer
862 true,
863 0,
864 layerBounds.width(),
865 layerBounds.height(),
866 it);
867 }
868 // blast it wholesale
869 QByteArray p;
870 p.resize(layerBounds.width() * layerBounds.height() * static_cast<int>(cs->pixelSize()));
871 dev->readBytes(reinterpret_cast<quint8 *>(p.data()), layerBounds);
872 return p;
873 } else {
875 dev->createHLineConstIteratorNG(layerBounds.x(), layerBounds.y(), layerBounds.width());
876
877 // detect traits based on depth
878 // if u8 or u16, also trigger swap
879 return HDR::writeLayer(cs->colorDepthId(),
880 convertToRec2020,
881 cs->profile()->isLinear(),
882 conversionPolicy,
883 removeHGLOOTF,
884 layerBounds.width(),
885 layerBounds.height(),
886 it,
887 hlgGamma,
888 cs);
889 }
890 }();
891
892 if (cfgMultiLayer || cfgMultiPage) {
893 JxlEncoderInitFrameHeader(frameHeader.get());
894
895 // Set frame duration to 0 to indicate a multi-layered image
896 if (cfgMultiLayer) {
897 frameHeader->duration = 0;
898 } else if (cfgMultiPage) {
899 frameHeader->duration = 0xFFFFFFFF;
900 }
901
902 // Enable crop info if layer dimension is different than main
903 // This also enables out-of-bound pixels to be preserved
904 if (node->exactBounds() == image->bounds()) {
905 frameHeader->layer_info.have_crop = false;
906 } else {
907 frameHeader->layer_info.have_crop = true;
908 }
909 frameHeader->layer_info.crop_x0 = layerBounds.x();
910 frameHeader->layer_info.crop_y0 = layerBounds.y();
911 frameHeader->layer_info.xsize = layerBounds.width();
912 frameHeader->layer_info.ysize = layerBounds.height();
913
914 if (cs->colorModelId() == CMYKAColorModelID) {
915 frameHeader->layer_info.blend_info.alpha = 1;
916 } else {
917 frameHeader->layer_info.blend_info.alpha = 0;
918 }
919
920 // EXPERIMENTAL! Additive blending mode on JPEG-XL produces
921 // slightly different result than Krita.
922 const QString frameName = node->name();
923 if (!isFirstLayer && cfgMultiLayer) {
924 if (node->compositeOpId() == QString("add")) {
925 frameHeader->layer_info.blend_info.blendmode = JXL_BLEND_MULADD;
926 } else {
927 frameHeader->layer_info.blend_info.blendmode = JXL_BLEND_BLEND;
928 }
929 }
930
931 if (JxlEncoderSetFrameHeader(frameSettings, frameHeader.get()) != JXL_ENC_SUCCESS) {
932 errFile << "JxlEncoderSetFrameHeader failed";
934 }
935 if (JxlEncoderSetFrameName(frameSettings, frameName.toLocal8Bit()) != JXL_ENC_SUCCESS) {
936 errFile << "JxlEncoderSetFrameName failed";
938 }
939 }
940
941 if (JxlEncoderAddImageFrame(frameSettings,
942 &pixelFormat,
943 pixels.data(),
944 static_cast<size_t>(pixels.size()))
945 != JXL_ENC_SUCCESS) {
946 errFile << "JxlEncoderAddImageFrame failed";
948 }
949
950 // CMYKA separate planar buffer for Key and Alpha
951 if (cs->colorModelId() == CMYKAColorModelID) {
953 dev->createHLineConstIteratorNG(layerBounds.x(), layerBounds.y(), layerBounds.width());
954
955 const QByteArray chaK = JXLExpTool::writeCMYKLayer(cs->colorDepthId(),
956 false,
957 3,
958 layerBounds.width(),
959 layerBounds.height(),
960 it);
961 it->resetRowPos();
962 const QByteArray chaA = JXLExpTool::writeCMYKLayer(cs->colorDepthId(),
963 false,
964 4,
965 layerBounds.width(),
966 layerBounds.height(),
967 it);
968
969 if (JxlEncoderSetExtraChannelBuffer(frameSettings,
970 &pixelFormat,
971 chaK,
972 static_cast<size_t>(chaK.size()),
973 0)
974 != JXL_ENC_SUCCESS) {
975 errFile << "JxlEncoderSetExtraChannelBuffer Key failed";
977 }
978 if (JxlEncoderSetExtraChannelBuffer(frameSettings,
979 &pixelFormat,
980 chaA,
981 static_cast<size_t>(chaA.size()),
982 1)
983 != JXL_ENC_SUCCESS) {
984 errFile << "JxlEncoderSetExtraChannelBuffer Alpha failed";
986 }
987 }
988
989#if JPEGXL_NUMERIC_VERSION >= JPEGXL_COMPUTE_NUMERIC_VERSION(0, 10, 1)
990 if (updater() && updater()->interrupted()) {
991 warnFile << "Save cancelled";
993 }
994 const int progress = (pos * 100) / image->root()->childCount();
995 setProgress(progress);
996 if ((pos == lastValidLayer && (cfgMultiLayer || cfgMultiPage)) || cfgFlattenLayer) {
997 JxlEncoderCloseInput(enc.get());
998 }
999 if (JxlEncoderFlushInput(enc.get()) != JXL_ENC_SUCCESS) {
1000 errFile << "JxlEncoderFlushInput failed";
1002 }
1003 if (cfgFlattenLayer) {
1004 break;
1005 }
1006 }
1007 }
1008#else
1009 // Quit loop if flatten is active
1010 if (cfgFlattenLayer) {
1011 break;
1012 }
1013 }
1014 }
1015 JxlEncoderCloseInput(enc.get());
1016
1017 QByteArray compressed(16384, 0x0);
1018 auto *nextOut = reinterpret_cast<uint8_t *>(compressed.data());
1019 auto availOut = static_cast<size_t>(compressed.size());
1020 auto result = JXL_ENC_NEED_MORE_OUTPUT;
1021 while (result == JXL_ENC_NEED_MORE_OUTPUT) {
1022 result = JxlEncoderProcessOutput(enc.get(), &nextOut, &availOut);
1023 if (result != JXL_ENC_ERROR) {
1024 io->write(compressed.data(), compressed.size() - static_cast<int>(availOut));
1025 }
1026 if (result == JXL_ENC_NEED_MORE_OUTPUT) {
1027 compressed.resize(compressed.size() * 2);
1028 nextOut = reinterpret_cast<uint8_t *>(compressed.data());
1029 availOut = static_cast<size_t>(compressed.size());
1030 }
1031 }
1032 if (JXL_ENC_SUCCESS != result) {
1033 errFile << "JxlEncoderProcessOutput failed";
1035 }
1036#endif
1037 }
1038
1039 return ImportExportCodes::OK;
1040}
1041
1043{
1044 // This checks before saving for what the file format supports: anything that is supported needs to be mentioned
1045 // here
1046
1047 QList<QPair<KoID, KoID>> supportedColorModels;
1049 ->get("AnimationCheck")
1055 supportedColorModels << QPair<KoID, KoID>() << QPair<KoID, KoID>(RGBAColorModelID, Integer8BitsColorDepthID)
1056 << QPair<KoID, KoID>(GrayAColorModelID, Integer8BitsColorDepthID)
1057 << QPair<KoID, KoID>(CMYKAColorModelID, Integer8BitsColorDepthID)
1058 << QPair<KoID, KoID>(RGBAColorModelID, Integer16BitsColorDepthID)
1059 << QPair<KoID, KoID>(GrayAColorModelID, Integer16BitsColorDepthID)
1060 << QPair<KoID, KoID>(CMYKAColorModelID, Integer16BitsColorDepthID)
1061#ifdef HAVE_OPENEXR
1062 << QPair<KoID, KoID>(RGBAColorModelID, Float16BitsColorDepthID)
1063 << QPair<KoID, KoID>(GrayAColorModelID, Float16BitsColorDepthID)
1064 << QPair<KoID, KoID>(CMYKAColorModelID, Float16BitsColorDepthID)
1065#endif
1066 << QPair<KoID, KoID>(RGBAColorModelID, Float32BitsColorDepthID)
1067 << QPair<KoID, KoID>(GrayAColorModelID, Float32BitsColorDepthID)
1068 << QPair<KoID, KoID>(CMYKAColorModelID, Float32BitsColorDepthID);
1069 addSupportedColorModels(supportedColorModels, "JPEG-XL");
1070
1072 addCapability(KisExportCheckRegistry::instance()->get("ColorModelHomogenousCheck")->create(KisExportCheckBase::PARTIALLY));
1073 addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisGroupLayer")->create(KisExportCheckBase::PARTIALLY));
1074 addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisGeneratorLayer")->create(KisExportCheckBase::PARTIALLY));
1075 addCapability(KisExportCheckRegistry::instance()->get("NodeTypeCheck/KisTransparencyMask")->create(KisExportCheckBase::PARTIALLY));
1077 addCapability(KisExportCheckRegistry::instance()->get("FillLayerTypeCheck/pattern")->create(KisExportCheckBase::PARTIALLY));
1078 addCapability(KisExportCheckRegistry::instance()->get("FillLayerTypeCheck/gradient")->create(KisExportCheckBase::PARTIALLY));
1080}
1081
1083JPEGXLExport::createConfigurationWidget(QWidget *parent, const QByteArray & /*from*/, const QByteArray & /*to*/) const
1084{
1085 return new KisWdgOptionsJPEGXL(parent);
1086}
1087
1088KisPropertiesConfigurationSP JPEGXLExport::defaultConfiguration(const QByteArray &, const QByteArray &) const
1089{
1091
1092 // WARNING: libjxl only allows setting encoding properties,
1093 // so I hardcoded values from https://libjxl.readthedocs.io/en/latest/api_encoder.html
1094 // https://readthedocs.org/projects/libjxl/builds/16271112/
1095
1096 // Options for the following were not added because they rely
1097 // on the image's specific color space, or can introduce more
1098 // trouble than help:
1099 // JXL_ENC_FRAME_SETTING_GROUP_ORDER_CENTER_X
1100 // JXL_ENC_FRAME_SETTING_GROUP_ORDER_CENTER_Y
1101 // JXL_ENC_FRAME_SETTING_MODULAR_COLOR_SPACE
1102 // JXL_ENC_FRAME_SETTING_MODULAR_NB_PREV_CHANNELS
1103 // These are directly incompatible with the export logic:
1104 // JXL_ENC_FRAME_SETTING_ALREADY_DOWNSAMPLED
1105 // JXL_ENC_FRAME_SETTING_COLOR_TRANSFORM
1106
1107 cfg->setProperty("haveAnimation", false);
1108 cfg->setProperty("flattenLayers", true);
1109 cfg->setProperty("multiLayer", false);
1110 cfg->setProperty("multiPage", false);
1111 cfg->setProperty("lossless", true);
1112 cfg->setProperty("effort", 7);
1113 cfg->setProperty("decodingSpeed", 0);
1114 cfg->setProperty("lossyQuality", 100);
1115 cfg->setProperty("forceModular", false);
1116 cfg->setProperty("modularSetVal", -1);
1117 cfg->setProperty("losslessAlpha", false);
1118
1119 cfg->setProperty("forceCicpLossless", false);
1120 cfg->setProperty("floatingPointConversionOption", "KeepSame");
1121 cfg->setProperty("HLGgamma", 1.2);
1122 cfg->setProperty("removeHGLOOTF", false);
1123
1124 cfg->setProperty("resampling", -1);
1125 cfg->setProperty("extraChannelResampling", -1);
1126 cfg->setProperty("photonNoise", 0);
1127 cfg->setProperty("dots", -1);
1128 cfg->setProperty("patches", -1);
1129 cfg->setProperty("epf", -1);
1130 cfg->setProperty("gaborish", -1);
1131 cfg->setProperty("modular", -1);
1132 cfg->setProperty("keepInvisible", -1);
1133 cfg->setProperty("groupOrder", -1);
1134 cfg->setProperty("responsive", -1);
1135 cfg->setProperty("progressiveAC", -1);
1136 cfg->setProperty("qProgressiveAC", -1);
1137 cfg->setProperty("progressiveDC", -1);
1138 cfg->setProperty("channelColorsGlobalPercent", -1);
1139 cfg->setProperty("channelColorsGroupPercent", -1);
1140 cfg->setProperty("paletteColors", -1);
1141 cfg->setProperty("lossyPalette", -1);
1142 cfg->setProperty("modularGroupSize", -1);
1143 cfg->setProperty("modularPredictor", -1);
1144 cfg->setProperty("modularMATreeLearningPercent", -1);
1145 cfg->setProperty("jpegReconCFL", -1);
1146
1147 cfg->setProperty("storeAuthor", false);
1148 cfg->setProperty("exif", true);
1149 cfg->setProperty("xmp", true);
1150 cfg->setProperty("iptc", true);
1151 cfg->setProperty("storeMetaData", false);
1152 cfg->setProperty("filters", "");
1153 return cfg;
1154}
1155
1156#include <JPEGXLExport.moc>
const Params2D p
qreal v
VertexDescriptor get(PredecessorMap const &m, VertexDescriptor v)
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID GrayAColorModelID("GRAYA", ki18n("Grayscale/Alpha"))
const KoID Float16BitsColorDepthID("F16", ki18n("16-bit float/channel"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
const KoID CMYKAColorModelID("CMYKA", ki18n("CMYK/Alpha"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
ColorPrimaries
The colorPrimaries enum Enum of colorants, follows ITU H.273 for values 0 to 255, and has extra known...
@ PRIMARIES_ITU_R_BT_2020_2_AND_2100_0
@ PRIMARIES_SMPTE_RP_431_2
@ PRIMARIES_ITU_R_BT_709_5
TransferCharacteristics
The transferCharacteristics enum Enum of transfer characteristics, follows ITU H.273 for values 0 to ...
@ TRC_IEC_61966_2_4
@ TRC_ITU_R_BT_2020_2_10bit
@ TRC_LOGARITHMIC_100
@ TRC_ITU_R_BT_470_6_SYSTEM_M
@ TRC_ITU_R_BT_470_6_SYSTEM_B_G
@ TRC_ITU_R_BT_1361
@ TRC_ITU_R_BT_2100_0_HLG
@ TRC_ITU_R_BT_2100_0_PQ
@ TRC_ITU_R_BT_601_6
@ TRC_IEC_61966_2_1
@ TRC_ITU_R_BT_709_5
@ TRC_SMPTE_ST_428_1
@ TRC_LOGARITHMIC_100_sqrt10
@ TRC_ITU_R_BT_2020_2_12bit
qreal distance(const QPointF &p1, const QPointF &p2)
void initializeCapabilities() override
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP cfg=nullptr) override
KisConfigWidget * createConfigurationWidget(QWidget *parent, const QByteArray &from="", const QByteArray &to="") const override
createConfigurationWidget creates a widget that can be used to define the settings for a given import...
KisPropertiesConfigurationSP defaultConfiguration(const QByteArray &from="", const QByteArray &to="") const override
defaultConfiguration defines the default settings for the given import export filter
JPEGXLExport(QObject *parent, const QVariantList &)
The KisExifInfoVisitor class looks for a layer with metadata.
KisMetaData::Store * exifInfo()
bool visit(KisNode *) override
static KisExportCheckRegistry * instance()
static KisFilterRegistry * instance()
static KisResourcesInterfaceSP instance()
virtual void resetRowPos()=0
const KisTimeSpan & documentPlaybackRange() const
documentPlaybackRange
void waitForDone()
KisGroupLayerSP rootLayer() const
const KoColorSpace * colorSpace() const
KisImageAnimationInterface * animationInterface() const
void convertImageColorSpace(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
KisPaintDeviceSP projection() const
QRect bounds() const override
The base class for import and export filters.
QPointer< KoUpdater > updater
void addSupportedColorModels(QList< QPair< KoID, KoID > > supportedColorModels, const QString &name, KisExportCheckBase::Level level=KisExportCheckBase::PARTIALLY)
void addCapability(KisExportCheckBase *capability)
virtual void setEnabledFilters(const QStringList &enabledFilters)
enable the filters in the given list; others will be disabled.
virtual bool saveTo(const Store *store, QIODevice *ioDevice, HeaderType headerType=NoHeader) const =0
static KisMetaData::SchemaRegistry * instance()
const Schema * schemaFromUri(const QString &uri) const
static const QString DublinCoreSchemaUri
static KisMetadataBackendRegistry * instance()
KisRasterKeyframeChannel * keyframeChannel() const
void convertTo(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags(), KUndo2Command *parentCommand=nullptr, KoUpdater *progressUpdater=nullptr)
void readBytes(quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h) const
KisHLineConstIteratorSP createHLineConstIteratorNG(qint32 x, qint32 y, qint32 w) const
The KisRasterKeyframe class is a concrete subclass of KisKeyframe that wraps a physical raster image ...
int end() const
virtual quint32 pixelSize() const =0
virtual bool hasHighDynamicRange() const =0
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual const KoColorProfile * profile() const =0
const T value(const QString &id) const
Definition KoID.h:30
QString id() const
Definition KoID.cpp:63
K_PLUGIN_FACTORY_WITH_JSON(KritaASCCDLFactory, "kritaasccdl.json", registerPlugin< KritaASCCDL >();) KritaASCCDL
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
#define bounds(x, a, b)
#define warnFile
Definition kis_debug.h:102
#define errFile
Definition kis_debug.h:123
#define dbgFile
Definition kis_debug.h:57
QByteArray writeLayer(const int width, const int height, KisHLineConstIteratorSP it, float hlgGamma, const KoColorSpace *cs)
QByteArray writeCMYKLayer(const KoID &id, Args &&...args)
void flattenImage(KisImageSP image, KisNodeSP activeNode, MergeFlags flags)
void flattenLayer(KisImageSP image, KisLayerSP layer, MergeFlags flags)
std::future< KisNodeSP > convertToPaintLayer(KisImageSP image, KisNodeSP src)
JxlEncoderOutputProcessor getOutputProcessor()
virtual KisPaintDeviceSP projection() const =0
const QString & compositeOpId() const
virtual QRect exactBounds() const
virtual const KoColorSpace * colorSpace() const =0
bool isAnimated() const
virtual KisPaintDeviceSP paintDevice() const =0
QString name() const
virtual bool isFakeNode() const
virtual bool visible(bool recursive=false) const
bool hasEditablePaintDevice() const
KisPSDLayerStyleSP layerStyle
Definition kis_layer.cc:171
KisNodeSP firstChild() const
Definition kis_node.cpp:361
quint32 childCount() const
Definition kis_node.cpp:414
KisNodeSP at(quint32 index) const
Definition kis_node.cpp:421
The KoColorProfileQuery struct.
virtual QByteArray rawData() const
virtual KoColorimetryUtils::xyY getWhitePointxyY() const =0
virtual ColorPrimaries getColorPrimaries() const
getColorPrimaries
virtual bool hasColorants() const =0
virtual bool isLinear() const =0
virtual QVector< KoColorimetryUtils::xyY > getColorantsxyY() const =0
virtual TransferCharacteristics getTransferCharacteristics() const
getTransferCharacteristics This function should be subclassed at some point so we can get the value f...
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
const KoColorProfile * profileFor(const KoColorProfileQuery &query, const bool generate=true) const
profileFor tries to find the profile that matches these characteristics, if no such profile is found,...