Support beyond YUV420 for NvJPEGDecoder/JPEG Decoder

This documentation page says, “The JPEG decoder is capable of decoding YUV420, YUV422, and YUV444 JPEG images. Note: Only the JCS_YCbCr (YUV420) color space is currently supported.”

It’s not clear from the datasheet whether this lack of support for anything other than YUV420 is a hardware constraint or a software constraint. As I understand the statement, even JPEGs encoded in YUV444 are downsampled to YUV420 when decoded — that causes a loss of quality. Are there any plans to support YUV444 output or any higher-quality format (goal is BGR in a Python Numpy array!) in the API?

(P.S.: Unrelated to this, please let your webmaster know that the "Release 36.4: API Reference " link on the Jetson Software Documentation page, Jetson Linux API Reference: Main Page | NVIDIA Docs, yields a 404 error.)

Hi,
By default the format is YUV420. You can check 06_jpeg_decode sample and customize it like:

  1. Check format of fd after decodeToFd() is done
  2. Allocate NvBufSurface in the format(NV16 for YUV422, and NV24 for YUV444)
  3. Call NvBufSurfTransform() to copy data from fd to the allocated NvBufSurface

Yes, I understand I can convert the YUV420 output to YUV444 easily and do see how to do it, but wouldn’t the image suffer a loss of quality due to passing through YUV420, as YUV420 uses 2x2 subsampling and YUV444 does not? The YUV444 conversion from YUV420 decoding output presumably would not match the quality that you’d have if the image was decoded in YUV444 format in the first place.

Hi,
Please add the code after decodeToFd():

{
    NvBufSurface *nvbuf_surf = NULL;
    NvBufSurfaceFromFd(fd, (void **)(&nvbuf_surf));
    if (nvbuf_surf->surfaceList[0].colorFormat ==
        NVBUF_COLOR_FORMAT_YUV444)
        cout << "color format is YUV444 " << endl;
    else
        cout << "color format = " << nvbuf_surf->surfaceList[0].colorFormat << endl;
}

And try to decode the image:

$ gst-launch-1.0 videotestsrc num-buffers=1 ! video/x-raw,format=Y444 ! jpegenc ! filesink location=a.jpg
06_jpeg_decode$ ./jpeg_decode num_files 1 a.jpg a.yuv

I think your code might be slightly off; I expect it will print color format is YUV444 if the color format is non-zero (anything but NVBUF_COLOR_FORMAT_INVALID), but both when I run your code and code modified to unconditionally print the colorFormat, I ascertain that the color format is NVBUF_COLOR_FORMAT_YUV444, which is what I want and not what I expected based on the documentation.

Thanks for the clarification and for your always-timely and incisive effort. I suppose I should have tested this myself and not relied on the documentation, which reads (to me, at least) that YUV420 is the only possible output. Hopefully, you can have it updated to clarify.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.