cancel
Showing results for 
Search instead for 
Did you mean: 

JPEG decompression to BMP

gnyturan
Associate II
Posted on July 17, 2013 at 11:47

Hello all,

I've been trying to convert JPEG files to BMP for over two weeks. I have STM3240G-EVAL which includes IJG's JPEG library in its ''demonstration builder'', however, I could not figure out how to use it. All I got is linker errors and I even cannot compile example code in the library. 

There is a methodology given by IJG but it wasn't of help. Actually this is a C related problem but not about STM32 itself but I thought maybe someone used the library anyway.

Can anyone please help me to learn how to use this library and its functions?

p.s. The most problem with the linker error is using the full library as I seen on all blogs forums etc. I tried that too. 

Best regards,

Gunay
7 REPLIES 7
sonurobots
Associate III
Posted on July 17, 2013 at 12:27

well  I have already used libjpeg in stm32f4discovery. it's quite fast without using any external ram .

          jpeg_create_decompress(&cinfo);

 jpeg_mem_src(&cinfo,wait1,sizeof(wait1));  //here wait1 is a jpeg file of size 240*160

 jpeg_read_header(&cinfo, TRUE);

 jpeg_start_decompress(&cinfo);

 int buffer_height =1;

 buffer=(JSAMPARRAY)malloc(sizeof(JSAMPROW) * buffer_height);

 buffer[0] = (JSAMPROW)malloc(sizeof(JSAMPLE) * row_stride);

 while (cinfo.output_scanline <cinfo.output_height)

 {

 jpeg_read_scanlines(&cinfo, buffer,1);

     sendlcd(buffer[0],480);  //////****************************main output line.

 }                        //sendlcd fills 1 row of 160 pixes .this is repeated for 240times for 240 coloumns.

gnyturan
Associate II
Posted on July 17, 2013 at 13:41

Thank you for quick response, it will be of great help.

I'll update you if I can success, or fail (:

Regards
gnyturan
Associate II
Posted on July 17, 2013 at 14:04

Hi, 

I had a problem. Since I do not know how to read a file, I put my jpeg file in an unsigned char array in hex format. Instead of wait 1 in your code I used this array. But the problem is buffer is not defined, I am defining an unsigned char pointer called buffer but the error message says:

Error[Pe167]: argument of type ''unsigned char *'' is incompatible with parameter of type ''JSAMPARRAY''

How can I read the jpeg file from the array and put it into another?

Thanks a lot in advance.

gnyturan
Associate II
Posted on July 18, 2013 at 09:10

Up

sonurobots
Associate III
Posted on July 19, 2013 at 07:39

declare the buffer like this

const char myjpeg[]={here the contents of your array };

remember declaring const will put your jpeg into the flash not ram. this is not necessary if you have enough ram.

sonurobots
Associate III
Posted on July 19, 2013 at 07:44

declare the buffer like this

const char myjpeg[]={here the contents of your array };

remember declaring const will put your jpeg into the flash not ram. this is not necessary if you have enough ram .

you also cant edit the contents if you declare it as const.

jpeg_mem_src is used only for jpeg array not for file. if you want to read from file 

then  use jpeg_stdio_src(&cinfo, infile);

infile is declared as FILE* infile.

sonurobots
Associate III
Posted on July 19, 2013 at 07:57

 while (cinfo.output_scanline <cinfo.output_height)

 {

 jpeg_read_scanlines(&cinfo, buffer,1);

     sendlcd(buffer[0],480);  //////****************************main output line.

 } 

have you declared JSAMPARRAY buffer; /* Output row buffer */

have you allocated the memory 

 buffer=(JSAMPARRAY)malloc(sizeof(JSAMPROW) * buffer_height);

 buffer[0] = (JSAMPROW)malloc(sizeof(JSAMPLE) * row_stride);

you need to do these steps before you call  jpeg_read_scanlines