Solved

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

Posted on 2003-12-02
10
2,581 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
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.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

810 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