Yalantis/uCrop · warning

save_magick(): Instance has pixel values in [%g,%g], probabl

Error message

save_magick(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.

What it means

Warning from CImg<T>::save_magick() when pixel values do not fit the chosen output depth: negative values present, max >= 256 with bytes_per_pixel==1, or max >= 65536 with 2-byte pixels. Values are clipped/wrapped when converted to Magick's 8/16-bit storage, so saved output may look washed out or saturated. The save still proceeds.

Source

Thrown at ucrop/src/main/jni/CImg.h:61997

      if (is_empty()) { cimg::fempty(0,filename); return *this; }

#ifdef cimg_use_magick
      double stmin, stmax = (double)max_min(stmin);
      if (_depth>1)
        cimg::warn(_cimg_instance
                   "save_magick(): Instance is volumetric, only the first slice will be saved in file '%s'.",
                   cimg_instance,
                   filename);

      if (_spectrum>3)
        cimg::warn(_cimg_instance
                   "save_magick(): Instance is multispectral, only the three first channels will be "
                   "saved in file '%s'.",
                   cimg_instance,
                   filename);

      if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)
        cimg::warn(_cimg_instance
                   "save_magick(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.",
                   cimg_instance,
                   stmin,stmax,filename);

      Magick::Image image(Magick::Geometry(_width,_height),"black");
      image.type(Magick::TrueColorType);
      image.depth(bytes_per_pixel?(8*bytes_per_pixel):(stmax>=256?16:8));
      const T
        *ptr_r = data(0,0,0,0),
        *ptr_g = _spectrum>1?data(0,0,0,1):0,
        *ptr_b = _spectrum>2?data(0,0,0,2):0;
      Magick::PixelPacket *pixels = image.getPixels(0,0,_width,_height);
      switch (_spectrum) {
      case 1 : // Scalar images
        for (ulongT off = (ulongT)_width*_height; off; --off) {
          pixels->red = pixels->green = pixels->blue = (Magick::Quantum)*(ptr_r++);
          ++pixels;
        }

View on GitHub (pinned to f788b534b4)

Solutions

  1. Normalize before saving: img.normalize(0,255) (or 0,65535 for 16-bit)
  2. Clamp with img.cut(0,255) to preserve scale and drop outliers
  3. Rescale negatives to non-negative (e.g. add offset or use get_abs) if negative data is meaningful
  4. Save as float-capable format (TIFF, .cimg, PFM) instead

Example fix

// before
img.save_magick("out.png"); // float [-1,1]
// after
img.get_normalize(0,255).save_magick("out.png");
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_magick

Try / catch

// cimg::warn does not throw; check the value range before writing

Prevention

When it happens

Trigger: Calling save_magick() with images whose min/max range (from max_min()) exceeds the target integer range, e.g. float images in [0,1] beyond 255? no — specifically stmin<0, or stmax>=256 for 8-bit, or stmax>=65536 for 16-bit output.

Common situations: Saving normalized float [0,1] data forgotten to be scaled to 0-255 (all-near-zero image), or int/float images with negative values from filters, or >16-bit scientific data.

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


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/5d17fae87ba8cd55. Report an issue: GitHub.