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

JPEG codec in jpegview usage problem

enjoysoft
Beginner
590 Views

I'm using the JPEG codec in jpegview sample as recommended. I'm making a network camera using TCPIP upon Windows, which will send Jpeg header once and data frame as client asked. I'm migrating from ijg to this codec but find little document and user'guide. The code does not work. Here is my demo code:

 const int imgSize = 768 * 576 * 3;
BYTE* buf = new BYTE[imgSize];
BYTE* img = new BYTE[imgSize];
 // Grab original image into img 
 // ...
IppiSize size = {768, 576};

CJPEGEncoder encoder;
encoder.SetSource((Ipp8u*)img, 768 * 3, size, 3, JC_BGR);
encoder.SetParams(JPEG_BASELINE,JC_YCBCR, JS_444, 0, 0, 95);

CMemBuffOutput jpegDest;
jpegDest.Open(buf, imgSize);
encoder.SetDestination(&jpegDest);

CJPEGDecoder decoder;
decoder.SetDestination((Ipp8u*)img, 768 * 3, size, 3, JC_BGR);

CMemBuffInput jpegSrc;
jpegSrc.Open(buf, imgSize);
decoder.SetSource(&jpegSrc);

int width, height, nchannels;
JCOLOR color;
JSS sampling;
int precision;
encoder.WriteHeader();
// The next ReadHeader() will get error -4, why?
decoder.ReadHeader(&width, &height, &nchannels, &color, &sampling, &precision);
for(int i = 0; i < 10; i++)
{
// Reset source and destination
jpegDest.Open(buf, imgSize);
encoder.SetDestination(&jpegDest);


jpegSrc.Open(buf, imgSize);
decoder.SetSource(&jpegSrc);






encoder.WriteData();
//int num = encoder.NumOfBytes();
decoder.ReadData();
}

delete[] img; delete[] buf;

So I use memoy to memory compress and decompress to show the whole system. The first loop will generate good result. But the next loop will be wrong. Is my code correct? Help!

0 Kudos
2 Replies
Vladimir_Dudnik
Employee
590 Views

Hello,

I think the reason is that you mix encoder and decoder calls and get situation where you lost JPEG header information (which is needed for decoder ReadHeader call) after you call encoder's WriteData. If you are trying to simulate network connection between encoder and decoder it might be better to separate encoder's output buffer from decoder's input buffer. Then operation Copy will simulate transmittion of data through network.

Regards,
Vladimir

0 Kudos
enjoysoft
Beginner
590 Views
Then how to export a jpeg file with only one head and several images?How to read it using decoder? Is there any example?
0 Kudos
Reply