I noticed that for none of the CMYK JPEG samples out there (e.g. the one attached underneath Exception reading a CMYK Jpeg · Issue #40 · coobird/thumbnailator · GitHub ) nvJPEG decodes properly the CMYK channels into either NVJPEG_OUTPUT_RGBI or NVJPEG_OUTPUT_UNCHANGED:
First, the decoupled decoding appears to be mandatory, even though the documentation may suggest that NVJPEG_OUTPUT_UNCHANGED works with the single step API: The single step API will produce a garbled black channel.
The output from decoupled decoding has strange CMY channels, but the correct black
NVJPEG_OUTPUT_RGBI gives roughly the same result as NVJPEG_OUTPUT_UNCHANGED and a manual conversion into RGB
Fitting the nvJPEG (nv for short) CMY channels vs. libjpeg (lj for short) output using the image linked above gives:
C_lj = 434.2 - 0.999 C_nv - 1.401 M_nv
M_lj = 119.6 - 1.000 C_nv + 0.344 M_nv + 0.714 Y_nv
Y_lj = 480.8 - 0.999 C_nv - 1.768 M_nv + 0.002 Y_nv
With some round-off error, and the constant in the front, this is basically one step of the YUV-to-RGB conversion with intermediate U’, V’, as seen e.g. here: YUV to RGB Conversion (4th set of equations).
Is the CMYK decoding in nvJPEG currently broken, and activates certain YUV conversion code paths in the library?