{"record":{"id":"5d17fae87ba8cd55","repo":"Yalantis/uCrop","slug":"save-magick-instance-has-pixel-values-in-g-g","errorCode":null,"errorMessage":"save_magick(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.","messagePattern":"save_magick\\(\\): 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":61997,"sourceCode":"      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n\n#ifdef cimg_use_magick\n      double stmin, stmax = (double)max_min(stmin);\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_magick(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename);\n\n      if (_spectrum>3)\n        cimg::warn(_cimg_instance\n                   \"save_magick(): Instance is multispectral, only the three first channels will be \"\n                   \"saved in file '%s'.\",\n                   cimg_instance,\n                   filename);\n\n      if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)\n        cimg::warn(_cimg_instance\n                   \"save_magick(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.\",\n                   cimg_instance,\n                   stmin,stmax,filename);\n\n      Magick::Image image(Magick::Geometry(_width,_height),\"black\");\n      image.type(Magick::TrueColorType);\n      image.depth(bytes_per_pixel?(8*bytes_per_pixel):(stmax>=256?16:8));\n      const T\n        *ptr_r = data(0,0,0,0),\n        *ptr_g = _spectrum>1?data(0,0,0,1):0,\n        *ptr_b = _spectrum>2?data(0,0,0,2):0;\n      Magick::PixelPacket *pixels = image.getPixels(0,0,_width,_height);\n      switch (_spectrum) {\n      case 1 : // Scalar images\n        for (ulongT off = (ulongT)_width*_height; off; --off) {\n          pixels->red = pixels->green = pixels->blue = (Magick::Quantum)*(ptr_r++);\n          ++pixels;\n        }","sourceCodeStart":61979,"sourceCodeEnd":62015,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61979-L62015","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Normalize before saving: img.normalize(0,255) (or 0,65535 for 16-bit)","Clamp with img.cut(0,255) to preserve scale and drop outliers","Rescale negatives to non-negative (e.g. add offset or use get_abs) if negative data is meaningful","Save as float-capable format (TIFF, .cimg, PFM) instead"],"exampleFix":"// before\nimg.save_magick(\"out.png\"); // float [-1,1]\n// after\nimg.get_normalize(0,255).save_magick(\"out.png\");","handlingStrategy":"validation","validationCode":"double mn, mx = img.max_min(mn);\nif (mn < 0 || mx >= 256) img.normalize(0,255); // then save_magick","typeGuard":null,"tryCatchPattern":"// cimg::warn does not throw; check the value range before writing","preventionTips":["Normalize to 0-255/0-65535 before saving","Check img.min()/img.max() before encode","Use PFM/TIFF for float data"],"tags":["image-encoding","value-range","imagemagick"],"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"}