Make your own free website on

Image Decoder Engine


This page provides sample image decoder source code(C++) at the end of page for download.


About JPEG:

JPEG is a standard encoding standard used for digital image storing. The image is segmented into blocks of 8x8 pixels. For each block, Discrete Cosine Transform (DCT) is used to decompose the pixels into frequency domain representation of 3 color components, intensity(Y), luminance(Cb) and chrominance(Cr). The data is then Huffman encoded and stored in commonly known .jpg or .jpeg files. 

Though the frequency decomposition introduces distortion to the original image, the quality loss in most images is invisible to human eye down to 0.5 bit/pixel compression.


About the decoding engine (CJPGEngine):

Image display is common in application programming. For this, JPEG is by far, the most widely available image source. With the compression technique used in JPEG file, image decoding is far from easy as compared to the uncompressed BMP or lightly compressed PCX file format. C++ class CJPGEngine provided through JPGLib.h and JPGLib.cpp here is an easy to use source code for JPEG decoding in application.

It can be easily plugged into C++ application to decode the JPEG bitstream into 24-bit RGB array. The only thing you need to do is to instantiate a CJPGEngine object. Then, call ProcessInFile() with a NULL terminated character array indicating the full path of the .jpg file. Finally, call GetImage() to retrieve a pointer to the decompressed image buffer. You can obtain the dimension of the image through GetX() and GetY(). Everything else is taken care by the CJPGEngine. One note to remember is that, the destructor will release the allocated buffer (returned by GetImage) upon object destruction. Thus, you need to copy its contents to somewhere else if you do not want to keep CJPGEngine alive throughout your program.

The provided JPGEngI.dsp serves as an example of the usage CJPGEngine. You can compile it directly on Microsoft Visual C++. Slight modifications may be required for other compilers.





About BMP, PCX:

BMP is standard bitmap image used in Microsoft Windows. Early BMP files store uncompressed pixel data. Development in color and resolution of computer graphic makes uncompressed image file unreasonably huge. Thus, latest BMP specification has included Run Length Encoding (RLE) as one of its options. On the other hand, PCX file format is originally developed by Z-soft for its Paintbrush products. Similar to BMP, PCX stores lossless digital image. PCX always store image run-length-encoded. In summary, BMP and PCX store image in similar way but with different file format.


About the decoding engine (CBMPEngine, CPCXEngine):

The usage is the same as CJPGEngine.





About TIF:

TIF specifications are maintained by Adobe. Data is stored in the file in blocks specified by header tags. This makes the format flexible to further extensions in various field. Use can also add in user-specific tags and blocks. Standard TIF readers simply skip the unknown blocks. This file format can be used to store image file (black-and-white, grayscale, 2/4/8-bit image or True Color) in various options such as compressed/uncompressed, lossless/lossy. TIF specification even allow JPG bitstream to be a TIF block.


About the decoding engine (CTIFFEngine):

The usage is the same as CJPGEngine.





About GIF:

GIF specifications are maintained by CompuServe Incorporated. Data is stored in the file in Lempel-Ziv compressed format (LZW). This file format can be used to store image file (2/4/8-bit image) losslessly. GIF specification allows multiple frames to be stored in the same file. Thus, allowing simple animation.


About the decoding engine (CGIFEngine):

The usage is the same as CJPGEngine.

Every call to GetImage() returns next image frame.

Frames() returns total number of frames in the file.





"The Graphics Interchange Format(c) is the Copyright property of

CompuServe Incorporated. GIF(sm) is a Service Mark property of

CompuServe Incorporated."


License Agreement:

The source code can be distributed freely and used in non-commercial software. Please read the license.txt included in the JPGEngI package for updated license agreement.

The author has tested CJPGEngine, CPCXEngine, CBMPEngine and CTIFFEngine on some images successfully. However, use the source code at your own risk! The author is not responsible for any damages/losses due to the use of the code.


Helps required?

Feedbacks are appreciated regarding any part of the design for fine tuning.



CJPGEngine, CPCXEngine, CBMPEngine along CTIFFEngine  along with example usage in JPGEngI package. (62Kb)


Related links: