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
kishan66Asked:
Who is Participating?
 
DanRollinsConnect With a Mentor Commented:
You seem to be using source code from what looks like a more-complex-than--necessary system.  The jinit_write_bmp function does not appear to be part of the standard JPGLIB code.  Take a look at this simpler example:
    Convert an RGB BYTE* array to BITMAP ... How?
    http://www.experts-exchange.com/Programming/Languages/CPP/Q_21550278.html
0
 
DanRollinsCommented:
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.
0
 
kishan66Author Commented:
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

0
 
kishan66Author Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.