Show understanding of how data for a bitmapped image are encoded

Published by Patrick Mutisya · 14 days ago

Cambridge A‑Level Computer Science 9618 – 1.2 Multimedia

Objective: Understand how data for a bitmapped image are encoded

Bitmapped (raster) images store colour information for each individual pixel. The way this information is encoded determines the file size, colour fidelity and the types of operations that can be performed efficiently.

Key Concepts

  • Pixel (picture element) – the smallest addressable element of an image, defined by its position (x, y) and colour value.
  • Resolution – the number of pixels in the horizontal and vertical directions, usually expressed as width × height (e.g., 1920 × 1080).
  • Colour depth (bits per pixel, bpp) – the number of bits used to represent the colour of a single pixel.
  • Palette (colour table) – a list of colours that can be referenced by an index; used in indexed colour images.
  • RGB model – each colour is represented by three components: red, green and blue.
  • Bit planes – the set of bits at the same position across all pixels; useful for certain image processing techniques.

Colour Encoding Methods

1. Direct (True‑colour) Encoding

Each pixel stores its colour directly, usually as separate red, green and blue components.

  • 24‑bit colour: 8 bits for each of R, G, B → \$2^{8}=256\$ levels per channel, \$256^3 = 16{,}777{,}216\$ possible colours.
  • 32‑bit colour: adds an 8‑bit alpha channel for transparency.

2. Indexed (Palette‑based) Encoding

Pixels store an index into a colour table (palette). The palette holds the actual RGB values.

  • Common palette sizes: 2, 4, 16, 256 colours (corresponding to 1, 2, 4, 8 bpp).
  • Reduces file size when the image uses a limited set of colours.

Calculating Image Data Size

The amount of data required for a bitmap image can be estimated with the following formula:

\$\text{File size (bits)} = \text{width} \times \text{height} \times \text{bits per pixel}\$

To convert to bytes, divide by 8 and round up to the nearest whole byte.

Example Calculation

Consider a 640 × 480 image stored with 8 bpp (256‑colour palette).

  1. Calculate total pixels: \$640 \times 480 = 307{,}200\$ pixels.
  2. Multiply by bits per pixel: \$307{,}200 \times 8 = 2{,}457{,}600\$ bits.
  3. Convert to bytes: \$\frac{2{,}457{,}600}{8} = 307{,}200\$ bytes ≈ 300 KB.

Colour Depth vs. Number of Colours

Bits per pixel (bpp)Number of coloursTypical use
12Black & white (binary images)
24Simple graphics, early video games
416Standard \cdot GA palettes
8256Indexed colour photographs, GIF
1665 536High‑colour displays, some BMP variants
2416 777 216True‑colour images, most JPEG/PNG
3216 777 216 + alphaTrue‑colour with transparency (PNG‑32)

Data Layout in Memory

Bitmapped images are usually stored row‑by‑row (scanline order). Each row may be padded to a byte or word boundary depending on the file format.

Example: 24‑bit RGB layout

Byte 0: Red component of pixel (0,0)

Byte 1: Green component of pixel (0,0)

Byte 2: Blue component of pixel (0,0)

Byte 3: Red component of pixel (1,0)

...

Example: 8‑bit indexed layout

Byte 0: Index into palette for pixel (0,0)

Byte 1: Index for pixel (1,0)

...

Common File Formats and Their Encoding

  • BMP – can store uncompressed RGB or indexed data; simple header followed by pixel array.
  • GIF – limited to 8 bpp indexed colour; includes LZW compression.
  • PNG – supports 1, 2, 4, 8, 16 bpp indexed or true‑colour; uses lossless DEFLATE compression.
  • JPEG – typically 24‑bit true‑colour; uses lossy DCT‑based compression (outside the scope of raw bitmap encoding).

Why Encoding Choice Matters

  • File size – fewer bits per pixel reduce storage and transmission costs.
  • Colour fidelity – higher colour depth provides smoother gradients and more accurate colour reproduction.
  • Processing speed – simpler encodings (e.g., 1‑bpp) allow faster pixel‑wise operations.
  • Compatibility – some devices or software only support certain colour depths.

Suggested diagram: A visual comparison of a 2‑bpp indexed image versus a 24‑bpp true‑colour image of the same scene, highlighting the difference in colour richness and pixel data layout.