{"record":{"id":"2f852b9e5a01ff67","repo":"Yalantis/uCrop","slug":"save-pnm-instance-has-pixel-values-in-g-g","errorCode":null,"errorMessage":"save_pnm(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.","messagePattern":"save_pnm\\(\\): 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":62292,"sourceCode":"      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_pnm(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n\n      double stmin, stmax = (double)max_min(stmin);\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_pnm(): Instance is volumetric, only the first slice will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n      if (_spectrum>3)\n        cimg::warn(_cimg_instance\n                   \"save_pnm(): Instance is multispectral, only the three first channels will be saved in file '%s'.\",\n                   cimg_instance,\n                   filename?filename:\"(FILE*)\");\n      if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)\n        cimg::warn(_cimg_instance\n                   \"save_pnm(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.\",\n                   cimg_instance,\n                   stmin,stmax,filename?filename:\"(FILE*)\");\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      const T\n        *ptr_r = data(0,0,0,0),\n        *ptr_g = (_spectrum>=2)?data(0,0,0,1):0,\n        *ptr_b = (_spectrum>=3)?data(0,0,0,2):0;\n      const ulongT buf_size = std::min((ulongT)(1024*1024),(ulongT)(_width*_height*(_spectrum==1?1UL:3UL)));\n\n      std::fprintf(nfile,\"P%c\\n%u %u\\n%u\\n\",\n                   (_spectrum==1?'5':'6'),_width,_height,stmax<256?255:(stmax<4096?4095:65535));\n\n      switch (_spectrum) {\n      case 1 : { // Scalar image\n        if (bytes_per_pixel==1 || (!bytes_per_pixel && stmax<256)) { // Binary PGM 8 bits\n          CImg<ucharT> buf((unsigned int)buf_size);","sourceCodeStart":62274,"sourceCodeEnd":62310,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62274-L62310","documentation":"CImg's save_pnm() emits this non-fatal warning when the image's pixel value range cannot be represented in the PNM output bit depth (8-bit when max<256, else 16-bit). PNM only supports unsigned integer samples, so negative values or values above the representable maximum will silently wrap/clamp on write. The library warns via cimg::warn() so the developer knows output pixels may be corrupted.","triggerScenarios":"Calling save_pnm()/save_pnm_pnm()/save_pnm_pgm()/save_pnm_ppm() on a CImg<T> whose minimum value stmin is negative, or whose maximum stmax is >=256 with 1-byte pixels, or >=65536 generally. Typical with float images (values 0..1 saved fine, but unnormalized floats or signed images overflow) or int16/int32 images with negative pixels.","commonSituations":"Saving a processed image that was computed in signed or float space (e.g. after subtracting images, convolution results, gradients) directly to PNM/PGM/PPM without normalizing to [0,255] or [0,65535]. Loading a 16-bit image and saving as 8-bit PNM. Debug pixel values outside [0,255] due to a bad normalization formula.","solutions":["Normalize the image before saving: img.normalize(0,255) (or cut(0,255)) so the range fits the PNM bit depth","If negative values are expected, cut them: img.cut(0,255) prior to save","Save in a format supporting arbitrary ranges (PNG, TIFF, PFM, EXR) instead of PNM","If the overflow is intentional/acceptable, raise the warning threshold or ignore cimg warnings via cimg::exception_mode"],"exampleFix":"// before\nimg.save_pnm(\"out.pnm\");            // warns: pixel range [0.3,12.7]\n// after\nimg.get_normalize(0,255).save_pnm(\"out.pnm\");","handlingStrategy":"validation","validationCode":"if (img.min() < 0 || img.max() >= (img.pixel_type_size()==1 ? 256 : 65536))\n  img.normalize(0, 255); // or choose a range-appropriate format\nimg.save_pnm(\"out.pnm\");","typeGuard":null,"tryCatchPattern":"try { img.save_pnm(\"out.pnm\"); } catch (CImgException& e) { /* handle save failure */ }","preventionTips":["Always normalize/cut pixel range to [0,255] or [0,65535] before PNM saves","Track pixel type through processing steps (float ops produce floats)","Prefer PNG/TIFF/PFM for non-byte or signed data"],"tags":["cimg","pnm","pixel-overflow","image-save"],"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"}