{"record":{"id":"20198e59c78950db","repo":"Yalantis/uCrop","slug":"save-jxl-instance-has-pixel-values-in-g-g","errorCode":null,"errorMessage":"save_jxl(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.","messagePattern":"save_jxl\\(\\): Instance has pixel values in \\[%g,%g\\], probable type overflow in file '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":61775,"sourceCode":"    **/\n    const CImg<T>& save_jxl(const char *const filename, const float distance=1.0f,\n                            const unsigned int bytes_per_pixel=0) const {\n      return _save_jxl(filename,distance,bytes_per_pixel);\n    }\n\n    const CImg<T>& _save_jxl(const char *const filename, const float distance=1.0f,\n                             const unsigned int bytes_per_pixel=0) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_jxl(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (_spectrum > 4)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_jxl(): JPEG XL only supports at most 4 channels.\",\n                                    cimg_instance);\n      double stmin, stmax = (double)max_min(stmin);\n      if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)\n        cimg::warn(_cimg_instance\n                   \"save_jxl(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.\",\n                   cimg_instance,\n                   stmin,stmax,filename);\n      if (bytes_per_pixel>2 || sizeof(T)<bytes_per_pixel)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_jxl(): bytes_per_pixel must be in [0, 2] and less than or equal to sizeof(T)\",\n                                    cimg_instance);\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_jxl(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename);\n#ifndef cimg_use_jxl\n      cimg::unused(distance);\n      return save_other(filename);\n#else\n      std::FILE *file = cimg::fopen(filename, \"wb\");\n      cimg_uint32 nChannels = _spectrum;","sourceCodeStart":61757,"sourceCodeEnd":61793,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61757-L61793","documentation":"This is a warning (via cimg::warn, not an exception) emitted by CImg<T>::save_jxl() when the image's pixel range does not fit the target JPEG XL bit depth. If any pixel is negative, or the range exceeds 255 for 8-bit or 65535 for 16-bit output, values will be clipped/wrap around during conversion to bytes_per_pixel-wide integers. The save continues; only data fidelity is at risk.","triggerScenarios":"Calling save_jxl() with bytes_per_pixel==1 while pixel max >= 256, or bytes_per_pixel==2 while pixel max >= 65536, or with any negative pixel value (stmin<0), as computed by max_min() just before the check.","commonSituations":"Saving float or int32 images whose values exceed 0-255 (e.g. HDR data, raw sensor values, scientific imagery) to 8-bit JXL; images containing negative values from filters, derivatives, or signed processing pipelines.","solutions":["Clamp/normalize pixel values to [0,255] (or [0,65535] for bytes_per_pixel==2) before saving, e.g. img = img.get_cut(0,255) or img.normalize(0,255)","Increase bytes_per_pixel to 2 if values fit in 16 bits","Shift the data so stmin>=0 before saving","Ignore the warning if clipping is acceptable"],"exampleFix":"// before\nimg.save_jxl(\"out.jxl\"); // values in [-12, 900]\n// after\nCImg<T> out = img.get_cut(0,255); // or get_normalize(0,255)\nout.save_jxl(\"out.jxl\");","handlingStrategy":"validation","validationCode":"double mn, mx = img.max_min(mn);\nif (mn < 0 || mx >= 256) img.normalize(0,255); // then save_jxl","typeGuard":null,"tryCatchPattern":"// cimg::warn does not throw; check the saved range before writing:\ndouble mn, mx = img.max_min(mn);\nassert(mn >= 0 && mx < 256);","preventionTips":["Always normalize or cut values to the target bit depth before saving","Check img.min()/img.max() before encode","Prefer float-capable formats for non-byte data"],"tags":["image-encoding","value-range","jxl"],"backgroundTag":"value-out-of-range","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"}