GIF Interlacing Explained: The Four-Pass Scheme

GIF interlacing is a technique designed to progressively render an image over slow connections by reorganizing the order in which horizontal scan lines are transmitted and displayed. Instead of drawing the image sequentially from top to bottom, an interlaced GIF divides all horizontal pixel rows into four distinct passes of increasing density. This allows a decoder or web browser to quickly display a low-resolution silhouette of the entire image and progressively sharpen the details as subsequent passes arrive.

The Mechanics of the Four Passes

In a standard, non-interlaced GIF, rows are stored sequentially from row 0 through row N - 1 (where N is the image height). In an interlaced GIF, the rows are extracted and stored using a fixed mathematical pattern across four passes:

Decoding and Display

When a decoder renders an interlaced GIF progressively, it does not leave empty scan lines between passes. Instead, it temporarily duplicates each decoded row into the empty rows beneath it:

  1. After Pass 1: Each line is repeated down 7 times (occupying an 8-pixel tall band).
  2. After Pass 2: Each line is repeated down 3 times (occupying a 4-pixel tall band).
  3. After Pass 3: Each line is repeated down 1 time (occupying a 2-pixel tall band).
  4. After Pass 4: The exact pixel rows are written directly without row duplication, revealing the final output.

This interlacing scheme ensures that all horizontal scan lines are visited exactly once across the four passes, restructuring the transmission order entirely without adding any extra pixel overhead.