{"record":{"id":"b15abd8af1e54323","repo":"Yalantis/uCrop","slug":"resize-invalid-specified-interpolation-d-shou","errorCode":null,"errorMessage":"resize(): Invalid specified interpolation %d (should be { -1=raw | 0=none | 1=nearest | 2=average | 3=linear | 4=grid | 5=cubic | 6=lanczos }).","messagePattern":"resize\\(\\): Invalid specified interpolation (.+?) \\(should be (.+?)\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":38761,"sourceCode":"                    val4 = ptrs<ptrsmax?(double)*(ptrs + 2*sxyz):val3,\n                    val = (val0*w0 + val1*w1 + val2*w2 + val3*w3 + val4*w4)/(w1 + w2 + w3 + w4);\n                  *ptrd = (T)(val<vmin?vmin:val>vmax?vmax:val);\n                  ptrd+=sxyz;\n                  ptrs+=*(poff++);\n                }\n              }\n            }\n          }\n          resz.assign();\n        } else resc.assign(resz,true);\n\n        return resc._is_shared?(resz._is_shared?(resy._is_shared?(resx._is_shared?(+(*this)):resx):resy):resz):resc;\n      } break;\n\n        // Unknown interpolation.\n        //\n      default :\n        throw CImgArgumentException(_cimg_instance\n                                    \"resize(): Invalid specified interpolation %d \"\n                                    \"(should be { -1=raw | 0=none | 1=nearest | 2=average | 3=linear | 4=grid | \"\n                                    \"5=cubic | 6=lanczos }).\",\n                                    cimg_instance,\n                                    interpolation_type);\n      }\n      return res;\n    }\n\n    //! Resize image to dimensions of another image.\n    /**\n       \\param src Reference image used for dimensions.\n       \\param interpolation_type Interpolation method.\n       \\param boundary_conditions Boundary conditions.\n         Can be { 0=dirichlet | 1=neumann | 2=periodic | 3=mirror }.\n       \\param centering_x Set centering type (only if \\p interpolation_type=0).\n       \\param centering_y Set centering type (only if \\p interpolation_type=0).\n       \\param centering_z Set centering type (only if \\p interpolation_type=0).","sourceCodeStart":38743,"sourceCodeEnd":38779,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L38743-L38779","documentation":"CImg's resize() accepts an interpolation_type parameter restricted to values -1 (raw), 0 (none), 1 (nearest), 2 (average), 3 (linear), 4 (grid), 5 (cubic), 6 (lanczos). When the switch in the resize implementation falls through to the default branch, it means the caller passed an integer outside this set, so CImg throws a CImgArgumentException naming the offending value. The library fails fast instead of silently substituting an interpolation method.","triggerScenarios":"Calling CImg<T>::resize() (or get_resize()) with interpolation_type not in {-1,0,1,2,3,4,5,6}, e.g. passing 7, a negative sentinel other than -1, or an uninitialized/garbage int. Also happens when a caller maps its own enum (whose values don't line up with CImg's) directly into the parameter.","commonSituations":"Wrapping CImg in higher-level code where an app-level quality enum (e.g. 0=low,1=medium,2=high) is forwarded verbatim as interpolation_type; a refactor or version change shifting CImg's enum values (e.g. code written for a different lib whose 'lanczos' is 5 vs CImg's 6); passing a bool/flag by mistake; uninitialized variable.","solutions":["Set interpolation_type to one of the documented values: -1, 0, 1, 2, 3, 4, 5, or 6 (e.g. 3 for linear, 6 for lanczos).","If your code uses its own enum, add an explicit mapping from your enum to CImg's constants before calling resize().","Check for uninitialized or corrupted interpolation_type values at the call site (log/print the value shown in the message).","If you intentionally want no interpolation, pass 0 (none) rather than an out-of-range sentinel."],"exampleFix":"// before\nimg.resize(w, h, -100, -100, -100, 2, 7); // 7 is invalid\n// after\nimg.resize(w, h, -100, -100, -100, 2, 6); // 6 = lanczos (valid range -1..6)","handlingStrategy":"validation","validationCode":"// C++\nbool isValidInterpolation(int t) {\n    return t >= -1 && t <= 6; // -1 raw,0 none,1 nearest,2 average,3 linear,4 grid,5 cubic,6 lanczos\n}\nif (!isValidInterpolation(interp)) throw std::invalid_argument(\"interpolation must be in [-1,6]\");\nimg.resize(w, h, -100, -100, -100, 2, interp);","typeGuard":"bool isValidInterpolation(int t) { return t >= -1 && t <= 6; }","tryCatchPattern":"try {\n    img.resize(w, h, -100, -100, -100, 2, interp);\n} catch (const cimg_library::CImgArgumentException& e) {\n    // log e.what(), fall back to a safe default\n    img.resize(w, h, -100, -100, -100, 2, 3); // linear\n}","preventionTips":["Use CImg's named constants / a wrapper enum restricted to -1..6 instead of raw ints","Validate any user- or config-supplied quality setting against the allowed set before mapping to interpolation_type","Never forward your own enum values directly to resize(); add an explicit mapping","Initialize the interpolation variable at declaration to avoid garbage values"],"tags":["cimg","invalid-argument","image-resize","interpolation"],"backgroundTag":"invalid-enum-value","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"}