Jump to content
  • Advertisement
Sign in to follow this  
yuppies

loading JPG in C

This topic is 4565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

guys do you have any code on how to load JPG file in ANSI C? pls dont tell me to use jpeglib.h which is common around the net., i just want to get the raw data of the image and some important information like the width or the height, when i say raw data of the image i meant the UNDECODED image or the verry bytes content of the file since the library jpeglib.h DECODE it to RGB format when jpeg_read_scanlines function is invoked. But most importantly i just need the image data itself, a simple jpg loader only.

Share this post


Link to post
Share on other sites
Advertisement
Hi.

If you don't want libjpeg then I guess you should take a look on http://www.wotsit.org/ and download JPEG format specification (in graphics section, page 5).

Hope it helps.

Share this post


Link to post
Share on other sites
You can read file header and get width/height and some other data from there. Look here for description of the JFIF header.
To load rest of the image, just allocate memory chunk big enough to hold it and read data from the file using fread function from CRT.

Share this post


Link to post
Share on other sites
"simple" is a relative word for the JPEG format; thanks to the wonders of mathematics, JPEG data is stored in wave information, in the lumanance/chromanance colorspace, not the RGB colorspace.

If you just want to get the contents of the JPEG file into memory, just fopen() it and read in the contents. The JFIF header might contain information like the image's scale, but personally I'd never touch the whole image format without a library; their is simply too much going on inside of the format for me to code/debug, etc, etc. And to tell you the truth, unless you're a CS major studying JPEG compression, the same's gonna be true here (but then again, why would you come to us with that question??)

So my advice is, use jpeglib.h. If you want the bytes before decoding, read them from the file, and then pass a copy of them instead of a reference to them to your JPEG decoder. Then you'll have a copy of both the raw, encoded data, and the decoded data.

Good luck, I have a feeling you're going to need it on this one.

EDIT: start with the Wikipedia article: JPEG, that'll explain a lot of how nasty it gets.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!