{"record":{"id":"380efe0f5628ecd7","repo":"Yalantis/uCrop","slug":"draw-mandelbrot-instance-and-specified-colormap","errorCode":null,"errorMessage":"draw_mandelbrot(): Instance and specified colormap (%u,%u,%u,%u,%p) have incompatible dimensions.","messagePattern":"draw_mandelbrot\\(\\): Instance and specified colormap \\(%u,%u,%u,%u,%p\\) have incompatible dimensions\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":53807,"sourceCode":"       \\param is_normalized_iteration Tells if iterations are normalized.\n       \\param is_julia_set Tells if the Mandelbrot or Julia set is rendered.\n       \\param param_r Real part of the Julia set parameter.\n       \\param param_i Imaginary part of the Julia set parameter.\n       \\note Fractal rendering is done by the Escape Time Algorithm.\n    **/\n    template<typename tc>\n    CImg<T>& draw_mandelbrot(const int x0, const int y0, const int x1, const int y1,\n                             const CImg<tc>& colormap, const float opacity=1,\n                             const double z0r=-2, const double z0i=-2, const double z1r=2, const double z1i=2,\n                             const unsigned int iteration_max=255,\n                             const bool is_normalized_iteration=false,\n                             const bool is_julia_set=false,\n                             const double param_r=0, const double param_i=0) {\n      if (is_empty()) return *this;\n      CImg<tc> palette;\n      if (colormap) palette.assign(colormap._data,colormap.size()/colormap._spectrum,1,1,colormap._spectrum,true);\n      if (palette && palette._spectrum!=_spectrum)\n        throw CImgArgumentException(_cimg_instance\n                                    \"draw_mandelbrot(): Instance and specified colormap (%u,%u,%u,%u,%p) have \"\n                                    \"incompatible dimensions.\",\n                                    cimg_instance,\n                                    colormap._width,colormap._height,colormap._depth,colormap._spectrum,colormap._data);\n\n      const float nopacity = cimg::abs(opacity), copacity = 1 - std::max(opacity,0.f), ln2 = (float)std::log(2.);\n      const int\n        _x0 = cimg::cut(x0,0,width() - 1),\n        _y0 = cimg::cut(y0,0,height() - 1),\n        _x1 = cimg::cut(x1,0,width() - 1),\n        _y1 = cimg::cut(y1,0,height() - 1);\n\n      cimg_pragma_openmp(parallel for cimg_openmp_collapse(2)\n                         cimg_openmp_if((1 + _x1 - _x0)*(1 + _y1 - _y0)>=(cimg_openmp_sizefactor)*2048))\n      for (int q = _y0; q<=_y1; ++q)\n        for (int p = _x0; p<=_x1; ++p) {\n          unsigned int iteration = 0;\n          const double x = z0r + p*(z1r-z0r)/_width, y = z0i + q*(z1i-z0i)/_height;","sourceCodeStart":53789,"sourceCodeEnd":53825,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L53789-L53825","documentation":"draw_mandelbrot() optionally accepts a colormap image; if supplied and non-empty, its spectrum (number of channels) must match the instance image's spectrum, otherwise CImgArgumentException is thrown listing the colormap's dimensions. Internally the colormap is reshaped into a palette of the same channel count as the target image, which is impossible when channel counts differ (e.g. RGB palette on a grayscale image).","triggerScenarios":"Calling img.draw_mandelbrot(...,colormap,...) where colormap._spectrum != img._spectrum — e.g. an RGB (3-channel) palette passed to a single-channel image, or a scalar palette passed to an RGB image; also passing an uninitialized-but-nonzero palette image.","commonSituations":"Reusing a palette from a color image for a grayscale render or vice versa; loading a palette JPEG/PNG with alpha (4 channels) for a 3-channel target; refactoring that changed the working image from color to gray without updating the palette.","solutions":["Match channel counts: convert the palette with colormap.channels(0,2) or the image to color (img.resize(...,3)) so spectra agree.","Construct the palette with the same spectrum as the target: CImg<unsigned char> palette(N,1,1,img.spectrum()).","Check colormap.spectrum()==img.spectrum() (when colormap is non-empty) before calling.","If you don't need a custom palette, omit the colormap argument entirely and use the built-in default."],"exampleFix":"// before\nCImg<unsigned char> palette = loadRGBPalette(); // spectrum 3\ngrayImg.draw_mandelbrot(zoomx,zoomy,...,palette,...);\n// after\nCImg<unsigned char> palette = loadRGBPalette().channels(0,0); // -> spectrum 1\ngrayImg.draw_mandelbrot(zoomx,zoomy,...,palette,...);","handlingStrategy":"validation","validationCode":"if (colormap && !colormap.is_empty() && colormap.spectrum()!=img.spectrum())\n    colormap = colormap.get_resize(colormap.width(),1,1,img.spectrum());\nimg.draw_mandelbrot(zoomx,zoomy,niter,jx,jy,true,0,0,false,0,0,colormap);","typeGuard":"bool paletteMatches(const CImg<unsigned char>& img, const CImg<unsigned char>& cmap){\n  return cmap.is_empty() || cmap.spectrum()==img.spectrum();\n}","tryCatchPattern":"try { img.draw_mandelbrot(zx,zy,it,...,colormap,...); }\ncatch (CImgArgumentException& e) { log_error(\"draw_mandelbrot palette mismatch: %s\", e.what()); }","preventionTips":["Build palettes with the same channel count as the target image.","Convert palettes (channels()) or images when switching between gray and color rendering.","Strip alpha channels from loaded palette images (channels(0,2)).","Skip the colormap argument when defaults suffice."],"tags":["cimg","image-processing","shape-mismatch","colormap"],"backgroundTag":"tensor-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"}