Advertisement

can you make a function to load other image format?

Started by January 20, 2002 08:35 AM
7 comments, last by mickey 22 years, 8 months ago
how does one create such a function? please don''t tell me you have to know their file structure coz i do have a reference to their file structure, but how do i make a function out of it? thanks!
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Whats your question? More detail...
-Dan
Advertisement
load other image formats like jpg., pcx etc., is that easy to do? what is the best image format for a game anyways? some people say png., what else? why not jpg?
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
load other image formats like jpg., pcx etc., is that easy to do? what is the best image format for a game anyways? some people say png., what else? why not jpg?
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
I don''t know if you have the Trick''s book by Andre LaMothe, but if you do he shows you how to build a .bmp loader. If you look at this, you can see what it takes to load other formats. Basically you usually build structures based on the header information, then load the headers into the structure, then have a data section to load the image. You then render the image based on the header info in the structure.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
No, write a graphics format loader is not easy. For example, if you look the code of the jpglib (open source library that loads jpeg file format) you''ll see about 30 .c files. Of course, there is less complicated file formats, like .bmp and .pcx. but anyway you''ll need to know the structure of the file and the algorithms used to compress/decompress the data.

"If you''''re gonna die, die with your boots on"
"If you''re gonna die, die with your boots on"
Advertisement
so okey this is what i must do...,
first, learn how to put all the datas of a file image to a structure.,
then i should learn how to make a function similar to LoadImage()? right?

gelmir? why do i need to know the compression etc., alogorithms?
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Most file formats compress the color data for the image they contain because otherwise the files would be rather large. Algorithms are necessary for decompressing that data so that it can be displayed on screen. Open a graphic file in a decent editor and then save it as a raw file, then compare the size with the original file. There should be quite a difference.

Different formats use different compression algorithms. For example, gif uses Lev-Zimpel-Welch (LZW), jpg uses discrete cosine transform (DCT), some bmps use run length encoding (RLE).

Consider - a 64 x 64 pixel graphic - that''s 4096 pixels x 24 bits per pixel to store the color value - that''s 12288 bytes plus however many bytes are in the header. Because there is a lot of repetition in graphics files and quite often a lot of "empty space" - they make good candidates for compression. Those 12288 bytes can be compressed into something like 4000 bytes. When it comes time to display the image, those 4000 bytes have to be decompressed back into the original 12288 bytes in order to display the correct color for each pixel.

‘But truth's a menace, science a public danger.’ Brave New World, Aldous Huxley
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
[shameless_plug]
This is more for 2D than 3D (depending on what your doing) but you might want to look at CDX. It's a nice 2D library using DX7. We've got several functions that load different image formats and it's all called with one function. It reads the file, finds out what kind of format it is, and calls the appropriate function. You can find CDX at http://www.cdxlib.com/.
[/shameless_plug]



Always remember, you''re unique. Just like everyone else.

Edited by - Greven on January 21, 2002 1:26:16 PM
Always remember, you''re unique. Just like everyone else.Greven

This topic is closed to new replies.

Advertisement