Skip to main content
gamedev.net
🔒 Locked

JPEG Loading

Started by rodrix Feb 28, 2007 at 1:12 AM 6 replies 3.8k views
Original Post
rodrix
rodrix
Hi there! I am sure this topic has been revised many times... but not recently up to what I checked. Well, I visited almost the entire net and found of old unuseful code (like an excellent wrapper to IJL, which is now not free, so I cannot find it anywhere, and other static libraries that only compile in VS6 but not VS8). Please guys, I am kind of really extremelly desperate! haaha (I don't know if you get my point... ) But I have spent the last 15 hours trying to add a JPEG loader so that I can then pass the bitmap data to OpenGL. None of all the codes I tried were a succesful compilation under Visual Studio 2005. I managed to make them work in VS6, however, once I upgrade, the code is useless, since I get linker and compilation errors because the .lib files are not meant to be user under VS 2005. I looked at other messages from forums (the newest I found was from 2002, and only one from 2005) and said that an alternative was to use "Devil" library or some other heavy libraires. However, I don't want to load all those big stuff to just use JPEG load. I want something easy to add to my current code. I went to the Independent JPEG Group's page (or something like that) and their last update is from 1998, and their sources are in VS6, no wonder they don't work in VS8. I also download the sources of the libraries and they are like thousands of sources in some cryptic undesciphrable code.... Could anyone please tell me where I can find a JPEG wrapper and library to use in my OpenGL engine that works in VS 2005?! (I just need bitmap data, width, and height). Thanks so much everyone!!!! Cheers! Rod
rodrix
rodrix
Yes I also tried that, I have a wrapper of that Independent JPEG Group libs for VS 6 but I couldn't make it work for VS 8.


I would've thought VS 2005 would import and convert VS 6 project files?
[/Quote]
Yes VS 2005 "upgrades" your code, but not the .lib's if they are static libraries since they are compiler dependent. So the solution does not compile since the .lib's cannot be used with 2005 even though the code is "upgraded".

One solution would be to recompile that .lib using VS 2005, however I don't have the source, nor the knowledge to recompile it (!) (their documentation is from 1998 and cryptic).

Do you propose any solution!?
Thanks so much in advance,
Cheers
Rod
cobru
cobru
I downloaded the sources of jpeg lib from here (as they say on ijg.org) and managed to get it to build under VS2005.

I made a solution file for you, you can download it here, example\example.c is the one that comes with the jpeg library and example\main.c is my own little test... seemed to work fine.

Good luck.
Q: How many programmers does it take to write a nice piece of software?A: MORE.
rodrix
rodrix
... I couldn't make it work... :( I get tons of linker errors... (definitions and other declarations clash with my other loaded libraries)
I really feel kind of dumb... I already spent more than two days with this and I can't solve it.

By the way, I found the Intel library IJL, which is supposed to be easier than Independent group Jpeg, and found a wrapper made by John W. Ratcliff. It links nicely and compiles perfectly (no clashes), however still the wrapper is not complete. I think I might be more lucky working on this solution that links ok.

Here I pass you the library which is indeed extremelly difficult to obtain in case you want it with the unfinished wrapper:

The wrapper is lovely and easy:
  static void *ReadImage(int &width,   // width of the image loaded.                         int &height,  // height of the image loaded.                         int &bpp,     // BYTES (not bits) PER PIXEL.                         const void *buffer, // memory address containing jpeg compressed data.                         int sizebytes); // size of jpeg compressed data.  static void * Compress(const void *buffer, // address of image in memory                         int width, // width of image in pixels                         int height, // height of image in pixels.                         int bpp, // *BYTES* per pixel of image 1 or 3                         int &len, // returns length of compressed data                         int quality=75); // image quality as a percentage



I uploaded the wrapper and the IJL library:
http://pianonews.googlepages.com/ijl151JPEGWrapper.zip

However, I am missing as to what to pass to buffer in ReadImage... should I pass all the JPEG's content, or skip the JPEG header? If I should do last, how can I read the JPEG's header to know the size of the actual data and read it?!

...aghh... I am really about to give up with JPEG...
Thanks so much in advance,
Rod
cobru
cobru
 if ( ijlRead(&jcprops,IJL_JBUFF_READPARAMS) != IJL_OK )  {    ijlFree(&jcprops);    return 0;  }


seems like you have to pass the entire file in the buffer parameter of ReadImage... (jpeg.h is 0 bytes in your zip file, is that how it's supposed to be?)

As for the scaline function, if you're referring to my example.c and main.c, it works like this:

read_JPEG_file() (from IJG's example.c) expects you to have a global function put_scaline_someplace, which recevies as input a line of bitmap data from the decompressed image. If you have a look in example.c, they commment pretty-much everything (so you should get a good picture on how to use the library).

As for the name clashes, normally, if you just include "jpeglib.h" in your program and link with the .lib, it shouldn't give you any problems.
If I have time, I'll try to make a wrapper class for you ...

Edit:

a while later, I made a small wrapper for the jpeg library, you can get the whole project at this address.

Basically, I put a class CJPEGImage inside the .lib with all the IJG stuff, so you just have to include "CJpegimage.h" in your project and link with jpeglib.lib and it should work.
You have a folder called library in the zip mentioned above, and there it goes like thi:
debug\jpeglib.lib -> link with this in your debug build (you can setup in your project settings the path to jpeglib.lib, under 'linker\general\additional library directories')
release\jpeglib.lib -> link with this in your release build
header\cjpegimage.h -> this is the header you need to include, setup the include path under project settings - c/c++ - general - additional include directories
src\CJpegImage.cpp -> this is the source for the class, basically it's just example.c from IJG, wrapped in a C++ class.

I'm not sure how 'good' the code is, it's just something put together very fast (or, in other words, "the code is provided AS IS" :D )

If you want to rebuild jpeglib.lib you can use the previous .zip you have and just add cjpegimage.cpp and cjpegimage.h in the jpeglib project and rebuild it...

the "key" to link with jpeglib would be to:
#include // must be before jpeglib !

extern "C" { // very important
#include "jpeglib.h"
}

Good luck.

[Edited by - cobru on March 1, 2007 4:17:53 AM]
Q: How many programmers does it take to write a nice piece of software?A: MORE.
rodrix
rodrix
Hi Cobru!
I don't know how much to thank you! I really appreciate all your time and your kindness. :)

Here is the IGL wrapper with the .h file header that did not upload correctly now complete:
http://pianonews.googlepages.com/ijl151JPEGWrapperOK.zip

Unfortunately, I tried you wrapper but I am still not succesful.. :(
Thanks for the extern "C" tip, I didn't know that, that was one my problems, anyways I got a Multiple Symbol Redefinition linker error, as it seems that some of the references that the .lib are repreated in my source. I deleted all #include 's from the .h files and .cpp files from and made sure was not repetead and everything... however, still same error.

I am now trying again with the IJL wrapper, that as I told you, links nicely.
I think I am on step far from making it work..

Thanks so much for everything,
Rod

[Edit:]

IT WORKED IT WORKED IT WORKED!!!!!!!!!!!!!!!
I am so happy, after three days of work!!!! I am jumping on one leg!!!!! Yes!!!!
THANK YOU THANK YOU THANK YOU Cobru!

Here is the code that makes it work:
	struct IMAGE	{		int planes;							int sizeX;							int sizeY;							unsigned char *data;				char isBGR;							IMAGE(){ planes=0; sizeX=0; sizeY=0; data=NULL; isBGR=0; }	};	IMAGE texture::LoadJPG(const char *filename)	{	IMAGE i;		Jpeg MyJpeg;	 	  int length;	  char * buffer;	  ifstream is;	  is.open (filename, ios::binary );	  // get length of file:	  is.seekg (0, ios::end);	  length = is.tellg();	  is.seekg (0, ios::beg);	  // allocate memory:	  buffer = new char [length];	  // read data as a block:	  is.read (buffer,length);	  is.close();	  cout.write (buffer,length);	 int width;	 int height;	 int level;	i.data= (unsigned char* )MyJpeg.ReadImage(width, height,level, buffer, length);		//	= (unsigned char *) buffer;	i.isBGR=0;	i.planes = level;	i.sizeX=width;	i.sizeY = height;			  delete[] buffer;				return i;}


and AGAIN, TTTTTHHHHHHHAAAAAAAAANNNNNKKKKKKKKKK YOU!!!!!!!! :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.