Solved

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

Posted on 2003-12-02
10
2,587 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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
 

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
designing in object programming 12 109
Android development question 2 81
best imaging disk tool 15 60
visual C++ 1 13
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
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"…

730 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