Sprite Image Format (SIF) file format Specification

Version 2.0 (7/23/2006)


Section 1: Revision History
Section 2: Introduction
Section 3: File Format
  Section 3.1: Header
  Section 3.2: Animation Segment
  Section 3.3: Graphical Segment
  Section 3.4: Palette Segment
Section 4: Credits


Revision History
7/23/2006: Rewrite version 2.0
-Major structural changes to file format
-Conversion of this document to HTML

7/25/2004: Update
-Expanded header and added Huffman compression for image data
-Removed sample code. (Sorry guys!)

7/14/2004: Original draft

Introduction
The goal of the SIF file format is to provide an open and standard format for storing 2D game sprites and associated animation data, enabling the sharing of these sprites between game developers and the creation of open libraries of ready-made sprite animations.

The SIF file format is intended to be an encapsulated sprite data and image storage for generic use. SIF files contain all of the image data required by the sprite along with metadata describing what sequence the images need to be displayed to create animations, including delays, sizes and X/Y position adjustments for each rectangular frame image.

The basic file is divided into three portions:
  -A very minimal header segment (16 bytes)
  -A structure segment defining data for recreating the animation sequences
  -An image segment which contains a list of compressed bitmap frames (compression optional)
  -An optional list of palettes that are referenced by images with either 16 or 256 colors


File Format


What follows is a detailed description of each of the three file portions described above

Header Segment
The header segment consists of 16 bytes:
WORD	"SF" (Denotes file type).This value is -21677 (signed) or 21676 (unsigned). 

BYTE	Version number. The contents of this document only apply to version "2".

BYTE	Flags. As of version 1 there are no flags. This value should be 0.

DWORD	Offset to the Animation Segment. This allows for an arbitrary amount of
	additional header to be added at a later date, or as a means to include
	application-specific data within the file.

DWORD	Offset to the Image segment. If all you're interested is loading the image
	data, jump to this offset to skip the structure segment.

DWORD	Offset to the Palette Segment, if any. A value of 0 indicates no Palette segment.


Animation Segment
The Animation Segment contains a set of nested structures that define ACTIONS, DIRECTIONS and SEQUENCES. For example, a spritee may have three ACTIONS: Walking, jumping and shooting. For each ACTION, there may be two DIRECTIONS: Facing left or right. Each of these DIRECTIONS will then have a SEQUENCE of frames that determine which frames of animation to show.

In a nutshell, the data takes the form:
WORD   Number_of_actions_defined - 1 (eg: Actions 0 to this_value)

	WORD    Number_of_directions_defined - 1 (for Action 0)

		WORD    Number of frames defined (For Action 0, Direction 0)

			WORD	Frame ID for Action 0, Direction 0, Image 0
			WORD	Just temp storage for internal use. Should be 0
			WORD	Frame lag value
			DWORD   Hotspot X relative to upper left corner
			DWORD   Hotspot Y relative to upper left corner

			WORD	Frame ID for Action 0, Direction 0, Image 1
			WORD	Just temp storage for internal use. Should be 0
			WORD	Frame lag value
			DWORD   Hotspot X relative to upper left corner
			DWORD   Hotspot Y relative to upper left corner

			(More images as required)

		WORD    Number of frames defined (For Action 0, Direction 1)

			(Images as described above)

		(More directions as required)

	WORD    Number_of_directions_defined - 1 (for Action 1)

		(Directions as described above)

			(Images as described above)

	(More actions as required)


Graphical Segment
The Graphical Segment contains a list of bitmaps, which the Animation Section references. This is a simple 1D array with basic data for each frame:
WORD	Number of frames in list

For each frame:

WORD	Flags (See below)
WORD	Pointer to Alpha Channel mask image (Only used if flag bit 3 set)
WORD	Default Palette to use (if 4bpp or 8bpp)
BYTE	Color Depth (Bits per pixel)
DWORD	24-bit color to be treated as "Transparent"
DWORD	Height of frame
DWORD	Width of frame
DWORD	Length of bitmap data OR compressed stream
STRING	Bitmap data or compressed stream
FLAGS has the following values and meanings:
Bit	Meaning
---	-----------
 0	Image has transparency
 1	Auto-Generate transparency mask
 2	Image has Alpha transparency
 3	Use seperate Alpha mask (See note 1)
 4	Custom Palette appears after bitmap data (Ignore palette index, use custom)
 5	RESERVED
 6	RESERVED
 7	RESERVED

Flag's High Byte is a value 0 to 255 indicating what type of compression, if any,
has been applied to the data stream:

 0	No compression. Data stream is raw Bitmap data.
 1	Image is RLE compressed (Size matches color depth)
 2	Image is Huffman compressed
 3	Image is LZW (GIF) compressed (See Note 2)
 4	Image is PNG compressed

(Additional image/compression formats may be added later)
Note 1: Bit 3 is only relevant if bit 2 is set. If 2 is set but 3 is not, then the progam should assume that the 4th byte in the 32bpp image is a 8-bit alpha channel. If the image is not 32bpp but bit 2 is set and bit 3 clear, then the program should ignore request for alpha channel support.

Note 2: LZW is only 'sane' to use on 8-bit streams, otherwise the lookup table gets difficult to deal with. If LZW compression is specified, then it is applies only to 8, 24 or 32bpp images. For 24 and 32bpp cases, LZW compression is applied once each to Alpha, Red, Green and Blue channels (in that order).

Only one type of compression is supported at a time, so no Huffman compressing of PNG files etc!

Supported color depths:
1bpp	(Monochrome)
4bpp	(16 color palette)
8bpp	(256 color palette)
16bpp	(RGB565)
24bpp	(RGB888)
32bpp	(ARGB8888)


Palette Segment
The file may contain a list of palettes for use by any image.
WORD	Number of Palettes in collection

For each Palette:

BYTE	Color depth for each palette entry (only 16, 24 or 32 allowed, but no alpha with 32)
BYTE	Number of colors defined
STRING	List of WORD or DWORD colors
Credits
Original SIF file format specification by Smidge204 (Smidge204@juno.com)