loading JPG in C
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.
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.
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.
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.
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.
"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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement