Yalantis/uCrop · warning
save_jxl(): Instance has pixel values in [%g,%g], probable t
Error message
save_jxl(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:61775
**/
const CImg<T>& save_jxl(const char *const filename, const float distance=1.0f,
const unsigned int bytes_per_pixel=0) const {
return _save_jxl(filename,distance,bytes_per_pixel);
}
const CImg<T>& _save_jxl(const char *const filename, const float distance=1.0f,
const unsigned int bytes_per_pixel=0) const {
if (!filename)
throw CImgArgumentException(_cimg_instance
"save_jxl(): Specified filename is (null).",
cimg_instance);
if (_spectrum > 4)
throw CImgArgumentException(_cimg_instance
"save_jxl(): JPEG XL only supports at most 4 channels.",
cimg_instance);
double stmin, stmax = (double)max_min(stmin);
if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)
cimg::warn(_cimg_instance
"save_jxl(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.",
cimg_instance,
stmin,stmax,filename);
if (bytes_per_pixel>2 || sizeof(T)<bytes_per_pixel)
throw CImgArgumentException(_cimg_instance
"save_jxl(): bytes_per_pixel must be in [0, 2] and less than or equal to sizeof(T)",
cimg_instance);
if (_depth>1)
cimg::warn(_cimg_instance
"save_jxl(): Instance is volumetric, only the first slice will be saved in file '%s'.",
cimg_instance,
filename);
#ifndef cimg_use_jxl
cimg::unused(distance);
return save_other(filename);
#else
std::FILE *file = cimg::fopen(filename, "wb");
cimg_uint32 nChannels = _spectrum;View on GitHub (pinned to f788b534b4)
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
Example fix
// before
img.save_jxl("out.jxl"); // values in [-12, 900]
// after
CImg<T> out = img.get_cut(0,255); // or get_normalize(0,255)
out.save_jxl("out.jxl"); Defensive patterns
Strategy: validation
Validate before calling
double mn, mx = img.max_min(mn); if (mn < 0 || mx >= 256) img.normalize(0,255); // then save_jxl
Try / catch
// cimg::warn does not throw; check the saved range before writing: double mn, mx = img.max_min(mn); assert(mn >= 0 && mx < 256);
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- save_jxl(): Instance is volumetric, only the first slice wil
- save_magick(): Instance has pixel values in [%g,%g], probabl
- save_png(): Instance has pixel values in [%g,%g], probable t
- load_jxl(): Failed to get file size '%s'.
- load_jxl(): Failed to configure decoder '%s'.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/20198e59c78950db.
Report an issue: GitHub.