decompress JPEG into BMP using jpeglib -- from memory buffer

Posted on 2009-04-22
Last Modified: 2012-05-06
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

Question by:kishan66
    LVL 49

    Expert Comment

    Since you seem to be finished with your earlier question (http:/Q_24333258.html) please close it.  See
       How Do I close a question?

    Author Comment

    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

    LVL 49

    Accepted Solution

    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?

    Author Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now