# Windows Imaging Component Codec Extensibilty Sample

This sample demonstrates how to create a custom CODEC using the Windows Imaging Component (WIC) of Vista and the Windows Presentation Foundation (WPF).

## About the AIT CODEC

The AIT CODEC was developed to keep it as simple as possible while demonstrating the extensibility of the Windows Imaging Component of Vista and Windows Presentation Foundation. It was also developed to represent data as if this were a production level CODEC, so concepts such as image blocks are similar to other formats, such as PNG.

Within the AIT CODEC, a block takes the form of:

``

    struct AIT_BLOCK
    {
       // Used to distinguish the type of block (first 3 bytes are ASCII,
       // last byte must be 0)
       uint8_t name[4];

       // Specifies which frame in the image this data should be applied to.
       uint32_t frame_number;

       // Gives the number of bytes in the data section of the block.

       uint32_t size;
       // Gives the raw data of the block must
       be interpreted based upon the name of the block

       uint8_t data[size];
    };

There are 6 types of blocks that the AIT CODEC support -- AIT, COL, FRA, PAL, PRE, THU

### AIT Block

This block must be the first block in the file and must be specified only once. It may be regarded as the header of AIT files.
The data section of this block takes the form:

``

    struct AIT_BLOCK_DATA
    {
       // number of frames in the images(permitted to be 0)
       uint32_t num_frames;
    };

### COL Block

This block specifies a color context to be applied either globally to the image (when AIT_BLOCK.frame_number == 0xFFFFFFFF) or to a frame (when AIT_BLOCK.frame_number != 0xFFFFFFFF). The field AIT_BLOCK.size specifies the size in bytes of the ICM profile to be used in this color context. The data section is the value of those bytes.

### FRA Block

This block specifies the bitmap data of a frame. The AIT_BLOCK.frame_number must be a value in the range [0, N) where N is the number of frames in the image (as specified in the AIT block).
The data section of this block takes the form:

``

    struct FRA_BLOCK_DATA
    {
      BITMAP_SOURCE_DATA bitmap_source;
    };

BITMAP_SOURCE_DATA takes the form:

``

    struct BITMAP_SOURCE_DATA
    {
        // Width dimension of the image
        uint32_t width;

        // Height dimension of the image
        uint32_t height;

        // Resolution (pixels/inch) of image in X direction
        double dpi_x;

        // Resolution (pixels/inch) of image in Y direction
        double dpi_y;

        // The number of bytes needed to the number of bytes needed to encode
        // one scan line of the bitmap
        uint32_t stride;

        // The GUID of the pixel format of this bitmap valid values include
        // those recognized in wincodec.h (GUID_WICPixelFormat*)
        GUID pixel_format;

        // All data values one scanline at a time beginning at the top-most
        //  scanline and continuing to the bottom-most scanline
        uint8_t bitmap_data[stride * height];
    };

(Here, a double is an IEEE 64-bit floating-point number and GUID is 16 bytes used to uniquely identify an object.)
A FRA block, therefore, is simply the BITMAP_SOURCE_DATA needed to represent that frame.

### PAL Block

This block specifies a palette to be either applied to the image as a whole or to an individual frame (using the same logic as outlined in the COL block).
The data section of this block takes the form:

``

    struct PAL_BLOCK_DATA
    {
       // Number of colors in this palette (must be > 0)
       uint32_t num_colors;

       // Gives those colors as WICColors (defined in wincodec.h)
       WICColor colors[num_colors];
    };

### PRE Block

This block specifies a preview bitmap that may be applied to the image as a whole (AIT_BLOCK.frame_number must equal 0xFFFFFFFF). Its data section is simply a BITMAP_SOURCE_DATA (similar to a FRA block).

### THU Block

This block specifies a thumbnail bitmap the may be applied to the entire image or a single frame (as specified in the save rules as COL’s). Its data section is simply a BITMAP_SOURCE_DATA (similar to a FRA block).