To get jpeg.lib:
1) Go to Ulrich von Zadow's "Class library for image file decoding" article, and click on the "Links" link.
2) Click on the "LIBJPEG ver 6b" link to download the "vanilla" libjpeg.
3) Do not use Mr. von Zadow's "Paintlib" version of libjpeg, because he seems to have made some internal changes for his own use.
The jpeg.lib project (LibJpeg) is set up to compile under numerous operating systems. The download includes a file called install.doc. Read the sections relevant to VC++/Windows. You have to rename a couple of files, etc.
The first time I installed and compiled libjpeg, it took a long time and was very aggravating. I then re-read the instructions, and it took about fifteen minutes. I'm sure there's a lesson here...
Testing Notes:
To test the code, I used MS Paint to create bitmap files in the four supported formats.
I then set up a VC++ project which read the bitmap files, and used the functions below to turn them into JPEG files (.jpg).
I then used Julian Smart's CImage demo application to display them.
I also used Internet Explorer as well as MS Word to display them.
I also created a jpeg file by loading an internal resource (see the example below). The largest bitmap file I dealt with was about 390 KB.
Error trapping:
libjpeg includes a number of provisions for improving error detection, and reporting them in a good manner. I have not investigated these, and the code does not include any of them. Right now, an internal error will simply cause the code to stop cold.
To get at jpeg.lib properly in your project:
- Under tools->options, directories tab:
- Set the Include Files to include the path to your jpeg.lib project
- Set the Library Files to include the path to your jpeg.lib release directory
- Under Project->Settings, Link tab:
- Add jpeg.lib to the Object/library modules list
Note on Quality Settings:
For the IDB_TEST resource, I tried two quality settings: 10 and 100. At "10", the image had a lot of black spottiness, and took up 1 KB. At "100" the image looked very good, and took up 4 KB.