Tes2Mod:Image formats/CIF

CIF files are slightly more complicated than IMG files, because CIF files were designed to support multiple animated images.  That is to say, each contained image is an animation of 1 or more frames.  SHOK00C6.CIF, for example, contains a single 6-frame image.  Most CIF files contain images of only a single frame.  

Single-frame CIF Files
The basic format of a single-frame CIF file is a contiguous list of ImgFile structures.  In essence one merely reads the contained elements one after another until the reaching the end of the file.  Since there is no master header indicating the count or sizes of contained images, there is no way to know how many ImgFile structures are so contained without reading the entire file.  Since each ImgFile structure does posses her own ImgHeader structure, one can skip elements by reading an ImgHeader and skipping forward ImgHeader.DataLength bytes until one has reached the element of interst.  The ImgFile elements are stored in frame-ascending order; this is to say the first ImgFile is to be displayed before the second ImgFile when animated.  

FACES.CIF
FACES.CIF is actually an RCI File.

Multi-frame CIF Files
Multi-frame CIF Files are a tad more complex because of the animation frames for each contained image.  For example, "FRST00C6.CIF" contains a single image, but that image is an animation composed of 6 frames.  Again, we will start with the easiest and move onwards in complexity.  

Magic Spell CIF Files
The Magic Spell CIF files are the easiest to parse.  They are identical to the above Single-frame CIF Format, except all contained images are to be interpreted as animation frames of a single image.  For example, the 6 images of FIRE00C6.CIF are to be considered a single image with 6 distinct frames of animation.  

The following files are Magic Spell CIF Files: 
FIRE00C6.CIF
FRST00C6.CIF
MJIC00C6.CIF
POIS00C6.CIF
SHOK00C6.CIF

Weapon CIF Files
The various weapon CIF files enjoy a slightly expanded format to accommodate the animation frames defining the various images.  The standard format (with exception noted below) consists of a single ImgFile (the "wielded" image), immediately followed by a contiguous list of one or more Animation structures (one for each different animation, such as the various "attack" animations).  Each Animation structure begins with an AnimationHeader structure, immediately followed by the AnimationPixelData which contains the PixelData for each frame implied by the AnimationHeader.  

The overall anatomy of a Weapon CIF File is straight-forward.  


Animation
An Animation structure begins with an AnimationHeader structure, immediately followed by the PixelData which compose the individual frames for the animation.  

AnimationHeader


Notably, there is no Compression field present.  The pixel data for each frame is assumed to be compressed as per RleCompressed.

AnimationPixelData
This is a contiguous list of PixelData structures (each an array of UInt8).  The length of each, except the last, is determined by comparing the elements of the AnimationHeader.FrameDataOffsetList.  The length of the last frame's PixelData is simply the remainder;  AnimationHeader.TotalSize - AnimationHeader.FrameDataOffsetList[   ] .  Since only positive values within the FrameDataOffsetList are valid offsets, and since animations are not required to have all 31 frames, care must be taken to determine  .  It should also be noted that while the frames are to be displayed in the order they are presented in the FrameDataOffsetList, they are not required to be stored to disk in that order; This is to say that FrameOffsetList[ 2 ] may have a smaller value than FrameOffsetList[ 0 ].  Editors should store the actual PixelData in frame-ascending order (store Frame1 before Frame2), but should be prepared to accept unsorted offsets in FrameDataOffsetList.  

The following files are Weapon CIF Files: 
WEAPON00.CIF
WEAPON01.CIF
WEAPON02.CIF
WEAPON03.CIF
WEAPON04.CIF
WEAPON05.CIF
WEAPON06.CIF
WEAPON07.CIF
WEAPON08.CIF
WEAPON10.CIF
WEAPON11.CIF
WEAPO101.CIF
WEAPO102.CIF
WEAPO104.CIF
WEAPO105.CIF
WEAPO106.CIF
WEAPO107.CIF
WEAPO108.CIF

WEAPON09.CIF
WEAPON09.CIF requires special handling because this file contains the bow animations, which do not posses a "wielded" image.  This means there is no root ImgFile structure at the start of the file; it is composed of merely a contiguous list of Animation structures.