I have followed the NVJPEG transcoder example from NVIDIA documentation, and I am observing some strange results with CUDA 11.6.
Specifically, the function
nvjpegEncoderParamsCopyHuffmanTables doesn’t seem to actually copy Huffman tables to encoded image. I have verified using JPEGSnoop tool that Huffman tables in the encoded image are not only reordered (DC->AC->DC->AC instead of DC->DC, AC->AC), but also different compared to the source image.
Source image I used for testing was created using Photoshop (dimensions 1155 x 1140) and the same image was saved as Baseline Standard, Baseline Optimized, and as Progressive with 3, 4, and 5 scans, all of them with Quality 12.
Where Photoshop produces 107.50 KB baseline standard and 31.61 KB baseline optimized image, NVJPEG transcoding of those images with copied quantization and Huffman tables results in 62.77 KB output image.
Where Photoshop produces 24.38 KB progressive JPEG with 3 scans, NVJPEG transcoding of that image with copied quantization and Huffman tables results in 131.68 KB output image.
Furthermore, I have encountered one image which when transcoded in this way has corruption in the output. If I re-save that image with Photoshop and transcode it, then it is ok just like any other images I tested with.
Moreover, transcoding CMYK JPEG images is not possible using the NVIDIA transcoder sample code, because the NVJPEG library is incorrectly returning
NVJPEG_CSS_UNKNOWN subsampling when parsing CMYK JPEG image. Here we get to the NVJPEG API design issue – chroma subsampling enum does not have subsampling values for 4 component streams such as YCCK. I am not sure which subsampling factors are supported for CMYK JPEG (YCCK), but at least 4444 should be supported (which would mean no subsampling on any component).
If you call
NVJPEG_CSS_UNKNOWN which you get from
nvjpegJpegStreamGetChromaSubsampling() it will of course error out, and I am not sure that even copying quantization and Huffman tables would work in that case.
Finally, NVJPEG still does not decode CMYK JPEG correctly (colors are totally wrong) even though I reported it here long time ago.
If someone from NVIDIA team can respond I can send them the CMYK image and the problematic image that gets corrupted on transcoding for testing along with a Visual Studio project in a private message.