{"record":{"id":"1d5ba0b35251e7ce","repo":"Yalantis/uCrop","slug":"xyytoxyz-instance-is-not-a-xyy-image","errorCode":null,"errorMessage":"xyYtoXYZ(): Instance is not a xyY image.","messagePattern":"xyYtoXYZ\\(\\): Instance is not a xyY image\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":37695,"sourceCode":"          Z = (Tfloat)p3[N],\n          sum = X + Y + Z,\n          nsum = sum>0?sum:1;\n        p1[N] = (T)(X/nsum);\n        p2[N] = (T)(Y/nsum);\n        p3[N] = (T)Y;\n      }\n      return *this;\n    }\n\n    //! Convert pixel values from XYZ to xyY color spaces \\newinstance.\n    CImg<Tfloat> get_XYZtoxyY() const {\n      return CImg<Tfloat>(*this,false).XYZtoxyY();\n    }\n\n    //! Convert pixel values from xyY pixels to XYZ color spaces.\n    CImg<T>& xyYtoXYZ() {\n      if (_spectrum!=3)\n        throw CImgInstanceException(_cimg_instance\n                                    \"xyYtoXYZ(): Instance is not a xyY image.\",\n                                    cimg_instance);\n\n      T *p1 = data(0,0,0,0), *p2 = data(0,0,0,1), *p3 = data(0,0,0,2);\n      const longT whd = (longT)width()*height()*depth();\n      cimg_pragma_openmp(parallel for cimg_openmp_if_size(whd,4096))\n      for (longT N = 0; N<whd; ++N) {\n        const Tfloat\n         px = (Tfloat)p1[N],\n         py = (Tfloat)p2[N],\n         Y = (Tfloat)p3[N],\n         ny = py>0?py:1;\n        p1[N] = (T)(px*Y/ny);\n        p2[N] = (T)Y;\n        p3[N] = (T)((1 - px - py)*Y/ny);\n      }\n      return *this;\n    }","sourceCodeStart":37677,"sourceCodeEnd":37713,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L37677-L37713","documentation":"xyYtoXYZ() converts xyY chromaticity values back to CIE XYZ and requires exactly 3 channels (x, y, Y). It throws CImgInstanceException when _spectrum != 3, since the transform indexes three channel planes. This is the inverse of XYZtoxyY and is only valid on images in xyY layout.","triggerScenarios":"Calling img.xyYtoXYZ() on an image with spectrum != 3 — grayscale images, RGB/RGBA images not in xyY form, or images where the alpha channel makes the count 4.","commonSituations":"Reversing a chromaticity conversion on an image that still carries an alpha channel; applying xyYtoXYZ to raw RGB data (never converted to xyY); loading multi-channel spectral data and forgetting to reduce to 3 channels.","solutions":["Check img.spectrum()==3 before the call and fix the pipeline so xyY data is stored as exactly 3 channels.","Only call xyYtoXYZ on the result of XYZtoxyY(); for raw RGB use RGBtoXYZ() instead.","Remove or separate extra channels: get_channels(0,2) for RGBA, or duplicate gray channels for 1-channel images.","Wrap the call in try/catch for CImgInstanceException in native code."],"exampleFix":"// before\nimg.xyYtoXYZ(); // img is grayscale, spectrum==1 -> throws\n// after\nif (img.spectrum()==1) img = img.get_resize(img.width(),img.height(),1,3); // replicate to 3 channels after ensuring data is xyY\nimg.xyYtoXYZ();","handlingStrategy":"validation","validationCode":"if (img.spectrum()!=3) { /* repair before xyYtoXYZ */ }","typeGuard":"template<class T> bool has3Channels(const cimg_library::CImg<T>& i){ return i.spectrum()==3; }","tryCatchPattern":"try { img.xyYtoXYZ(); } catch (cimg_library::CImgInstanceException& e) { /* recover */ }","preventionTips":["Only invert xyY on XYZtoxyY output","Keep xyY data alpha-free"],"tags":["cimg","color-space","image-processing","instance-check"],"backgroundTag":"incompatible-source-type","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"}