Hello. I am using nvJPEG to encode a raw BMP image to JPEG. Everything seems to work ok but the encoded image output is a little corrupt. You can tell that it is the original image, but there are lines through it.
Image of nvJPEG output:
Here is my setup code for nvJPEG
nvjpegCreateSimple(&nvjpeg_handle);
nvjpegJpegStateCreate(nvjpeg_handle, &jpeg_state);
nvjpegEncoderStateCreate(nvjpeg_handle, &encoder_state, NULL);
nvjpegEncoderParamsCreate(nvjpeg_handle, &encode_params, NULL);
nvjpegEncoderParamsSetQuality(encode_params, 70, NULL);
nvjpegEncoderParamsSetOptimizedHuffman(encode_params, 1, NULL);
nvjpegEncoderParamsSetSamplingFactors(encode_params, NVJPEG_CSS_420, NULL);
And here is the encoding part
nvjpegStatus_t status;
int imageSize = width * height * 4;
int rowPitch = width * 4;
unsigned char* pBuffer = NULL;
nvjpegImage_t source;
cudaMalloc((void**)&pBuffer, imageSize);
cudaMemcpy(pBuffer, bmpData, imageSize, cudaMemcpyHostToDevice);
source.channel[0] = pBuffer;
source.pitch[0] = rowPitch;
status = nvjpegEncodeImage(nvjpeg_handle, encoder_state, encode_params, &source, NVJPEG_INPUT_RGBI, width, height, NULL);
std::vector<unsigned char> obuffer;
size_t length;
nvjpegEncodeRetrieveBitstream(
nvjpeg_handle,
encoder_state,
NULL,
&length,
NULL);
obuffer.resize(length);
nvjpegEncodeRetrieveBitstream(
nvjpeg_handle,
encoder_state,
obuffer.data(),
&length,
NULL);
cudaFree(pBuffer);
Ive tried with multiple different inputs/outputs for the encoder params and input_format for nvjpegEncodeImage. And yes the BMP file im reading is RGBI, the channels are not split so that is not my issue. Any help is appreciated!