• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2087
  • Last Modified:

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

  • 2
  • 2
1 Solution
Since you seem to be finished with your earlier question (http:/Q_24333258.html) please close it.  See
   How Do I close a question?
kishan66Author Commented:
Hi ,

When i am trying to Decompress Jpeg into BMP i am getting this 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);
	/* 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);
		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
	/* 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->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);
	/* Close files */
	/* All done. */
	exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);
				/* suppress no-return-value warnings */

Open in new window

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?
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now