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

writing/creating a jpeg image on disk

Lis
Beginner
795 Views

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? 

  

0 Kudos
9 Replies
Sergey_K_Intel
Employee
795 Views

Hi Lis,

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?

Regards,
Sergey 

0 Kudos
Lis
Beginner
795 Views

Hi Sergey,

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;
while(isNotFinish)
{
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.

0 Kudos
Sergey_K_Intel
Employee
795 Views

There's a sample at http://software.intel.com/sites/products/documentation/hpc/ipp/ippi/ippi_ch15/functn_EncodeStoreBits_JPEG2K.html#ex15-7

[cpp]

int isNotFinish = 1;
while(isNotFinish)
{
    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);
}

[/cpp]

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.

Regards,
Sergey 

0 Kudos
Lis
Beginner
795 Views

As you can see, pDst is not the result of some malloc statement. pDst is my array so when I take its size, it's giving me array size in bytes right?

0 Kudos
Sergey_K_Intel
Employee
795 Views

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.

Regards,
Sergey 

0 Kudos
Lis
Beginner
795 Views

Hi Sergey,

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

Lis

0 Kudos
Sergey_K_Intel
Employee
795 Views

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-intel-ipp-library-71

Regards,
Sergey 

0 Kudos
SergeyKostrov
Valued Contributor II
795 Views
>>...I was afraid that might be the case! I suppose Ipp does not have any functions that might give me a "viewable" >>image file... You could verify your jpg-file if it has a header. Just open it as a binary in any editor and if this is a correct jpg-file it should have a signature JFIF at the beginning of the file ( positions from 7 to 10 ).
0 Kudos
adem_metin_cali
Beginner
795 Views

Hi Lis,

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

0 Kudos
Reply