Advertisement

Loading a JPG or GIF

Started by May 24, 2002 04:02 AM
5 comments, last by TimeStorm 22 years, 5 months ago
How cand I load in visual C a JPG or/and a GIF
I'd forget about loading jpegs for the time being, it is a nasty file format which requires a bit of maths to decode. Gifs are a bit easier, they use a RLE compression algorithm (Run Length Encoding) which is pretty easy to decode, although you will also need to load the palette information.

You can find more info on the file formats at Wotsit.org, or you could always Google for some third party libraries if you don't want to write your own.


[edited by - Sandman on May 24, 2002 8:12:11 AM]
Advertisement
>> Gifs are a bit easier, they use a RLE compression algorithm (Run Length Encoding) which is pretty easy to decode

This is not correct. GIF does not use RLE encoding but LZW encoding and it is a somewhat more complex than RLE. I think you are confusing it with PCX which uses RLE or with BMP which optionally can use RLE encoding.

Anyway, TimeStorm, try to find the source code on the net or write a loader yourself. If you don''t care about space the most simple format you can use is the PPM format which is specified here:
http://astronomy.swin.edu.au/~pbourke/dataformats/ppm/
A loader for this format can be written in minutes. And most major graphics programs support it.
Jacob Marner, M.Sc.Console Programmer, Deadline Games
quote: Original post by felonius
This is not correct. GIF does not use RLE encoding but LZW encoding and it is a somewhat more complex than RLE. I think you are confusing it with PCX which uses RLE or with BMP which optionally can use RLE encoding.


D''oh! I stand corrected.

Intel has a library for loading JPEGs[1]. In addition, the GDI+ libraries support both JPEG and GIF natively.

[1]http://www.intel.com/software/products/perflib/ijl/

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Independent JPEG Group have a library for jpeg loading (bit of work because you need to compile it). Also look at PNG for a GIF replacement (there were some issues with patents and so forth on the GIF decoders, not sure about the current status of this).
Advertisement
Check out DevIL. It''s fairly easy to use, and it supports multiple graphics file formats, including .jpg and .gif. I don''t think you can save .gifs with it, but you can definitely save .jpgs. Check out the Features page to see what formats it can currently load and save.

This topic is closed to new replies.

Advertisement