WZJPG SDK Documentation
Introduction
WZJPEG is a powerful implementation for JPEG image compression and decompression, based on the Independent JPEG Group's software with additional modifications from libjpeg-turbo and Mozilla. It provides robust functionality for handling JPEG images with various optimization features and quality settings.
Key Options
- Quality Control: Adjustable compression quality (0-100)
- Multiple Speed Profiles: Three speed profiles (fastest, medium, slow) balancing compression speed and quality
API Definitions
Key functions:
/* Initialize compression */
jpeg_create_compress(j_compress_ptr cinfo); // Create compression object
jpeg_stdio_dest(j_compress_ptr cinfo, outfile); // Set output destination
/* Set parameters */
jpeg_set_defaults(j_compress_ptr cinfo); // Set default parameters
jpeg_set_quality(j_compress_ptr cinfo, quality, TRUE); // Set compression quality
jpeg_c_set_bool_param(j_compress_ptr cinfo, param, value); // Set boolean parameter
jpeg_c_set_int_param(j_compress_ptr cinfo, param, value); // Set integer parameter
jpeg_c_set_float_param(j_compress_ptr cinfo, param, value); // Set float parameter
/* Compression process */
jpeg_start_compress(j_compress_ptr cinfo, TRUE); // Start compression
jpeg_write_scanlines(j_compress_ptr cinfo, row_pointer, 1); // Write image data
jpeg_finish_compress(j_compress_ptr cinfo); // Finish compression
jpeg_destroy_compress(j_compress_ptr cinfo); // Clean up
API Parameters
Key structures and parameters:
| Parameter | DataType | Definition |
|---|---|---|
| JINT_COMPRESS_PROFILE | int | Compression profile (e.g., JCP_MAX_COMPRESSION for slow/best, JCP_MEDIUM, JCP_FASTEST for baseline) |
| JBOOLEAN_TRELLIS_QUANT | boolean | TRUE = use trellis quantization for coefficient optimization |
WZJPG Sample Encoder
Introduction to the wzjpg_sample_encoder
wzjpg_sample_encoder is a simple application that demonstrates how to use the WZJPG library for JPEG compression. It accepts PPM (P6 format) images as input and produces JPEG files as output. The encoder showcases key features of the WZJPG library including:
- Quality control (0-100 scale)
- Speed profile selection (slow/best, medium, fast)
- Basic error handling
- Memory management
- Proper initialization and cleanup of JPEG compression structures
Building the wzjpg_sample_encoder
To build the sample encoder, follow these steps:
- Ensure you have the WZJPG library installed on your system
- Create a new file named
wzjpg_sample_encoder.cwith the provided code - Compile using one of these methods:
Dynamic Linking (Recommended)
gcc -o wzjpg_sample_encoder wzjpg_sample_encoder.c -I/usr/local/include -L/usr/local/lib -lwzjpg
Static Linking
gcc -o wzjpg_sample_encoder wzjpg_sample_encoder.c -I/usr/local/include /usr/local/lib/libwzjpg.a
Notes:
- Adjust the include path (-I) and library path according to your WZJPG installation location
- For static linking, replace
/usr/local/lib/libwzjpg.awith the actual path to your static library - Static linking will embed the WZJPG library into your executable, making it larger but more portable
- Dynamic linking requires the WZJPG shared library to be available on the target system
Running the wzjpg_sample_encoder
The sample encoder accepts four command-line arguments:
./wzjpg_sample_encoder <input.ppm> <output.jpg> <quality> <speed>
Example usage:
# Compress input.ppm to output.jpg with high quality and slow/best compression
./wzjpg_sample_encoder input.ppm output.jpg 90 0
# Compress with medium quality and fast compression
./wzjpg_sample_encoder input.ppm output.jpg 75 2
Parameters:
input.ppm: Input PPM file (must be in P6 binary format)output.jpg: Output JPEG file name with extensionquality: This takes values in the range[0, 100](higher numbers mean better quality)speed: Compression speed profile0: Slow/best quality (uses JCP_MAX_COMPRESSION)1: Medium quality (uses JCP_MEDIUM)2: Fast quality (uses JCP_FASTEST)
Additional Resources
For more detailed information about specific functions and parameters, please refer to:
- Header files (jpeglib.h)
- Source code documentation
License and Attribution
This library includes code from:
- Independent JPEG Group's software
- libjpeg-turbo modifications
- Mozilla Corporation modifications
Please refer to the accompanying README.ijg file for detailed license information and conditions of use.