Alias Sketchbook Pro Multi-Layer TIFF File Format Specification
Written by Ian Ameline
Hosted with kind permission of Ian Ameline of Alias Systems
Alias Sketchbook Pro is a sketching and imaging application that is capable of manipulating and storing multi-layer images, much as Adobe Photoshop does. We decided against using the Photoshop file format for several reasons; It's proprietary, not publicly documented, and very poorly supported by available libraries with commercial software friendly license terms. And it also does not store all the information we wish to store. (Hand drawn layer names, for example.)
TIFF is extremely well supported by the publicly available LibTiff, and it has friendly license terms. TIFF is well documented, broadly supported by other applications, and is nicely extensible. This document assumes the reader is familiar with both LibTiff and the TIFF file format.
Alias Sketchbook Pro TIFF Files
Sketchbook V1.1.1 and earlier stores its layers in a TIFF file using only standard tags that are supported by LibTiff. It does, however hijack some less commonly used tags for its own purposes, but only when the file is clearly identified as an Alias Multi Layer TIFF file in the Software tag.
Later versions of Sketchbook will use a custom tag to store exactly the same data. This tag number is 50784 (decimal), and is registered with Adobe. We call it Alias Layer Metadata. Version 1.2 of Sketchbook will write the metadata into the original HostComputer and Model tags (as described below) as well as the new Alias Layer Metadata tag. On reading, versions of Sketchbook after 1.1.1 will look at the new tag first, and if it is not present, will fall back on the old hijacked tags. Versions Of Sketchbook after V1.2 will write only the new tag. (As of this writing, Sept 27, 2004, the current version of Sketchbook is 1.1.1.)
A Sketchbook layer stack is fairly simple - the layers are all combined with a simple "over" blend equivalent to using an OpenGL blend function of (GL_ONE, GL_ONE_MINUS_SRC_ALPHA).
An Alias Multi-Layer TIFF file consists of a composite image, possibly one or two reduced resolution versions of that composite image, and a layer stack. A layer stack consists of a background color, and an ordered collection of one or more image layers. Each image layer consists of a single 4-channel RGBA image of the layer (the alpha is associated - which is to say that the RGB channels are premultiplied by the alpha channel), and 1 or more auxiliary images. (Each image is stored in its own SUBIFD.) The first auxiliary image for a layer is a hand drawn layer name. Future versions of Sketchbook will store several more single channel auxiliary images for masks, visibility channels etc. The layers in the layer stack are ordered from the bottom of the layer stack to the top.
In the TIFF file, Sketchbook stores a single page - in this image goes the composite of all the visible layers in the layer stack. This image is primarily for the consumption of other applications - Sketchbook ignores this image when reading Alias multi-layer TIFF files. In addition to this single image is a collection of SUBIFDs in which thumbnails and layer images are stored. The first 0, 1, or 2 SUBIFDs (as indicated in a metadata tag on the main image) are reduced resolution versions of the composite image. If present, the first will be a large thumbnail sized version (larger dimension will be 256 pixels). If present, the second will be a roughly screen sized version - this allows an application to quickly load and display a fitted-to-view version of the image while proceeding to read the layers. This is especially useful with very large images. Both of these will be marked as reduced resolution images using the NewSubfileType tag, specifically setting it to FILETYPE_REDUCEDIMAGE. Subsequent SUBIFDs are layer images or auxiliary layer images.
Composite Image Tags
The Software tag will be set to "Alias MultiLayer TIFF V1.1". If this tag is not set like this, Sketchbook will assume it's just an ordinary TIFF, and treat it as such. Note: Because of a rather nasty bug in the Windows file system explorer (it will corrupt all the SUBIFDs if you try to change file metadata like author etc), sketchbook saves the composite image with a strip size of 256 lines. If, on reading, the strip size is other than this, Sketchbook will assume the SUBIFDs and the layers stored in them have been corrupted by this bug in Windows, and ignore them.
"%03d, %03d, %08x, %03d, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000"
The fields are, in order; LayerCount, CurrentLayer, BackgroundColor, ReducedImageCount. The remaining fields are reserved and must be 0.
These fields are defined as follows:
- LayerCount - Integer count of the number of layers - must be greater than 0.
- CurrentLayer - The number (bottom layer = 1) of the current layer.
- BackgroundColor - a 32 bit value encoded as an 8 digit hexadecimal number. The channel ordering is ARGB. (alpha is the most significant byte). Usually ffffffff.
- ReducedImageCount - Integer count of the reduced resolution images. When present, both of the two reduced resolution images are standard in every respect - But their Page Names (on the PageName) are "Thumbnail" and "ScreenSizeProxy" respectively.
The channel ordering of the composite image and the two reduced resolution images is RGBA. The channel ordering of the layer images is BGRA, and they are stored lower-left origin, 8 bit u_int per/channel (32 bit per pixel) with the RGB channels premultiplied by the A channel.
Each layer image has some meta-data stored on it in various tags as follows:
The PageName tag will have an ASCII layer name in it.
"%05.3f, %02x, %1d, %1d, %1d, %d, %d, %d, %d, %d".
The fields are, in order: LayerOpacity, LayerFillColor, LayerVisible, LayerLocked, LayerNameImagePresent, VisibilityChannelCount, MaskLayerCount, Reserved1, Reserved2, Reserved3.
These fields are defined as follows:
- LayerOpacity - floating point number from 0.0 to 1.0. The layer's overall opacity is modulated by this number - 0.0 indicating the layer will be completely invisible, and 1.0 indicating it is fully opaque (where its per-pixel alphas are 1.0).
- LayerFillColor - hex coded 32 bit color value, channel order is ARGB. All pixels outside the bounds of the layer image are assumed to be this color. Usually 0.
- LayerVisible - 0, or 1. Boolean indicating whether the layer is visible or not. (1 = Visible)
- LayerLocked - 0 or 1. Boolean indicating whether the layer is locked or not. With Sketchbook the layer lock locks everything about a layer - it's name, opacity, and all its pixels. (1 = Locked)
- LayerNamePresent -- 0 or 1. Boolean indicating that the next SUBIFD is an image containing a hand-written layer name. (1 = Layer Name image is present in the next SUBIFD.)
- VisibilityChannelCount - Indicates the following n SUBIFDs (after the LayerName) are single channel images with unassociated alpha channels in them.
MaskLayerCount - Indicates the following n SUBIFDs (following the LayerName and 0 or more Visibility Channels) are single channel mask layers.
When present, both the mask and visibility SUBIFDs will have a Model tag on them with Opacity, FillColor, Visible, Locked, and Active fields (and 4 reserved fields) formatted as follows:
"%05.3f, %02x, %1d, %1d, %1d, %d, %d, %d, %d".
The mask and visibility channels are not stored as extra samples on the RGBA layer image for several reasons -- mainly performance. They are often not present, often with different bounds than their corresponding layer image, and are stored as seperate images internally in Sketchbook -- Combining them with the RGBA channels at save time and seperating them at load time would be wasteful both in terms of memory and CPU cycles.
- Reserved1, Reserved2, Reserved3 - reserved, must be 0.
Compression & Other Notes
Alias Sketchbook compresses the composite image, and the reduced resolution images with LZW, and uses ADOBE_DEFLATE for the layer images.
Sketchbook tends to write images in strips of 256 rows. (Except the screen-sized reduced resolution image is written as one strip.)
As discussed above, Sketchbook Version 1.1.1 and earlier use only the HostComputer and Model tags. Version 1.2 will write both a new custom Alias Layer Metadata tag and the old tags for backwards compatibility. All future versions (1.2 and later) will read the new tag first, and if it's not present will fall back on the old tags. Versions of Sketchbook after 1.2 will write only the new custom tag, but will continue to support reading the old tags.
Disclaimer & Copyright
This document is Copyright (C) Alias Systems Corp. Permission is given to reproduce this document whole, and without change.
This document is provided as-is, with no warranty of any kind, and is subject to change without notice.