The Packed with a Planar

In computer graphics, Packed and Packed are the two main ways of storing pixel data.

Packed: Each pixel is stored consecutively in memory. If each pixel has 16 bits, each pixel is stored in memory as two consecutive 8-bit bytes. If each pixel has four bits, then every two pixels are stored in memory in one byte, one pixel per half byte. If a pixel has more than one channel, the channels are interleaved in memory, as in RGB with three channels:

Planar: The composition of individual pixels, not stored consecutively together. It’s split in different bit planes of memory. If the pixels are single-channel, Planar can also be used, which consists of bits of a single pixel and distributes them in different planes. If pixels are multi-channel, it is common to store each channel in a different plane (which can be understood as different blocks of memory), such as RGB, if Planar:

The difference between Packed and Planar

Take RGBI in unconventional RGB format as an example:

RGBI is not composed of R, G and B channels. It is bit-based, and every 4 bits makes up an RGBI, with a total of 24 = 16 colors to choose from. RGBI’s color palette is as follows:

If four RGBI pixels are represented by Packed, its memory structure may be as follows:

Each half byte represents a pixel. The four RGBI pixels are stored in memory as two consecutive bytes.

If the four RGBI pixels are Planar, their memory structure may be as follows:

Represented by 4 planes, the 4 bits of an RGBI are split into different planes. The four RGBI pixels are stored in memory as four discrete bytes. As can be seen, Planar usually needs more memory than Packed.

The advantages and disadvantages of Packed and Planar

Packed’s advantage of course lies in saving more memory space.

Planar’s advantages:

  • Pixel data can be accessed in parallel. In the case of insufficient memory bandwidth, Planar is obviously superior to Packed. For YUV, Planar, compared with Packed, can access Y, U and V in parallel. It takes only 1/3 of the time to access a YUV pixel.

  • Planar switches bit depth even faster: it can quickly enlarge or shrink the palette by adding or discarding planes. For example, when 4 planes become 5 planes, the number of colors per pixel becomes 25 = 32.

  • When the number of bits representing pixels is not the power of 2, Planar has higher efficiency in space and time than Packed. For example, in 3-bit RGB (every 3 bits represents a pixel, and the optional colors of a pixel are 23 = 8).

    • If thePlanarYou only need 3 planes.
    • If thePacked, can be implemented in two ways:
      • Allowing pixels across byte boundaries: Increased complexity of memory addressing and unpacked pixels, resulting in increased time consumption.
      • Padding: only two pixels are stored in each byte, consuming 6 bits. Two 2bits are reserved for unused use, resulting in increased space consumption. RGB555 does just that.

The resources

Packed pixel

Planar

List of monochrome and RGB color formats

RGB file: Packed or Planar?