The JPEG (Joint Photographic Experts Group) compression standard is the most widely used format for digital photographs on the web. Unlike lossless codecs, JPEG achieves very high compression ratios by discarding perceptually insignificant information from the image. At its core, the algorithm transforms pixel data into the frequency domain, aggressively quantises the high-frequency components (which the human eye is less sensitive to), and then encodes the result efficiently.
This Java program demonstrates the key computational stages of JPEG compression applied to a single 8×8 pixel block: the Discrete Cosine Transform (DCT), quantisation, zigzag scan, and a simplified entropy encoding step.
This example provides an educational look at the key stages of JPEG compression.
JPEG Compression Pipeline
A real JPEG encoder processes an image in the following sequence. This program implements all four stages for one 8×8 luminance block:
Input block — An 8×8 grid of pixel intensity values.
DCT — Converts spatial pixel data into frequency-domain coefficients.
Quantisation — Divides each DCT coefficient by a value from the standard luminance quantisation table and rounds to the nearest integer, discarding fine detail.
Zigzag scan — Reorders the 8×8 quantised coefficients into a 1D array, placing the most significant low-frequency coefficients first.
Entropy encoding — Encodes the 1D array using a simplified run-length + binary scheme similar to the actual JPEG Huffman coding step.
Run-Length Encoding (RLE) is one of the simplest lossless data compression techniques. Instead of storing every character individually, it replaces consecutive runs of the same character with a single instance of that character preceded by a count. For example, the string AAABBC becomes 3A2B1C. RLE works best on data with long repeated runs, such as bitmap images or binary sequences, and is often used as a preprocessing step in more sophisticated codecs like JPEG and fax compression standards.
This Java program reads a string from the user, applies RLE compression using hexadecimal run-length counts, and reports the encoded output along with the original length, encoded length, and the resulting compression ratio.
Computer graphics animation is the technique of creating the illusion of movement by rapidly drawing and erasing images on screen. In the Borland Turbo C environment, the graphics.h library provides low-level drawing functions that make it straightforward to build simple frame-by-frame animations. In this post, we walk through a C program that animates a truck moving across the screen using rectangles and circles to represent the truck body and wheels.
What the Program Does
The program draws a simple truck shape — a large rectangle for the cabin/body, a smaller rectangle for the cab, and two circles for the wheels — then shifts this shape incrementally across the screen to create an animation effect. Between each frame the viewport is cleared, giving the impression of smooth movement.