Module: NVIDIA Jetson AGX Orin(32GB ram)
L4T: 35.1.0
Jetpack: 5.0.2 GA
As the title suggested, the decoded image is skewed. I created a minimal example:
#include <NvJpegDecoder.h>
#include <NvUtils.h>
#include <NvBufSurface.h>
#include <fmt/format.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <vector>
int main() {
std::vector<uint8_t> jpeg_data;
std::ifstream jpeg_file("sample.jpeg", std::ios::binary);
jpeg_file.seekg(0, std::ios::end);
jpeg_data.resize(jpeg_file.tellg());
jpeg_file.seekg(0, std::ios::beg);
jpeg_file.read(reinterpret_cast<char*>(jpeg_data.data()), jpeg_data.size());
auto nvjpeg_dec = NvJPEGDecoder::createJPEGDecoder("jpegdec");
int fd = 0;
uint32_t w, h, pixfmt;
if (nvjpeg_dec->decodeToFd(fd, jpeg_data.data(), jpeg_data.size(), pixfmt, w, h) < 0) {
std::cerr << "Cannot decode JPEG" << std::endl;
return 1;
}
std::cout << fmt::format("jpeg decoded to pixfmt {} as {}x{}", pixfmt, w, h) << std::endl;
NvBufSurf::NvCommonAllocateParams param_alloc;
memset(¶m_alloc, 0, sizeof(param_alloc));
param_alloc.memType = NVBUF_MEM_SURFACE_ARRAY;
param_alloc.width = w;
param_alloc.height = h;
param_alloc.layout = NVBUF_LAYOUT_PITCH;
param_alloc.colorFormat = NVBUF_COLOR_FORMAT_RGBA;
param_alloc.memtag = NvBufSurfaceTag_NONE;
int dst_dma_fd;
if (NvBufSurf::NvAllocate(¶m_alloc, 1, &dst_dma_fd) < 0) {
std::cerr << "NvBufSurf::NvAllocate failed" << std::endl;
return 1;
}
NvBufSurf::NvCommonTransformParams param_trans;
param_trans.src_top = 0;
param_trans.src_left = 0;
param_trans.src_width = w;
param_trans.src_height = h;
param_trans.dst_top = 0;
param_trans.dst_left = 0;
param_trans.dst_width = w;
param_trans.dst_height = h;
param_trans.flag = NVBUFSURF_TRANSFORM_FILTER;
param_trans.flip = NvBufSurfTransform_None;
param_trans.filter = NvBufSurfTransformInter_Nearest;
if (NvBufSurf::NvTransform(¶m_trans, fd, dst_dma_fd) < 0) {
std::cerr << "NvBufSurf::NvTransform failed" << std::endl;
return 1;
}
std::ofstream raw_file("decoded.rgba", std::ios::binary);
if (dump_dmabuf(dst_dma_fd, 0, &raw_file) < 0) {
std::cerr << "dump_dmabuf failed" << std::endl;
return 1;
}
return 0;
}
This will load a local jpeg file and decode it to rgba. The source sample.jpeg and the result rgba file’s screenshot is uploaded.
Should notice the decoded image’s bottom rows are blurred, and the full image seems like scaled a little but the width*height is still kept(click to open the attached image, and use mouse to switch between them, the different is easy to get noticed).