Apple Intermediate Codec

From MultimediaWiki
(Redirected from ICOD)
Jump to navigation Jump to search

Lossy codec used in Final Cut Express HD and iLife ’05

Apple Lists its Features as:

  • Intra Only
  • 4:2:0 color
  • 8-bits per sample

Frame format

Each frame starts with 24-byte header:

 0     version (should be 1)
 1     frame header size (should be 22)
 2- 5  full frame size
 6- 7  frame width
 8- 9  frame height
10-11  frame width (for displaying?)
12-13  frame height(for displaying?)
14     two nibbles, purpose unknown
15     quantiser
16     high nibble is 0 for progressive frame, 3 for interlaced, low nibble is unknown (should be 9 or 14)
17     unknown variables packed in 2:3:3 bits
18     unknown
19     gamma: 4 -> 2.2, 5 -> 2.8, 8 -> 1.0, other values default to 2.(2)
20     unknown
21-23  padding?

It is followed by some tables consisting of 16-bit little-endian tile sizes (in 32-bit words). The table is aligned to 4 bytes.

Tile height is 1 macroblock, tile width is selected so that frame width is divided into <= 32 tiles of the same width (or 16 tiles in case it's not possible).

Tile coding

Tile consists of 4 bands: blocks with 64 luma coefficients, blocks with 32 chroma coefficients, blocks with 192 luma extension coefficients and blocks with 96 chroma extension coefficients. This is done for scalable decoding.

Each band is an array of 16-bit entries.

 A - no skips / skips present (1 bit)
 B - use Rice / ext-exp-Golomb for coeff (3 bits)
 C - code parameter (1 bit)
 if (A == 1) {
 D - use Rice / ext-exp-Golomb for skip (1 bit)
 E - skip parameter (3 bits)
 }
 
 if (!A) {
     for (i = 0; i < num_mbs; i++) {
         for (idx = 0; idx < num_coeffs; idx++)
             dst[scan[idx]] = B ? get_eg(C) : get_rice(C);
 } else {
     for (i = 0; i < num_mbs; i++) {
         idx = 0;
         while (idx < num_coeffs) { //32-196
             idx += (D ? get_eg(E) : get_rice(E)) + 1;
             if (idx == num_coeffs - 1)
                 break;
             dst[scan[idx]] = (B ? get_eg(C) : get_rice(C)) + 1;
         }
     }
 }
 int get_eg(int k)
 {
    val = get_unary();
    return (1 << val + k) - (1 << k) + get_bits(val + k);
 }

Unquantisation is performed as

 val = src[i] >> 1;
 if (src[i] & 1)
     val = -val;
 val = (val * quant_matrix[i] * quant >> 4) + (src[i] & 1)

Tables

Quantisation matrix

 8, 16, 19, 22, 22, 26, 26, 27
16, 16, 22, 22, 26, 27, 27, 29
19, 22, 26, 26, 27, 29, 29, 35
22, 24, 27, 27, 29, 32, 34, 38
26, 27, 29, 29, 32, 35, 38, 46
27, 29, 34, 34, 35, 40, 46, 56
29, 34, 34, 37, 40, 48, 56, 69
34, 37, 38, 40, 48, 58, 69, 83

Luma scan

 0,  4,  1,  2,  5,  8, 12,  9
 6,  3,  7, 10, 13, 14, 11, 15
47, 43, 46, 45, 42, 39, 35, 38
41, 44, 40, 37, 34, 33, 36, 32
16, 20, 17, 18, 21, 24, 28, 25
22, 19, 23, 26, 29, 30, 27, 31
63, 59, 62, 61, 58, 55, 51, 54
57, 60, 56, 53, 50, 49, 52, 48

Luma extension scan

64, 72, 65, 66, 73, 80, 88, 81
74, 67, 75, 82, 89, 90, 83, 91
0, 4, 1, 2, 5, 8, 12, 9
6, 3, 7, 10, 13, 14, 11, 15
16, 20, 17, 18, 21, 24, 28, 25
22, 19, 23, 26, 29, 30, 27, 31
155, 147, 154, 153, 146, 139, 131, 138
145, 152, 144, 137, 130, 129, 136, 128
47, 43, 46, 45, 42, 39, 35, 38
41, 44, 40, 37, 34, 33, 36, 32
63, 59, 62, 61, 58, 55, 51, 54
57, 60, 56, 53, 50, 49, 52, 48
96, 104, 97, 98, 105, 112, 120, 113
106, 99, 107, 114, 121, 122, 115, 123
68, 76, 69, 70, 77, 84, 92, 85
78, 71, 79, 86, 93, 94, 87, 95
100, 108, 101, 102, 109, 116, 124, 117
110, 103, 111, 118, 125, 126, 119, 127
187, 179, 186, 185, 178, 171, 163, 170
177, 184, 176, 169, 162, 161, 168, 160
159, 151, 158, 157, 150, 143, 135, 142
149, 156, 148, 141, 134, 133, 140, 132
191, 183, 190, 189, 182, 175, 167, 174
181, 188, 180, 173, 166, 165, 172, 164

Chroma scan

 0,  4,  1,  2,  5,  8, 12,  9
 6,  3,  7, 10, 13, 14, 11, 15
31, 27, 30, 29, 26, 23, 19, 22
25, 28, 24, 21, 18, 17, 20, 16
32, 36, 33, 34, 37, 40, 44, 41
38, 35, 39, 42, 45, 46, 43, 47
63, 59, 62, 61, 58, 55, 51, 54
57, 60, 56, 53, 50, 49, 52, 48

Chroma extension scan

16, 24, 17, 18, 25, 32, 40, 33
26, 19, 27, 34, 41, 42, 35, 43
0, 4, 1, 2, 5, 8, 12, 9
6, 3, 7, 10, 13, 14, 11, 15
20, 28, 21, 22, 29, 36, 44, 37
30, 23, 31, 38, 45, 46, 39, 47
95, 87, 94, 93, 86, 79, 71, 78
85, 92, 84, 77, 70, 69, 76, 68
63, 59, 62, 61, 58, 55, 51, 54
57, 60, 56, 53, 50, 49, 52, 48
91, 83, 90, 89, 82, 75, 67, 74
81, 88, 80, 73, 66, 65, 72, 64
112, 120, 113, 114, 121, 128, 136, 129
122, 115, 123, 130, 137, 138, 131, 139
96, 100, 97, 98, 101, 104, 108, 105
102, 99, 103, 106, 109, 110, 107, 111
116, 124, 117, 118, 125, 132, 140, 133
126, 119, 127, 134, 141, 142, 135, 143
191, 183, 190, 189, 182, 175, 167, 174
181, 188, 180, 173, 166, 165, 172, 164
159, 155, 158, 157, 154, 151, 147, 150
153, 156, 152, 149, 146, 145, 148, 144
187, 179, 186, 185, 178, 171, 163, 170
177, 184, 176, 169, 162, 161, 168, 160