Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
6709 Discussions

Read JPEG then copy to second CIppImage write corrupted

alessandroferrucci
255 Views
Hello,
I have a very small application where I'm reading 1 image, copying it to another CIppImage and attempting to encode the second image but the Encoder fails to encode the second image. The failure happens on the WriteData portion of the encoder.

If I simply decode the JPEG into a CIppImage and then re-encode that same CIppImage, then everything works fine.

The SaveImageJPEG and ReadImageJPEG are the methods that are provided in jpeg.cpp/h in picnic application.

I'm running this against IPP 6.1.2.041.

I'm certain that I'm doing something really stupid in initializing the copyImage but can't figure out what.

Edit: I have even tried to use CIppImage's method CopyFrom ( ). to copy all data from 1 CIppImage to another, but I still get failures on encoding.

Here is the sample code.

JERRCODE ReadImageJPEGHighLevel ( CIppImage& image, std::string fileName );
JERRCODE SaveImageJPEGHighLevel ( CIppImage& image, std::string fileName );
int main ( int argc, char**argv ){
cout << "Test rotate image" << endl;
CIppImage image;
string fileName= "C:\\test.jpg";
string fileNameOut="C:\\testout2.jpg";
JERRCODE jerr;
jerr=ReadImageJPEGHighLevel ( image, fileName );
if(jerr!=JPEG_OK){
cerr << "read image failed"< }else{
cout << "read image success"< }

//rotate the image
CIppImage copyImage( image.Size(), image.NChannels(), image.Precision() );
ippiCopy_8u_C1R ( image.DataPtr(),image.Step(),copyImage.DataPtr(),copyImage.Step(),image.Size() );
jerr=SaveImageJPEGHighLevel ( copyImage, fileNameOut );
if(jerr!=JPEG_OK){
cerr << "save image failed"< cout << "REASON: " << jerr << endl;
}else{
cout << "save image success"< }
image.Free();
copyImage.Free();
}

JERRCODE SaveImageJPEGHighLevel ( CIppImage& image, std::string fileName ){
JERRCODE jerr;
CStdFileOutput fo;
BaseStream::TStatus status;
status = fo.Open(fileName.c_str());

PARAMS_JPEG m_param_jpeg;
m_param_jpeg.color=JC_RGB;
m_param_jpeg.huffman_opt=0;
m_param_jpeg.mode=JPEG_BASELINE;
m_param_jpeg.point_transform=0;
m_param_jpeg.predictor=1;
m_param_jpeg.quality=75;
m_param_jpeg.restart_interval=0;
m_param_jpeg.sampling=JS_411;
m_param_jpeg.dct_scale=JD_1_1;
m_param_jpeg.use_qdct=1;
m_param_jpeg.comment_size=0;
m_param_jpeg.comment[0] = '';

jerr=SaveImageJPEG( image,m_param_jpeg, fo );
fo.Close();
return jerr;
}

JERRCODE ReadImageJPEGHighLevel ( CIppImage& image, std::string fileName ){
JERRCODE jerr;

image.Color(JC_UNKNOWN);

CStdFileInput in;

UIC::BaseStream::TStatus status;
status = in.Open(fileName.c_str());
PARAMS_JPEG m_param_jpeg;
m_param_jpeg.nthreads = 2;
m_param_jpeg.dct_scale = JD_1_1;
m_param_jpeg.use_qdct = 1;
jerr = ReadImageJPEG(in, m_param_jpeg, image);
in.Close();
return jerr;
}
0 Kudos
1 Reply
alessandroferrucci
255 Views
Upon further debugging I have found the issue.

My Copy image was not getting the m_order,color, and sampling attributes set correctly (they were un-initialized) and thus was causing issues on the encoder process.

Adding these lines:

copyImage.Order(0);
copyImage.Color(JC_RGB);
copyImage.Sampling(JS_444);

Fixes the issue.

Thanks,
0 Kudos
Reply