{"record":{"id":"736b22acdfc10240","repo":"Yalantis/uCrop","slug":"load-yuv-specified-chroma-subsampling-u-is-inv","errorCode":null,"errorMessage":"load_yuv(): Specified chroma subsampling %u is invalid, for file '%s'.","messagePattern":"load_yuv\\(\\): Specified chroma subsampling %u is invalid, for file '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67196,"sourceCode":"                                    const unsigned int size_x, const unsigned int size_y=1,\n                                    const unsigned int chroma_subsampling=444,\n                                    const unsigned int first_frame=0, const unsigned int last_frame=~0U,\n                                    const unsigned int step_frame=1, const bool yuv2rgb=true) {\n      return CImgList<T>().load_yuv(file,size_x,size_y,chroma_subsampling,\n                                    first_frame,last_frame,step_frame,yuv2rgb);\n    }\n\n    CImgList<T>& _load_yuv(std::FILE *const file, const char *const filename,\n                           const unsigned int size_x, const unsigned int size_y,\n                           const unsigned int chroma_subsampling,\n                           const unsigned int first_frame, const unsigned int last_frame,\n                           const unsigned int step_frame, const bool yuv2rgb) {\n      if (!filename && !file)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_yuv(): Specified filename is (null).\",\n                                    cimglist_instance);\n      if (chroma_subsampling!=420 && chroma_subsampling!=422 && chroma_subsampling!=444)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_yuv(): Specified chroma subsampling %u is invalid, for file '%s'.\",\n                                    cimglist_instance,\n                                    chroma_subsampling,filename?filename:\"(FILE*)\");\n      const unsigned int\n        cfx = chroma_subsampling==420 || chroma_subsampling==422?2:1,\n        cfy = chroma_subsampling==420?2:1,\n        nfirst_frame = first_frame<last_frame?first_frame:last_frame,\n        nlast_frame = first_frame<last_frame?last_frame:first_frame,\n        nstep_frame = step_frame?step_frame:1;\n\n      if (!size_x || !size_y || size_x%cfx || size_y%cfy)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_yuv(): Specified dimensions (%u,%u) are invalid, for file '%s'.\",\n                                    cimglist_instance,\n                                    size_x,size_y,filename?filename:\"(FILE*)\");\n\n      CImg<ucharT> YUV(size_x,size_y,1,3), UV(size_x/cfx,size_y/cfy,1,2);\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");","sourceCodeStart":67178,"sourceCodeEnd":67214,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67178-L67214","documentation":"load_yuv() only supports the chroma subsampling schemes 4:2:0, 4:2:2 and 4:4:4, which define how U/V planes are laid out in the raw stream. Any other value is rejected with CImgArgumentException before any I/O, since plane sizes (cfx/cfy) would be undefined.","triggerScenarios":"Calling load_yuv(filename, w, h, chroma_subsampling, ...) with chroma_subsampling set to anything other than 420, 422, or 444 - e.g. 0 (default-initialized/omitted), 411, 440, or a percent-like value 50.","commonSituations":"Forgetting the parameter so it defaults to 0; guessing the subsampling of a raw YUV dump; confusing 4:2:0 vs 4:2:2 layout conventions (I420/YV12 vs YUY2) or passing a codec fourcc instead of the numeric scheme.","solutions":["Pass the actual scheme of your file: 420 (most common, e.g. I420), 422, or 444","If the parameter was accidentally 0/default, supply it explicitly","Determine the subsampling with ffprobe (e.g. `ffprobe -pix_fmt file.yuv` context) and map pix_fmt to the scheme: yuv420p->420, yuv422p->422, yuv444p->444"],"exampleFix":"// before\nimgs.load_yuv(\"video.yuv\", 640, 480); // chroma defaults to 0\n// after\nimgs.load_yuv(\"video.yuv\", 640, 480, 420); // I420 raw stream","handlingStrategy":"validation","validationCode":"unsigned int cs = /* configured */;\nif (cs != 420 && cs != 422 && cs != 444) { /* reject config / map from pix_fmt first */ }","typeGuard":"bool validChromaSubsampling(unsigned int cs) { return cs == 420 || cs == 422 || cs == 444; }","tryCatchPattern":"try { imgs.load_yuv(path, w, h, cs); }\ncatch (CImgArgumentException& e) { fprintf(stderr, \"bad chroma subsampling %u: %s\\n\", cs, e.what()); }","preventionTips":["Make chroma_subsampling a required, validated config field (never default 0)","Determine subsampling with ffprobe instead of guessing","Document the mapping pix_fmt -> 420/422/444 for your pipeline"],"tags":["cimg","yuv","invalid-argument","video-loading","enum"],"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"}