Solved

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

Posted on 2003-12-02
10
2,574 Views
Last Modified: 2013-11-19
Could somebody guide me how to convert JPEG to RGB?

Any suggestion.
0
Comment
Question by:neel3333
10 Comments
 

Author Comment

by:neel3333
ID: 9863223
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
 
LVL 49

Accepted Solution

by:
DanRollins earned 500 total points
ID: 9863320
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
 
LVL 3

Expert Comment

by:monkesdb
ID: 9864233
0
 
LVL 2

Expert Comment

by:jonnin
ID: 9866087
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:neel3333
ID: 9869160
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 9869655
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
 

Author Comment

by:neel3333
ID: 9878290
I'm using standard jpg library
0
 

Author Comment

by:neel3333
ID: 10112066
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
 
LVL 5

Expert Comment

by:migoEX
ID: 10331544
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

IT, Stop Being Called Into Every Meeting

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!

Join & Write a Comment

Suggested Solutions

If your app took Google’s lash recently, here are the 5 most likely reasons.
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…

707 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

21 Experts available now in Live!

Get 1:1 Help Now