{"record":{"id":"75e9d35d7824c322","repo":"Yalantis/uCrop","slug":"save-pfm-image-instance-is-multispectral-only","errorCode":null,"errorMessage":"save_pfm(): image instance is multispectral, only the three first channels will be saved in file '%s'.","messagePattern":"save_pfm\\(\\): image 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":62491,"sourceCode":"    //! Save image as a PFM file \\overloading.\n    const CImg<T>& save_pfm(std::FILE *const file) const {\n      get_mirror('y')._save_pfm(file,0);\n      return *this;\n    }\n\n    const CImg<T>& _save_pfm(std::FILE *const file, const char *const filename) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_pfm(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(file,filename); return *this; }\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_pfm(): 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_pfm(): image instance is multispectral, only the three first channels will be saved \"\n                   \"in file '%s'.\",\n                   cimg_instance,\n                   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 unsigned int buf_size = std::min(1024*1024U,_width*_height*(_spectrum==1?1:3));\n\n      std::fprintf(nfile,\"P%c\\n%u %u\\n1.0\\n\",\n                   (_spectrum==1?'f':'F'),_width,_height);\n\n      switch (_spectrum) {\n      case 1 : { // Scalar image\n        CImg<floatT> buf(buf_size);","sourceCodeStart":62473,"sourceCodeEnd":62509,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L62473-L62509","documentation":"save_pfm() stores single-channel (gray) or RGB float data; CImg warns when _spectrum>3 because extra spectral channels beyond the first three cannot be represented in PFM and are silently dropped. Emitted via cimg::warn(), non-fatal.","triggerScenarios":"Calling save_pfm() on an image with more than 3 channels (_spectrum>3), e.g. RGBA images, hyperspectral data, or 4+ channel feature maps.","commonSituations":"Saving RGBA data where only RGB is expected (forgetting to drop the alpha channel); hyperspectral or multi-band scientific data written to a 3-channel-capable format.","solutions":["Keep only the channels that fit: img.get_channels(0,2) before saving","Split channels and save each separately with get_channel(c)","Use a format that supports arbitrary channel counts (TIFF via save_tiff, or save_cimg for raw dumps)","If the alpha channel is unwanted, drop it explicitly: img.get_channels(0,2)"],"exampleFix":"// before\nrgbaImage.save_pfm(\"out.pfm\");      // alpha dropped silently\n// after\nrgbaImage.get_channels(0, 2).save_pfm(\"out.pfm\");","handlingStrategy":"validation","validationCode":"if (img.spectrum() > 3) img = img.get_channels(0, 2);\nimg.save_pfm(\"out.pfm\");","typeGuard":"bool has_at_most_3_channels(const cimg_library::CImg<T>& img) { return img.spectrum() <= 3; }","tryCatchPattern":"try { img.save_pfm(\"out.pfm\"); } catch (CImgException& e) { /* handle */ }","preventionTips":["Drop or split extra channels before saving to 3-channel formats","Check spectrum() against format capacity","Use TIFF for >3 channel data"],"tags":["cimg","pfm","multispectral","channel-truncation"],"backgroundTag":"unsupported-operation","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}