# Bitmap Graphics & Pixel Calculations

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 1: Data Representation
- **Estimated Duration:** 15 minutes
- **Access:** Open Theory + Free Practice

---

## Theory & Conceptual Background

Computers store visual images in one of two formats: vector graphics (which store mathematical formulas defining lines and shapes) or bitmap graphics (also called raster graphics). Cambridge IGCSE focuses on bitmap graphics and how their pixel values are encoded in binary.

Learning Objectives
Explain how bitmap images are constructed from a grid of pixels with binary colour values.Define and distinguish between image resolution and colour depth (bit depth).Calculate uncompressed bitmap image file sizes in bits, bytes, and binary multiples (KiB, MiB).Explain the role and necessity of metadata in digital graphic files.

Pixels and Bitmap Structure
A bitmap graphic is composed of a two-dimensional grid of picture elements called pixels:
Pixel (Picture Element): The smallest controllable, addressable unit of a digital display or bitmap image.Each pixel in the grid has a specific $(x, y)$ coordinate and is assigned a binary number representing its colour.When an image is zoomed in significantly, individual square pixels become visible, causing pixelation.
+---+---+---+---+
| W | B | B | W |   W = White (binary 1)
+---+---+---+---+   B = Black (binary 0)
| B | W | W | B |
+---+---+---+---+   A 4x4 monochrome bitmap
| B | W | W | B |   requires 16 bits of pixel data.
+---+---+---+---+
| W | B | B | W |
+---+---+---+---+

Key Image Properties
1. Image Resolution
Definition: The total number of pixels that make up the image, typically expressed as:
$$\text{Resolution} = \text{Width (pixels)} \times \text{Height (pixels)}$$
Display Resolution / Pixel Density: Often measured in PPI (pixels per inch) or DPI (dots per inch).A higher resolution contains more pixels per unit of area, providing finer detail and sharper clarity, but increasing total storage size.
2. Colour Depth (Bit Depth)
Definition: The number of binary bits allocated to store the colour value of each individual pixel.The number of distinct colours that can be represented is determined by the formula:
$$\text{Number of Unique Colours} = 2^{\text{Colour Depth (bits)}}$$

  
    Colour DepthAvailable Colours FormulaTotal ColoursCommon Usage
    1-bit$2^1$2 coloursMonochrome (Pure Black and White)4-bit$2^4$16 coloursEarly computer graphics / EGA8-bit$2^8$256 coloursGrayscale or 256-colour indexed palette (GIF)16-bit$2^{16}$65,536 coloursHigh Colour24-bit$2^{24}$$16,777,216$ coloursTrue Colour (8 bits Red, 8 bits Green, 8 bits Blue)32-bit$2^{24}$ colours + $2^8$ alpha$16.7\text{M colours} + \text{Transparency}$True Colour with 8-bit Alpha transparency channel
  

In 24-bit True Colour, every pixel uses three 8-bit bytes:
1 byte (8 bits) for Red ($0\text{ to }255$)1 byte (8 bits) for Green ($0\text{ to }255$)1 byte (8 bits) for Blue ($0\text{ to }255$)
Combining 256 levels for each of the three primary light colours yields $256 \times 256 \times 256 = 16,777,216$ unique shades.

Image File Size Calculations
To calculate the minimum uncompressed file size of a bitmap image (excluding header metadata):
$$\text{File Size (bits)} = \text{Width (pixels)} \times \text{Height (pixels)} \times \text{Colour Depth (bits)}$$
To express the size in bytes:
$$\text{File Size (bytes)} = \frac{\text{Width} \times \text{Height} \times \text{Colour Depth}}{8}$$

Worked Example: Bitmap File Size Calculation
Problem: A digital camera captures an uncompressed bitmap photo with a resolution of $1920 \times 1080$ pixels using a $24\text{-bit}$ True Colour depth. Calculate the file size in:
Total pixelsBitsBytesMebibytes (MiB), rounded to two decimal places.
Step-by-step Solution:
Calculate total pixels:
$$\text{Total Pixels} = 1920 \times 1080 = 2,073,600\text{ pixels}$$
Calculate size in bits:
$$\text{Size in bits} = 2,073,600 \times 24 = 49,766,400\text{ bits}$$
Convert to bytes:
$$\text{Size in bytes} = \frac{49,766,400}{8} = 6,220,800\text{ bytes}$$
(Shortcut: Notice that 24 bits = 3 bytes, so $2,073,600 \times 3 = 6,220,800\text{ bytes}$).
Convert to binary Mebibytes (MiB):
$$\text{Size in KiB} = \frac{6,220,800}{1,024} = 6,075\text{ KiB}$$
$$\text{Size in MiB} = \frac{6,075}{1,024} \approx 5.93\text{ MiB}$$

Image Metadata
When an image file is saved, it contains more than just raw pixel values. It also includes metadata.
Definition: Metadata is data about data. It consists of technical and descriptive parameters stored in the file header.Why Metadata is Essential:A raw bitmap file is simply a continuous stream of binary bits (e.g., 110100101011...).Without metadata, a computer cannot know the grid dimensions (how many pixels make up one horizontal row) or how many bits belong to each pixel.An image of 12 pixels could be $1 \times 12$, $2 \times 6$, $3 \times 4$, $4 \times 3$, $6 \times 2$, or $12 \times 1$. Metadata tells the rendering engine how to reshape the linear bitstream into the correct 2D visual matrix.Examples of Stored Metadata:Image width and height (dimensions in pixels).Colour depth (number of bits per pixel).Image resolution (e.g. 300 DPI).File format / compression type (e.g. BMP, PNG, JPEG).Date and time of creation.Camera settings (focal length, shutter speed, ISO, GPS coordinates).
Written practice and self-review
Define what is meant by metadata in the context of digital images.
Explain why image viewing software requires metadata to display an uncompressed bitmap file correctly, and give two specific examples of metadata stored in an image file.
Write an explanation before checking the theory. Check that each claim answers the question, uses the correct concept and explains why it applies. Discuss uncertain points with a teacher. The structured exercise below checks specific facts; it does not automatically mark this explanation.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Bitmap Image Resolution & Colour Depth (Multiple choice, 25 XP)

**Instructions:**
A bitmap image has dimensions of 100 × 50 pixels and uses an 8-bit colour depth. What is the minimum uncompressed file size in bytes (excluding metadata)?

**Options:**
- **A**: 500 bytes
- **B**: 5,000 bytes
- **C**: 40,000 bytes
- **D**: 50,000 bytes


**Autotest Expectations:**
- **Correct option selected**: `selection_match` -> Expected: `b`

### Exercise 2: Exam-Style Question: Calculating True Colour Palette and File Size (Fill in blank, 35 XP)

**Instructions:**
A digital photograph has a resolution of **400 pixels wide by 300 pixels high** and uses a **24-bit True Colour** depth.

Calculate:

1. The total number of unique colours that can be represented per pixel: [blank_1]
2. The uncompressed file size in **bytes** (excluding metadata): [blank_2]


**Starter Code:**
```text
{"template":"Number of unique colours: [blank_1]\nFile size in bytes: [blank_2]","word_bank":["16777216","360000","2880000","48","65536","45000"]}
```

**Autotest Expectations:**
- **Unique colours and file size in bytes**: `text_exact` -> Expected: `{&quot;blank_1&quot;:&quot;16777216&quot;,&quot;blank_2&quot;:&quot;360000&quot;}`

### Exercise 3: Application: Check the reasoning (Fill in blank, 30 XP)

**Instructions:**
Work out each answer before submitting. Number of colours available with four bits per pixel: Raw bytes for a 64 by 32 image at eight bits per pixel: Double colour depth with the same dimensions: double or halve raw storage?


**Starter Code:**
```text
{"prompt":"Application: Check the reasoning","template":"1. Number of colours available with four bits per pixel: [blank_1]\n2. Raw bytes for a 64 by 32 image at eight bits per pixel: [blank_2]\n3. Double colour depth with the same dimensions: double or halve raw storage? [blank_3]","blanks":[{"id":"blank_1"},{"id":"blank_2"},{"id":"blank_3"}],"word_bank":["16","2048","double","8","32","256","1024","16384","halve"]}
```


