{"record":{"id":"c40d2e2723790ed3","repo":"Yalantis/uCrop","slug":"save-pnm-instance-is-multispectral-only-the-th","errorCode":null,"errorMessage":"save_pnm(): Instance is multispectral, only the three first channels will be saved in file '%s'.","messagePattern":"save_pnm\\(\\): Instance is multispectral, only the three first channels will be saved in file '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":62287,"sourceCode":"      return _save_pnm(file,0,bytes_per_pixel);\n    }\n\n    const CImg<T>& _save_pnm(std::FILE *const file, const char *const filename,\n                             const unsigned int bytes_per_pixel=0) const {\n      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));","sourceCodeStart":62269,"sourceCodeEnd":62305,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62269-L62305","documentation":"Warning from CImg<T>::save_pnm() when the image has more than 3 channels (_spectrum>3). PNM supports at most 3 channels (RGB for PPM), so channels beyond the first three are dropped. The save proceeds normally.","triggerScenarios":"Calling save_pnm() on an image with _spectrum>3, e.g. RGBA images (alpha dropped) or multispectral data with 4+ bands.","commonSituations":"Saving RGBA imagery to PPM/PGM (alpha silently discarded), or scientific multi-band data to PNM-based toolchains.","solutions":["Reduce to RGB before saving: img.get_channels(0,2)","Handle alpha by compositing over a background or saving it as a separate image","Use a format preserving 4+ channels (PNG, TIFF, .cimg)","Ignore if dropping the extra channels is acceptable"],"exampleFix":"// before\nrgba.save_pnm(\"out.ppm\"); // alpha dropped\n// after\nrgba.get_channels(0,2).save_pnm(\"out.ppm\");","handlingStrategy":"validation","validationCode":"if (img.spectrum() > 3) img = img.get_channels(0,2); // then save_pnm","typeGuard":null,"tryCatchPattern":"// warning only; guard by spectrum check before calling save_pnm","preventionTips":["Check img.spectrum() before saving to PNM","PNM supports at most 3 channels; use PNG/TIFF for RGBA+"],"tags":["image-encoding","channels","pnm"],"backgroundTag":"unsupported-operation","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"}