changeset 2460:42077bb89a53 libavcodec

norm-6 / diff-6 support (untested, parts of it just guessed as the spec is unclear)
author michael
date Mon, 24 Jan 2005 01:46:12 +0000
parents 7a875ef7597b
children 1d818bf32736
files vc9.c vc9data.h
diffstat 2 files changed, 128 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/vc9.c	Mon Jan 24 00:35:18 2005 +0000
+++ b/vc9.c	Mon Jan 24 01:46:12 2005 +0000
@@ -136,6 +136,8 @@
 static VLC vc9_imode_vlc;
 #define VC9_NORM2_VLC_BITS 3
 static VLC vc9_norm2_vlc;
+#define VC9_NORM6_VLC_BITS 9
+static VLC vc9_norm6_vlc;
 /* Could be optimized, one table only needs 8 bits */
 #define VC9_TTMB_VLC_BITS 12
 static VLC vc9_ttmb_vlc[3];
@@ -281,6 +283,18 @@
     v->ac_pred_plane = v->over_flags_plane = NULL;
     v->hrd_rate = v->hrd_buffer = NULL;
 #endif
+#if 0 // spec -> actual tables converter
+    for(i=0; i<64; i++){
+        int code= (vc9_norm6_spec[i][1] << vc9_norm6_spec[i][4]) + vc9_norm6_spec[i][3];
+        av_log(NULL, AV_LOG_DEBUG, "0x%03X, ", code);
+        if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n");
+    }
+    for(i=0; i<64; i++){
+        int code= vc9_norm6_spec[i][2] + vc9_norm6_spec[i][4];
+        av_log(NULL, AV_LOG_DEBUG, "%2d, ", code);
+        if(i%16==15) av_log(NULL, AV_LOG_DEBUG, "\n");
+    }
+#endif
     if(!done)
     {
         done = 1;
@@ -290,6 +304,9 @@
         INIT_VLC(&vc9_norm2_vlc, VC9_NORM2_VLC_BITS, 4,
                  vc9_norm2_bits, 1, 1,
                  vc9_norm2_codes, 1, 1, 1);
+        INIT_VLC(&vc9_norm6_vlc, VC9_NORM6_VLC_BITS, 64,
+                 vc9_norm6_bits, 1, 1,
+                 vc9_norm6_codes, 2, 2, 1);
         INIT_VLC(&vc9_cbpcy_i_vlc, VC9_CBPCY_I_VLC_BITS, 64,
                  vc9_cbpcy_i_bits, 1, 1,
                  vc9_cbpcy_i_codes, 2, 2, 1);
@@ -712,6 +729,7 @@
     }
 }
 
+//FIXME optimize
 static void decode_colskip(uint8_t* plane, int width, int height, int stride, VC9Context *v){
     int x, y;
 
@@ -730,7 +748,7 @@
 //FIXME is this supposed to set elements to 0/FF or 0/1?
 static int bitplane_decoding(uint8_t* plane, int width, int height, VC9Context *v)
 {
-    int imode, x, y, i, code, use_vertical_tile;
+    int imode, x, y, i, code, use_vertical_tile, tile_w, tile_h;
     uint8_t invert, *planep = plane;
     int stride= width;
 
@@ -763,18 +781,39 @@
     case IMODE_DIFF6:
     case IMODE_NORM6:
         use_vertical_tile= height%3==0 && width%3!=0;
-        if(use_vertical_tile){
-        }else{
+        tile_w= use_vertical_tile ? 2 : 3;
+        tile_h= use_vertical_tile ? 3 : 2;
+
+        for(y= height%tile_h; y<height; y+=tile_h){
+            for(x= width%tile_w; x<width; x+=tile_w){
+                code = get_vlc2(&v->gb, vc9_norm6_vlc.table, VC9_NORM6_VLC_BITS, 2);
+                //FIXME following is a pure guess and probably wrong
+                planep[x     + 0*stride]= (code>>0)&1;
+                planep[x + 1 + 0*stride]= (code>>1)&1;
+                if(use_vertical_tile){
+                    planep[x + 0 + 1*stride]= (code>>2)&1;
+                    planep[x + 1 + 1*stride]= (code>>3)&1;
+                    planep[x + 0 + 2*stride]= (code>>4)&1;
+                    planep[x + 1 + 2*stride]= (code>>5)&1;
+                }else{
+                    planep[x + 2 + 0*stride]= (code>>2)&1;
+                    planep[x + 0 + 1*stride]= (code>>3)&1;
+                    planep[x + 1 + 1*stride]= (code>>4)&1;
+                    planep[x + 2 + 1*stride]= (code>>5)&1;
+                }
+            }
         }
-        
-        av_log(v->avctx, AV_LOG_ERROR, "Imode using Norm-6 isn't supported\n");
-        return -1;
+
+        x= width % tile_w;
+        decode_colskip(plane  ,         x, height         , stride, v);
+        decode_rowskip(plane+x, width - x, height % tile_h, stride, v);
+
         break;
     case IMODE_ROWSKIP:
         decode_rowskip(plane, width, height, stride, v);
         break;
     case IMODE_COLSKIP: //Teh ugly
-        decode_rowskip(plane, width, height, stride, v);
+        decode_colskip(plane, width, height, stride, v);
         break;
     default: break;
     }
--- a/vc9data.h	Mon Jan 24 00:35:18 2005 +0000
+++ b/vc9data.h	Mon Jan 24 01:46:12 2005 +0000
@@ -71,6 +71,88 @@
   1, 3, 3, 2
 };
 
+static const uint16_t vc9_norm6_codes[64] = {
+0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E, 
+0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037, 
+0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036, 
+0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007, 
+};
+
+static const uint8_t vc9_norm6_bits[64] = {
+ 1,  4,  4,  8,  4,  8,  8, 10,  4,  8,  8, 10,  8, 10, 10, 13, 
+ 4,  8,  8, 10,  8, 10, 10, 13,  8, 10, 10, 13, 10, 13, 13,  9, 
+ 4,  8,  8, 10,  8, 10, 10, 13,  8, 10, 10, 13, 10, 13, 13,  9, 
+ 8, 10, 10, 13, 10, 13, 13,  9, 10, 13, 13,  9, 13,  9,  9,  6,
+};
+#if 0
+/* Normal-6 imode */
+static const uint8_t vc9_norm6_spec[64][5] = {
+{ 0,  1, 1        },
+{ 1,  2, 4        },
+{ 2,  3, 4        },
+{ 3,  0, 8        },
+{ 4,  4, 4        },
+{ 5,  1, 8        },
+{ 6,  2, 8        },
+{ 7,  2, 5,  7, 5 },
+{ 8,  5, 4        },
+{ 9,  3, 8        },
+{10,  4, 8        },
+{11,  2, 5, 11, 5 },
+{12,  5, 8        },
+{13,  2, 5, 13, 5 },
+{14,  2, 5, 14, 5 },
+{15,  3, 5, 14, 8 },
+{16,  6, 4        },
+{17,  6, 8        },
+{18,  7, 8        },
+{19,  2, 5, 19, 5 },
+{20,  8, 8        },
+{21,  2, 5, 21, 5 },
+{22,  2, 5, 22, 5 },
+{23,  3, 5, 13, 8 },
+{24,  9, 8        },
+{25,  2, 5, 25, 5 },
+{26,  2, 5, 26, 5 },
+{27,  3, 5, 12, 8 },
+{28,  2, 5, 28, 5 },
+{29,  3, 5, 11, 8 },
+{30,  3, 5, 10, 8 },
+{31,  3, 5,  7, 4 },
+{32,  7, 4        },
+{33, 10, 8        },
+{34, 11, 8        },
+{35,  2, 5,  3, 5 },
+{36, 12, 8        },
+{37,  2, 5,  5, 5 },
+{38,  2, 5,  6, 5 },
+{39,  3, 5,  9, 8 },
+{40, 13, 8        },
+{41,  2, 5,  9, 5 },
+{42,  2, 5, 10, 5 },
+{43,  3, 5,  8, 8 },
+{44,  2, 5, 12, 5 },
+{45,  3, 5,  7, 8 },
+{46,  3, 5,  6, 8 },
+{47,  3, 5,  6, 4 },
+{48, 14, 8        },
+{49,  2, 5, 17, 5 },
+{50,  2, 5, 18, 5 },
+{51,  3, 5,  5, 8 },
+{52,  2, 5, 20, 5 },
+{53,  3, 5,  4, 8 },
+{54,  3, 5,  3, 8 },
+{55,  3, 5,  5, 4 },
+{56,  2, 5, 24, 5 },
+{57,  3, 5,  2, 8 },
+{58,  3, 5,  1, 8 },
+{59,  3, 5,  4, 4 },
+{60,  3, 5,  0, 8 },
+{61,  3, 5,  3, 4 },
+{62,  3, 5,  2, 4 },
+{63,  3, 5,  1, 1 },
+};
+#endif
 /* 4MV Block pattern VLC tables */
 static const uint8_t vc9_4mv_block_pattern_codes[4][16] = {
   { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27,  0, 28,  1,  2,  2},