[xiph-commits] r14050 - in trunk/theora/lib: . dec enc

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Oct 25 16:28:11 PDT 2007


Author: xiphmont
Date: 2007-10-25 16:28:11 -0700 (Thu, 25 Oct 2007)
New Revision: 14050

Removed:
   trunk/theora/lib/enc/common.c
Modified:
   trunk/theora/lib/Makefile.am
   trunk/theora/lib/dec/decapiwrapper.c
   trunk/theora/lib/dec/decode.c
   trunk/theora/lib/dec/dequant.c
   trunk/theora/lib/enc/codec_internal.h
   trunk/theora/lib/enc/dct_encode.c
   trunk/theora/lib/enc/encode.c
   trunk/theora/lib/enc/encoder_quant.c
   trunk/theora/lib/enc/encoder_toplevel.c
   trunk/theora/lib/enc/frarray.c
   trunk/theora/lib/internal.h
Log:
Add some simple debug output code (disabled by default)


Modified: trunk/theora/lib/Makefile.am
===================================================================
--- trunk/theora/lib/Makefile.am	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/Makefile.am	2007-10-25 23:28:11 UTC (rev 14050)
@@ -33,7 +33,6 @@
 	enc/encoder_toplevel.c \
 	enc/encoder_quant.c \
 	enc/blockmap.c \
-	enc/common.c \
 	enc/dct.c \
 	enc/dct_decode.c \
 	enc/frarray.c \
@@ -45,7 +44,7 @@
 	enc/reconstruct.c \
 	enc/scan.c \
 	enc/dsp.c
-	
+
 if CPU_x86_64
 enc_arch_dir = enc/x86_64
 encoder_arch_sources= \
@@ -131,7 +130,6 @@
 	dec/ocintrin.h \
 	dec/quant.h \
 	dec/x86/x86int.h
-	
 
 libtheora_la_CFLAGS = $(OGG_CFLAGS)
 libtheora_la_LDFLAGS = -version-info @TH_LIB_CURRENT@:@TH_LIB_REVISION@:@TH_LIB_AGE@ @THEORA_LDFLAGS@

Modified: trunk/theora/lib/dec/decapiwrapper.c
===================================================================
--- trunk/theora/lib/dec/decapiwrapper.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/dec/decapiwrapper.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -21,8 +21,6 @@
 #include "apiwrapper.h"
 #include "theora/theoradec.h"
 
-
-
 static void th_dec_api_clear(th_api_wrapper *_api){
   if(_api->setup)th_setup_free(_api->setup);
   if(_api->decode)th_decode_free(_api->decode);
@@ -31,6 +29,10 @@
 
 static void theora_decode_clear(theora_state *_td){
   if(_td->i!=NULL)theora_info_clear(_td->i);
+#ifdef _TH_DEBUG_
+  fclose(debugout);
+  debugout=NULL;
+#endif
   memset(_td,0,sizeof(*_td));
 }
 
@@ -90,6 +92,7 @@
   th_api_info    *apiinfo;
   th_api_wrapper *api;
   th_info         info;
+
   api=(th_api_wrapper *)_ci->codec_setup;
   /*Allocate our own combined API wrapper/theora_info struct.
     We put them both in one malloc'd block so that when the API wrapper is
@@ -127,6 +130,11 @@
   th_api_wrapper *api;
   th_info         info;
   int             ret;
+
+#ifdef _TH_DEBUG_
+  debugout = fopen("theoradec-debugout.txt","w");
+#endif
+
   api=(th_api_wrapper *)_ci->codec_setup;
   /*Allocate an API wrapper struct on demand, since it will not also include a
      theora_info struct like the ones that are used in a theora_state struct.*/
@@ -183,5 +191,10 @@
     _yuv->u=buf[1].data;
     _yuv->v=buf[2].data;
   }
+
+#ifdef _TH_DEBUG_
+  dframe++;
+#endif 
+
   return ret;
 }

Modified: trunk/theora/lib/dec/decode.c
===================================================================
--- trunk/theora/lib/dec/decode.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/dec/decode.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -24,8 +24,6 @@
 # include "png.h"
 #endif
 
-
-
 /*No post-processing.*/
 #define OC_PP_LEVEL_DISABLED  (0)
 /*Keep track of DC qi for each block only.*/
@@ -360,6 +358,7 @@
   int    run_count;
   theora_read1(&_dec->opb,&val);
   flag=(int)val;
+
   sb=_dec->state.sbs;
   sb_end=sb+_dec->state.nsbs;
   run_count=npartial=0;
@@ -373,6 +372,7 @@
       npartial+=flag;
       sb++;
     }
+
     while(--run_count>0&&sb<sb_end);
     if(full_run&&sb<sb_end){
       theora_read1(&_dec->opb,&val);
@@ -402,6 +402,7 @@
   for(;sb->coded_partially;sb++);
   theora_read1(&_dec->opb,&val);
   flag=(int)val;
+
   while(sb<sb_end){
     int full_run;
     run_count=oc_sb_run_unpack(&_dec->opb);

Modified: trunk/theora/lib/dec/dequant.c
===================================================================
--- trunk/theora/lib/dec/dequant.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/dec/dequant.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -21,8 +21,6 @@
 #include "dequant.h"
 #include "decint.h"
 
-
-
 int oc_quant_params_unpack(oggpack_buffer *_opb,
  th_quant_info *_qinfo){
   th_quant_base *base_mats;
@@ -129,6 +127,65 @@
     }
     while(qri-->0);
   }
+
+#ifdef _TH_DEBUG_
+  /* dump the tables */
+  {
+    int i, j, k, l, m;
+    TH_DEBUG("loop filter limits = {");
+    for(i=0;i<64;){
+      TH_DEBUG("\n        ");
+      for(j=0;j<16;i++,j++)
+	TH_DEBUG("%3d ",_qinfo->loop_filter_limits[i]);
+    }
+    TH_DEBUG("\n}\n\n");
+
+    TH_DEBUG("ac scale = {");
+    for(i=0;i<64;){
+      TH_DEBUG("\n        ");
+      for(j=0;j<16;i++,j++)
+	TH_DEBUG("%3d ",_qinfo->ac_scale[i]);
+    }
+    TH_DEBUG("\n}\n\n");
+
+    TH_DEBUG("dc scale = {");
+    for(i=0;i<64;){
+      TH_DEBUG("\n        ");
+      for(j=0;j<16;i++,j++)
+	TH_DEBUG("%3d ",_qinfo->dc_scale[i]);
+    }
+    TH_DEBUG("\n}\n\n");
+
+    for(k=0;k<2;k++)
+      for(l=0;l<3;l++){
+	char *name[2][3]={
+	  {"intra Y bases","intra U bases", "intra V bases"},
+	  {"inter Y bases","inter U bases", "inter V bases"}
+	};
+
+	th_quant_ranges *r = &_qinfo->qi_ranges[k][l];
+	TH_DEBUG("%s = {\n",name[k][l]);
+	TH_DEBUG("        ranges = %d\n",r->nranges);
+	TH_DEBUG("        intervals = { ");
+	for(i=0;i<r->nranges;i++)
+	  TH_DEBUG("%3d ",r->sizes[i]);
+	TH_DEBUG("}\n");
+	TH_DEBUG("\n        matricies = { ");
+	for(m=0;m<r->nranges+1;m++){
+	  TH_DEBUG("\n          { ");
+	  for(i=0;i<64;){
+	    TH_DEBUG("\n            ");
+	    for(j=0;j<8;i++,j++)
+	      TH_DEBUG("%3d ",r->base_matrices[m][i]);
+	  }
+	  TH_DEBUG("\n          }");
+	}
+	TH_DEBUG("\n        }\n");
+      }
+  }
+    
+#endif
+
   _ogg_free(base_mats);
   return 0;
 }

Modified: trunk/theora/lib/enc/codec_internal.h
===================================================================
--- trunk/theora/lib/enc/codec_internal.h	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/enc/codec_internal.h	2007-10-25 23:28:11 UTC (rev 14050)
@@ -726,7 +726,6 @@
 
 extern void ClearPPInstance(PP_INSTANCE *ppi);
 extern void InitPPInstance(PP_INSTANCE *ppi, DspFunctions *funcs);
-extern int GetFrameType(PB_INSTANCE *pbi);
 extern void InitPBInstance(PB_INSTANCE *pbi);
 extern void ClearPBInstance(PB_INSTANCE *pbi);
 
@@ -842,14 +841,20 @@
 extern void UpdateUMVBorder( PB_INSTANCE *pbi,
                              unsigned char * DestReconPtr );
 extern void PInitFrameInfo(PP_INSTANCE * ppi);
-extern int GetFrameType(PB_INSTANCE *pbi);
-extern void SetFrameType( PB_INSTANCE *pbi,unsigned char FrType );
+
 extern double GetEstimatedBpb( CP_INSTANCE *cpi, ogg_uint32_t TargetQ );
 extern void ClearTmpBuffers(PB_INSTANCE * pbi);
 extern void InitTmpBuffers(PB_INSTANCE * pbi);
 extern void ScanYUVInit( PP_INSTANCE *  ppi,
                          SCAN_CONFIG_DATA * ScanConfigPtr);
-extern int LoadAndDecode(PB_INSTANCE *pbi);
 
+static inline int GetFrameType(PB_INSTANCE *pbi){
+  return pbi->FrameType;
+}
 
+static inline void SetFrameType( PB_INSTANCE *pbi,unsigned char FrType ){
+  pbi->FrameType = FrType;
+}
+
+
 #endif /* ENCODER_INTERNAL_H */

Deleted: trunk/theora/lib/enc/common.c
===================================================================
--- trunk/theora/lib/enc/common.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/enc/common.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -1,890 +0,0 @@
-/********************************************************************
- *                                                                  *
- * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
- * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
- * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
- * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
- *                                                                  *
- * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2006                *
- * by the Xiph.Org Foundation http://www.xiph.org/                  *
- *                                                                  *
- ********************************************************************
-
-  function:
-  last mod: $Id$
-
- ********************************************************************/
-
-#include <string.h>
-#include "codec_internal.h"
-#include "block_inline.h"
-
-static const CODING_MODE  ModeAlphabet[MODE_METHODS-2][MAX_MODES] = {
-
-  /* Last motion vector dominates */
-  {    CODE_INTER_LAST_MV,    CODE_INTER_PRIOR_LAST,
-       CODE_INTER_PLUS_MV,    CODE_INTER_NO_MV,
-       CODE_INTRA,            CODE_USING_GOLDEN,
-       CODE_GOLDEN_MV,        CODE_INTER_FOURMV },
-
-  {    CODE_INTER_LAST_MV,    CODE_INTER_PRIOR_LAST,
-       CODE_INTER_NO_MV,      CODE_INTER_PLUS_MV,
-       CODE_INTRA,            CODE_USING_GOLDEN,
-       CODE_GOLDEN_MV,        CODE_INTER_FOURMV },
-
-  {    CODE_INTER_LAST_MV,    CODE_INTER_PLUS_MV,
-       CODE_INTER_PRIOR_LAST, CODE_INTER_NO_MV,
-       CODE_INTRA,            CODE_USING_GOLDEN,
-       CODE_GOLDEN_MV,        CODE_INTER_FOURMV },
-
-  {    CODE_INTER_LAST_MV,    CODE_INTER_PLUS_MV,
-       CODE_INTER_NO_MV,      CODE_INTER_PRIOR_LAST,
-       CODE_INTRA,            CODE_USING_GOLDEN,
-       CODE_GOLDEN_MV,        CODE_INTER_FOURMV },
-
-  /* No motion vector dominates */
-  {    CODE_INTER_NO_MV,      CODE_INTER_LAST_MV,
-       CODE_INTER_PRIOR_LAST, CODE_INTER_PLUS_MV,
-       CODE_INTRA,            CODE_USING_GOLDEN,
-       CODE_GOLDEN_MV,        CODE_INTER_FOURMV },
-
-  {    CODE_INTER_NO_MV,      CODE_USING_GOLDEN,
-       CODE_INTER_LAST_MV,    CODE_INTER_PRIOR_LAST,
-       CODE_INTER_PLUS_MV,    CODE_INTRA,
-       CODE_GOLDEN_MV,        CODE_INTER_FOURMV },
-
-};
-
-int GetFrameType(PB_INSTANCE *pbi){
-  return pbi->FrameType;
-}
-
-static int LoadFrameHeader(PB_INSTANCE *pbi){
-  long ret;
-  int NQIndex;
-  unsigned char  DctQIndex[3];
-  unsigned char  SpareBits;       /* Spare cfg bits */
-
-  /* Is the frame and inter frame or a key frame */
-  theora_read(pbi->opb,1,&ret);
-  pbi->FrameType = (unsigned char)ret;
-
-  /* Quality (Q) index */
-  NQIndex = 0;
-  theora_read(pbi->opb,6,&ret);
-  if (ret < 0 || ret >= 64) {   /* range check */
-    ret = 0;
-    pbi->DecoderErrorCode = 1;
-  }
-  DctQIndex[NQIndex++] = (unsigned char)ret;
-
-  theora_read(pbi->opb,1,&ret);
-  SpareBits = (unsigned char)ret;
-  if (SpareBits) {
-    theora_read(pbi->opb,6,&ret);
-    if (ret < 0 || ret >= 64) { /* range check */
-      ret = 0;
-      pbi->DecoderErrorCode = 1;
-    }
-    DctQIndex[NQIndex++] = (unsigned char)ret;
-    theora_read(pbi->opb,1,&ret);
-    SpareBits = (unsigned char)ret;
-    if (SpareBits) {
-      theora_read(pbi->opb,6,&ret);
-      if (ret < 0 || ret >= 64) {       /* range check */
-        ret = 0;
-        pbi->DecoderErrorCode = 1;
-      }
-      DctQIndex[NQIndex++] = (unsigned char)ret;
-    }
-  }
-
-  if (NQIndex != 1) return OC_IMPL;
-
-  if ( (pbi->FrameType == KEY_FRAME) ){
-    /* Read the type / coding method for the key frame. */
-    theora_read(pbi->opb,1,&ret);
-    pbi->KeyFrameType = (unsigned char)ret;
-
-    theora_read(pbi->opb,2,&ret);
-    SpareBits = (unsigned char)ret;
-
-    if (pbi->KeyFrameType || SpareBits) return OC_BADPACKET;
-  }
-
-  /* Set this frame quality value and tables from the coded Q Index */
-  UpdateQ(pbi, DctQIndex[0]);
-
-  return pbi->DecoderErrorCode;
-}
-
-void SetFrameType( PB_INSTANCE *pbi,unsigned char FrType ){
-  /* Set the appropriate frame type according to the request. */
-  switch ( FrType ){
-
-  case KEY_FRAME:
-    pbi->FrameType = FrType;
-    break;
-
-  default:
-    pbi->FrameType = FrType;
-    break;
-  }
-}
-
-static int LoadFrame(PB_INSTANCE *pbi){
-
-  /* Load the frame header (including the frame size). */
-  if ( LoadFrameHeader(pbi) == 0 ){
-    /* Read in the updated block map */
-    QuadDecodeDisplayFragments( pbi );
-    return 0;
-  }
-
-  return pbi->DecoderErrorCode;
-}
-
-static void DecodeModes (PB_INSTANCE *pbi,
-                         ogg_uint32_t SBRows,
-                         ogg_uint32_t SBCols){
-  long ret;
-  ogg_int32_t   FragIndex;
-  ogg_uint32_t  MB;
-  ogg_uint32_t  SBrow;
-  ogg_uint32_t  SBcol;
-  ogg_uint32_t  SB=0;
-  CODING_MODE  CodingMethod;
-
-  ogg_uint32_t  UVRow;
-  ogg_uint32_t  UVColumn;
-  ogg_uint32_t  UVFragOffset;
-
-  ogg_uint32_t  CodingScheme;
-
-  ogg_uint32_t  MBListIndex = 0;
-
-  ogg_uint32_t  i;
-
-  /* If the frame is an intra frame then all blocks have mode intra. */
-  if ( GetFrameType(pbi) == KEY_FRAME ){
-    for ( i = 0; i < pbi->UnitFragments; i++ ){
-      pbi->FragCodingMethod[i] = CODE_INTRA;
-    }
-  }else{
-    ogg_uint32_t        ModeEntry; /* Mode bits read */
-    CODING_MODE         CustomModeAlphabet[MAX_MODES];
-    const CODING_MODE  *ModeList;
-
-    /* Read the coding method */
-    theora_read(pbi->opb, MODE_METHOD_BITS, &ret);
-    CodingScheme=ret;
-
-    /* If the coding method is method 0 then we have to read in a
-       custom coding scheme */
-    if ( CodingScheme == 0 ){
-      /* Read the coding scheme. */
-      for ( i = 0; i < MAX_MODES; i++ ){
-        theora_read(pbi->opb, MODE_BITS, &ret);
-        CustomModeAlphabet[ret]=i;
-      }
-      ModeList=CustomModeAlphabet;
-    }
-    else{
-      ModeList=ModeAlphabet[CodingScheme-1];
-    }
-
-    /* Unravel the quad-tree */
-    for ( SBrow=0; SBrow<SBRows; SBrow++ ){
-      for ( SBcol=0; SBcol<SBCols; SBcol++ ){
-        for ( MB=0; MB<4; MB++ ){
-          /* There may be MB's lying out of frame which must be
-             ignored. For these MB's top left block will have a negative
-             Fragment Index. */
-          if ( QuadMapToMBTopLeft(pbi->BlockMap, SB,MB) >= 0){
-            /* Is the Macro-Block coded: */
-            if ( pbi->MBCodedFlags[MBListIndex++] ){
-              /* Upack the block level modes and motion vectors */
-              FragIndex = QuadMapToMBTopLeft( pbi->BlockMap, SB, MB );
-
-              /* Unpack the mode. */
-              if ( CodingScheme == (MODE_METHODS-1) ){
-                /* This is the fall back coding scheme. */
-                /* Simply MODE_BITS bits per mode entry. */
-                theora_read(pbi->opb, MODE_BITS, &ret);
-                CodingMethod = (CODING_MODE)ret;
-              }else{
-                ModeEntry = FrArrayUnpackMode(pbi);
-                CodingMethod = ModeList[ModeEntry];
-              }
-
-              /* Note the coding mode for each block in macro block. */
-              pbi->FragCodingMethod[FragIndex] = CodingMethod;
-              pbi->FragCodingMethod[FragIndex + 1] = CodingMethod;
-              pbi->FragCodingMethod[FragIndex + pbi->HFragments] =
-                CodingMethod;
-              pbi->FragCodingMethod[FragIndex + pbi->HFragments + 1] =
-                CodingMethod;
-
-              /* Matching fragments in the U and V planes */
-              UVRow = (FragIndex / (pbi->HFragments * 2));
-              UVColumn = (FragIndex % pbi->HFragments) / 2;
-              UVFragOffset = (UVRow * (pbi->HFragments / 2)) + UVColumn;
-              pbi->FragCodingMethod[pbi->YPlaneFragments + UVFragOffset] =
-                CodingMethod;
-              pbi->FragCodingMethod[pbi->YPlaneFragments +
-                                   pbi->UVPlaneFragments + UVFragOffset] =
-                CodingMethod;
-
-            }
-          }
-        }
-
-        /* Next Super-Block */
-        SB++;
-      }
-    }
-  }
-}
-
-static ogg_int32_t ExtractMVectorComponentA(PB_INSTANCE *pbi){
-  long ret;
-  ogg_int32_t   MVectComponent;
-  ogg_uint32_t  MVCode = 0;
-  ogg_uint32_t  ExtraBits = 0;
-
-  /* Get group to which coded component belongs */
-  theora_read(pbi->opb, 3, &ret);
-  MVCode=ret;
-
-  /*  Now extract the appropriate number of bits to identify the component */
-  switch ( MVCode ){
-  case 0:
-    MVectComponent = 0;
-    break;
-  case 1:
-    MVectComponent = 1;
-    break;
-  case 2:
-    MVectComponent = -1;
-    break;
-  case 3:
-    theora_read(pbi->opb,1,&ret);
-    if (ret)
-      MVectComponent = -2;
-    else
-      MVectComponent = 2;
-    break;
-  case 4:
-    theora_read(pbi->opb,1,&ret);
-    if (ret)
-      MVectComponent = -3;
-    else
-      MVectComponent = 3;
-    break;
-  case 5:
-    theora_read(pbi->opb,2,&ret);
-    ExtraBits=ret;
-    MVectComponent = 4 + ExtraBits;
-    theora_read(pbi->opb,1,&ret);
-    if (ret)
-      MVectComponent = -MVectComponent;
-    break;
-  case 6:
-    theora_read(pbi->opb,3,&ret);
-    ExtraBits=ret;
-    MVectComponent = 8 + ExtraBits;
-    theora_read(pbi->opb,1,&ret);
-    if (ret)
-      MVectComponent = -MVectComponent;
-    break;
-  case 7:
-    theora_read(pbi->opb,4,&ret);
-    ExtraBits=ret;
-    MVectComponent = 16 + ExtraBits;
-    theora_read(pbi->opb,1,&ret);
-    if (ret)
-      MVectComponent = -MVectComponent;
-    break;
-  default:
-    /* occurs if there is a read error */
-    MVectComponent = 0;
-  }
-
-  return MVectComponent;
-}
-
-static ogg_int32_t ExtractMVectorComponentB(PB_INSTANCE *pbi){
-  long ret;
-  ogg_int32_t   MVectComponent;
-
-  /* Get group to which coded component belongs */
-  theora_read(pbi->opb,5,&ret);
-  MVectComponent=ret;
-  theora_read(pbi->opb,1,&ret);
-  if (ret)
-    MVectComponent = -MVectComponent;
-
-  return MVectComponent;
-}
-
-static void DecodeMVectors ( PB_INSTANCE *pbi,
-                             ogg_uint32_t SBRows,
-                             ogg_uint32_t SBCols ){
-  long ret;
-  ogg_int32_t   FragIndex;
-  ogg_uint32_t  MB;
-  ogg_uint32_t  SBrow;
-  ogg_uint32_t  SBcol;
-  ogg_uint32_t  SB=0;
-  ogg_uint32_t  CodingMethod;
-
-  MOTION_VECTOR MVect[6];
-  MOTION_VECTOR TmpMVect;
-  MOTION_VECTOR LastInterMV;
-  MOTION_VECTOR PriorLastInterMV;
-  ogg_int32_t (*ExtractMVectorComponent)(PB_INSTANCE *pbi);
-
-  ogg_uint32_t  UVRow;
-  ogg_uint32_t  UVColumn;
-  ogg_uint32_t  UVFragOffset;
-
-  ogg_uint32_t  MBListIndex = 0;
-
-  /* Should not be decoding motion vectors if in INTRA only mode. */
-  if ( GetFrameType(pbi) == KEY_FRAME ){
-    return;
-  }
-
-  /* set the default motion vectors to 0,0 */
-  MVect[0].x = 0;
-  MVect[0].y = 0;
-  MVect[1].x = 0;
-  MVect[1].y = 0;
-  MVect[2].x = 0;
-  MVect[2].y = 0;
-  MVect[3].x = 0;
-  MVect[3].y = 0;
-  MVect[4].x = 0;
-  MVect[4].y = 0;
-  MVect[5].x = 0;
-  MVect[5].y = 0;
-  LastInterMV.x = 0;
-  LastInterMV.y = 0;
-  PriorLastInterMV.x = 0;
-  PriorLastInterMV.y = 0;
-
-  /* Read the entropy method used and set up the appropriate decode option */
-  theora_read(pbi->opb, 1, &ret);  
-  if ( ret == 0 )
-    ExtractMVectorComponent = ExtractMVectorComponentA;
-  else
-    ExtractMVectorComponent = ExtractMVectorComponentB;
-
-  /* Unravel the quad-tree */
-  for ( SBrow=0; SBrow<SBRows; SBrow++ ){
-
-    for ( SBcol=0; SBcol<SBCols; SBcol++ ){
-      for ( MB=0; MB<4; MB++ ){
-        /* There may be MB's lying out of frame which must be
-           ignored. For these MB's the top left block will have a
-           negative Fragment. */
-        if ( QuadMapToMBTopLeft(pbi->BlockMap, SB,MB) >= 0 ) {
-          /* Is the Macro-Block further coded: */
-          if ( pbi->MBCodedFlags[MBListIndex++] ){
-            /* Upack the block level modes and motion vectors */
-            FragIndex = QuadMapToMBTopLeft( pbi->BlockMap, SB, MB );
-
-            /* Clear the motion vector before we start. */
-            MVect[0].x = 0;
-            MVect[0].y = 0;
-
-            /* Unpack the mode (and motion vectors if necessary). */
-            CodingMethod = pbi->FragCodingMethod[FragIndex];
-
-            /* Read the motion vector or vectors if present. */
-            if ( (CodingMethod == CODE_INTER_PLUS_MV) ||
-                 (CodingMethod == CODE_GOLDEN_MV) ){
-              MVect[0].x = ExtractMVectorComponent(pbi);
-              MVect[1].x = MVect[0].x;
-              MVect[2].x = MVect[0].x;
-              MVect[3].x = MVect[0].x;
-              MVect[4].x = MVect[0].x;
-              MVect[5].x = MVect[0].x;
-              MVect[0].y = ExtractMVectorComponent(pbi);
-              MVect[1].y = MVect[0].y;
-              MVect[2].y = MVect[0].y;
-              MVect[3].y = MVect[0].y;
-              MVect[4].y = MVect[0].y;
-              MVect[5].y = MVect[0].y;
-            }else if ( CodingMethod == CODE_INTER_FOURMV ){
-              /* Extrac the 4 Y MVs */
-              MVect[0].x = ExtractMVectorComponent(pbi);
-              MVect[0].y = ExtractMVectorComponent(pbi);
-
-              MVect[1].x = ExtractMVectorComponent(pbi);
-              MVect[1].y = ExtractMVectorComponent(pbi);
-
-              MVect[2].x = ExtractMVectorComponent(pbi);
-              MVect[2].y = ExtractMVectorComponent(pbi);
-
-              MVect[3].x = ExtractMVectorComponent(pbi);
-              MVect[3].y = ExtractMVectorComponent(pbi);
-
-              /* Calculate the U and V plane MVs as the average of the
-                 Y plane MVs. */
-              /* First .x component */
-              MVect[4].x = MVect[0].x + MVect[1].x + MVect[2].x + MVect[3].x;
-              if ( MVect[4].x >= 0 )
-                MVect[4].x = (MVect[4].x + 2) / 4;
-              else
-                MVect[4].x = (MVect[4].x - 2) / 4;
-              MVect[5].x = MVect[4].x;
-              /* Then .y component */
-              MVect[4].y = MVect[0].y + MVect[1].y + MVect[2].y + MVect[3].y;
-              if ( MVect[4].y >= 0 )
-                MVect[4].y = (MVect[4].y + 2) / 4;
-              else
-                MVect[4].y = (MVect[4].y - 2) / 4;
-              MVect[5].y = MVect[4].y;
-            }
-
-            /* Keep track of last and prior last inter motion vectors. */
-            if ( CodingMethod == CODE_INTER_PLUS_MV ){
-              PriorLastInterMV.x = LastInterMV.x;
-              PriorLastInterMV.y = LastInterMV.y;
-              LastInterMV.x = MVect[0].x;
-              LastInterMV.y = MVect[0].y;
-            }else if ( CodingMethod == CODE_INTER_LAST_MV ){
-              /* Use the last coded Inter motion vector. */
-              MVect[0].x = LastInterMV.x;
-              MVect[1].x = MVect[0].x;
-              MVect[2].x = MVect[0].x;
-              MVect[3].x = MVect[0].x;
-              MVect[4].x = MVect[0].x;
-              MVect[5].x = MVect[0].x;
-              MVect[0].y = LastInterMV.y;
-              MVect[1].y = MVect[0].y;
-              MVect[2].y = MVect[0].y;
-              MVect[3].y = MVect[0].y;
-              MVect[4].y = MVect[0].y;
-              MVect[5].y = MVect[0].y;
-            }else if ( CodingMethod == CODE_INTER_PRIOR_LAST ){
-              /* Use the next-to-last coded Inter motion vector. */
-              MVect[0].x = PriorLastInterMV.x;
-              MVect[1].x = MVect[0].x;
-              MVect[2].x = MVect[0].x;
-              MVect[3].x = MVect[0].x;
-              MVect[4].x = MVect[0].x;
-              MVect[5].x = MVect[0].x;
-              MVect[0].y = PriorLastInterMV.y;
-              MVect[1].y = MVect[0].y;
-              MVect[2].y = MVect[0].y;
-              MVect[3].y = MVect[0].y;
-              MVect[4].y = MVect[0].y;
-              MVect[5].y = MVect[0].y;
-
-              /* Swap the prior and last MV cases over */
-              TmpMVect.x = PriorLastInterMV.x;
-              TmpMVect.y = PriorLastInterMV.y;
-              PriorLastInterMV.x = LastInterMV.x;
-              PriorLastInterMV.y = LastInterMV.y;
-              LastInterMV.x = TmpMVect.x;
-              LastInterMV.y = TmpMVect.y;
-            }else if ( CodingMethod == CODE_INTER_FOURMV ){
-              /* Update last MV and prior last mv */
-              PriorLastInterMV.x = LastInterMV.x;
-              PriorLastInterMV.y = LastInterMV.y;
-              LastInterMV.x = MVect[3].x;
-              LastInterMV.y = MVect[3].y;
-            }
-
-            /* Note the coding mode and vector for each block in the
-               current macro block. */
-            pbi->FragMVect[FragIndex].x = MVect[0].x;
-            pbi->FragMVect[FragIndex].y = MVect[0].y;
-
-            pbi->FragMVect[FragIndex + 1].x = MVect[1].x;
-            pbi->FragMVect[FragIndex + 1].y = MVect[1].y;
-
-            pbi->FragMVect[FragIndex + pbi->HFragments].x = MVect[2].x;
-            pbi->FragMVect[FragIndex + pbi->HFragments].y = MVect[2].y;
-
-            pbi->FragMVect[FragIndex + pbi->HFragments + 1].x = MVect[3].x;
-            pbi->FragMVect[FragIndex + pbi->HFragments + 1].y = MVect[3].y;
-
-            /* Matching fragments in the U and V planes */
-            UVRow = (FragIndex / (pbi->HFragments * 2));
-            UVColumn = (FragIndex % pbi->HFragments) / 2;
-            UVFragOffset = (UVRow * (pbi->HFragments / 2)) + UVColumn;
-
-            pbi->FragMVect[pbi->YPlaneFragments + UVFragOffset].x = MVect[4].x;
-            pbi->FragMVect[pbi->YPlaneFragments + UVFragOffset].y = MVect[4].y;
-
-            pbi->FragMVect[pbi->YPlaneFragments + pbi->UVPlaneFragments +
-                          UVFragOffset].x = MVect[5].x;
-            pbi->FragMVect[pbi->YPlaneFragments + pbi->UVPlaneFragments +
-                          UVFragOffset].y = MVect[5].y;
-          }
-        }
-      }
-
-      /* Next Super-Block */
-      SB++;
-    }
-  }
-}
-
-static ogg_uint32_t ExtractToken(oggpack_buffer *opb,
-                                 HUFF_ENTRY * CurrentRoot){
-  long ret;
-  ogg_uint32_t Token;
-  /* Loop searches down through tree based upon bits read from the
-     bitstream */
-  /* until it hits a leaf at which point we have decoded a token */
-  while ( CurrentRoot->Value < 0 ){
-
-    theora_read(opb, 1, &ret);
-    if (ret < 0) break; /* out of packet data! */
-    if (ret)
-      CurrentRoot = CurrentRoot->OneChild;
-    else
-      CurrentRoot = CurrentRoot->ZeroChild;
-
-  }
-  Token = CurrentRoot->Value;
-  return Token;
-}
-
-static void UnpackAndExpandDcToken( PB_INSTANCE *pbi,
-                                    Q_LIST_ENTRY *ExpandedBlock,
-                                    unsigned char * CoeffIndex ){
-  long                  ret;
-  ogg_int32_t           ExtraBits = 0;
-  ogg_uint32_t          Token;
-
-  Token = ExtractToken(pbi->opb, pbi->HuffRoot_VP3x[pbi->DcHuffChoice]);
-
-
-  /* Now.. if we are using the DCT optimised coding system, extract any
-   *  assosciated additional bits token.
-   */
-  if ( pbi->ExtraBitLengths_VP3x[Token] > 0 ){
-    /* Extract the appropriate number of extra bits. */
-    theora_read(pbi->opb,pbi->ExtraBitLengths_VP3x[Token], &ret);
-    ExtraBits = ret;
-  }
-
-  /* Take token dependant action */
-  if ( Token >= DCT_SHORT_ZRL_TOKEN ) {
-    /* "Value", "zero run" and "zero run value" tokens */
-    ExpandToken(ExpandedBlock, CoeffIndex, Token, ExtraBits );
-    if ( *CoeffIndex >= BLOCK_SIZE )
-      pbi->BlocksToDecode --;
-  } else if ( Token == DCT_EOB_TOKEN ){
-    *CoeffIndex = BLOCK_SIZE;
-    pbi->BlocksToDecode --;
-  }else{
-    /* Special action and EOB tokens */
-    switch ( Token ){
-    case DCT_EOB_PAIR_TOKEN:
-      pbi->EOB_Run = 1;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_EOB_TRIPLE_TOKEN:
-      pbi->EOB_Run = 2;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_REPEAT_RUN_TOKEN:
-      pbi->EOB_Run = ExtraBits + 3;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_REPEAT_RUN2_TOKEN:
-      pbi->EOB_Run = ExtraBits + 7;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_REPEAT_RUN3_TOKEN:
-      pbi->EOB_Run = ExtraBits + 15;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_REPEAT_RUN4_TOKEN:
-      pbi->EOB_Run = ExtraBits - 1;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    }
-  }
-}
-
-static void UnpackAndExpandAcToken( PB_INSTANCE *pbi,
-                                    Q_LIST_ENTRY * ExpandedBlock,
-                                    unsigned char * CoeffIndex  ) {
-  long                  ret;
-  ogg_int32_t           ExtraBits = 0;
-  ogg_uint32_t          Token;
-
-  Token = ExtractToken(pbi->opb, pbi->HuffRoot_VP3x[pbi->ACHuffChoice]);
-
-  /* Now.. if we are using the DCT optimised coding system, extract any
-   *  assosciated additional bits token.
-   */
-  if ( pbi->ExtraBitLengths_VP3x[Token] > 0 ){
-    /* Extract the appropriate number of extra bits. */
-    theora_read(pbi->opb,pbi->ExtraBitLengths_VP3x[Token], &ret);
-    ExtraBits = ret;
-  }
-
-  /* Take token dependant action */
-  if ( Token >= DCT_SHORT_ZRL_TOKEN ){
-    /* "Value", "zero run" and "zero run value" tokens */
-    ExpandToken(ExpandedBlock, CoeffIndex, Token, ExtraBits );
-    if ( *CoeffIndex >= BLOCK_SIZE )
-      pbi->BlocksToDecode --;
-  } else if ( Token == DCT_EOB_TOKEN ) {
-    *CoeffIndex = BLOCK_SIZE;
-    pbi->BlocksToDecode --;
-  } else {
-    /* Special action and EOB tokens */
-    switch ( Token ) {
-    case DCT_EOB_PAIR_TOKEN:
-      pbi->EOB_Run = 1;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_EOB_TRIPLE_TOKEN:
-      pbi->EOB_Run = 2;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_REPEAT_RUN_TOKEN:
-      pbi->EOB_Run = ExtraBits + 3;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_REPEAT_RUN2_TOKEN:
-      pbi->EOB_Run = ExtraBits + 7;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_REPEAT_RUN3_TOKEN:
-      pbi->EOB_Run = ExtraBits + 15;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    case DCT_REPEAT_RUN4_TOKEN:
-      pbi->EOB_Run = ExtraBits - 1;
-      *CoeffIndex = BLOCK_SIZE;
-      pbi->BlocksToDecode --;
-      break;
-    }
-  }
-}
-
-static void UnPackVideo (PB_INSTANCE *pbi){
-  long ret;
-  ogg_int32_t       EncodedCoeffs = 1;
-  ogg_int32_t       FragIndex;
-  ogg_int32_t *     CodedBlockListPtr;
-  ogg_int32_t *     CodedBlockListEnd;
-
-  unsigned char     AcHuffIndex1;
-  unsigned char     AcHuffIndex2;
-  unsigned char     AcHuffChoice1;
-  unsigned char     AcHuffChoice2;
-
-  unsigned char     DcHuffChoice1;
-  unsigned char     DcHuffChoice2;
-
-
-  /* Bail out immediately if a decode error has already been reported. */
-  if ( pbi->DecoderErrorCode ) return;
-
-  /* Clear down the array that indicates the current coefficient index
-     for each block. */
-  memset(pbi->FragCoeffs, 0, pbi->UnitFragments);
-  memset(pbi->FragCoefEOB, 0, pbi->UnitFragments);
-
-  /* Clear down the pbi->QFragData structure for all coded blocks. */
-  ClearDownQFragData(pbi);
-
-  /* Note the number of blocks to decode */
-  pbi->BlocksToDecode = pbi->CodedBlockIndex;
-
-  /* Get the DC huffman table choice for Y and then UV */
-  theora_read(pbi->opb,DC_HUFF_CHOICE_BITS,&ret); 
-  DcHuffChoice1 = ret + DC_HUFF_OFFSET;
-  if (ret < 0 || DcHuffChoice1 >= NUM_HUFF_TABLES) {
-    DcHuffChoice1 = DC_HUFF_OFFSET;
-    pbi->DecoderErrorCode = 1;
-  }
-  theora_read(pbi->opb,DC_HUFF_CHOICE_BITS,&ret); 
-  DcHuffChoice2 = ret + DC_HUFF_OFFSET;
-  if (ret < 0 || DcHuffChoice2 >= NUM_HUFF_TABLES) {
-    DcHuffChoice2 = DC_HUFF_OFFSET;
-    pbi->DecoderErrorCode = 1;
-  }
-
-  /* UnPack DC coefficients / tokens */
-  CodedBlockListPtr = pbi->CodedBlockList;
-  CodedBlockListEnd = &pbi->CodedBlockList[pbi->CodedBlockIndex];
-  while ( CodedBlockListPtr < CodedBlockListEnd  ) {
-    /* Get the block data index */
-    FragIndex = *CodedBlockListPtr;
-    pbi->FragCoefEOB[FragIndex] = pbi->FragCoeffs[FragIndex];
-
-    /* Select the appropriate huffman table offset according to
-       whether the token is from a Y or UV block */
-    if ( FragIndex < (ogg_int32_t)pbi->YPlaneFragments )
-      pbi->DcHuffChoice = DcHuffChoice1;
-    else
-      pbi->DcHuffChoice = DcHuffChoice2;
-
-    /* If we are in the middle of an EOB run */
-    if ( pbi->EOB_Run ){
-      /* Mark the current block as fully expanded and decrement
-         EOB_RUN count */
-      pbi->FragCoeffs[FragIndex] = BLOCK_SIZE;
-      pbi->EOB_Run --;
-      pbi->BlocksToDecode --;
-    }else{
-      /* Else unpack a DC token */
-      UnpackAndExpandDcToken( pbi,
-                              pbi->QFragData[FragIndex],
-                              &pbi->FragCoeffs[FragIndex] );
-    }
-    CodedBlockListPtr++;
-  }
-
-  /* Get the AC huffman table choice for Y and then for UV. */
-
-  theora_read(pbi->opb,AC_HUFF_CHOICE_BITS,&ret); 
-  AcHuffIndex1 = ret + AC_HUFF_OFFSET;
-  if (ret < 0 || AcHuffIndex1 >= NUM_HUFF_TABLES) {
-    AcHuffIndex1 = AC_HUFF_OFFSET;
-    pbi->DecoderErrorCode = 1;
-  }
-  theora_read(pbi->opb,AC_HUFF_CHOICE_BITS,&ret); 
-  AcHuffIndex2 = ret + AC_HUFF_OFFSET;
-  if (ret < 0 || AcHuffIndex2 >= NUM_HUFF_TABLES) {
-    AcHuffIndex2 = AC_HUFF_OFFSET;
-    pbi->DecoderErrorCode = 1;
-  }
-
-  /* Unpack Lower AC coefficients. */
-  while ( EncodedCoeffs < 64 ) {
-    /* Repeatedly scan through the list of blocks. */
-    CodedBlockListPtr = pbi->CodedBlockList;
-    CodedBlockListEnd = &pbi->CodedBlockList[pbi->CodedBlockIndex];
-
-    /* Huffman table selection based upon which AC coefficient we are on */
-    if ( EncodedCoeffs <= AC_TABLE_2_THRESH ){
-      AcHuffChoice1 = AcHuffIndex1;
-      AcHuffChoice2 = AcHuffIndex2;
-    }else if ( EncodedCoeffs <= AC_TABLE_3_THRESH ){
-      AcHuffChoice1 = AcHuffIndex1 + AC_HUFF_CHOICES;
-      AcHuffChoice2 = AcHuffIndex2 + AC_HUFF_CHOICES;
-    } else if ( EncodedCoeffs <= AC_TABLE_4_THRESH ){
-      AcHuffChoice1 = AcHuffIndex1 + (AC_HUFF_CHOICES * 2);
-      AcHuffChoice2 = AcHuffIndex2 + (AC_HUFF_CHOICES * 2);
-    } else {
-      AcHuffChoice1 = AcHuffIndex1 + (AC_HUFF_CHOICES * 3);
-      AcHuffChoice2 = AcHuffIndex2 + (AC_HUFF_CHOICES * 3);
-    }
-
-    while( CodedBlockListPtr < CodedBlockListEnd ) {
-      /* Get the linear index for the current fragment. */
-      FragIndex = *CodedBlockListPtr;
-
-      /* Should we decode a token for this block on this pass. */
-      if ( pbi->FragCoeffs[FragIndex] <= EncodedCoeffs ) {
-        pbi->FragCoefEOB[FragIndex] = pbi->FragCoeffs[FragIndex];
-        /* If we are in the middle of an EOB run */
-        if ( pbi->EOB_Run ) {
-          /* Mark the current block as fully expanded and decrement
-             EOB_RUN count */
-          pbi->FragCoeffs[FragIndex] = BLOCK_SIZE;
-          pbi->EOB_Run --;
-          pbi->BlocksToDecode --;
-        }else{
-          /* Else unpack an AC token */
-          /* Work out which huffman table to use, then decode a token */
-          if ( FragIndex < (ogg_int32_t)pbi->YPlaneFragments )
-            pbi->ACHuffChoice = AcHuffChoice1;
-          else
-            pbi->ACHuffChoice = AcHuffChoice2;
-
-          UnpackAndExpandAcToken( pbi, pbi->QFragData[FragIndex],
-                                  &pbi->FragCoeffs[FragIndex] );
-        }
-      }
-      CodedBlockListPtr++;
-    }
-
-    /* Test for condition where there are no blocks left with any
-       tokesn to decode */
-    if ( !pbi->BlocksToDecode )
-      break;
-
-    EncodedCoeffs ++;
-  }
-}
-
-static void DecodeData(PB_INSTANCE *pbi){
-  ogg_uint32_t i;
-
-  /* Bail out immediately if a decode error has already been reported. */
-  if ( pbi->DecoderErrorCode ) return;
-
-  /* Clear down the macro block level mode and MV arrays. */
-  for ( i = 0; i < pbi->UnitFragments; i++ ){
-    pbi->FragCodingMethod[i] = CODE_INTER_NO_MV; /* Default coding mode */
-    pbi->FragMVect[i].x = 0;
-    pbi->FragMVect[i].y = 0;
-  }
-
-  /* Zero Decoder EOB run count */
-  pbi->EOB_Run = 0;
-
-  /* Make a note of the number of coded blocks this frame */
-  pbi->CodedBlocksThisFrame = pbi->CodedBlockIndex;
-
-  /* Decode the modes data */
-  DecodeModes( pbi, pbi->YSBRows, pbi->YSBCols);
-  if (pbi->DecoderErrorCode) return;
-
-  /* Unpack and decode the motion vectors. */
-  DecodeMVectors ( pbi, pbi->YSBRows, pbi->YSBCols);
-  if (pbi->DecoderErrorCode) return;
-
-  /* Unpack and decode the actual video data. */
-  UnPackVideo(pbi);
-  if (pbi->DecoderErrorCode) return;
-
-  /* Reconstruct and display the frame */
-  dsp_save_fpu (pbi->dsp);
-  ReconRefFrames(pbi);
-  dsp_restore_fpu (pbi->dsp);
-
-}
-
-
-int LoadAndDecode(PB_INSTANCE *pbi){
-
-  /* Reset the DC predictors. */
-  pbi->InvLastIntraDC = 0;
-  pbi->InvLastInterDC = 0;
-
-  if ( LoadFrame(pbi) == 0 ){
-    pbi->LastFrameQualityValue = pbi->ThisFrameQualityValue;
-
-    /* Decode the data into the fragment buffer. */
-    DecodeData(pbi);
-    if (pbi->DecoderErrorCode == 0) return 0;
-  }
-
-  return OC_BADPACKET;
-}

Modified: trunk/theora/lib/enc/dct_encode.c
===================================================================
--- trunk/theora/lib/enc/dct_encode.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/enc/dct_encode.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include "codec_internal.h"
 #include "dsp.h"
+#include "quant_lookup.h"
 
 
 static int ModeUsesMC[MAX_MODES] = { 0, 0, 1, 1, 1, 0, 1, 1 };

Modified: trunk/theora/lib/enc/encode.c
===================================================================
--- trunk/theora/lib/enc/encode.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/enc/encode.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -153,6 +153,8 @@
   /* Add the DC huffman table choice to the bitstream */
   oggpackB_write( opb, DcHuffChoice[1], DC_HUFF_CHOICE_BITS );
 
+  TH_DEBUG("dc hufftables = %d %d\n",(int)DcHuffChoice[0],(int)DcHuffChoice[1]);
+
   /* Encode the token list */
   for ( i = 0; i < cpi->OptimisedTokenCount; i++ ) {
 
@@ -560,6 +562,8 @@
   ogg_int32_t FragIndex;
   ogg_uint32_t HuffIndex; /* Index to group of tables used to code a token */
 
+  TH_DEBUG("\n>>>> beginning frame %d\n\n",dframe);
+
   /* Reset the count of second order optimised tokens */
   cpi->OptimisedTokenCount = 0;
 

Modified: trunk/theora/lib/enc/encoder_quant.c
===================================================================
--- trunk/theora/lib/enc/encoder_quant.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/enc/encoder_quant.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -20,6 +20,11 @@
 #include "codec_internal.h"
 #include "quant_lookup.h"
 
+#ifdef _TH_DEBUG_
+#include <stdio.h>
+extern FILE *debugout;
+extern long dframe;
+#endif
 
 void WriteQTables(PB_INSTANCE *pbi,oggpack_buffer* _opb) {
   
@@ -120,6 +125,64 @@
       oggpackB_write(_opb,indices[qti][pli][qri+1],nbits);
     }
   }
+
+#ifdef _TH_DEBUG_
+  /* dump the tables */
+  {
+    int i, j, k, l, m;
+    TH_DEBUG("loop filter limits = {");
+    for(i=0;i<64;){
+      TH_DEBUG("\n        ");
+      for(j=0;j<16;i++,j++)
+	TH_DEBUG("%3d ",_qinfo->loop_filter_limits[i]);
+    }
+    TH_DEBUG("\n}\n\n");
+
+    TH_DEBUG("ac scale = {");
+    for(i=0;i<64;){
+      TH_DEBUG("\n        ");
+      for(j=0;j<16;i++,j++)
+	TH_DEBUG("%3d ",_qinfo->ac_scale[i]);
+    }
+    TH_DEBUG("\n}\n\n");
+
+    TH_DEBUG("dc scale = {");
+    for(i=0;i<64;){
+      TH_DEBUG("\n        ");
+      for(j=0;j<16;i++,j++)
+	TH_DEBUG("%3d ",_qinfo->dc_scale[i]);
+    }
+    TH_DEBUG("\n}\n\n");
+
+    for(k=0;k<2;k++)
+      for(l=0;l<3;l++){
+	char *name[2][3]={
+	  {"intra Y bases","intra U bases", "intra V bases"},
+	  {"inter Y bases","inter U bases", "inter V bases"}
+	};
+
+	th_quant_ranges *r = &_qinfo->qi_ranges[k][l];
+	TH_DEBUG("%s = {\n",name[k][l]);
+	TH_DEBUG("        ranges = %d\n",r->nranges);
+	TH_DEBUG("        intervals = { ");
+	for(i=0;i<r->nranges;i++)
+	  TH_DEBUG("%3d ",r->sizes[i]);
+	TH_DEBUG("}\n");
+	TH_DEBUG("\n        matricies = { ");
+	for(m=0;m<r->nranges+1;m++){
+	  TH_DEBUG("\n          { ");
+	  for(i=0;i<64;){
+	    TH_DEBUG("\n            ");
+	    for(j=0;j<8;i++,j++)
+	      TH_DEBUG("%3d ",r->base_matrices[m][i]);
+	  }
+	  TH_DEBUG("\n          }");
+	}
+	TH_DEBUG("\n        }\n");
+      }
+  }
+    
+#endif
 }
 
 
@@ -233,7 +296,7 @@
     case 0:
       ZBinFactor = 0.65;
       if ( scale_factor <= 50 )
-        RoundingFactor = 0.499;
+        RoundingFactor = 0.49;
       else
         RoundingFactor = 0.46;
       break;

Modified: trunk/theora/lib/enc/encoder_toplevel.c
===================================================================
--- trunk/theora/lib/enc/encoder_toplevel.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/enc/encoder_toplevel.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -26,6 +26,11 @@
 #include "dsp.h"
 #include "codec_internal.h"
 
+#ifdef _TH_DEBUG_
+FILE *debugout=NULL;
+long dframe=0;
+#endif
+
 #define A_TABLE_SIZE        29
 #define DF_CANDIDATE_WINDOW 5
 
@@ -36,26 +41,26 @@
 /*The default quantization parameters used by VP3.1.*/
 static const int OC_VP31_RANGE_SIZES[1]={63};
 static const th_quant_base OC_VP31_BASES_INTRA_Y[2]={
-  {
-     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, 58, 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
+  { 
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
   },
-  {
-     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, 58, 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
-  }
+  { 
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+  },
 };
 static const th_quant_base OC_VP31_BASES_INTRA_C[2]={
   {
@@ -80,26 +85,28 @@
   }
 };
 static const th_quant_base OC_VP31_BASES_INTER[2]={
-  {
-     16, 16, 16, 20, 24, 28, 32, 40,
-     16, 16, 20, 24, 28, 32, 40, 48,
-     16, 20, 24, 28, 32, 40, 48, 64,
-     20, 24, 28, 32, 40, 48, 64, 64,
-     24, 28, 32, 40, 48, 64, 64, 64,
-     28, 32, 40, 48, 64, 64, 64, 96,
-     32, 40, 48, 64, 64, 64, 96,128,
-     40, 48, 64, 64, 64, 96,128,128
+  { 
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
   },
-  {
-     16, 16, 16, 20, 24, 28, 32, 40,
-     16, 16, 20, 24, 28, 32, 40, 48,
-     16, 20, 24, 28, 32, 40, 48, 64,
-     20, 24, 28, 32, 40, 48, 64, 64,
-     24, 28, 32, 40, 48, 64, 64, 64,
-     28, 32, 40, 48, 64, 64, 64, 96,
-     32, 40, 48, 64, 64, 64, 96,128,
-     40, 48, 64, 64, 64, 96,128,128
-  }
+  { 
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+    10,10,10,10,10,10,10,10,
+  },
+
+  
 };
 
 const th_quant_info TH_VP31_QUANT_INFO={
@@ -928,7 +935,7 @@
   cpi->ExhaustiveSearchThresh = 2500;
   cpi->MinImprovementForFourMV = 100;
   cpi->FourMVThreshold = 10000;
-  cpi->BitRateCapFactor = 1.50;
+  cpi->BitRateCapFactor = 5.0;
   cpi->InterTripOutThresh = 5000;
   cpi->MVEnabled = 1;
   cpi->InterCodeCount = 127;
@@ -1129,6 +1136,10 @@
     ((cpi->CurrentFrame - cpi->LastKeyFrame)<<cpi->pb.keyframe_granule_shift)+
     cpi->LastKeyFrame - 1;
 
+#ifdef _TH_DEBUG_
+  dframe++;
+#endif  
+
   return 0;
 }
 
@@ -1179,6 +1190,10 @@
   CP_INSTANCE *cpi=(CP_INSTANCE *)(t->internal_encode);
   int offset_y;
 
+#ifdef _TH_DEBUG_
+  debugout=fopen("theoraenc-debugout.txt","w");
+#endif
+
 #ifndef LIBOGG2
   oggpackB_reset(cpi->oggbuffer);
 #else
@@ -1345,6 +1360,12 @@
     _ogg_free(cpi->oggbuffer);
     _ogg_free(cpi);
   }
+
+#ifdef _TH_DEBUG_
+  fclose(debugout);
+  debugout=NULL;
+#endif
+
   memset(th,0,sizeof(*th));
 }
 

Modified: trunk/theora/lib/enc/frarray.c
===================================================================
--- trunk/theora/lib/enc/frarray.c	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/enc/frarray.c	2007-10-25 23:28:11 UTC (rev 14050)
@@ -20,7 +20,7 @@
 #include "block_inline.h"
 
 /* Long run bit string coding */
-static ogg_uint32_t FrArrayCodeSBRun( CP_INSTANCE *cpi, ogg_uint32_t value ){
+static ogg_uint32_t FrArrayCodeSBRun( CP_INSTANCE *cpi, ogg_uint32_t value){
   ogg_uint32_t CodedVal = 0;
   ogg_uint32_t CodedBits = 0;
 
@@ -56,7 +56,6 @@
     CodedVal = 0x3F000 + (value - 34);
     CodedBits = 18;
   }
-  /* todo: handle value > 4129 extension */
 
   /* Add the bits to the encode holding buffer. */
   oggpackB_write( cpi->oggbuffer, CodedVal, CodedBits );
@@ -109,7 +108,7 @@
 }
 
 void PackAndWriteDFArray( CP_INSTANCE *cpi ){
-  ogg_uint32_t  i;
+  ogg_uint32_t  i,j,k;
   unsigned char val;
   ogg_uint32_t  run_count;
 
@@ -124,6 +123,11 @@
   memset( cpi->PartiallyCodedFlags, 0, cpi->pb.SuperBlocks );
   memset( cpi->BlockCodedFlags, 0, cpi->pb.UnitFragments);
 
+#ifdef _TH_DEBUG_
+  unsigned char blockraster[cpi->pb.UnitFragments];
+  memset(blockraster,0,sizeof(blockraster));
+#endif
+
   for( SB = 0; SB < cpi->pb.SuperBlocks; SB++ ) {
     /* Check for coded blocks and macro-blocks */
     for ( MB=0; MB<4; MB++ ) {
@@ -139,9 +143,14 @@
             if ( cpi->pb.display_fragments[DfBlockIndex] ) {
               cpi->pb.SBCodedFlags[SB] = 1; /* SB at least partly coded */
               cpi->BlockCodedFlags[BListIndex] = 1; /* Block is coded */
+
+#ifdef _TH_DEBUG_
+	      blockraster[DfBlockIndex]=1;
+#endif	      
+
             }else{
               cpi->pb.SBFullyFlags[SB] = 0; /* SB not fully coded */
-              cpi->BlockCodedFlags[BListIndex] = 0; /* Block is not coded */
+              //cpi->BlockCodedFlags[BListIndex] = 0; /* Block is not coded */
             }
 
             BListIndex++;
@@ -161,24 +170,95 @@
     }
   }
 
+#ifdef _TH_DEBUG_
+  // assuming 4:2:0 right now
+  TH_DEBUG("predicted (partially coded frame)\n");
+  TH_DEBUG("superblock coded flags = {");
+  int x,y;
+  i=0;
+
+  for(y=0;y< (cpi->ScanConfig.VideoFrameHeight+31)/32;y++){
+    TH_DEBUG("\n   ");
+    for(x=0;x< (cpi->ScanConfig.VideoFrameWidth+31)/32;x++,i++)
+      TH_DEBUG("%x", ((cpi->pb.SBFullyFlags[i]!=0)|
+		      (cpi->PartiallyCodedFlags[i]!=0)));
+  }
+  TH_DEBUG("\n   ");
+  for(y=0;y< (cpi->ScanConfig.VideoFrameHeight+63)/64;y++){
+    TH_DEBUG("\n   ");
+    for(x=0;x< (cpi->ScanConfig.VideoFrameWidth+63)/64;x++,i++)
+      TH_DEBUG("%x", ((cpi->pb.SBFullyFlags[i]!=0)|
+		      (cpi->PartiallyCodedFlags[i]!=0)));
+  }
+  TH_DEBUG("\n   ");
+  for(y=0;y< (cpi->ScanConfig.VideoFrameHeight+63)/64;y++){
+    TH_DEBUG("\n   ");
+    for(x=0;x< (cpi->ScanConfig.VideoFrameWidth+63)/64;x++,i++)
+      TH_DEBUG("%x", ((cpi->pb.SBFullyFlags[i]!=0)|
+		      (cpi->PartiallyCodedFlags[i]!=0)));
+  }
+  TH_DEBUG("\n}\n");
+
+  if(i!=cpi->pb.SuperBlocks)
+    TH_DEBUG("WARNING!  superblock count, raster %d != flat %d\n",
+	     i,cpi->pb.SuperBlocks);
+
+  TH_DEBUG("block coded flags = {");
+
+  i=0;
+
+  for(y=0;y< (cpi->ScanConfig.VideoFrameHeight+7)/8;y++){
+    TH_DEBUG("\n   ");
+    for(x=0;x< (cpi->ScanConfig.VideoFrameWidth+7)/8;x++,i++)
+      TH_DEBUG("%x", blockraster[i]);
+  }
+  TH_DEBUG("\n   ");
+  for(y=0;y< (cpi->ScanConfig.VideoFrameHeight+15)/16;y++){
+    TH_DEBUG("\n   ");
+    for(x=0;x< (cpi->ScanConfig.VideoFrameWidth+15)/16;x++,i++)
+      TH_DEBUG("%x", blockraster[i]);
+  }
+  TH_DEBUG("\n   ");
+  for(y=0;y< (cpi->ScanConfig.VideoFrameHeight+15)/16;y++){
+    TH_DEBUG("\n   ");
+    for(x=0;x< (cpi->ScanConfig.VideoFrameWidth+15)/16;x++,i++)
+      TH_DEBUG("%x", blockraster[i]);
+  }
+  TH_DEBUG("\n}\n");
+
+  if(i!=cpi->pb.UnitFragments)
+    TH_DEBUG("WARNING!  block count, raster %d != flat %d\n",
+	     i,cpi->pb.UnitFragments);
+#endif	      
+
   /* Code list of partially coded Super-Block.  */
   val = cpi->PartiallyCodedFlags[0];
   oggpackB_write( cpi->oggbuffer, (ogg_uint32_t)val, 1);
-  i = 0;
+
+  i = 0; 
   while ( i < cpi->pb.SuperBlocks ) {
     run_count = 0;
-    while ( (i<cpi->pb.SuperBlocks) && (cpi->PartiallyCodedFlags[i]==val) ) {
+    while ( (i<cpi->pb.SuperBlocks) && 
+	    (cpi->PartiallyCodedFlags[i]==val) &&
+	    run_count<4129 ) {
       i++;
       run_count++;
     }
 
     /* Code the run */
-    FrArrayCodeSBRun( cpi, run_count );
-    val = ( val == 0 ) ? 1 : 0;
+    FrArrayCodeSBRun( cpi, run_count);
+
+    if(run_count >= 4129 && i < cpi->pb.SuperBlocks ){
+      val = cpi->PartiallyCodedFlags[i];
+      oggpackB_write( cpi->oggbuffer, (ogg_uint32_t)val, 1);
+      
+    }else
+      val = ( val == 0 ) ? 1 : 0;
   }
 
+
   /* RLC Super-Block fully/not coded. */
-  i = 0;
+  i = 0; 
 
   /* Skip partially coded blocks */
   while( (i < cpi->pb.SuperBlocks) && cpi->PartiallyCodedFlags[i] )
@@ -190,7 +270,9 @@
 
     while ( i < cpi->pb.SuperBlocks ) {
       run_count = 0;
-      while ( (i < cpi->pb.SuperBlocks) && (cpi->pb.SBFullyFlags[i] == val) ) {
+      while ( (i < cpi->pb.SuperBlocks) && 
+	      (cpi->pb.SBFullyFlags[i] == val) &&
+	      run_count < 4129) {
         i++;
         /* Skip partially coded blocks */
         while( (i < cpi->pb.SuperBlocks) && cpi->PartiallyCodedFlags[i] )
@@ -200,10 +282,16 @@
 
       /* Code the run */
       FrArrayCodeSBRun( cpi, run_count );
+
+    if(run_count >= 4129 && i < cpi->pb.SuperBlocks ){
+      val = cpi->PartiallyCodedFlags[i];
+      oggpackB_write( cpi->oggbuffer, (ogg_uint32_t)val, 1);
+    }else
       val = ( val == 0 ) ? 1 : 0;
     }
   }
 
+
   /*  Now code the block flags */
   if ( BListIndex > 0 ) {
     /* Code the block flags start value */
@@ -219,403 +307,11 @@
       }
 
       FrArrayCodeBlockRun( cpi, run_count );
-      val = ( val == 0 ) ? 1 : 0;
 
+      val = ( val == 0 ) ? 1 : 0;
     }
   }
 }
 
-static void FrArrayDeCodeInit(PB_INSTANCE *pbi){
-  /* Initialise the decoding of a run.  */
-  pbi->bit_pattern = 0;
-  pbi->bits_so_far = 0;
-}
 
-/* Short run bit string decoding */
-static int FrArrayDeCodeBlockRun(  PB_INSTANCE *pbi, ogg_uint32_t bit_value,
-                            ogg_int32_t * run_value ){
-  int  ret_val = 0;
 
-  /* Add in the new bit value. */
-  pbi->bits_so_far++;
-  pbi->bit_pattern = (pbi->bit_pattern << 1) + (bit_value & 1);
-
-  /* Coding scheme:
-     Codeword           RunLength
-     0x                    1-2
-     10x                   3-4
-     110x                  5-6
-     1110xx                7-10
-     11110xx              11-14
-     11111xxxx            15-30
-  */
-
-  switch ( pbi->bits_so_far ){
-  case 2:
-    /* If bit 1 is clear */
-    if ( !(pbi->bit_pattern & 0x0002) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0001) + 1;
-    }
-    break;
-
-  case 3:
-    /* If bit 1 is clear */
-    if ( !(pbi->bit_pattern & 0x0002) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0001) + 3;
-    }
-    break;
-
-  case 4:
-    /* If bit 1 is clear */
-    if ( !(pbi->bit_pattern & 0x0002) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0001) + 5;
-    }
-    break;
-
-  case 6:
-    /* If bit 2 is clear */
-    if ( !(pbi->bit_pattern & 0x0004) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0003) + 7;
-    }
-    break;
-
-  case 7:
-    /* If bit 2 is clear */
-    if ( !(pbi->bit_pattern & 0x0004) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0003) + 11;
-    }
-    break;
-
-  case 9:
-    ret_val = 1;
-    *run_value = (pbi->bit_pattern & 0x000F) + 15;
-    break;
-  }
-
-  return ret_val;
-}
-
-/* Long run bit string decoding */
-static int FrArrayDeCodeSBRun (PB_INSTANCE *pbi, ogg_uint32_t bit_value,
-                        ogg_int32_t * run_value ){
-  int ret_val = 0;
-
-  /* Add in the new bit value. */
-  pbi->bits_so_far++;
-  pbi->bit_pattern = (pbi->bit_pattern << 1) + (bit_value & 1);
-
-  /* Coding scheme:
-     Codeword            RunLength
-     0                       1
-     10x                    2-3
-     110x                   4-5
-     1110xx                 6-9
-     11110xxx              10-17
-     111110xxxx            18-33
-     111111xxxxxxxxxxxx    34-4129
-  */
-
-  switch ( pbi->bits_so_far ){
-  case 1:
-    if ( pbi->bit_pattern == 0 ){
-      ret_val = 1;
-      *run_value = 1;
-    }
-    break;
-
-  case 3:
-    /* Bit 1 clear */
-    if ( !(pbi->bit_pattern & 0x0002) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0001) + 2;
-    }
-    break;
-
-  case 4:
-    /* Bit 1 clear */
-    if ( !(pbi->bit_pattern & 0x0002) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0001) + 4;
-    }
-    break;
-
-  case 6:
-    /* Bit 2 clear */
-    if ( !(pbi->bit_pattern & 0x0004) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0003) + 6;
-    }
-    break;
-
-  case 8:
-    /* Bit 3 clear */
-    if ( !(pbi->bit_pattern & 0x0008) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x0007) + 10;
-    }
-    break;
-
-  case 10:
-    /* Bit 4 clear */
-    if ( !(pbi->bit_pattern & 0x0010) ){
-      ret_val = 1;
-      *run_value = (pbi->bit_pattern & 0x000F) + 18;
-    }
-    break;
-
-  case 18:
-    ret_val = 1;
-    *run_value = (pbi->bit_pattern & 0x0FFF) + 34;
-    break;
-
-  default:
-    ret_val = 0;
-    break;
-  }
-
-  /* todo: handle additional bits for values over 4129 */
-
-  return ret_val;
-}
-
-static void GetNextBInit(PB_INSTANCE *pbi){
-  long ret;
-
-  theora_read(pbi->opb,1,&ret);
-  pbi->NextBit = (unsigned char)ret;
-
-  /* Read run length */
-  FrArrayDeCodeInit(pbi);
-  do theora_read(pbi->opb,1,&ret);
-  while (FrArrayDeCodeBlockRun(pbi,ret,&pbi->BitsLeft)==0);
-
-}
-
-static unsigned char GetNextBBit (PB_INSTANCE *pbi){
-  long ret;
-  if ( !pbi->BitsLeft ){
-    /* Toggle the value.   */
-    pbi->NextBit = ( pbi->NextBit == 1 ) ? 0 : 1;
-
-    /* Read next run */
-    FrArrayDeCodeInit(pbi);
-    do theora_read(pbi->opb,1,&ret);
-    while (FrArrayDeCodeBlockRun(pbi,ret,&pbi->BitsLeft)==0);
-
-  }
-
-  /* Have  read a bit */
-  pbi->BitsLeft--;
-
-  /* Return next bit value */
-  return pbi->NextBit;
-}
-
-static void GetNextSbInit(PB_INSTANCE *pbi){
-  long ret;
-
-  theora_read(pbi->opb,1,&ret);
-  pbi->NextBit = (unsigned char)ret;
-
-  /* Read run length */
-  FrArrayDeCodeInit(pbi);
-  do theora_read(pbi->opb,1,&ret);
-  while (FrArrayDeCodeSBRun(pbi,ret,&pbi->BitsLeft)==0);
-
-}
-
-static unsigned char GetNextSbBit (PB_INSTANCE *pbi){
-  long ret;
-
-  if ( !pbi->BitsLeft ){
-    /* Toggle the value.   */
-    pbi->NextBit = ( pbi->NextBit == 1 ) ? 0 : 1;
-
-    /* Read next run */
-    FrArrayDeCodeInit(pbi);
-    do theora_read(pbi->opb,1,&ret);
-    while (FrArrayDeCodeSBRun(pbi,ret,&pbi->BitsLeft)==0);
-
-  }
-
-  /* Have  read a bit */
-  pbi->BitsLeft--;
-
-  /* Return next bit value */
-  return pbi->NextBit;
-}
-
-void QuadDecodeDisplayFragments ( PB_INSTANCE *pbi ){
-  ogg_uint32_t  SB, MB, B;
-  int    DataToDecode;
-
-  ogg_int32_t   dfIndex;
-  ogg_uint32_t  MBIndex = 0;
-
-  /* Reset various data structures common to key frames and inter frames. */
-  pbi->CodedBlockIndex = 0;
-  memset ( pbi->display_fragments, 0, pbi->UnitFragments );
-
-  /* For "Key frames" mark all blocks as coded and return. */
-  /* Else initialise the ArrayPtr array to 0 (all blocks uncoded by default) */
-  if ( GetFrameType(pbi) == KEY_FRAME ) {
-    memset( pbi->SBFullyFlags, 1, pbi->SuperBlocks );
-    memset( pbi->SBCodedFlags, 1, pbi->SuperBlocks );
-        memset( pbi->MBCodedFlags, 0, pbi->MacroBlocks );
-  }else{
-    memset( pbi->SBFullyFlags, 0, pbi->SuperBlocks );
-    memset( pbi->MBCodedFlags, 0, pbi->MacroBlocks );
-
-    /* Un-pack the list of partially coded Super-Blocks */
-    GetNextSbInit(pbi);
-    for( SB = 0; SB < pbi->SuperBlocks; SB++){
-      pbi->SBCodedFlags[SB] = GetNextSbBit (pbi);
-    }
-
-    /* Scan through the list of super blocks.  Unless all are marked
-       as partially coded we have more to do. */
-    DataToDecode = 0;
-    for ( SB=0; SB<pbi->SuperBlocks; SB++ ) {
-      if ( !pbi->SBCodedFlags[SB] ) {
-        DataToDecode = 1;
-        break;
-      }
-    }
-
-    /* Are there further block map bits to decode ? */
-    if ( DataToDecode ) {
-      /* Un-pack the Super-Block fully coded flags. */
-      GetNextSbInit(pbi);
-      for( SB = 0; SB < pbi->SuperBlocks; SB++) {
-        /* Skip blocks already marked as partially coded */
-        while( (SB < pbi->SuperBlocks) && pbi->SBCodedFlags[SB] )
-          SB++;
-
-        if ( SB < pbi->SuperBlocks ) {
-          pbi->SBFullyFlags[SB] = GetNextSbBit (pbi);
-
-          if ( pbi->SBFullyFlags[SB] )       /* If SB is fully coded. */
-            pbi->SBCodedFlags[SB] = 1;       /* Mark the SB as coded */
-        }
-      }
-    }
-
-    /* Scan through the list of coded super blocks.  If at least one
-       is marked as partially coded then we have a block list to
-       decode. */
-    for ( SB=0; SB<pbi->SuperBlocks; SB++ ) {
-      if ( pbi->SBCodedFlags[SB] && !pbi->SBFullyFlags[SB] ) {
-        /* Initialise the block list decoder. */
-        GetNextBInit(pbi);
-        break;
-      }
-    }
-  }
-
-  /* Decode the block data from the bit stream. */
-  for ( SB=0; SB<pbi->SuperBlocks; SB++ ){
-    for ( MB=0; MB<4; MB++ ){
-      /* If MB is in the frame */
-      if ( QuadMapToMBTopLeft(pbi->BlockMap, SB,MB) >= 0 ){
-        /* Only read block level data if SB was fully or partially coded */
-        if ( pbi->SBCodedFlags[SB] ) {
-          for ( B=0; B<4; B++ ){
-            /* If block is valid (in frame)... */
-            dfIndex = QuadMapToIndex1( pbi->BlockMap, SB, MB, B );
-            if ( dfIndex >= 0 ){
-              if ( pbi->SBFullyFlags[SB] )
-                pbi->display_fragments[dfIndex] = 1;
-              else
-                pbi->display_fragments[dfIndex] = GetNextBBit(pbi);
-
-              /* Create linear list of coded block indices */
-              if ( pbi->display_fragments[dfIndex] ) {
-                pbi->MBCodedFlags[MBIndex] = 1;
-                pbi->CodedBlockList[pbi->CodedBlockIndex] = dfIndex;
-                pbi->CodedBlockIndex++;
-              }
-            }
-          }
-        }
-        MBIndex++;
-
-      }
-    }
-  }
-}
-
-CODING_MODE FrArrayUnpackMode(PB_INSTANCE *pbi){
-  long ret;
-  /* Coding scheme:
-     Token                      Codeword           Bits
-     Entry   0 (most frequent)  0                   1
-     Entry   1                  10                  2
-     Entry   2                  110                 3
-     Entry   3                  1110                4
-     Entry   4                  11110               5
-     Entry   5                  111110              6
-     Entry   6                  1111110             7
-     Entry   7                  1111111             7
-  */
-
-  /* Initialise the decoding. */
-  pbi->bits_so_far = 0;
-
-  theora_read(pbi->opb,1,&ret);
-  pbi->bit_pattern = ret;
-
-  /* Do we have a match */
-  if ( pbi->bit_pattern == 0 )
-    return (CODING_MODE)0;
-
-  /* Get the next bit */
-  theora_read(pbi->opb,1,&ret);
-  pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
-
-  /* Do we have a match */
-  if ( pbi->bit_pattern == 0x0002 )
-    return (CODING_MODE)1;
-
-  theora_read(pbi->opb,1,&ret);
-  pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
-
-  /* Do we have a match  */
-  if ( pbi->bit_pattern == 0x0006 )
-    return (CODING_MODE)2;
-
-  theora_read(pbi->opb,1,&ret);
-  pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
-
-  /* Do we have a match */
-  if ( pbi->bit_pattern == 0x000E )
-    return (CODING_MODE)3;
-
-  theora_read(pbi->opb,1,&ret);
-  pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
-
-  /* Do we have a match */
-  if ( pbi->bit_pattern == 0x001E )
-    return (CODING_MODE)4;
-
-  theora_read(pbi->opb,1,&ret);
-  pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
-
-  /* Do we have a match */
-  if ( pbi->bit_pattern == 0x003E )
-    return (CODING_MODE)5;
-
-  theora_read(pbi->opb,1,&ret);
-  pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
-
-  /* Do we have a match */
-  if ( pbi->bit_pattern == 0x007E )
-    return (CODING_MODE)6;
-  else
-    return (CODING_MODE)7;
-}
-

Modified: trunk/theora/lib/internal.h
===================================================================
--- trunk/theora/lib/internal.h	2007-10-25 17:21:04 UTC (rev 14049)
+++ trunk/theora/lib/internal.h	2007-10-25 23:28:11 UTC (rev 14050)
@@ -28,11 +28,13 @@
 # include "dec/quant.h"
 
 /* debug macros */
-#ifdef DEBUG
+#ifdef _TH_DEBUG_
 #include <stdio.h>
-#define TH_DEBUG(x) fprintf(stderr, x)
+extern long dframe;
+extern FILE *debugout;
+#define TH_DEBUG(...) fprintf(debugout, __VA_ARGS__)
 #else
-#define TH_DEBUG(x)
+#define TH_DEBUG(...)
 #endif
 
 /*Thank you Microsoft, I know the order of operations.*/



More information about the commits mailing list