KISS General Specification: CEL

5. Details of Cel files

A cel file is a binary file. The modern CEL file format contains a 32-byte header. See Table 5-1.
A cel is an image that is composed of pixels, arranged in rows. Each pixel represents a color in one of two basic forms: Palette-based and Color-based.

Pixel Formats

There are two pixel formats that can be used in cels. Each format specifies where the colors for each pixel come from:

Palette-based

In a palette-based image, a pixel is an index into a palette of colors. This index can be 4 or 8 bits in size, depending on the size of the palette. A 4-bit pixel can index 16 colors while an 8-bit pixel can index 256 colors.

Color-based

In a color-based image, each pixel contains all the color data so a palette is not needed.
32-bit colors also include what is known as an "alpha" channel. The "alpha" channel controls the translucency of the pixels and ranges from 0 to 255. A translucency of 0 means that the pixel is completely transparent to the background while a translucency of 255 means the background is completely hidden.

Translucency and Transparency

There are two terms associated with pixel art that are applicable to KiSS cels:

Translucency

A pixel that is translucent allows the background to "bleed" through, like looking through a stained-glass window. The background is visible, but it is colored by the translucent pixel in front of it.

Transparency

A pixel that is transparent allows the background to show through, like a clear windowpane. "Transparent as glass".
In palette-based cels, pixels that are 0 are treated as transparent pixels. That means that any cel allows the background to show through where the cel's pixels are 0, making the cel look like a cut-out.
With color-based pixels (32-bit), a pixel with an "alpha" channel of 0 is considered transparent.

Mouse Clicks and Transparency

Transparency also affects where in a cel a mouse click can be "seen". Clicking in a transparent section of a cel causes the click to go through that cel and to whatever is underneath the cel. For 32-bit pixels, the "alpha" channel must be set to 0 to allow a mouse click to go through to what lies beneath.

Cel File Format

Table 5-1: Modern CEL Header block
Offset
(in bytes)
Size
(in bytes)
Contents
+04 Identifier 'KiSS' ( 4Bh 69h 53h 53h )
+41 Cel file mark (the type of cel):
  • 20h = Palette-based cel, colors come from a palette.
  • 21h = Color-based cel, each pixel in the cel is a 32-bit color with alpha (transparency) control.
+51 bits per pixel:
  • 4: palette-based image (16 colors per pixel in a palette)
  • 8: palette-based image (256 colors per pixel in a palette)
  • 32: color-based image (16,777,216 colors per pixel, no palette)
+62 Reserved. Must be set to 0.
+82 Width ( 1 ... XMAX )
(+8 = low byte, +9 = high byte)
+102 Height ( 1 ... YMAX )
(+10 = low byte, +11 = high byte)
+122 X-offset ( 0 ... XMAX )
(+12 = low byte, +13 = high byte)
+142 Y-offset ( 0 ... YMAX )
(+14 = low byte, +15 = high byte)
+1616 Reserved. Must all be 0.
+32...Pixel data, ordered by rows. See Remarks for details.

Remarks

Cel Positions

Cels declared in the same object are aligned at the top left corner. X,Y-offsets are the offsets from this alignment point.

Pixel Data

The format of the pixels in a cel depends on whether the cel is palette-based or color-based.
The width of a cel image (as specified in the header) indicates how many pixels wide the image is. The height of a cel image (as specified in the header) indicates how many rows high the image is.

Pixel data order (4 bits/pixel)

With 4 bits per pixel, each byte in a cel row contains 2 pixels. In the situation where the number of pixels is odd, the remaining 4 bits are set to 0.
Table 5-2: 4-bit pixel layout
Byte 0 Byte 1 Byte 2 Byte N
7654 3210
pix0 pix1
7654 3210
pix2 pix3
7654 3210
pix4 pix5
7654 3210
pixN 0000

Pixel data order (8 bits/pixel)

With 8 bits per pixel, each byte in a cel row contains 1 pixel.
Table 5-3: 8-bit pixel layout
Byte 0 Byte 1 Byte 2 Byte N
76543210
pixel 0
76543210
pixel 1
76543210
pixel 2
76543210
pixel 3

Pixel data order (32 bits/pixel)

With 32 bits per pixel, each pixel in a cel row uses 4 bytes.
Table 5-4: 32-bit pixel layout
Byte 0 Byte 1 Byte 2 Byte 3
76543210
blue
76543210
green
76543210
red
76543210
alpha
The "alpha" channel controls the translucency of the pixel, which determines how much of the background "bleeds" through the pixel. An "alpha" of 0 means completely transparent while an "alpha" of 255 means completely opaque.
32-bit cels are clickable at any point where alpha is greater than 0.
"Ghosted" cels are the exception.

Old File Format

If the top 4-byte identifier is not 'KiSS', the file format is as follows:
Table 5-5: Old format CEL Header block
Offset
(in bytes)
Size
(in bytes)
Contents
+02 Width ( 1 ... XMAX )
(+0 = low byte, +1 = high byte)
+22 Height ( 1 ... YMAX )
(+2 = low byte, +3 = high byte)
+4...Pixel data, ordered by rows. Always 4-bit pixel data.