Link to home
Start Free TrialLog in
Avatar of kishan66
kishan66Flag for United States of America

asked on

decompress JPEG into BMP using jpeglib -- from memory buffer

hi all,

how can we decompress an jpeg into BMP using JPEGLIB???

i have compressed data in memory buffer ...and now i want to make this as  the source and decompress it into BYTES.

Environment:- C,WIN32 application

Thanks
Avatar of DanRollins
DanRollins
Flag of United States of America image

Since you seem to be finished with your earlier question (http:/Q_24333258.html) please close it.  See
   How Do I close a question?
   http://www.experts-exchange.com/help.jsp?hi=407
Thanks.
Avatar of kishan66

ASKER

Hi ,

When i am trying to Decompress Jpeg into BMP i am getting this error.

______ERROR___________
unresolved external symbol "struct djpeg_dest_struct * __cdecl jinit_write_bmp(struct jpeg_decompress_struct *,unsigned char)"
_____END ERROR________

please find the code for the Decompression...
void write_BMP_file (BYTE *image_buffer, BITMAPINFO *image, int quality,char *filestring);
where  image_buffer = memory_buffer  containing the JPEG data got from the Copression.
            image= BITMAPINFO HEader data.


void write_BMP_file (BYTE *image_buffer, BITMAPINFO *image, int quality,char *filestring)
        struct jpeg_decompress_struct cinfo;
	struct jpeg_error_mgr jerr;
	int i;
	djpeg_dest_ptr dest_mgr = NULL;
	
	FILE * output_file;
	JDIMENSION num_scanlines;
	/* Initialize the JPEG decompression object with default error handling. */
	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_decompress(&cinfo);
	/* Add some application-specific error messages (from cderror.h) */
	jerr.addon_message_table = cdjpeg_message_table;
	jerr.first_addon_message = JMSG_FIRSTADDONCODE;
	jerr.last_addon_message = JMSG_LASTADDONCODE;
 
	if ((output_file = fopen(filestring, WRITE_BINARY)) == NULL) {
		//fprintf(stderr, "can't open %s\n",filestring);
		//exit(EXIT_FAILURE);
		MessageBoxA(hwnd," file unable to open ","File Error",NULL);
	}
	
	/* Specify data source for decompression */
		//jpeg_stdio_src(&cinfo, input_file);
	  int numBytes = 0; //size of jpeg after compression
		char * storage=new char[150000];//storage buffer
		JOCTET *jpgbuff = (JOCTET*)storage; //JOCTET pointer to buffer
		jpeg_memory_src(&cinfo,jpgbuff,150000);
 
	/* Read file header, set default decompression parameters */
	(void) jpeg_read_header(&cinfo, TRUE);
 
	/* Output must be BMP */
	dest_mgr = jinit_write_bmp(&cinfo, FALSE);
	dest_mgr->output_file = output_file;
 
	/* Start decompressor */
	(void) jpeg_start_decompress(&cinfo);
	
	/* Write output file header */
	  cinfo.image_width =  image->bmiHeader.biWidth ; /* image width and height, in pixels */
	  cinfo.image_height =  image->bmiHeader.biHeight*-1;
	  cinfo.out_color_components =3;       /* # of color components per pixel */
	  cinfo.out_color_space = JCS_RGB;     /* colorspace of input image */
	
	(*dest_mgr->start_output) (&cinfo, dest_mgr);
 
	/* Process data */
	while (cinfo.output_scanline < cinfo.output_height) 
	{
		num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,
			dest_mgr->buffer_height);
		(*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);
	}
 
	/* Finish decompression and release memory. */
	(*dest_mgr->finish_output) (&cinfo, dest_mgr);
	(void) jpeg_finish_decompress(&cinfo);
	jpeg_destroy_decompress(&cinfo);
 
	/* Close files */
	//fclose(input_file);
	fclose(output_file);
 
	/* All done. */
	exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
				/* suppress no-return-value warnings */
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi DanRollins,

Example is very good and easy to understand.

But in that eample, it reads from a file ..where as i want to read from a Byte*.....
So  can tell me how to Decompress Jpeg ...into a BYTE* where source is BYTE *

i really appreciate your help.

Thank you