Apple Pixlet Codec

From MultimediaWiki
Jump to navigation Jump to search

Pixar/Apple Pixlet codec. Reportedly based on a wavelet transform and encodes only I-frames. FFmpeg have open source decoder. This codec was designed as an editing format and is rarely used for media distribution.

Frame Format

Frame Header

All values are 32-bit big-endian words.

  0- 3  -- frame size
  4- 7  -- version, supposed to be 1
  8-11  -- ???
 12-15  -- should be 0x01000000
 16-19  -- ???
 20-23  -- width
 24-27  -- height
 28-31  -- number of levels (should be 4)
 32-35  -- ???
 36-39  -- some number * 1000
 40-43  -- coded planes size?

Each plane starts with (level*2) words that contain scaling parameters used in wavelet reconstruction (horizontal/vertical) multiplied by 1000000 followed by lowpass subband and (level*3) highpass subbands.

Lowpass subband coding

Decoding order:

  • top left pixel (as 16-bit BE, no special coding)
  • top row (without the first pixel)
  • left column (without the first pixel)
  • the rest of pixels

After decoding pixel data is top+left predicted, i.e. dst[x][y] += dst[x-1][y] + dst[x][y-1];

Coefficients are decoded as adaptive Rice codes in form of val, [skip]:

 flag = 0;
 rparam      = 3;
 quant       = 120;
 max_length  = 14;
 max_zlength = 
 while (!done) {
   nbits = log2((rparam >> 8) + 3);
   if (nbits > max_length)
     nbits = max_length;
   if (show_bits(8) == 0xFF) {
     skip_bits(8);
     val = get_bits(16);
   } else {
     pfx = show_unary(); // like 111110 -> 5
     val = ((1 << nbits) - 1) * pfx + get_bits(nbits) - 1;
   }
   val += flag;
   if (val & 1)
     *dst++ = -((val + 1) >> 1);
   else
     *dst++ =   (val + 1) >> 1;
 
   rparam += quant * (val - (rparam >> 8));
   flag = 0;
 
   if (rparam * 4 > 0xFF && dst < dst_end) {
     nbits = log2(rparam) + ((rparam + 8) >> 5) - 24;
     if (nbits > max_zlength)
       nbits = max_zlength;
     if (show_bits(8) == 0xFF) {
       skip_bits(8);
       val = get_bits(16);
     } else {
       pfx = show_unary(); // like 111110 -> 5
       val = ((1 << nbits) - 1) * pfx + get_bits(nbits) - 1;
     }
     rparam = 0;
     if (val <= 0xFFFE)
       flag = 1;
     dst += val;
   }
 }

Highpass subbands coding

Header:

  0- 3 -- some negative value
  4- 7 -- some positive value
  8-11 -- some parameter
 12-15 -- some parameter 2
 16-19 -- 0xDEADBEEF

Coefficients decoding is done similarly to the lowpass subband decoding except that some parameters are taken from the subband header.

Wavelet filters

Edges:

 -0.07576144003329376
  0.8586296626673486
 -0.07576144003329376
  0.3535533905932737
  0.3535533905932737

Main:

 -0.01515228715813062
  0.3687056777514043
  0.3687056777514043
 -0.01515228715813062

  0.07071067811865475
 -0.8485281374238569
  0.07071067811865475