The filter chain calls this method to perform the actual conversion. The passed mimetypes should be a pair of those you specified in your .desktop file. You have to implement this method to make the filter work.
249{
250 if (!io->isReadable()) {
251 errFile <<
"Cannot read image contents";
253 }
254
256 const auto data = io->readAll();
257
258 const auto validation =
259 JxlSignatureCheck(reinterpret_cast<const uint8_t *>(data.constData()), static_cast<size_t>(data.size()));
260
261 switch (validation) {
262 case JXL_SIG_NOT_ENOUGH_BYTES:
263 errFile <<
"Failed magic byte validation, not enough data";
265 case JXL_SIG_INVALID:
266 errFile <<
"Failed magic byte validation, incorrect format";
268 default:
269 break;
270 }
271
272
273 auto runner = JxlResizableParallelRunnerMake(nullptr);
274 auto dec = JxlDecoderMake(nullptr);
275
277
278
279 static constexpr std::array<JxlBlendMode, 3> supportedBlendMode = {JXL_BLEND_REPLACE, JXL_BLEND_BLEND, JXL_BLEND_MULADD};
280
281
282 bool isAnimated = false;
283 bool isMultilayer = false;
284 bool isMultipage = false;
285 bool forceCoalesce = false;
286 {
287 if (JXL_DEC_SUCCESS
288 != JxlDecoderSubscribeEvents(dec.get(), JXL_DEC_BASIC_INFO | JXL_DEC_FRAME)) {
289 errFile <<
"JxlDecoderSubscribeEvents failed";
291 }
292
293 if (JXL_DEC_SUCCESS != JxlDecoderSetParallelRunner(dec.get(), JxlResizableParallelRunner, runner.get())) {
294 errFile <<
"JxlDecoderSetParallelRunner failed";
296 }
297
298 if (JXL_DEC_SUCCESS
299 != JxlDecoderSetInput(dec.get(),
300 reinterpret_cast<const uint8_t *>(data.constData()),
301 static_cast<size_t>(data.size()))) {
302 errFile <<
"JxlDecoderSetInput failed";
304 };
305 JxlDecoderCloseInput(dec.get());
306
307 if (JXL_DEC_SUCCESS != JxlDecoderSetDecompressBoxes(dec.get(), JXL_TRUE)) {
308 errFile <<
"JxlDecoderSetDecompressBoxes failed";
310 };
311
312 if (JXL_DEC_SUCCESS != JxlDecoderSetCoalescing(dec.get(), JXL_FALSE)) {
313 errFile <<
"JxlDecoderSetCoalescing failed";
315 };
316
317 for (;;) {
318 JxlDecoderStatus status = JxlDecoderProcessInput(dec.get());
319
320 if (status == JXL_DEC_ERROR) {
323 } else if (status == JXL_DEC_NEED_MORE_INPUT) {
324 errFile <<
"Error, already provided all input";
326 } else if (status == JXL_DEC_BASIC_INFO) {
327 if (JXL_DEC_SUCCESS != JxlDecoderGetBasicInfo(dec.get(), &
d.m_info)) {
328 errFile <<
"JxlDecoderGetBasicInfo failed";
330 }
331
332 if (
d.m_info.have_animation) {
333 isMultilayer = false;
334 isAnimated = true;
335 isMultipage = true;
336 forceCoalesce = true;
337 }
338
339 dbgFile <<
"Extra Channel[s] info:";
340 for (uint32_t i = 0; i <
d.m_info.num_extra_channels; i++) {
341 if (JXL_DEC_SUCCESS != JxlDecoderGetExtraChannelInfo(dec.get(), i, &
d.m_extra)) {
342 errFile <<
"JxlDecoderGetExtraChannelInfo failed";
343 break;
344 }
345
346
347
348 const QString channelTypeString = [&]() {
349 switch (
d.m_extra.type) {
350 case JXL_CHANNEL_ALPHA:
351 return QString("JXL-Alpha");
352 case JXL_CHANNEL_DEPTH:
353 return QString("JXL-Depth");
354 case JXL_CHANNEL_SPOT_COLOR:
355 return QString("JXL-SpotColor");
356 case JXL_CHANNEL_SELECTION_MASK:
357 return QString("JXL-SelectionMask");
358 case JXL_CHANNEL_BLACK:
359 return QString("JXL-Black");
360 case JXL_CHANNEL_CFA:
361 return QString("JXL-CFA");
362 case JXL_CHANNEL_THERMAL:
363 return QString("JXL-Thermal");
364 default:
365 return QString("JXL-UNKNOWN");
366 }
367 }();
368
369
370 dbgFile <<
"index:" << i <<
" | type:" << channelTypeString;
371 if (
d.m_extra.type == JXL_CHANNEL_BLACK) {
374 }
375 if (
d.m_extra.type == JXL_CHANNEL_SPOT_COLOR) {
376 warnFile <<
"Spot color channels unsupported! Rewinding decoder with coalescing enabled";
377 document->setWarningMessage(i18nc("JPEG-XL errors",
378 "Detected JPEG-XL image with spot color channels, "
379 "importing flattened image."));
380 forceCoalesce = true;
381 }
382 }
383
385 dbgFile <<
"Size:" <<
d.m_info.xsize <<
"x" <<
d.m_info.ysize;
386 dbgFile <<
"Depth:" <<
d.m_info.bits_per_sample <<
d.m_info.exponent_bits_per_sample;
387 dbgFile <<
"Number of color channels:" <<
d.m_info.num_color_channels;
388 dbgFile <<
"Number of extra channels:" <<
d.m_info.num_extra_channels;
389 dbgFile <<
"Extra channels depth:" <<
d.m_info.alpha_bits <<
d.m_info.alpha_exponent_bits;
390 dbgFile <<
"Has animation:" <<
d.m_info.have_animation <<
"loops:" <<
d.m_info.animation.num_loops
391 <<
"tick:" <<
d.m_info.animation.tps_numerator <<
d.m_info.animation.tps_denominator;
392 dbgFile <<
"Internal pixel format:" << (
d.m_info.uses_original_profile ?
"Original" :
"XYB");
393 JxlResizableParallelRunnerSetThreads(
394 runner.get(),
395 JxlResizableParallelRunnerSuggestThreads(
d.m_info.xsize,
d.m_info.ysize));
396
397 if (
d.m_info.exponent_bits_per_sample != 0) {
398 if (
d.m_info.bits_per_sample <= 16) {
399 d.m_pixelFormat.data_type = JXL_TYPE_FLOAT16;
401 }
else if (
d.m_info.bits_per_sample <= 32) {
402 d.m_pixelFormat.data_type = JXL_TYPE_FLOAT;
404 } else {
405 errFile <<
"Unsupported JPEG-XL input depth" <<
d.m_info.bits_per_sample
406 <<
d.m_info.exponent_bits_per_sample;
408 }
409 }
else if (
d.m_info.bits_per_sample <= 8) {
410 d.m_pixelFormat.data_type = JXL_TYPE_UINT8;
412 }
else if (
d.m_info.bits_per_sample <= 16) {
413 d.m_pixelFormat.data_type = JXL_TYPE_UINT16;
415 } else {
416 errFile <<
"Unsupported JPEG-XL input depth" <<
d.m_info.bits_per_sample
417 <<
d.m_info.exponent_bits_per_sample;
419 }
420
421 if (
d.m_info.num_color_channels == 1) {
422
423 d.m_pixelFormat.num_channels = 2;
425 }
else if (
d.m_info.num_color_channels == 3 && !
d.isCMYK) {
426
427 d.m_pixelFormat.num_channels = 4;
429 }
else if (
d.m_info.num_color_channels == 3 &&
d.isCMYK) {
430
431 d.m_pixelFormat.num_channels = 4;
433 } else {
434 warnFile <<
"Forcing a RGBA conversion, unknown color space";
435 d.m_pixelFormat.num_channels = 4;
437 }
438
439 if (!
d.m_info.uses_original_profile) {
440 d.m_pixelFormat_target.data_type =
d.m_pixelFormat.data_type;
441 d.m_pixelFormat.data_type = JXL_TYPE_FLOAT;
442 d.m_depthID_target =
d.m_depthID;
443 d.m_colorID_target =
d.m_colorID;
445
448 }
449 }
450 } else if (status == JXL_DEC_FRAME) {
451 if (JXL_DEC_SUCCESS != JxlDecoderGetFrameHeader(dec.get(), &
d.m_header)) {
452 errFile <<
"JxlDecoderGetFrameHeader failed";
454 }
455
456 const JxlBlendMode blendMode =
d.m_header.layer_info.blend_info.blendmode;
457 const bool isBlendSupported =
458 std::find(supportedBlendMode.begin(), supportedBlendMode.end(), blendMode) != supportedBlendMode.end();
459
460 if (!isBlendSupported) {
461 forceCoalesce = true;
462 }
463
464 if (
d.m_header.duration == 0) {
465 isMultilayer = true;
466 }
else if (
d.m_header.duration == 0xFFFFFFFF) {
467 isMultipage = true;
468 isAnimated = false;
469 forceCoalesce = true;
470 } else {
471 isAnimated = true;
472 isMultipage = false;
473 isMultilayer = false;
474 forceCoalesce = true;
475 }
476 } else if (status == JXL_DEC_SUCCESS) {
477 break;
478 }
479 }
480 }
481 JxlDecoderReset(dec.get());
482
483
484 if (JXL_DEC_SUCCESS != JxlDecoderSetCoalescing(dec.get(), forceCoalesce ? JXL_TRUE : JXL_FALSE)) {
485 errFile <<
"JxlDecoderSetCoalescing failed";
487 }
488
489 if (JXL_DEC_SUCCESS
490 != JxlDecoderSubscribeEvents(dec.get(),
491 JXL_DEC_COLOR_ENCODING | JXL_DEC_FULL_IMAGE | JXL_DEC_BOX | JXL_DEC_FRAME)) {
492 errFile <<
"JxlDecoderSubscribeEvents failed";
494 }
495
496 if (JXL_DEC_SUCCESS != JxlDecoderSetParallelRunner(dec.get(), JxlResizableParallelRunner, runner.get())) {
497 errFile <<
"JxlDecoderSetParallelRunner failed";
499 }
500
501 if (JXL_DEC_SUCCESS
502 != JxlDecoderSetInput(dec.get(),
503 reinterpret_cast<const uint8_t *>(data.constData()),
504 static_cast<size_t>(data.size()))) {
505 errFile <<
"JxlDecoderSetInput failed";
507 };
508 JxlDecoderCloseInput(dec.get());
509
510 if (JXL_DEC_SUCCESS != JxlDecoderSetDecompressBoxes(dec.get(), JXL_TRUE)) {
511 errFile <<
"JxlDecoderSetDecompressBoxes failed";
513 };
514
517 std::multimap<QByteArray, QByteArray> metadataBoxes;
518 std::vector<KisLayerSP> additionalLayers;
519 bool bgLayerSet = false;
520 bool needColorTransform = false;
521 bool needIntermediateTransform = false;
522 QByteArray boxType(5, 0x0);
523 QByteArray box(16384, 0x0);
524 auto boxSize = box.size();
525
526
527 for (;;) {
528 JxlDecoderStatus status = JxlDecoderProcessInput(dec.get());
529
530 if (status == JXL_DEC_ERROR) {
533 } else if (status == JXL_DEC_NEED_MORE_INPUT) {
534 errFile <<
"Error, already provided all input";
536 } else if (status == JXL_DEC_COLOR_ENCODING) {
537
541
542
543
544
545 JxlColorEncoding colorEncoding{};
546 if (JXL_DEC_SUCCESS
547 == JxlDecoderGetColorAsEncodedProfile(dec.get(),
548#if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0, 9, 0)
549 nullptr,
550#endif
551 JXL_COLOR_PROFILE_TARGET_DATA,
552 &colorEncoding)) {
554 switch (colorEncoding.transfer_function) {
555 case JXL_TRANSFER_FUNCTION_PQ: {
556 dbgFile <<
"linearizing from PQ";
559 }
560 case JXL_TRANSFER_FUNCTION_HLG: {
561 dbgFile <<
"linearizing from HLG";
562 if (!document->fileBatchMode()) {
564 dlg.exec();
565 d.applyOOTF = dlg.applyOOTF();
566 d.displayGamma = dlg.gamma();
567 d.displayNits = dlg.nominalPeakBrightness();
568 }
571 }
572 case JXL_TRANSFER_FUNCTION_DCI: {
573 dbgFile <<
"linearizing from SMPTE 428";
576 }
577 case JXL_TRANSFER_FUNCTION_709:
579 case JXL_TRANSFER_FUNCTION_SRGB:
581 case JXL_TRANSFER_FUNCTION_GAMMA: {
582
583 const double estGamma = 1.0 / colorEncoding.gamma;
584 const double error = 0.0001;
585
586
587 if ((std::fabs(estGamma - 1.8) < error) || (std::fabs(estGamma - (461.0 / 256.0)) < error)) {
589 } else if (std::fabs(estGamma - 2.2) < error) {
591 } else if (std::fabs(estGamma - (563.0 / 256.0)) < error) {
593 } else if (std::fabs(estGamma - 2.4) < error) {
595 } else if (std::fabs(estGamma - 2.8) < error) {
597 } else {
598 warnFile <<
"Found custom estimated gamma value for JXL color space" << estGamma;
600 }
601 }
602 case JXL_TRANSFER_FUNCTION_LINEAR:
604 case JXL_TRANSFER_FUNCTION_UNKNOWN:
605 default:
608 }
609 }();
610
612 switch (colorEncoding.primaries) {
613 case JXL_PRIMARIES_SRGB:
615 case JXL_PRIMARIES_2100:
617 case JXL_PRIMARIES_P3:
619 default:
621 }
622 }();
623
625 if (colorEncoding.primaries != JXL_PRIMARIES_CUSTOM) {
626 return {};
627 } else {
628 return {colorEncoding.white_point_xy[0],
629 colorEncoding.white_point_xy[1],
630 colorEncoding.primaries_red_xy[0],
631 colorEncoding.primaries_red_xy[1],
632 colorEncoding.primaries_green_xy[0],
633 colorEncoding.primaries_green_xy[1],
634 colorEncoding.primaries_blue_xy[0],
635 colorEncoding.primaries_blue_xy[1]};
636 }
637 }();
638
639 if (colorEncoding.rendering_intent == JXL_RENDERING_INTENT_PERCEPTUAL) {
641 } else if (colorEncoding.rendering_intent == JXL_RENDERING_INTENT_RELATIVE) {
643 } else if (colorEncoding.rendering_intent == JXL_RENDERING_INTENT_ABSOLUTE) {
645 } else if (colorEncoding.rendering_intent == JXL_RENDERING_INTENT_SATURATION) {
647 } else {
648 warnFile <<
"Cannot determine color rendering intent, set to Perceptual instead";
650 }
651
654
655 dbgFile <<
"CICP profile data:" << colorants << colorPrimaries << transferFunction;
656
657 if (profile) {
658 dbgFile <<
"JXL CICP profile found" << profile->
name();
659
661
663 d.m_pixelFormat.data_type =
d.m_pixelFormat_target.data_type;
664
665
667 }
668 }
669 }
670
672 size_t iccSize = 0;
673 QByteArray iccProfile;
674 if (JXL_DEC_SUCCESS
675 != JxlDecoderGetICCProfileSize(dec.get(),
676#if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0,9,0)
677 nullptr,
678#endif
679 JXL_COLOR_PROFILE_TARGET_DATA,
680 &iccSize)) {
681 errFile <<
"ICC profile size retrieval failed";
682 document->setErrorMessage(i18nc("JPEG-XL errors", "Unable to read the image profile."));
684 }
685 iccProfile.resize(static_cast<int>(iccSize));
686 if (JXL_DEC_SUCCESS
687 != JxlDecoderGetColorAsICCProfile(dec.get(),
688#if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0,9,0)
689 nullptr,
690#endif
691 JXL_COLOR_PROFILE_TARGET_DATA,
692 reinterpret_cast<uint8_t *>(iccProfile.data()),
693 static_cast<size_t>(iccProfile.size()))) {
694 document->setErrorMessage(i18nc("JPEG-XL errors", "Unable to read the image profile."));
696 }
697
698
699 size_t iccTargetSize = 0;
700 QByteArray iccTargetProfile;
701 if (!
d.m_info.uses_original_profile) {
702 if (JXL_DEC_SUCCESS
703 != JxlDecoderGetICCProfileSize(dec.get(),
704#if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0,9,0)
705 nullptr,
706#endif
707 JXL_COLOR_PROFILE_TARGET_ORIGINAL,
708 &iccTargetSize)) {
709 errFile <<
"ICC profile size retrieval failed";
710 document->setErrorMessage(i18nc("JPEG-XL errors", "Unable to read the image profile."));
712 }
713 iccTargetProfile.resize(static_cast<int>(iccTargetSize));
714 if (JXL_DEC_SUCCESS
715 != JxlDecoderGetColorAsICCProfile(dec.get(),
716#if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0,9,0)
717 nullptr,
718#endif
719 JXL_COLOR_PROFILE_TARGET_ORIGINAL,
720 reinterpret_cast<uint8_t *>(iccTargetProfile.data()),
721 static_cast<size_t>(iccTargetProfile.size()))) {
722 document->setErrorMessage(i18nc("JPEG-XL errors", "Unable to read the image profile."));
724 }
725 }
726
727 if (iccTargetSize && (iccProfile != iccTargetProfile)) {
728
729
730
731
732
733
734 dbgFile <<
"XYB with color transform needed";
735 needColorTransform = true;
738 iccProfile);
742 iccTargetProfile);
745 profileIntermediate);
747 d.m_depthID_target.id(),
748 iccTargetProfile);
750 d.m_depthID_target.id(),
751 profileTarget);
752
753
756 needIntermediateTransform = true;
757 }
758 }
else if (!
d.m_info.uses_original_profile) {
759
760
761
762
763 dbgFile <<
"XYB without color transform needed";
764 needColorTransform = false;
765 d.m_depthID =
d.m_depthID_target;
766 d.m_colorID =
d.m_colorID_target;
767 d.m_pixelFormat.data_type =
d.m_pixelFormat_target.data_type;
769
770
772 dbgFile <<
"JXL CICP data couldn't be handled, falling back to ICC profile retrieval";
774 d.m_depthID_target.id(),
775 iccProfile);
777 d.m_depthID_target.id(),
778 profile);
779 }
780 } else {
781
782 dbgFile <<
"Original without color transform needed";
783 needColorTransform = false;
786 iccProfile);
788 }
789 }
790
792 dbgFile <<
"Source profile:" <<
d.cs->profile()->name();
793 dbgFile <<
"Source space:" <<
d.cs->name() <<
d.cs->colorModelId() <<
d.cs->colorDepthId();
794 dbgFile <<
"Target profile:" <<
d.cs_target->profile()->name();
795 dbgFile <<
"Color space:" <<
d.cs_target->name() <<
d.cs_target->colorModelId()
796 <<
d.cs_target->colorDepthId();
797 } else {
798 dbgFile <<
"Color space:" <<
d.cs->name() <<
d.cs->colorModelId() <<
d.cs->colorDepthId();
799 }
800 dbgFile <<
"JXL depth" <<
d.m_pixelFormat.data_type;
801
802 d.lCoef =
d.cs->lumaCoefficients();
803
804 image =
new KisImage(document->createUndoStore(),
805 static_cast<int>(
d.m_info.xsize),
806 static_cast<int>(
d.m_info.ysize),
808 "JPEG-XL image");
809
810 layer =
new KisPaintLayer(image, image->nextLayerName(), UCHAR_MAX);
811 } else if (status == JXL_DEC_NEED_IMAGE_OUT_BUFFER) {
813
814
815 size_t rawSize = 0;
816 if (JXL_DEC_SUCCESS != JxlDecoderImageOutBufferSize(dec.get(), &
d.m_pixelFormat, &rawSize)) {
817 qWarning() << "JxlDecoderImageOutBufferSize failed";
819 }
820 d.m_rawData.resize(rawSize);
821 if (JXL_DEC_SUCCESS
822 != JxlDecoderSetImageOutBuffer(dec.get(),
824 reinterpret_cast<uint8_t *
>(
d.m_rawData.data()),
825 static_cast<size_t>(
d.m_rawData.size()))) {
826 qWarning() << "JxlDecoderSetImageOutBuffer failed";
828 }
829
831
832 size_t bufferSize = 0;
833 if (JXL_DEC_SUCCESS
834 != JxlDecoderExtraChannelBufferSize(dec.get(), &
d.m_pixelFormat, &bufferSize,
d.cmykChannelID)) {
835 errFile <<
"JxlDecoderExtraChannelBufferSize failed";
837 break;
838 }
839 d.kPlane.resize(bufferSize);
840 if (JXL_DEC_SUCCESS
841 != JxlDecoderSetExtraChannelBuffer(dec.get(),
844 bufferSize,
846 errFile <<
"JxlDecoderSetExtraChannelBuffer failed";
848 break;
849 }
850 }
851 } else if (status == JXL_DEC_FRAME) {
852 if (JXL_DEC_SUCCESS != JxlDecoderGetFrameHeader(dec.get(), &
d.m_header)) {
853 errFile <<
"JxlDecoderGetFrameHeader failed";
855 }
856
857 const JxlBlendMode blendMode =
d.m_header.layer_info.blend_info.blendmode;
858
859 if (isMultilayer || isMultipage) {
860 QString layerName;
861 QByteArray layerNameRaw;
862 if (
d.m_header.name_length) {
864 {
865 document->setErrorMessage(i18nc("JPEG-XL", "Invalid JPEG-XL layer name length"));
867 }
868 layerNameRaw.resize(
static_cast<int>(
d.m_header.name_length + 1));
869 if (JXL_DEC_SUCCESS
870 != JxlDecoderGetFrameName(dec.get(),
871 layerNameRaw.data(),
872 static_cast<size_t>(layerNameRaw.size()))) {
873 errFile <<
"JxlDecoderGetFrameName failed";
874 break;
875 }
876 dbgFile <<
"\tlayer name:" << QString(layerNameRaw);
877 layerName = QString(layerNameRaw);
878 } else {
879 layerName = QString("Layer");
880 }
881
882 if (!bgLayerSet) {
883 if (!layerNameRaw.isEmpty()) {
884 layer->setName(layerName);
885 }
886 } else {
887 additionalLayers.emplace_back(
new KisPaintLayer(image, layerName, UCHAR_MAX));
888 if (blendMode == JXL_BLEND_MULADD) {
889 additionalLayers.back()->setCompositeOpId(QString("add"));
890 }
891 }
892 }
893 } else if (status == JXL_DEC_FULL_IMAGE) {
894
896 const JxlLayerInfo layerInfo =
d.m_header.layer_info;
897 const QRect layerBounds = QRect(static_cast<int>(layerInfo.crop_x0),
898 static_cast<int>(layerInfo.crop_y0),
899 static_cast<int>(layerInfo.xsize),
900 static_cast<int>(layerInfo.ysize));
901 if (isAnimated) {
902 dbgFile <<
"Importing frame @" <<
d.m_nextFrameTime
903 <<
d.m_header.duration;
904
905
906
907
908
909 const uint32_t frameDurationNorm =
d.m_header.duration == 0xFFFFFFFF ? 1 :
d.m_header.duration;
910 if (
d.m_nextFrameTime == 0) {
911 dbgFile <<
"Animation detected, ticks per second:"
912 <<
d.m_info.animation.tps_numerator
913 <<
d.m_info.animation.tps_denominator;
914
915
916
917
918
919 int framerate =
920 std::lround(
d.m_info.animation.tps_numerator
921 / static_cast<double>(
922 d.m_info.animation.tps_denominator));
923 if (framerate > 240) {
924 warnFile <<
"JXL ticks per second value exceeds 240, "
925 "approximating FPS from the duration of "
926 "the first frame";
927 document->setWarningMessage(
928 i18nc("JPEG-XL errors",
929 "The animation declares a frame rate of more "
930 "than 240 FPS."));
931 const int approximatedFramerate = std::lround(
932 1000.0 /
static_cast<double>(
d.m_header.duration));
933 d.m_durationFrameInTicks =
934 static_cast<int>(frameDurationNorm);
935 framerate = std::max(approximatedFramerate, 1);
936 } else {
937 d.m_durationFrameInTicks = 1;
938 }
939 dbgFile <<
"Framerate:" << framerate;
940 layer->enableAnimation();
941 image->animationInterface()->setDocumentRangeStartFrame(0);
942 image->animationInterface()->setFramerate(framerate);
943 }
944
945 const int currentFrameTime = std::lround(
946 static_cast<double>(
d.m_nextFrameTime)
947 /
static_cast<double>(
d.m_durationFrameInTicks));
948
951 image->animationInterface()->setDocumentRangeEndFrame(
952 std::lround(
static_cast<double>(
d.m_nextFrameTime
953 + frameDurationNorm)
954 /
static_cast<double>(
d.m_durationFrameInTicks))
955 - 1);
956 frame->
importFrame(currentFrameTime,
d.m_currentFrame,
nullptr);
957 d.m_nextFrameTime +=
static_cast<int>(frameDurationNorm);
958 } else {
959 if (
d.isCMYK &&
d.m_info.uses_original_profile) {
961 layerBounds.y(),
962 layerBounds.width(),
963 layerBounds.height());
964
965
966 planes[3] =
reinterpret_cast<quint8 *
>(
d.kPlane.data());
967 d.m_currentFrame->writePlanarBytes(planes,
968 layerBounds.x(),
969 layerBounds.y(),
970 layerBounds.width(),
971 layerBounds.height());
972
973
974
980 f->process(
d.m_currentFrame, layerBounds, kfc->cloneWithResourcesSnapshot());
981 }
982 if (!bgLayerSet) {
983 layer->paintDevice()->makeCloneFrom(
d.m_currentFrame, layerBounds);
984 bgLayerSet = true;
985 } else {
986 additionalLayers.back()->paintDevice()->makeCloneFrom(
d.m_currentFrame, layerBounds);
987 }
988 }
989 } else if (status == JXL_DEC_SUCCESS || status == JXL_DEC_BOX) {
990 if (std::strlen(boxType.data()) != 0) {
991
992 const auto availOut = JxlDecoderReleaseBoxBuffer(dec.get());
993 const int finalSize = box.size() - static_cast<int>(availOut);
994
995
996 QByteArray type = boxType.toLower();
997 if ((std::equal(
exifTag.begin(),
exifTag.end(), type.constBegin())
998 || std::equal(
xmpTag.begin(),
xmpTag.end(), type.constBegin()))
999 && finalSize != 0) {
1000 metadataBoxes.emplace(type, QByteArray(box.data(), finalSize));
1001 }
1002
1003
1004 boxType.fill('\0');
1005 }
1006 if (status == JXL_DEC_SUCCESS) {
1007
1008
1009
1010
1011 for (auto &metaBox : metadataBoxes) {
1012 const QByteArray &type = metaBox.first;
1013 QByteArray &
value = metaBox.second;
1014 QBuffer buf(&
value);
1015 if (std::equal(
exifTag.begin(),
exifTag.end(), type.constBegin())) {
1016 dbgFile <<
"Loading EXIF data. Size: " <<
value.size();
1017
1018 const auto *backend =
1020 "exif");
1021
1022 backend->
loadFrom(layer->metaData(), &buf);
1023 }
else if (std::equal(
xmpTag.begin(),
xmpTag.end(), type.constBegin())) {
1024 dbgFile <<
"Loading XMP or IPTC data. Size: " <<
value.size();
1025
1026 const auto *xmpBackend =
1028 "xmp");
1029
1030 if (!xmpBackend->loadFrom(layer->metaData(), &buf)) {
1033 "iptc");
1034 iptcBackend->
loadFrom(layer->metaData(), &buf);
1035 }
1036 }
1037 }
1038
1039
1040
1041 image->addNode(layer, image->rootLayer().data());
1042
1043 for (
const KisLayerSP &addLayer : additionalLayers) {
1044 image->addNode(addLayer, image->rootLayer().data());
1045 }
1046 if (needColorTransform) {
1047 if (needIntermediateTransform) {
1048 dbgFile <<
"Transforming to intermediate color space";
1049 image->convertImageColorSpace(
d.cs_intermediate,
1052 image->waitForDone();
1053 }
1054 dbgFile <<
"Transforming to target color space";
1055 image->convertImageColorSpace(
d.cs_target,
1058 image->waitForDone();
1059 }
1060 document->setCurrentImage(image);
1062 } else {
1063 if (JxlDecoderGetBoxType(dec.get(), boxType.data(), JXL_TRUE) != JXL_DEC_SUCCESS) {
1064 errFile <<
"JxlDecoderGetBoxType failed";
1066 }
1067 const QByteArray type = boxType.toLower();
1068 if (std::equal(
exifTag.begin(),
exifTag.end(), type.constBegin())
1069 || std::equal(
xmpTag.begin(),
xmpTag.end(), type.constBegin())) {
1070 if (JxlDecoderSetBoxBuffer(
1071 dec.get(),
1072 reinterpret_cast<uint8_t *>(box.data()),
1073 static_cast<size_t>(box.size()))
1074 != JXL_DEC_SUCCESS) {
1075 errFile <<
"JxlDecoderSetBoxBuffer failed";
1077 }
1078 } else {
1079 dbgFile <<
"Skipping box" << boxType.data();
1080 }
1081 }
1082 } else if (status == JXL_DEC_BOX_NEED_MORE_OUTPUT) {
1083
1084 boxSize = box.size();
1085 box.resize(boxSize * 2);
1086
1087 JxlDecoderReleaseBoxBuffer(dec.get());
1088 if (JxlDecoderSetBoxBuffer(
1089 dec.get(),
1090 reinterpret_cast<uint8_t *>(box.data() + boxSize),
1091 static_cast<size_t>(box.size() - boxSize))
1092 != JXL_DEC_SUCCESS) {
1093 errFile <<
"JxlDecoderGetBoxType failed";
1095 }
1096 } else {
1097 errFile <<
"Unknown decoder status" << status;
1099 }
1100 }
1101
1103}
static constexpr std::array< char, 4 > exifTag
float value(const T *src, size_t ch)
static constexpr std::array< char, 4 > xmpTag
void generateCallback(JPEGXLImportData &d)
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_ITU_R_BT_470_6_SYSTEM_M
@ TRC_ITU_R_BT_470_6_SYSTEM_B_G
static KisFilterRegistry * instance()
static KisResourcesInterfaceSP instance()
The KisRasterKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisRas...
void importFrame(int time, KisPaintDeviceSP sourceDevice, KUndo2Command *parentCommand)
const T value(const QString &id) const
#define KIS_SAFE_ASSERT_RECOVER(cond)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
@ FormatFeaturesUnsupported
The KoColorProfileQuery struct.
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,...
const KoColorProfile * createColorProfile(const QString &colorModelId, const QString &colorDepthId, const QByteArray &rawData)