Jump to content
  • Advertisement
Sign in to follow this  
Endar

writing a loader for jpegs

This topic is 4551 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

For jpegs, do you think I should I try to write my own loader or should I go for an already existsing free lib?

Share this post


Link to post
Share on other sites
Advertisement
Blech. JPEG is not like TGA. Writing a loader for it requires implementing the Inverse Discrete Cosine Transform yourself, as well as transforming between RGB and YCbCr. Unless it's your intention to learn more about signal processing theory, just use a preexisting lib.

Share this post


Link to post
Share on other sites
Go for free library imo, because usually you'll waste your time and come up with a result inferior to the one which has had countless hours spent on development, testing and optimizing.
Try to not re-invent the wheel as much as you can

Hope this helps

Regards,
/Omid

Share this post


Link to post
Share on other sites
Any suggestions on simple libraries? Perhaps libs that only read and don't write? Most of the ones that I've found read, write, and do about 50 million other things. And, I suppose it would be a little strange for a library just to read jpeg's, but do you know of any?

[Edited by - Endar on December 30, 2005 1:33:55 AM]

Share this post


Link to post
Share on other sites
GDI and GDI+ actually support JPEGs, so unless you're developing for a platform other than Windows there is no need for using a 3rd party library.

Share this post


Link to post
Share on other sites
I wrote my own png loader once. It's a single .cpp file with less than 1000 lines of code, and a header with the manual written in there, it has no dependencies at all (it does use std::vectors so it's for C++ only).

You need to call only one function to convert a .png file buffer into a 32-bit RGBA image buffer no matter what the original format was. Or if you don't want an RGBA buffer but a buffer in the original format of the image (RGB, bitmap, palette, 4-bit RGB, ...) you can call another function that returns you both the buffer and the required info like the palette. So it's extremely simple to use :)

I found it much better to write it myself than using a library, because now I can load png's without having to link to anything. And I learned a lot from it, and study "multimedia and signal processing" at university anyway.

However, I didn't write a jpeg library yet, I think I'll do a png writer first...

Share this post


Link to post
Share on other sites
If this is for OpenGL, NeHe's IPicture code can handle a wide variety of formats. Link: http://nehe.gamedev.net/counter.asp?file=files/misc/nehe_ipicture.zip (Didn't linkify because everytime I do someone tells me my link is broken)

Share this post


Link to post
Share on other sites
Quote:
Original post by darookie
GDI and GDI+ actually support JPEGs, so unless you're developing for a platform other than Windows there is no need for using a 3rd party library.


Okay, well, the windows jpeg library is giving me a big problem - it's not picking up the typedef's in its own files because of....something. I don't know. I include, and it never picks it up.

Anywayz, when using GDI, how does it work? Am I able to use GDI functions to load the jpeg and then get a pointer back to the raw RGB data?

Share this post


Link to post
Share on other sites
Okay, here we are again.

I've including this at the top of the source file where I use the jpeglib code.


extern "C" {
#include "..\jpeglib\jconfig.h"
#include "..\jpeglib\jmorecfg.h"
#include "..\jpeglib\jinclude.h"
#include "..\jpeglib\jpeglib.h"
}


I'm not sure if I should be including all of them, but, anyway. At this point, the code that uses this lib is commented out.

Every time I attempt to compile with these, just having the includes at the top gives a bunch of "undefined type" errors for all the typedef's in "jpeglib.h".

The first one is the "UINT16" type. I go into jconfig.h and that has a define for "HAVE_UNSIGNED_SHORT", and in jmorecfg.h it has:

#ifdef HAVE_UNSIGNED_SHORT
typedef unsigned short UINT16;
#else /* not HAVE_UNSIGNED_SHORT */
typedef unsigned int UINT16;
#endif /* HAVE_UNSIGNED_SHORT */


This is nested in an "#ifndef HAVE_ALL_INTS", and I checked, that is not defined.

So, does anyone know what is happening? Why this seemingly simple pre-processor stuff isn't working?

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!