I am a newcomer to the Intel IPP world. I am working in Visual C++. The code I'm working on performs certain manipulations on C++ arrays. After performing all these manipulations which use many IPP functions like FFT, Convert and so on, I'd like to write the array as an image to file. So far, I've succeeded in using ippiEncodeLoadCodeBlock_JPEG2K_32s_C1R and ippiEncodeStoreBits_JPEG2K_1u to encode the array to jpeg. The example in the IPP documentation illustrates that the encoded array can be written to file thus
fwrite(pDst, sizeof(Ipp8u), sizeof(pDst), FILE* file);
However, though the imagefile is created on disk and it has a non-zero size(some 60KB), I'm not able to view the image.
Can somebody please tell me what is wrong and how to correct it?
I wonder how you were able to get 60 KB of file :). You should get 4/8-byte long file. Because sizeof(pDst) is usually 4/8 depending on architecture used. You should know the size of your output data. What is the last IPP function you are using to fill pDst buffer? What destination parameters does it have?
Thanks for replying. I'm attaching the code block
status = ippiEncodeInitAlloc_JPEG2K(&pState, imgsize);
status = ippiEncodeLoadCodeBlock_JPEG2K_32s_C1R(psrc, 256*sizeof(Ipp32s), imgsize, pState, ippWTSubbandLxLy, 16, ippMQTermSimple, ippMQRateApprGood, IPP_JPEG2K_USE_SEGMENTATION_SYMBOLS, &psfbits, &nOfpasses, &nOfTermPasses);
status = ippsConvert_32s32f_Sfs(psrc, pnewsrc, 256*256, 0);
status = ippsConvert_32f8u_Sfs(pnewsrc, pDst, 256*256, ippRndNear, -2);
int isNotFinish = 1;
int len = sizeof(pDst);
ippiEncodeStoreBits_JPEG2K_1u(pDst, &len, pState, &isNotFinish);
FILE* outfile = fopen("D:image1.jpg", "wb");
fwrite(pDst, sizeof(Ipp8u), len, outfile);
I'm not sure about some of the parameters supplied to ippiEncodeLoadCodeBlock_JPEG2K_32s_C1R; subband, magnBits, mqTermType, codeStyleFlags are all assumptions. I've tried going through the documentation time and again but my understanding is not complete so I had hoped that if I could atleast get an image, even if it is somehow wrong, I would be able to tweak the parameters and correct it.
int isNotFinish = 1;
int len = BUFFER_LEN;
ippiEncodeStoreBits_JPEG2K_1u(buffer, &len, state, &isNotFinish);
// You can write compressed data to the output stream, for example:
// fwrite(buffer, sizeof(Ipp8u), len, file);
Look how "len" is used. Before calling EncodeStoreBits it contains the length of buffer (BUFFER_LEN). It can be 1024, 2048, whatever. In your example you take len=sizeof(pDst). If "pDST" is a result of some "pDst = malloc(your_buffer_len)" statement, this is not correct. You should use "your_buffer_len" as initializer for "int len" variable within inner loop.
Last minute thoughts. I haven't tried this, but you may not get the image. You may get only compressed bits of an image. It's like JPEG file without internal format headers, footers etc. To have full-functional compressed image, which can be viewed by any image viewer, you need to add standard format records, describing the compressed data, that you have.
Yes, I was afraid that might be the case! I suppose Ipp does not have any functions that might give me a "viewable" image file? Or any documentation to say what headers to be added for the type of encoding I'm using - Entropy encoding?
Thanks a lot
You may want to look at UIC sample (JPEG2000 codec) and to use it as is, or as a base of your own modification. http://software.intel.com/en-us/articles/code-samples-for-intel-integrated-performance-primitives-in...
Why don't you use OpenCV to write.It is really a good friend with IPP when you need opening or writing image files after or before processing with ipp.
Adem Metin CALI