[xiph-commits] r14272 - branches/theora-thusnelda/lib/enc
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Wed Dec 5 21:32:49 PST 2007
Author: xiphmont
Date: 2007-12-05 21:32:49 -0800 (Wed, 05 Dec 2007)
New Revision: 14272
Modified:
branches/theora-thusnelda/lib/enc/codec_internal.h
branches/theora-thusnelda/lib/enc/dct_decode.c
branches/theora-thusnelda/lib/enc/dct_encode.c
branches/theora-thusnelda/lib/enc/encode.c
branches/theora-thusnelda/lib/enc/encoder_huffman.h
branches/theora-thusnelda/lib/enc/frinit.c
Log:
Eliminate the multi-stage 'token optimization'; directly pack to 64 group arrays, then tie the EOB runs of neighboring groups together.
Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h 2007-12-05 05:32:02 UTC (rev 14271)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h 2007-12-06 05:32:49 UTC (rev 14272)
@@ -205,7 +205,6 @@
unsigned char *dct_token[64];
ogg_uint16_t *dct_token_eb[64];
- ogg_uint32_t dct_token_pre[64];
ogg_uint32_t dct_token_count[64];
ogg_uint32_t dct_token_ycount[64];
@@ -236,8 +235,6 @@
/*********************************************************************/
- ogg_uint32_t RunLength;
-
ogg_int32_t MVPixelOffsetY[MAX_SEARCH_SITES];
ogg_uint32_t InterTripOutThresh;
unsigned char MVEnabled;
Modified: branches/theora-thusnelda/lib/enc/dct_decode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_decode.c 2007-12-05 05:32:02 UTC (rev 14271)
+++ branches/theora-thusnelda/lib/enc/dct_decode.c 2007-12-06 05:32:49 UTC (rev 14272)
@@ -58,7 +58,7 @@
default:
dsp_IDctSlow(cpi->dsp, data, quantizers, reconstruct );
}
-
+
/* Convert fragment number to a pixel offset in a reconstruction buffer. */
dsp_recon8x8 (cpi->dsp, &cpi->recon[fp->buffer_index],
reconstruct, cpi->stride[plane]);
Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c 2007-12-05 05:32:02 UTC (rev 14271)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c 2007-12-06 05:32:49 UTC (rev 14272)
@@ -16,6 +16,7 @@
********************************************************************/
#include <stdlib.h>
+#include <string.h>
#include "codec_internal.h"
#include "dsp.h"
#include "quant_lookup.h"
@@ -31,71 +32,97 @@
/* plane == 0 for Y, 1 for UV */
static void add_token(CP_INSTANCE *cpi, int plane, int coeff,
- unsigned char token, ogg_uint16_t eb,
- int prepend){
- if(prepend){
- int pre = cpi->dct_token_pre[coeff]++;
- *(cpi->dct_token[coeff] - pre) = token;
- *(cpi->dct_token_eb[coeff] - pre) = eb;
+ unsigned char token, ogg_uint16_t eb){
+
+ cpi->dct_token[coeff][cpi->dct_token_count[coeff]] = token;
+ cpi->dct_token_eb[coeff][cpi->dct_token_count[coeff]] = eb;
+ cpi->dct_token_count[coeff]++;
+
+ if(coeff == 0){
+ /* DC */
+ int i;
+ for ( i = 0; i < DC_HUFF_CHOICES; i++)
+ cpi->dc_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[i][token];
}else{
- cpi->dct_token[pos][cpi->dct_token_count[pos]] = token;
- cpi->dct_token_eb[pos][cpi->dct_token_count[pos]] = eb;
- cpi->dct_token_count[pos]++;
+ /* AC */
+ int i,offset = acoffset[coeff];
+ for ( i = 0; i < AC_HUFF_CHOICES; i++)
+ cpi->ac_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
}
+ if(!plane)cpi->dct_token_ycount[coeff]++;
+}
+
+static void prepend_token(CP_INSTANCE *cpi, int plane, int coeff,
+ unsigned char token, ogg_uint16_t eb){
+
+ cpi->dct_token[coeff]--;
+ cpi->dct_token_eb[coeff]--;
+ cpi->dct_token[coeff][0] = token;
+ cpi->dct_token_eb[coeff][0] = eb;
+ cpi->dct_token_count[coeff]++;
+
if(coeff == 0){
/* DC */
+ int i;
for ( i = 0; i < DC_HUFF_CHOICES; i++)
cpi->dc_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[i][token];
}else{
/* AC */
- int offset = acoffset[coeff];
+ int i,offset = acoffset[coeff];
for ( i = 0; i < AC_HUFF_CHOICES; i++)
- cpc->ac_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
+ cpi->ac_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
}
if(!plane)cpi->dct_token_ycount[coeff]++;
}
-static void emit_eob_run(CP_INSTANCE *cpi, int plane, int pos, int run, int prepend){
+static void emit_eob_run(CP_INSTANCE *cpi, int plane, int pos, int run){
if ( run <= 3 ) {
if ( run == 1 ) {
- add_token(cpi, plane, pos, DCT_EOB_TOKEN, 0, prepend);
- } else if ( cpi->RunLength == 2 ) {
- add_token(cpi, plane, pos, DCT_EOB_PAIR_TOKEN, 0, prepend);
+ add_token(cpi, plane, pos, DCT_EOB_TOKEN, 0);
+ } else if ( run == 2 ) {
+ add_token(cpi, plane, pos, DCT_EOB_PAIR_TOKEN, 0);
} else {
- add_token(cpi, plane, pos, DCT_EOB_TRIPLE_TOKEN, 0, prepend);
+ add_token(cpi, plane, pos, DCT_EOB_TRIPLE_TOKEN, 0);
}
} else {
if ( run < 8 ) {
- add_token(cpi, plane, pos, DCT_REPEAT_RUN_TOKEN, run-4, prepend);
- } else if ( cpi->RunLength < 16 ) {
- add_token(cpi, plane, pos, DCT_REPEAT_RUN2_TOKEN, run-8, prepend);
- } else if ( cpi->RunLength < 32 ) {
- add_token(cpi, plane, pos, DCT_REPEAT_RUN3_TOKEN, run-16, prepend);
- } else if ( cpi->RunLength < 4096) {
- add_token(cpi, plane, pos, DCT_REPEAT_RUN4_TOKEN, run, prepend);
+ add_token(cpi, plane, pos, DCT_REPEAT_RUN_TOKEN, run-4);
+ } else if ( run < 16 ) {
+ add_token(cpi, plane, pos, DCT_REPEAT_RUN2_TOKEN, run-8);
+ } else if ( run < 32 ) {
+ add_token(cpi, plane, pos, DCT_REPEAT_RUN3_TOKEN, run-16);
+ } else if ( run < 4096) {
+ add_token(cpi, plane, pos, DCT_REPEAT_RUN4_TOKEN, run);
}
}
}
-static void add_eob_run(CP_INSTANCE *cpi, int plane, int pos,
- int *eob_run, int *eob_pre){
- run = eob_run[pos];
- if(!run) return;
-
- /* pre-runs for a coefficient group > DC are a special case; they're
- handled when groups are tied together at the end of tokenization */
- if(pos > 0 !cpi->dct_token_count[pos]){
- /* no tokens emitted yet, this is a pre-run */
- eob_pre[pos] += run;
- }else{
- emit_eob_run(cpi,plane,pos,run,0);
+static void prepend_eob_run(CP_INSTANCE *cpi, int plane, int pos, int run){
+ if ( run <= 3 ) {
+ if ( run == 1 ) {
+ prepend_token(cpi, plane, pos, DCT_EOB_TOKEN, 0);
+ } else if ( run == 2 ) {
+ prepend_token(cpi, plane, pos, DCT_EOB_PAIR_TOKEN, 0);
+ } else {
+ prepend_token(cpi, plane, pos, DCT_EOB_TRIPLE_TOKEN, 0);
+ }
+
+ } else {
+
+ if ( run < 8 ) {
+ prepend_token(cpi, plane, pos, DCT_REPEAT_RUN_TOKEN, run-4);
+ } else if ( run < 16 ) {
+ prepend_token(cpi, plane, pos, DCT_REPEAT_RUN2_TOKEN, run-8);
+ } else if ( run < 32 ) {
+ prepend_token(cpi, plane, pos, DCT_REPEAT_RUN3_TOKEN, run-16);
+ } else if ( run < 4096) {
+ prepend_token(cpi, plane, pos, DCT_REPEAT_RUN4_TOKEN, run);
+ }
}
-
- eob_run[pos] = 0;
}
static void TokenizeDctValue (CP_INSTANCE *cpi,
@@ -108,39 +135,39 @@
if ( AbsDataVal == 1 ){
- add_token(cpi, plane, pos, (neg ? MINUS_ONE_TOKEN : ONE_TOKEN), 0, 0);
+ add_token(cpi, plane, coeff, (neg ? MINUS_ONE_TOKEN : ONE_TOKEN), 0);
} else if ( AbsDataVal == 2 ) {
- add_token(cpi, plane, pos, (neg ? MINUS_TWO_TOKEN : TWO_TOKEN), 0, 0);
+ add_token(cpi, plane, coeff, (neg ? MINUS_TWO_TOKEN : TWO_TOKEN), 0);
} else if ( AbsDataVal <= MAX_SINGLE_TOKEN_VALUE ) {
- add_token(cpi, plane, pos, LOW_VAL_TOKENS + (AbsDataVal - DCT_VAL_CAT2_MIN), neg, 0);
+ add_token(cpi, plane, coeff, LOW_VAL_TOKENS + (AbsDataVal - DCT_VAL_CAT2_MIN), neg);
} else if ( AbsDataVal <= 8 ) {
- add_token(cpi, plane, pos, DCT_VAL_CATEGORY3, (AbsDataVal - DCT_VAL_CAT3_MIN) + (neg << 1), 0);
+ add_token(cpi, plane, coeff, DCT_VAL_CATEGORY3, (AbsDataVal - DCT_VAL_CAT3_MIN) + (neg << 1));
} else if ( AbsDataVal <= 12 ) {
- add_token(cpi, plane, pos, DCT_VAL_CATEGORY4, (AbsDataVal - DCT_VAL_CAT4_MIN) + (neg << 2), 0);
+ add_token(cpi, plane, coeff, DCT_VAL_CATEGORY4, (AbsDataVal - DCT_VAL_CAT4_MIN) + (neg << 2));
} else if ( AbsDataVal <= 20 ) {
- add_token(cpi, plane, pos, DCT_VAL_CATEGORY5, (AbsDataVal - DCT_VAL_CAT5_MIN) + (neg << 3), 0);
+ add_token(cpi, plane, coeff, DCT_VAL_CATEGORY5, (AbsDataVal - DCT_VAL_CAT5_MIN) + (neg << 3));
} else if ( AbsDataVal <= 36 ) {
- add_token(cpi, plane, pos, DCT_VAL_CATEGORY6, (AbsDataVal - DCT_VAL_CAT6_MIN) + (neg << 4), 0);
+ add_token(cpi, plane, coeff, DCT_VAL_CATEGORY6, (AbsDataVal - DCT_VAL_CAT6_MIN) + (neg << 4));
} else if ( AbsDataVal <= 68 ) {
- add_token(cpi, plane, pos, DCT_VAL_CATEGORY7, (AbsDataVal - DCT_VAL_CAT7_MIN) + (neg << 5), 0);
+ add_token(cpi, plane, coeff, DCT_VAL_CATEGORY7, (AbsDataVal - DCT_VAL_CAT7_MIN) + (neg << 5));
} else {
- add_token(cpi, plane, pos, DCT_VAL_CATEGORY8, (AbsDataVal - DCT_VAL_CAT8_MIN) + (neg << 9), 0);
+ add_token(cpi, plane, coeff, DCT_VAL_CATEGORY8, (AbsDataVal - DCT_VAL_CAT8_MIN) + (neg << 9));
}
}
@@ -152,6 +179,7 @@
ogg_int16_t DataValue){
ogg_uint32_t AbsDataVal = abs( (ogg_int32_t)DataValue );
+ int neg = (DataValue<0);
/* Values are tokenised as category value and a number of additional
bits that define the category. */
@@ -159,150 +187,217 @@
if ( AbsDataVal == 1 ) {
if ( RunLength <= 5 )
- add_token(cpi,plane,coeff, DCT_RUN_CATEGORY1 + (RunLength - 1), ((DataValue&0x8000)>>15), 0);
+ add_token(cpi,plane,coeff, DCT_RUN_CATEGORY1 + RunLength - 1, neg);
else if ( RunLength <= 9 )
- add_token(cpi,plane,coeff, DCT_RUN_CATEGORY1B, RunLength - 6 + ((DataValue&0x8000)>>13), 0);
+ add_token(cpi,plane,coeff, DCT_RUN_CATEGORY1B, RunLength - 6 + (neg<<2));
else
- add_token(cpi,plane,coeff, DCT_RUN_CATEGORY1C, RunLength - 10 + ((DataValue&0x8000)>>12), 0);
+ add_token(cpi,plane,coeff, DCT_RUN_CATEGORY1C, RunLength - 10 + (neg<<3));
} else if ( AbsDataVal <= 3 ) {
if ( RunLength == 1 )
- add_token(cpi,plane,coeff, DCT_RUN_CATEGORY2, AbsDataVal - 2 + ((DataValue&0x8000)>>14), 0);
+ add_token(cpi,plane,coeff, DCT_RUN_CATEGORY2, AbsDataVal - 2 + (neg<<1));
else
add_token(cpi,plane,coeff, DCT_RUN_CATEGORY2B,
- ((DataValue&0x8000)>>13) + ((AbsDataVal-2)<<1) + RunLength - 2, 0);
+ (neg<<2) + ((AbsDataVal-2)<<1) + RunLength - 2);
}
}
-static int tokenize_pass (fragment_t *fp, int pos, int plane, int *eob_run, int *eob_pre){
- ogg_int16_t DC = fp->pred_dc;
- ogg_int16_t *RawData = fp->dct;
- ogg_uint32_t *TokenListPtr = fp->token_list;
- ogg_int16_t val = (i ? RawData[i] : DC);
- int zero_run;
- int i = pos;
-
- while( (i < BLOCK_SIZE) && (!val) )
- val = RawData[++i];
+static void tokenize_groups(CP_INSTANCE *cpi,
+ int *eob_run, int *eob_plane, int *eob_ypre, int *eob_uvpre){
+ fragment_t *fp = cpi->coded_tail;
- if ( i == BLOCK_SIZE ){
+ while(fp){
+ int coeff = 0;
+ int plane = (fp >= cpi->frag[1]);
+ fp->nonzero = 0;
- eob_run[pos]++;
- if(eob_run[pos] >= 4095)
- add_eob_run(cpi,plane,pos,eob_run,eob_pre);
- return i;
+ while(coeff < BLOCK_SIZE){
+ ogg_int16_t val = (coeff ? fp->dct[coeff] : fp->pred_dc);
+ int zero_run;
+ int i = coeff;
+
+ fp->nonzero = coeff;
+
+ while( !val && (++i < BLOCK_SIZE) )
+ val = fp->dct[i];
+
+ if ( i == BLOCK_SIZE ){
- }
-
- fp->nonzero = i;
- add_eob_run(cpi,plane,pos,eob_run,eob_pre); /* if any */
-
- zero_run = i-pos;
- if (zero_run){
- ogg_uint32_t absval = abs(val);
- if ( ((absval == 1) && (zero_run <= 17)) ||
- ((absval <= 3) && (zero_run <= 3)) ) {
- TokenizeDctRunValue( cpi, plane, pos, run_count, val);
- }else{
- if ( zero_run <= 8 )
- add_token(cpi, plane, pos, DCT_SHORT_ZRL_TOKEN, run_count - 1);
- else
- add_token(cpi, pos, DCT_ZRL_TOKEN, run_count - 1);
- TokenizeDctValue( cpi, plane, pos, val );
+ /* if there are no other tokens in this group yet, set up to be
+ prepended later. Group 0 is the exception (can't be
+ prepended) */
+ if(cpi->dct_token_count[coeff] == 0 && coeff){
+ if(!plane)
+ eob_ypre[coeff]++;
+ else
+ eob_uvpre[coeff]++;
+ }else{
+ if(eob_run[coeff] == 4095){
+ emit_eob_run(cpi,eob_plane[coeff],coeff,4095);
+ eob_run[coeff] = 0;
+ }
+
+ if(eob_run[coeff]==0)
+ eob_plane[coeff]=plane;
+
+ eob_run[coeff]++;
+ }
+ coeff = BLOCK_SIZE;
+ }else{
+
+ if(eob_run[coeff]){
+ emit_eob_run(cpi,eob_plane[coeff],coeff,eob_run[coeff]);
+ eob_run[coeff]=0;
+ }
+
+ zero_run = i-coeff;
+ if (zero_run){
+ ogg_uint32_t absval = abs(val);
+ if ( ((absval == 1) && (zero_run <= 17)) ||
+ ((absval <= 3) && (zero_run <= 3)) ) {
+ TokenizeDctRunValue( cpi, plane, coeff, zero_run, val);
+ coeff = i+1;
+ }else{
+ if ( zero_run <= 8 )
+ add_token(cpi, plane, coeff, DCT_SHORT_ZRL_TOKEN, zero_run - 1);
+ else
+ add_token(cpi, plane, coeff, DCT_ZRL_TOKEN, zero_run - 1);
+ coeff = i;
+ }
+ }else{
+ TokenizeDctValue( cpi, plane, coeff, val );
+ coeff = i+1;
+ }
+ }
}
- }else{
- TokenizeDctValue( cpi, plane, pos, val );
+ fp=fp->next;
}
-
- return i+1;
}
void DPCMTokenize (CP_INSTANCE *cpi){
- fragment_t *fp = cpi->coded_tail;
int eob_run[64];
- int eob_pre[64];
+ int eob_plane[64];
- memset(eob_run, 0 sizeof(eob_run));
- memset(eob_pre, 0 sizeof(eob_pre));
+ int eob_ypre[64];
+ int eob_uvpre[64];
+
+ int i;
+
+ memset(eob_run, 0, sizeof(eob_run));
+ memset(eob_ypre, 0, sizeof(eob_ypre));
+ memset(eob_uvpre, 0, sizeof(eob_uvpre));
memset(cpi->dc_bits, 0, sizeof(cpi->dc_bits));
memset(cpi->ac_bits, 0, sizeof(cpi->ac_bits));
memset(cpi->dct_token_count, 0, sizeof(cpi->dct_token_count));
memset(cpi->dct_token_ycount, 0, sizeof(cpi->dct_token_ycount));
- memset(cpi->dct_token_pre, 0, sizeof(cpi->dct_token_pre));
- /* Tokenise the dct data. */
- while(fp){
- int coeff = 0;
- int plane = (fp >= cpi->frag[1]);
-
- fp->nonzero = 0;
- while(coeff < BLOCK_SIZE)
- coeff = tokenize_pass (fp, coeff, plane, eob_run, eob_pre);
+ for(i=0;i<BLOCK_SIZE;i++){
+ cpi->dct_token[i] = cpi->dct_token_storage+cpi->frag_total*i;
+ cpi->dct_token_eb[i] = cpi->dct_token_eb_storage+cpi->frag_total*i;
+ }
- fp = fp->next;
- }
-
- /* sew together group pre- and post- EOB runs */
- /* there are two categories of runs:
- 1) runs that end a group and may or may not extend into the next
- 2) pre runs that begin at group position 0
-
- Category 2 is a special case that requires potentially
- 'prepending' tokens to the group. */
-
+ /* Tokenize the dct data. */
+ tokenize_groups (cpi, eob_run, eob_plane, eob_ypre, eob_uvpre);
+
+ /* tie together eob runs at the beginnings/ends of coeff groups */
{
+ int coeff = 0;
int run = 0;
- int run_coeff = 0;
- int run_frag = 0;
+ int plane = 0;
for(i=0;i<BLOCK_SIZE;i++){
- run += cpi->dct_eob_pre[i];
- if(cpi->dct_token_count[i]){
-
- /* first code the spanning/preceeding run */
- while(run){
- int v = (run < 4095 ? run : 4095);
- int plane = (run_frag >= cpi->coded_y);
-
- if(run_coeff == i){
- /* prepend to current group */
- emit_eob_run(cpi, plane, run_coeff, v, 1);
+ if(eob_ypre[i] || eob_uvpre[i]){
+ /* group begins with an EOB run */
+
+ if(run && run + eob_ypre[i] >= 4095){
+ emit_eob_run(cpi,plane,coeff,4095);
+ eob_ypre[i] -= 4095-run;
+ run = 0;
+ coeff = i;
+ plane = (eob_ypre[i] ? 0 : 1);
+ }
+
+ if(run && run + eob_ypre[i] + eob_uvpre[i] >= 4095){
+ emit_eob_run(cpi,plane,coeff,4095);
+ eob_uvpre[i] -= 4095 - eob_ypre[i] - run;
+ eob_ypre[i] = 0;
+ run = 0;
+ coeff = i;
+ plane = 1;
+ }
+
+ if(run){
+ if(cpi->dct_token_count[i]){
+ /* group is not only an EOB run; emit the run token */
+ emit_eob_run(cpi,plane,coeff,run + eob_ypre[i] + eob_uvpre[i]);
+ eob_ypre[i] = 0;
+ eob_uvpre[i] = 0;
+ run = eob_run[i];
+ coeff = i;
+ plane = eob_plane[i];
}else{
- /* append to indicated coeff group; it is possible the run
- spans multiple coeffs, it will always be an append as
- intervening groups would have a zero token count */
- emit_eob_run(cpi, plane, run_coeff, v, 0);
+ /* group consists entirely of EOB run. Add, iterate */
+ run += eob_ypre[i];
+ run += eob_uvpre[i];
+ eob_ypre[i] = 0;
+ eob_uvpre[i] = 0;
}
+ }else{
- run_frag += v;
- run -= v;
- while(run_frag >= cpi->coded_total){
- run_coeff++;
- run_frag -= cpi->coded_total;
+ if(cpi->dct_token_count[i]){
+ /* there are other tokens in this group; work backwards as we need to prepend */
+ while(eob_uvpre[i] >= 4095){
+ prepend_eob_run(cpi,1,i,4095);
+ eob_uvpre[i] -= 4095;
+ }
+ while(eob_uvpre[i] + eob_ypre[i] >= 4095){
+ prepend_eob_run(cpi,0,i,4095);
+ eob_ypre[i] -= 4095 - eob_uvpre[i];
+ eob_uvpre[i] = 0;
+ }
+ if(eob_uvpre[i] + eob_ypre[i]){
+ prepend_eob_run(cpi, (eob_ypre[i] ? 0 : 1), i, eob_ypre[i] + eob_uvpre[i]);
+ eob_ypre[i] = 0;
+ eob_uvpre[i] = 0;
+ }
+ run = eob_run[i];
+ coeff = i;
+ plane = eob_plane[i];
+ }else{
+ /* group consists entirely of EOB run. Add, flush overs, iterate */
+ while(eob_ypre[i] >= 4095){
+ emit_eob_run(cpi,0,i,4095);
+ eob_ypre[i] -= 4095;
+ }
+ while(eob_uvpre[i] + eob_ypre[i] >= 4095){
+ emit_eob_run(cpi,(eob_ypre[i] ? 0 : 1), i, 4095);
+ eob_uvpre[i] -= 4095 - eob_ypre[i];
+ eob_ypre[i] = 0;
+ }
+ run = eob_uvpre[i]+eob_ypre[i];
+ coeff = i;
+ plane = (eob_ypre[i] ? 0 : 1);
}
}
-
- run_frag = cpi->coded_total - cpi->dct_eob_run[i];
+ }else{
+ /* no eob run to begin group */
+ if(cpi->dct_token_count[i]){
+ if(run)
+ emit_eob_run(cpi,plane,coeff,run);
+
+ run = eob_run[i];
+ coeff = i;
+ plane = eob_plane[i];
+ }
}
- run += cpi->dct_eob_run[i];
-
}
- /* tie off last run */
- while(run){
- int v = (run < 4095 ? run : 4095);
- int plane = (run_frag >= cpi->coded_y);
- emit_eob_run(cpi, plane, run_coeff, v,0);
- run_frag += v;
- run -= v;
- while(run_frag >= cpi->coded_total){
- run_coeff++;
- run_frag -= cpi->coded_total;
- }
- }
+ if(run)
+ emit_eob_run(cpi,plane,coeff,run);
+
}
}
Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c 2007-12-05 05:32:02 UTC (rev 14271)
+++ branches/theora-thusnelda/lib/enc/encode.c 2007-12-06 05:32:49 UTC (rev 14272)
@@ -198,7 +198,7 @@
}
static void EncodeDcTokenList (CP_INSTANCE *cpi) {
- int i,j;
+ int i,plane;
int best;
int huff[2];
oggpack_buffer *opb=cpi->oggbuffer;
@@ -206,11 +206,11 @@
/* Work out which table options are best for DC */
for(plane = 0; plane<2; plane++){
best = cpi->dc_bits[plane][0];
- huff[plane] = 0;
- for ( j = 1; j < DC_HUFF_CHOICES; j++ ) {
- if ( cpi->dc_bits[plane][j] < best ) {
- best = cpi->dc_bits[plane][j];
- huff[plane] = j + DC_HUFF_OFFSET;
+ huff[plane] = DC_HUFF_OFFSET;
+ for ( i = 1; i < DC_HUFF_CHOICES; i++ ) {
+ if ( cpi->dc_bits[plane][i] < best ) {
+ best = cpi->dc_bits[plane][i];
+ huff[plane] = i + DC_HUFF_OFFSET;
}
}
oggpackB_write( opb, huff[plane] - DC_HUFF_OFFSET, DC_HUFF_CHOICE_BITS );
@@ -221,6 +221,7 @@
int token = cpi->dct_token[0][i];
int eb = cpi->dct_token_eb[0][i];
int plane = (i >= cpi->dct_token_ycount[0]);
+
oggpackB_write( opb, cpi->HuffCodeArray_VP3x[huff[plane]][token],
cpi->HuffCodeLengthArray_VP3x[huff[plane]][token] );
@@ -231,46 +232,29 @@
static void EncodeAcGroup(CP_INSTANCE *cpi, int group, int huff_offset, int *huffchoice){
int i;
-
+ oggpack_buffer *opb=cpi->oggbuffer;
int c = 0;
int y = cpi->dct_token_ycount[group];
- /* pre-tokens, then post-tokens */
-
- for(j=1; j<=cpi->dct_token_pre[group]; j++){
- int token = *(cpi->dct_token[group]-j);
- int eb = *(cpi->dct_token_eb[group]-j);
+ for(i=0; i<cpi->dct_token_count[group]; i++){
+ int token = cpi->dct_token[group][i];
+ int eb = cpi->dct_token_eb[group][i];
int plane = (c >= y);
- int hi = huff_offset + huffchoice[plane];
- oggpackB_write( opb, cpi->pb.HuffCodeArray_VP3x[hi][token],
- cpi->pb.HuffCodeLengthArray_VP3x[hi][token] );
-
- if ( cpi->pb.ExtraBitLengths_VP3x[token] > 0 )
- oggpackB_write( opb, eb,cpi->pb.ExtraBitLengths_VP3x[token] );
-
- c++;
- }
-
- for(j=0; j<cpi->dct_token_count[group]; j++){
- int token = cpi->dct_token[group][j];
- int eb = cpi->dct_token_eb[group][j];
- int plane = (c >= y);
-
int hi = huff_offset + huffchoice[plane];
- oggpackB_write( opb, cpi->pb.HuffCodeArray_VP3x[hi][token],
- cpi->pb.HuffCodeLengthArray_VP3x[hi][token] );
+ oggpackB_write( opb, cpi->HuffCodeArray_VP3x[hi][token],
+ cpi->HuffCodeLengthArray_VP3x[hi][token] );
- if ( cpi->pb.ExtraBitLengths_VP3x[token] > 0 )
- oggpackB_write( opb, eb,cpi->pb.ExtraBitLengths_VP3x[token] );
+ if (cpi->ExtraBitLengths_VP3x[token] > 0)
+ oggpackB_write( opb, eb,cpi->ExtraBitLengths_VP3x[token] );
c++;
}
}
static void EncodeAcTokenList (CP_INSTANCE *cpi) {
- int i,j;
+ int i,plane;
int best;
int huff[2];
oggpack_buffer *opb=cpi->oggbuffer;
@@ -278,11 +262,11 @@
/* Work out which table options are best for AC */
for(plane = 0; plane<2; plane++){
best = cpi->ac_bits[plane][0];
- huff[plane] = 0;
- for ( j = 1; j < AC_HUFF_CHOICES; j++ ) {
- if ( cpi->ac_bits[plane][j] < best ){
- best = cpi->ac_bits[plane][j];
- huff[plane] = j + AC_HUFF_OFFSET;
+ huff[plane] = AC_HUFF_OFFSET;
+ for ( i = 1; i < AC_HUFF_CHOICES; i++ ) {
+ if ( cpi->ac_bits[plane][i] < best ){
+ best = cpi->ac_bits[plane][i];
+ huff[plane] = i + AC_HUFF_OFFSET;
}
}
oggpackB_write( opb, huff[plane] - AC_HUFF_OFFSET, AC_HUFF_CHOICE_BITS );
@@ -483,9 +467,6 @@
PredictDC(cpi);
DPCMTokenize(cpi);
- ogg_int32_t EncodedCoeffs = 1;
- fragment_t *fp;
-
/* The tree is not needed (implicit) for key frames */
if ( cpi->FrameType != KEY_FRAME )
PackAndWriteDFArray( cpi );
Modified: branches/theora-thusnelda/lib/enc/encoder_huffman.h
===================================================================
--- branches/theora-thusnelda/lib/enc/encoder_huffman.h 2007-12-05 05:32:02 UTC (rev 14271)
+++ branches/theora-thusnelda/lib/enc/encoder_huffman.h 2007-12-06 05:32:49 UTC (rev 14272)
@@ -57,19 +57,19 @@
#define TWO_TOKEN 11
#define MINUS_TWO_TOKEN 12
-#define LOW_VAL_TOKENS (MINUS_TWO_TOKEN + 1)
-#define DCT_VAL_CATEGORY3 (LOW_VAL_TOKENS + 4)
-#define DCT_VAL_CATEGORY4 (DCT_VAL_CATEGORY3 + 1)
-#define DCT_VAL_CATEGORY5 (DCT_VAL_CATEGORY4 + 1)
-#define DCT_VAL_CATEGORY6 (DCT_VAL_CATEGORY5 + 1)
-#define DCT_VAL_CATEGORY7 (DCT_VAL_CATEGORY6 + 1)
-#define DCT_VAL_CATEGORY8 (DCT_VAL_CATEGORY7 + 1)
+#define LOW_VAL_TOKENS (MINUS_TWO_TOKEN + 1) /* 13-16 */
+#define DCT_VAL_CATEGORY3 (LOW_VAL_TOKENS + 4) /* 17 */
+#define DCT_VAL_CATEGORY4 (DCT_VAL_CATEGORY3 + 1) /* 18 */
+#define DCT_VAL_CATEGORY5 (DCT_VAL_CATEGORY4 + 1) /* 19 */
+#define DCT_VAL_CATEGORY6 (DCT_VAL_CATEGORY5 + 1) /* 20 */
+#define DCT_VAL_CATEGORY7 (DCT_VAL_CATEGORY6 + 1) /* 21 */
+#define DCT_VAL_CATEGORY8 (DCT_VAL_CATEGORY7 + 1) /* 22 */
-#define DCT_RUN_CATEGORY1 (DCT_VAL_CATEGORY8 + 1)
-#define DCT_RUN_CATEGORY1B (DCT_RUN_CATEGORY1 + 5)
-#define DCT_RUN_CATEGORY1C (DCT_RUN_CATEGORY1B + 1)
-#define DCT_RUN_CATEGORY2 (DCT_RUN_CATEGORY1C + 1)
-#define DCT_RUN_CATEGORY2B (DCT_RUN_CATEGORY2 + 1)
+#define DCT_RUN_CATEGORY1 (DCT_VAL_CATEGORY8 + 1) /* 23-27 */
+#define DCT_RUN_CATEGORY1B (DCT_RUN_CATEGORY1 + 5) /* 28 */
+#define DCT_RUN_CATEGORY1C (DCT_RUN_CATEGORY1B+ 1) /* 29 */
+#define DCT_RUN_CATEGORY2 (DCT_RUN_CATEGORY1C+ 1) /* 30 */
+#define DCT_RUN_CATEGORY2B (DCT_RUN_CATEGORY2 + 1) /* 31 */
/* 32 */
-#define MAX_ENTROPY_TOKENS (DCT_RUN_CATEGORY2 + 2)
+#define MAX_ENTROPY_TOKENS (DCT_RUN_CATEGORY2B + 1) /* 32 */
Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c 2007-12-05 05:32:02 UTC (rev 14271)
+++ branches/theora-thusnelda/lib/enc/frinit.c 2007-12-06 05:32:49 UTC (rev 14272)
@@ -16,6 +16,7 @@
********************************************************************/
#include <stdlib.h>
+#include <string.h>
#include "codec_internal.h"
@@ -33,18 +34,15 @@
if(cpi->recon) _ogg_free(cpi->recon);
cpi->recon = 0;
- if(cpi->OptimisedTokenListEb ) _ogg_free(cpi->OptimisedTokenListEb);
- cpi->OptimisedTokenListEb = 0;
+ if(cpi->dct_token_storage) _ogg_free(cpi->dct_token_storage);
+ cpi->dct_token_storage = 0;
- if(cpi->OptimisedTokenList ) _ogg_free(cpi->OptimisedTokenList);
- cpi->OptimisedTokenList = 0;
+ if(cpi->dct_token_eb_storage) _ogg_free(cpi->dct_token_eb_storage);
+ cpi->dct_token_eb_storage = 0;
- if(cpi->OptimisedTokenListHi ) _ogg_free(cpi->OptimisedTokenListHi);
- cpi->OptimisedTokenListHi = 0;
+ memset(cpi->dct_token,0,sizeof(cpi->dct_token));
+ memset(cpi->dct_token_eb,0,sizeof(cpi->dct_token_eb));
- if(cpi->OptimisedTokenListPl ) _ogg_free(cpi->OptimisedTokenListPl);
- cpi->OptimisedTokenListPl = 0;
-
if(cpi->frag[0]) _ogg_free(cpi->frag[0]);
cpi->frag[0] = 0;
cpi->frag[1] = 0;
@@ -82,6 +80,7 @@
a waste of code. */
void InitFrameInfo(CP_INSTANCE *cpi){
+
cpi->stride[0] = (cpi->info.width + STRIDE_EXTRA);
cpi->stride[1] = (cpi->info.width + STRIDE_EXTRA) / 2;
cpi->stride[2] = (cpi->info.width + STRIDE_EXTRA) / 2;
@@ -211,19 +210,9 @@
cpi->golden = _ogg_malloc(cpi->frame_size*sizeof(*cpi->golden));
cpi->recon = _ogg_malloc(cpi->frame_size*sizeof(*cpi->recon));
- cpi->OptimisedTokenListEb =
- _ogg_malloc(cpi->frame_size*
- sizeof(*cpi->OptimisedTokenListEb));
- cpi->OptimisedTokenList =
- _ogg_malloc(cpi->frame_size*
- sizeof(*cpi->OptimisedTokenList));
- cpi->OptimisedTokenListHi =
- _ogg_malloc(cpi->frame_size*
- sizeof(*cpi->OptimisedTokenListHi));
- cpi->OptimisedTokenListPl =
- _ogg_malloc(cpi->frame_size*
- sizeof(*cpi->OptimisedTokenListPl));
-
+ cpi->dct_token_storage = _ogg_malloc(cpi->frag_total*BLOCK_SIZE*sizeof(*cpi->dct_token_storage));
+ cpi->dct_token_eb_storage = _ogg_malloc(cpi->frag_total*BLOCK_SIZE*sizeof(*cpi->dct_token_eb_storage));
+
/* Re-initialise the pixel index table. */
{
ogg_uint32_t plane,row,col;
More information about the commits
mailing list