[Mndiff-dev] [mndiff]: r9 - in trunk: docs docs/4xm.html docs/4xm.lyx docs/4xm.ps docs/4xm.txt docs/asv1.html docs/asv1.lyx docs/asv1.pdf docs/asv1.ps docs/asv1.txt docs/ffv1.html docs/ffv1.lyx docs/ffv1.ps docs/ffv1.txt docs/msmpeg4.txt misc misc/chain-check.c misc/codec-features.html misc/lumi-masking.png misc/mndiff-0.1.tar.bz2 misc/patent.html misc/relative_lumi.png patches patches/bttv-420-2.4.26.patch patches/bttv-420-2.6.6.patch patches/bttv-comb-2.4.26.patch patches/bttv-comb-2.6.6.patch patches/colorgcc.diff patches/colorgccrc-debian.diff patches/colorgccrc-upstream.diff patches/huffyuv-order1-context-patch2.bz2
michael
subversion at mplayerhq.hu
Mon Mar 19 19:52:06 CET 2007
Author: michael
Date: Mon Mar 19 19:52:05 2007
New Revision: 9
Added:
trunk/docs/
trunk/docs/4xm.html
trunk/docs/4xm.lyx
trunk/docs/4xm.ps (contents, props changed)
trunk/docs/4xm.txt
trunk/docs/asv1.html
trunk/docs/asv1.lyx
trunk/docs/asv1.pdf (contents, props changed)
trunk/docs/asv1.ps (contents, props changed)
trunk/docs/asv1.txt
trunk/docs/ffv1.html
trunk/docs/ffv1.lyx
trunk/docs/ffv1.ps (contents, props changed)
trunk/docs/ffv1.txt
trunk/docs/msmpeg4.txt
trunk/misc/
trunk/misc/chain-check.c
trunk/misc/codec-features.html
trunk/misc/lumi-masking.png (contents, props changed)
trunk/misc/mndiff-0.1.tar.bz2 (contents, props changed)
trunk/misc/patent.html
trunk/misc/relative_lumi.png (contents, props changed)
trunk/patches/
trunk/patches/bttv-420-2.4.26.patch
trunk/patches/bttv-420-2.6.6.patch
trunk/patches/bttv-comb-2.4.26.patch
trunk/patches/bttv-comb-2.6.6.patch
trunk/patches/colorgcc.diff
trunk/patches/colorgccrc-debian.diff
trunk/patches/colorgccrc-upstream.diff
trunk/patches/huffyuv-order1-context-patch2.bz2 (contents, props changed)
Log:
the stuff from my old home directory from mphq1
Added: trunk/docs/4xm.html
==============================================================================
--- (empty file)
+++ trunk/docs/4xm.html Mon Mar 19 19:52:05 2007
@@ -0,0 +1,938 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
+ "http://www.w3.org/TR/REC-html40/loose.dtd">
+<html>
+<meta name="GENERATOR" content="TtH 3.33">
+ <style type="text/css"> div.p { margin-top: 7pt;}</style>
+ <style type="text/css"><!--
+ td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
+ td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
+ td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
+ td div.norm {line-height:normal;}
+ span.roman {font-family: serif; font-style: normal; font-weight: normal;}
+ span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
+ span.overacc1 {position: relative; left: .6em; top: -1.2ex;} --></style>
+
+
+
+
+
+
+<title> \noindent Description of the 4XM Video Codec</title>
+
+<h1 align="center"> Description of the 4XM Video Codec </h1>
+
+<div class="p"><!----></div>
+
+<h3 align="center">by Michael Niedermayer <michaelni at gmx.at> </h3>
+
+<div class="p"><!----></div>
+
+<h1>Contents </h1>
+<a href="#tth_sEc1"
+>1 Introduction</a><br />
+<a href="#tth_sEc2"
+>2 Terms and Definitions</a><br />
+<a href="#tth_sEc3"
+>3 High-level Description</a><br />
+ <a href="#tth_sEc3.1"
+>3.1 I-Frame</a><br />
+ <a href="#tth_sEc3.1.1"
+>3.1.1 Macroblock</a><br />
+ <a href="#tth_sEc3.1.2"
+>3.1.2 DC Prediction</a><br />
+ <a href="#tth_sEc3.1.3"
+>3.1.3 Dequantization and IDCT</a><br />
+
+
+
+ <a href="#tth_sEc3.1.4"
+>3.1.4 YCbCr 4:2:0 -> RGB565 colorspace transform</a><br />
+ <a href="#tth_sEc3.2"
+>3.2 P-Frame</a><br />
+ <a href="#tth_sEc3.2.1"
+>3.2.1 Motion Vector table</a><br />
+ <a href="#tth_sEc3.3"
+>3.3 C-Frame</a><br />
+<a href="#tth_sEc4"
+>4 Bitstream</a><br />
+ <a href="#tth_sEc4.1"
+>4.1 I-Frame</a><br />
+ <a href="#tth_sEc4.1.1"
+>4.1.1 Prefix stream</a><br />
+ <a href="#tth_sEc4.1.2"
+>4.1.2 Macroblock</a><br />
+ <a href="#tth_sEc4.1.3"
+>4.1.3 Block</a><br />
+ <a href="#tth_sEc4.2"
+>4.2 P-Frame</a><br />
+ <a href="#tth_sEc4.2.1"
+>4.2.1 Block</a><br />
+ <a href="#tth_sEc4.3"
+>4.3 C-Frame</a><br />
+<a href="#tth_sEc5"
+>5 VLC Codes</a><br />
+ <a href="#tth_sEc5.1"
+>5.1 prefix_vlc in I frames</a><br />
+ <a href="#tth_sEc5.2"
+>5.2 level vlc in I Frames</a><br />
+ <a href="#tth_sEc5.3"
+>5.3 Block Mode Codes in P frames</a><br />
+
+
+
+
+<a href="#tth_sEc6"
+>6 Applications and Platforms</a><br />
+<a href="#tth_sEc7"
+>7 Changelog</a><br />
+<a href="#tth_sEc8"
+>8 Copyright</a><br />
+
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc1">
+1</a> Introduction</h2>
+
+<div class="p"><!----></div>
+The 4XM video codec is a mixture between a very simplified JPEG scheme
+and rectangular block based fullpel motion compensation with DC difference
+coding. The codec uses 4:2:0 YCbCr colorspace for the JPEG part but
+converts it to RGB16 before using it for motion compensation.
+
+<div class="p"><!----></div>
+The latest version of this document is available at http://www.mplayerhq.hu/michael/4xm.{lyx,txt,html,ps}
+
+<div class="p"><!----></div>
+4XM video is normally encapsulated in the proprietary 4XM format <a href="http://www.pcisys.net/~melanson/codecs/4xm-format.txt"><tt>http://www.pcisys.net/~melanson/codecs/4xm-format.txt</tt></a>.
+
+<div class="p"><!----></div>
+ This document assumes familiarity with mathematical and
+coding concepts such as the discrete cosine transform, quantization,
+YCbCr colorspaces, macroblocks, and variable length codes (VLCs).
+A familiarity with the standard JPEG coding method is also helpful.
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc2">
+2</a> Terms and Definitions</h2>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>AC</b></dt>
+ <dd>Any DCT coefficient for which the frequency in one or both dimensions
+is non-zero.</dd>
+ <dt><b>DC</b></dt>
+ <dd>The DCT coefficient for which the frequency is zero in both dimensions</dd>
+ <dt><b>(I)DCT</b></dt>
+ <dd>(Inverse) Discrete Cosine Transform</dd>
+ <dt><b>VLC</b></dt>
+ <dd>Variable Length Code</dd>
+ <dt><b>AAN IDCT</b></dt>
+ <dd>IDCT algorithm by Arai, Agui, and Nakajima</dd>
+ <dt><b>JPEG</b></dt>
+ <dd>Joint Photographic Expert Group
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc3">
+3</a> High-level Description</h2>
+
+<div class="p"><!----></div>
+The 4XM video coding method embodies 3 types of frames: I-frames,
+P-frames, and C-frames. I-frames are intraframes and stand on their
+own. P and C-frames are Interframes.
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.1">
+3.1</a> I-Frame</h3>
+
+<div class="p"><!----></div>
+I-frames are practically the same as JPEG images. Differences include
+just a single Huffman table, different headers, and a bitstream split
+into 2 partitions with one partition written in 32-bit byteswapped
+order. There are also no parameters for rate or quality control.
+
+<div class="p"><!----></div>
+The picture is split into macroblocks which are coded left->right,
+top->bottom.
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc3.1.1">
+3.1.1</a> Macroblock</h4>
+
+<div class="p"><!----></div>
+16x16 luma + 8x8 chroma as 4 8x8 luma blocks and 2 8x8 chroma blocks
+:
+
+<div class="p"><!----></div>
+Y:
+<table border="1">
+<tr><td align="center">0</td><td align="center">1</td></tr>
+
+<tr><td align="center">2</td><td align="center">3</td></tr>
+</table>
+ Cb:
+<table border="1">
+<tr><td align="center">4</td></tr>
+</table>
+ Cr:
+<table border="1">
+<tr><td align="center">5</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc3.1.2">
+3.1.2</a> DC Prediction</h4>
+
+<div class="p"><!----></div>
+DC values are predicted from the last coded block. The initial prediction
+value used for the first top left luma block is 0. No special handling
+is done between luma and chroma blocks or at the right border, so
+the DC value of the rightmost 8x8 Cr block of the first row will be
+used as the predictor for the first/top-left 8x8 luma block of the
+second MB row.
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc3.1.3">
+3.1.3</a> Dequantization and IDCT</h4>
+
+<div class="p"><!----></div>
+4XM uses an AAN IDCT with the premultiply table merged with the quantization
+table. The quantization table is the default luma table used in JPEG.
+
+<div class="p"><!----></div>
+
+<b>default luma quantization table used in JPEG </b>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+16, 11, 10, 16, 24, 40, 51, 61,
+
+<div class="p"><!----></div>
+12, 12, 14, 19, 26, 58, 60, 55,
+
+<div class="p"><!----></div>
+14, 13, 16, 24, 40, 57, 69, 56,
+
+<div class="p"><!----></div>
+14, 17, 22, 29, 51, 87, 80, 62,
+
+<div class="p"><!----></div>
+18, 22, 37, 56, 68, 109, 103, 77,
+
+<div class="p"><!----></div>
+24, 35, 55, 64, 81, 104, 113, 92,
+
+<div class="p"><!----></div>
+49, 64, 78, 87, 103, 121, 120, 101,
+
+<div class="p"><!----></div>
+72, 92, 95, 98, 112, 100, 103, 99
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+
+<b>AAN premultiply table </b>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+
+<div class="p"><!----></div>
+22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
+
+<div class="p"><!----></div>
+21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
+
+<div class="p"><!----></div>
+19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
+
+<div class="p"><!----></div>
+16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+
+<div class="p"><!----></div>
+12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
+
+<div class="p"><!----></div>
+8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446,
+
+<div class="p"><!----></div>
+4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+
+<b>merged table used in 4XM </b>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+16, 15, 13, 19, 24, 31, 28, 17,
+
+<div class="p"><!----></div>
+17, 23, 25, 31, 36, 63, 45, 21,
+
+<div class="p"><!----></div>
+18, 24, 27, 37, 52, 59, 49, 20,
+
+<div class="p"><!----></div>
+16, 28, 34, 40, 60, 80, 51, 20,
+
+<div class="p"><!----></div>
+18, 31, 48, 66, 68, 86, 56, 21,
+
+<div class="p"><!----></div>
+19, 38, 56, 59, 64, 64, 48, 20,
+
+<div class="p"><!----></div>
+27, 48, 55, 55, 56, 51, 35, 15,
+
+<div class="p"><!----></div>
+20, 35, 34, 32, 31, 22, 15, 8,
+</dd>
+</dl>
+This is simply the element-wise product of the quantization table
+and the AAN table divided by 2<sup>16</sup>.
+
+<div class="p"><!----></div>
+4XM's AAN IDCT uses (a*const)> >16 to approximate
+multiplications and simply shifts the transformed result 16 bits to
+the right. The scaled constants are:
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">exact</td><td align="center">scaled constant</td></tr>
+<tr><td>
+<tr><td align="center">1.082392200...</td><td align="center">70936</td></tr>
+
+<tr><td align="center">1.414213562...</td><td align="center">92682</td></tr>
+
+<tr><td align="center">1.847759065...</td><td align="center">121095</td></tr>
+
+<tr><td align="center">2.613125930...</td><td align="center">171254</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+which are simply the exact constants multiplied by 2<sup>16</sup> and rounded
+to the nearest integer.
+
+<div class="p"><!----></div>
+see 4xm.c <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/4xm.c?rev=HEAD&content-type=text/vnd.viewcvs-markup"><tt>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/4xm.c?rev=HEAD&content-type=text/vnd.viewcvs-markup</tt></a>
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc3.1.4">
+3.1.4</a> YCbCr 4:2:0 -> RGB565 colorspace transform</h4>
+
+<div class="p"><!----></div>
+Chroma is first upsampled by sample replication / nearest neighbor
+scaling, so that the same Cb and Cr samples are used for each 2x2
+Y samples
+
+<div class="p"><!----></div>
+R= (Y + Cr + 128)> >3
+
+<div class="p"><!----></div>
+G= (Y - ((Cb+Cr)> >1) + 128)> >2
+
+<div class="p"><!----></div>
+B= (Y + 2Cb + 128)> >3
+
+<div class="p"><!----></div>
+There is no check or protection against overflow, so values will wrap
+around if they are too large or small.
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.2">
+3.2</a> P-Frame</h3>
+
+<div class="p"><!----></div>
+A P-frame picture is split into blocks which are coded left->right,
+top->bottom. Each block contains 8x8 samples in RGB565 format (5 bits
+for red, 6 bits for green, 5 bits for blue). Each block can be recursively
+split into 2, down to 2x1/1x2 sized blocks.
+
+<div class="p"><!----></div>
+A P-frame block can be coded using 1 of 7 methods:
+
+<div class="p"><!----></div>
+
+<ol type="1">
+<li> motion compensated with 1 vector<br /><br /></li>
+
+<li> horizontally split in the middle<br /><br /></li>
+
+<li> vertically split in the middle<br /><br /></li>
+
+<li> skipped (block data copied from the frame before the last)<br />
+Example: Intraframe, Interframe1, Interframe2, Interframe3<br />
+a skipped block in Interframe3 will use the data from Interframe1;
+skipped blocks in Interframe1 are dissallowed as there is no source
+frame<br /><br /></li>
+
+<li> motion vector + DC difference (the 16-bit words of the DC and the
+source block are simply added, there is no special handling of overflows)<br /><br /></li>
+
+<li> DC only, the whole block is filled with the DC color<br /><br /></li>
+
+<li> hardcoded pixel values (left->right, top->bottom)<br /><br /></li>
+</ol>
+Block splitting is only available if the resulting blocks are larger
+than 1x2/2x1. Hardcoded pixel values are only available for 1x2/2x1
+sized blocks
+
+<div class="p"><!----></div>
+Motion compensation assumes that the number of words (16-bit RGB565
+pixels) per line is equal to the width, so that motion vectors which
+point right or left outside of the picture use the pixels from the
+other side. There is no subpel motion compensation or filtering which
+means that motion compensation can simply be done by copying the pixels
+from the motion block.
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc3.2.1">
+3.2.1</a> Motion Vector table</h4>
+
+<div class="p"><!----></div>
+See mv[256][2] at 4xm.c <a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/4xm.c?rev=HEAD&content-type=text/vnd.viewcvs-markup"><tt>http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/4xm.c?rev=HEAD&content-type=text/vnd.viewcvs-markup</tt></a>.
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.3">
+3.3</a> C-Frame</h3>
+
+<div class="p"><!----></div>
+A C-frame is essentially a partial P frame. It has all the same coding
+options but a different header.
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc4">
+4</a> Bitstream</h2>
+
+<div class="p"><!----></div>
+All 32-bit values are in little endian byte order.
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.1">
+4.1</a> I-Frame</h3>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>32bit</b></dt>
+ <dd>'ifrm'</dd>
+ <dt><b>32bit</b></dt>
+ <dd>chunk length</dd>
+ <dt><b>32bit</b></dt>
+ <dd>0 (unknown)</dd>
+ <dt><b>32bit</b></dt>
+ <dd>bitstream size</dd>
+ <dt><b>n byte</b></dt>
+ <dd>bitstream</dd>
+ <dt><b>32bit</b></dt>
+ <dd>prefixstream size / 4</dd>
+ <dt><b>32bit</b></dt>
+ <dd>token_count</dd>
+ <dt><b>n byte</b></dt>
+ <dd>prefixstream
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc4.1.1">
+4.1.1</a> Prefix stream</h4>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+start 8bit
+
+<div class="p"><!----></div>
+end 8bit
+
+<div class="p"><!----></div>
+do{
+
+<div class="p"><!----></div>
+ for(i=start; i<=end; i++)
+
+<div class="p"><!----></div>
+ frequency[i] 8bit
+
+<div class="p"><!----></div>
+ start 8bit
+
+<div class="p"><!----></div>
+ if(start==0) break;
+
+<div class="p"><!----></div>
+ end 8bit
+
+<div class="p"><!----></div>
+}
+
+<div class="p"><!----></div>
+while(not 32bit aligned)
+
+<div class="p"><!----></div>
+ 0 8bit
+
+<div class="p"><!----></div>
+for(i=0; i<token_count; i++)
+
+<div class="p"><!----></div>
+ prefix[i] prefix_vlc
+
+<div class="p"><!----></div>
+256 prefix_vlc
+</dd>
+</dl>
+Note: The prefix_vlc are stored so that each aligned 32-bit word
+is stored in byteswapped order. This byteswapping is not done to the
+bitstream, just the prefix stream
+
+<div class="p"><!----></div>
+Frequency values which are not explicitly set are 0 except that frequency[256]=1.
+This is the "end of picture" code.
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc4.1.2">
+4.1.2</a> Macroblock</h4>
+
+<div class="p"><!----></div>
+A macroblock bitstream is simply a bitstream of 6 blocks.
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc4.1.3">
+4.1.3</a> Block</h4>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+dc_prefix prefix_vlc prefix stream
+
+<div class="p"><!----></div>
+dc_suffix dc_prefix bits bitstream
+
+<div class="p"><!----></div>
+i=1;
+
+<div class="p"><!----></div>
+while(i<64){
+
+<div class="p"><!----></div>
+ ac_prefix prefix_vlc prefix_stream
+
+<div class="p"><!----></div>
+ if(ac_prefix == 0xF0)
+
+<div class="p"><!----></div>
+ i+=16;
+
+<div class="p"><!----></div>
+ else if(ac_prefix == 0x00)
+
+<div class="p"><!----></div>
+ break;
+
+<div class="p"><!----></div>
+ else{
+
+<div class="p"><!----></div>
+ i+= ac_prefix> >4;
+
+<div class="p"><!----></div>
+ level_prefix= ac_prefix&0xF;
+
+<div class="p"><!----></div>
+ level_suffix level_prefix bits bitstream
+
+<div class="p"><!----></div>
+ block[ zigzag[i] ]= level;
+
+<div class="p"><!----></div>
+ i++;
+
+<div class="p"><!----></div>
+ }
+
+<div class="p"><!----></div>
+}
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.2">
+4.2</a> P-Frame</h3>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>32bit</b></dt>
+ <dd>'pfrm'</dd>
+ <dt><b>32bit</b></dt>
+ <dd>chunk size</dd>
+ <dt><b>32bit</b></dt>
+ <dd>0 (unknown)</dd>
+ <dt><b>32bit</b></dt>
+ <dd>unknown, perhaps a checksum</dd>
+ <dt><b>32bit</b></dt>
+ <dd>unknown</dd>
+ <dt><b>32bit</b></dt>
+ <dd>bitstream size</dd>
+ <dt><b>32bit</b></dt>
+ <dd>wordstream size</dd>
+ <dt><b>32bit</b></dt>
+ <dd>bytestream size</dd>
+ <dt><b>n bytes</b></dt>
+ <dd>bitstream, stored in byteswapped 32-bit words</dd>
+ <dt><b>n bytes</b></dt>
+ <dd>RGB16 wordstream, stored in little endian order</dd>
+ <dt><b>n bytes</b></dt>
+ <dd>bytestream
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc4.2.1">
+4.2.1</a> Block</h4>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+block(){
+
+<div class="p"><!----></div>
+ mode vlc bitstream
+
+<div class="p"><!----></div>
+ if(mode==h_split || mode==v_split){
+
+<div class="p"><!----></div>
+ block()
+
+<div class="p"><!----></div>
+ block()
+
+<div class="p"><!----></div>
+ }
+
+<div class="p"><!----></div>
+ if(mode==mc || mode==mcdc)
+
+<div class="p"><!----></div>
+ mv 8bit bytestream
+
+<div class="p"><!----></div>
+ if(mode==dc || mode==mcdc)
+
+<div class="p"><!----></div>
+ dc 16bit wordstream
+
+<div class="p"><!----></div>
+ if(mode==esc){
+
+<div class="p"><!----></div>
+ col1 16bit wordstream
+
+<div class="p"><!----></div>
+ col2 16bit wordstream
+
+<div class="p"><!----></div>
+ }
+
+<div class="p"><!----></div>
+}
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.3">
+4.3</a> C-Frame</h3>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>32bit</b></dt>
+ <dd>'cfrm'</dd>
+ <dt><b>32bit</b></dt>
+ <dd>chunk size</dd>
+ <dt><b>32bit</b></dt>
+ <dd>0 (unknown)</dd>
+ <dt><b>32bit</b></dt>
+ <dd>frame number / frame id, this is the frame number where the
+frame will be shown, it is also the frame number at which the last
+cframe part of this frame will be; note, all parts of the same cframe
+contain the same id here</dd>
+ <dt><b>32bit</b></dt>
+ <dd>whole frame size</dd>
+ <dt><b>*</b></dt>
+ <dd>p frame, this is (unk, unk, bitstream size, wordstream size,
+...) for the first c frame chunk of a c frame
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc5">
+5</a> VLC Codes</h2>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc5.1">
+5.1</a> prefix_vlc in I frames</h3>
+
+<div class="p"><!----></div>
+The prefix_vlc table is generated from the frequencies stored in
+the prefix stream. Additionally, the element 256 is added with an
+implicit frequency of 1. For the exact algorithm see libavcodec/4xm.c
+read_huffman_tables().
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc5.2">
+5.2</a> level vlc in I Frames</h3>
+
+<div class="p"><!----></div>
+Identical to JPEG
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">prefix</td><td align="center">vlc</td><td align="center">level</td></tr>
+<tr><td>
+<tr><td align="center">0</td><td align="center"></td><td align="center">0</td></tr>
+
+<tr><td align="center">1</td><td align="center">0/1</td><td align="center">-1/1</td></tr>
+
+<tr><td align="center">2</td><td align="center">0X/1X</td><td align="center">-3..-2/2..3</td></tr>
+
+<tr><td align="center">3</td><td align="center">0XX/1XX</td><td align="center">-7..-4/4..7</td></tr>
+
+<tr><td align="center">...</td><td align="center">...</td><td align="center">...</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+One way to decode this is:
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+if(prefix){
+
+<div class="p"><!----></div>
+ v= get_bits(prefix);
+
+<div class="p"><!----></div>
+ if((v & (1< <(prefix-1))) == 0)
+
+<div class="p"><!----></div>
+ v= (-1 < <prefix)|(v+1);
+
+<div class="p"><!----></div>
+}else
+
+<div class="p"><!----></div>
+ v= 0;
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc5.3">
+5.3</a> Block Mode Codes in P frames</h3>
+
+<div class="p"><!----></div>
+
+<b>For blocks 8x8, 8x4, 8x2, 4x8, 4x4, 4x2, 2x8, 2x4, 2x2 </b>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0</td><td align="center">mc</td></tr>
+
+<tr><td align="center">10</td><td align="center">h_split</td></tr>
+
+<tr><td align="center">110</td><td align="center">v_split</td></tr>
+
+<tr><td align="center">1110</td><td align="center">skip</td></tr>
+
+<tr><td align="center">11110</td><td align="center">mcdc</td></tr>
+
+<tr><td align="center">11111</td><td align="center">dc</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+
+<b>For blocks 8x1, 4x1 </b>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0</td><td align="center">mc</td></tr>
+
+<tr><td align="center">10</td><td align="center">h_split</td></tr>
+
+<tr><td align="center">110</td><td align="center">skip</td></tr>
+
+<tr><td align="center">1110</td><td align="center">mcdc</td></tr>
+
+<tr><td align="center">1111</td><td align="center">dc</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+
+<b>For blocks 1x8, 1x4 </b>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0</td><td align="center">mc</td></tr>
+
+<tr><td align="center">10</td><td align="center">v_split</td></tr>
+
+<tr><td align="center">110</td><td align="center">skip</td></tr>
+
+<tr><td align="center">1110</td><td align="center">mcdc</td></tr>
+
+<tr><td align="center">1111</td><td align="center">dc</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+
+<b>For blocks 2x1, 1x2 </b>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0</td><td align="center">mc</td></tr>
+
+<tr><td align="center">10</td><td align="center">skip</td></tr>
+
+<tr><td align="center">110</td><td align="center">mcdc</td></tr>
+
+<tr><td align="center">1110</td><td align="center">dc</td></tr>
+
+<tr><td align="center">1111</td><td align="center">esc</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc6">
+6</a> Applications and Platforms</h2>
+
+<div class="p"><!----></div>
+The 4XM video codec is intended for gaming applications. It is known
+to operate on these computing platforms:
+
+<div class="p"><!----></div>
+
+<ul>
+<li> PC/Microsoft Windows<br /><br /></li>
+
+<li> Apple Macintosh<br /><br /></li>
+
+<li> Sega Dreamcast<br /><br /></li>
+
+<li> Nintendo Gameboy Advance<br /><br /></li>
+</ul>
+While the Dreamcast and the targeted PC/Mac platforms have quite a
+bit of computing power (at least 200 MHz), the GBA has an ARM RISC
+CPU running at 16-17 MHz.
+
+<div class="p"><!----></div>
+The 4XM coding method seems a little odd in its mixture of YCbCr and
+RGB colorspaces. In the end, all of the output data is RGB565. It
+is useful to note that many video game consoles can efficiently manuipulate
+this colorspace with video hardware. By contrast, many video consoles
+have no, or very limited, facilites for direct YCbCr rendering, particularly
+planar YCbCr modes.
+
+<div class="p"><!----></div>
+One more note about interframe block addition: One possible approach
+to implementing this part of the method on console hardware, at least
+the Sega Dreamcast, would be to fill a texture with all zero values,
+skip all blocks that are not coded, and fill the coded blocks with
+the coded RGB565 difference. Then, the final texture could be added
+to the current frame. This also has the implicit side effect of saturating
+the addition so that the resulting pixels do not wrap around.
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc7">
+7</a> Changelog</h2>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>0.01</b></dt>
+ <dd>2003-06-01<br />
+initial version by Michael Niedermayer</dd>
+ <dt><b>0.02</b></dt>
+ <dd>2003-06-07<br />
+minor changes</dd>
+ <dt><b>0.03</b></dt>
+ <dd>2003-06-08<br />
+peer review, grammar/spelling/punctuation fixes and "Applications
+and Platforms" section by Mike Melanson<br />
+minor changes by Michael</dd>
+ <dt><b>0.04</b></dt>
+ <dd>2003-06-08<br />
+minor changes by Mike Melanson and Michael Niedermayer
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc8">
+8</a> Copyright</h2>
+
+<div class="p"><!----></div>
+Copyright 2003 Michael Niedermayer <michaelni at gmx.at> <br />
+This text can be used under the GNU Free Documentation License or
+GNU General Public License. See <a href="http://www.gnu.org/licenses/fdl.txt"><tt>http://www.gnu.org/licenses/fdl.txt</tt></a>.
+
+<br /><br /><hr /><small>File translated from
+T<sub><font size="-1">E</font></sub>X
+by <a href="http://hutchinson.belmont.ma.us/tth/">
+T<sub><font size="-1">T</font></sub>H</a>,
+version 3.33.<br />On 8 Jun 2003, 00:03.</small>
+</html>
Added: trunk/docs/4xm.lyx
==============================================================================
--- (empty file)
+++ trunk/docs/4xm.lyx Mon Mar 19 19:52:05 2007
@@ -0,0 +1,1640 @@
+#LyX 1.3 created this file. For more info see http://www.lyx.org/
+\lyxformat 221
+\textclass article
+\language english
+\inputencoding auto
+\fontscheme default
+\graphics default
+\paperfontsize default
+\spacing single
+\papersize Default
+\paperpackage a4
+\use_geometry 0
+\use_amsmath 0
+\use_natbib 0
+\use_numerical_citations 0
+\paperorientation portrait
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation skip
+\defskip medskip
+\quotes_language english
+\quotes_times 2
+\papercolumns 1
+\papersides 1
+\paperpagestyle default
+
+\layout Title
+\noindent
+Description of the 4XM Video Codec
+\layout Author
+
+by Michael Niedermayer <michaelni at gmx.at>
+\layout Standard
+
+
+\begin_inset LatexCommand \tableofcontents{}
+
+\end_inset
+
+
+\layout Section
+
+Introduction
+\layout Standard
+
+The 4XM video codec is a mixture between a very simplified JPEG scheme and
+ rectangular block based fullpel motion compensation with DC difference
+ coding.
+ The codec uses 4:2:0 YCbCr colorspace for the JPEG part but converts it
+ to RGB16 before using it for motion compensation.
+\layout Standard
+
+The latest version of this document is available at http://www.mplayerhq.hu/~micha
+el/4xm.{lyx,txt,html,ps}
+\layout Standard
+
+4XM video is normally encapsulated in the proprietary
+\begin_inset LatexCommand \url[4XM format]{http://www.pcisys.net/~melanson/codecs/4xm-format.txt}
+
+\end_inset
+
+.
+\layout Standard
+\noindent
+This document assumes familiarity with mathematical and coding concepts
+ such as the discrete cosine transform, quantization, YCbCr colorspaces,
+ macroblocks, and variable length codes (VLCs).
+ A familiarity with the standard JPEG coding method is also helpful.
+\layout Section
+
+Terms and Definitions
+\layout List
+\labelwidthstring 00.00.0000
+
+AC Any DCT coefficient for which the frequency in one or both dimensions
+ is non-zero.
+\layout List
+\labelwidthstring 00.00.0000
+
+DC The DCT coefficient for which the frequency is zero in both dimensions
+\layout List
+\labelwidthstring 00.00.0000
+
+(I)DCT (Inverse) Discrete Cosine Transform
+\layout List
+\labelwidthstring 00.00.0000
+
+VLC Variable Length Code
+\layout List
+\labelwidthstring 00.00.0000
+
+AAN\SpecialChar ~
+IDCT IDCT algorithm by Arai, Agui, and Nakajima
+\layout List
+\labelwidthstring 00.00.0000
+
+JPEG Joint Photographic Expert Group
+\layout Section
+
+High-level Description
+\layout Standard
+
+The 4XM video coding method embodies 3 types of frames: I-frames, P-frames,
+ and C-frames.
+ I-frames are intraframes and stand on their own.
+ P and C-frames are Interframes.
+\layout Subsection
+
+I-Frame
+\layout Standard
+
+I-frames are practically the same as JPEG images.
+ Differences include just a single Huffman table, different headers, and
+ a bitstream split into 2 partitions with one partition written in 32-bit
+ byteswapped order.
+ There are also no parameters for rate or quality control.
+\layout Standard
+
+The picture is split into macroblocks which are coded left->right, top->bottom.
+\layout Subsubsection
+
+Macroblock
+\layout Standard
+
+16x16 luma + 8x8 chroma as 4 8x8 luma blocks and 2 8x8 chroma blocks :
+\layout Standard
+
+Y:
+\begin_inset Tabular
+<lyxtabular version="3" rows="2" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+ Cb:
+\begin_inset Tabular
+<lyxtabular version="3" rows="1" columns="1">
+<features>
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+4
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+ Cr:
+\begin_inset Tabular
+<lyxtabular version="3" rows="1" columns="1">
+<features>
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+5
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Subsubsection
+
+DC Prediction
+\layout Standard
+
+DC values are predicted from the last coded block.
+ The initial prediction value used for the first top left luma block is
+ 0.
+ No special handling is done between luma and chroma blocks or at the right
+ border, so the DC value of the rightmost 8x8 Cr block of the first row
+ will be used as the predictor for the first/top-left 8x8 luma block of
+ the second MB row.
+
+\layout Subsubsection
+
+Dequantization and IDCT
+\layout Standard
+
+4XM uses an AAN IDCT with the premultiply table merged with the quantization
+ table.
+ The quantization table is the default luma table used in JPEG.
+\layout Paragraph
+
+default luma quantization table used in JPEG
+\layout LyX-Code
+
+16, 11, 10, 16, 24, 40, 51, 61,
+\layout LyX-Code
+
+12, 12, 14, 19, 26, 58, 60, 55,
+\layout LyX-Code
+
+14, 13, 16, 24, 40, 57, 69, 56,
+\layout LyX-Code
+
+14, 17, 22, 29, 51, 87, 80, 62,
+\layout LyX-Code
+
+18, 22, 37, 56, 68, 109, 103, 77,
+\layout LyX-Code
+
+24, 35, 55, 64, 81, 104, 113, 92,
+\layout LyX-Code
+
+49, 64, 78, 87, 103, 121, 120, 101,
+\layout LyX-Code
+
+72, 92, 95, 98, 112, 100, 103, 99
+\layout Paragraph
+
+AAN premultiply table
+\layout LyX-Code
+
+16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+\layout LyX-Code
+
+22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
+\layout LyX-Code
+
+21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
+\layout LyX-Code
+
+19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
+\layout LyX-Code
+
+16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+\layout LyX-Code
+
+12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
+\layout LyX-Code
+
+8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446,
+\layout LyX-Code
+
+4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247
+\layout Paragraph
+
+merged table used in 4XM
+\layout LyX-Code
+
+16, 15, 13, 19, 24, 31, 28, 17,
+\layout LyX-Code
+
+17, 23, 25, 31, 36, 63, 45, 21,
+\layout LyX-Code
+
+18, 24, 27, 37, 52, 59, 49, 20,
+\layout LyX-Code
+
+16, 28, 34, 40, 60, 80, 51, 20,
+\layout LyX-Code
+
+18, 31, 48, 66, 68, 86, 56, 21,
+\layout LyX-Code
+
+19, 38, 56, 59, 64, 64, 48, 20,
+\layout LyX-Code
+
+27, 48, 55, 55, 56, 51, 35, 15,
+\layout LyX-Code
+
+20, 35, 34, 32, 31, 22, 15, 8,
+\layout Standard
+
+This is simply the element-wise product of the quantization table and the
+ AAN table divided by
+\begin_inset Formula $2^{16}$
+\end_inset
+
+.
+\layout Standard
+
+4XM's AAN IDCT uses (a*const)>>16 to approximate multiplications and simply
+ shifts the transformed result 16 bits to the right.
+ The scaled constants are:
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="5" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+exact
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+scaled constant
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1.082392200...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+70936
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1
+\family default
+\series default
+\shape default
+\size default
+\emph default
+\bar default
+\noun default
+\color default
+.
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+414213562
+\family default
+\series default
+\shape default
+\size default
+\emph default
+\bar default
+\noun default
+\color default
+...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+92682
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1.847759065...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+121095
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2.613125930...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+171254
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Standard
+
+which are simply the exact constants multiplied by
+\begin_inset Formula $2^{16}$
+\end_inset
+
+ and rounded to the nearest integer.
+\layout Standard
+
+see
+\begin_inset LatexCommand \htmlurl[4xm.c]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/4xm.c?rev=HEAD&content-type=text/vnd.viewcvs-markup}
+
+\end_inset
+
+
+\layout Subsubsection
+
+YCbCr 4:2:0 -> RGB565 colorspace transform
+\layout Standard
+
+Chroma is first upsampled by sample replication / nearest neighbor scaling,
+ so that the same Cb and Cr samples are used for each 2x2 Y samples
+\layout Standard
+
+R= (Y + Cr + 128)>>3
+\layout Standard
+
+G= (Y - ((Cb+Cr)>>1) + 128)>>2
+\layout Standard
+
+B= (Y + 2Cb + 128)>>3
+\layout Standard
+
+There is no check or protection against overflow, so values will wrap around
+ if they are too large or small.
+\layout Subsection
+
+P-Frame
+\layout Standard
+
+A P-frame picture is split into blocks which are coded left->right, top->bottom.
+ Each block contains 8x8 samples in RGB565 format (5 bits for red, 6 bits
+ for green, 5 bits for blue).
+ Each block can be recursively split into 2, down to 2x1/1x2 sized blocks.
+\layout Standard
+
+A P-frame block can be coded using 1 of 7 methods:
+\layout Enumerate
+
+motion compensated with 1 vector
+\layout Enumerate
+
+horizontally split in the middle
+\layout Enumerate
+
+vertically split in the middle
+\layout Enumerate
+
+skipped (block data copied from the frame before the last)
+\newline
+Example: Intraframe, Interframe1, Interframe2, Interframe3
+\newline
+a skipped block in Interframe3 will use the data from Interframe1; skipped
+ blocks in Interframe1 are dissallowed as there is no source frame
+\layout Enumerate
+
+motion vector + DC difference (the 16-bit words of the DC and the source
+ block are simply added, there is no special handling of overflows)
+\layout Enumerate
+
+DC only, the whole block is filled with the DC color
+\layout Enumerate
+
+hardcoded pixel values (left->right, top->bottom)
+\layout Standard
+
+Block splitting is only available if the resulting blocks are larger than
+ 1x2/2x1.
+ Hardcoded pixel values are only available for 1x2/2x1 sized blocks
+\layout Standard
+
+Motion compensation assumes that the number of words (16-bit RGB565 pixels)
+ per line is equal to the width, so that motion vectors which point right
+ or left outside of the picture use the pixels from the other side.
+ There is no subpel motion compensation or filtering which means that motion
+ compensation can simply be done by copying the pixels from the motion block.
+\layout Subsubsection
+
+Motion Vector table
+\layout Standard
+
+See mv[256][2] at
+\begin_inset LatexCommand \htmlurl[4xm.c]{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/4xm.c?rev=HEAD&content-type=text/vnd.viewcvs-markup}
+
+\end_inset
+
+.
+\layout Subsection
+
+C-Frame
+\layout Standard
+
+A C-frame is essentially a partial P frame.
+ It has all the same coding options but a different header.
+\layout Section
+
+Bitstream
+\layout Standard
+
+All 32-bit values are in little endian byte order.
+\layout Subsection
+
+I-Frame
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit 'ifrm'
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit chunk length
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit 0 (unknown)
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit bitstream size
+\layout List
+\labelwidthstring 00.00.0000
+
+n\SpecialChar ~
+byte bitstream
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit prefixstream size / 4
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit token_count
+\layout List
+\labelwidthstring 00.00.0000
+
+n\SpecialChar ~
+byte prefixstream
+\layout Subsubsection
+
+Prefix stream
+\layout LyX-Code
+
+start 8bit
+\layout LyX-Code
+
+end 8bit
+\layout LyX-Code
+
+do{
+\layout LyX-Code
+
+ for(i=start; i<=end; i++)
+\layout LyX-Code
+
+ frequency[i] 8bit
+\layout LyX-Code
+
+ start 8bit
+\layout LyX-Code
+
+ if(start==0) break;
+\layout LyX-Code
+
+ end 8bit
+\layout LyX-Code
+
+}
+\layout LyX-Code
+
+while(not 32bit aligned)
+\layout LyX-Code
+
+ 0 8bit
+\layout LyX-Code
+
+for(i=0; i<token_count; i++)
+\layout LyX-Code
+
+ prefix[i] prefix_vlc
+\layout LyX-Code
+
+256 prefix_vlc
+\layout Standard
+
+Note: The prefix_vlc are stored so that each aligned 32-bit word is stored
+ in byteswapped order.
+ This byteswapping is not done to the bitstream, just the prefix stream
+\layout Standard
+
+Frequency values which are not explicitly set are 0 except that frequency[256]=1.
+ This is the
+\begin_inset Quotes eld
+\end_inset
+
+end of picture
+\begin_inset Quotes erd
+\end_inset
+
+ code.
+\layout Subsubsection
+
+Macroblock
+\layout Standard
+
+A macroblock bitstream is simply a bitstream of 6 blocks.
+\layout Subsubsection
+
+Block
+\layout LyX-Code
+
+dc_prefix prefix_vlc prefix stream
+\layout LyX-Code
+
+dc_suffix dc_prefix bits bitstream
+\layout LyX-Code
+
+i=1;
+\layout LyX-Code
+
+while(i<64){
+\layout LyX-Code
+
+ ac_prefix prefix_vlc prefix_stream
+\layout LyX-Code
+
+ if(ac_prefix == 0xF0)
+\layout LyX-Code
+
+ i+=16;
+\layout LyX-Code
+
+ else if(ac_prefix == 0x00)
+\layout LyX-Code
+
+ break;
+\layout LyX-Code
+
+ else{
+\layout LyX-Code
+
+ i+= ac_prefix>>4;
+\layout LyX-Code
+
+ level_prefix= ac_prefix&0xF;
+\layout LyX-Code
+
+ level_suffix level_prefix bits bitstream
+\layout LyX-Code
+
+ block[ zigzag[i] ]= level;
+\layout LyX-Code
+
+ i++;
+\layout LyX-Code
+
+ }
+\layout LyX-Code
+
+}
+\layout Subsection
+
+P-Frame
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit 'pfrm'
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit chunk size
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit 0 (unknown)
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit unknown, perhaps a checksum
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit unknown
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit bitstream size
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit wordstream size
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit bytestream size
+\layout List
+\labelwidthstring 00.00.0000
+
+n\SpecialChar ~
+bytes bitstream, stored in byteswapped 32-bit words
+\layout List
+\labelwidthstring 00.00.0000
+
+n\SpecialChar ~
+bytes RGB16 wordstream, stored in little endian order
+\layout List
+\labelwidthstring 00.00.0000
+
+n\SpecialChar ~
+bytes bytestream
+\layout Subsubsection
+
+Block
+\layout LyX-Code
+
+block(){
+\layout LyX-Code
+
+ mode vlc bitstream
+\layout LyX-Code
+
+ if(mode==h_split || mode==v_split){
+\layout LyX-Code
+
+ block()
+\layout LyX-Code
+
+ block()
+\layout LyX-Code
+
+ }
+\layout LyX-Code
+
+ if(mode==mc || mode==mcdc)
+\layout LyX-Code
+
+ mv 8bit bytestream
+\layout LyX-Code
+
+ if(mode==dc || mode==mcdc)
+\layout LyX-Code
+
+ dc 16bit wordstream
+\layout LyX-Code
+
+ if(mode==esc){
+\layout LyX-Code
+
+ col1 16bit wordstream
+\layout LyX-Code
+
+ col2 16bit wordstream
+\layout LyX-Code
+
+ }
+\layout LyX-Code
+
+}
+\layout Subsection
+
+C-Frame
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit 'cfrm'
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit chunk size
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit 0 (unknown)
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit frame number / frame id, this is the frame number where the frame
+ will be shown, it is also the frame number at which the last cframe part
+ of this frame will be; note, all parts of the same cframe contain the same
+ id here
+\layout List
+\labelwidthstring 00.00.0000
+
+32bit whole frame size
+\layout List
+\labelwidthstring 00.00.0000
+
+* p frame, this is (unk, unk, bitstream size, wordstream size, ...) for the
+ first c frame chunk of a c frame
+\layout Section
+
+VLC Codes
+\layout Subsection
+
+prefix_vlc in I frames
+\layout Standard
+
+The prefix_vlc table is generated from the frequencies stored in the prefix
+ stream.
+ Additionally, the element 256 is added with an implicit frequency of 1.
+ For the exact algorithm see libavcodec/4xm.c read_huffman_tables().
+\layout Subsection
+
+level vlc in I Frames
+\layout Standard
+
+Identical to JPEG
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="6" columns="3">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+prefix
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+vlc
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+level
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0/1
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-1/1
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0X/1X
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-3..-2/2..3
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0XX/1XX
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-7..-4/4..7
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Standard
+
+One way to decode this is:
+\layout LyX-Code
+
+if(prefix){
+\layout LyX-Code
+
+ v= get_bits(prefix);
+\layout LyX-Code
+
+ if((v & (1<<(prefix-1))) == 0)
+\layout LyX-Code
+
+ v= (-1 <<prefix)|(v+1);
+\layout LyX-Code
+
+}else
+\layout LyX-Code
+
+ v= 0;
+\layout Subsection
+
+Block Mode Codes in P frames
+\layout Paragraph
+
+For blocks 8x8, 8x4, 8x2, 4x8, 4x4, 4x2, 2x8, 2x4, 2x2
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="6" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+mc
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+h_split
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+v_split
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+skip
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+11110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+mcdc
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+11111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+dc
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Paragraph
+
+For blocks 8x1, 4x1
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="5" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+mc
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+h_split
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+skip
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+mcdc
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+dc
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Paragraph
+
+For blocks 1x8, 1x4
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="5" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+mc
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+v_split
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+skip
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+mcdc
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+dc
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Paragraph
+
+For blocks 2x1, 1x2
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="5" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+mc
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+skip
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+mcdc
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+dc
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+esc
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Section
+
+Applications and Platforms
+\layout Standard
+
+The 4XM video codec is intended for gaming applications.
+ It is known to operate on these computing platforms:
+\layout Itemize
+
+PC/Microsoft Windows
+\layout Itemize
+
+Apple Macintosh
+\layout Itemize
+
+Sega Dreamcast
+\layout Itemize
+
+Nintendo Gameboy Advance
+\layout Standard
+
+While the Dreamcast and the targeted PC/Mac platforms have quite a bit of
+ computing power (at least 200 MHz), the GBA has an ARM RISC CPU running
+ at 16-17 MHz.
+\layout Standard
+
+The 4XM coding method seems a little odd in its mixture of YCbCr and RGB
+ colorspaces.
+ In the end, all of the output data is RGB565.
+ It is useful to note that many video game consoles can efficiently manuipulate
+ this colorspace with video hardware.
+ By contrast, many video consoles have no, or very limited, facilites for
+ direct YCbCr rendering, particularly planar YCbCr modes.
+\layout Standard
+
+One more note about interframe block addition: One possible approach to
+ implementing this part of the method on console hardware, at least the
+ Sega Dreamcast, would be to fill a texture with all zero values, skip all
+ blocks that are not coded, and fill the coded blocks with the coded RGB565
+ difference.
+ Then, the final texture could be added to the current frame.
+ This also has the implicit side effect of saturating the addition so that
+ the resulting pixels do not wrap around.
+\layout Section
+
+Changelog
+\layout List
+\labelwidthstring 00.00.0000
+
+0.01 2003-06-01
+\newline
+initial version by Michael Niedermayer
+\layout List
+\labelwidthstring 00.00.0000
+
+0.02 2003-06-07
+\newline
+minor changes
+\layout List
+\labelwidthstring 00.00.0000
+
+0.03 2003-06-08
+\newline
+peer review, grammar/spelling/punctuation fixes and
+\begin_inset Quotes eld
+\end_inset
+
+Applications and Platforms
+\begin_inset Quotes erd
+\end_inset
+
+ section by Mike Melanson
+\newline
+minor changes by Michael
+\layout List
+\labelwidthstring 00.00.0000
+
+0.04 2003-06-08
+\newline
+minor changes by Mike Melanson and Michael Niedermayer
+\layout Section
+
+Copyright
+\layout Standard
+
+Copyright 2003 Michael Niedermayer <michaelni at gmx.at>
+\newline
+This text can be used under the GNU Free Documentation License or GNU General
+ Public License.
+ See
+\begin_inset LatexCommand \htmlurl{http://www.gnu.org/licenses/fdl.txt}
+
+\end_inset
+
+.
+\the_end
Added: trunk/docs/4xm.ps
==============================================================================
Binary file. No diff available.
Added: trunk/docs/4xm.txt
==============================================================================
--- (empty file)
+++ trunk/docs/4xm.txt Mon Mar 19 19:52:05 2007
@@ -0,0 +1,611 @@
+Description of the 4XM Video Codec
+
+by Michael Niedermayer <michaelni at gmx.at>
+
+Table of Contents
+
+1 Introduction
+2 Terms and Definitions
+3 High-level Description
+ 3.1 I-Frame
+ 3.1.1 Macroblock
+ 3.1.2 DC Prediction
+ 3.1.3 Dequantization and IDCT
+ 3.1.4 YCbCr 4:2:0 -> RGB565 colorspace transform
+ 3.2 P-Frame
+ 3.2.1 Motion Vector table
+ 3.3 C-Frame
+4 Bitstream
+ 4.1 I-Frame
+ 4.1.1 Prefix stream
+ 4.1.2 Macroblock
+ 4.1.3 Block
+ 4.2 P-Frame
+ 4.2.1 Block
+ 4.3 C-Frame
+5 VLC Codes
+ 5.1 prefix_vlc in I frames
+ 5.2 level vlc in I Frames
+ 5.3 Block Mode Codes in P frames
+6 Applications and Platforms
+7 Changelog
+8 Copyright
+
+
+
+1 Introduction
+
+The 4XM video codec is a mixture between a very
+simplified JPEG scheme and rectangular block based
+fullpel motion compensation with DC difference coding.
+The codec uses 4:2:0 YCbCr colorspace for the JPEG part
+but converts it to RGB16 before using it for motion compensation.
+
+The latest version of this document is available at
+http://www.mplayerhq.hu/~michael/4xm.{lyx,txt,html,ps}
+
+4XM video is normally encapsulated in the proprietary [http://www.pcisys.net/~melanson/codecs/4xm-format.txt||4XM format].
+
+This document assumes familiarity with mathematical and
+coding concepts such as the discrete cosine transform,
+quantization, YCbCr colorspaces, macroblocks, and
+variable length codes (VLCs). A familiarity with the
+standard JPEG coding method is also helpful.
+
+2 Terms and Definitions
+
+AC Any DCT coefficient for which the frequency in one
+or both dimensions is non-zero.
+
+DC The DCT coefficient for which the frequency is zero
+in both dimensions
+
+(I)DCT (Inverse) Discrete Cosine Transform
+
+VLC Variable Length Code
+
+AAN IDCT IDCT algorithm by Arai, Agui, and Nakajima
+
+JPEG Joint Photographic Expert Group
+
+3 High-level Description
+
+The 4XM video coding method embodies 3 types of frames:
+I-frames, P-frames, and C-frames. I-frames are
+intraframes and stand on their own. P and C-frames are
+Interframes.
+
+3.1 I-Frame
+
+I-frames are practically the same as JPEG images.
+Differences include just a single Huffman table,
+different headers, and a bitstream split into 2
+partitions with one partition written in 32-bit
+byteswapped order. There are also no parameters for
+rate or quality control.
+
+The picture is split into macroblocks which are coded
+left->right, top->bottom.
+
+3.1.1 Macroblock
+
+16x16 luma + 8x8 chroma as 4 8x8 luma blocks and 2 8x8
+chroma blocks :
+
+Y:+----+---+
+| 0 | 1 |
++----+---+
+| 2 | 3 |
++----+---+
+ Cb:+---+
+| 4 |
++---+
+ Cr:+---+
+| 5 |
++---+
+
+
+3.1.2 DC Prediction
+
+DC values are predicted from the last coded block. The
+initial prediction value used for the first top left
+luma block is 0. No special handling is done between
+luma and chroma blocks or at the right border, so the
+DC value of the rightmost 8x8 Cr block of the first row
+will be used as the predictor for the first/top-left
+8x8 luma block of the second MB row.
+
+3.1.3 Dequantization and IDCT
+
+4XM uses an AAN IDCT with the premultiply table merged
+with the quantization table. The quantization table is
+the default luma table used in JPEG.
+
+ default luma quantization table used in JPEG
+
+16, 11, 10, 16, 24, 40, 51, 61,
+
+12, 12, 14, 19, 26, 58, 60, 55,
+
+14, 13, 16, 24, 40, 57, 69, 56,
+
+14, 17, 22, 29, 51, 87, 80, 62,
+
+18, 22, 37, 56, 68, 109, 103, 77,
+
+24, 35, 55, 64, 81, 104, 113, 92,
+
+49, 64, 78, 87, 103, 121, 120, 101,
+
+72, 92, 95, 98, 112, 100, 103, 99
+
+ AAN premultiply table
+
+16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+
+22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
+
+21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
+
+19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
+
+16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
+
+12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
+
+8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446,
+
+4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247
+
+ merged table used in 4XM
+
+16, 15, 13, 19, 24, 31, 28, 17,
+
+17, 23, 25, 31, 36, 63, 45, 21,
+
+18, 24, 27, 37, 52, 59, 49, 20,
+
+16, 28, 34, 40, 60, 80, 51, 20,
+
+18, 31, 48, 66, 68, 86, 56, 21,
+
+19, 38, 56, 59, 64, 64, 48, 20,
+
+27, 48, 55, 55, 56, 51, 35, 15,
+
+20, 35, 34, 32, 31, 22, 15, 8,
+
+This is simply the element-wise product of the
+quantization table and the AAN table divided by 2^{16} .
+
+4XM's AAN IDCT uses (a*const)>>16 to approximate
+multiplications and simply shifts the transformed
+result 16 bits to the right. The scaled constants are:
+
++-----------------+-----------------+
+| exact | scaled constant |
++-----------------+-----------------+
++-----------------+-----------------+
+| 1.082392200... | 70936 |
++-----------------+-----------------+
+| 1.414213562... | 92682 |
++-----------------+-----------------+
+| 1.847759065... | 121095 |
++-----------------+-----------------+
+| 2.613125930... | 171254 |
++-----------------+-----------------+
+
+
+which are simply the exact constants multiplied by 2^{16} and
+rounded to the nearest integer.
+
+see [http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/4xm.c?rev=HEAD&content-type=text/vnd.viewcvs-markup||4xm.c]
+
+3.1.4 YCbCr 4:2:0 -> RGB565 colorspace transform
+
+Chroma is first upsampled by sample replication /
+nearest neighbor scaling, so that the same Cb and Cr
+samples are used for each 2x2 Y samples
+
+R= (Y + Cr + 128)>>3
+
+G= (Y - ((Cb+Cr)>>1) + 128)>>2
+
+B= (Y + 2Cb + 128)>>3
+
+There is no check or protection against overflow, so
+values will wrap around if they are too large or small.
+
+3.2 P-Frame
+
+A P-frame picture is split into blocks which are coded
+left->right, top->bottom. Each block contains 8x8
+samples in RGB565 format (5 bits for red, 6 bits for
+green, 5 bits for blue). Each block can be recursively
+split into 2, down to 2x1/1x2 sized blocks.
+
+A P-frame block can be coded using 1 of 7 methods:
+
+1. motion compensated with 1 vector
+
+2. horizontally split in the middle
+
+3. vertically split in the middle
+
+4. skipped (block data copied from the frame before the last)
+ Example: Intraframe, Interframe1, Interframe2, Interframe3
+ a skipped block in Interframe3 will use the data from
+ Interframe1; skipped blocks in Interframe1 are
+ dissallowed as there is no source frame
+
+5. motion vector + DC difference (the 16-bit words of
+ the DC and the source block are simply added, there
+ is no special handling of overflows)
+
+6. DC only, the whole block is filled with the DC color
+
+7. hardcoded pixel values (left->right, top->bottom)
+
+Block splitting is only available if the resulting
+blocks are larger than 1x2/2x1. Hardcoded pixel values
+are only available for 1x2/2x1 sized blocks
+
+Motion compensation assumes that the number of words
+(16-bit RGB565 pixels) per line is equal to the width,
+so that motion vectors which point right or left
+outside of the picture use the pixels from the other
+side. There is no subpel motion compensation or
+filtering which means that motion compensation can
+simply be done by copying the pixels from the motion block.
+
+3.2.1 Motion Vector table
+
+See mv[256][2] at [http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/4xm.c?rev=HEAD&content-type=text/vnd.viewcvs-markup||4xm.c].
+
+3.3 C-Frame
+
+A C-frame is essentially a partial P frame. It has all
+the same coding options but a different header.
+
+4 Bitstream
+
+All 32-bit values are in little endian byte order.
+
+4.1 I-Frame
+
+32bit 'ifrm'
+
+32bit chunk length
+
+32bit 0 (unknown)
+
+32bit bitstream size
+
+n byte bitstream
+
+32bit prefixstream size / 4
+
+32bit token_count
+
+n byte prefixstream
+
+4.1.1 Prefix stream
+
+start 8bit
+
+end 8bit
+
+do{
+
+ for(i=start; i<=end; i++)
+
+ frequency[i] 8bit
+
+ start 8bit
+
+ if(start==0) break;
+
+ end 8bit
+
+}
+
+while(not 32bit aligned)
+
+ 0 8bit
+
+for(i=0; i<token_count; i++)
+
+ prefix[i] prefix_vlc
+
+256 prefix_vlc
+
+Note: The prefix_vlc are stored so that each aligned
+32-bit word is stored in byteswapped order. This
+byteswapping is not done to the bitstream, just the
+prefix stream
+
+Frequency values which are not explicitly set are 0
+except that frequency[256]=1. This is the "end of picture"
+ code.
+
+4.1.2 Macroblock
+
+A macroblock bitstream is simply a bitstream of 6 blocks.
+
+4.1.3 Block
+
+dc_prefix prefix_vlc prefix stream
+
+dc_suffix dc_prefix bits bitstream
+
+i=1;
+
+while(i<64){
+
+ ac_prefix prefix_vlc prefix_stream
+
+ if(ac_prefix == 0xF0)
+
+ i+=16;
+
+ else if(ac_prefix == 0x00)
+
+ break;
+
+ else{
+
+ i+= ac_prefix>>4;
+
+ level_prefix= ac_prefix&0xF;
+
+ level_suffix level_prefix bits bitstream
+
+ block[ zigzag[i] ]= level;
+
+ i++;
+
+ }
+
+}
+
+4.2 P-Frame
+
+32bit 'pfrm'
+
+32bit chunk size
+
+32bit 0 (unknown)
+
+32bit unknown, perhaps a checksum
+
+32bit unknown
+
+32bit bitstream size
+
+32bit wordstream size
+
+32bit bytestream size
+
+n bytes bitstream, stored in byteswapped 32-bit words
+
+n bytes RGB16 wordstream, stored in little endian order
+
+n bytes bytestream
+
+4.2.1 Block
+
+block(){
+
+ mode vlc bitstream
+
+ if(mode==h_split || mode==v_split){
+
+ block()
+
+ block()
+
+ }
+
+ if(mode==mc || mode==mcdc)
+
+ mv 8bit bytestream
+
+ if(mode==dc || mode==mcdc)
+
+ dc 16bit wordstream
+
+ if(mode==esc){
+
+ col1 16bit wordstream
+
+ col2 16bit wordstream
+
+ }
+
+}
+
+4.3 C-Frame
+
+32bit 'cfrm'
+
+32bit chunk size
+
+32bit 0 (unknown)
+
+32bit frame number / frame id, this is the frame number
+where the frame will be shown, it is also the frame
+number at which the last cframe part of this frame will
+be; note, all parts of the same cframe contain the same
+id here
+
+32bit whole frame size
+
+* p frame, this is (unk, unk, bitstream size,
+wordstream size, ...) for the first c frame chunk of a
+c frame
+
+5 VLC Codes
+
+5.1 prefix_vlc in I frames
+
+The prefix_vlc table is generated from the frequencies
+stored in the prefix stream. Additionally, the element
+256 is added with an implicit frequency of 1. For the
+exact algorithm see libavcodec/4xm.c read_huffman_tables().
+
+5.2 level vlc in I Frames
+
+Identical to JPEG
+
++---------+---------+--------------+
+| prefix | vlc | level |
++---------+---------+--------------+
++---------+---------+--------------+
+| 0 | | 0 |
++---------+---------+--------------+
+| 1 | 0/1 | -1/1 |
++---------+---------+--------------+
+| 2 | 0X/1X | -3..-2/2..3 |
++---------+---------+--------------+
+| 3 | 0XX/1XX | -7..-4/4..7 |
++---------+---------+--------------+
+| ... | ... | ... |
++---------+---------+--------------+
+
+
+One way to decode this is:
+
+if(prefix){
+
+ v= get_bits(prefix);
+
+ if((v & (1<<(prefix-1))) == 0)
+
+ v= (-1 <<prefix)|(v+1);
+
+}else
+
+ v= 0;
+
+5.3 Block Mode Codes in P frames
+
+ For blocks 8x8, 8x4, 8x2, 4x8, 4x4, 4x2, 2x8, 2x4, 2x2
+
++--------+---------+
+| 0 | mc |
++--------+---------+
+| 10 | h_split |
++--------+---------+
+| 110 | v_split |
++--------+---------+
+| 1110 | skip |
++--------+---------+
+| 11110 | mcdc |
++--------+---------+
+| 11111 | dc |
++--------+---------+
+
+
+ For blocks 8x1, 4x1
+
++-------+---------+
+| 0 | mc |
++-------+---------+
+| 10 | h_split |
++-------+---------+
+| 110 | skip |
++-------+---------+
+| 1110 | mcdc |
++-------+---------+
+| 1111 | dc |
++-------+---------+
+
+
+ For blocks 1x8, 1x4
+
++-------+---------+
+| 0 | mc |
++-------+---------+
+| 10 | v_split |
++-------+---------+
+| 110 | skip |
++-------+---------+
+| 1110 | mcdc |
++-------+---------+
+| 1111 | dc |
++-------+---------+
+
+
+ For blocks 2x1, 1x2
+
++-------+------+
+| 0 | mc |
++-------+------+
+| 10 | skip |
++-------+------+
+| 110 | mcdc |
++-------+------+
+| 1110 | dc |
++-------+------+
+| 1111 | esc |
++-------+------+
+
+
+6 Applications and Platforms
+
+The 4XM video codec is intended for gaming
+applications. It is known to operate on these computing
+platforms:
+
+* PC/Microsoft Windows
+
+* Apple Macintosh
+
+* Sega Dreamcast
+
+* Nintendo Gameboy Advance
+
+While the Dreamcast and the targeted PC/Mac platforms
+have quite a bit of computing power (at least 200 MHz),
+the GBA has an ARM RISC CPU running at 16-17 MHz.
+
+The 4XM coding method seems a little odd in its mixture
+of YCbCr and RGB colorspaces. In the end, all of the
+output data is RGB565. It is useful to note that many
+video game consoles can efficiently manuipulate this
+colorspace with video hardware. By contrast, many video
+consoles have no, or very limited, facilites for direct
+YCbCr rendering, particularly planar YCbCr modes.
+
+One more note about interframe block addition: One
+possible approach to implementing this part of the
+method on console hardware, at least the Sega
+Dreamcast, would be to fill a texture with all zero
+values, skip all blocks that are not coded, and fill
+the coded blocks with the coded RGB565 difference.
+Then, the final texture could be added to the current
+frame. This also has the implicit side effect of
+saturating the addition so that the resulting pixels do
+not wrap around.
+
+7 Changelog
+
+0.01 2003-06-01
+initial version by Michael Niedermayer
+
+0.02 2003-06-07
+minor changes
+
+0.03 2003-06-08
+peer review, grammar/spelling/punctuation fixes and "
+Applications and Platforms" section by Mike Melanson
+minor changes by Michael
+
+0.04 2003-06-08
+minor changes by Mike Melanson and Michael Niedermayer
+
+8 Copyright
+
+Copyright 2003 Michael Niedermayer <michaelni at gmx.at>
+This text can be used under the GNU Free Documentation
+License or GNU General Public License. See [http://www.gnu.org/licenses/fdl.txt].
Added: trunk/docs/asv1.html
==============================================================================
--- (empty file)
+++ trunk/docs/asv1.html Mon Mar 19 19:52:05 2007
@@ -0,0 +1,742 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<meta name="GENERATOR" content="TtH 3.67">
+ <style type="text/css"> div.p { margin-top: 7pt;}</style>
+ <style type="text/css"><!--
+ td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
+ td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
+ td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
+ td div.norm {line-height:normal;}
+ span.roman {font-family: serif; font-style: normal; font-weight: normal;}
+ span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
+ span.overacc1 {position: relative; left: .6em; top: -1.2ex;} --></style>
+
+
+
+
+<title> \noindent ASUS V1/V2 Codecs</title>
+
+<h1 align="center"> ASUS V1/V2 Codecs </h1>
+
+<div class="p"><!----></div>
+
+<h1>Contents </h1>
+<a href="#tth_sEc1"
+>1 Introduction</a><br />
+<a href="#tth_sEc2"
+>2 Terms and definitions</a><br />
+<a href="#tth_sEc3"
+>3 Highlevel Description</a><br />
+ <a href="#tth_sEc3.1"
+>3.1 Picture</a><br />
+ <a href="#tth_sEc3.2"
+>3.2 Macroblock</a><br />
+ <a href="#tth_sEc3.3"
+>3.3 Block</a><br />
+ <a href="#tth_sEc3.4"
+>3.4 Coefficient group</a><br />
+ <a href="#tth_sEc3.5"
+>3.5 DC coefficient Dequantization</a><br />
+ <a href="#tth_sEc3.6"
+>3.6 AC coefficient Dequantization</a><br />
+
+<a href="#tth_sEc4"
+>4 Bitstream</a><br />
+ <a href="#tth_sEc4.1"
+>4.1 Fourcc</a><br />
+ <a href="#tth_sEc4.2"
+>4.2 Global (per file) Header</a><br />
+ <a href="#tth_sEc4.3"
+>4.3 Macroblock</a><br />
+ <a href="#tth_sEc4.4"
+>4.4 ASV1 Block</a><br />
+ <a href="#tth_sEc4.5"
+>4.5 ASV2 Block</a><br />
+<a href="#tth_sEc5"
+>5 VLC Codes</a><br />
+ <a href="#tth_sEc5.1"
+>5.1 ASV1</a><br />
+ <a href="#tth_sEc5.1.1"
+>5.1.1 Level</a><br />
+ <a href="#tth_sEc5.1.2"
+>5.1.2 Coded coefficient pattern</a><br />
+ <a href="#tth_sEc5.2"
+>5.2 ASV2</a><br />
+ <a href="#tth_sEc5.2.1"
+>5.2.1 First Coded coefficient pattern</a><br />
+ <a href="#tth_sEc5.2.2"
+>5.2.2 Coded coefficient pattern</a><br />
+ <a href="#tth_sEc5.2.3"
+>5.2.3 Level</a><br />
+<a href="#tth_sEc6"
+>6 Example ASV1 decoder </a><br />
+<a href="#tth_sEc7"
+>7 Changelog</a><br />
+<a href="#tth_sEc8"
+>8 Copyright</a><br />
+
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc1">
+1</a> Introduction</h2>
+
+<div class="p"><!----></div>
+ASV1/2 are purely intracoded DCT-based codecs, with a per file quantization
+parameter (QP), use 4:2:0 YCbCr colorspace and operate on macroblocks.<br />
+The latest version of this document is available at http://www.mplayerhq.hu/michael/asv1.{lyx,txt,html,ps}
+
+<div class="p"><!----></div>
+ This document assumes familiarity with mathematical and
+coding concepts such as the discrete cosine transform, quantization,
+YUV (YCbCr) colorspaces, macroblocks, and variable length codes (VLCs).
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc2">
+2</a> Terms and definitions</h2>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>AC</b></dt>
+ <dd>Any DCT coefficient for which the frequency in one or both both
+dimensions in non-zero.</dd>
+ <dt><b>DC</b></dt>
+ <dd>The DCT coefficient for which the frequency is zero in both dimensions</dd>
+ <dt><b>QP</b></dt>
+ <dd>Quantization Parameter</dd>
+ <dt><b>(I)DCT</b></dt>
+ <dd>(Inverse) Discrete Cosine Transform</dd>
+ <dt><b>VLC</b></dt>
+ <dd>Variable Length Code
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc3">
+3</a> Highlevel Description</h2>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.1">
+3.1</a> Picture</h3>
+
+<div class="p"><!----></div>
+The picture is split into macroblocks which are coded left->right,
+top->bottom, as long as MBs are completely within the width/height
+area that is divisible by 16. If width is not divisible by 16, the
+right column is coded after the main body. If height is not divisible
+by 16, the bottom strip is coded after the right column.
+
+<div class="p"><!----></div>
+Example: 56x56 sized image
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0</td><td align="center">1</td><td align="center">2</td><td align="center">9</td></tr>
+
+<tr><td align="center">3</td><td align="center">4</td><td align="center">5</td><td align="center">10</td></tr>
+
+<tr><td align="center">6</td><td align="center">7</td><td align="center">8</td><td align="center">11</td></tr>
+
+<tr><td align="center">12</td><td align="center">13</td><td align="center">14</td><td align="center">15</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.2">
+3.2</a> Macroblock</h3>
+
+<div class="p"><!----></div>
+16x16 luma + 8x8 chroma as 4 8x8 luma blocks and 2 8x8 chroma blocks
+<br />
+Y:
+<table border="1">
+<tr><td align="center">0</td><td align="center">1</td></tr>
+
+<tr><td align="center">2</td><td align="center">3</td></tr>
+</table>
+ Cb:
+<table border="1">
+<tr><td align="center">4</td></tr>
+</table>
+ Cr:
+<table border="1">
+<tr><td align="center">5</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.3">
+3.3</a> Block</h3>
+
+<div class="p"><!----></div>
+Contains 64(=8x8) coefficients in 16(=4x4) coefficient groups with
+4(=2x2) coefficients each<br />
+
+<table border="1">
+<tr><td align="center">0</td><td align="center">1</td><td align="center">5</td><td align="center">9</td></tr>
+
+<tr><td align="center">2</td><td align="center">3</td><td align="center">8</td><td align="center">12</td></tr>
+
+<tr><td align="center">4</td><td align="center">7</td><td align="center">11</td><td align="center">14</td></tr>
+
+<tr><td align="center">6</td><td align="center">10</td><td align="center">13</td><td align="center">15</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+Coefficients in the coefficient groups 10..15 cannot be coded (they
+must be 0) in ASV1.<br />
+The first coefficient (DC coefficient) in the first coefficient group
+must be coded as 0. Note it is coded seperately in the 8 bits prior
+to the AC coefficients.
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.4">
+3.4</a> Coefficient group</h3>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0</td><td align="center">1</td></tr>
+
+<tr><td align="center">2</td><td align="center">3</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.5">
+3.5</a> DC coefficient Dequantization</h3>
+
+<div class="p"><!----></div>
+c<sub>00</sub><font face="symbol">¢</font
+>=8c<sub>00</sub>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>c<sub>00</sub></b></dt>
+ <dd>quantized and coded DC coefficient</dd>
+ <dt><b>c<sub>00</sub><font face="symbol">¢</font
+></b></dt>
+ <dd>unquantized DC coefficient
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.6">
+3.6</a> AC coefficient Dequantization</h3>
+
+<div class="p"><!----></div>
+
+<b><br clear="all" /><table border="0" align="left" cellspacing="0" cellpadding="0"><tr><td nowrap="nowrap">c<sub>xy</sub><font face="symbol">¢</font
+>=</td><td nowrap="nowrap" align="center">
+c<sub>xy</sub>
+<div class="hrcomp"><hr noshade="noshade" size="1"/></div>16<br /></td><td nowrap="nowrap" align="center">
+</td><td align="left" class="cl"><font face="symbol">
+ê<br />ë
+</font> </td><td nowrap="nowrap" align="center">
+Dq<sub>xy</sub>
+<div class="hrcomp"><hr noshade="noshade" size="1"/></div>QP<br /></td><td align="left" class="cl"><font face="symbol">
+ú<br />û
+</font></td><td nowrap="nowrap" align="center">
+
+</td></tr></table><br /> </b>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>QP</b></dt>
+ <dd>Quantization Parameter from the global header</dd>
+ <dt><b>D</b></dt>
+ <dd>64 for ASV1, 128 forASV2</dd>
+ <dt><b>c</b></dt>
+ <dd>quantized and coded coefficient</dd>
+ <dt><b>c'</b></dt>
+ <dd>unquantized coefficient</dd>
+ <dt><b>q</b></dt>
+ <dd>ISO MPEG1 intra quantization matrix
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc4">
+4</a> Bitstream</h2>
+
+<div class="p"><!----></div>
+The bitstream in ASV1 is stored with byte-swapped 32bit words (24..31,
+16..23, 8..15, 0..7, 56..63, 48..55, 40..47, 32..39, ...)
+
+<div class="p"><!----></div>
+The bitstream in ASV2 is stored with the bits in each byte reversed
+so (7..0, 15..8, 23..16, 31..24, 39..32, ...)
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.1">
+4.1</a> Fourcc</h3>
+
+<div class="p"><!----></div>
+ASV1 / ASV2
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.2">
+4.2</a> Global (per file) Header</h3>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">Length in bits</td><td align="center">Value</td></tr>
+<tr><td></td></tr>
+<tr><td align="center">8</td><td align="center">QP</td></tr>
+
+<tr><td align="center">24</td><td align="center">unkown, 0 for ASV1</td></tr>
+
+<tr><td align="center">8</td><td align="center">'A'</td></tr>
+
+<tr><td align="center">8</td><td align="center">'S'</td></tr>
+
+<tr><td align="center">8</td><td align="center">'U'</td></tr>
+
+<tr><td align="center">8</td><td align="center">'S'</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.3">
+4.3</a> Macroblock</h3>
+
+<div class="p"><!----></div>
+Simply the bitstream of the 6 blocks
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.4">
+4.4</a> ASV1 Block</h3>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>8-bit</b></dt>
+ <dd>DC coefficient</dd>
+ <dt><b>.</b></dt>
+ <dd>for each coefficient group
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>2-5bit</b></dt>
+ <dd>Coded coefficient pattern</dd>
+ <dt><b>.</b></dt>
+ <dd>for each coded coefficient
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>2-11bit</b></dt>
+ <dd>level
+</dd>
+</dl>
+</dd>
+</dl></dd>
+ <dt><b>5bit</b></dt>
+ <dd>End Of Block
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.5">
+4.5</a> ASV2 Block</h3>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>4-bit</b></dt>
+ <dd>coefficient group count</dd>
+ <dt><b>8-bit</b></dt>
+ <dd>DC coefficient</dd>
+ <dt><b>2-4bit</b></dt>
+ <dd>First Coded coefficient pattern</dd>
+ <dt><b>.</b></dt>
+ <dd>for each coded coefficient
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>2-13bit</b></dt>
+ <dd>level
+</dd>
+</dl></dd>
+ <dt><b>.</b></dt>
+ <dd>for each coefficient group
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>2-6bit</b></dt>
+ <dd>Coded coefficient pattern</dd>
+ <dt><b>.</b></dt>
+ <dd>for each coded coefficient
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>2-13bit</b></dt>
+ <dd>level
+</dd>
+</dl>
+</dd>
+</dl>
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc5">
+5</a> VLC Codes</h2>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc5.1">
+5.1</a> ASV1</h3>
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc5.1.1">
+5.1.1</a> Level</h4>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0011</td><td align="center">-3</td></tr>
+
+<tr><td align="center">011</td><td align="center">-2</td></tr>
+
+<tr><td align="center">11</td><td align="center">-1</td></tr>
+
+<tr><td align="center">000xxxxxxxx</td><td align="center">xxxxxxxx</td></tr>
+
+<tr><td align="center">10</td><td align="center">1</td></tr>
+
+<tr><td align="center">010</td><td align="center">2</td></tr>
+
+<tr><td align="center">0010</td><td align="center">3</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+xxxxxxxx is a twos complement signed 8 bit nubmer (=int8_t)
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc5.1.2">
+5.1.2</a> Coded coefficient pattern</h4>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">00001</td><td align="center">14</td></tr>
+
+<tr><td align="center">00010</td><td align="center">13</td></tr>
+
+<tr><td align="center">...</td><td align="center">...</td></tr>
+
+<tr><td align="center">01101</td><td align="center">2</td></tr>
+
+<tr><td align="center">01110</td><td align="center">1</td></tr>
+
+<tr><td align="center">01111</td><td align="center">EOB</td></tr>
+
+<tr><td align="center">10</td><td align="center">0</td></tr>
+
+<tr><td align="center">11</td><td align="center">15</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc5.2">
+5.2</a> ASV2</h3>
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc5.2.1">
+5.2.1</a> First Coded coefficient pattern</h4>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">VLC</td><td align="center">CCP</td></tr>
+
+<tr><td align="center">00</td><td align="center">0111</td></tr>
+
+<tr><td align="center">01</td><td align="center">0000</td></tr>
+
+<tr><td align="center">100</td><td align="center">0110</td></tr>
+
+<tr><td align="center">101</td><td align="center">0100</td></tr>
+
+<tr><td align="center">1100</td><td align="center">0011</td></tr>
+
+<tr><td align="center">1101</td><td align="center">0001</td></tr>
+
+<tr><td align="center">1110</td><td align="center">0101</td></tr>
+
+<tr><td align="center">1111</td><td align="center">0010</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc5.2.2">
+5.2.2</a> Coded coefficient pattern</h4>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">VLC</td><td align="center">CCP</td></tr>
+
+<tr><td align="center">00</td><td align="center">0000</td></tr>
+
+<tr><td align="center">010</td><td align="center">0100</td></tr>
+
+<tr><td align="center">011</td><td align="center">1000</td></tr>
+
+<tr><td align="center">1000</td><td align="center">1010</td></tr>
+
+<tr><td align="center">1001</td><td align="center">1100</td></tr>
+
+<tr><td align="center">1010</td><td align="center">0010</td></tr>
+
+<tr><td align="center">1011</td><td align="center">1101</td></tr>
+
+<tr><td align="center">1100</td><td align="center">1111</td></tr>
+
+<tr><td align="center">1101</td><td align="center">1110</td></tr>
+
+<tr><td align="center">111000</td><td align="center">0111</td></tr>
+
+<tr><td align="center">111001</td><td align="center">0101</td></tr>
+
+<tr><td align="center">111010</td><td align="center">0011</td></tr>
+
+<tr><td align="center">111011</td><td align="center">0001</td></tr>
+
+<tr><td align="center">111100</td><td align="center">0110</td></tr>
+
+<tr><td align="center">111101</td><td align="center">1001</td></tr>
+
+<tr><td align="center">11111</td><td align="center">1011</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc5.2.3">
+5.2.3</a> Level</h4>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0000111111</td><td align="center">-31</td></tr>
+
+<tr><td align="center">...</td><td align="center">...</td></tr>
+
+<tr><td align="center">001111</td><td align="center">-7</td></tr>
+
+<tr><td align="center">001011</td><td align="center">-6</td></tr>
+
+<tr><td align="center">001101</td><td align="center">-5</td></tr>
+
+<tr><td align="center">001001</td><td align="center">-4</td></tr>
+
+<tr><td align="center">0111</td><td align="center">-3</td></tr>
+
+<tr><td align="center">0101</td><td align="center">-2</td></tr>
+
+<tr><td align="center">11</td><td align="center">-1</td></tr>
+
+<tr><td align="center">00000xxxxxxxx</td><td align="center">xxxxxxxx</td></tr>
+
+<tr><td align="center">10</td><td align="center">1</td></tr>
+
+<tr><td align="center">0100</td><td align="center">2</td></tr>
+
+<tr><td align="center">0110</td><td align="center">3</td></tr>
+
+<tr><td align="center">001000</td><td align="center">4</td></tr>
+
+<tr><td align="center">001100</td><td align="center">5</td></tr>
+
+<tr><td align="center">001010</td><td align="center">6</td></tr>
+
+<tr><td align="center">001110</td><td align="center">7</td></tr>
+
+<tr><td align="center">...</td><td align="center">...</td></tr>
+
+<tr><td align="center">0000111110</td><td align="center">31</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+xxxxxxxx is a twos complement signed 8 bit nubmer (=int8_t)
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc6">
+6</a> Example ASV1 decoder </h2>
+
+<div class="p"><!----></div>
+
+<ul>
+<li> foreach macroblock, decode Y0 Y1 Y2 Y3 U V blocks, Y blocks are arranged
+as: <br />
+Y0 Y1 <br />
+Y2 Y3
+<div class="p"><!----></div>
+</li>
+
+<li> foreach block:
+
+<div class="p"><!----></div>
+
+<ul>
+<li> DC coeff is the next 8 bits in the stream * 8 (this gives a range
+of 0..2040)
+<div class="p"><!----></div>
+</li>
+
+<li> foreach of up to 11 coefficient groups:
+
+<div class="p"><!----></div>
+
+<ul>
+<li> get vlc from ccp table, value should range from 0..16
+<div class="p"><!----></div>
+</li>
+
+<li> if value is 16, coefficient decode is done
+<div class="p"><!----></div>
+</li>
+
+<li> if 11th iteration, 16 should occur, else error
+<div class="p"><!----></div>
+</li>
+
+<li> ccp contains 4 bits at this point (3-0)
+<div class="p"><!----></div>
+</li>
+
+<li> each bit corresponds to a quantized coeff. #(iter. * 4 + bit)
+<div class="p"><!----></div>
+</li>
+
+<li> if 0, coeff. is 0 else get_level():
+
+<div class="p"><!----></div>
+
+<ul>
+<li> get vlc from level vlc table
+<div class="p"><!----></div>
+</li>
+
+<li> if vlc is 3, use the next 8 bits (as a signed number) as level
+<div class="p"><!----></div>
+</li>
+
+<li> else, use vlc - 3
+<div class="p"><!----></div>
+</li>
+
+<li> store coefficient
+<div class="p"><!----></div>
+</li>
+</ul>
+<div class="p"><!----></div>
+</li>
+</ul>
+<div class="p"><!----></div>
+</li>
+
+<li> dequantize, idct
+<div class="p"><!----></div>
+</li>
+</ul>
+<div class="p"><!----></div>
+</li>
+</ul>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc7">
+7</a> Changelog</h2>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>0.01</b></dt>
+ <dd>2003-05-21<br />
+initial version by Michael Niedermayer with some stuff from Mike Melanson</dd>
+ <dt><b>0.02</b></dt>
+ <dd>2003-05-21<br />
+spelling, punctuation, example decoder, various minor changes by Mike
+Melanson<br />
+various minor changes by Michael</dd>
+ <dt><b>0.03</b></dt>
+ <dd>2003-09-01<br />
+minor fixes and ASV2 by Michael</dd>
+ <dt><b>0.04</b></dt>
+ <dd>2004-08-24<br />
+clarify bitstream order by Michael
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc8">
+8</a> Copyright</h2>
+
+<div class="p"><!----></div>
+Copyright 2003 Michael Niedermayer <michaelni at gmx.at> <br />
+This text can be used under the GNU Free Documentation License or
+GNU General Public License<br />
+see http://www.gnu.org/licenses/fdl.txt
+
+<br /><br /><hr /><small>File translated from
+T<sub><font size="-1">E</font></sub>X
+by <a href="http://hutchinson.belmont.ma.us/tth/">
+T<sub><font size="-1">T</font></sub>H</a>,
+version 3.67.<br />On 1 Sep 2005, 03:40.</small>
+</html>
Added: trunk/docs/asv1.lyx
==============================================================================
--- (empty file)
+++ trunk/docs/asv1.lyx Mon Mar 19 19:52:05 2007
@@ -0,0 +1,2548 @@
+#LyX 1.3 created this file. For more info see http://www.lyx.org/
+\lyxformat 221
+\textclass article
+\language english
+\inputencoding auto
+\fontscheme default
+\graphics default
+\paperfontsize default
+\spacing single
+\papersize Default
+\paperpackage a4
+\use_geometry 0
+\use_amsmath 0
+\use_natbib 0
+\use_numerical_citations 0
+\paperorientation portrait
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation skip
+\defskip medskip
+\quotes_language english
+\quotes_times 2
+\papercolumns 1
+\papersides 1
+\paperpagestyle default
+
+\layout Title
+\noindent
+ASUS V1/V2 Codecs
+\layout Standard
+
+
+\begin_inset LatexCommand \tableofcontents{}
+
+\end_inset
+
+
+\layout Section
+
+Introduction
+\layout Standard
+
+ASV1/2 are purely intracoded DCT-based codecs, with a per file quantization
+ parameter (QP), use 4:2:0 YCbCr colorspace and operate on macroblocks.
+\newline
+The latest version of this document is available at http://www.mplayerhq.hu/~micha
+el/asv1.{lyx,txt,html,ps}
+\layout Standard
+\noindent
+This document assumes familiarity with mathematical and coding concepts
+ such as the discrete cosine transform, quantization, YUV (YCbCr) colorspaces,
+ macroblocks, and variable length codes (VLCs).
+\layout Section
+
+Terms and definitions
+\layout List
+\labelwidthstring 00.00.0000
+
+AC Any DCT coefficient for which the frequency in one or both both dimensions
+ in non-zero.
+\layout List
+\labelwidthstring 00.00.0000
+
+DC The DCT coefficient for which the frequency is zero in both dimensions
+\layout List
+\labelwidthstring 00.00.0000
+
+QP Quantization Parameter
+\layout List
+\labelwidthstring 00.00.0000
+
+(I)DCT (Inverse) Discrete Cosine Transform
+\layout List
+\labelwidthstring 00.00.0000
+
+VLC Variable Length Code
+\layout Section
+
+Highlevel Description
+\layout Subsection
+
+Picture
+\layout Standard
+
+The picture is split into macroblocks which are coded left->right, top->bottom,
+ as long as MBs are completely within the width/height area that is divisible
+ by 16.
+ If width is not divisible by 16, the right column is coded after the main
+ body.
+ If height is not divisible by 16, the bottom strip is coded after the right
+ column.
+\layout Standard
+
+Example: 56x56 sized image
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="4" columns="4">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+9
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+4
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+5
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+6
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+7
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+11
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+12
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+13
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+14
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+15
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Subsection
+
+Macroblock
+\layout Standard
+
+16x16 luma + 8x8 chroma as 4 8x8 luma blocks and 2 8x8 chroma blocks
+\newline
+Y:
+\begin_inset Tabular
+<lyxtabular version="3" rows="2" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+ Cb:
+\begin_inset Tabular
+<lyxtabular version="3" rows="1" columns="1">
+<features>
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+4
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+ Cr:
+\begin_inset Tabular
+<lyxtabular version="3" rows="1" columns="1">
+<features>
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+5
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Subsection
+
+Block
+\layout Standard
+
+Contains 64(=8x8) coefficients in 16(=4x4) coefficient groups with 4(=2x2)
+ coefficients each
+\newline
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="4" columns="4">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+5
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+9
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+12
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+4
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+7
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+11
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+14
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+6
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+13
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+15
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Standard
+
+Coefficients in the coefficient groups 10..15 cannot be coded (they must be
+ 0) in ASV1.
+\newline
+The first coefficient (DC coefficient) in the first coefficient group must
+ be coded as 0.
+ Note it is coded seperately in the 8 bits prior to the AC coefficients.
+\layout Subsection
+
+Coefficient group
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="2" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Subsection
+
+DC coefficient Dequantization
+\layout Standard
+
+
+\begin_inset Formula $c_{00}'=8c_{00}$
+\end_inset
+
+
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\begin_inset Formula $c_{00}$
+\end_inset
+
+ quantized and coded DC coefficient
+\layout List
+\labelwidthstring 00.00.0000
+
+
+\begin_inset Formula $c_{00}'$
+\end_inset
+
+ unquantized DC coefficient
+\layout Subsection
+
+AC coefficient Dequantization
+\layout Paragraph
+
+
+\begin_inset Formula $c_{xy}'=\frac{c_{xy}}{16}\left\lfloor \frac{Dq_{xy}}{QP}\right\rfloor $
+\end_inset
+
+
+\layout List
+\labelwidthstring 00.00.0000
+
+QP Quantization Parameter from the global header
+\layout List
+\labelwidthstring 00.00.0000
+
+D 64 for ASV1, 128 forASV2
+\layout List
+\labelwidthstring 00.00.0000
+
+c quantized and coded coefficient
+\layout List
+\labelwidthstring 00.00.0000
+
+c' unquantized coefficient
+\layout List
+\labelwidthstring 00.00.0000
+
+q ISO MPEG1 intra quantization matrix
+\layout Section
+
+Bitstream
+\layout Standard
+
+The bitstream in ASV1 is stored with byte-swapped 32bit words (24..31, 16..23,
+ 8..15, 0..7, 56..63, 48..55, 40..47, 32..39, ...)
+\layout Standard
+
+The bitstream in ASV2 is stored with the bits in each byte reversed so (7..0,
+ 15..8, 23..16, 31..24, 39..32, ...)
+\layout Subsection
+
+Fourcc
+\layout Standard
+
+ASV1 / ASV2
+\layout Subsection
+
+Global (per file) Header
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="7" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Length in bits
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+Value
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+QP
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+24
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+unkown, 0 for ASV1
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+'A'
+\end_inset
+</cell>
+</row>
+<row>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+'S'
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+'U'
+\end_inset
+</cell>
+</row>
+<row bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+8
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+'S'
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Subsection
+
+Macroblock
+\layout Standard
+
+Simply the bitstream of the 6 blocks
+\layout Subsection
+
+ASV1 Block
+\layout List
+\labelwidthstring 00.00.0000
+
+8-bit DC coefficient
+\layout List
+\labelwidthstring 00.00.0000
+
+.
+ for each coefficient group
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+2-5bit Coded coefficient pattern
+\layout List
+\labelwidthstring 00.00.0000
+
+.
+ for each coded coefficient
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+2-11bit level
+\end_deeper
+\end_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+5bit End Of Block
+\layout Subsection
+
+ASV2 Block
+\layout List
+\labelwidthstring 00.00.0000
+
+4-bit coefficient group count
+\layout List
+\labelwidthstring 00.00.0000
+
+8-bit DC coefficient
+\layout List
+\labelwidthstring 00.00.0000
+
+2-4bit First Coded coefficient pattern
+\layout List
+\labelwidthstring 00.00.0000
+
+.
+ for each coded coefficient
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+2-13bit level
+\end_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+.
+ for each coefficient group
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+2-6bit Coded coefficient pattern
+\layout List
+\labelwidthstring 00.00.0000
+
+.
+ for each coded coefficient
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+2-13bit level
+\end_deeper
+\end_deeper
+\layout Section
+
+VLC Codes
+\layout Subsection
+
+ASV1
+\layout Subsubsection
+
+Level
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="7" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0011
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-3
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+011
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-2
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+11
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-1
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+000xxxxxxxx
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+xxxxxxxx
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+010
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0010
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Standard
+
+xxxxxxxx is a twos complement signed 8 bit nubmer (=int8_t)
+\layout Subsubsection
+
+Coded coefficient pattern
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="8" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+00001
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+14
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+00010
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+13
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+01101
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+01110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+01111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+EOB
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+11
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+15
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Subsection
+
+ASV2
+\layout Subsubsection
+
+First Coded coefficient pattern
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="9" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+VLC
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+CCP
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+00
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0111
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+01
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0000
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+100
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0110
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+101
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0100
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1100
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0011
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1101
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0001
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0101
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0010
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Subsubsection
+
+Coded coefficient pattern
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="17" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+VLC
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+CCP
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+00
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0000
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+010
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0100
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+011
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1000
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1000
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1010
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1001
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1100
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1010
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0010
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1011
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1101
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1100
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1111
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1101
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1110
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+111000
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0111
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+111001
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0101
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+111010
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0011
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+111011
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0001
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+111100
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+0110
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+111101
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1001
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+11111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+
+\family roman
+\series medium
+\shape up
+\size normal
+\emph off
+\bar no
+\noun off
+\color none
+1011
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Subsubsection
+
+Level
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="19" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0000111111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-31
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-7
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001011
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-6
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001101
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-5
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001001
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-4
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0111
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-3
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0101
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-2
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+11
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+-1
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+00000xxxxxxxx
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+xxxxxxxx
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0100
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+3
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001000
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+4
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001100
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+5
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001010
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+6
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+7
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0000111110
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+31
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Standard
+
+xxxxxxxx is a twos complement signed 8 bit nubmer (=int8_t)
+\layout Section
+
+Example ASV1 decoder
+\layout Itemize
+
+foreach macroblock, decode Y0 Y1 Y2 Y3 U V blocks, Y blocks are arranged
+ as:
+\newline
+Y0 Y1
+\newline
+Y2 Y3
+\layout Itemize
+
+foreach block:
+\begin_deeper
+\layout Itemize
+
+DC coeff is the next 8 bits in the stream * 8 (this gives a range of 0..2040)
+\layout Itemize
+
+foreach of up to 11 coefficient groups:
+\begin_deeper
+\layout Itemize
+
+get vlc from ccp table, value should range from 0..16
+\layout Itemize
+
+if value is 16, coefficient decode is done
+\layout Itemize
+
+if 11th iteration, 16 should occur, else error
+\layout Itemize
+
+ccp contains 4 bits at this point (3-0)
+\layout Itemize
+
+each bit corresponds to a quantized coeff.
+ #(iter.
+ * 4 + bit)
+\layout Itemize
+
+if 0, coeff.
+ is 0 else get_level():
+\begin_deeper
+\layout Itemize
+
+get vlc from level vlc table
+\layout Itemize
+
+if vlc is 3, use the next 8 bits (as a signed number) as level
+\layout Itemize
+
+else, use vlc - 3
+\layout Itemize
+
+store coefficient
+\end_deeper
+\end_deeper
+\layout Itemize
+
+dequantize, idct
+\end_deeper
+\layout Section
+
+Changelog
+\layout List
+\labelwidthstring 00.00.0000
+
+0.01 2003-05-21
+\newline
+initial version by Michael Niedermayer with some stuff from Mike Melanson
+\layout List
+\labelwidthstring 00.00.0000
+
+0.02 2003-05-21
+\newline
+spelling, punctuation, example decoder, various minor changes by Mike Melanson
+\newline
+various minor changes by Michael
+\layout List
+\labelwidthstring 00.00.0000
+
+0.03 2003-09-01
+\newline
+minor fixes and ASV2 by Michael
+\layout List
+\labelwidthstring 00.00.0000
+
+0.04 2004-08-24
+\newline
+clarify bitstream order by Michael
+\layout Section
+
+Copyright
+\layout Standard
+
+Copyright 2003 Michael Niedermayer <michaelni at gmx.at>
+\newline
+This text can be used under the GNU Free Documentation License or GNU General
+ Public License
+\newline
+see http://www.gnu.org/licenses/fdl.txt
+\the_end
Added: trunk/docs/asv1.pdf
==============================================================================
Binary file. No diff available.
Added: trunk/docs/asv1.ps
==============================================================================
Binary file. No diff available.
Added: trunk/docs/asv1.txt
==============================================================================
--- (empty file)
+++ trunk/docs/asv1.txt Mon Mar 19 19:52:05 2007
@@ -0,0 +1,440 @@
+ASUS V1/V2 Codecs
+
+Table of Contents
+
+1 Introduction
+2 Terms and definitions
+3 Highlevel Description
+ 3.1 Picture
+ 3.2 Macroblock
+ 3.3 Block
+ 3.4 Coefficient group
+ 3.5 DC coefficient Dequantization
+ 3.6 AC coefficient Dequantization
+4 Bitstream
+ 4.1 Fourcc
+ 4.2 Global (per file) Header
+ 4.3 Macroblock
+ 4.4 ASV1 Block
+ 4.5 ASV2 Block
+5 VLC Codes
+ 5.1 ASV1
+ 5.1.1 Level
+ 5.1.2 Coded coefficient pattern
+ 5.2 ASV2
+ 5.2.1 First Coded coefficient pattern
+ 5.2.2 Coded coefficient pattern
+ 5.2.3 Level
+6 Example ASV1 decoder
+7 Changelog
+8 Copyright
+
+
+
+1 Introduction
+
+ASV1/2 are purely intracoded DCT-based codecs, with a
+per file quantization parameter (QP), use 4:2:0 YCbCr
+colorspace and operate on macroblocks.
+The latest version of this document is available at
+http://www.mplayerhq.hu/~michael/asv1.{lyx,txt,html,ps}
+
+This document assumes familiarity with mathematical and
+coding concepts such as the discrete cosine transform,
+quantization, YUV (YCbCr) colorspaces, macroblocks, and
+variable length codes (VLCs).
+
+2 Terms and definitions
+
+AC Any DCT coefficient for which the frequency in one
+or both both dimensions in non-zero.
+
+DC The DCT coefficient for which the frequency is zero
+in both dimensions
+
+QP Quantization Parameter
+
+(I)DCT (Inverse) Discrete Cosine Transform
+
+VLC Variable Length Code
+
+3 Highlevel Description
+
+3.1 Picture
+
+The picture is split into macroblocks which are coded
+left->right, top->bottom, as long as MBs are completely
+within the width/height area that is divisible by 16.
+If width is not divisible by 16, the right column is
+coded after the main body. If height is not divisible
+by 16, the bottom strip is coded after the right column.
+
+Example: 56x56 sized image
+
++-----+-----+-----+----+
+| 0 | 1 | 2 | 9 |
++-----+-----+-----+----+
+| 3 | 4 | 5 | 10 |
++-----+-----+-----+----+
+| 6 | 7 | 8 | 11 |
++-----+-----+-----+----+
+| 12 | 13 | 14 | 15 |
++-----+-----+-----+----+
+
+
+3.2 Macroblock
+
+16x16 luma + 8x8 chroma as 4 8x8 luma blocks and 2 8x8
+chroma blocks
+Y:+----+---+
+| 0 | 1 |
++----+---+
+| 2 | 3 |
++----+---+
+ Cb:+---+
+| 4 |
++---+
+ Cr:+---+
+| 5 |
++---+
+
+
+3.3 Block
+
+Contains 64(=8x8) coefficients in 16(=4x4) coefficient
+groups with 4(=2x2) coefficients each
++----+-----+-----+----+
+| 0 | 1 | 5 | 9 |
++----+-----+-----+----+
+| 2 | 3 | 8 | 12 |
++----+-----+-----+----+
+| 4 | 7 | 11 | 14 |
++----+-----+-----+----+
+| 6 | 10 | 13 | 15 |
++----+-----+-----+----+
+
+
+Coefficients in the coefficient groups 10..15 cannot be
+coded (they must be 0) in ASV1.
+The first coefficient (DC coefficient) in the first
+coefficient group must be coded as 0. Note it is coded
+seperately in the 8 bits prior to the AC coefficients.
+
+3.4 Coefficient group
+
++----+---+
+| 0 | 1 |
++----+---+
+| 2 | 3 |
++----+---+
+
+
+3.5 DC coefficient Dequantization
+
+ c_{00}'=8c_{00}
+
+ c_{00} quantized and coded DC coefficient
+
+ c_{00}' unquantized DC coefficient
+
+3.6 AC coefficient Dequantization
+
+ c_{xy}'=\frac{c_{xy}}{16}\left\lfloor \frac{Dq_{xy}}{QP}\right\rfloor
+
+QP Quantization Parameter from the global header
+
+D 64 for ASV1, 128 forASV2
+
+c quantized and coded coefficient
+
+c' unquantized coefficient
+
+q ISO MPEG1 intra quantization matrix
+
+4 Bitstream
+
+The bitstream in ASV1 is stored with byte-swapped 32bit
+words (24..31, 16..23, 8..15, 0..7, 56..63, 48..55,
+40..47, 32..39, ...)
+
+The bitstream in ASV2 is stored with the bits in each
+byte reversed so (7..0, 15..8, 23..16, 31..24, 39..32, ...)
+
+4.1 Fourcc
+
+ASV1 / ASV2
+
+4.2 Global (per file) Header
+
++-----------------+--------------------+
+| Length in bits | Value |
++-----------------+--------------------+
++-----------------+--------------------+
+| 8 | QP |
++-----------------+--------------------+
+| 24 | unkown, 0 for ASV1 |
++-----------------+--------------------+
+| 8 | 'A' |
++-----------------+--------------------+
+| 8 | 'S' |
++-----------------+--------------------+
+| 8 | 'U' |
++-----------------+--------------------+
+| 8 | 'S' |
++-----------------+--------------------+
+
+
+4.3 Macroblock
+
+Simply the bitstream of the 6 blocks
+
+4.4 ASV1 Block
+
+8-bit DC coefficient
+
+. for each coefficient group
+
+ 2-5bit Coded coefficient pattern
+
+ . for each coded coefficient
+
+ 2-11bit level
+
+5bit End Of Block
+
+4.5 ASV2 Block
+
+4-bit coefficient group count
+
+8-bit DC coefficient
+
+2-4bit First Coded coefficient pattern
+
+. for each coded coefficient
+
+ 2-13bit level
+
+. for each coefficient group
+
+ 2-6bit Coded coefficient pattern
+
+ . for each coded coefficient
+
+ 2-13bit level
+
+5 VLC Codes
+
+5.1 ASV1
+
+5.1.1 Level
+
++--------------+----------+
+| 0011 | -3 |
++--------------+----------+
+| 011 | -2 |
++--------------+----------+
+| 11 | -1 |
++--------------+----------+
+| 000xxxxxxxx | xxxxxxxx |
++--------------+----------+
+| 10 | 1 |
++--------------+----------+
+| 010 | 2 |
++--------------+----------+
+| 0010 | 3 |
++--------------+----------+
+
+
+xxxxxxxx is a twos complement signed 8 bit nubmer (=int8_t)
+
+5.1.2 Coded coefficient pattern
+
++--------+-----+
+| 00001 | 14 |
++--------+-----+
+| 00010 | 13 |
++--------+-----+
+| ... | ... |
++--------+-----+
+| 01101 | 2 |
++--------+-----+
+| 01110 | 1 |
++--------+-----+
+| 01111 | EOB |
++--------+-----+
+| 10 | 0 |
++--------+-----+
+| 11 | 15 |
++--------+-----+
+
+
+5.2 ASV2
+
+5.2.1 First Coded coefficient pattern
+
++-------+------+
+| VLC | CCP |
++-------+------+
+| 00 | 0111 |
++-------+------+
+| 01 | 0000 |
++-------+------+
+| 100 | 0110 |
++-------+------+
+| 101 | 0100 |
++-------+------+
+| 1100 | 0011 |
++-------+------+
+| 1101 | 0001 |
++-------+------+
+| 1110 | 0101 |
++-------+------+
+| 1111 | 0010 |
++-------+------+
+
+
+5.2.2 Coded coefficient pattern
+
++---------+------+
+| VLC | CCP |
++---------+------+
+| 00 | 0000 |
++---------+------+
+| 010 | 0100 |
++---------+------+
+| 011 | 1000 |
++---------+------+
+| 1000 | 1010 |
++---------+------+
+| 1001 | 1100 |
++---------+------+
+| 1010 | 0010 |
++---------+------+
+| 1011 | 1101 |
++---------+------+
+| 1100 | 1111 |
++---------+------+
+| 1101 | 1110 |
++---------+------+
+| 111000 | 0111 |
++---------+------+
+| 111001 | 0101 |
++---------+------+
+| 111010 | 0011 |
++---------+------+
+| 111011 | 0001 |
++---------+------+
+| 111100 | 0110 |
++---------+------+
+| 111101 | 1001 |
++---------+------+
+| 11111 | 1011 |
++---------+------+
+
+
+5.2.3 Level
+
++----------------+----------+
+| 0000111111 | -31 |
++----------------+----------+
+| ... | ... |
++----------------+----------+
+| 001111 | -7 |
++----------------+----------+
+| 001011 | -6 |
++----------------+----------+
+| 001101 | -5 |
++----------------+----------+
+| 001001 | -4 |
++----------------+----------+
+| 0111 | -3 |
++----------------+----------+
+| 0101 | -2 |
++----------------+----------+
+| 11 | -1 |
++----------------+----------+
+| 00000xxxxxxxx | xxxxxxxx |
++----------------+----------+
+| 10 | 1 |
++----------------+----------+
+| 0100 | 2 |
++----------------+----------+
+| 0110 | 3 |
++----------------+----------+
+| 001000 | 4 |
++----------------+----------+
+| 001100 | 5 |
++----------------+----------+
+| 001010 | 6 |
++----------------+----------+
+| 001110 | 7 |
++----------------+----------+
+| ... | ... |
++----------------+----------+
+| 0000111110 | 31 |
++----------------+----------+
+
+
+xxxxxxxx is a twos complement signed 8 bit nubmer (=int8_t)
+
+6 Example ASV1 decoder
+
+* foreach macroblock, decode Y0 Y1 Y2 Y3 U V blocks, Y
+ blocks are arranged as:
+ Y0 Y1
+ Y2 Y3
+
+* foreach block:
+
+ * DC coeff is the next 8 bits in the stream * 8 (this
+ gives a range of 0..2040)
+
+ * foreach of up to 11 coefficient groups:
+
+ * get vlc from ccp table, value should range from 0..16
+
+ * if value is 16, coefficient decode is done
+
+ * if 11th iteration, 16 should occur, else error
+
+ * ccp contains 4 bits at this point (3-0)
+
+ * each bit corresponds to a quantized coeff.
+ #(iter. * 4 + bit)
+
+ * if 0, coeff. is 0 else get_level():
+
+ * get vlc from level vlc table
+
+ * if vlc is 3, use the next 8 bits (as a signed
+ number) as level
+
+ * else, use vlc - 3
+
+ * store coefficient
+
+ * dequantize, idct
+
+7 Changelog
+
+0.01 2003-05-21
+initial version by Michael Niedermayer with some stuff
+from Mike Melanson
+
+0.02 2003-05-21
+spelling, punctuation, example decoder, various minor
+changes by Mike Melanson
+various minor changes by Michael
+
+0.03 2003-09-01
+minor fixes and ASV2 by Michael
+
+0.04 2004-08-24
+clarify bitstream order by Michael
+
+8 Copyright
+
+Copyright 2003 Michael Niedermayer <michaelni at gmx.at>
+This text can be used under the GNU Free Documentation
+License or GNU General Public License
+see http://www.gnu.org/licenses/fdl.txt
Added: trunk/docs/ffv1.html
==============================================================================
--- (empty file)
+++ trunk/docs/ffv1.html Mon Mar 19 19:52:05 2007
@@ -0,0 +1,724 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<meta name="GENERATOR" content="TtH 3.40">
+ <style type="text/css"> div.p { margin-top: 7pt;}</style>
+ <style type="text/css"><!--
+ td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
+ td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
+ td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
+ td div.norm {line-height:normal;}
+ span.roman {font-family: serif; font-style: normal; font-weight: normal;}
+ span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
+ span.overacc1 {position: relative; left: .6em; top: -1.2ex;} --></style>
+
+
+
+
+
+
+<title> \noindent Description of the FFV1 Video Codec</title>
+
+<h1 align="center"> Description of the FFV1 Video Codec </h1>
+
+<div class="p"><!----></div>
+
+<h3 align="center">by Michael Niedermayer <michaelni at gmx.at> </h3>
+
+<div class="p"><!----></div>
+
+<h1>Contents </h1>
+<a href="#tth_sEc1"
+>1 Introduction</a><br />
+<a href="#tth_sEc2"
+>2 Terms and Definitions</a><br />
+<a href="#tth_sEc3"
+>3 High-level Description</a><br />
+ <a href="#tth_sEc3.1"
+>3.1 Border</a><br />
+ <a href="#tth_sEc3.2"
+>3.2 Median predictor</a><br />
+ <a href="#tth_sEc3.3"
+>3.3 Context</a><br />
+ <a href="#tth_sEc3.4"
+>3.4 Quantization</a><br />
+ <a href="#tth_sEc3.5"
+>3.5 Colorspace</a><br />
+ <a href="#tth_sEc3.5.1"
+>3.5.1 JPEG2000-RCT</a><br />
+ <a href="#tth_sEc3.6"
+>3.6 Coding of the sample difference </a><br />
+ <a href="#tth_sEc3.6.1"
+>3.6.1 Arithmetic coding mode</a><br />
+
+
+
+ <a href="#tth_sEc3.6.2"
+>3.6.2 Huffman coding mode</a><br />
+
+
+
+
+
+
+<a href="#tth_sEc4"
+>4 Bitstream</a><br />
+ <a href="#tth_sEc4.1"
+>4.1 Frame</a><br />
+ <a href="#tth_sEc4.2"
+>4.2 Header</a><br />
+ <a href="#tth_sEc4.3"
+>4.3 Quant Table</a><br />
+<a href="#tth_sEc5"
+>5 Changelog</a><br />
+<a href="#tth_sEc6"
+>6 ToDo</a><br />
+<a href="#tth_sEc7"
+>7 Bibliography</a><br />
+<a href="#tth_sEc8"
+>8 Copyright</a><br />
+
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc1">
+1</a> Introduction</h2>
+
+<div class="p"><!----></div>
+The FFV1 video codec is a simple lossless intra only codec. It is
+still under development and the bitstream might change between versions.
+
+<div class="p"><!----></div>
+The latest version of this document is available at http://www.mplayerhq.hu/michael/ffv1.{lyx,txt,html,ps}
+
+<div class="p"><!----></div>
+ This document assumes familiarity with mathematical and
+coding concepts such as Arithmetic coding and YCbCr colorspaces.
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc2">
+2</a> Terms and Definitions</h2>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>CABAC</b></dt>
+ <dd>Context Adaptive Binary Arithmetic Coder[<a href="#H264" name="CITEH264">H264</a>]</dd>
+ <dt><b>RCT</b></dt>
+ <dd>Reversible component transform
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc3">
+3</a> High-level Description</h2>
+
+<div class="p"><!----></div>
+Each frame is split in 3 planes (Y, Cb, Cr). In the case of the normal
+YCbCr colorspace the Y plane is coded first followed by the Cb and
+Cr planes, in the case of the JPEG2000-RCT colorspace the lines are
+interleaved to reduce cache trashing as most likely the RCT will be
+immedeatly converted to RGB during decoding, the order of the lines
+in the interleaving is again Y,Cb,Cr.
+
+<div class="p"><!----></div>
+Samples within a plane are coded in raster scan order (left->right,
+top->bottom), each sample is predicted by the median predictor from
+samples in the same plane and the difference is stored
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.1">
+3.1</a> Border</h3>
+
+<div class="p"><!----></div>
+Samples above the coded picture are assumed to be 0, right of the
+coded picture are identical to the closest left sample and left of
+the coded picture are identical to the top right one
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">0</td><td align="center">0</td><td align="center">0</td><td align="center">0</td><td align="center">0</td></tr>
+<tr><td>
+<tr><td align="center">0</td><td align="center">a</td><td align="center">b</td><td align="center">c</td><td align="center">c</td></tr>
+
+<tr><td align="center">a</td><td align="center">d</td><td align="center"></td><td align="center">e</td><td align="center">e</td></tr>
+
+<tr><td align="center">d</td><td align="center">f</td><td align="center">g</td><td align="center">h</td><td align="center">h</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+Note, this is identical to [<a href="#JPEGLS" name="CITEJPEGLS">JPEGLS</a>]
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.2">
+3.2</a> Median predictor</h3>
+
+<div class="p"><!----></div>
+median(left, top, left + top - diag)
+
+<div class="p"><!----></div>
+left, top, diag are the left, top and lefttop samples
+
+<div class="p"><!----></div>
+Note, this is also used in [<a href="#JPEGLS" name="CITEJPEGLS">JPEGLS</a>,<a href="#HuffYuv" name="CITEHuffYuv">HUFFYUV</a>]
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.3">
+3.3</a> Context</h3>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center"></td><td align="center"></td><td align="center">T</td><td align="center"></td></tr>
+
+<tr><td align="center"></td><td align="center">tl</td><td align="center">t</td><td align="center">tr</td></tr>
+
+<tr><td align="center">L</td><td align="center">l</td><td align="center">X</td><td align="center"></td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+The quantized sample differences L-l, l-tl, tl-t, t-T, t-tr are used
+as context
+
+<div class="p"><!----></div>
+context=Q<sub>0</sub>[l<font face="symbol">-</font
+>tl]+|Q<sub>0</sub>|(Q<sub>1</sub>[tl<font face="symbol">-</font
+>t]+|Q<sub>1</sub>|(Q<sub>2</sub>[t<font face="symbol">-</font
+>tr]+|Q<sub>2</sub>|(Q<sub>3</sub>[L<font face="symbol">-</font
+>l]+|Q<sub>3</sub>|Q<sub>4</sub>[T<font face="symbol">-</font
+>t])))
+
+<div class="p"><!----></div>
+If context < 0 then -context is used and the difference between the
+sample and its predicted value is encoded with a flipped sign
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.4">
+3.4</a> Quantization</h3>
+
+<div class="p"><!----></div>
+There are 5 quantization tables for the 5 sample differences, both
+the number of quantization steps and their distribution are stored
+in the bitstream. Each quantization table has exactly 256 entries,
+and the 8 least significant bits of the sample difference are used
+as index
+
+<div class="p"><!----></div>
+Q<sub>i</sub>[a<font face="symbol">-</font
+>b]=Table<sub>i</sub>[(a<font face="symbol">-</font
+>b)&255]
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.5">
+3.5</a> Colorspace</h3>
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc3.5.1">
+3.5.1</a> JPEG2000-RCT</h4>
+
+<div class="p"><!----></div>
+Cb=b<font face="symbol">-</font
+>g
+
+<div class="p"><!----></div>
+Cr=r<font face="symbol">-</font
+>g
+
+<div class="p"><!----></div>
+Y=g+(Cb+Cr) >> 2
+
+<div class="p"><!----></div>
+g=Y<font face="symbol">-</font
+>(Cb+Cr) >> 2
+
+<div class="p"><!----></div>
+r=Cr+g
+
+<div class="p"><!----></div>
+b=Cb+g
+
+<div class="p"><!----></div>
+[<a href="#JPEG2000" name="CITEJPEG2000">JPEG2000</a>]
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc3.6">
+3.6</a> Coding of the sample difference </h3>
+
+<div class="p"><!----></div>
+Instead of coding the 9 (or 10 in the case of RCT) bits of the sample
+difference with huffman or CABAC coding only the 8 (or 9) least significant
+bits are used as thats enough the recover the original sample
+
+<div class="p"><!----></div>
+coder_ input=[(sample_ difference+2<sup>bits<font face="symbol">-</font
+>1</sup>)&(2<sup>bits</sup><font face="symbol">-</font
+>1)]<font face="symbol">-</font
+>2<sup>bits<font face="symbol">-</font
+>1</sup>
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc3.6.1">
+3.6.1</a> Arithmetic coding mode</h4>
+
+<div class="p"><!----></div>
+
+<b>Context Adaptive Binary Arithmetic Coding (CABAC) </b>
+
+<div class="p"><!----></div>
+The coder is borrowed from[<a href="#H264" name="CITEH264">H264</a>] and the reader is referred
+to that for further information, it is also noted that the author
+doesn't know if the coder is patented, so care must be taken if FFV1
+is used in countries where software patents are legal. But even if
+CABAC turns out to be patent free there is still some risk that other
+parts of FFV1 are covered by patents. By just looking at the very
+long list of patents which cover other relatively simple standards
+it is shown that the patent offices seem to pass nearly everything.
+In many cases the patents cover basic operations like subtraction
+or taking the median of 3 integers in a specific case like motion
+vectors.
+
+<div class="p"><!----></div>
+
+<b>Non binary values </b>
+
+<div class="p"><!----></div>
+<a name="sub:Non-binary-values">
+</a>To encode 8 or 9bit numbers as is needed
+in our case, we could simply encode each bit separately and use the
+past bits as context, but that would mean 255 contexts per 8bit symbol
+which is not only a waste of memory but also requires more past data
+to reach reasonable good estimate of the probabilities. Alternatively
+simply assuming a laplacian distribution and only dealing with its
+variance and mean like we do in huffman coding mode would be another
+possibility, but due to flexibility and simplicity, another method
+was chosen, which simply uses a single symbol to encode if a number
+is 0 and if not encodes the number using its exponent,mantisse and
+sign, the exact contexts which are used can probably better be described
+by the following code then by some english text
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+put_symbol(CABACContext *c, uint8_t *state, int v, int is_signed, int max_exp){
+
+<div class="p"><!----></div>
+ int i;
+
+<div class="p"><!----></div>
+ if(v){
+
+<div class="p"><!----></div>
+ const int a= ABS(v);
+
+<div class="p"><!----></div>
+ const int e= av_log2(a);
+
+<div class="p"><!----></div>
+ put_cabac(c, state+0, 0);
+
+<div class="p"><!----></div>
+ for(i=0; i<e; i++){
+
+<div class="p"><!----></div>
+ put_cabac(c, state+1+i, 1); //1..8
+
+<div class="p"><!----></div>
+ }
+
+<div class="p"><!----></div>
+ if(e<max_exp){
+
+<div class="p"><!----></div>
+ put_cabac(c, state+1+i, 0); //1..8
+
+<div class="p"><!----></div>
+ for(i=e-1; i>=0; i--){
+
+<div class="p"><!----></div>
+ put_cabac(c, state+16+e+i, (a> >i)&1); //17..29
+
+<div class="p"><!----></div>
+ }
+
+<div class="p"><!----></div>
+ if(is_signed)
+
+<div class="p"><!----></div>
+ put_cabac(c, state+9 + e, v < 0); //9..16
+
+<div class="p"><!----></div>
+ }
+
+<div class="p"><!----></div>
+ }else{
+
+<div class="p"><!----></div>
+ put_cabac(c, state+0, 1);
+
+<div class="p"><!----></div>
+ }
+
+<div class="p"><!----></div>
+}
+
+<div class="p"><!----></div>
+</dd>
+</dl>max_exp is 7 unless the RCT is used, in which case it is 8 for the
+samples in a plane and 7 for the elements in the header
+
+<div class="p"><!----></div>
+is_signed is 1 for encoding of the samples within a plane or line,
+and 0 for the elements of the header
+
+<div class="p"><!----></div>
+
+<b>Initial values for the context model </b>
+
+<div class="p"><!----></div>
+At keyframes all CABAC state variables are set to 0 except number
+7 which is set to 124, number 7 is used to select between -127..-64,64..127
+and -128 which should explain the strong favoring of the earlier
+
+<div class="p"><!----></div>
+ <h4><a name="tth_sEc3.6.2">
+3.6.2</a> Huffman coding mode</h4>
+
+<div class="p"><!----></div>
+Uses golomb rice codes. The VLC code is split in 2 parts, the prefix
+stores the most significant bits, the suffix stores the k least significant
+bits or stores the whole number in the ESC case
+
+<div class="p"><!----></div>
+
+<b>Prefix </b>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">bits</td><td align="center">value</td></tr>
+<tr><td>
+<tr><td align="center">1</td><td align="center">0</td></tr>
+
+<tr><td align="center">01</td><td align="center">1</td></tr>
+
+<tr><td align="center">...</td><td align="center">...</td></tr>
+
+<tr><td align="center">0000 0000 0001</td><td align="center">11</td></tr>
+
+<tr><td align="center">0000 0000 0000</td><td align="center">ESC</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+
+<b>Suffix </b>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>non ESC</b></dt>
+ <dd>the k least significant bits MSB first</dd>
+ <dt><b>ESC</b></dt>
+ <dd>the value - 11, in MSB first order, ESC may only be used if
+the value cannot be coded as non ESC
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+
+<b>Examples </b>
+
+<div class="p"><!----></div>
+
+<table border="1">
+<tr><td align="center">k</td><td align="center">bits</td><td align="center">value</td></tr>
+<tr><td>
+<tr><td align="center">0</td><td align="center">1</td><td align="center">0</td></tr>
+
+<tr><td align="center">0</td><td align="center">001</td><td align="center">2</td></tr>
+
+<tr><td align="center">2</td><td align="center">1 00</td><td align="center">0</td></tr>
+
+<tr><td align="center">2</td><td align="center">1 10</td><td align="center">2</td></tr>
+
+<tr><td align="center">2</td><td align="center">01 01</td><td align="center">5</td></tr>
+
+<tr><td align="center">any</td><td align="center">000000000000 10000000</td><td align="center">139</td></tr>
+</table>
+
+
+<div class="p"><!----></div>
+
+<b>run mode </b>
+
+<div class="p"><!----></div>
+run mode is entered when the context is 0, and left as soon as a non
+0 difference is found, the level is identical to the predicted one,
+the run and the first different level is coded
+
+<div class="p"><!----></div>
+
+<b>run length coding </b>
+
+<div class="p"><!----></div>
+
+<b>level coding </b>
+
+<div class="p"><!----></div>
+is identical to the normal difference coding with the exception that
+the 0 value is removed as it cant occur
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+ <dt><b></b></dt>
+ <dd>
+if(diff>0) diff--;
+
+<div class="p"><!----></div>
+encode(diff);
+</dd>
+</dl>
+Note, this is different from JPEG-LS, which doesn't use prediction
+in run mode, and uses a different encoding and context model for the
+last difference, on a small set of test samples the use of prediction
+improved the compression rate a bit
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc4">
+4</a> Bitstream</h2>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>b</b></dt>
+ <dd>CABAC 1-bit symbol</dd>
+ <dt><b>v</b></dt>
+ <dd>7bit unsigned symbol coded with the method described in <a href="#sub:Non-binary-values">3.6.1</a>
+</dd>
+</dl>
+The same context which is initialized to 0 is used for all fields
+in the header
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.1">
+4.1</a> Frame</h3>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>b</b></dt>
+ <dd>keyframe</dd>
+ <dt><b>if(keyframe)</b></dt>
+ <dd>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>Header</b></dt>
+ <dd>
+</dd>
+</dl></dd>
+ <dt><b>if(JPEG2000_RCT){</b></dt>
+ <dd>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>for(y=0; y<height; y++){</b></dt>
+ <dd>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>LumaLine[y]</b></dt>
+ <dd> </dd>
+ <dt><b>CbLine[y]</b></dt>
+ <dd> </dd>
+ <dt><b>CrLine[y]</b></dt>
+ <dd>
+</dd>
+</dl></dd>
+ <dt><b>}</b></dt>
+ <dd>
+</dd>
+</dl></dd>
+ <dt><b>}else{</b></dt>
+ <dd>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>LumaPlane</b></dt>
+ <dd> </dd>
+ <dt><b>CbPlane</b></dt>
+ <dd> </dd>
+ <dt><b>CrPlane</b></dt>
+ <dd>
+</dd>
+</dl></dd>
+ <dt><b>}</b></dt>
+ <dd>
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.2">
+4.2</a> Header</h3>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>v</b></dt>
+ <dd>Version</dd>
+ <dt><b>v</b></dt>
+ <dd>coder type (0-> golomb rice, 1-> CABAC)</dd>
+ <dt><b>v</b></dt>
+ <dd>Colorspace type (0->YCbCr, 1->JPEG2000_RCT)</dd>
+ <dt><b>b</b></dt>
+ <dd>grayscale</dd>
+ <dt><b>v</b></dt>
+ <dd>log2_h_chroma_subsample (chroma_ width=2<sup><font face="symbol">-</font
+>log2_ h_ chroma_ subsample</sup>luma_ width)</dd>
+ <dt><b>v</b></dt>
+ <dd>log2_v_chroma_subsample (chroma_ height=2<sup><font face="symbol">-</font
+>log2_ v_ chroma_ subsample</sup>luma_ height)</dd>
+ <dt><b>b</b></dt>
+ <dd>alpha plane</dd>
+ <dt><b>x</b></dt>
+ <dd>Quantization tables
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h3><a name="tth_sEc4.3">
+4.3</a> Quant Table</h3>
+
+<div class="p"><!----></div>
+The quantization tables are simply stored by storing the number of
+equal entries -1 of the first half of the table using the method described
+in <a href="#sub:Non-binary-values">3.6.1</a>, the second half doesn't need to be
+stored as it is identical to the first with flipped sign
+
+<div class="p"><!----></div>
+example:<br />
+Table: 0 0 1 1 1 1 2 2-2-2-2-1-1-1-1 0<br />
+Stored values: 1, 3, 1
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc5">
+5</a> Changelog</h2>
+
+<div class="p"><!----></div>
+
+<dl compact="compact">
+
+
+
+
+ <dt><b>0.01</b></dt>
+ <dd>2003-06-09<br />
+initial version by Michael Niedermayer</dd>
+ <dt><b>0.02</b></dt>
+ <dd>2004-02-15<br />
+update to match implementation (significant changes)</dd>
+ <dt><b>0.03</b></dt>
+ <dd>2004-02-18<br />
+"Boarder"->"Border" by Jim Leonard<br />
+huffyuv url by Felix Buenemann<br />
+minor fixes by me</dd>
+ <dt><b>0.04</b></dt>
+ <dd>2004-03-19<br />
+new huffyuv url by Raphael Clifford as old one is down
+</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc6">
+6</a> ToDo</h2>
+
+<div class="p"><!----></div>
+
+<ul>
+<li> mean,k estimation for the golomb rice codes<br /><br /></li>
+
+<li> bitstream end handling<br /><br /></li>
+
+<li> spelling errors<br /><br /></li>
+</ul>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc7">
+7</a> Bibliography</h2>
+
+<div class="p"><!----></div>
+
+<h2>References</h2>
+
+<dl compact="compact">
+ <dt><a href="#CITEJPEGLS" name="JPEGLS">[JPEGLS]</a></dt><dd>JPEG-LS FCD 14495 <a href="http://www.jpeg.org/public/fcd14495p.pdf"><tt>http://www.jpeg.org/public/fcd14495p.pdf</tt></a>
+</dd>
+ <dt><a href="#CITEH264" name="H264">[H264]</a></dt><dd>H.264 Draft <a href="http://bs.hhi.de/~wiegand/JVT-G050.pdf"><tt>http://bs.hhi.de/~wiegand/JVT-G050.pdf</tt></a>
+</dd>
+ <dt><a href="#CITEHuffYuv" name="HuffYuv">[HUFFYUV]</a></dt><dd>Huffyuv <a href="http://cultact-server.novi.dk/kpo/huffyuv/huffyuv.html"><tt>http://cultact-server.novi.dk/kpo/huffyuv/huffyuv.html</tt></a>
+</dd>
+ <dt><a href="#CITEFFMPEG" name="FFMPEG">[FFMPEG]</a></dt><dd>FFmpeg <a href="http://ffmpeg.org"><tt>http://ffmpeg.org</tt></a>
+</dd>
+ <dt><a href="#CITEJPEG2000" name="JPEG2000">[JPEG2000]</a></dt><dd>JPEG2000 url</dd>
+</dl>
+
+<div class="p"><!----></div>
+ <h2><a name="tth_sEc8">
+8</a> Copyright</h2>
+
+<div class="p"><!----></div>
+Copyright 2003,2004 Michael Niedermayer <michaelni at gmx.at> <br />
+This text can be used under the GNU Free Documentation License or
+GNU General Public License. See <a href="http://www.gnu.org/licenses/fdl.txt"><tt>http://www.gnu.org/licenses/fdl.txt</tt></a>.
+
+<br /><br /><hr /><small>File translated from
+T<sub><font size="-1">E</font></sub>X
+by <a href="http://hutchinson.belmont.ma.us/tth/">
+T<sub><font size="-1">T</font></sub>H</a>,
+version 3.40.<br />On 19 Mar 2004, 17:11.</small>
+</html>
Added: trunk/docs/ffv1.lyx
==============================================================================
--- (empty file)
+++ trunk/docs/ffv1.lyx Mon Mar 19 19:52:05 2007
@@ -0,0 +1,1293 @@
+#LyX 1.3 created this file. For more info see http://www.lyx.org/
+\lyxformat 221
+\textclass article
+\language english
+\inputencoding auto
+\fontscheme default
+\graphics default
+\paperfontsize default
+\spacing single
+\papersize Default
+\paperpackage a4
+\use_geometry 0
+\use_amsmath 0
+\use_natbib 0
+\use_numerical_citations 0
+\paperorientation portrait
+\secnumdepth 3
+\tocdepth 3
+\paragraph_separation skip
+\defskip medskip
+\quotes_language english
+\quotes_times 2
+\papercolumns 1
+\papersides 1
+\paperpagestyle default
+
+\layout Title
+\noindent
+Description of the FFV1 Video Codec
+\layout Author
+
+by Michael Niedermayer <michaelni at gmx.at>
+\layout Standard
+
+
+\begin_inset LatexCommand \tableofcontents{}
+
+\end_inset
+
+
+\layout Section
+
+Introduction
+\layout Standard
+
+The FFV1 video codec is a simple lossless intra only codec.
+ It is still under development and the bitstream might change between versions.
+
+\layout Standard
+
+The latest version of this document is available at http://www.mplayerhq.hu/~micha
+el/ffv1.{lyx,txt,html,ps}
+\layout Standard
+\noindent
+This document assumes familiarity with mathematical and coding concepts
+ such as Arithmetic coding and YCbCr colorspaces.
+\layout Section
+
+Terms and Definitions
+\layout List
+\labelwidthstring 00.00.0000
+
+CABAC Context Adaptive Binary Arithmetic Coder
+\begin_inset LatexCommand \cite{H264}
+
+\end_inset
+
+
+\layout List
+\labelwidthstring 00.00.0000
+
+RCT Reversible component transform
+\layout Section
+
+High-level Description
+\layout Standard
+
+Each frame is split in 3 planes (Y, Cb, Cr).
+ In the case of the normal YCbCr colorspace the Y plane is coded first followed
+ by the Cb and Cr planes, in the case of the JPEG2000-RCT colorspace the
+ lines are interleaved to reduce cache trashing as most likely the RCT will
+ be immedeatly converted to RGB during decoding, the order of the lines
+ in the interleaving is again Y,Cb,Cr.
+\layout Standard
+
+Samples within a plane are coded in raster scan order (left->right, top->bottom)
+, each sample is predicted by the median predictor from samples in the same
+ plane and the difference is stored
+\layout Subsection
+
+Border
+\layout Standard
+
+Samples above the coded picture are assumed to be 0, right of the coded
+ picture are identical to the closest left sample and left of the coded
+ picture are identical to the top right one
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="4" columns="5">
+<features>
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+a
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+b
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+c
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+c
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+a
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+d
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+e
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+e
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+d
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+f
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+g
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+h
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+h
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Standard
+
+Note, this is identical to
+\begin_inset LatexCommand \cite{JPEGLS}
+
+\end_inset
+
+
+\layout Subsection
+
+Median predictor
+\layout Standard
+
+median(left, top, left + top - diag)
+\layout Standard
+
+left, top, diag are the left, top and lefttop samples
+\layout Standard
+
+Note, this is also used in
+\begin_inset LatexCommand \cite{JPEGLS,HuffYuv}
+
+\end_inset
+
+
+\layout Subsection
+
+Context
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="3" columns="4">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+T
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+tl
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+t
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+tr
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+L
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+l
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+X
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Standard
+
+The quantized sample differences L-l, l-tl, tl-t, t-T, t-tr are used as
+ context
+\layout Standard
+
+
+\begin_inset Formula $context=Q_{0}[l-tl]+\left|Q_{0}\right|(Q_{1}[tl-t]+\left|Q_{1}\right|(Q_{2}[t-tr]+\left|Q_{2}\right|(Q_{3}[L-l]+\left|Q_{3}\right|Q_{4}[T-t])))$
+\end_inset
+
+
+\layout Standard
+
+If context < 0 then -context is used and the difference between the sample
+ and its predicted value is encoded with a flipped sign
+\layout Subsection
+
+Quantization
+\layout Standard
+
+There are 5 quantization tables for the 5 sample differences, both the number
+ of quantization steps and their distribution are stored in the bitstream.
+ Each quantization table has exactly 256 entries, and the 8 least significant
+ bits of the sample difference are used as index
+\layout Standard
+
+
+\begin_inset Formula $Q_{i}[a-b]=Table_{i}[(a-b)\&255]$
+\end_inset
+
+
+\layout Subsection
+
+Colorspace
+\layout Subsubsection
+
+JPEG2000-RCT
+\layout Standard
+
+
+\begin_inset Formula $Cb=b-g$
+\end_inset
+
+
+\layout Standard
+
+
+\begin_inset Formula $Cr=r-g$
+\end_inset
+
+
+\layout Standard
+
+
+\begin_inset Formula $Y=g+(Cb+Cr)>>2$
+\end_inset
+
+
+\layout Standard
+
+
+\begin_inset Formula $g=Y-(Cb+Cr)>>2$
+\end_inset
+
+
+\layout Standard
+
+
+\begin_inset Formula $r=Cr+g$
+\end_inset
+
+
+\layout Standard
+
+
+\begin_inset Formula $b=Cb+g$
+\end_inset
+
+
+\layout Standard
+
+
+\begin_inset LatexCommand \cite{JPEG2000}
+
+\end_inset
+
+
+\layout Subsection
+
+Coding of the sample difference
+\layout Standard
+
+Instead of coding the 9 (or 10 in the case of RCT) bits of the sample difference
+ with huffman or CABAC coding only the 8 (or 9) least significant bits are
+ used as thats enough the recover the original sample
+\layout Standard
+
+
+\begin_inset Formula $coder\_ input=\left[\left(sample\_ difference+2^{bits-1}\right)\&\left(2^{bits}-1\right)\right]-2^{bits-1}$
+\end_inset
+
+
+\layout Subsubsection
+
+Arithmetic coding mode
+\layout Paragraph
+
+Context Adaptive Binary Arithmetic Coding (CABAC)
+\layout Standard
+
+The coder is borrowed from
+\begin_inset LatexCommand \cite{H264}
+
+\end_inset
+
+ and the reader is referred to that for further information, it is also
+ noted that the author doesn't know if the coder is patented, so care must
+ be taken if FFV1 is used in countries where software patents are legal.
+ But even if CABAC turns out to be patent free there is still some risk
+ that other parts of FFV1 are covered by patents.
+ By just looking at the very long list of patents which cover other relatively
+ simple standards it is shown that the patent offices seem to pass nearly
+ everything.
+ In many cases the patents cover basic operations like subtraction or taking
+ the median of 3 integers in a specific case like motion vectors.
+\layout Paragraph
+
+Non binary values
+\layout Standard
+
+
+\begin_inset LatexCommand \label{sub:Non-binary-values}
+
+\end_inset
+
+To encode 8 or 9bit numbers as is needed in our case, we could simply encode
+ each bit separately and use the past bits as context, but that would mean
+ 255 contexts per 8bit symbol which is not only a waste of memory but also
+ requires more past data to reach reasonable good estimate of the probabilities.
+ Alternatively simply assuming a laplacian distribution and only dealing
+ with its variance and mean like we do in huffman coding mode would be another
+ possibility, but due to flexibility and simplicity, another method was
+ chosen, which simply uses a single symbol to encode if a number is 0 and
+ if not encodes the number using its exponent,mantisse and sign, the exact
+ contexts which are used can probably better be described by the following
+ code then by some english text
+\layout LyX-Code
+
+put_symbol(CABACContext *c, uint8_t *state, int v, int is_signed, int max_exp){
+
+\layout LyX-Code
+
+ int i;
+\layout LyX-Code
+
+ if(v){
+\layout LyX-Code
+
+ const int a= ABS(v);
+\layout LyX-Code
+
+ const int e= av_log2(a);
+\layout LyX-Code
+
+ put_cabac(c, state+0, 0);
+\layout LyX-Code
+
+ for(i=0; i<e; i++){
+\layout LyX-Code
+
+ put_cabac(c, state+1+i, 1); //1..8
+\layout LyX-Code
+
+ }
+\layout LyX-Code
+
+ if(e<max_exp){
+\layout LyX-Code
+
+ put_cabac(c, state+1+i, 0); //1..8
+\layout LyX-Code
+
+ for(i=e-1; i>=0; i--){
+\layout LyX-Code
+
+ put_cabac(c, state+16+e+i, (a>>i)&1); //17..29
+\layout LyX-Code
+
+ }
+\layout LyX-Code
+
+ if(is_signed)
+\layout LyX-Code
+
+ put_cabac(c, state+9 + e, v < 0); //9..16
+\layout LyX-Code
+
+ }
+\layout LyX-Code
+
+ }else{
+\layout LyX-Code
+
+ put_cabac(c, state+0, 1);
+\layout LyX-Code
+
+ }
+\layout LyX-Code
+
+}
+\layout LyX-Code
+
+\layout Standard
+
+max_exp is 7 unless the RCT is used, in which case it is 8 for the samples
+ in a plane and 7 for the elements in the header
+\layout Standard
+
+is_signed is 1 for encoding of the samples within a plane or line, and 0
+ for the elements of the header
+\layout Paragraph
+
+Initial values for the context model
+\layout Standard
+
+At keyframes all CABAC state variables are set to 0 except number 7 which
+ is set to 124, number 7 is used to select between -127..-64,64..127 and -128
+ which should explain the strong favoring of the earlier
+\layout Subsubsection
+
+Huffman coding mode
+\layout Standard
+
+Uses golomb rice codes.
+ The VLC code is split in 2 parts, the prefix stores the most significant
+ bits, the suffix stores the k least significant bits or stores the whole
+ number in the ESC case
+\layout Paragraph
+
+Prefix
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="6" columns="2">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+bits
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+value
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+01
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+...
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0000 0000 0001
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+11
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0000 0000 0000
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+ESC
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Paragraph
+
+Suffix
+\layout List
+\labelwidthstring 00.00.0000
+
+non\SpecialChar ~
+ESC the k least significant bits MSB first
+\layout List
+\labelwidthstring 00.00.0000
+
+ESC the value - 11, in MSB first order, ESC may only be used if the value
+ cannot be coded as non ESC
+\layout Paragraph
+
+Examples
+\layout Standard
+
+
+\begin_inset Tabular
+<lyxtabular version="3" rows="7" columns="3">
+<features>
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" width="0">
+<column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+k
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+bits
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+value
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+001
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1 00
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+0
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+1 10
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+</row>
+<row topline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+2
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+01 01
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+5
+\end_inset
+</cell>
+</row>
+<row topline="true" bottomline="true">
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+any
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+000000000000 10000000
+\end_inset
+</cell>
+<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
+\begin_inset Text
+
+\layout Standard
+
+139
+\end_inset
+</cell>
+</row>
+</lyxtabular>
+
+\end_inset
+
+
+\layout Paragraph
+
+run mode
+\layout Standard
+
+run mode is entered when the context is 0, and left as soon as a non 0 differenc
+e is found, the level is identical to the predicted one, the run and the
+ first different level is coded
+\layout Paragraph
+
+run length coding
+\layout Paragraph
+
+level coding
+\layout Standard
+
+is identical to the normal difference coding with the exception that the
+ 0 value is removed as it cant occur
+\layout LyX-Code
+
+if(diff>0) diff--;
+\layout LyX-Code
+
+encode(diff);
+\layout Standard
+
+Note, this is different from JPEG-LS, which doesn't use prediction in run
+ mode, and uses a different encoding and context model for the last difference,
+ on a small set of test samples the use of prediction improved the compression
+ rate a bit
+\layout Section
+
+Bitstream
+\layout List
+\labelwidthstring 00.00.0000
+
+b CABAC 1-bit symbol
+\layout List
+\labelwidthstring 00.00.0000
+
+v 7bit unsigned symbol coded with the method described in
+\begin_inset LatexCommand \ref{sub:Non-binary-values}
+
+\end_inset
+
+
+\layout Standard
+
+The same context which is initialized to 0 is used for all fields in the
+ header
+\layout Subsection
+
+Frame
+\layout List
+\labelwidthstring 00.00.0000
+
+b keyframe
+\layout List
+\labelwidthstring 00.00.0000
+
+if(keyframe)
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+Header
+\end_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+if(JPEG2000_RCT){
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+for(y=0;\SpecialChar ~
+y<height;\SpecialChar ~
+y++){
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+LumaLine[y]
+\layout List
+\labelwidthstring 00.00.0000
+
+CbLine[y]
+\layout List
+\labelwidthstring 00.00.0000
+
+CrLine[y]
+\end_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+}
+\end_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+}else{
+\begin_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+LumaPlane
+\layout List
+\labelwidthstring 00.00.0000
+
+CbPlane
+\layout List
+\labelwidthstring 00.00.0000
+
+CrPlane
+\end_deeper
+\layout List
+\labelwidthstring 00.00.0000
+
+}
+\layout Subsection
+
+Header
+\layout List
+\labelwidthstring 00.00.0000
+
+v Version
+\layout List
+\labelwidthstring 00.00.0000
+
+v coder type (0-> golomb rice, 1-> CABAC)
+\layout List
+\labelwidthstring 00.00.0000
+
+v Colorspace type (0->YCbCr, 1->JPEG2000_RCT)
+\layout List
+\labelwidthstring 00.00.0000
+
+b grayscale
+\layout List
+\labelwidthstring 00.00.0000
+
+v log2_h_chroma_subsample (
+\begin_inset Formula $chroma\_ width=2^{-log2\_ h\_ chroma\_ subsample}luma\_ width$
+\end_inset
+
+)
+\layout List
+\labelwidthstring 00.00.0000
+
+v log2_v_chroma_subsample (
+\begin_inset Formula $chroma\_ height=2^{-log2\_ v\_ chroma\_ subsample}luma\_ height$
+\end_inset
+
+)
+\layout List
+\labelwidthstring 00.00.0000
+
+b alpha plane
+\layout List
+\labelwidthstring 00.00.0000
+
+x Quantization tables
+\layout Subsection
+
+Quant Table
+\layout Standard
+
+The quantization tables are simply stored by storing the number of equal
+ entries -1 of the first half of the table using the method described in
+
+\begin_inset LatexCommand \ref{sub:Non-binary-values}
+
+\end_inset
+
+, the second half doesn't need to be stored as it is identical to the first
+ with flipped sign
+\layout Standard
+
+example:
+\newline
+Table: 0 0 1 1 1 1 2 2-2-2-2-1-1-1-1 0
+\newline
+Stored values: 1, 3, 1
+\layout Section
+
+Changelog
+\layout List
+\labelwidthstring 00.00.0000
+
+0.01 2003-06-09
+\newline
+initial version by Michael Niedermayer
+\layout List
+\labelwidthstring 00.00.0000
+
+0.02 2004-02-15
+\newline
+update to match implementation (significant changes)
+\layout List
+\labelwidthstring 00.00.0000
+
+0.03 2004-02-18
+\newline
+
+\begin_inset Quotes eld
+\end_inset
+
+Boarder
+\begin_inset Quotes erd
+\end_inset
+
+->
+\begin_inset Quotes erd
+\end_inset
+
+Border
+\begin_inset Quotes erd
+\end_inset
+
+ by Jim Leonard
+\newline
+huffyuv url by Felix Buenemann
+\newline
+minor fixes by me
+\layout List
+\labelwidthstring 00.00.0000
+
+0.04 2004-03-19
+\newline
+new huffyuv url by Raphael Clifford as old one is down
+\layout Section
+
+ToDo
+\layout Itemize
+
+mean,k estimation for the golomb rice codes
+\layout Itemize
+
+bitstream end handling
+\layout Itemize
+
+spelling errors
+\layout Section
+
+Bibliography
+\layout Bibliography
+\bibitem [JPEGLS]{JPEGLS}
+
+
+\begin_inset LatexCommand \url[JPEG-LS FCD 14495]{http://www.jpeg.org/public/fcd14495p.pdf}
+
+\end_inset
+
+
+\layout Bibliography
+\bibitem [H264]{H264}
+
+
+\begin_inset LatexCommand \url[H.264 Draft]{http://bs.hhi.de/~wiegand/JVT-G050.pdf}
+
+\end_inset
+
+
+\layout Bibliography
+\bibitem [HUFFYUV]{HuffYuv}
+
+
+\begin_inset LatexCommand \url[Huffyuv]{http://cultact-server.novi.dk/kpo/huffyuv/huffyuv.html}
+
+\end_inset
+
+
+\layout Bibliography
+\bibitem [FFMPEG]{FFMPEG}
+
+
+\begin_inset LatexCommand \url[FFmpeg]{http://ffmpeg.org}
+
+\end_inset
+
+
+\layout Bibliography
+\bibitem [JPEG2000]{JPEG2000}
+
+JPEG2000 url
+\layout Section
+
+Copyright
+\layout Standard
+
+Copyright 2003,2004 Michael Niedermayer <michaelni at gmx.at>
+\newline
+This text can be used under the GNU Free Documentation License or GNU General
+ Public License.
+ See
+\begin_inset LatexCommand \htmlurl{http://www.gnu.org/licenses/fdl.txt}
+
+\end_inset
+
+.
+\the_end
Added: trunk/docs/ffv1.ps
==============================================================================
Binary file. No diff available.
Added: trunk/docs/ffv1.txt
==============================================================================
--- (empty file)
+++ trunk/docs/ffv1.txt Mon Mar 19 19:52:05 2007
@@ -0,0 +1,443 @@
+Description of the FFV1 Video Codec
+
+by Michael Niedermayer <michaelni at gmx.at>
+
+Table of Contents
+
+1 Introduction
+2 Terms and Definitions
+3 High-level Description
+ 3.1 Border
+ 3.2 Median predictor
+ 3.3 Context
+ 3.4 Quantization
+ 3.5 Colorspace
+ 3.5.1 JPEG2000-RCT
+ 3.6 Coding of the sample difference
+ 3.6.1 Arithmetic coding mode
+ 3.6.2 Huffman coding mode
+4 Bitstream
+ 4.1 Frame
+ 4.2 Header
+ 4.3 Quant Table
+5 Changelog
+6 ToDo
+7 Bibliography
+8 Copyright
+
+
+
+1 Introduction
+
+The FFV1 video codec is a simple lossless intra only
+codec. It is still under development and the bitstream
+might change between versions.
+
+The latest version of this document is available at
+http://www.mplayerhq.hu/~michael/ffv1.{lyx,txt,html,ps}
+
+This document assumes familiarity with mathematical and
+coding concepts such as Arithmetic coding and YCbCr colorspaces.
+
+2 Terms and Definitions
+
+CABAC Context Adaptive Binary Arithmetic Coder[H264]
+
+RCT Reversible component transform
+
+3 High-level Description
+
+Each frame is split in 3 planes (Y, Cb, Cr). In the
+case of the normal YCbCr colorspace the Y plane is
+coded first followed by the Cb and Cr planes, in the
+case of the JPEG2000-RCT colorspace the lines are
+interleaved to reduce cache trashing as most likely the
+RCT will be immedeatly converted to RGB during
+decoding, the order of the lines in the interleaving is
+again Y,Cb,Cr.
+
+Samples within a plane are coded in raster scan order
+(left->right, top->bottom), each sample is predicted by
+the median predictor from samples in the same plane and
+the difference is stored
+
+3.1 Border
+
+Samples above the coded picture are assumed to be 0,
+right of the coded picture are identical to the closest
+left sample and left of the coded picture are identical
+to the top right one
+
++---++----+----+---++---+
+| 0 || 0 | 0 | 0 || 0 |
++---++----+----+---++---+
++---++----+----+---++---+
+| 0 || a | b | c || c |
++---++----+----+---++---+
+| a || d | | e || e |
++---++----+----+---++---+
+| d || f | g | h || h |
++---++----+----+---++---+
+
+
+Note, this is identical to [JPEGLS]
+
+3.2 Median predictor
+
+median(left, top, left + top - diag)
+
+left, top, diag are the left, top and lefttop samples
+
+Note, this is also used in [JPEGLS, HuffYuv]
+
+3.3 Context
+
++----+-----+----+----+
+| | | T | |
++----+-----+----+----+
+| | tl | t | tr |
++----+-----+----+----+
+| L | l | X | |
++----+-----+----+----+
+
+
+The quantized sample differences L-l, l-tl, tl-t, t-T,
+t-tr are used as context
+
+ context=Q_{0}[l-tl]+\left|Q_{0}\right|(Q_{1}[tl-t]+\left|Q_{1}\right|(Q_{2}[t-tr]+\left|Q_{2}\right|(Q_{3}[L-l]+\left|Q_{3}\right|Q_{4}[T-t])))
+
+If context < 0 then -context is used and the difference
+between the sample and its predicted value is encoded
+with a flipped sign
+
+3.4 Quantization
+
+There are 5 quantization tables for the 5 sample
+differences, both the number of quantization steps and
+their distribution are stored in the bitstream. Each
+quantization table has exactly 256 entries, and the 8
+least significant bits of the sample difference are
+used as index
+
+ Q_{i}[a-b]=Table_{i}[(a-b)\&255]
+
+3.5 Colorspace
+
+3.5.1 JPEG2000-RCT
+
+ Cb=b-g
+
+ Cr=r-g
+
+ Y=g+(Cb+Cr)>>2
+
+ g=Y-(Cb+Cr)>>2
+
+ r=Cr+g
+
+ b=Cb+g
+
+[JPEG2000]
+
+3.6 Coding of the sample difference
+
+Instead of coding the 9 (or 10 in the case of RCT) bits
+of the sample difference with huffman or CABAC coding
+only the 8 (or 9) least significant bits are used as
+thats enough the recover the original sample
+
+ coder\_ input=\left[\left(sample\_ difference+2^{bits-1}\right)\&\left(2^{bits}-1\right)\right]-2^{bits-1}
+
+3.6.1 Arithmetic coding mode
+
+ Context Adaptive Binary Arithmetic Coding (CABAC)
+
+The coder is borrowed from[H264] and the reader is referred
+to that for further information, it is also noted that
+the author doesn't know if the coder is patented, so
+care must be taken if FFV1 is used in countries where
+software patents are legal. But even if CABAC turns out
+to be patent free there is still some risk that other
+parts of FFV1 are covered by patents. By just looking
+at the very long list of patents which cover other
+relatively simple standards it is shown that the patent
+offices seem to pass nearly everything. In many cases
+the patents cover basic operations like subtraction or
+taking the median of 3 integers in a specific case like
+motion vectors.
+
+ Non binary values
+
+<sub:Non-binary-values>To encode 8 or 9bit numbers as is needed in our case,
+we could simply encode each bit separately and use the
+past bits as context, but that would mean 255 contexts
+per 8bit symbol which is not only a waste of memory but
+also requires more past data to reach reasonable good
+estimate of the probabilities. Alternatively simply
+assuming a laplacian distribution and only dealing with
+its variance and mean like we do in huffman coding mode
+would be another possibility, but due to flexibility
+and simplicity, another method was chosen, which simply
+uses a single symbol to encode if a number is 0 and if
+not encodes the number using its exponent,mantisse and
+sign, the exact contexts which are used can probably
+better be described by the following code then by some
+english text
+
+put_symbol(CABACContext *c, uint8_t *state, int v, int
+is_signed, int max_exp){
+
+ int i;
+
+ if(v){
+
+ const int a= ABS(v);
+
+ const int e= av_log2(a);
+
+ put_cabac(c, state+0, 0);
+
+ for(i=0; i<e; i++){
+
+ put_cabac(c, state+1+i, 1); //1..8
+
+ }
+
+ if(e<max_exp){
+
+ put_cabac(c, state+1+i, 0); //1..8
+
+ for(i=e-1; i>=0; i--){
+
+ put_cabac(c, state+16+e+i, (a>>i)&1); //17..29
+
+ }
+
+ if(is_signed)
+
+ put_cabac(c, state+9 + e, v < 0); //9..16
+
+ }
+
+ }else{
+
+ put_cabac(c, state+0, 1);
+
+ }
+
+}
+
+
+
+max_exp is 7 unless the RCT is used, in which case it
+is 8 for the samples in a plane and 7 for the elements
+in the header
+
+is_signed is 1 for encoding of the samples within a
+plane or line, and 0 for the elements of the header
+
+ Initial values for the context model
+
+At keyframes all CABAC state variables are set to 0
+except number 7 which is set to 124, number 7 is used
+to select between -127..-64,64..127 and -128 which
+should explain the strong favoring of the earlier
+
+3.6.2 Huffman coding mode
+
+Uses golomb rice codes. The VLC code is split in 2
+parts, the prefix stores the most significant bits, the
+suffix stores the k least significant bits or stores
+the whole number in the ESC case
+
+ Prefix
+
++-----------------+-------+
+| bits | value |
++-----------------+-------+
++-----------------+-------+
+| 1 | 0 |
++-----------------+-------+
+| 01 | 1 |
++-----------------+-------+
+| ... | ... |
++-----------------+-------+
+| 0000 0000 0001 | 11 |
++-----------------+-------+
+| 0000 0000 0000 | ESC |
++-----------------+-------+
+
+
+ Suffix
+
+non ESC the k least significant bits MSB first
+
+ESC the value - 11, in MSB first order, ESC may only be
+used if the value cannot be coded as non ESC
+
+ Examples
+
++------+------------------------+-------+
+| k | bits | value |
++------+------------------------+-------+
++------+------------------------+-------+
+| 0 | 1 | 0 |
++------+------------------------+-------+
+| 0 | 001 | 2 |
++------+------------------------+-------+
+| 2 | 1 00 | 0 |
++------+------------------------+-------+
+| 2 | 1 10 | 2 |
++------+------------------------+-------+
+| 2 | 01 01 | 5 |
++------+------------------------+-------+
+| any | 000000000000 10000000 | 139 |
++------+------------------------+-------+
+
+
+ run mode
+
+run mode is entered when the context is 0, and left as
+soon as a non 0 difference is found, the level is
+identical to the predicted one, the run and the first
+different level is coded
+
+ run length coding
+
+ level coding
+
+is identical to the normal difference coding with the
+exception that the 0 value is removed as it cant occur
+
+if(diff>0) diff--;
+
+encode(diff);
+
+Note, this is different from JPEG-LS, which doesn't use
+prediction in run mode, and uses a different encoding
+and context model for the last difference, on a small
+set of test samples the use of prediction improved the
+compression rate a bit
+
+4 Bitstream
+
+b CABAC 1-bit symbol
+
+v 7bit unsigned symbol coded with the method described
+in [sub:Non-binary-values]
+
+The same context which is initialized to 0 is used for
+all fields in the header
+
+4.1 Frame
+
+b keyframe
+
+if(keyframe)
+
+ Header
+
+if(JPEG2000_RCT){
+
+ for(y=0; y<height; y++){
+
+ LumaLine[y]
+
+ CbLine[y]
+
+ CrLine[y]
+
+ }
+
+}else{
+
+ LumaPlane
+
+ CbPlane
+
+ CrPlane
+
+}
+
+4.2 Header
+
+v Version
+
+v coder type (0-> golomb rice, 1-> CABAC)
+
+v Colorspace type (0->YCbCr, 1->JPEG2000_RCT)
+
+b grayscale
+
+v log2_h_chroma_subsample ( chroma\_ width=2^{-log2\_ h\_ chroma\_ subsample}luma\_ width )
+
+v log2_v_chroma_subsample ( chroma\_ height=2^{-log2\_ v\_ chroma\_ subsample}luma\_ height )
+
+b alpha plane
+
+x Quantization tables
+
+4.3 Quant Table
+
+The quantization tables are simply stored by storing
+the number of equal entries -1 of the first half of the
+table using the method described in [sub:Non-binary-values], the second half
+doesn't need to be stored as it is identical to the
+first with flipped sign
+
+example:
+Table: 0 0 1 1 1 1 2 2-2-2-2-1-1-1-1 0
+Stored values: 1, 3, 1
+
+5 Changelog
+
+0.01 2003-06-09
+initial version by Michael Niedermayer
+
+0.02 2004-02-15
+update to match implementation (significant changes)
+
+0.03 2004-02-18
+"Boarder"->"Border" by Jim Leonard
+huffyuv url by Felix Buenemann
+minor fixes by me
+
+0.04 2004-03-19
+new huffyuv url by Raphael Clifford as old one is down
+
+6 ToDo
+
+* mean,k estimation for the golomb rice codes
+
+* bitstream end handling
+
+* spelling errors
+
+7 Bibliography
+
+References
+
+[http://www.jpeg.org/public/fcd14495p.pdf||JPEG-LS FCD 14495]
+
+References
+
+[http://bs.hhi.de/~wiegand/JVT-G050.pdf||H.264 Draft]
+
+References
+
+[http://cultact-server.novi.dk/kpo/huffyuv/huffyuv.html||Huffyuv]
+
+References
+
+[http://ffmpeg.org||FFmpeg]
+
+References
+
+JPEG2000 url
+
+8 Copyright
+
+Copyright 2003,2004 Michael Niedermayer
+<michaelni at gmx.at>
+This text can be used under the GNU Free Documentation
+License or GNU General Public License. See [http://www.gnu.org/licenses/fdl.txt].
Added: trunk/docs/msmpeg4.txt
==============================================================================
--- (empty file)
+++ trunk/docs/msmpeg4.txt Mon Mar 19 19:52:05 2007
@@ -0,0 +1,899 @@
+ DIVX3 / MS-MPEG4v1-v3 / WMV7-8
+
+Version: 0.07 2003-01-13
+
+ Copyright (c) 2003 Michael Niedermayer <michaelni at gmx.at>
+ Permission is granted to copy, distribute and/or modify this document
+ under the terms of the GNU Free Documentation License, Version 1.2
+ or any later version published by the Free Software Foundation;
+ with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
+ A copy of the license is included in the section entitled "GNU
+ Free Documentation License".
+
+Version numbers used in this doc:
+1 MS MPEG4v1
+2 MS MPEG4v2
+3 MS MPEG4v3 / divx3
+4 Windows Media Video 7 / WMV7 / WMV1
+5 Windows Media Video 8 / WMV8 / WMV2
+
+latest version is available at:
+http://www.mplayerhq.hu/~michael/msmpeg4.txt
+
+Introduction:
+MS MPEG4/DIVX3/WMV will be referred to by using MSMPEG4 throught this
+document. It is assumed that the reader is familiar with video coding
+concepts including VLCs, run-length encoding, DCTs, quantization, motion
+compensation, frame types, etc. (FIXME some links to MPEG video intros)
+MSMPEG4 upto version 3 is pretty much ISO-MPEG4 with most advanced
+features removed, and different VLC tables. WMV1 just has different
+scantables too and WMV2 additionally uses 8x4, 4x8 DCT in addition to
+the 8x8 DCT for P Frames, and supports horizontal quarterpel motion
+compensation.
+
+Note: The WMV8=WMV2 info is not complete yet.
+
+===============================================================================
+Terms and Definitions:
+ABT adaptive block transform
+AC Any DCT coefficient for which the frequency in one or
+ both dimensions is non-zero.
+CBP coded block pattern
+DC The DCT coefficient for which the frequency is zero in
+ both dimensions.
+DCT Discrete cosine transform
+GOP Group of pictures (starts with an I Frame)
+IDCT inverse discrete cosine transform
+MB Macroblock
+MPEG Motion Pictures Expert Group
+MS microsoft
+MV Motion Vector
+MC Motion Compensation
+Slice for MSMPEG4: consecutive macroblock rows, so a slice is
+ a rectangle of macroblocks which always touches the left
+ and right edge of the image
+VLC variable length code
+WMV windows media video
+median(a,b,c) a+b+c - MAX(a,b,c) - MIN(a,b,c) (= the middle value of 3)
+
+===============================================================================
+High Level Description:
+
+MSMPEG3 supports the following frame types:
+I Frames (these are decoded without using any previous frames)
+P Frames (these use the last decoded frame for prediction)
+J Frames (they are like I Frames but use a different encoding, they only exist
+ in WMV2)
+Note: None of the MSMPEG4 versions support B frames
+
+---------------
+Colorspace / Output Format:
+
+YV12 / planar 4:2:0 YCbCr (like MPEG1/2/4)
+
+---------------
+Macroblocks:
+
+Macroblock are comprised of 16x16 luma samples & 8x8 U + V chroma
+samples. There are intra & inter type macroblocks. While MSMPEG4 splits
+a MB into 4 luma 8x8 blocks & 2 chroma 8x8 blocks, WMV2 also splits some
+8x8 blocks in 2 8x4 or 4x8 blocks but only in P frames.
+
+Note: J Frames do not use Macroblocks.
+
+The coded order of 8x8 blocks in a MB is luma then Cb then Cr. The luma
+blocks are organized as:
+Y->Y
+ /
+ /
+Y->Y
+
+If a 8x8 block is split into subblocks then the left or top subblock is
+transmitted first.
+
+---------------
+Slices:
+
+MSMPEG4 frames can be split into slices, but only at the start of a MB
+row. All slices in all pictures in a GOP have the same height (except
+the last slice in the pictures which may be shorter). Normally the
+height stays the same throughout the video, and WMV2 cannot even change
+it between GOPs, as the number of slices is encoded in a global header
+for WMV2.
+
+The slice height is encoded directly in MSMPEG4 v1. For the later
+versions the number of slices is encoded instead.
+
+Vectors for motion vector prediction across a slice boundary are not
+available, like for the top edge.
+
+AC, DC, and coded values for prediction are not available for
+prediction across a slice boundary in versions 1-3.
+
+Note: There is no special marker or header at the slice start or end.
+
+---------------
+Motion Compensation:
+
+MSMPEG4 motion compensation is macroblock-based like in MPEG1, so there
+is exactly one motion vector for every MB in a P frame. MSMPEG4 supports
+rounded and not rounded halfpel interpolation like ISO-MPEG4.
+
+WMV2 supports 2 different motion compensation methods:
+1. The ISO-MPEG4 standard halfpel interpolation with 2 rounding modes
+ like in the older MSMPEG4 versions
+2. the WMV2 horizontal quarter pel interpolation with only 1 rounding mode
+
+---------------
+Block Coding:
+
+MSMPEG4 is identical to ISO-MPEG4 in zigzag / horizontal and vertical
+alternate scans with run/level/last VLC, with the exception of WMV1&2
+which use different scantables.
+
+The decoding process for an individual block is:
+
+bitstream ---vlc decode---> run/level/last ---RLE decode with scantable--->
+8x8 block of coefficients (+dc/ac prediction for intra MBs)
+---dequantize--IDCT---> residual 8x8 block
+
+For intra MBs the residual block is identical to what is displayed.
+For inter MBs the residual block is the difference between what should
+actually be displayed and what was predicted by motion compensation
+
+---------------
+DC Prediction For Intra Macroblocks:
+
+DC prediciton for intra MBs for MSMPEG4 v1 is identical to MPEG1. The dc
+is simply predicted from the "last" block of the same type (left
+block for Cb/Cr). The prediction is reset to gray (128) after each
+macroblock row.
+
+The luma prediction order for MBs follows this pattern:
+
+Y->Y Y->Y Y->Y
+ / / / / /
+ / / / / /
+Y->Y Y->Y Y->Y
+
+DC prediction for intra MBs in version 2-3 is nearly identical to
+ISO-MPEG4.
+
+A B
+
+C X
+
+A is the dc value of the top left 8x8 block
+B is the dc value of the top 8x8 block
+C is the dc value of the left 8x8 block
+X is the predicted dc value of the current 8x8 block
+
+Unavailable blocks (left or top edge or inter blocks are set to gray),
+where:
+ gray = (1024 + dc_scale/2)/dc_scale
+
+if(abs(a-c) <= abs(a-b))
+ x= b
+else
+ x= c
+
+Note: The difference between this scheme and ISO-MPEG4 is that the
+latter uses "abs(a-c) < abs(a-b)" instead of "abs(a-c) <= abs(a-b)".
+
+DC prediction For intra MBs in version 4-5 is identical to ISO-MPEG4. In
+other words, '<=' is replaced by '<'.
+
+However, if inter_intra_pred==1 then the following prediction is used
+instead:
+( Note: inter_intra_pred == (width*height < 320*240 && bit_rate<=128kbit && P Frame); )
+
+For the top left luma block in a macroblock the prediction direction is
+coded in the bitstream. The prediction is the average of the 64 samples of
+the top or left 8x8 block (even if it is inter). The prediction is gray if
+it is on an edge. The prediction direction of the 2 chroma blocks is also
+encoded in the bitstream, (note, that the bitstream stores just 1
+direction for both Cb and Cr blocks). The top right and bottom left luma
+blocks in a MB are predicted by using the DC of the left top luma block.
+The bottom right luma block in a MB uses the same rule as non inter_intra
+predicted blocks.
+
+This is the prediction direction for the luma blocks in a MB:
+
+ |
+ v
+-->Y->Y
+ | |
+ v v
+ Y->Y
+
+---------------
+AC Prediction:
+
+AC prediction in MSMPEG4 is identical to ISO-MPEG4. Intra blocks are AC
+predicted in the same direction as the DC prediction if the ac_pred bit
+is set for the current macroblock.
+
+Left AC prediction: The left column of AC values (=7) in the current 8x8
+block is predicted from the left block.
+
+Top AC prediction: the top row of AC values (=7) in the current 8x8
+block is predicted from the top block.
+
+DAAAAAAA DAAAAAAA
+A....... A|||||||
+A....... A|||||||
+A....... A|||||||
+A....... A|||||||
+A....... A|||||||
+A....... A|||||||
+A....... A|||||||
+ |||||||
+ |||||||
+ vvvvvvv
+DAAAAAAA DAAAAAAA
+A---------->A.......
+A---------->A.......
+A---------->A.......
+A---------->A.......
+A---------->A.......
+A---------->A.......
+A---------->A.......
+
+Unavailable blocks and inter blocks are replaced by all 0.
+
+---------------
+Scantables:
+
+Version 1-3: (identical to ISO-MPEG4)
+Inter and intra blocks without AC prediction use the zigzag scantable.
+AC-predicted intra blocks use the alternate horizontal and vertical
+scantables depending upon the prediction direction.
+
+Version 4-5
+Identical to version 1-3 except that all tables are replaced by
+different ones and the inter and intra without AC prediction use
+different tables.
+
+Note that in version 5 the 8x4 & 4x8 subblocks use a fixed scantable.
+
+---------------
+Luma Coded Block Pattern Prediction For I Frames:
+
+A B
+
+C X
+
+A is the coded value of the top left 8x8 luma block
+B is the coded value of the top 8x8 luma block
+C is the coded value of the left 8x8 luma block
+X is the predicted value of the current 8x8 luma block
+
+Unavailable blocks (left & top edge) have coded=0.
+
+if(A==B) X=C;
+else X=B
+
+Note: Neither the chroma CBP, nor the CBP of any MB in a P Frame is
+ predicted.
+Note: Coded means that there are non zero AC coefficients in the 8x8
+ block, which are are coded in the bitstream.
+Note: Due to the AC prediction, it is possible that there are non zero
+ AC coefficients which are not coded. In that case, coded=0.
+
+---------------
+Motion Vector Prediction:
+
+The motion vector prediction scheme used in v1-4 is identical to the
+scheme used in ISO MPEG-4. The scheme used in v5 is differs in that the
+halfpel motion vector is predicted from the left, top & top right
+halfpel motion vectors.
+
+If only the left vector is available then it is used as predictor. If
+only the top and top right vectors are available then the vector of the medians
+of their components and 0 is used as predictor. If all 3 vectors are available
+then the vector of the medians of their components is used as predictor unless
+all of the following conditions are
+true:
+
+1. version==5
+2. mspel==0
+3. top_left_mv_flag==1
+4. the horizontal or vertical difference of the top & left vectors is >= 8
+
+If these conditions are met, an extra bit is transmitted which selects
+the left or top vectors as predictors.
+
+Note: median((a0,a1), (b0,b1), (c0,c1)) = (median(a0,b0,c0), median(a1,b1,c1))
+ median(a,b,c) = a+b+c - MAX(a,b,c) - MIN(a,b,c) (= the middle value of 3)
+---------------
+Differential Encoding of Motion Vectors:
+
+For halfpel:
+(dmvx, dmvy) is the motion vector difference from the bitstream
+(pmvx, pmvy) is the predicted motion vector
+(mvx, mvy) is the motion vector
+
+mvx= pmvx + dmvx
+if (mvx<=-64) mvx+= 64;
+else if(mvx>= 64) mvx-= 64;
+
+The same calculations apply for the y components.
+
+So the components of the motion vectors are limited to -63 ... 63 which
+is -31.5 ... 31.5 in fullpel units.
+
+For horizontal qpel: in WMV2 (mspel==1)
+If the halfpel vector does not point to a full pel position then an
+additional bit is transmitted which shifts the vector right by 1/4 pixel
+if the bit is 1.
+
+---------------
+Halfpel Motion Compensation:
+
+Halfpel MC in MSMPEG4 is identical to ISO-MPEG4.
+
+F Fullpel position
+H H or V halfpel position
+h HV halfpel position
+
+FHF
+HhH
+FHF
+
+F->H<-F
+|\ /|
+v \ / v
+H h H
+^ / \ ^
+|/ \|
+F->H<-F
+
+H= (F+F+r)>>1
+f= (F+F+F+F+1+r)>>2
+r is 0 or 1 depending upon the rounding mode for the current frame
+
+---------------
+WMV2 Horizontal Quarter Pel:
+
+F Fullpel position
+H H or V halfpel position
+h HV halfpel position
+Q,q quarterpel positions
+
+FQHQF
+.....
+HqhqH
+.....
+FQHQF
+
+F-----F->H<-F-----F
+ | | |
+ | | |
+ | | |
+ | | |
+F-----F->H<-F-----F
+ | | |
+ v v v
+ H h H
+ ^ ^ ^
+ | | |
+F-----F->H<-F-----F
+ | | |
+ | | |
+ | | |
+ | | |
+F-----F->H<-F-----F
+
+
+F->Q<-H->Q<-F
+
+H->q<-h->q<-H
+
+H = from F by 4tap (halfpel samples)
+h = from H by 4tap vertically (halfpel samples)
+Q = (F+H+1)>>1 (quarterpel samples)
+q = (H+h+1)>>1 (quarterpel samples)
+
+4tap = clip((-a + 9b + 9c - d + 8)>>4, 0, 255);
+
+
+---------------
+8x8 IDCT (identical to MPEG1/2/4):
+ 2 N-1 N-1 (2x+1)u*pi (2y+1)v*pi
+f(x,y) = - SUM SUM C(u)C(v)F(u,v)cos---------- cos----------
+ N u=0 v=0 2N 2N
+N=8
+C(u) = 1/sqrt(2) if u==0
+ 1 if u!=0
+
+
+---------------
+8x4 and 4x8 IDCT:
+ 2 N-1 M-1 (2x+1)u*pi (2y+1)v*pi
+f(x,y) = ------- SUM SUM C(u)C(v)F(u,v)cos---------- cos----------
+ sqrt(MN) u=0 v=0 2N 2M
+N=8
+M=4
+C(u) = 1/sqrt(2) if u==0
+ 1 if u!=0
+
+---------------
+(de)quantization:
+For AC coefficients in intra blocks and all coefficients in inter
+blocks, the quantization is the same as H263 / ISO-MPEG4.
+
+For the DC coefficient:
+for luma dequant_dc= quant_dc * luma_scale [quantizer_scale]
+for chroma dequant_dc= quant_dc * chroma_scale[quantizer_scale]
+
+For version 1-2:
+both luma_scale & chroma_scale are constant 8 (like ISO-MPEG1)
+
+For version 3 (like ISO-MPEG4):
+ luma_scale[31]= {0, 8, 8, 8, 8,10,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,36,38,40,42,44,46};
+chroma_scale[31]= {0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,20,21,22,23,24,25};
+
+For version 4-5:
+ luma_scale[31]= {0, 8, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21};
+chroma_scale[31]= {0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22};
+
+===============================================================================
+Bitstream:
+Name type Values Version Default
+
+-----------------
+Header:
+Startcode u(24) 0x100 1
+Frame number u(5) 1
+Picture type u(2) 00 I-Frame 1234
+ 01 P-Frame 1234
+ u(1) 0 I-Frame 5
+ 1 P-Frame 5
+if(Picture type == I-Frame)
+ code u(7) 5
+Quantizer scale u(5) 1-31 12345
+if(Picture type == I-Frame){
+ slice code u(5) 1234
+ ext_header 4
+ if(j_type_bit)
+ j_type u(1) 5 0
+ if(j_type==0){
+ if(per_mb_rl_bit)
+ per_mb_rl_table u(1) 45
+ else
+ per_mb_rl_table NC 0 12345
+ if(!per_mb_rl_table){
+ rl chroma_table_index c3 345 2
+ rl table_index c3 345 2
+ }
+ dc_table_index u(1) 345 0
+ }
+}else{
+ wmv2_skip 5
+ use_mb_skip_code NC 1 1
+ u(1) 234
+ NC 0 5
+ if(quantizer scale<=10)
+ cbp_index c3 0 0 5 3
+ 10 2 5 3
+ 11 1 5 3
+ else if(quantizer scaley<=20)
+ cbp_index c3 0 1 5 3
+ 10 0 5 3
+ 11 2 5 3
+ else
+ cbp_index c3 0 2 5 3
+ 10 1 5 3
+ 11 0 5 3
+ if(mspel_bit)
+ mspel u(1) 5 0
+ if(abt_flag){
+ per_mb_abt u(1)^1 5 0
+ if(!per_mb_abt)
+ abt_type c3 5
+ }
+ if(per_mb_rl_bit)
+ per_mb_rl_table u(1) 45
+ else
+ per_mb_rl_table NC 0 12345
+ if(!per_mb_rl_table){
+ rl chroma_table_index c3 345 2
+ rl table_index = rl chroma_table_index
+ }
+ dc_table_index u(1) 345 0
+ mv_table_index u(1) 345 0
+}
+
+The frame number is the frame number modulo 31 (skipped frames are
+counted too).
+
+The slice code is the height of each slice in MSMPEG4 v1. In later
+versions, it is the number of slices + 0x16.
+
+j_type_bit: indicates that the j_type flag is coded
+j_type: is 1 if the Frame is a J Frame 0 if its a I Frame
+per_mb_rl_bit is 1 if the ac vlc table is selected per Macroblock
+use_mb_skip_code is 1 if the skip bit is coded for each MB
+
+----------------
+Ext Header:
+
+ext_header:
+fps u(5) 12345
+bitrate (in kbit) u(11) 12345
+flipflop_rounding NC 0 12
+ u(1) 34
+ NC 1 5
+mspel_bit u(1) 5 0
+? u(1) 5 ?
+abt_flag u(1) 5 0
+j_type_bit u(1) 5 0
+top_left_mv_flag u(1) 5 0
+per_mb_rl_bit NC 0 123
+ NC bit_rate>50kbit 4
+ u(1) 5
+slice_code u(3) >0 5
+
+FPS is truncated to an integer value (e.g., 30.9 -> 30).
+
+The slice_code is the number of slices (note no + 0x16 here).
+
+The ext header is at the end of each I Frame for version 1-3, part of
+the main I frame header for version 4 and in the global ASF/AVI header
+for version 5
+
+---------------
+3rd Level AC ESC Coding, Versions 1-3:
+
+esc3:
+last u(1) 123
+run u(6) 123
+level s(8) 123
+
+----------------
+3rd Level AC ESC Coding, Versions 4-5:
+
+esc3:
+last u(1) 45
+if(first_esc3_in_frame){
+ if(quantizer_scale<8){
+ level_length u(3) 45
+ if(level_length==0){
+ level_length u(1)+8 45
+ }
+ }else{
+ level_length 1 2 45
+ 01 3 45
+ ...
+ 000001 7 45
+ 000000 8 45
+ }
+ run_length u(2)+3 45
+}
+run u(run_length) 45
+sign u(1) 45
+level u(level_length) 45
+
+---------------
+WMV2 MB Skip Bitstream;
+
+wmv2_skip:
+skip_type u(2) 5
+if(skip_type==0){
+// no macroblock is skiped
+ for(mb_y=0; mb_y < mb_height; mb_y++){
+ for(mb_x=0; mb_x < mb_width; mb_x++){
+ skip[mb_y][mb_x] NC 0 5
+ }
+ }
+}else if(skip_type==1){
+//1 skip bit for every macroblock
+ for(mb_y=0; mb_y < mb_height; mb_y++){
+ for(mb_x=0; mb_x < mb_width; mb_x++){
+ skip[mb_y][mb_x] u(1) 5
+ }
+ }
+}else if(skip_type==2){
+ for(mb_y=0; mb_y < mb_height; mb_y++){
+ skip_row[mb_y] u(1) 5
+ if(!skip_row[mb_y]){
+ for(mb_x=0; mb_x < mb_width; mb_x++){
+ skip[mb_y][mb_x] u(1) 5 1
+ }
+ }
+ }
+}else{
+ for(mb_x=0; mb_x < mb_width; mb_x++){
+ skip_column[mb_x] u(1) 5
+ if(!skip_column[mb_x]){
+ for(mb_y=0; mb_y < mb_height; mb_y++){
+ skip[mb_y][mb_x] u(1) 5 1
+ }
+ }
+ }
+}
+
+---------------
+Macroblock Bitstream, Versions 1-2:
+
+mb:
+if(P Frame){
+ if(use_skip_mb_code)
+ skip[mb_y][mb_x] u(1) 1234 0
+ code v1_inter_cbpc 1
+ code v2_mb_type 2
+ intra_mb= code>>2
+}else{
+ code v1_intra_cbpc 1
+ code v2_intra_cbpc 2
+ intra_mb= 1
+}
+if(intra_mb)
+ ac_pred u(1) 2 0
+cbpy cbpy_tab 12
+cbp= (code & 0x3) | (cbpy<<2)
+if(intra_mb){
+ if(P Frame && version==1) cbp^= 0x3C;
+}else{
+ if(version==1 || (cbp&3) != 3) cbp^= 0x3C;
+ mv
+}
+for(i=0; i<6; i++){
+ block(i, (cbp>>(5-i))&1)
+}
+
+---------------
+Macroblock Bitstream, Versions 3-5:
+
+mb:
+if(P Frame){
+ // Note: for version 5 skip is stored directly after the main header
+ if(use_skip_mb_code)
+ skip[mb_y][mb_x] u(1) 1234
+ else
+ skip[mb_y][mb_x] NC 0 1234
+ code table_mb_non_intra 34
+ code wmv2_inter_table[cbp_index] 5
+ intra_mb= (~code&0x40)>>6
+ cbp= code &0x3F
+}else{
+ code table_mb_intra 345
+ intra_mb= 1
+ cbp=0
+ for(i=0;i<6;i++) {
+ int val = ((code >> (5 - i)) & 1);
+ if (i < 4) {
+ val = val ^ coded_block_pred(i);
+ }
+ cbp |= val << (5 - i);
+ }
+}
+if(intra_mb){
+ ac_pred u(1) 345
+ if(inter_intra_pred)
+ pred_direction table_inter_intra 45
+}else{
+ if(!mspel && top_left_mv_flag && mb_x && mb_y && top_left_mv_diff >=8)
+ mv_prediction_direction u(1) 5 2
+}
+if(per_mb_rl_table && cbp){
+ rl_table_index c3 45
+ chroma_rl_table_index= rl_table_index
+}
+if(!intra_mb){
+ if(abt_flag && per_mb_abt && cbp){
+ per_block_abt u(1) 5 0
+ if(!per_block_abt)
+ abt_type c3 5 0
+ }else
+ per_block_abt=0
+ mv 345
+}
+
+for(i=0; i<6; i++){
+ block(i, (cbp>>(5-i))&1)
+}
+
+mv_prediction_direction: 0-> predict from left MB
+ 1-> predict from top MB
+ 2-> predict from median
+
+table_inter_intra[4][2]={
+ {0,1} /*Luma-Left Chroma-Left*/,
+ {2,2} /*Luma-Top Chroma-Left*/,
+ {6,3} /*luma-Left Chroma-Top */,
+ {7,3} /*luma-Top Chroma-Top */
+};
+---------------
+Block Bitstream:
+
+block(i, coded):
+if(intra_mb)
+ subblock(i, coded)
+else if(coded){
+ if(per_block_abt)
+ abt_type c3 5 0
+
+ if(abt_type)
+ sub_cbp 0 2 5 1
+ 10 3 5 1
+ 11 1 5 1
+ if(sub_cbp&1)
+ subblock(i, 1)
+
+ if(sub_cbp&2)
+ subblock(i, 1)
+}
+
+Note: For versions 1-4 subblocks == blocks.
+
+---------------
+Subblock Bitstream (mostly identical to ISO-MPEG4 for version 2-5):
+
+subblock(i, coded):
+if(intra_mb){
+ dc
+ if(n<4) // luma
+ rl= rl_table[rl_table_index]
+ else //chroma
+ rl= rl_table[3 + chroma_rl_table_index]
+}else{
+ rl= rl_table[3 + rl_table_index]
+ run_diff=1 345 0
+}
+last= coded
+while(!last){
+ code rl 12345
+ if(code==rl->n){ //Escape
+ escape 1-2 1 1 2345 3
+ 01 2
+ 00 3
+ if(escape==1){
+ code rl 2345
+ sign u(1) 2345
+ run= rl->run[code]
+ last= rl->last[code]
+ level= rl->level[code] + rl->max_level[last][run]
+ }else if(escape==2){
+ code rl 2345
+ sign u(1) 2345
+ level= rl->level[code]
+ last= rl->last[code]
+ run= rl->run[code] + rl->max_run[last][level] + run_diff
+ }else
+ esc3
+ }else{
+ sign u(1) 12345
+ level= rl->level[code]
+ last= rl->last[code]
+ run= rl->run[code]
+ }
+}
+
+---------------
+Motion Vector Bitstream, Versions 1-2 (identical to ISO-MPEG4 except for
+the limited range):
+
+mv:
+mv_component(dmvx)
+mv_component(dmvy)
+
+mv_component(dmv):
+code mv2_vlc 12
+if(code){
+ sign u(1) 12
+ if(sign)
+ dmv= -code
+ else
+ dmv= code
+}else
+ dmv= 0
+
+---------------
+Motion Vector Bitstream, Versions 3-5:
+
+mv:
+code mv_vlc[mv_table_index] 345
+if(code==1099){
+ dmvx u(6)-32 345
+ dmvy u(6)-32 345
+}else{
+ dmvx = mvx_table[code]
+ dmvy = mvy_table[code]
+}
+if(mspel && ((dmvx|dmvy)&1))
+ hshift u(1) 5 0
+
+---------------
+DC Bitstream, Versions 1-2 (identical to ISO-MPEG4 except that 0 and 1
+are exchanged):
+
+dc:
+len dc2_vlc[isChroma]^-1 12
+if(len!=0){
+ level u(len) 12
+ if((level >> (len - 1)) == 0) /* if MSB not set it is negative*/
+ level = - (level ^ ((1 << len) - 1));
+ if(len>8)
+ marker u(1) 1 12
+}else
+ level=0
+
+---------------
+DC Bitstream, Versions 3-5:
+
+dc:
+if(isLumaBlock)
+ level luma_dc_vlc[dc_table_index]345
+else
+ level chroma_dc_vlc[dc_table_index]345
+if(level==119)
+ level u(8) 345
+if(level!=0)
+ sign u(1) 345
+if(sign)
+ level= -level
+
+------------------------------
+Data Types:
+
+u(x) unsigned number encoded in x bits in MSB first order
+s(x) a twos complement signed number encoded in x bits in MSB first order
+ = simply the x least significant bits of a variable (on a normal cpu)
+c3
+ value bitstream
+ 0 0
+ 1 10
+ 2 11
+NC Not coded (always a constant)
+
+------------------------------
+MSMPEG4 tables:
+http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/msmpeg4data.h?rev=HEAD&content-type=text/vnd.viewcvs-markup
+
+Standard ISO-MPEG4 & H263 tables:
+http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/mpeg4data.h?rev=HEAD&content-type=text/vnd.viewcvs-markup
+http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ffmpeg/ffmpeg/libavcodec/h263data.h?rev=HEAD&content-type=text/vnd.viewcvs-markup
+===============================================================================
+Changelog:
+0.07 2003-01-13
+ cosmetics by Mike Melanson
+ minor changes
+0.06 2003-01-13 (still non public)
+ dc prediction direction fix (variable names where exchanged)
+ Grammar, punctuation, spelling, capitalization by Mike Melanson
+ formatting, 80 column linewrap by Mike Melanson
+ dc & mv prediction fix
+ minor changes
+0.05 2003-01-10 (non public AFAIK)
+ minor changes
+ non linear dc quantization
+ ext header is also in msmpeg4v1
+ finished header bitstream
+ mb bitstream
+ block & subblock bitstream
+0.04 2003-01-10 (non public AFAIK)
+ minor changes
+ cbp prediction
+ ac prediction & scantables
+ dc bitstream
+ slices & prediction
+ more cosmetics by Mike Melanson
+0.03 (non public AFAIK)
+ spelling fixes & comments & improvements by Mike Melanson
+ fixed table links
+0.02 (non public AFAIK)
+ added defaults to the bitstream syntax instead of lots of not coded cases
+ dct/idct
+ MV prediction
+ MV bitstream
+ MB skip encoding
+ ext header
+ ac esc3 encoding
+ dc prediction
+0.01 2003-01-07 initial (non public AFAIK)
+
+Note: Entries without a name are written by Michael Niedermayer
+===============================================================================
+GNU Free Documentation License:
+see http://www.gnu.org/licenses/fdl.html
Added: trunk/misc/chain-check.c
==============================================================================
--- (empty file)
+++ trunk/misc/chain-check.c Mon Mar 19 19:52:05 2007
@@ -0,0 +1,52 @@
+#include <stdlib.h>
+#include <inttypes.h>
+
+#define MAX_LENGTH 256*256*256
+
+main(){
+ int length, start, i, len;
+ uint8_t *array= malloc(MAX_LENGTH+10);
+ uint8_t *subchain= malloc(MAX_LENGTH+10);
+
+ srand(time(0));
+
+ for(length=16; length<MAX_LENGTH; length+=length){
+ printf("length: %d :", length);
+
+ for(i=0; i<length; i++)
+ array[i]= rand()/19;
+ memset(subchain, 0, length);
+
+ for(start=0; start<length; start++){
+ int packets=0;
+
+ if(subchain[start]) continue;
+
+ for(i=start; i<length; ){
+ int v= array[i];
+ int len0= array[i+1];
+ int len1= array[i+2];
+ int len2= array[i+3];
+
+ if (!(len0&128)) len= len0 + 2;
+ else if(!(len1&128)) len= len0 - 128 + len1*128 + 3;
+ else len= len0 - 128 + len1*128 - 128*128 + len2*128*128 + 4;
+ len= 16*len + (v&15);
+
+ packets++;
+
+ subchain[i]=1;
+
+ if(v == 'N') break;
+ if(len + i >= length){
+ if(len + i == length)
+ printf("%d(%d) ", packets, length-start);
+ break;
+ }
+ i += len;
+ }
+ }
+
+ printf("\n");
+ }
+}
Added: trunk/misc/codec-features.html
==============================================================================
--- (empty file)
+++ trunk/misc/codec-features.html Mon Mar 19 19:52:05 2007
@@ -0,0 +1,342 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
+<meta name="author" content="Michael Niedermayer"/>
+<title>Codec feature comparission</title>
+<style type="text/css">
+<!--
+.supported { background-color:#8FFF8F }
+.buggy { background-color:#FFFF8F }
+.partial { background-color:#FFCF8F }
+.notsupported { background-color:#FF8F8F }
+.unknown { background-color:#CFCFCF }
+-->
+</style>
+</head>
+<body>
+<h1>Codec feature comparission</h1>
+
+<h2>News:</h2>
+<h3>2003-08-03</h3>
+<p>
+ xvid supports 3point GMC (since mid july), Thanks to Edouard Gomez for the info
+</p>
+<h3>2003-06-07</h3>
+<p>
+ sklmp4 supports trellis quantization, Thanks to Thomas for the info
+</p>
+<h3>2003-04-28</h3>
+<p>
+ xvid supports trellis quantization, info from xvid-dev mailinglist
+</p>
+<h3>2003-03-22</h3>
+<p>
+ added sklmp4 codec, thanks to skal for the info
+</p>
+<h3>2003-03-19</h3>
+<p>
+ new ffmpeg features: rvlc decoding<br/>
+ new xvid features: 1 & 2 warp point GMC de/encoding. Thanks to Christoph Lampert for the info
+</p>
+<h3>2003-01-13</h3>
+<p>
+ new ffmpeg features: qpel encoding, chroma Motion estimation, trellis quantization<br/>
+ Added 3ivx D4 PR2. Thanks to Capt. Stux *-Jedi for the info.
+</p>
+<h3>2002-12-14</h3>
+<p>
+ Added envivo decoder, xvid decoder supports slices. Thanks to suxen drol for the info.<br/>
+ Added "*" for unverified entries. ffmpeg supports dynamic b frames for encoding now.
+</p>
+<h3>2002-11-09</h3>
+<p>
+ Divx5 doesnt seem to support decoding of gmc with more then 1 warp point (it just crashed)<br/>
+ Xvid has GMC support, now<br/>
+ adding text, instead of just colors, so broken browsers like netscape 4.x & lynx display
+ at least someting
+</p>
+<h3>2002-10-22</h3>
+<p>
+ Divx5 does support RVLC decoding. Thanks to Andrea Graziani for the info.
+</p>
+<h3>2002-10-19</h3>
+<p>
+ Divx5 does support adaptive quantization (the psychovisual enhancements stuff activates it). Thanks to
+ Eugene Kuznetsov for that info.
+</p>
+
+<h2>Mpeg4 Decoder features:</h2>
+<table border="1">
+ <thead>
+ <tr>
+ <th></th>
+ <th>ffmpeg/libavcodec</th>
+ <th>divx5</th>
+ <th>xvid</th>
+ <th>envivo v1.2.46</th>
+ <th>3ivx D4 PR2</th>
+ <th>sklmp4</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>ac/dc prediction</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>mpeg quantizer</td>
+ <td class="supported">Sup</td>
+ <td class="buggy">Bug, rounding?</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>B-Vop</td>
+ <td class="supported">Sup</td>
+ <td class="buggy">Bug, B before I</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>4-MV</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+
+ </tr>
+ <tr>
+ <td>quarter pel MC</td>
+ <td class="supported">Sup</td>
+ <td class="buggy">Bug, 1. chroma rounding<br/>2. 4mv</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>Global MC</td>
+ <td class="supported">Sup</td>
+ <td class="partial">Part, 1 warp point is supported</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="partial">Part, 1 warp point is supported*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>interlacing</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No</td>
+ <td class="partial">Part, only DCT*</td>
+ <td class="notsupported">No*</td>
+ <td class="notsupported">No*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>reduced res VOP</td>
+ <td class="notsupported">No</td>
+ <td class="notsupported">No*</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="notsupported">No*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>slices</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>data partitioning</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No</td>
+ <td class="unknown">Unk*</td>
+ <td class="notsupported">No*</td>
+ <td class="notsupported">No*</td>
+ </tr>
+ <tr>
+ <td>reversible vlc</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No</td>
+ <td class="unknown">Unk*</td>
+ <td class="notsupported">No*</td>
+ <td class="notsupported">No*</td>
+ </tr>
+ </tbody>
+</table>
+<h2>Mpeg4 Encoder features:</h2>
+<table border="1">
+ <thead>
+ <tr>
+ <th></th>
+ <th>ffmpeg/libavcodec</th>
+ <th>divx5</th>
+ <th>xvid</th>
+ <th>sklmp4</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>ac/dc prediction</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>mpeg quantizer</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>B-Vop</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No*</td>
+ </tr>
+ <tr>
+ <td>dynamic b frame decision</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No</td>
+ <td class="supported">Sup*</td>
+ <td class="notsupported">No*</td>
+ </tr>
+ <tr>
+ <td>4-MV</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>quarter pel MC</td>
+ <td class="supported">Sup</td>
+ <td class="buggy">Bug, chroma rounding</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>Global MC</td>
+ <td class="notsupported">No</td>
+ <td class="partial">Part, 1 warp point only</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>interlacing</td>
+ <td class="partial">Part, only DCT</td>
+ <td class="notsupported">No</td>
+ <td class="partial">Part, only DCT</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>reduced res VOP</td>
+ <td class="notsupported">No</td>
+ <td class="notsupported">No</td>
+ <td class="supported">Sup*</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>slices</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No</td>
+ <td class="unknown">Unk</td>
+ </tr>
+ <tr>
+ <td>data partitioning</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="notsupported">No</td>
+ <td class="notsupported">No*</td>
+ </tr>
+ <tr>
+ <td>reversible vlc</td>
+ <td class="notsupported">No</td>
+ <td class="notsupported">No</td>
+ <td class="notsupported">No</td>
+ <td class="notsupported">No*</td>
+ </tr>
+ <tr>
+ <td>adaptive quantization</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>custom quantizer matrixes</td>
+ <td class="notsupported">No</td>
+ <td class="notsupported">No</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ <tr>
+ <td>Chroma Motion Estimation</td>
+ <td class="supported">Sup</td>
+ <td class="unknown">Unk</td>
+ <td class="supported">Sup</td>
+ <td class="unknown">Unk</td>
+ </tr>
+ <tr>
+ <td>Trellis Quantization</td>
+ <td class="supported">Sup</td>
+ <td class="unknown">Unk</td>
+ <td class="supported">Sup</td>
+ <td class="supported">Sup*</td>
+ </tr>
+ </tbody>
+</table>
+<table border="1">
+ <tr>
+ <th class="supported">Sup,<br/> supported</th>
+ <th class="buggy">Bug,<br/> buggy</th>
+ <th class="partial">Part,<br/> partial</th>
+ <th class="notsupported">No,<br/> not supported</th>
+ <th class="unknown">Unk,<br/> unknown</th>
+ <th>*<br/>not verified by me</th>
+ </tr>
+</table>
+<p>
+ if u notice ANY errors in the tables then please send <a href="mailto:michaelni at gmx.at">me</a> an email.
+ if u dont want the codec of ur company listed here then tell me and ill remove it. patches / additions
+ with codecs listed not here are very welcome too.
+</p>
+<p>
+ Note: i did not do extensive tests with the codecs except ffmpeg so there might be errors<br/>
+ some of the bugs mentioned might be corrected allready, if u do know about one then tell me so i
+ can fix the table<br/>
+ features which are supported but where it is not known if the support is complete are marked as unknown<br/>
+ for all "buggy/partial" entries the exact reason is mentioned
+</p>
+<p>
+ copyleft 2002-2003 <a href="mailto:michaelni at gmx.at">Michael Niedermayer</a>
+</p>
+<p>
+ <a href="http://validator.w3.org/check/referer"><img
+ src="http://www.w3.org/Icons/valid-xhtml10"
+ alt="Valid XHTML 1.0!" height="31" width="88" /></a>
+</p>
+</body>
+</html>
Added: trunk/misc/lumi-masking.png
==============================================================================
Binary file. No diff available.
Added: trunk/misc/mndiff-0.1.tar.bz2
==============================================================================
Binary file. No diff available.
Added: trunk/misc/patent.html
==============================================================================
--- (empty file)
+++ trunk/misc/patent.html Mon Mar 19 19:52:05 2007
@@ -0,0 +1,39 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"/>
+<meta name="author" content="Michael Niedermayer"/>
+<title>a few software patent related links</title>
+</head>
+<body>
+<h1>a few links to software patent examples</h1>
+<h2>US:</h2>
+<ul>
+ <li><a href="http://www.base.com/software-patents/examples.html">Examples of Software Patents</a></li>
+</ul>
+<h2>Europe:</h2>
+<ul>
+ <li><a href="http://swpat.ffii.org/patents/samples/index.en.html">European Software Patents: Assorted Examples</a></li>
+</ul>
+<h1>free online Patent databases</h1>
+<p>Warning, according to <a href="http://lists.debian.org/debian-legal/2003/debian-legal-200301/msg00212.html">some debian legal mail</a> it is legally very bad to read patents about the area u are working in</p>
+<h2>US:</h2>
+<ul>
+ <li><a href="http://www.uspto.gov">United States Patent and Trademark Office Home Page</a></li>
+</ul>
+<h2>Europe:</h2>
+<ul>
+ <li><a href="http://ep.espacenet.com/">esp at cenet worldwide database</a></li>
+</ul>
+<h1>patent related news</h1>
+<h2>Europe:</h2>
+<ul>
+ <li><a href="http://swpat.ffii.org/neues/index.en.html">FFII News about Software Patents</a></li>
+</ul>
+<h1>various petitions & appeals u can vote for</h1>
+<h2>Europe:</h2>
+<ul>
+ <li><a href="http://petition.eurolinux.org">Petition for a Software Patent Free Europe</a></li>
+ <li><a href="http://petition.ffii.org/eubsa/en">Call for Action</a></li>
+</ul>
+</html>
Added: trunk/misc/relative_lumi.png
==============================================================================
Binary file. No diff available.
Added: trunk/patches/bttv-420-2.4.26.patch
==============================================================================
--- (empty file)
+++ trunk/patches/bttv-420-2.4.26.patch Mon Mar 19 19:52:05 2007
@@ -0,0 +1,22 @@
+--- bttv-driver.c.orig 2004-07-02 03:19:11.000000000 +0200
++++ bttv-driver.c 2004-07-02 00:28:22.000000000 +0200
+@@ -772,7 +772,7 @@
+ u32 bl, blcr, blcb, rcmd;
+ u32 todo;
+ u32 **rp;
+- int inter;
++ int inter, field_off;
+ unsigned long cbadr, cradr;
+ unsigned long vadr=(unsigned long) vbuf;
+ u32 shift, csize;
+@@ -832,8 +832,8 @@
+ else
+ rp= (line>=height) ? &ro : &re;
+
+-
+- if(line&lmask)
++ field_off= inter && (line & (lmask+1));
++ if((line - field_off)&lmask)
+ rcmd=BT848_RISC_WRITE1S23|BT848_RISC_SOL;
+ else
+ rcmd=BT848_RISC_WRITE123|BT848_RISC_SOL;
Added: trunk/patches/bttv-420-2.6.6.patch
==============================================================================
--- (empty file)
+++ trunk/patches/bttv-420-2.6.6.patch Mon Mar 19 19:52:05 2007
@@ -0,0 +1,21 @@
+--- bttv-risc.c.orig 2004-07-02 12:36:27.000000000 +0200
++++ bttv-risc.c 2004-07-03 19:14:01.000000000 +0200
+@@ -122,6 +122,7 @@
+ struct scatterlist *usg;
+ struct scatterlist *vsg;
+ int rc;
++ int is_2nd_field= !!yoffset;
+
+ /* estimate risc mem: worst case is one write per page border +
+ one write per scan line (5 dwords)
+@@ -146,8 +147,8 @@
+ continue;
+ switch (vshift) {
+ case 0: chroma = 1; break;
+- case 1: chroma = !(line & 1); break;
+- case 2: chroma = !(line & 3); break;
++ case 1: chroma = !((line -is_2nd_field) & 1); break;
++ case 2: chroma = !((line-1-is_2nd_field) & 3); break;
+ default: chroma = 0;
+ }
+ for (todo = ybpl; todo > 0; todo -= ylen) {
Added: trunk/patches/bttv-comb-2.4.26.patch
==============================================================================
--- (empty file)
+++ trunk/patches/bttv-comb-2.4.26.patch Mon Mar 19 19:52:05 2007
@@ -0,0 +1,15 @@
+--- bttv-driver.c.orig 2004-07-02 03:19:11.000000000 +0200
++++ bttv-driver.c 2004-07-02 16:56:23.000000000 +0200
+@@ -1191,7 +1191,11 @@
+
+ if (combfilter) {
+ /* Some people say interpolation looks bad ... */
+- vtc = (width < 193) ? 2 : ((width < 385) ? 1 : 0);
++ if(combfilter==2)
++ vtc = (width < 193 && 6*height < tvn->sheight) ? 2 :
++ ((width < 385 && 3*height < tvn->sheight) ? 1 : 0);
++ else
++ vtc = (width < 193) ? 2 : ((width < 385) ? 1 : 0);
+ if (width < 769)
+ btor(BT848_VSCALE_COMB, BT848_E_VSCALE_HI+off);
+ else
Added: trunk/patches/bttv-comb-2.6.6.patch
==============================================================================
--- (empty file)
+++ trunk/patches/bttv-comb-2.6.6.patch Mon Mar 19 19:52:05 2007
@@ -0,0 +1,15 @@
+--- bttv-risc.c.orig 2004-07-02 12:36:27.000000000 +0200
++++ bttv-risc.c 2004-07-03 19:14:01.000000000 +0200
+@@ -334,7 +335,11 @@
+ geo->sheight = tvnorm->sheight;
+ geo->vtotal = tvnorm->vtotal;
+
+- if (btv->opt_combfilter) {
++ if (btv->opt_combfilter==2) {
++ geo->vtc = (width < 193 && 6*height < tvnorm->sheight) ? 2 :
++ ((width < 385 && 3*height < tvnorm->sheight) ? 1 : 0);
++ geo->comb = (width < 769) ? 1 : 0;
++ } else if (btv->opt_combfilter) {
+ geo->vtc = (width < 193) ? 2 : ((width < 385) ? 1 : 0);
+ geo->comb = (width < 769) ? 1 : 0;
+ } else {
Added: trunk/patches/colorgcc.diff
==============================================================================
--- (empty file)
+++ trunk/patches/colorgcc.diff Mon Mar 19 19:52:05 2007
@@ -0,0 +1,57 @@
+--- /usr/bin/colorgcc 2005-03-25 16:45:18.000000000 +0100
++++ /home/michael/bin/colorgcc 2005-08-22 23:55:01.000000000 +0200
+@@ -99,9 +99,17 @@
+ $colors{"srcColor"} = color("cyan");
+ $colors{"introColor"} = color("blue");
+
+- $colors{"warningFileNameColor"} = color("yellow");
+- $colors{"warningNumberColor"} = color("yellow");
+- $colors{"warningMessageColor"} = color("yellow");
++ $colors{"infoFileNameColor"} = color("green");
++ $colors{"infoNumberColor"} = color("green");
++ $colors{"infoMessageColor"} = color("green");
++
++ $colors{"pedanticFileNameColor"} = color("yellow");
++ $colors{"pedanticNumberColor"} = color("yellow");
++ $colors{"pedanticMessageColor"} = color("yellow");
++
++ $colors{"warningFileNameColor"} = color("bold yellow");
++ $colors{"warningNumberColor"} = color("bold yellow");
++ $colors{"warningMessageColor"} = color("bold yellow");
+
+ $colors{"errorFileNameColor"} = color("bold red");
+ $colors{"errorNumberColor"} = color("bold red");
+@@ -255,12 +263,28 @@
+ $field2 = $2 || "";
+ $field3 = $3 || "";
+
+- if ($field3 =~ m/\s+warning:.*/)
++ if ($field3 =~ m/\s+warning:\s*(.*)/)
+ {
+- # Warning
+- print($colors{"warningFileNameColor"}, "$field1:", color("reset"));
+- print($colors{"warningNumberColor"}, "$field2:", color("reset"));
+- srcscan($field3, $colors{"warningMessageColor"});
++ $warning = $1 || "";
++ if($warning =~ m/^unused variable|^unused parameter|defined but not used$|is not at beginning of declaration$|missing initializer$|^.near initialization/)
++ {
++ print($colors{"infoFileNameColor"}, "$field1:", color("reset"));
++ print($colors{"infoNumberColor"}, "$field2:", color("reset"));
++ srcscan($field3, $colors{"infoMessageColor"});
++ }
++ elsif($warning =~ m/differ in signedness$|comparison between signed and unsigned$|signed and unsigned type in conditional expression$|not handled in switch$/)
++ {
++ print($colors{"pedanticFileNameColor"}, "$field1:", color("reset"));
++ print($colors{"pedanticNumberColor"}, "$field2:", color("reset"));
++ srcscan($field3, $colors{"pedanticMessageColor"});
++ }
++ else
++ {
++ # Warning
++ print($colors{"warningFileNameColor"}, "$field1:", color("reset"));
++ print($colors{"warningNumberColor"}, "$field2:", color("reset"));
++ srcscan($field3, $colors{"warningMessageColor"});
++ }
+ }
+ else
+ {
Added: trunk/patches/colorgccrc-debian.diff
==============================================================================
--- (empty file)
+++ trunk/patches/colorgccrc-debian.diff Mon Mar 19 19:52:05 2007
@@ -0,0 +1,24 @@
+--- /etc/colorgcc/colorgccrc 2003-12-16 18:05:02.000000000 +0100
++++ .colorgccrc 2005-08-22 23:45:11.000000000 +0200
+@@ -48,10 +48,20 @@
+ # filename:999:Message
+ # Each field may be assigned a different color.
+
++# info
++infoFileNameColor: reset
++infoNumberColor: blue
++infoMessageColor: green
++
++# pedantic "warnings"
++pedanticFileNameColor: reset
++pedanticNumberColor: blue
++pedanticMessageColor: yellow
++
+ # Warnings
+ warningFileNameColor: reset
+ warningNumberColor: blue
+-warningMessageColor: yellow
++warningMessageColor: bold yellow
+
+ # Errors
+ errorFileNameColor: reset
Added: trunk/patches/colorgccrc-upstream.diff
==============================================================================
--- (empty file)
+++ trunk/patches/colorgccrc-upstream.diff Mon Mar 19 19:52:05 2007
@@ -0,0 +1,24 @@
+--- colorgccrc-old 2005-08-23 00:19:12.000000000 +0200
++++ colorgccrc 2005-08-23 00:19:54.000000000 +0200
+@@ -41,10 +41,20 @@
+ # filename:999:Message
+ # Each field may be assigned a different color.
+
++# info
++infoFileNameColor: reset
++infoNumberColor: white
++infoMessageColor: green
++
++# pedantic "warnings"
++pedanticFileNameColor: reset
++pedanticNumberColor: white
++pedanticMessageColor: yellow
++
+ # Warnings
+ warningFileNameColor: reset
+ warningNumberColor: white
+-warningMessageColor: yellow
++warningMessageColor: bold yellow
+
+ # Errors
+ errorFileNameColor: reset
Added: trunk/patches/huffyuv-order1-context-patch2.bz2
==============================================================================
Binary file. No diff available.
More information about the Mndiff-dev
mailing list