JPEG Encoding with Discrete Cosine Transform, Quantisation & Run-Length Compression
This repository contains a JPEG image encoder implemented in C. It takes a BMP image as input and encodes it using Discrete Cosine Transform (DCT), quantisation, and Run-Length Encoding (RLE), producing a compressed output file.
The encoder performs the following steps:
- Image Loading: Loads a BMP image from the specified input file using the
image_load
function. - Color Conversion: Converts the RGB color space to YCbCr.
- DCT: Applies the Discrete Cosine Transform (DCT) on 8x8 blocks of the image using the
forward_dct
function. - Quantisation: Quantizes the DCT coefficients using predefined quantisation matrices and the
quantize_block
function. - RLE: Encodes the quantized coefficients using Run-Length Encoding (RLE).
- File Output: Writes the encoded data to the specified output file, including a header, quantisation tables, and RLE encoded data.
The repository has the following structure:
include/
: Contains header files, including encoder.h, which defines the image and encoder structures and function prototypes.src/
: Contains the source code files.jpeg_encoder.c
: Implements the JPEG encoding logic, including color conversion, DCT, quantisation, and RLE. The main encoding function isjpeg_encode
.dct.c
: Implements the Discrete Cosine Transform (DCT) and quantisation functions, includingforward_dct
,quantize_block
, and related utility functions.main.c
: Contains the main function that parses command-line arguments, loads the image, performs the encoding, and saves the output.utils/
: Contains utility functions.bitstream.c
: Implements bitstream reading and writing functions (currently not used in this encoder).image.c
: Implements image loading and saving functions, includingimage_load
andimage_save
.
Makefile
: Defines the build process for the project.README.md
: This file, providing an overview of the project.
To build the encoder, you need a C compiler (e.g., GCC) and the make
build tool.
- Clone the repository.
- Navigate to the repository's root directory.
- Run the
make
command.
make