flic 0.1.6

Autodesk Animator FLI and Autodesk Animator Pro FLC file encoder and decoder.
Documentation
//! Codec for chunk type 14 = FLI_ICOLORS.

use std::cmp::min;

use ::RasterMut;

/// Magic for a FLI_ICOLORS chunk.
///
/// This is likely to be used by very old development FLICs only.
pub const FLI_ICOLORS: u16 = 14;

/// Animator initial colour map.
const INIT_CMAP: [u8; 3 * 256] = [
    /* 32 level grey scale */
      0,  0,  0,      8,  8,  8,     16, 16, 16,     24, 24, 24,
     32, 32, 32,     40, 40, 40,     48, 48, 48,     56, 56, 56,
     64, 64, 64,     72, 72, 72,     80, 80, 80,     88, 88, 88,
     96, 96, 96,    104,104,104,    112,112,112,    120,120,120,
    132,132,132,    140,140,140,    148,148,148,    156,156,156,
    164,164,164,    172,172,172,    180,180,180,    188,188,188,
    196,196,196,    204,204,204,    212,212,212,    220,220,220,
    228,228,228,    236,236,236,    244,244,244,    252,252,252,
    /* A hand threaded 6x6x6 rgb cube */
    252,204,204,    252,252,204,    204,252,204,    204,252,252,
    204,204,252,    252,204,252,    252,156,156,    252,204,156,
    252,252,156,    204,252,156,    156,252,156,    156,252,204,
    156,252,252,    156,204,252,    156,156,252,    204,156,252,
    252,156,252,    252,156,204,    252,108,108,    252,156,108,
    252,204,108,    252,252,108,    204,252,108,    156,252,108,
    108,252,108,    108,252,156,    108,252,204,    108,252,252,
    108,204,252,    108,156,252,    108,108,252,    156,108,252,
    204,108,252,    252,108,252,    252,108,204,    252,108,156,
    252, 60, 60,    252,108, 60,    252,156, 60,    252,204, 60,
    252,252, 60,    204,252, 60,    156,252, 60,    108,252, 60,
     60,252, 60,     60,252,108,     60,252,156,     60,252,204,
     60,252,252,     60,204,252,     60,156,252,     60,108,252,
     60, 60,252,    108, 60,252,    156, 60,252,    204, 60,252,
    252, 60,252,    252, 60,204,    252, 60,156,    252, 60,108,
    252, 12, 60,    252, 12, 12,    252, 60, 12,    252,108, 12,
    252,156, 12,    252,204, 12,    252,252, 12,    204,252, 12,
    156,252, 12,    108,252, 12,     60,252, 12,     12,252, 12,
     12,252, 60,     12,252,108,     12,252,156,     12,252,204,
     12,252,252,     12,204,252,     12,156,252,     12,108,252,
     12, 60,252,     12, 12,252,     60, 12,252,    108, 12,252,
    156, 12,252,    204, 12,252,    252, 12,252,    252, 12,204,
    252, 12,156,    252, 12,108,    204, 12, 60,    204, 12, 12,
    204, 60, 12,    204,108, 12,    204,156, 12,    204,204, 12,
    156,204, 12,    108,204, 12,     60,204, 12,     12,204, 12,
     12,204, 60,     12,204,108,     12,204,156,     12,204,204,
     12,156,204,     12,108,204,     12, 60,204,     12, 12,204,
     60, 12,204,    108, 12,204,    156, 12,204,    204, 12,204,
    204, 12,156,    204, 12,108,    156, 12, 60,    156, 12, 12,
    156, 60, 12,    156,108, 12,    156,156, 12,    108,156, 12,
     60,156, 12,     12,156, 12,     12,156, 60,     12,156,108,
     12,156,156,     12,108,156,     12, 60,156,     12, 12,156,
     60, 12,156,    108, 12,156,    156, 12,156,    156, 12,108,
    108, 12, 60,    108, 12, 12,    108, 60, 12,    108,108, 12,
     60,108, 12,     12,108, 12,     12,108, 60,     12,108,108,
     12, 60,108,     12, 12,108,     60, 12,108,    108, 12,108,
     60, 12, 12,     60, 60, 12,     12, 60, 12,     12, 60, 60,
     12, 12, 60,     60, 12, 60,    108, 60, 60,    108,108, 60,
     60,108, 60,     60,108,108,     60, 60,108,    108, 60,108,
    156, 60, 60,    156,108, 60,    156,156, 60,    108,156, 60,
     60,156, 60,     60,156,108,     60,156,156,     60,108,156,
     60, 60,156,    108, 60,156,    156, 60,156,    156, 60,108,
    204, 60, 60,    204,108, 60,    204,156, 60,    204,204, 60,
    156,204, 60,    108,204, 60,     60,204, 60,     60,204,108,
     60,204,156,     60,204,204,     60,156,204,     60,108,204,
     60, 60,204,    108, 60,204,    156, 60,204,    204, 60,204,
    204, 60,156,    204, 60,108,    204,108,108,    204,156,108,
    204,204,108,    156,204,108,    108,204,108,    108,204,156,
    108,204,204,    108,156,204,    108,108,204,    156,108,204,
    204,108,204,    204,108,156,    204,156,156,    204,204,156,
    156,204,156,    156,204,204,    156,156,204,    204,156,204,
    156,108,108,    156,156,108,    108,156,108,    108,156,156,
    108,108,156,    156,108,156,     12, 12, 12,     60, 60, 60,
    108,108,108,    156,156,156,    204,204,204,    252,252,252,
    /* 3 empty slots */
    252, 88, 12,    156, 28, 20,    144,144,252,
    /* Colours the system would like to use for interface */
      0,  0,  0, /* menu black */
     88, 88, 88, /* menu grey */
    152,152,152, /* menu light */
    208,208,208, /* menu bright */
    252,  0,  0, /* menu red */
];

/// Decode a FLI_ICOLORS chunk.
pub fn decode_fli_icolors(dst: &mut RasterMut) {
    let start = 0;
    let end = min(dst.pal.len(), INIT_CMAP.len());

    dst.pal[start..end].copy_from_slice(&INIT_CMAP[start..end]);
}