Understanding Road-Pizza Compression

Map of the region around Blogorershchensk

While a good chunk of my QuickDraw Viewer code just dispatches the rendering of images to Core Graphics, the underlying display system of Mac OS X, there is one type of images I could not dispatch this way: Road-Pizza.

Now even if you used the early versions of QuickTime on the Mac, you probably never heard this term, the official name of this codec was Apple Video, and only it’s FourCC leaked its internal name: RPZA. Implementing a decoder for this code was interesting, because it gives a glimpse into computing before the use of the Discrete Cosine Transform (DCT), which is the basis of JPEG, MPEG, etc.

Despite the Apple Video name, RPZA is fundamentally a still image compression scheme, the only feature that is relevant for video encoding is the ability to omit a block if is the same as in the previous frame. You can see this as a very rough form of alpha-channel. The big difference compared to classic QuickDraw image compression is that first, the compression can be lossy, and second that the pixels are organised in 4×4 pixel blocks, so decoding is done by block, not by scan-line. Decoding does not require any floating point arithmetic: floating point units (FPU) were still optional on many machines.

A block can be represented in four ways:

  • Skip (transparent)
  • One uniform colour
  • 16 pixels using a 2 bit palette
  • 16 direct RGB555 pixels

The encoding is designed in such a way that in the worst case – all 16 pixels expressed in RGB555 – the file is not bigger than a regular 16 bit/pixel stream. This is achieved by using the fact that the first bit of each pixel is unused: with 5 bits for each colour channel, 15 bits are needed, the top bit is not used. So the encoding uses two of these top bits to select which representation is needed. If the first top bit is zero, the first 4 bytes are two RGB555 colours with their top bits used for control, the top bit of the second colour controls if is direct colour bits and there 14 more RGB555 pixels to read, or the palette case, in which case 16, 2-bit colour-table entries follow.

If the first top bit is one, then the following two bits represent an opcode, followed by a three bit value that represents the number of affected blocks this opcode affects. The following bytes are the parameters for the operation: nothing for the skip operation, one colour for the uniform colour operation, two + palette data in the palette block.

The palette mode is interesting, as there are only two colours for a two bit palette, the two missing colours are generated linearly from the present ones. So for instance, if the two colours were black and white, the two other colours in the palette would be 33% and 66% gray. This is very similar to the used in graphic cards.

2 thoughts on “Understanding Road-Pizza Compression”

  1. Interestingly, this format can be interpreted by ffmpeg. I just tried to display a RPZA video with timg (terminal image viewer) and its ffmpeg-based video decoder could deal with it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.