Solved

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

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

Any suggestion.
0
Comment
Question by:neel3333
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 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