{"record":{"id":"e819a91b33ecba6e","repo":"mozilla/pdf.js","slug":"unsupported-color-mode","errorCode":null,"errorMessage":"Unsupported color mode","messagePattern":"Unsupported color mode","errorType":"exception","errorClass":"JpegError","httpStatus":null,"severity":"error","filePath":"src/core/jpg.js","lineNumber":1393,"sourceCode":"    if (ColorSpaceUtils.cmyk instanceof DeviceCmykCS) {\n      // The alpha-component isn't updated by `DeviceCmykCS`, doing it manually.\n      for (let i = 3, ii = data.length; i < ii; i += 4) {\n        data[i] = 255;\n      }\n    }\n    return data;\n  }\n\n  getData({\n    width,\n    height,\n    forceRGBA = false,\n    forceRGB = false,\n    isSourcePDF = typeof PDFJSDev === \"undefined\" ||\n      !PDFJSDev.test(\"IMAGE_DECODERS\"),\n  }) {\n    if (this.numComponents > 4) {\n      throw new JpegError(\"Unsupported color mode\");\n    }\n    // Type of data: Uint8ClampedArray(width * height * numComponents)\n    const data = this.#getLinearizedBlockData(width, height, isSourcePDF);\n\n    if (this.numComponents === 1 && (forceRGBA || forceRGB)) {\n      const len = data.length * (forceRGBA ? 4 : 3);\n      const rgbaData = new Uint8ClampedArray(len);\n      let offset = 0;\n      if (forceRGBA) {\n        grayToRGBA(data, new Uint32Array(rgbaData.buffer));\n      } else {\n        for (const grayColor of data) {\n          rgbaData[offset++] = grayColor;\n          rgbaData[offset++] = grayColor;\n          rgbaData[offset++] = grayColor;\n        }\n      }\n      return rgbaData;","sourceCodeStart":1375,"sourceCodeEnd":1411,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/jpg.js#L1375-L1411","documentation":"Thrown by getData() if the parsed JPEG has more than 4 color components. The decoder supports grayscale (1), RGB/YCbCr (3), and CMYK/YCCK (4) only; 5+ components (e.g. hexachrome, multi-spectral) have no defined color-conversion path.","triggerScenarios":"Calling jpegImg.getData({...}) when jpegImg.numComponents > 4. The numComponents value comes from the SOF's componentsCount during parse().","commonSituations":"An unusual JPEG with extra ink channels (hexachrome/Hi-Fi color), or an image with an alpha-like 5th component. Very rare in PDF workflows; usually from specialized print/spectral imaging.","solutions":["Check jpegImg.numComponents before calling getData and reject/handle 5+ explicitly.","Re-encode the image to a standard 1/3/4-component color space before embedding.","If you must decode it, use a specialized multi-channel decoder outside PDF.js."],"exampleFix":"// before\nconst pixels = jpegImg.getData({ width, height, forceRGBA: true });\n\n// after\nif (jpegImg.numComponents > 4) {\n  throw new Error(`Unsupported: ${jpegImg.numComponents} color components`);\n}\nconst pixels = jpegImg.getData({ width, height, forceRGBA: true });","handlingStrategy":"validation","validationCode":"if (jpegImg.numComponents > 4) {\n  throw new Error('JPEG has ' + jpegImg.numComponents + ' components; only 1, 3, or 4 are supported');\n}\n// only then:\nconst pixels = jpegImg.getData({ width, height });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check jpegImg.numComponents after parse() and before getData().","Re-encode multi-channel JPEGs to a standard 1/3/4-component color space.","Reject 5+ component images early with a clear error rather than letting getData throw."],"tags":["jpeg","color-space","image-decoding","validation"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}