{"record":{"id":"4269231ac337f32d","repo":"Yalantis/uCrop","slug":"load-jxl-failed-to-decode-image-data-s","errorCode":null,"errorMessage":"load_jxl(): Failed to decode image data '%s'.","messagePattern":"load_jxl\\(\\): Failed to decode image data '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57207,"sourceCode":"                                  nfilename);\n          }\n          if (jxlInfo.have_animation!=0) {\n            JxlDecoderDestroy(decoder);\n            throw CImgIOException(_cimg_instance\n                                  \"load_jxl(): Does not support animated JPEG XL '%s'.\",\n                                  cimg_instance,\n                                  nfilename);\n          }\n          hasAlpha = jxlInfo.alpha_bits!=0;\n          nChannels = hasAlpha?jxlInfo.num_color_channels + 1:jxlInfo.num_color_channels;\n          isGray = jxlInfo.num_color_channels==1;\n        } else if (status==JXL_DEC_NEED_IMAGE_OUT_BUFFER) {\n          std::size_t imgDataSize = 0;\n          format.num_channels = nChannels;\n          format.data_type = jxlInfo.bits_per_sample==16?JXL_TYPE_UINT16:JXL_TYPE_UINT8;\n          if (JXL_DEC_SUCCESS!=JxlDecoderImageOutBufferSize(decoder,&format,&imgDataSize)) {\n            JxlDecoderDestroy(decoder);\n            throw CImgIOException(_cimg_instance\n                                  \"load_jxl(): Failed to decode image data '%s'.\",\n                                  cimg_instance,\n                                  nfilename);\n          }\n          imgData.assign(imgDataSize);\n          if (JXL_DEC_SUCCESS!=JxlDecoderSetImageOutBuffer(decoder,&format,(void*)imgData.data(),imgDataSize)) {\n            JxlDecoderDestroy(decoder);\n            throw CImgIOException(_cimg_instance\n                                  \"load_jxl(): Failed to set decode buffer '%s'.\",\n                                  cimg_instance,\n                                  nfilename);\n          }\n        }\n      }\n\n      assign(jxlInfo.xsize,jxlInfo.ysize,1,nChannels);\n      T\n        *ptr_r = data(0,0,0,0),","sourceCodeStart":57189,"sourceCodeEnd":57225,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57189-L57225","documentation":"On JXL_DEC_NEED_IMAGE_OUT_BUFFER, load_jxl() asks libjxl for the required output size via JxlDecoderImageOutBufferSize. A non-success return makes allocating the output impossible, so the decoder is destroyed and this error is thrown. Usually reflects an unsupported pixel format choice or decoder state problem.","triggerScenarios":"JxlDecoderImageOutBufferSize(decoder, &format, &imgDataSize) returns != JXL_DEC_SUCCESS where format.num_channels was set from image basic info and data_type is UINT8/UINT16 by bits_per_sample.","commonSituations":"Images with unusual sample layouts (e.g. >4 channels, CMYK, float samples, 32-bit depth) that clash with the hardcoded UINT8/UINT16 format choices in CImg.","solutions":["Check the image's bits_per_sample/num_color_channels; re-encode to standard 8/16-bit RGB(A) JXL.","Update CImg/libjxl; newer libjxl accepts more format combinations.","Decode with libjxl directly choosing a supported JxlPixelFormat, then wrap the buffer in a CImg."],"exampleFix":"// before\n// 16-bit float CMYK jxl -> ImageOutBufferSize fails\n// after\n// re-encode: cjxl input.png -- BitsPerSample=8 out.jxl\nimg.load_jxl(\"out.jxl\");","handlingStrategy":"validation","validationCode":"bool jxlFormatSupported(unsigned bits_per_sample, unsigned num_color_channels, unsigned alpha_bits) {\n  unsigned n = num_color_channels + (alpha_bits ? 1 : 0);\n  return (bits_per_sample == 8 || bits_per_sample == 16) && n >= 1 && n <= 4;\n}","typeGuard":null,"tryCatchPattern":"try { img.load_jxl(path); } catch (CImgIOException& e) { log(\"unsupported jxl pixel format\"); reencodeToStdJxl(path); }","preventionTips":["Normalize assets to 8/16-bit RGB(A) JXL before ingestion","Reject CMYK/float/exotic-channel images at import","Keep CImg and libjxl updated for broader format support"],"tags":["jxl","pixel-format","decode-failed","cimg"],"backgroundTag":"unsupported-dtype","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}