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

getting RGB (unsigned char *) from JPEG (binary).

Could somebody guide me how to convert JPEG to RGB?

Any suggestion.
0
neel3333
Asked:
neel3333
1 Solution
 
neel3333Author Commented:
I found some code.
 jpeg_decompress_struct cInfo;
     FILE *filePtr;
               
     unsigned char     *imageData;
     unsigned int     imageWidth;
     unsigned int     imageHeight;
     unsigned char     bitDepth;

     filePtr = fopen(path, "rb");
               
     jpeg_error_mgr jerr;
     cInfo.err = jpeg_std_error(&jerr);
     jpeg_create_decompress(&cInfo);
     jpeg_stdio_src(&cInfo, filePtr);

     jpeg_read_header(&cInfo, TRUE);
     jpeg_start_decompress(&cInfo);
     bitDepth = cInfo.num_components;
     imageWidth = cInfo.image_width;
     imageHeight = cInfo.image_height;

     imageData = ((unsigned char*)malloc(sizeof(unsigned char)*imageWidth*imageHeight*bitDepth));

     jpeg_finish_decompress(&cInfo);

     jpeg_destroy_decompress(&cInfo);
     free(imageData);
     fclose(filePtr);

but it seem that it does not get pass jpeg_finish_decompress(&cInfo) when I compile the code. Someone plz help me get the imageData from jpeg image.

thank you.
0
 
DanRollinsCommented:
I don't know aanything about those jpeg_Xxxxx calls you are making.  But...

If you are programming for Windows, there is an API that loads a JPG file and produces a bitmap image in memory.   That lets you get the image data in RGB format quit easily.  See these references for the first step.  When you are able to successfully load a JPG file, then post back and I'll show you how to obtain RGB values from the image data.

    C++ Q&A: Displaying a JPG in your MFC Application -- MSDN Magazine, October 2001
    http://msdn.microsoft.com/msdnmag/issues/01/10/c/default.aspx
    http://msdn.microsoft.com/msdnmag/issues/01/10/c

    OleLoadPicture API call
    http://msdn.microsoft.com/library/en-us/com/htm/ofn_ol2z_0k4l.asp

    SAMPLE: How to Load and Display Graphics Files with LOADPIC.EXE
    http://support.microsoft.com/support/kb/articles/Q218/9/72.ASP

-- Dan
0
 
monkesdbCommented:
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jonninCommented:
The standard jpg library (from the jpeg group page) has code to decompress into a targa. An uncompressed targa (one of the options) is a rgb file with headers, I hacked this code to return the rgb array in short order.

0
 
neel3333Author Commented:
I did that at first, but the
    put_scanline_someplace(buffer[0], row_stride);
has undeclared identifier.
My idea of the whole thing is get the unsigned char* of the image, b/c my SetDIBitsToDevice() function only accept unsigned char *.
Plz help ASAP.

Thank you
0
 
DanRollinsCommented:
neel3333,
You are clearly using Windows.  Are you set on using the standard jpg library, or have you tried using the OleLoadPicture API?  

If you are in a hurry, I can help, but not if you will be using some third-party library code.

-- Dan
0
 
neel3333Author Commented:
I'm using standard jpg library
0
 
neel3333Author Commented:
Hi Dan. Sorry we did not able to reply your post in time.
We modified the loadpic code to recieve jpeg file, but we a problem with displaying the images. I didn't have the code on the machine, but I'll put it up later. Basicly, I deleted most of the option with loadpic  and inserted socket to recieve the gif file and then loading it.

Right now I'm have problem of view sequence of files (streaming).
0
 
migoEXCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept DanRollins's comment as answer.

Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

migoEX
EE Cleanup Volunteer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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