Suggested Palette (sPLT)
- Status: PNG Specification
- Location: before first IDAT
- Multiple: yes
The suggested-palette chunk, sPLT, grew out of an acknowledgment of
some limitations in PNG's PLTE, tRNS, and hIST chunks. I have already
noted that PLTE is allowed only in palette, RGB, and RGBA images and
that hIST is allowed only in images with PLTE; I also noted that tRNS
is disallowed in images with alpha channels, which rules out the use
of PLTE plus tRNS as a suggested gray/alpha or RGBA palette. sPLT
eliminates these restrictions by merging all three of the older chunks
into a general-purpose, suggested-RGBA-palette-plus-histogram
chunk. In addition, sPLT may contain any number of entries (as long as
it doesn't exceed the maximum chunk-size limit of two gigabytes); its
entries may have either 8-bit or 16-bit sample depths; and multiple
sPLT chunks encoding different suggested quantizations are allowed. A
palette-based image may even have an sPLT chunk, perhaps representing
a reduced palette for a particular web browser. The format of sPLT, given in
Table 11-3, is straightforward.
Field |
Length and Valid Range |
Palette name |
1-79 bytes (Latin-1 text) |
Null separator |
1 byte |
Sample depth |
1 byte (8 or 16) |
Red value #1 |
1 byte (0-255) or 2 bytes (0-65,535) |
Green value #1 |
1 byte (0-255) or 2 bytes (0-65,535) |
Blue value #1 |
1 byte (0-255) or 2 bytes (0-65,535) |
Alpha value #1 |
1 byte (0-255) or 2 bytes (0-65,535) |
Relative frequency #1 |
2 bytes (0-65,535) |
... |
... |
The number of sPLT entries is implicitly given by the size of the chunk and
the sample depth; in the more common case of 8-bit samples, it is obtained
by dividing the chunk size, less the length of the palette name and the two
subsequent bytes, by six. Entries are required to appear in decreasing
order of frequency, but there is no requirement that all of them be different
nor that all of them be used by the image. Furthermore, opaque images may
include nonopaque sPLT entries, grayscale images may include colored
entries, and the sample depth of sPLT is independent of that of the image.
Unlike the suggested practice for PLTE in RGBA images, the red, green, and
blue values in sPLT are neither premultiplied by the alpha values nor
precomposited against a background color. An encoder would still have to
inspect every pixel if it wanted to compute an optimal palette for display
of an RGBA image against a patterned background, but sPLT would enable a
statistical approach based on the background image's own histogram in
that case. And for solid backgrounds, sPLT provides the means to build
an optimal palette regardless of the choice of background color.
As with the hIST chunk, frequency values are scaled to the range 0-65,535
and therefore are likely to be approximate. Inflating ``important'' colors
based on the image's subject matter is allowed in sPLT, too. But whereas hIST
requires a 0 frequency to correspond exactly to 0 pixels, sPLT allows
the 0 value to represent infrequently used or unimportant colors. If all
of the frequency values are 0, however, the histogram is undefined.
Note that multiple sPLT chunks are required to have different palette names.
|