{"record":{"id":"e8ef6eff00d3d276","repo":"Yalantis/uCrop","slug":"save-jxl-failed-to-set-basic-info-when-saving-f","errorCode":null,"errorMessage":"save_jxl(): Failed to set basic info when saving file '%s'.","messagePattern":"save_jxl\\(\\): Failed to set basic info when saving file '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":61865,"sourceCode":"        0,\n      };\n      JxlBasicInfo basicInfo;\n      JxlEncoderInitBasicInfo(&basicInfo);\n      basicInfo.bits_per_sample = bytesPerPixel*8;\n      basicInfo.exponent_bits_per_sample = 0;\n      basicInfo.xsize = _width;\n      basicInfo.ysize = _height;\n      basicInfo.uses_original_profile = JXL_FALSE;\n      if (hasAlpha) {\n        basicInfo.alpha_bits = bytesPerPixel*8;\n        basicInfo.alpha_exponent_bits = 0;\n        basicInfo.num_extra_channels = 1;\n      }\n      basicInfo.num_color_channels = nChannels;\n      if (JXL_ENC_SUCCESS!=JxlEncoderSetBasicInfo(encoder,&basicInfo)) {\n        cimg::fclose(file);\n        JxlEncoderDestroy(encoder);\n        throw CImgIOException(_cimg_instance\n                              \"save_jxl(): Failed to set basic info when saving file '%s'.\",\n                              cimg_instance,\n                              filename);\n      }\n\n      JxlColorEncoding colorEncoding = {};\n      JXL_BOOL isGray = pixelFormat.num_channels<3?JXL_TRUE:JXL_FALSE;\n      JxlColorEncodingSetToSRGB(&colorEncoding, isGray);\n      if (JXL_ENC_SUCCESS!=JxlEncoderSetColorEncoding(encoder,&colorEncoding)) {\n        cimg::fclose(file);\n        JxlEncoderDestroy(encoder);\n        throw CImgIOException(_cimg_instance\n                              \"save_jxl(): Failed to set color encoding when saving file '%s'.\",\n                              cimg_instance,\n                              filename);\n      }\n\n      JxlEncoderFrameSettings* frameSettings = JxlEncoderFrameSettingsCreate(encoder,NULL);","sourceCodeStart":61847,"sourceCodeEnd":61883,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61847-L61883","documentation":"CImg calls JxlEncoderSetBasicInfo to describe dimensions, bit depth, and channel layout to libjxl. When that call does not return JXL_ENC_SUCCESS, save_jxl() closes the file, destroys the encoder, and throws CImgIOException — the image data itself was fine, but the encoder rejected the basic info (inconsistent dimensions/BitDepth/extra-channel setup).","triggerScenarios":"Calling save_jxl() where the assembled JxlBasicInfo conflicts with the pixel format — e.g. mismatched exponent/sample bits for the chosen bytes_per_pixel, invalid dimensions (0 or too large), or inconsistent num_color_channels / num_extra_channels for the spectrum.","commonSituations":"Custom or mismatched libjxl versions where struct fields (e.g. alpha_bits, num_extra_channels) are set inconsistently; images with degenerate dimensions; ABI drift between CImg.h and an older/newer libjxl.","solutions":["Check image width/height are > 0 before saving; JXL rejects zero or absurd dimensions.","Update/align the libjxl version with the CImg.h expectations (rebuild with a current libjxl).","Reduce unusual configurations: standard 8/16-bit gray or RGBA images encode reliably; verify alpha settings match _spectrum==4."],"exampleFix":"// before\nif (img.width() == 0 || img.height() == 0) {} // unchecked\nimg.save_jxl(\"out.jxl\");\n// after\nif (img.width() == 0 || img.height() == 0) throw std::invalid_argument(\"empty image\");\nimg.save_jxl(\"out.jxl\");","handlingStrategy":"validation","validationCode":"if (img.width() == 0 || img.height() == 0) {\n  throw std::invalid_argument(\"image dimensions must be positive for jxl\");\n}\nimg.save_jxl(\"out.jxl\");","typeGuard":null,"tryCatchPattern":"try {\n  img.save_jxl(\"out.jxl\");\n} catch (const cimg_library::CImgIOException &e) {\n  std::fprintf(stderr, \"jxl encoder setup failed: %s\\n\", e.what());\n}","preventionTips":["Keep libjxl version aligned with the bundled CImg.h.","Use standard gray/RGB(A) channel layouts.","Check dimensions before encoder-based saves."],"tags":["cimg","jxl","libjxl","encoder-failure"],"backgroundTag":"api-request-failed","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"}