This project aims to create an image compressor/decompressor in C based on the JPEG specification and following the lossy compression model for 24-bit BMP images.
- The image width and height must be multiples of 8.
- The image dimensions must be within the allowed range (8x8 to 1280x800).
- The image must have 24 bits per pixel and no compression.
- There are 2 separated programs, the
compressorand thedecompressor. - Some data is lost during compression (lossly).
- Huffman tables, DCT and quantization matrices used are standard ones, provided in the code (
types.c).
-
Color Space Conversion: Converts RGB to YCbCr color space.
-
Chroma Subsampling (4:2:0): Reduces resolution of the Cb and Cr channels by averaging 2×2 blocks.
-
Block Splitting: Each channel is split into 8×8 pixel blocks.
-
Discrete Cosine Transform (DCT): Transforms each block from spatial to frequency domain.
-
Quantization: Applies a quantization matrix to discard less important frequencies.
-
Zigzag Ordering: Rearranges coefficients from each block into a 1D array prioritizing low-frequency values.
-
Differential & Run-Length Encoding (RLE):
- DC coefficients use differential encoding.
- AC coefficients are compressed with RLE.
-
Huffman Encoding: Encodes the RLE symbols using provided Huffman tables.
-
Binary Writing: The compressed output is saved in a .bin file.
-
Binary Parsing and Huffman Decoding
-
RLE Expansion and Delta Decoding
-
Reverse Zigzag
-
Dequantization
-
Inverse DCT (IDCT)
-
Block Reconstruction
-
Color Space Conversion: Converts YCbCr back to RGB.
To compile both compressor and decompressor, run:
bash compile.sh
or use any equivalent command like sh.
To remove all compiled binaries and object files, run:
bash clean.sh
./compressor <input.bmp> <output.bin>
After compression, the program will display the input and output file sizes and the compression ratio and create the <output.bin> file.
./decompressor <input.bin> <output.bmp>
After decompression, the program will create the <output.bmp> file that you can compare with the original image.
- Store the downsampled Cb and Cr channels correctly in the binary.
- During the decompression process, upsample the Cb and Cr channels back to their original size matrices after reading the binary.