The following code from the attached sample project mimics the 06_jpeg_decode sample from the SDK.
NvJPEGDecoder *jpegdec = NvJPEGDecoder::createJPEGDecoder("jpegdec");
if (!jpegdec)
{
std::cerr << "NvJPEGDecoder::createJPEGDecoder() FAILED" << std::endl;
return cv::cuda::GpuMat();
}
jpegdec->disableMjpegDecode();
uint32_t width, height, pixfmt;
ret = jpegdec->decodeToFd(fd, buffer, size, pixfmt, width, height);
if (ret == -1 || fd == 0)
{
std::cerr << "jpegdec->decodeToFd() FAILED" << std::endl;
return cv::cuda::GpuMat();
}
NvBufSurf::NvCommonAllocateParams params;
/* Create PitchLinear output buffer for transform. */
params.memType = NVBUF_MEM_SURFACE_ARRAY;
params.width = width;
params.height = height;
params.layout = NVBUF_LAYOUT_PITCH;
if (out_pixfmt == 1)
params.colorFormat = NVBUF_COLOR_FORMAT_NV12;
else if (out_pixfmt == 2)
params.colorFormat = NVBUF_COLOR_FORMAT_YUV420;
else if (out_pixfmt == 3)
params.colorFormat = NVBUF_COLOR_FORMAT_NV16;
else if (out_pixfmt == 4)
params.colorFormat = NVBUF_COLOR_FORMAT_NV24;
params.memtag = NvBufSurfaceTag_VIDEO_CONVERT;
ret = NvBufSurf::NvAllocate(¶ms, 1, &dst_dma_fd);
if (ret == -1)
{
std::cerr << "NvBufSurf::NvAllocate() FAILED, create dmabuf failed" << std::endl;
return cv::cuda::GpuMat();
}
/* Clip & Stitch can be done by adjusting rectangle. */
NvBufSurf::NvCommonTransformParams transform_params;
transform_params.src_top = 0;
transform_params.src_left = 0;
transform_params.src_width = width;
transform_params.src_height = height;
transform_params.dst_top = 0;
transform_params.dst_left = 0;
transform_params.dst_width = width;
transform_params.dst_height = height;
transform_params.flag = NVBUFSURF_TRANSFORM_FILTER;
transform_params.flip = NvBufSurfTransform_None;
transform_params.filter = NvBufSurfTransformInter_Nearest;
ret = NvBufSurf::NvTransform(&transform_params, fd, dst_dma_fd);
if (ret == -1 || dst_dma_fd == -1)
{
std::cerr << "NvBufSurf::NvTransform() FAILED" << std::endl;
return cv::cuda::GpuMat();
}
#if 1
// Write raw video frame to file.
// output is 512x240 corrupt image, but valid YUV
std::ofstream *out_file = new std::ofstream("/test/nvidia/dumped-output.yuv");
if (out_file)
{
/* Dumping two planes for NV12, NV16, NV24 and three for I420 */
dump_dmabuf(dst_dma_fd, 0, out_file);
dump_dmabuf(dst_dma_fd, 1, out_file);
if (out_pixfmt == 2)
{
dump_dmabuf(dst_dma_fd, 2, out_file);
}
}
#endif
The code from the SDK is identical and the calls to dump_dmabuf generate a valid YUV at the correct resolution. The code from the attached sample project generates a YUV image at an incorrect resolution of 512x240 as shown in the previous post. Both applications tested with same input JPEG.
How is the pitch not taken into account and what needs to be done to resolve the issue?
jpeg_hwaccel.zip (22.3 KB)