Yalantis/uCrop · error · CImgArgumentException
[cimg_appname_math_parser] CImg<%s>::%s: %s: Colormap size (
Error message
[cimg_appname_math_parser] CImg<%s>::%s: %s: Colormap size (%lu values) and specified dimension of colormap entries (%u) do not match.
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:22124
arg4 = arg5 = 0;
if (s1<se1) {
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg4 = compile(s1,s2,depth1,0,block_flags);
arg5 = s2<se1?compile(++s2,se1,depth1,0,block_flags):0;
}
_cimg_mp_check_type(arg1,1,2,0);
_cimg_mp_check_type(arg2,2,2,0);
_cimg_mp_check_const_scalar(arg3,3,3);
_cimg_mp_check_type(arg4,4,1,0);
_cimg_mp_check_const_scalar(arg5,5,2);
p1 = size(arg1);
p2 = size(arg2);
arg3 = (unsigned int)mem[arg3];
arg5 = (unsigned int)mem[arg5];
p3 = p2/arg3; // Number of color entries
if (p2!=p3*arg3) {
_cimg_mp_strerr;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Colormap size (%lu values) and specified "
"dimension of colormap entries (%u) do not match.",
pixel_type(),_cimg_mp_calling_function,s_op,
std::max(p2,1U),arg3);
}
if (p1%arg3) {
_cimg_mp_strerr;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Input vector size (%lu values) and specified "
"dimension of colormap entries (%u) do not match.",
pixel_type(),_cimg_mp_calling_function,s_op,
std::max(p1,1U),arg3);
}
pos = vector(arg5?p1:p1/arg3);
CImg<ulongT>::vector((ulongT)mp_index,pos,arg1,p1,arg2,p2,arg3,arg4,arg5).move_to(code);
return_comp = true;
_cimg_mp_return(pos);
}View on GitHub (pinned to f788b534b4)
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
Example fix
// before
img.fill("apply([0,0,0, 255,255,255, 128,128], 3, ...)"); // 9 not divisible by 3? actually 10 values
// after
img.fill("apply([0,0,0, 255,255,255, 128,128,128], 3, ...)"); // 9 values / dim 3 Defensive patterns
Strategy: validation
Validate before calling
void checkColormap(double[] cmap, int dim) {
if (cmap.length % dim != 0)
throw new IllegalArgumentException("Colormap size " + cmap.length + " not a multiple of dim " + dim);
} Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Input vector si
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Specified input
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Specified kerne
- [" cimg_appname "_math_parser] CImg<%s>: Function '%s()': El
- "[" cimg_appname "_math_parser] CImg<%s>: Function '%s()': E
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/7b867f016831400f.
Report an issue: GitHub.