Skip to content

Image Encoder Decoder

Encoder Decoder

Image Encoder

IMage decodes all standard JPGs (baseline, progressive, subsampled) and outputs them in BMP format. This project was created for the video series, Everything You Need to Know About JPEG.

So what does this do?

IMage is a C++ JPG Encoder/Decoder. It enables users to:

  • Encode uncompressed BMP images into baseline JPG format.
  • Decode all standard JPG images (baseline, progressive, and subsampled) and convert them into BMP format.

Features

  • Handles standard JPG formats including baseline, progressive, and subsampled JPGs.
  • Supports decoding of all JPG markers and standard quantization and Huffman tables.
  • Allows encoding of BMP images to JPG format using the Baseline DCT method.

Decode JPG to BMP

  1. Ensure the build environment is set up (follow the encoding steps above).
  2. Run the decoder: Decode a JPG file and convert it to BMP format.
make

Data Structures

Quantization Table

The quantization tables are pre-defined for various quality settings (e.g., 50, 75, and 100). Each table consists of 64 values that determine the level of compression for Y, Cb, and Cr components of the image.

const QuantizationTable qTableY50 = { ... };

Huffman Tables

Huffman tables are used to efficiently encode and decode the image data. The tables include both DC and AC tables for the Y, Cb, and Cr components.

HuffmanTable hDCTableY = { ... };
HuffmanTable hACTableY = { ... };

Common Issues

  • Invalid JPG format: If the decoder fails to read the JPG file, ensure that the image is in a standard format (baseline, progressive, or subsampled).
  • Compression artifacts: If encoding results in poor image quality, adjust the quantization table for a better quality setting (e.g., use a higher quality table such as qTableY75 or qTableY100).