{"record":{"id":"7b867f016831400f","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-color","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: Colormap size (%lu values) and specified dimension of colormap entries (%u) do not match.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Colormap size \\(%lu values\\) and specified dimension of colormap entries \\(%u\\) do not match\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":22124,"sourceCode":"              arg4 = arg5 = 0;\n              if (s1<se1) {\n                s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;\n                arg4 = compile(s1,s2,depth1,0,block_flags);\n                arg5 = s2<se1?compile(++s2,se1,depth1,0,block_flags):0;\n              }\n              _cimg_mp_check_type(arg1,1,2,0);\n              _cimg_mp_check_type(arg2,2,2,0);\n              _cimg_mp_check_const_scalar(arg3,3,3);\n              _cimg_mp_check_type(arg4,4,1,0);\n              _cimg_mp_check_const_scalar(arg5,5,2);\n              p1 = size(arg1);\n              p2 = size(arg2);\n              arg3 = (unsigned int)mem[arg3];\n              arg5 = (unsigned int)mem[arg5];\n              p3 = p2/arg3; // Number of color entries\n              if (p2!=p3*arg3) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Colormap size (%lu values) and specified \"\n                                            \"dimension of colormap entries (%u) do not match.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,\n                                            std::max(p2,1U),arg3);\n              }\n              if (p1%arg3) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Input vector size (%lu values) and specified \"\n                                            \"dimension of colormap entries (%u) do not match.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,\n                                            std::max(p1,1U),arg3);\n              }\n              pos = vector(arg5?p1:p1/arg3);\n              CImg<ulongT>::vector((ulongT)mp_index,pos,arg1,p1,arg2,p2,arg3,arg4,arg5).move_to(code);\n              return_comp = true;\n              _cimg_mp_return(pos);\n            }","sourceCodeStart":22106,"sourceCodeEnd":22142,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L22106-L22142","documentation":"Math-parser palette/colormap application functions take a colormap vector and the per-entry dimension (number of values per color entry, e.g. 3 for RGB). The colormap size must be an exact multiple of that dimension; p2 (colormap size) must satisfy p2 == (p2/arg3)*arg3. Otherwise CImg throws this error reporting the actual size and requested dimension.","triggerScenarios":"Calling a colormap-based expression function (e.g. palette lookup / `apply_palette` style ops) with a colormap vector whose length is not divisible by the given nb_entries/dimension argument, e.g. a 10-value colormap with dimension 3.","commonSituations":"Hand-built colormaps with a trailing or missing channel value; mixing RGBA colormaps (dim 4) with RGB code expecting dim 3; passing image pixel buffers instead of packed colormap vectors.","solutions":["Make the colormap length an exact multiple of the entries dimension (pad or truncate values)","Pass the correct dimension argument (3 for RGB, 4 for RGBA) matching the colormap layout","Validate `colormap.size() % dim == 0` in code before invoking the expression","Build colormaps via CImg API helpers that enforce the layout instead of manual vectors"],"exampleFix":"// before\nimg.fill(\"apply([0,0,0, 255,255,255, 128,128], 3, ...)\"); // 9 not divisible by 3? actually 10 values\n// after\nimg.fill(\"apply([0,0,0, 255,255,255, 128,128,128], 3, ...)\"); // 9 values / dim 3","handlingStrategy":"validation","validationCode":"void checkColormap(double[] cmap, int dim) {\n  if (cmap.length % dim != 0)\n    throw new IllegalArgumentException(\"Colormap size \" + cmap.length + \" not a multiple of dim \" + dim);\n}","typeGuard":null,"tryCatchPattern":"try { img.fill(expr); } catch (CImgArgumentException e) { if (e.getMessage().contains(\"Colormap size\") && e.getMessage().contains(\"do not match\")) { /* fix cmap layout or dim and retry */ } throw e; }","preventionTips":["Build colormaps as flat arrays with a fixed entries dimension (3 for RGB, 4 for RGBA)","Assert colormap.length % dim == 0 before use","Do not hand-edit colormap arrays; generate them programmatically"],"tags":["cimg","math-parser","colormap","size-mismatch"],"backgroundTag":"shape-mismatch","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"}