248 if (!io->isReadable()) {
249 errFile <<
"Cannot read image contents";
254 const auto data = io->readAll();
256 const auto validation =
257 JxlSignatureCheck(
reinterpret_cast<const uint8_t *
>(data.constData()),
static_cast<size_t>(data.size()));
259 switch (validation) {
260 case JXL_SIG_NOT_ENOUGH_BYTES:
261 errFile <<
"Failed magic byte validation, not enough data";
263 case JXL_SIG_INVALID:
264 errFile <<
"Failed magic byte validation, incorrect format";
271 auto runner = JxlResizableParallelRunnerMake(
nullptr);
272 auto dec = JxlDecoderMake(
nullptr);
277 static constexpr std::array<JxlBlendMode, 3> supportedBlendMode = {JXL_BLEND_REPLACE, JXL_BLEND_BLEND, JXL_BLEND_MULADD};
280 bool isAnimated =
false;
281 bool isMultilayer =
false;
282 bool isMultipage =
false;
283 bool forceCoalesce =
false;
286 != JxlDecoderSubscribeEvents(dec.get(), JXL_DEC_BASIC_INFO | JXL_DEC_FRAME)) {
287 errFile <<
"JxlDecoderSubscribeEvents failed";
291 if (JXL_DEC_SUCCESS != JxlDecoderSetParallelRunner(dec.get(), JxlResizableParallelRunner, runner.get())) {
292 errFile <<
"JxlDecoderSetParallelRunner failed";
297 != JxlDecoderSetInput(dec.get(),
298 reinterpret_cast<const uint8_t *
>(data.constData()),
299 static_cast<size_t>(data.size()))) {
300 errFile <<
"JxlDecoderSetInput failed";
303 JxlDecoderCloseInput(dec.get());
305 if (JXL_DEC_SUCCESS != JxlDecoderSetDecompressBoxes(dec.get(), JXL_TRUE)) {
306 errFile <<
"JxlDecoderSetDecompressBoxes failed";
310 if (JXL_DEC_SUCCESS != JxlDecoderSetCoalescing(dec.get(), JXL_FALSE)) {
311 errFile <<
"JxlDecoderSetCoalescing failed";
316 JxlDecoderStatus status = JxlDecoderProcessInput(dec.get());
318 if (status == JXL_DEC_ERROR) {
321 }
else if (status == JXL_DEC_NEED_MORE_INPUT) {
322 errFile <<
"Error, already provided all input";
324 }
else if (status == JXL_DEC_BASIC_INFO) {
325 if (JXL_DEC_SUCCESS != JxlDecoderGetBasicInfo(dec.get(), &
d.m_info)) {
326 errFile <<
"JxlDecoderGetBasicInfo failed";
330 if (
d.m_info.have_animation) {
331 isMultilayer =
false;
334 forceCoalesce =
true;
337 dbgFile <<
"Extra Channel[s] info:";
338 for (uint32_t i = 0; i <
d.m_info.num_extra_channels; i++) {
339 if (JXL_DEC_SUCCESS != JxlDecoderGetExtraChannelInfo(dec.get(), i, &
d.m_extra)) {
340 errFile <<
"JxlDecoderGetExtraChannelInfo failed";
346 const QString channelTypeString = [&]() {
347 switch (
d.m_extra.type) {
348 case JXL_CHANNEL_ALPHA:
349 return QString(
"JXL-Alpha");
350 case JXL_CHANNEL_DEPTH:
351 return QString(
"JXL-Depth");
352 case JXL_CHANNEL_SPOT_COLOR:
353 return QString(
"JXL-SpotColor");
354 case JXL_CHANNEL_SELECTION_MASK:
355 return QString(
"JXL-SelectionMask");
356 case JXL_CHANNEL_BLACK:
357 return QString(
"JXL-Black");
358 case JXL_CHANNEL_CFA:
359 return QString(
"JXL-CFA");
360 case JXL_CHANNEL_THERMAL:
361 return QString(
"JXL-Thermal");
363 return QString(
"JXL-UNKNOWN");
368 dbgFile <<
"index:" << i <<
" | type:" << channelTypeString;
369 if (
d.m_extra.type == JXL_CHANNEL_BLACK) {
373 if (
d.m_extra.type == JXL_CHANNEL_SPOT_COLOR) {
374 warnFile <<
"Spot color channels unsupported! Rewinding decoder with coalescing enabled";
375 document->setWarningMessage(i18nc(
"JPEG-XL errors",
376 "Detected JPEG-XL image with spot color channels, "
377 "importing flattened image."));
378 forceCoalesce =
true;
383 dbgFile <<
"Size:" <<
d.m_info.xsize <<
"x" <<
d.m_info.ysize;
384 dbgFile <<
"Depth:" <<
d.m_info.bits_per_sample <<
d.m_info.exponent_bits_per_sample;
385 dbgFile <<
"Number of color channels:" <<
d.m_info.num_color_channels;
386 dbgFile <<
"Number of extra channels:" <<
d.m_info.num_extra_channels;
387 dbgFile <<
"Extra channels depth:" <<
d.m_info.alpha_bits <<
d.m_info.alpha_exponent_bits;
388 dbgFile <<
"Has animation:" <<
d.m_info.have_animation <<
"loops:" <<
d.m_info.animation.num_loops
389 <<
"tick:" <<
d.m_info.animation.tps_numerator <<
d.m_info.animation.tps_denominator;
390 dbgFile <<
"Internal pixel format:" << (
d.m_info.uses_original_profile ?
"Original" :
"XYB");
391 JxlResizableParallelRunnerSetThreads(
393 JxlResizableParallelRunnerSuggestThreads(
d.m_info.xsize,
d.m_info.ysize));
395 if (
d.m_info.exponent_bits_per_sample != 0) {
396 if (
d.m_info.bits_per_sample <= 16) {
397 d.m_pixelFormat.data_type = JXL_TYPE_FLOAT16;
399 }
else if (
d.m_info.bits_per_sample <= 32) {
400 d.m_pixelFormat.data_type = JXL_TYPE_FLOAT;
403 errFile <<
"Unsupported JPEG-XL input depth" <<
d.m_info.bits_per_sample
404 <<
d.m_info.exponent_bits_per_sample;
407 }
else if (
d.m_info.bits_per_sample <= 8) {
408 d.m_pixelFormat.data_type = JXL_TYPE_UINT8;
410 }
else if (
d.m_info.bits_per_sample <= 16) {
411 d.m_pixelFormat.data_type = JXL_TYPE_UINT16;
414 errFile <<
"Unsupported JPEG-XL input depth" <<
d.m_info.bits_per_sample
415 <<
d.m_info.exponent_bits_per_sample;
419 if (
d.m_info.num_color_channels == 1) {
421 d.m_pixelFormat.num_channels = 2;
423 }
else if (
d.m_info.num_color_channels == 3 && !
d.isCMYK) {
425 d.m_pixelFormat.num_channels = 4;
427 }
else if (
d.m_info.num_color_channels == 3 &&
d.isCMYK) {
429 d.m_pixelFormat.num_channels = 4;
432 warnFile <<
"Forcing a RGBA conversion, unknown color space";
433 d.m_pixelFormat.num_channels = 4;
437 if (!
d.m_info.uses_original_profile) {
438 d.m_pixelFormat_target.data_type =
d.m_pixelFormat.data_type;
439 d.m_pixelFormat.data_type = JXL_TYPE_FLOAT;
440 d.m_depthID_target =
d.m_depthID;
441 d.m_colorID_target =
d.m_colorID;
448 }
else if (status == JXL_DEC_FRAME) {
449 if (JXL_DEC_SUCCESS != JxlDecoderGetFrameHeader(dec.get(), &
d.m_header)) {
450 errFile <<
"JxlDecoderGetFrameHeader failed";
454 const JxlBlendMode blendMode =
d.m_header.layer_info.blend_info.blendmode;
455 const bool isBlendSupported =
456 std::find(supportedBlendMode.begin(), supportedBlendMode.end(), blendMode) != supportedBlendMode.end();
458 if (!isBlendSupported) {
459 forceCoalesce =
true;
462 if (
d.m_header.duration == 0) {
464 }
else if (
d.m_header.duration == 0xFFFFFFFF) {
467 forceCoalesce =
true;
471 isMultilayer =
false;
472 forceCoalesce =
true;
474 }
else if (status == JXL_DEC_SUCCESS) {
479 JxlDecoderReset(dec.get());
482 if (JXL_DEC_SUCCESS != JxlDecoderSetCoalescing(dec.get(), forceCoalesce ? JXL_TRUE : JXL_FALSE)) {
483 errFile <<
"JxlDecoderSetCoalescing failed";
488 != JxlDecoderSubscribeEvents(dec.get(),
489 JXL_DEC_COLOR_ENCODING | JXL_DEC_FULL_IMAGE | JXL_DEC_BOX | JXL_DEC_FRAME)) {
490 errFile <<
"JxlDecoderSubscribeEvents failed";
494 if (JXL_DEC_SUCCESS != JxlDecoderSetParallelRunner(dec.get(), JxlResizableParallelRunner, runner.get())) {
495 errFile <<
"JxlDecoderSetParallelRunner failed";
500 != JxlDecoderSetInput(dec.get(),
501 reinterpret_cast<const uint8_t *
>(data.constData()),
502 static_cast<size_t>(data.size()))) {
503 errFile <<
"JxlDecoderSetInput failed";
506 JxlDecoderCloseInput(dec.get());
508 if (JXL_DEC_SUCCESS != JxlDecoderSetDecompressBoxes(dec.get(), JXL_TRUE)) {
509 errFile <<
"JxlDecoderSetDecompressBoxes failed";
515 std::multimap<QByteArray, QByteArray> metadataBoxes;
516 std::vector<KisLayerSP> additionalLayers;
517 bool bgLayerSet =
false;
518 bool needColorTransform =
false;
519 bool needIntermediateTransform =
false;
520 QByteArray boxType(5, 0x0);
521 QByteArray box(16384, 0x0);
522 auto boxSize = box.size();
526 JxlDecoderStatus status = JxlDecoderProcessInput(dec.get());
528 if (status == JXL_DEC_ERROR) {
531 }
else if (status == JXL_DEC_NEED_MORE_INPUT) {
532 errFile <<
"Error, already provided all input";
534 }
else if (status == JXL_DEC_COLOR_ENCODING) {
543 JxlColorEncoding colorEncoding{};
545 == JxlDecoderGetColorAsEncodedProfile(dec.get(),
546#
if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0, 9, 0)
549 JXL_COLOR_PROFILE_TARGET_DATA,
552 switch (colorEncoding.transfer_function) {
553 case JXL_TRANSFER_FUNCTION_PQ: {
554 dbgFile <<
"linearizing from PQ";
558 case JXL_TRANSFER_FUNCTION_HLG: {
559 dbgFile <<
"linearizing from HLG";
563 case JXL_TRANSFER_FUNCTION_DCI: {
564 dbgFile <<
"linearizing from SMPTE 428";
568 case JXL_TRANSFER_FUNCTION_709:
570 case JXL_TRANSFER_FUNCTION_SRGB:
572 case JXL_TRANSFER_FUNCTION_GAMMA: {
574 const double estGamma = 1.0 / colorEncoding.gamma;
575 const double error = 0.0001;
578 if ((std::fabs(estGamma - 1.8) < error) || (std::fabs(estGamma - (461.0 / 256.0)) < error)) {
580 }
else if (std::fabs(estGamma - 2.2) < error) {
582 }
else if (std::fabs(estGamma - (563.0 / 256.0)) < error) {
584 }
else if (std::fabs(estGamma - 2.4) < error) {
586 }
else if (std::fabs(estGamma - 2.8) < error) {
589 warnFile <<
"Found custom estimated gamma value for JXL color space" << estGamma;
593 case JXL_TRANSFER_FUNCTION_LINEAR:
595 case JXL_TRANSFER_FUNCTION_UNKNOWN:
603 switch (colorEncoding.primaries) {
604 case JXL_PRIMARIES_SRGB:
606 case JXL_PRIMARIES_2100:
608 case JXL_PRIMARIES_P3:
616 if (colorEncoding.primaries != JXL_PRIMARIES_CUSTOM) {
619 return {colorEncoding.white_point_xy[0],
620 colorEncoding.white_point_xy[1],
621 colorEncoding.primaries_red_xy[0],
622 colorEncoding.primaries_red_xy[1],
623 colorEncoding.primaries_green_xy[0],
624 colorEncoding.primaries_green_xy[1],
625 colorEncoding.primaries_blue_xy[0],
626 colorEncoding.primaries_blue_xy[1]};
630 if (colorEncoding.rendering_intent == JXL_RENDERING_INTENT_PERCEPTUAL) {
632 }
else if (colorEncoding.rendering_intent == JXL_RENDERING_INTENT_RELATIVE) {
634 }
else if (colorEncoding.rendering_intent == JXL_RENDERING_INTENT_ABSOLUTE) {
636 }
else if (colorEncoding.rendering_intent == JXL_RENDERING_INTENT_SATURATION) {
639 warnFile <<
"Cannot determine color rendering intent, set to Perceptual instead";
646 dbgFile <<
"CICP profile data:" << colorants << colorPrimaries << transferFunction;
649 dbgFile <<
"JXL CICP profile found" << profile->
name();
654 d.m_pixelFormat.data_type =
d.m_pixelFormat_target.data_type;
664 QByteArray iccProfile;
666 != JxlDecoderGetICCProfileSize(dec.get(),
667#
if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0,9,0)
670 JXL_COLOR_PROFILE_TARGET_DATA,
672 errFile <<
"ICC profile size retrieval failed";
673 document->setErrorMessage(i18nc(
"JPEG-XL errors",
"Unable to read the image profile."));
676 iccProfile.resize(
static_cast<int>(iccSize));
678 != JxlDecoderGetColorAsICCProfile(dec.get(),
679#
if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0,9,0)
682 JXL_COLOR_PROFILE_TARGET_DATA,
683 reinterpret_cast<uint8_t *
>(iccProfile.data()),
684 static_cast<size_t>(iccProfile.size()))) {
685 document->setErrorMessage(i18nc(
"JPEG-XL errors",
"Unable to read the image profile."));
690 size_t iccTargetSize = 0;
691 QByteArray iccTargetProfile;
692 if (!
d.m_info.uses_original_profile) {
694 != JxlDecoderGetICCProfileSize(dec.get(),
695#
if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0,9,0)
698 JXL_COLOR_PROFILE_TARGET_ORIGINAL,
700 errFile <<
"ICC profile size retrieval failed";
701 document->setErrorMessage(i18nc(
"JPEG-XL errors",
"Unable to read the image profile."));
704 iccTargetProfile.resize(
static_cast<int>(iccTargetSize));
706 != JxlDecoderGetColorAsICCProfile(dec.get(),
707#
if JPEGXL_NUMERIC_VERSION < JPEGXL_COMPUTE_NUMERIC_VERSION(0,9,0)
710 JXL_COLOR_PROFILE_TARGET_ORIGINAL,
711 reinterpret_cast<uint8_t *
>(iccTargetProfile.data()),
712 static_cast<size_t>(iccTargetProfile.size()))) {
713 document->setErrorMessage(i18nc(
"JPEG-XL errors",
"Unable to read the image profile."));
718 if (iccTargetSize && (iccProfile != iccTargetProfile)) {
725 dbgFile <<
"XYB with color transform needed";
726 needColorTransform =
true;
736 profileIntermediate);
738 d.m_depthID_target.id(),
741 d.m_depthID_target.id(),
747 needIntermediateTransform =
true;
749 }
else if (!
d.m_info.uses_original_profile) {
754 dbgFile <<
"XYB without color transform needed";
755 needColorTransform =
false;
756 d.m_depthID =
d.m_depthID_target;
757 d.m_colorID =
d.m_colorID_target;
758 d.m_pixelFormat.data_type =
d.m_pixelFormat_target.data_type;
763 dbgFile <<
"JXL CICP data couldn't be handled, falling back to ICC profile retrieval";
765 d.m_depthID_target.id(),
768 d.m_depthID_target.id(),
773 dbgFile <<
"Original without color transform needed";
774 needColorTransform =
false;
783 dbgFile <<
"Source profile:" <<
d.cs->profile()->name();
784 dbgFile <<
"Source space:" <<
d.cs->name() <<
d.cs->colorModelId() <<
d.cs->colorDepthId();
785 dbgFile <<
"Target profile:" <<
d.cs_target->profile()->name();
786 dbgFile <<
"Color space:" <<
d.cs_target->name() <<
d.cs_target->colorModelId()
787 <<
d.cs_target->colorDepthId();
789 dbgFile <<
"Color space:" <<
d.cs->name() <<
d.cs->colorModelId() <<
d.cs->colorDepthId();
791 dbgFile <<
"JXL depth" <<
d.m_pixelFormat.data_type;
793 d.lCoef =
d.cs->lumaCoefficients();
795 image =
new KisImage(document->createUndoStore(),
796 static_cast<int>(
d.m_info.xsize),
797 static_cast<int>(
d.m_info.ysize),
801 layer =
new KisPaintLayer(image, image->nextLayerName(), UCHAR_MAX);
802 }
else if (status == JXL_DEC_NEED_IMAGE_OUT_BUFFER) {
807 if (JXL_DEC_SUCCESS != JxlDecoderImageOutBufferSize(dec.get(), &
d.m_pixelFormat, &rawSize)) {
808 qWarning() <<
"JxlDecoderImageOutBufferSize failed";
811 d.m_rawData.resize(rawSize);
813 != JxlDecoderSetImageOutBuffer(dec.get(),
815 reinterpret_cast<uint8_t *
>(
d.m_rawData.data()),
816 static_cast<size_t>(
d.m_rawData.size()))) {
817 qWarning() <<
"JxlDecoderSetImageOutBuffer failed";
823 size_t bufferSize = 0;
825 != JxlDecoderExtraChannelBufferSize(dec.get(), &
d.m_pixelFormat, &bufferSize,
d.cmykChannelID)) {
826 errFile <<
"JxlDecoderExtraChannelBufferSize failed";
830 d.kPlane.resize(bufferSize);
832 != JxlDecoderSetExtraChannelBuffer(dec.get(),
837 errFile <<
"JxlDecoderSetExtraChannelBuffer failed";
842 }
else if (status == JXL_DEC_FRAME) {
843 if (JXL_DEC_SUCCESS != JxlDecoderGetFrameHeader(dec.get(), &
d.m_header)) {
844 errFile <<
"JxlDecoderGetFrameHeader failed";
848 const JxlBlendMode blendMode =
d.m_header.layer_info.blend_info.blendmode;
850 if (isMultilayer || isMultipage) {
852 QByteArray layerNameRaw;
853 if (
d.m_header.name_length) {
856 document->setErrorMessage(i18nc(
"JPEG-XL",
"Invalid JPEG-XL layer name length"));
859 layerNameRaw.resize(
static_cast<int>(
d.m_header.name_length + 1));
861 != JxlDecoderGetFrameName(dec.get(),
863 static_cast<size_t>(layerNameRaw.size()))) {
864 errFile <<
"JxlDecoderGetFrameName failed";
867 dbgFile <<
"\tlayer name:" << QString(layerNameRaw);
870 layerName = QString::fromUtf8(layerNameRaw.data(),
d.m_header.name_length);
872 layerName = QString(
"Layer");
876 if (!layerNameRaw.isEmpty()) {
877 layer->setName(layerName);
880 additionalLayers.emplace_back(
new KisPaintLayer(image, layerName, UCHAR_MAX));
881 if (blendMode == JXL_BLEND_MULADD) {
882 additionalLayers.back()->setCompositeOpId(QString(
"add"));
886 }
else if (status == JXL_DEC_FULL_IMAGE) {
889 const JxlLayerInfo layerInfo =
d.m_header.layer_info;
890 const QRect layerBounds = QRect(
static_cast<int>(layerInfo.crop_x0),
891 static_cast<int>(layerInfo.crop_y0),
892 static_cast<int>(layerInfo.xsize),
893 static_cast<int>(layerInfo.ysize));
895 dbgFile <<
"Importing frame @" <<
d.m_nextFrameTime
896 <<
d.m_header.duration;
902 const uint32_t frameDurationNorm =
d.m_header.duration == 0xFFFFFFFF ? 1 :
d.m_header.duration;
903 if (
d.m_nextFrameTime == 0) {
904 dbgFile <<
"Animation detected, ticks per second:"
905 <<
d.m_info.animation.tps_numerator
906 <<
d.m_info.animation.tps_denominator;
913 std::lround(
d.m_info.animation.tps_numerator
914 /
static_cast<double>(
915 d.m_info.animation.tps_denominator));
916 if (framerate > 240) {
917 warnFile <<
"JXL ticks per second value exceeds 240, "
918 "approximating FPS from the duration of "
920 document->setWarningMessage(
921 i18nc(
"JPEG-XL errors",
922 "The animation declares a frame rate of more "
924 const int approximatedFramerate = std::lround(
925 1000.0 /
static_cast<double>(
d.m_header.duration));
926 d.m_durationFrameInTicks =
927 static_cast<int>(frameDurationNorm);
928 framerate = std::max(approximatedFramerate, 1);
930 d.m_durationFrameInTicks = 1;
932 dbgFile <<
"Framerate:" << framerate;
933 layer->enableAnimation();
934 image->animationInterface()->setDocumentRangeStartFrame(0);
935 image->animationInterface()->setFramerate(framerate);
938 const int currentFrameTime = std::lround(
939 static_cast<double>(
d.m_nextFrameTime)
940 /
static_cast<double>(
d.m_durationFrameInTicks));
944 image->animationInterface()->setDocumentRangeEndFrame(
945 std::lround(
static_cast<double>(
d.m_nextFrameTime
947 /
static_cast<double>(
d.m_durationFrameInTicks))
949 frame->
importFrame(currentFrameTime,
d.m_currentFrame,
nullptr);
950 d.m_nextFrameTime +=
static_cast<int>(frameDurationNorm);
952 if (
d.isCMYK &&
d.m_info.uses_original_profile) {
956 layerBounds.height());
959 planes[3] =
reinterpret_cast<quint8 *
>(
d.kPlane.data());
960 d.m_currentFrame->writePlanarBytes(planes,
964 layerBounds.height());
973 f->process(
d.m_currentFrame, layerBounds, kfc->cloneWithResourcesSnapshot());
976 layer->paintDevice()->makeCloneFrom(
d.m_currentFrame, layerBounds);
979 additionalLayers.back()->paintDevice()->makeCloneFrom(
d.m_currentFrame, layerBounds);
982 }
else if (status == JXL_DEC_SUCCESS || status == JXL_DEC_BOX) {
983 if (std::strlen(boxType.data()) != 0) {
985 const auto availOut = JxlDecoderReleaseBoxBuffer(dec.get());
986 const int finalSize = box.size() -
static_cast<int>(availOut);
989 QByteArray type = boxType.toLower();
990 if ((std::equal(
exifTag.begin(),
exifTag.end(), type.constBegin())
991 || std::equal(
xmpTag.begin(),
xmpTag.end(), type.constBegin()))
993 metadataBoxes.emplace(type, QByteArray(box.data(), finalSize));
999 if (status == JXL_DEC_SUCCESS) {
1004 for (
auto &metaBox : metadataBoxes) {
1005 const QByteArray &type = metaBox.first;
1006 QByteArray &
value = metaBox.second;
1007 QBuffer buf(&
value);
1008 if (std::equal(
exifTag.begin(),
exifTag.end(), type.constBegin())) {
1009 dbgFile <<
"Loading EXIF data. Size: " <<
value.size();
1011 const auto *backend =
1015 backend->
loadFrom(layer->metaData(), &buf);
1016 }
else if (std::equal(
xmpTag.begin(),
xmpTag.end(), type.constBegin())) {
1017 dbgFile <<
"Loading XMP or IPTC data. Size: " <<
value.size();
1019 const auto *xmpBackend =
1023 if (!xmpBackend->loadFrom(layer->metaData(), &buf)) {
1027 iptcBackend->
loadFrom(layer->metaData(), &buf);
1034 image->addNode(layer, image->rootLayer().data());
1036 for (
const KisLayerSP &addLayer : additionalLayers) {
1037 image->addNode(addLayer, image->rootLayer().data());
1039 if (needColorTransform) {
1040 if (needIntermediateTransform) {
1041 dbgFile <<
"Transforming to intermediate color space";
1042 image->convertImageColorSpace(
d.cs_intermediate,
1045 image->waitForDone();
1047 dbgFile <<
"Transforming to target color space";
1048 image->convertImageColorSpace(
d.cs_target,
1051 image->waitForDone();
1053 document->setCurrentImage(image);
1056 if (JxlDecoderGetBoxType(dec.get(), boxType.data(), JXL_TRUE) != JXL_DEC_SUCCESS) {
1057 errFile <<
"JxlDecoderGetBoxType failed";
1060 const QByteArray type = boxType.toLower();
1061 if (std::equal(
exifTag.begin(),
exifTag.end(), type.constBegin())
1062 || std::equal(
xmpTag.begin(),
xmpTag.end(), type.constBegin())) {
1063 if (JxlDecoderSetBoxBuffer(
1065 reinterpret_cast<uint8_t *
>(box.data()),
1066 static_cast<size_t>(box.size()))
1067 != JXL_DEC_SUCCESS) {
1068 errFile <<
"JxlDecoderSetBoxBuffer failed";
1072 dbgFile <<
"Skipping box" << boxType.data();
1075 }
else if (status == JXL_DEC_BOX_NEED_MORE_OUTPUT) {
1077 boxSize = box.size();
1078 box.resize(boxSize * 2);
1080 JxlDecoderReleaseBoxBuffer(dec.get());
1081 if (JxlDecoderSetBoxBuffer(
1083 reinterpret_cast<uint8_t *
>(box.data() + boxSize),
1084 static_cast<size_t>(box.size() - boxSize))
1085 != JXL_DEC_SUCCESS) {
1086 errFile <<
"JxlDecoderGetBoxType failed";
1090 errFile <<
"Unknown decoder status" << status;