diff options
Diffstat (limited to 'vp8')
-rw-r--r-- | vp8/common/blockd.h | 10 | ||||
-rw-r--r-- | vp8/common/entropy.h | 5 | ||||
-rw-r--r-- | vp8/common/entropymode.c | 129 | ||||
-rw-r--r-- | vp8/common/idctllm.c | 73 | ||||
-rw-r--r-- | vp8/common/loopfilter.c | 8 | ||||
-rw-r--r-- | vp8/common/postproc.c | 9 | ||||
-rw-r--r-- | vp8/common/pred_common.c | 6 | ||||
-rw-r--r-- | vp8/common/reconintra.c | 350 | ||||
-rw-r--r-- | vp8/common/reconintra.h | 16 | ||||
-rw-r--r-- | vp8/common/x86/x86_systemdependent.c | 6 | ||||
-rw-r--r-- | vp8/decoder/decodframe.c | 62 | ||||
-rw-r--r-- | vp8/encoder/bitstream.c | 175 | ||||
-rw-r--r-- | vp8/encoder/block.h | 2 | ||||
-rw-r--r-- | vp8/encoder/dct.c | 302 | ||||
-rw-r--r-- | vp8/encoder/encodeframe.c | 75 | ||||
-rw-r--r-- | vp8/encoder/encodemb.c | 14 | ||||
-rw-r--r-- | vp8/encoder/mbgraph.c | 1 | ||||
-rw-r--r-- | vp8/encoder/onyx_if.c | 129 | ||||
-rw-r--r-- | vp8/encoder/onyx_int.h | 63 | ||||
-rw-r--r-- | vp8/encoder/ratectrl.c | 12 | ||||
-rw-r--r-- | vp8/encoder/rdopt.c | 182 |
21 files changed, 1290 insertions, 339 deletions
diff --git a/vp8/common/blockd.h b/vp8/common/blockd.h index 791571412..19511f31d 100644 --- a/vp8/common/blockd.h +++ b/vp8/common/blockd.h @@ -86,8 +86,16 @@ typedef enum DC_PRED, /* average of above and left pixels */ V_PRED, /* vertical prediction */ H_PRED, /* horizontal prediction */ +#if CONFIG_NEWINTRAMODES + D45_PRED, /* Directional 45 deg prediction [anti-clockwise from 0 deg hor] */ + D135_PRED, /* Directional 135 deg prediction [anti-clockwise from 0 deg hor] */ + D117_PRED, /* Directional 112 deg prediction [anti-clockwise from 0 deg hor] */ + D153_PRED, /* Directional 157 deg prediction [anti-clockwise from 0 deg hor] */ + D27_PRED, /* Directional 22 deg prediction [anti-clockwise from 0 deg hor] */ + D63_PRED, /* Directional 67 deg prediction [anti-clockwise from 0 deg hor] */ +#endif TM_PRED, /* Truemotion prediction */ - I8X8_PRED, /* 8x8 based prediction, each 8x8 has its own prediction mode */ + I8X8_PRED, /* 8x8 based prediction, each 8x8 has its own prediction mode */ B_PRED, /* block based prediction, each block has its own prediction mode */ NEARESTMV, diff --git a/vp8/common/entropy.h b/vp8/common/entropy.h index 42de3ea52..4c42d455d 100644 --- a/vp8/common/entropy.h +++ b/vp8/common/entropy.h @@ -91,8 +91,9 @@ extern DECLARE_ALIGNED(64, const unsigned char, vp8_coef_bands_8x8[64]); #endif #if CONFIG_NEWUPDATE -#define SUBEXP_PARAM 1 /* Subexponential code parameter */ -#define COEFUPDATETYPE 2 /* coef update type to use (1/2/3) */ +#define SUBEXP_PARAM 2 /* Subexponential code parameter */ +#define MODULUS_PARAM 21 /* Modulus parameter */ +#define COEFUPDATETYPE 2 /* coef update type to use (1/2/3) */ #endif diff --git a/vp8/common/entropymode.c b/vp8/common/entropymode.c index aa8d03717..0ae6a9343 100644 --- a/vp8/common/entropymode.c +++ b/vp8/common/entropymode.c @@ -17,6 +17,16 @@ const unsigned int kf_y_mode_cts[8][VP8_YMODES] = { +#if CONFIG_NEWINTRAMODES + {12, 6, 5, 5, 5, 5, 5, 5, 5, 2, 22, 200}, + {25, 13, 13, 7, 7, 7, 7, 7, 7, 6, 27, 160}, + {31, 17, 18, 8, 8, 8, 8, 8, 8, 9, 26, 139}, + {40, 22, 23, 8, 8, 8, 8, 8, 8, 12, 27, 116}, + {53, 26, 28, 8, 8, 8, 8, 8, 8, 13, 26, 94}, + {68, 33, 35, 8, 8, 8, 8, 8, 8, 17, 20, 68}, + {78, 38, 38, 8, 8, 8, 8, 8, 8, 19, 16, 52}, + {89, 42, 42, 8, 8, 8, 8, 8, 8, 21, 12, 34}, +#else {17, 6, 5, 2, 22, 203}, {27, 13, 13, 6, 27, 170}, {35, 17, 18, 9, 26, 152}, @@ -25,29 +35,69 @@ const unsigned int kf_y_mode_cts[8][VP8_YMODES] = {73, 33, 36, 17, 20, 78}, {88, 38, 39, 19, 16, 57}, {99, 42, 43, 21, 12, 39}, +#endif }; -static const unsigned int y_mode_cts [VP8_YMODES] = { - 106, 25, 21, 13, 16, 74}; +static const unsigned int y_mode_cts [VP8_YMODES] = +#if CONFIG_NEWINTRAMODES + {98, 19, 15, 14, 14, 14, 14, 12, 12, 13, 16, 70}; +#else + {106, 25, 21, 13, 16, 74}; +#endif static const unsigned int uv_mode_cts [VP8_YMODES] [VP8_UV_MODES] ={ +#if CONFIG_NEWINTRAMODES + { 200, 15, 15, 10, 10, 10, 10, 10, 10, 6}, + { 130, 75, 10, 10, 10, 10, 10, 10, 10, 6}, + { 130, 10, 75, 10, 10, 10, 10, 10, 10, 6}, + { 130, 15, 10, 75, 10, 10, 10, 10, 10, 6}, + { 150, 15, 10, 10, 75, 10, 10, 10, 10, 6}, + { 150, 15, 10, 10, 10, 75, 10, 10, 10, 6}, + { 150, 15, 10, 10, 10, 10, 75, 10, 10, 6}, + { 150, 15, 10, 10, 10, 10, 10, 75, 10, 6}, + { 150, 15, 10, 10, 10, 10, 10, 10, 75, 6}, + { 160, 30, 30, 10, 10, 10, 10, 10, 10, 16}, + { 132, 46, 40, 10, 10, 10, 10, 10, 10, 18}, /* never used */ + { 150, 35, 41, 10, 10, 10, 10, 10, 10, 10}, +#else { 210, 20, 20, 6}, { 180, 60, 10, 6}, { 150, 20, 80, 6}, { 170, 35, 35, 16}, { 142, 51, 45, 18}, /* never used */ { 160, 40, 46, 10}, +#endif }; -static const unsigned int i8x8_mode_cts [VP8_UV_MODES] = {93, 69, 81, 13}; +static const unsigned int i8x8_mode_cts [VP8_I8X8_MODES] = +#if CONFIG_NEWINTRAMODES + {73, 49, 61, 30, 30, 30, 30, 30, 30, 13}; +#else + {93, 69, 81, 13}; +#endif static const unsigned int kf_uv_mode_cts [VP8_YMODES] [VP8_UV_MODES] ={ +#if CONFIG_NEWINTRAMODES + { 160, 24, 24, 20, 20, 20, 20, 20, 20, 8}, + { 102, 64, 30, 20, 20, 20, 20, 20, 20, 10}, + { 102, 30, 64, 20, 20, 20, 20, 20, 20, 10}, + { 102, 33, 20, 64, 20, 20, 20, 20, 20, 14}, + { 102, 33, 20, 20, 64, 20, 20, 20, 20, 14}, + { 122, 33, 20, 20, 20, 64, 20, 20, 20, 14}, + { 102, 33, 20, 20, 20, 20, 64, 20, 20, 14}, + { 102, 33, 20, 20, 20, 20, 20, 64, 20, 14}, + { 102, 33, 20, 20, 20, 20, 20, 20, 64, 14}, + { 132, 36, 30, 20, 20, 20, 20, 20, 20, 18}, + { 122, 41, 35, 20, 20, 20, 20, 20, 20, 18}, /* never used */ + { 122, 41, 35, 20, 20, 20, 20, 20, 20, 18}, +#else { 180, 34, 34, 8}, { 132, 74, 40, 10}, { 132, 40, 74, 10}, { 152, 46, 40, 18}, { 142, 51, 45, 18}, /* never used */ { 142, 51, 45, 18}, +#endif }; static const unsigned int bmode_cts[VP8_BINTRAMODES] = @@ -133,7 +183,7 @@ const vp8_prob vp8_mbsplit_probs [VP8_NUMMBSPLITS-1] = { 110, 111, 150}; /* Array indices are identical to previously-existing INTRAMODECONTEXTNODES. */ -const vp8_tree_index vp8_bmode_tree[18] = /* INTRAMODECONTEXTNODE value */ +const vp8_tree_index vp8_bmode_tree[VP8_BINTRAMODES*2-2] = /* INTRAMODECONTEXTNODE value */ { -B_DC_PRED, 2, /* 0 = DC_NODE */ -B_TM_PRED, 4, /* 1 = TM_NODE */ @@ -146,6 +196,67 @@ const vp8_tree_index vp8_bmode_tree[18] = /* INTRAMODECONTEXTNODE value */ -B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */ }; +#if CONFIG_NEWINTRAMODES +/* Again, these trees use the same probability indices as their + explicitly-programmed predecessors. */ +const vp8_tree_index vp8_ymode_tree[VP8_YMODES*2-2] = +{ + 2, 14, + -DC_PRED, 4, + 6, 8, + -D45_PRED, -D135_PRED, + 10, 12, + -D117_PRED, -D153_PRED, + -D27_PRED, -D63_PRED, + 16, 18, + -V_PRED, -H_PRED, + -TM_PRED, 20, + -B_PRED, -I8X8_PRED +}; + +const vp8_tree_index vp8_kf_ymode_tree[VP8_YMODES*2-2] = +{ + 2, 14, + -DC_PRED, 4, + 6, 8, + -D45_PRED, -D135_PRED, + 10, 12, + -D117_PRED, -D153_PRED, + -D27_PRED, -D63_PRED, + 16, 18, + -V_PRED, -H_PRED, + -TM_PRED, 20, + -B_PRED, -I8X8_PRED +}; + +const vp8_tree_index vp8_i8x8_mode_tree[VP8_I8X8_MODES*2-2] = +{ + 2, 14, + -DC_PRED, 4, + 6, 8, + -D45_PRED, -D135_PRED, + 10, 12, + -D117_PRED, -D153_PRED, + -D27_PRED, -D63_PRED, + -V_PRED, 16, + -H_PRED, -TM_PRED +}; + +const vp8_tree_index vp8_uv_mode_tree[VP8_UV_MODES*2-2] = +{ + 2, 14, + -DC_PRED, 4, + 6, 8, + -D45_PRED, -D135_PRED, + 10, 12, + -D117_PRED, -D153_PRED, + -D27_PRED, -D63_PRED, + -V_PRED, 16, + -H_PRED, -TM_PRED +}; + +#else /* CONFIG_NEWINTRAMODES */ + /* Again, these trees use the same probability indices as their explicitly-programmed predecessors. */ const vp8_tree_index vp8_ymode_tree[10] = @@ -179,6 +290,8 @@ const vp8_tree_index vp8_uv_mode_tree[6] = -H_PRED, -TM_PRED }; +#endif /* CONFIG_NEWINTRAMODES */ + const vp8_tree_index vp8_mbsplit_tree[6] = { -3, 2, @@ -282,10 +395,10 @@ void vp8_init_mbmode_probs(VP8_COMMON *x) } vp8_tree_probs_from_distribution( - VP8_UV_MODES, vp8_i8x8_mode_encodings, vp8_i8x8_mode_tree, + VP8_I8X8_MODES, vp8_i8x8_mode_encodings, vp8_i8x8_mode_tree, x->i8x8_mode_prob, bct, i8x8_mode_cts, - 256, 1 - ); + 256, 1); + vpx_memcpy(x->fc.sub_mv_ref_prob, sub_mv_ref_prob, sizeof(sub_mv_ref_prob)); } @@ -448,7 +561,7 @@ void vp8_update_mode_context(VP8_COMMON *pc) void print_mode_contexts(VP8_COMMON *pc) { int j, i; - printf("====================\n"); + printf("\n====================\n"); for(j=0; j<6; j++) { for (i = 0; i < 4; i++) diff --git a/vp8/common/idctllm.c b/vp8/common/idctllm.c index f0536d5e4..b2523ba7c 100644 --- a/vp8/common/idctllm.c +++ b/vp8/common/idctllm.c @@ -138,65 +138,60 @@ void vp8_short_inv_walsh4x4_c(short *input, short *output) { int i; int a1, b1, c1, d1; - int a2, b2, c2, d2; short *ip = input; short *op = output; for (i = 0; i < 4; i++) { - a1 = ip[0] + ip[12]; - b1 = ip[4] + ip[8]; - c1 = ip[4] - ip[8]; - d1 = ip[0] - ip[12]; + a1 = ((ip[0] + ip[3])); + b1 = ((ip[1] + ip[2])); + c1 = ((ip[1] - ip[2])); + d1 = ((ip[0] - ip[3])); - op[0] = a1 + b1; - op[4] = c1 + d1; - op[8] = a1 - b1; - op[12] = d1 - c1; - ip++; - op++; + op[0] = (a1 + b1 + 1)>>1; + op[1] = (c1 + d1)>>1; + op[2] = (a1 - b1)>>1; + op[3] = (d1 - c1)>>1; + + ip += 4; + op += 4; } ip = output; op = output; - for (i = 0; i < 4; i++) { - a1 = ip[0] + ip[3]; - b1 = ip[1] + ip[2]; - c1 = ip[1] - ip[2]; - d1 = ip[0] - ip[3]; - - a2 = a1 + b1; - b2 = c1 + d1; - c2 = a1 - b1; - d2 = d1 - c1; - - op[0] = (a2 + 1) >> 2; - op[1] = (b2 + 1) >> 2; - op[2] = (c2 + 1) >> 2; - op[3] = (d2 + 1) >> 2; - - ip += 4; - op += 4; + a1 = ip[0] + ip[12]; + b1 = ip[4] + ip[8]; + c1 = ip[4] - ip[8]; + d1 = ip[0] - ip[12]; + op[0] = (a1 + b1 + 1)>>1; + op[4] = (c1 + d1)>>1; + op[8] = (a1 - b1)>>1; + op[12]= (d1 - c1)>>1; + ip++; + op++; } } -void vp8_short_inv_walsh4x4_1_c(short *input, short *output) +void vp8_short_inv_walsh4x4_1_c(short *in, short *out) { int i; - int a1; - short *op = output; + short tmp[4]; + short *ip = in; + short *op = tmp; - a1 = (input[0] + 1 )>> 2; + op[0] =(ip[0]+ 1)>>1; + op[1] = op[2] = op[3] = (ip[0]>>1); - for (i = 0; i < 4; i++) + ip = tmp; + op = out; + for(i = 0; i<4; i++) { - op[0] = a1; - op[1] = a1; - op[2] = a1; - op[3] = a1; - op += 4; + op[0] =(ip[0]+ 1)>>1; + op[4] = op[8] = op[12] = (ip[0]>>1); + ip ++; + op ++; } } diff --git a/vp8/common/loopfilter.c b/vp8/common/loopfilter.c index 1cac063e0..6f57d49b4 100644 --- a/vp8/common/loopfilter.c +++ b/vp8/common/loopfilter.c @@ -149,6 +149,14 @@ static void lf_init_lut(loop_filter_info_n *lfi) } lfi->mode_lf_lut[DC_PRED] = 1; +#if CONFIG_NEWINTRAMODES + lfi->mode_lf_lut[D45_PRED] = 1; + lfi->mode_lf_lut[D135_PRED] = 1; + lfi->mode_lf_lut[D117_PRED] = 1; + lfi->mode_lf_lut[D153_PRED] = 1; + lfi->mode_lf_lut[D27_PRED] = 1; + lfi->mode_lf_lut[D63_PRED] = 1; +#endif lfi->mode_lf_lut[V_PRED] = 1; lfi->mode_lf_lut[H_PRED] = 1; lfi->mode_lf_lut[TM_PRED] = 1; diff --git a/vp8/common/postproc.c b/vp8/common/postproc.c index d88b419bc..7e7ed3cb7 100644 --- a/vp8/common/postproc.c +++ b/vp8/common/postproc.c @@ -32,6 +32,14 @@ static const unsigned char MB_PREDICTION_MODE_colors[MB_MODE_COUNT][3] = { RGB_TO_YUV(0x98FB98) }, /* PaleGreen */ { RGB_TO_YUV(0x00FF00) }, /* Green */ { RGB_TO_YUV(0xADFF2F) }, /* GreenYellow */ +#if CONFIG_NEWINTRAMODES + { RGB_TO_YUV(0x8F0000) }, /* Dark Red */ + { RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */ + { RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */ + { RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */ + { RGB_TO_YUV(0x8F0000) }, /* Dark Red */ + { RGB_TO_YUV(0x8F0000) }, /* Dark Red */ +#endif { RGB_TO_YUV(0x228B22) }, /* ForestGreen */ { RGB_TO_YUV(0x006400) }, /* DarkGreen */ { RGB_TO_YUV(0x98F5FF) }, /* Cadet Blue */ @@ -39,6 +47,7 @@ static const unsigned char MB_PREDICTION_MODE_colors[MB_MODE_COUNT][3] = { RGB_TO_YUV(0x00008B) }, /* Dark blue */ { RGB_TO_YUV(0x551A8B) }, /* Purple */ { RGB_TO_YUV(0xFF0000) } /* Red */ + { RGB_TO_YUV(0xCC33FF) }, /* Magenta */ }; static const unsigned char B_PREDICTION_MODE_colors[B_MODE_COUNT][3] = diff --git a/vp8/common/pred_common.c b/vp8/common/pred_common.c index 0e01e6c8a..f7222a7ec 100644 --- a/vp8/common/pred_common.c +++ b/vp8/common/pred_common.c @@ -277,7 +277,7 @@ void calc_ref_probs( int * count, vp8_prob * probs ) tot_count = count[0] + count[1] + count[2] + count[3]; if ( tot_count ) { - probs[0] = (vp8_prob)((count[0] * 255) / tot_count); + probs[0] = (vp8_prob)((count[0] * 255 + (tot_count >> 1)) / tot_count); probs[0] += !probs[0]; } else @@ -286,7 +286,7 @@ void calc_ref_probs( int * count, vp8_prob * probs ) tot_count -= count[0]; if ( tot_count ) { - probs[1] = (vp8_prob)((count[1] * 255) / tot_count); + probs[1] = (vp8_prob)((count[1] * 255 + (tot_count >> 1)) / tot_count); probs[1] += !probs[1]; } else @@ -295,7 +295,7 @@ void calc_ref_probs( int * count, vp8_prob * probs ) tot_count -= count[1]; if ( tot_count ) { - probs[2] = (vp8_prob)((count[2] * 255) / tot_count); + probs[2] = (vp8_prob)((count[2] * 255 + (tot_count >> 1)) / tot_count); probs[2] += !probs[2]; } else diff --git a/vp8/common/reconintra.c b/vp8/common/reconintra.c index 501eacab2..27b47926e 100644 --- a/vp8/common/reconintra.c +++ b/vp8/common/reconintra.c @@ -8,7 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ - +#include <stdio.h> #include "vpx_ports/config.h" #include "recon.h" #include "reconintra.h" @@ -17,6 +17,217 @@ /* For skip_recon_mb(), add vp8_build_intra_predictors_mby_s(MACROBLOCKD *x) and * vp8_build_intra_predictors_mbuv_s(MACROBLOCKD *x). */ + +#if CONFIG_NEWINTRAMODES +void d27_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col) +{ + int r, c, h, w, v; + int a, b; + r = 0; + for (c = 0; c < n-2; c++) + { + if (c&1) + a = yleft_col[r + 1]; + else + a = (yleft_col[r] + yleft_col[r + 1] + 1) >> 1; + b = yabove_row[c + 2]; + ypred_ptr[c] = (2 * a + (c + 1) * b + (c + 3)/2) / (c + 3); + } + for (r = 1; r < n/2 - 1; r++) + { + for (c = 0; c < n - 2 - 2 * r; c++) + { + if (c&1) + a = yleft_col[r + 1]; + else + a = (yleft_col[r] + yleft_col[r + 1] + 1) >> 1; + b = ypred_ptr[(r - 1) * y_stride + c + 2]; + ypred_ptr[r * y_stride + c] = (2 * a + (c + 1) * b + (c + 3)/2) / (c + 3); + } + } + for (; r < n - 1; ++r) + { + for (c = 0; c < n; c++) + { + v = (c & 1 ? yleft_col[r + 1] : (yleft_col[r] + yleft_col[r + 1] + 1) >> 1); + h = r - c/2; + ypred_ptr[h * y_stride + c] = v; + } + } + c = 0; + r = n - 1; + ypred_ptr[r * y_stride] = (ypred_ptr[(r - 1) * y_stride] + + yleft_col[r] + 1) >> 1; + for (r = n - 2; r >= n/2; --r) + { + w = c + (n - 1 - r) * 2; + ypred_ptr[r * y_stride + w] = (ypred_ptr[(r - 1) * y_stride + w] + + ypred_ptr[r * y_stride + w - 1] + 1) >> 1; + } + for (c = 1; c < n; c++) + { + for (r = n - 1; r >= n/2 + c/2; --r) + { + w = c + (n - 1 - r) * 2; + ypred_ptr[r * y_stride + w] = (ypred_ptr[(r - 1) * y_stride + w] + + ypred_ptr[r * y_stride + w - 1] + 1) >> 1; + } + } +} + +void d63_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col) +{ + int r, c, h, w, v; + int a, b; + c = 0; + for (r = 0; r < n-2; r++) + { + if (r&1) + a = yabove_row[c + 1]; + else + a = (yabove_row[c] + yabove_row[c + 1] + 1) >> 1; + b = yleft_col[r + 2]; + ypred_ptr[r * y_stride] = (2 * a + (r + 1) * b + (r + 3)/2) / (r + 3); + } + for (c = 1; c < n/2 - 1; c++) + { + for (r = 0; r < n - 2 - 2 * c; r++) + { + if (r&1) + a = yabove_row[c + 1]; + else + a = (yabove_row[c] + yabove_row[c + 1] + 1) >> 1; + b = ypred_ptr[(r + 2) * y_stride + c - 1]; + ypred_ptr[r * y_stride + c] = (2 * a + (c + 1) * b + (c + 3)/2) / (c + 3); + } + } + for (; c < n - 1; ++c) + { + for (r = 0; r < n; r++) + { + v = (r & 1 ? yabove_row[c + 1] : (yabove_row[c] + yabove_row[c + 1] + 1) >> 1); + w = c - r/2; + ypred_ptr[r * y_stride + w] = v; + } + } + r = 0; + c = n - 1; + ypred_ptr[c] = (ypred_ptr[(c - 1)] + yabove_row[c] + 1) >> 1; + for (c = n - 2; c >= n/2; --c) + { + h = r + (n - 1 - c) * 2; + ypred_ptr[h * y_stride + c] = (ypred_ptr[h * y_stride + c - 1] + + ypred_ptr[(h - 1) * y_stride + c] + 1) >> 1; + } + for (r = 1; r < n; r++) + { + for (c = n - 1; c >= n/2 + r/2; --c) + { + h = r + (n - 1 - c) * 2; + ypred_ptr[h * y_stride + c] = (ypred_ptr[h * y_stride + c - 1] + + ypred_ptr[(h - 1) * y_stride + c] + 1) >> 1; + } + } +} + +void d45_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col) +{ + int r, c; + for (r = 0; r < n - 1; ++r) + { + for (c = 0; c <= r; ++c) + { + ypred_ptr[(r - c) * y_stride + c] = + (yabove_row[r+1] * (c + 1) + + yleft_col[r+1] * (r - c + 1) + r/2 + 1) / (r + 2); + } + } + for (c = 0; c <= r; ++c) + { + int yabove_ext = yabove_row[r]; //2*yabove_row[r] - yabove_row[r-1]; + int yleft_ext = yleft_col[r]; //2*yleft_col[r] - yleft_col[r-1]; + yabove_ext = (yabove_ext > 255 ? 255 : (yabove_ext < 0 ? 0 : yabove_ext)); + yleft_ext = (yleft_ext > 255 ? 255 : (yleft_ext < 0 ? 0 : yleft_ext)); + ypred_ptr[(r - c) * y_stride + c] = + (yabove_ext * (c + 1) + + yleft_ext * (r - c + 1) + r/2 + 1) / (r + 2); + } + for (r = 1; r < n; ++r) + { + for (c = n - r; c < n; ++c) + ypred_ptr[r * y_stride + c] = (ypred_ptr[(r - 1) * y_stride + c] + + ypred_ptr[r * y_stride + c - 1] + 1) >> 1; + } +} + +void d117_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col) +{ + int r, c; + for (c = 0; c < n; c++) + ypred_ptr[c] = (yabove_row[c-1] + yabove_row[c] + 1) >> 1; + ypred_ptr += y_stride; + for (c = 0; c < n; c++) + ypred_ptr[c] = yabove_row[c-1]; + ypred_ptr += y_stride; + for (r = 2; r < n; ++r) + { + ypred_ptr[0] = yleft_col[r - 2]; + for (c = 1; c < n; c++) + ypred_ptr[c] = ypred_ptr[-2*y_stride+c-1]; + ypred_ptr += y_stride; + } +} + +void d135_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col) +{ + int r, c; + ypred_ptr[0] = yabove_row[-1]; + for (c = 1; c < n; c++) + ypred_ptr[c] = yabove_row[c - 1]; + for (r = 1; r < n; ++r) + ypred_ptr[r * y_stride] = yleft_col[r - 1]; + + ypred_ptr += y_stride; + for (r = 1; r < n; ++r) + { + for (c = 1; c < n; c++) + { + ypred_ptr[c] = ypred_ptr[-y_stride + c - 1]; + } + ypred_ptr += y_stride; + } +} + +void d153_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col) +{ + int r, c; + ypred_ptr[0] = (yabove_row[-1] + yleft_col[0] + 1) >> 1; + for (r = 1; r < n; r++) + ypred_ptr[r * y_stride] = (yleft_col[r-1] + yleft_col[r] + 1) >> 1; + ypred_ptr++; + ypred_ptr[0] = yabove_row[-1]; + for (r = 1; r < n; r++) + ypred_ptr[r * y_stride] = yleft_col[r-1]; + ypred_ptr++; + + for (c = 0; c < n - 2; c++) + ypred_ptr[c] = yabove_row[c]; + ypred_ptr += y_stride; + for (r = 1; r < n; ++r) + { + for (c = 0; c < n - 2; c++) + ypred_ptr[c] = ypred_ptr[-y_stride+c-2]; + ypred_ptr += y_stride; + } +} +#endif /* CONFIG_NEWINTRAMODES */ + void vp8_recon_intra_mbuv(const vp8_recon_rtcd_vtable_t *rtcd, MACROBLOCKD *x) { int i; @@ -64,7 +275,6 @@ void vp8_build_intra_predictors_mby_internal(MACROBLOCKD *x, unsigned char *ypre if (x->left_available) { - for (i = 0; i < 16; i++) { average += yleft_col[i]; @@ -134,6 +344,38 @@ void vp8_build_intra_predictors_mby_internal(MACROBLOCKD *x, unsigned char *ypre } break; +#if CONFIG_NEWINTRAMODES + case D45_PRED: + { + d45_predictor(ypred_ptr, y_stride, 16, yabove_row, yleft_col); + } + break; + case D135_PRED: + { + d135_predictor(ypred_ptr, y_stride, 16, yabove_row, yleft_col); + } + break; + case D117_PRED: + { + d117_predictor(ypred_ptr, y_stride, 16, yabove_row, yleft_col); + } + break; + case D153_PRED: + { + d153_predictor(ypred_ptr, y_stride, 16, yabove_row, yleft_col); + } + break; + case D27_PRED: + { + d27_predictor(ypred_ptr, y_stride, 16, yabove_row, yleft_col); + } + break; + case D63_PRED: + { + d63_predictor(ypred_ptr, y_stride, 16, yabove_row, yleft_col); + } + break; +#endif #if CONIFG_I8X8 case I8X8_PRED: #endif @@ -313,6 +555,44 @@ void vp8_build_intra_predictors_mbuv_internal(MACROBLOCKD *x, } break; +#if CONFIG_NEWINTRAMODES + case D45_PRED: + { + d45_predictor(upred_ptr, uv_stride, 8, uabove_row, uleft_col); + d45_predictor(vpred_ptr, uv_stride, 8, vabove_row, vleft_col); + } + break; + case D135_PRED: + { + d135_predictor(upred_ptr, uv_stride, 8, uabove_row, uleft_col); + d135_predictor(vpred_ptr, uv_stride, 8, vabove_row, vleft_col); + } + break; + case D117_PRED: + { + d117_predictor(upred_ptr, uv_stride, 8, uabove_row, uleft_col); + d117_predictor(vpred_ptr, uv_stride, 8, vabove_row, vleft_col); + } + break; + case D153_PRED: + { + d153_predictor(upred_ptr, uv_stride, 8, uabove_row, uleft_col); + d153_predictor(vpred_ptr, uv_stride, 8, vabove_row, vleft_col); + } + break; + case D27_PRED: + { + d27_predictor(upred_ptr, uv_stride, 8, uabove_row, uleft_col); + d27_predictor(vpred_ptr, uv_stride, 8, vabove_row, vleft_col); + } + break; + case D63_PRED: + { + d63_predictor(upred_ptr, uv_stride, 8, uabove_row, uleft_col); + d63_predictor(vpred_ptr, uv_stride, 8, vabove_row, vleft_col); + } + break; +#endif case B_PRED: case NEARESTMV: case NEARMV: @@ -403,7 +683,6 @@ void vp8_intra8x8_predict(BLOCKD *x, { for (c = 0; c < 8; c++) { - predictor[c] = yabove_row[c]; } predictor += 16; @@ -444,6 +723,38 @@ void vp8_intra8x8_predict(BLOCKD *x, } } break; +#if CONFIG_NEWINTRAMODES + case D45_PRED: + { + d45_predictor(predictor, 16, 8, yabove_row, yleft_col); + } + break; + case D135_PRED: + { + d135_predictor(predictor, 16, 8, yabove_row, yleft_col); + } + break; + case D117_PRED: + { + d117_predictor(predictor, 16, 8, yabove_row, yleft_col); + } + break; + case D153_PRED: + { + d153_predictor(predictor, 16, 8, yabove_row, yleft_col); + } + break; + case D27_PRED: + { + d27_predictor(predictor, 16, 8, yabove_row, yleft_col); + } + break; + case D63_PRED: + { + d63_predictor(predictor, 16, 8, yabove_row, yleft_col); + } + break; +#endif } } @@ -452,7 +763,6 @@ void vp8_comp_intra8x8_predict(BLOCKD *x, int mode, int second_mode, unsigned char *out_predictor) { - unsigned char predictor[2][8*16]; int i, j; @@ -553,6 +863,38 @@ void vp8_intra_uv4x4_predict(BLOCKD *x, } } break; +#if CONFIG_NEWINTRAMODES + case D45_PRED: + { + d45_predictor(predictor, 8, 4, above_row, left_col); + } + break; + case D135_PRED: + { + d135_predictor(predictor, 8, 4, above_row, left_col); + } + break; + case D117_PRED: + { + d117_predictor(predictor, 8, 4, above_row, left_col); + } + break; + case D153_PRED: + { + d153_predictor(predictor, 8, 4, above_row, left_col); + } + break; + case D27_PRED: + { + d27_predictor(predictor, 8, 4, above_row, left_col); + } + break; + case D63_PRED: + { + d63_predictor(predictor, 8, 4, above_row, left_col); + } + break; +#endif } } diff --git a/vp8/common/reconintra.h b/vp8/common/reconintra.h index 47e479285..03b50f2c1 100644 --- a/vp8/common/reconintra.h +++ b/vp8/common/reconintra.h @@ -12,6 +12,22 @@ #ifndef __INC_RECONINTRA_H #define __INC_RECONINTRA_H +#include "blockd.h" +#if CONFIG_NEWINTRAMODES +void d45_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col); +void d135_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col); +void d116_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col); +void d153_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col); +void d27_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col); +void d64_predictor(unsigned char *ypred_ptr, int y_stride, int n, + unsigned char *yabove_row, unsigned char *yleft_col); +#endif /* CONFIG_NEWINTRAMODES */ + extern void init_intra_left_above_pixels(MACROBLOCKD *x); #endif diff --git a/vp8/common/x86/x86_systemdependent.c b/vp8/common/x86/x86_systemdependent.c index 53009502c..b88eb3dc8 100644 --- a/vp8/common/x86/x86_systemdependent.c +++ b/vp8/common/x86/x86_systemdependent.c @@ -84,10 +84,12 @@ void vp8_arch_x86_common_init(VP8_COMMON *ctx) rtcd->recon.recon2 = vp8_recon2b_sse2; rtcd->recon.recon4 = vp8_recon4b_sse2; rtcd->recon.copy16x16 = vp8_copy_mem16x16_sse2; +#if CONFIG_NEWINTRAMODES == 0 rtcd->recon.build_intra_predictors_mbuv = vp8_build_intra_predictors_mbuv_sse2; rtcd->recon.build_intra_predictors_mbuv_s = vp8_build_intra_predictors_mbuv_s_sse2; +#endif rtcd->idct.iwalsh16 = vp8_short_inv_walsh4x4_sse2; @@ -122,7 +124,7 @@ void vp8_arch_x86_common_init(VP8_COMMON *ctx) if (flags & HAS_SSSE3) { -#if CONFIG_ENHANCED_INTERP == 0 && CONFIG_HIGH_PRECISION_MV == 0 +#if CONFIG_ENHANCED_INTERP == 0 && CONFIG_HIGH_PRECISION_MV == 0 && CONFIG_SIXTEENTH_SUBPEL_UV == 0 rtcd->subpix.sixtap16x16 = vp8_sixtap_predict16x16_ssse3; rtcd->subpix.sixtap8x8 = vp8_sixtap_predict8x8_ssse3; rtcd->subpix.sixtap8x4 = vp8_sixtap_predict8x4_ssse3; @@ -131,10 +133,12 @@ void vp8_arch_x86_common_init(VP8_COMMON *ctx) rtcd->subpix.bilinear8x8 = vp8_bilinear_predict8x8_ssse3; #endif +#if CONFIG_NEWINTRAMODES == 0 rtcd->recon.build_intra_predictors_mbuv = vp8_build_intra_predictors_mbuv_ssse3; rtcd->recon.build_intra_predictors_mbuv_s = vp8_build_intra_predictors_mbuv_s_ssse3; +#endif } #endif diff --git a/vp8/decoder/decodframe.c b/vp8/decoder/decodframe.c index 877653290..d375cdd52 100644 --- a/vp8/decoder/decodframe.c +++ b/vp8/decoder/decodframe.c @@ -45,13 +45,29 @@ int dec_debug = 0; #endif #if CONFIG_NEWUPDATE + +static int merge_index(int v, int n, int modulus) +{ + int max1 = (n-1 - modulus/2)/modulus + 1; + if (v < max1) v = v * modulus + modulus/2; + else + { + int w; + v -= max1; + w = v; + v += (v + modulus-modulus/2)/modulus; + while (v%modulus == modulus/2 || + w != v - (v + modulus-modulus/2)/modulus) v++; + } + return v; +} + static int inv_remap_prob(int v, int m) { const int n = 256; - int i; - //if (v <= n - 2 - s) v += s; else v = n - 2 - v; - //v = ((v&240)>>4) | ((v&15)<<4); - v = (v%15)*17 + (v/15); + const int modulus = MODULUS_PARAM; + int i, w; + v = merge_index(v, n-1, modulus); if ((m<<1)<=n) { i = inv_recenter_nonneg(v+1, m); } else { @@ -59,6 +75,12 @@ static int inv_remap_prob(int v, int m) } return i; } + +static vp8_prob read_prob_diff_update(vp8_reader *const bc, int oldp) +{ + int delp = vp8_decode_term_subexp(bc, SUBEXP_PARAM, 255); + return (vp8_prob)inv_remap_prob(delp, oldp); +} #endif void vp8cx_init_de_quantizer(VP8D_COMP *pbi) @@ -811,11 +833,7 @@ static void read_coef_probs3(VP8D_COMP *pbi) { vp8_prob *const p = pc->fc.coef_probs [i][j][k] + l; int u = vp8_read(bc, vp8_coef_update_probs [i][j][k][l]); - if (u) - { - int delp = vp8_decode_term_subexp(bc, SUBEXP_PARAM, 255); - *p = (vp8_prob)inv_remap_prob(delp, *p); - } + if (u) *p = read_prob_diff_update(bc, *p); } } } @@ -839,11 +857,7 @@ static void read_coef_probs3(VP8D_COMP *pbi) { vp8_prob *const p = pc->fc.coef_probs_8x8 [i][j][k] + l; int u = vp8_read(bc, vp8_coef_update_probs_8x8 [i][j][k][l]); - if (u) - { - int delp = vp8_decode_term_subexp(bc, SUBEXP_PARAM, 255); - *p = (vp8_prob)inv_remap_prob(delp, *p); - } + if (u) *p = read_prob_diff_update(bc, *p); } } } @@ -874,11 +888,7 @@ static void read_coef_probs2(VP8D_COMP *pbi) { vp8_prob *const p = pc->fc.coef_probs [i][j][k] + l; int u = vp8_read(bc, vp8_coef_update_probs [i][j][k][l]); - if (u) - { - int delp = vp8_decode_term_subexp(bc, SUBEXP_PARAM, 255); - *p = (vp8_prob)inv_remap_prob(delp, *p); - } + if (u) *p = read_prob_diff_update(bc, *p); } } } @@ -902,11 +912,7 @@ static void read_coef_probs2(VP8D_COMP *pbi) vp8_prob *const p = pc->fc.coef_probs_8x8 [i][j][k] + l; int u = vp8_read(bc, vp8_coef_update_probs_8x8 [i][j][k][l]); - if (u) - { - int delp = vp8_decode_term_subexp(bc, SUBEXP_PARAM, 255); - *p = (vp8_prob)inv_remap_prob(delp, *p); - } + if (u) *p = read_prob_diff_update(bc, *p); } } } @@ -945,10 +951,7 @@ static void read_coef_probs(VP8D_COMP *pbi) if (vp8_read(bc, vp8_coef_update_probs [i][j][k][l])) { #if CONFIG_NEWUPDATE - int delp = vp8_decode_term_subexp(bc, SUBEXP_PARAM, 255); - //printf("delp = %d/%d", *p, delp); - *p = (vp8_prob)inv_remap_prob(delp, *p); - //printf("/%d\n", *p); + *p = read_prob_diff_update(bc, *p); #else *p = (vp8_prob)vp8_read_literal(bc, 8); #endif @@ -982,8 +985,7 @@ static void read_coef_probs(VP8D_COMP *pbi) if (vp8_read(bc, vp8_coef_update_probs_8x8 [i][j][k][l])) { #if CONFIG_NEWUPDATE - int delp = vp8_decode_term_subexp(bc, SUBEXP_PARAM, 255); - *p = (vp8_prob)inv_remap_prob(delp, *p); + *p = read_prob_diff_update(bc, *p); #else *p = (vp8_prob)vp8_read_literal(bc, 8); #endif diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c index a96a75e06..6033f790e 100644 --- a/vp8/encoder/bitstream.c +++ b/vp8/encoder/bitstream.c @@ -34,15 +34,18 @@ unsigned __int64 Sectionbits[500]; #endif #ifdef ENTROPY_STATS -int intra_mode_stats[10][10][10]; +int intra_mode_stats[VP8_BINTRAMODES] + [VP8_BINTRAMODES] + [VP8_BINTRAMODES]; static unsigned int tree_update_hist [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] - [ENTROPY_NODES][2]={0}; + [ENTROPY_NODES] [2]={0}; static unsigned int tree_update_hist_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] [2]={0}; + extern unsigned int active_section; #endif @@ -64,19 +67,41 @@ static void compute_update_table() update_bits[i] = vp8_count_term_subexp(i, SUBEXP_PARAM, 255); } +static int split_index(int i, int n, int modulus) +{ + int max1 = (n-1 - modulus/2)/modulus + 1; + if (i%modulus == modulus/2) i = i/modulus; + else i = max1 + i - (i + modulus-modulus/2)/modulus; + return i; +} + static int remap_prob(int v, int m) { const int n = 256; + const int modulus = MODULUS_PARAM; + const int max1 = (n-2-modulus/2+modulus-1)/modulus; int i; if ((m<<1)<=n) i = recenter_nonneg(v, m) - 1; else i = recenter_nonneg(n-1-v, n-1-m) - 1; - //if (i >= s) i -= s; else i = n - 2 - i; - //i = ((i>>4)&15) | ((i((i>>4)&15) | ((i&15)<<4);&15)<<4); - i = (i%17)*15 + (i/17); + + i = split_index(i, n-1, modulus); return i; } + +static void write_prob_diff_update(vp8_writer *const w, + vp8_prob newp, vp8_prob oldp) +{ + int delp = remap_prob(newp, oldp); + vp8_encode_term_subexp(w, delp, SUBEXP_PARAM, 255); +} + +static int prob_diff_update_cost(vp8_prob newp, vp8_prob oldp) +{ + int delp = remap_prob(newp, oldp); + return update_bits[delp]*256; +} #endif static void update_mode( @@ -194,21 +219,11 @@ void update_skip_probs(VP8_COMP *cpi) static void update_refpred_stats( VP8_COMP *cpi ) { VP8_COMMON *const cm = & cpi->common; - MACROBLOCKD *const xd = & cpi->mb.e_mbd; - - int mb_row, mb_col; int i; int tot_count; - int ref_pred_count[PREDICTION_PROBS][2]; vp8_prob new_pred_probs[PREDICTION_PROBS]; - unsigned char pred_context; - unsigned char pred_flag; - int old_cost, new_cost; - // Clear the prediction hit counters - vpx_memset(ref_pred_count, 0, sizeof(ref_pred_count)); - // Set the prediction probability structures to defaults if ( cm->frame_type == KEY_FRAME ) { @@ -222,47 +237,17 @@ static void update_refpred_stats( VP8_COMP *cpi ) } else { - // For non-key frames....... - - // Scan through the macroblocks and collate prediction counts. - xd->mode_info_context = cm->mi; - for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) - { - for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) - { - // Get the prediction context and status - pred_flag = get_pred_flag( xd, PRED_REF ); - pred_context = get_pred_context( cm, xd, PRED_REF ); - - // Count prediction success - ref_pred_count[pred_context][pred_flag]++; - - // Step on to the next mb - xd->mode_info_context++; - } - - // this is to account for the border in mode_info_context - xd->mode_info_context++; - } - // From the prediction counts set the probabilities for each context for ( i = 0; i < PREDICTION_PROBS; i++ ) { - // MB reference frame not relevent to key frame encoding - if ( cm->frame_type != KEY_FRAME ) + tot_count = cpi->ref_pred_count[i][0] + cpi->ref_pred_count[i][1]; + if ( tot_count ) { - // Work out the probabilities for the reference frame predictor - tot_count = ref_pred_count[i][0] + ref_pred_count[i][1]; - if ( tot_count ) - { - new_pred_probs[i] = - ( ref_pred_count[i][0] * 255 ) / tot_count; + new_pred_probs[i] = + ( cpi->ref_pred_count[i][0] * 255 + (tot_count >> 1)) / tot_count; - // Clamp to minimum allowed value - new_pred_probs[i] += !new_pred_probs[i]; - } - else - new_pred_probs[i] = 128; + // Clamp to minimum allowed value + new_pred_probs[i] += !new_pred_probs[i]; } else new_pred_probs[i] = 128; @@ -270,12 +255,12 @@ static void update_refpred_stats( VP8_COMP *cpi ) // Decide whether or not to update the reference frame probs. // Returned costs are in 1/256 bit units. old_cost = - (ref_pred_count[i][0] * vp8_cost_zero(cm->ref_pred_probs[i])) + - (ref_pred_count[i][1] * vp8_cost_one(cm->ref_pred_probs[i])); + (cpi->ref_pred_count[i][0] * vp8_cost_zero(cm->ref_pred_probs[i])) + + (cpi->ref_pred_count[i][1] * vp8_cost_one(cm->ref_pred_probs[i])); new_cost = - (ref_pred_count[i][0] * vp8_cost_zero(new_pred_probs[i])) + - (ref_pred_count[i][1] * vp8_cost_one(new_pred_probs[i])); + (cpi->ref_pred_count[i][0] * vp8_cost_zero(new_pred_probs[i])) + + (cpi->ref_pred_count[i][1] * vp8_cost_one(new_pred_probs[i])); // Cost saving must be >= 8 bits (2048 in these units) if ( (old_cost - new_cost) >= 2048 ) @@ -329,22 +314,28 @@ static int prob_update_savings(const unsigned int *ct, { const int old_b = vp8_cost_branch256(ct, oldp); const int new_b = vp8_cost_branch256(ct, newp); -#if CONFIG_NEWUPDATE - const int delp = remap_prob(newp, oldp); - const int update_b = update_bits[delp]*256 + vp8_cost_upd256; -#else const int update_b = 2048 + vp8_cost_upd256; -#endif return (old_b - new_b - update_b); } #if CONFIG_NEWUPDATE -static int prob_update_savings_search(const unsigned int *ct, +static int prob_diff_update_savings(const unsigned int *ct, + const vp8_prob oldp, const vp8_prob newp, + const vp8_prob upd) +{ + const int old_b = vp8_cost_branch256(ct, oldp); + const int new_b = vp8_cost_branch256(ct, newp); + const int update_b = (newp == oldp ? 0 : + prob_diff_update_cost(newp, oldp) + vp8_cost_upd256); + return (old_b - new_b - update_b); +} + +static int prob_diff_update_savings_search(const unsigned int *ct, const vp8_prob oldp, vp8_prob *bestp, const vp8_prob upd) { const int old_b = vp8_cost_branch256(ct, oldp); - int new_b, delp, update_b, savings, bestsavings, step; + int new_b, update_b, savings, bestsavings, step; vp8_prob newp, bestnewp; bestsavings = 0; @@ -354,8 +345,7 @@ static int prob_update_savings_search(const unsigned int *ct, for (newp = *bestp; newp != oldp; newp+=step) { new_b = vp8_cost_branch256(ct, newp); - delp = remap_prob(newp, oldp); - update_b = update_bits[delp]*256 + vp8_cost_upd256; + update_b = prob_diff_update_cost(newp, oldp) + vp8_cost_upd256; savings = old_b - new_b - update_b; if (savings > bestsavings) { @@ -1197,6 +1187,7 @@ static void write_kfmodes(VP8_COMP *cpi) int row_delta[4] = { 0, +1, 0, -1}; int col_delta[4] = {+1, -1, +1, +1}; + //printf("write_kfmodes\n"); if (c->mb_no_coeff_skip) { // Divide by 0 check. 0 case possible with segment features @@ -1322,6 +1313,7 @@ static void write_kfmodes(VP8_COMP *cpi) #endif write_bmode(bc, bm, c->kf_bmode_prob [A] [L]); + //printf(" mode: %d\n", bm); #if CONFIG_COMP_INTRA_PRED if (uses_second) { @@ -1335,12 +1327,16 @@ static void write_kfmodes(VP8_COMP *cpi) { write_i8x8_mode(bc, m->bmi[0].as_mode.first, c->i8x8_mode_prob); + //printf(" mode: %d\n", m->bmi[0].as_mode.first); fflush(stdout); write_i8x8_mode(bc, m->bmi[2].as_mode.first, c->i8x8_mode_prob); + //printf(" mode: %d\n", m->bmi[2].as_mode.first); fflush(stdout); write_i8x8_mode(bc, m->bmi[8].as_mode.first, c->i8x8_mode_prob); + //printf(" mode: %d\n", m->bmi[8].as_mode.first); fflush(stdout); write_i8x8_mode(bc, m->bmi[10].as_mode.first, c->i8x8_mode_prob); + //printf(" mode: %d\n", m->bmi[10].as_mode.first); fflush(stdout); } else write_uv_mode(bc, m->mbmi.uv_mode, c->kf_uv_mode_prob[ym]); @@ -1519,7 +1515,7 @@ static void update_coef_probs3(VP8_COMP *cpi) #endif #if defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) u = 1; if (u) @@ -1558,7 +1554,7 @@ static void update_coef_probs3(VP8_COMP *cpi) continue; #endif #if defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) u = 1; #else @@ -1574,8 +1570,7 @@ static void update_coef_probs3(VP8_COMP *cpi) #endif if (u) { /* send/use new probability */ - int delp = remap_prob(newp, *Pold); - vp8_encode_term_subexp(w, delp, SUBEXP_PARAM, 255); + write_prob_diff_update(w, newp, *Pold); *Pold = newp; } @@ -1608,7 +1603,7 @@ static void update_coef_probs3(VP8_COMP *cpi) continue; #endif #if defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct_8x8 [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) @@ -1650,7 +1645,7 @@ static void update_coef_probs3(VP8_COMP *cpi) continue; #endif #if defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct_8x8 [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) @@ -1670,8 +1665,7 @@ static void update_coef_probs3(VP8_COMP *cpi) if (u) { /* send/use new probability */ - int delp = remap_prob(newp, *Pold); - vp8_encode_term_subexp( w, delp, SUBEXP_PARAM, 255); + write_prob_diff_update(w, newp, *Pold); *Pold = newp; } } @@ -1704,18 +1698,18 @@ static void update_coef_probs2(VP8_COMP *cpi) { for (k = 0; k < PREV_COEF_CONTEXTS; ++k) { -#if CONFIG_EXPANDED_COEF_CONTEXT - if (k >=3 && ((i == 0 && j == 1) || (i > 0 && j == 0))) - continue; -#endif vp8_prob newp = cpi->frame_coef_probs [i][j][k][t]; vp8_prob *Pold = cpi->common.fc.coef_probs [i][j][k] + t; const vp8_prob upd = vp8_coef_update_probs [i][j][k][t]; int s; int u = 0; +#if CONFIG_EXPANDED_COEF_CONTEXT + if (k >=3 && ((i == 0 && j == 1) || (i > 0 && j == 0))) + continue; +#endif #if defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) u = 1; if (u) @@ -1756,7 +1750,7 @@ static void update_coef_probs2(VP8_COMP *cpi) continue; #endif #if defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) u = 1; #else @@ -1771,8 +1765,7 @@ static void update_coef_probs2(VP8_COMP *cpi) #endif if (u) { /* send/use new probability */ - int delp = remap_prob(newp, *Pold); - vp8_encode_term_subexp(w, delp, SUBEXP_PARAM, 255); + write_prob_diff_update(w, newp, *Pold); *Pold = newp; } } @@ -1803,7 +1796,7 @@ static void update_coef_probs2(VP8_COMP *cpi) continue; #endif #if defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct_8x8 [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) @@ -1847,7 +1840,7 @@ static void update_coef_probs2(VP8_COMP *cpi) continue; #endif #if defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct_8x8 [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) @@ -1867,8 +1860,7 @@ static void update_coef_probs2(VP8_COMP *cpi) if (u) { /* send/use new probability */ - int delp = remap_prob(newp, *Pold); - vp8_encode_term_subexp( w, delp, SUBEXP_PARAM, 255); + write_prob_diff_update(w, newp, *Pold); *Pold = newp; } } @@ -1920,7 +1912,7 @@ static void update_coef_probs(VP8_COMP *cpi) continue; #endif #if CONFIG_NEWUPDATE && defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) @@ -1992,7 +1984,7 @@ static void update_coef_probs(VP8_COMP *cpi) #endif #if CONFIG_NEWUPDATE && defined(SEARCH_NEWP) - s = prob_update_savings_search( + s = prob_diff_update_savings_search( cpi->frame_branch_ct [i][j][k][t], *Pold, &newp, upd); if (s > 0 && newp != *Pold) @@ -2015,9 +2007,7 @@ static void update_coef_probs(VP8_COMP *cpi) { /* send/use new probability */ #if CONFIG_NEWUPDATE - vp8_encode_term_subexp( - w, remap_prob(newp, *Pold), SUBEXP_PARAM, 255); - //printf("delp = %d/%d/%d\n", *Pold, remap_prob(newp, *Pold, 256), newp); + write_prob_diff_update(w, newp, *Pold); #else vp8_write_literal(w, newp, 8); #endif @@ -2068,7 +2058,7 @@ static void update_coef_probs(VP8_COMP *cpi) continue; #endif #if CONFIG_NEWUPDATE && defined(SEARCH_NEWP) - const int s = prob_update_savings_search(ct, oldp, &newp, upd); + const int s = prob_diff_update_savings_search(ct, oldp, &newp, upd); const int u = s > 0 && newp != oldp ? 1 : 0; if (u) savings += s - (int)(vp8_cost_zero(upd)); @@ -2124,7 +2114,7 @@ static void update_coef_probs(VP8_COMP *cpi) const vp8_prob oldp = *Pold; const vp8_prob upd = vp8_coef_update_probs_8x8 [i][j][k][t]; #if CONFIG_NEWUPDATE && defined(SEARCH_NEWP) - const int s = prob_update_savings_search(ct, oldp, &newp, upd); + const int s = prob_diff_update_savings_search(ct, oldp, &newp, upd); const int u = s > 0 && newp != oldp ? 1 : 0; #else const int s = prob_update_savings(ct, oldp, newp, upd); @@ -2144,8 +2134,7 @@ static void update_coef_probs(VP8_COMP *cpi) { /* send/use new probability */ #if CONFIG_NEWUPDATE - vp8_encode_term_subexp( - w, remap_prob(newp, oldp), SUBEXP_PARAM, 255); + write_prob_diff_update(w, newp, oldp); #else vp8_write_literal(w, newp, 8); #endif diff --git a/vp8/encoder/block.h b/vp8/encoder/block.h index 2b21fa2b2..98bc13277 100644 --- a/vp8/encoder/block.h +++ b/vp8/encoder/block.h @@ -124,7 +124,7 @@ typedef struct #endif int mbmode_cost[2][MB_MODE_COUNT]; int intra_uv_mode_cost[2][MB_MODE_COUNT]; - unsigned int bmode_costs[10][10][10]; + unsigned int bmode_costs[VP8_BINTRAMODES][VP8_BINTRAMODES][VP8_BINTRAMODES]; unsigned int i8x8_mode_costs[MB_MODE_COUNT]; unsigned int inter_bmode_costs[B_MODE_COUNT]; diff --git a/vp8/encoder/dct.c b/vp8/encoder/dct.c index c2f2d1117..6f9c68ef7 100644 --- a/vp8/encoder/dct.c +++ b/vp8/encoder/dct.c @@ -12,11 +12,250 @@ #include <math.h> #include "vpx_ports/config.h" +#if CONFIG_INT_8X8FDCT +static const int xC1S7 = 16069; +static const int xC2S6 = 15137; +static const int xC3S5 = 13623; +static const int xC4S4 = 11585; +static const int xC5S3 = 9102; +static const int xC6S2 = 6270; +static const int xC7S1 = 3196; +#define SHIFT_BITS 14 +#define DOROUND(X) X += (1<<(SHIFT_BITS-1)); +#define FINAL_SHIFT 3 +#define FINAL_ROUNDING (1<<(FINAL_SHIFT -1)) +#define IN_SHIFT (FINAL_SHIFT+1) +void vp8_short_fdct8x8_c ( short * InputData, short * OutputData, int pitch) +{ + int loop; + int short_pitch = pitch>>1; + int is07, is12, is34, is56; + int is0734, is1256; + int id07, id12, id34, id56; + int irot_input_x, irot_input_y; + int icommon_product1; // Re-used product (c4s4 * (s12 - s56)) + int icommon_product2; // Re-used product (c4s4 * (d12 + d56)) + int temp1, temp2; // intermediate variable for computation + + int InterData[64]; + int *ip = InterData; + short *op = OutputData; + + for (loop = 0; loop < 8; loop++) + { + // Pre calculate some common sums and differences. + is07 = (InputData[0] + InputData[7])<<IN_SHIFT; + is12 = (InputData[1] + InputData[2])<<IN_SHIFT; + is34 = (InputData[3] + InputData[4])<<IN_SHIFT; + is56 = (InputData[5] + InputData[6])<<IN_SHIFT; + id07 = (InputData[0] - InputData[7])<<IN_SHIFT; + id12 = (InputData[1] - InputData[2])<<IN_SHIFT; + id34 = (InputData[3] - InputData[4])<<IN_SHIFT; + id56 = (InputData[5] - InputData[6])<<IN_SHIFT; + + is0734 = is07 + is34; + is1256 = is12 + is56; + + // Pre-Calculate some common product terms. + icommon_product1 = xC4S4*(is12 - is56); + DOROUND(icommon_product1) + icommon_product1>>=SHIFT_BITS; + + icommon_product2 = xC4S4*(id12 + id56); + DOROUND(icommon_product2) + icommon_product2>>=SHIFT_BITS; + + + ip[0] = (xC4S4*(is0734 + is1256)); + DOROUND(ip[0]); + ip[0] >>= SHIFT_BITS; + + ip[4] = (xC4S4*(is0734 - is1256)); + DOROUND(ip[4]); + ip[4] >>= SHIFT_BITS; + + // Define inputs to rotation for outputs 2 and 6 + irot_input_x = id12 - id56; + irot_input_y = is07 - is34; + + // Apply rotation for outputs 2 and 6. + temp1=xC6S2*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC2S6*irot_input_y; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + ip[2] = temp1 + temp2; + + temp1=xC6S2*irot_input_y; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC2S6*irot_input_x ; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + ip[6] = temp1 -temp2 ; + + // Define inputs to rotation for outputs 1 and 7 + irot_input_x = icommon_product1 + id07; + irot_input_y = -( id34 + icommon_product2 ); + + // Apply rotation for outputs 1 and 7. + temp1=xC1S7*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC7S1*irot_input_y; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + ip[1] = temp1 - temp2; + + temp1=xC7S1*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC1S7*irot_input_y ; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + ip[7] = temp1 + temp2 ; + + // Define inputs to rotation for outputs 3 and 5 + irot_input_x = id07 - icommon_product1; + irot_input_y = id34 - icommon_product2; + + // Apply rotation for outputs 3 and 5. + temp1=xC3S5*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC5S3*irot_input_y ; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + ip[3] = temp1 - temp2 ; + + + temp1=xC5S3*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC3S5*irot_input_y; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + ip[5] = temp1 + temp2; + + // Increment data pointer for next row + InputData += short_pitch ; + ip += 8; + } + + // Performed DCT on rows, now transform the columns + ip = InterData; + for (loop = 0; loop < 8; loop++) + { + // Pre calculate some common sums and differences. + is07 = ip[0 * 8] + ip[7 * 8]; + is12 = ip[1 * 8] + ip[2 * 8]; + is34 = ip[3 * 8] + ip[4 * 8]; + is56 = ip[5 * 8] + ip[6 * 8]; + + id07 = ip[0 * 8] - ip[7 * 8]; + id12 = ip[1 * 8] - ip[2 * 8]; + id34 = ip[3 * 8] - ip[4 * 8]; + id56 = ip[5 * 8] - ip[6 * 8]; + + is0734 = is07 + is34; + is1256 = is12 + is56; + + // Pre-Calculate some common product terms + icommon_product1 = xC4S4*(is12 - is56) ; + icommon_product2 = xC4S4*(id12 + id56) ; + DOROUND(icommon_product1) + DOROUND(icommon_product2) + icommon_product1>>=SHIFT_BITS; + icommon_product2>>=SHIFT_BITS; + + + temp1 = xC4S4*(is0734 + is1256) ; + temp2 = xC4S4*(is0734 - is1256) ; + DOROUND(temp1); + DOROUND(temp2); + temp1>>=SHIFT_BITS; + + temp2>>=SHIFT_BITS; + op[0*8] = (temp1 + FINAL_ROUNDING)>>FINAL_SHIFT; + op[4*8] = (temp2 + FINAL_ROUNDING)>>FINAL_SHIFT; + + // Define inputs to rotation for outputs 2 and 6 + irot_input_x = id12 - id56; + irot_input_y = is07 - is34; + + // Apply rotation for outputs 2 and 6. + temp1=xC6S2*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC2S6*irot_input_y; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + op[2*8] = (temp1 + temp2 + FINAL_ROUNDING)>>FINAL_SHIFT; + + temp1=xC6S2*irot_input_y; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC2S6*irot_input_x ; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + op[6*8] = (temp1 -temp2 + FINAL_ROUNDING)>>FINAL_SHIFT ; + + // Define inputs to rotation for outputs 1 and 7 + irot_input_x = icommon_product1 + id07; + irot_input_y = -( id34 + icommon_product2 ); + + // Apply rotation for outputs 1 and 7. + temp1=xC1S7*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC7S1*irot_input_y; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + op[1*8] = (temp1 - temp2 + FINAL_ROUNDING)>>FINAL_SHIFT; + + temp1=xC7S1*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC1S7*irot_input_y ; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + op[7*8] = (temp1 + temp2 + FINAL_ROUNDING)>>FINAL_SHIFT; + + // Define inputs to rotation for outputs 3 and 5 + irot_input_x = id07 - icommon_product1; + irot_input_y = id34 - icommon_product2; + + // Apply rotation for outputs 3 and 5. + temp1=xC3S5*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC5S3*irot_input_y ; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + op[3*8] = (temp1 - temp2 + FINAL_ROUNDING)>>FINAL_SHIFT ; + + + temp1=xC5S3*irot_input_x; + DOROUND(temp1); + temp1>>=SHIFT_BITS; + temp2=xC3S5*irot_input_y; + DOROUND(temp2); + temp2>>=SHIFT_BITS; + op[5*8] = (temp1 + temp2 + FINAL_ROUNDING)>>FINAL_SHIFT; + + // Increment data pointer for next column. + ip ++; + op ++; + } +} +#else + void vp8_short_fdct8x8_c(short *block, short *coefs, int pitch) { int j1, i, j, k; @@ -106,7 +345,7 @@ void vp8_short_fdct8x8_c(short *block, short *coefs, int pitch) return; } - +#endif void vp8_short_fhaar2x2_c(short *input, short *output, int pitch) //pitch = 8 { @@ -181,52 +420,41 @@ void vp8_short_walsh4x4_c(short *input, short *output, int pitch) { int i; int a1, b1, c1, d1; - int a2, b2, c2, d2; short *ip = input; short *op = output; - + int pitch_short = pitch >>1; for (i = 0; i < 4; i++) { - a1 = ((ip[0] + ip[2])); - d1 = ((ip[1] + ip[3])); - c1 = ((ip[1] - ip[3])); - b1 = ((ip[0] - ip[2])); - - op[0] = a1 + d1; - op[1] = b1 + c1; - op[2] = b1 - c1; - op[3] = a1 - d1; - ip += pitch / 2; - op += 4; - } + a1 = ip[0 * pitch_short] + ip[3 * pitch_short]; + b1 = ip[1 * pitch_short] + ip[2 * pitch_short]; + c1 = ip[1 * pitch_short] - ip[2 * pitch_short]; + d1 = ip[0 * pitch_short] - ip[3 * pitch_short]; + + op[0] = (a1 + b1 + 1)>>1; + op[4] = (c1 + d1)>>1; + op[8] = (a1 - b1)>>1; + op[12]= (d1 - c1)>>1; + ip++; + op++; + } ip = output; op = output; for (i = 0; i < 4; i++) { - a1 = ip[0] + ip[8]; - d1 = ip[4] + ip[12]; - c1 = ip[4] - ip[12]; - b1 = ip[0] - ip[8]; - - a2 = a1 + d1; - b2 = b1 + c1; - c2 = b1 - c1; - d2 = a1 - d1; - - a2 += a2<0; - b2 += b2<0; - c2 += c2<0; - d2 += d2<0; - - op[0] = (a2+1) >> 2; - op[4] = (b2+1) >> 2; - op[8] = (c2+1) >> 2; - op[12]= (d2+1) >> 2; + a1 = ip[0] + ip[3]; + b1 = ip[1] + ip[2]; + c1 = ip[1] - ip[2]; + d1 = ip[0] - ip[3]; - ip++; - op++; + op[0] = (a1 + b1 + 1)>>1; + op[1] = (c1 + d1)>>1; + op[2] = (a1 - b1)>>1; + op[3] = (d1 - c1)>>1; + + ip += 4; + op += 4; } -} +}
\ No newline at end of file diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c index a044f8cb9..364d6ed55 100644 --- a/vp8/encoder/encodeframe.c +++ b/vp8/encoder/encodeframe.c @@ -71,22 +71,14 @@ static void adjust_act_zbin( VP8_COMP *cpi, MACROBLOCK *x ); #ifdef MODE_STATS -unsigned int inter_y_modes[MB_MODE_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -unsigned int inter_uv_modes[VP8_UV_MODES] = {0, 0, 0, 0}; -unsigned int inter_b_modes[B_MODE_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -unsigned int y_modes[VP8_YMODES] = {0, 0, 0, 0, 0, 0}; -unsigned int i8x8_modes[VP8_I8X8_MODES]={0 }; -unsigned int uv_modes[VP8_UV_MODES] = {0, 0, 0, 0}; -unsigned int uv_modes_y[VP8_YMODES][VP8_UV_MODES]= -{ -{0, 0, 0, 0}, -{0, 0, 0, 0}, -{0, 0, 0, 0}, -{0, 0, 0, 0}, -{0, 0, 0, 0}, -{0, 0, 0, 0} -}; -unsigned int b_modes[B_MODE_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +unsigned int inter_y_modes[MB_MODE_COUNT]; +unsigned int inter_uv_modes[VP8_UV_MODES]; +unsigned int inter_b_modes[B_MODE_COUNT]; +unsigned int y_modes[VP8_YMODES]; +unsigned int i8x8_modes[VP8_I8X8_MODES]; +unsigned int uv_modes[VP8_UV_MODES]; +unsigned int uv_modes_y[VP8_YMODES][VP8_UV_MODES]; +unsigned int b_modes[B_MODE_COUNT]; #endif @@ -628,6 +620,23 @@ static void pick_mb_modes (VP8_COMP *cpi, } else { + int seg_id; + + if (xd->segmentation_enabled && cpi->seg0_cnt > 0 && + !segfeature_active( xd, 0, SEG_LVL_REF_FRAME ) && + segfeature_active( xd, 1, SEG_LVL_REF_FRAME ) && + check_segref(xd, 1, INTRA_FRAME) + + check_segref(xd, 1, LAST_FRAME) + + check_segref(xd, 1, GOLDEN_FRAME) + + check_segref(xd, 1, ALTREF_FRAME) == 1) + { + cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; + } + else + { + cpi->seg0_progress = (((mb_col & ~1) * 2 + (mb_row & ~1) * cm->mb_cols + i) << 16) / cm->MBs; + } + *totalrate += vp8cx_pick_mode_inter_macroblock(cpi, x, recon_yoffset, recon_uvoffset); @@ -635,6 +644,26 @@ static void pick_mb_modes (VP8_COMP *cpi, // Dummy encode, do not do the tokenization vp8cx_encode_inter_macroblock(cpi, x, tp, recon_yoffset, recon_uvoffset, 0); + + seg_id = xd->mode_info_context->mbmi.segment_id; + if (cpi->mb.e_mbd.segmentation_enabled && seg_id == 0) + { + cpi->seg0_idx++; + } + if (!xd->segmentation_enabled || + !segfeature_active( xd, seg_id, SEG_LVL_REF_FRAME ) || + check_segref(xd, seg_id, INTRA_FRAME) + + check_segref(xd, seg_id, LAST_FRAME) + + check_segref(xd, seg_id, GOLDEN_FRAME) + + check_segref(xd, seg_id, ALTREF_FRAME) > 1) + { + // Get the prediction context and status + int pred_flag = get_pred_flag( xd, PRED_REF ); + int pred_context = get_pred_context( cm, xd, PRED_REF ); + + // Count prediction success + cpi->ref_pred_count[pred_context][pred_flag]++; + } } // Keep a copy of the updated left context @@ -997,6 +1026,8 @@ void init_encode_frame_mb_context(VP8_COMP *cpi) x->mb_activity_ptr = cpi->mb_activity_map; x->act_zbin_adj = 0; + cpi->seg0_idx = 0; + vpx_memset(cpi->ref_pred_count, 0, sizeof(cpi->ref_pred_count)); x->partition_info = x->pi; @@ -1288,11 +1319,13 @@ void vp8_encode_frame(VP8_COMP *cpi) else frame_type = 2; - if (cpi->rd_prediction_type_threshes[frame_type][1] > - cpi->rd_prediction_type_threshes[frame_type][0] && - cpi->rd_prediction_type_threshes[frame_type][1] > - cpi->rd_prediction_type_threshes[frame_type][2] && - check_dual_ref_flags(cpi)) + if (frame_type == 3) + pred_type = SINGLE_PREDICTION_ONLY; + else if (cpi->rd_prediction_type_threshes[frame_type][1] > + cpi->rd_prediction_type_threshes[frame_type][0] && + cpi->rd_prediction_type_threshes[frame_type][1] > + cpi->rd_prediction_type_threshes[frame_type][2] && + check_dual_ref_flags(cpi)) pred_type = COMP_PREDICTION_ONLY; else if (cpi->rd_prediction_type_threshes[frame_type][0] > cpi->rd_prediction_type_threshes[frame_type][1] && diff --git a/vp8/encoder/encodemb.c b/vp8/encoder/encodemb.c index ae8ab8846..81c69d9f8 100644 --- a/vp8/encoder/encodemb.c +++ b/vp8/encoder/encodemb.c @@ -239,7 +239,9 @@ void vp8_transform_mbuv_8x8(MACROBLOCK *x) { int i; +#if !CONFIG_INT_8X8FDCT vp8_clear_system_state(); +#endif for (i = 16; i < 24; i += 4) { @@ -252,9 +254,9 @@ void vp8_transform_mbuv_8x8(MACROBLOCK *x) void vp8_transform_intra_mby_8x8(MACROBLOCK *x)//changed { int i; - +#if !CONFIG_INT_8X8FDCT vp8_clear_system_state(); - +#endif for (i = 0; i < 9; i += 8) { x->vp8_short_fdct8x8(&x->block[i].src_diff[0], @@ -279,9 +281,9 @@ void vp8_transform_intra_mby_8x8(MACROBLOCK *x)//changed void vp8_transform_mb_8x8(MACROBLOCK *x) { int i; - +#if !CONFIG_INT_8X8FDCT vp8_clear_system_state(); - +#endif for (i = 0; i < 9; i += 8) { x->vp8_short_fdct8x8(&x->block[i].src_diff[0], @@ -312,9 +314,9 @@ void vp8_transform_mb_8x8(MACROBLOCK *x) void vp8_transform_mby_8x8(MACROBLOCK *x) { int i; - +#if !CONFIG_INT_8X8FDCT vp8_clear_system_state(); - +#endif for (i = 0; i < 9; i += 8) { x->vp8_short_fdct8x8(&x->block[i].src_diff[0], diff --git a/vp8/encoder/mbgraph.c b/vp8/encoder/mbgraph.c index ebdb9b504..d2d3b6bdc 100644 --- a/vp8/encoder/mbgraph.c +++ b/vp8/encoder/mbgraph.c @@ -502,6 +502,7 @@ void separate_arf_mbs else cpi->static_mb_pct = 0; + cpi->seg0_cnt = ncnt[0]; vp8_enable_segmentation((VP8_PTR) cpi); } else diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 1a174c125..a66e71af4 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -140,7 +140,7 @@ extern int skip_false_count; #ifdef ENTROPY_STATS -extern int intra_mode_stats[10][10][10]; +extern int intra_mode_stats[VP8_BINTRAMODES][VP8_BINTRAMODES][VP8_BINTRAMODES]; #endif #ifdef SPEEDSTATS @@ -156,13 +156,13 @@ extern unsigned __int64 Sectionbits[500]; #endif #ifdef MODE_STATS extern INT64 Sectionbits[500]; -extern int y_modes[VP8_YMODES] ; -extern int i8x8_modes[VP8_I8X8_MODES]; -extern int uv_modes[VP8_UV_MODES] ; -extern int uv_modes_y[VP8_YMODES][VP8_UV_MODES]; -extern int b_modes[B_MODE_COUNT]; -extern int inter_y_modes[MB_MODE_COUNT] ; -extern int inter_uv_modes[VP8_UV_MODES] ; +extern unsigned int y_modes[VP8_YMODES] ; +extern unsigned int i8x8_modes[VP8_I8X8_MODES]; +extern unsigned int uv_modes[VP8_UV_MODES] ; +extern unsigned int uv_modes_y[VP8_YMODES][VP8_UV_MODES]; +extern unsigned int b_modes[B_MODE_COUNT]; +extern unsigned int inter_y_modes[MB_MODE_COUNT] ; +extern unsigned int inter_uv_modes[VP8_UV_MODES] ; extern unsigned int inter_b_modes[B_MODE_COUNT]; #endif @@ -760,6 +760,14 @@ void vp8_set_speed_features(VP8_COMP *cpi) sf->thresh_mult[THR_V_PRED ] = 1000; sf->thresh_mult[THR_H_PRED ] = 1000; +#if CONFIG_NEWINTRAMODES + sf->thresh_mult[THR_D45_PRED ] = 1000; + sf->thresh_mult[THR_D135_PRED] = 1000; + sf->thresh_mult[THR_D117_PRED] = 1000; + sf->thresh_mult[THR_D153_PRED] = 1000; + sf->thresh_mult[THR_D27_PRED ] = 1000; + sf->thresh_mult[THR_D63_PRED ] = 1000; +#endif sf->thresh_mult[THR_B_PRED ] = 2000; sf->thresh_mult[THR_I8X8_PRED] = 2000; sf->thresh_mult[THR_TM ] = 1000; @@ -803,6 +811,14 @@ void vp8_set_speed_features(VP8_COMP *cpi) sf->thresh_mult[THR_NEARMV ] = 0; sf->thresh_mult[THR_V_PRED ] = 1000; sf->thresh_mult[THR_H_PRED ] = 1000; +#if CONFIG_NEWINTRAMODES + sf->thresh_mult[THR_D45_PRED ] = 1000; + sf->thresh_mult[THR_D135_PRED] = 1000; + sf->thresh_mult[THR_D117_PRED] = 1000; + sf->thresh_mult[THR_D153_PRED] = 1000; + sf->thresh_mult[THR_D27_PRED ] = 1000; + sf->thresh_mult[THR_D63_PRED ] = 1000; +#endif sf->thresh_mult[THR_B_PRED ] = 2500; sf->thresh_mult[THR_I8X8_PRED] = 2500; sf->thresh_mult[THR_TM ] = 1000; @@ -881,6 +897,14 @@ void vp8_set_speed_features(VP8_COMP *cpi) sf->thresh_mult[THR_TM ] = 1500; sf->thresh_mult[THR_V_PRED ] = 1500; sf->thresh_mult[THR_H_PRED ] = 1500; +#if CONFIG_NEWINTRAMODES + sf->thresh_mult[THR_D45_PRED ] = 1500; + sf->thresh_mult[THR_D135_PRED] = 1500; + sf->thresh_mult[THR_D117_PRED] = 1500; + sf->thresh_mult[THR_D153_PRED] = 1500; + sf->thresh_mult[THR_D27_PRED ] = 1500; + sf->thresh_mult[THR_D63_PRED ] = 1500; +#endif sf->thresh_mult[THR_B_PRED ] = 5000; sf->thresh_mult[THR_I8X8_PRED] = 5000; @@ -939,6 +963,14 @@ void vp8_set_speed_features(VP8_COMP *cpi) sf->thresh_mult[THR_TM ] = 2000; sf->thresh_mult[THR_V_PRED ] = 2000; sf->thresh_mult[THR_H_PRED ] = 2000; +#if CONFIG_NEWINTRAMODES + sf->thresh_mult[THR_D45_PRED ] = 2000; + sf->thresh_mult[THR_D135_PRED] = 2000; + sf->thresh_mult[THR_D117_PRED] = 2000; + sf->thresh_mult[THR_D153_PRED] = 2000; + sf->thresh_mult[THR_D27_PRED ] = 2000; + sf->thresh_mult[THR_D63_PRED ] = 2000; +#endif sf->thresh_mult[THR_B_PRED ] = 7500; sf->thresh_mult[THR_I8X8_PRED] = 7500; @@ -1719,6 +1751,16 @@ VP8_PTR vp8_create_compressor(VP8_CONFIG *oxcf) #ifdef ENTROPY_STATS init_context_counters(); #endif +#ifdef MODE_STATS + vp8_zero(y_modes); + vp8_zero(i8x8_modes); + vp8_zero(uv_modes); + vp8_zero(uv_modes_y); + vp8_zero(b_modes); + vp8_zero(inter_y_modes); + vp8_zero(inter_uv_modes); + vp8_zero(inter_b_modes); +#endif /*Initialize the feed-forward activity masking.*/ cpi->activity_avg = 90<<12; @@ -2006,32 +2048,49 @@ void vp8_remove_compressor(VP8_PTR *ptr) sprintf(modes_stats_file, "modes_q%03d.stt",cpi->common.base_qindex); f = fopen(modes_stats_file, "w"); fprintf(f, "intra_mode in Intra Frames:\n"); - fprintf(f, "Y: %8d, %8d, %8d, %8d, %8d, %8d\n", y_modes[0], y_modes[1], y_modes[2], y_modes[3], y_modes[4], y_modes[5]); - fprintf(f, "I8:%8d, %8d, %8d, %8d\n", i8x8_modes[0], i8x8_modes[1], i8x8_modes[2], i8x8_modes[3]); - fprintf(f, "UV:%8d, %8d, %8d, %8d\n", uv_modes[0], uv_modes[1], uv_modes[2], uv_modes[3]); - fprintf(f, "KeyFrame Y-UV:\n"); { int i; + fprintf(f, "Y: "); + for (i=0;i<VP8_YMODES;i++) fprintf(f, " %8d,", y_modes[i]); + fprintf(f, "\n"); + } + { + int i; + fprintf(f, "I8: "); + for (i=0;i<VP8_I8X8_MODES;i++) fprintf(f, " %8d,", i8x8_modes[i]); + fprintf(f, "\n"); + } + { + int i; + fprintf(f, "UV: "); + for (i=0;i<VP8_UV_MODES;i++) fprintf(f, " %8d,", uv_modes[i]); + fprintf(f, "\n"); + } + { + int i, j; + fprintf(f, "KeyFrame Y-UV:\n"); for(i=0;i<VP8_YMODES;i++) { - fprintf(f, "%2d:%8d, %8d, %8d, %8d\n",i,uv_modes_y[i][0], - uv_modes_y[i][1], uv_modes_y[i][2], uv_modes_y[i][3]); + fprintf(f, "%2d:", i); + for (j=0; j<VP8_UV_MODES;j++) fprintf(f, "%8d, ",uv_modes_y[i][j]); + fprintf(f, "\n"); } } - fprintf(f, "Inter Y-UV:\n"); { - int i; + int i, j; + fprintf(f, "Inter Y-UV:\n"); for(i=0;i<VP8_YMODES;i++) { - fprintf(f, "%2d:%8d, %8d, %8d, %8d\n",i,cpi->y_uv_mode_count[i][0], - cpi->y_uv_mode_count[i][1], cpi->y_uv_mode_count[i][2], cpi->y_uv_mode_count[i][3]); + fprintf(f, "%2d:", i); + for (j=0; j<VP8_UV_MODES;j++) fprintf(f, "%8d, ",cpi->y_uv_mode_count[i][j]); + fprintf(f, "\n"); } } - fprintf(f, "B: "); { int i; - for (i = 0; i < 10; i++) + fprintf(f, "B: "); + for (i = 0; i < VP8_BINTRAMODES; i++) fprintf(f, "%8d, ", b_modes[i]); fprintf(f, "\n"); @@ -2039,23 +2098,23 @@ void vp8_remove_compressor(VP8_PTR *ptr) } fprintf(f, "Modes in Inter Frames:\n"); - fprintf(f, - "Y: %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d, %8d\n", - inter_y_modes[0], inter_y_modes[1], inter_y_modes[2], - inter_y_modes[3], inter_y_modes[4], inter_y_modes[5], - inter_y_modes[6], inter_y_modes[7], inter_y_modes[8], - inter_y_modes[9], inter_y_modes[10]); - fprintf(f, "UV:%8d, %8d, %8d, %8d\n", inter_uv_modes[0], - inter_uv_modes[1], inter_uv_modes[2], inter_uv_modes[3]); - fprintf(f, "B: "); { int i; - - for (i = 0; i < 15; i++) - fprintf(f, "%8d, ", inter_b_modes[i]); - + fprintf(f, "Y: "); + for (i=0;i<MB_MODE_COUNT;i++) fprintf(f, " %8d,", inter_y_modes[i]); + fprintf(f, "\n"); + } + { + int i; + fprintf(f, "UV: "); + for (i=0;i<VP8_UV_MODES;i++) fprintf(f, " %8d,", inter_uv_modes[i]); + fprintf(f, "\n"); + } + { + int i; + fprintf(f, "B: "); + for (i = 0; i < B_MODE_COUNT; i++) fprintf(f, "%8d, ", inter_b_modes[i]); fprintf(f, "\n"); - } fprintf(f, "P:%8d, %8d, %8d, %8d\n", count_mb_seg[0], count_mb_seg[1], count_mb_seg[2], count_mb_seg[3]); fprintf(f, "PB:%8d, %8d, %8d, %8d\n", inter_b_modes[LEFT4X4], inter_b_modes[ABOVE4X4], inter_b_modes[ZERO4X4], inter_b_modes[NEW4X4]); @@ -2082,7 +2141,7 @@ void vp8_remove_compressor(VP8_PTR *ptr) fprintf(fmode, " {"); - for (k = 0; k < 10; k++) + for (k = 0; k < VP8_BINTRAMODES; k++) { if (!intra_mode_stats[i][j][k]) fprintf(fmode, " %5d, ", 1); diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index 93a445cba..feefc249a 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -41,7 +41,12 @@ #define AF_THRESH 25 #define AF_THRESH2 100 #define ARF_DECAY_THRESH 12 + +#if CONFIG_NEWINTRAMODES +#define MAX_MODES 42 +#else #define MAX_MODES 36 +#endif #define MIN_THRESHMULT 32 #define MAX_THRESHMULT 512 @@ -173,38 +178,46 @@ typedef enum THR_V_PRED = 10, THR_H_PRED = 11, - THR_TM = 12, +#if CONFIG_NEWINTRAMODES + THR_D45_PRED, + THR_D135_PRED, + THR_D117_PRED, + THR_D153_PRED, + THR_D27_PRED, + THR_D63_PRED, +#endif + THR_TM, - THR_NEWMV = 13, - THR_NEWG = 14, - THR_NEWA = 15, + THR_NEWMV, + THR_NEWG, + THR_NEWA, - THR_SPLITMV = 16, - THR_SPLITG = 17, - THR_SPLITA = 18, + THR_SPLITMV, + THR_SPLITG, + THR_SPLITA, - THR_B_PRED = 19, - THR_I8X8_PRED = 20, + THR_B_PRED, + THR_I8X8_PRED, - THR_COMP_ZEROLG = 21, - THR_COMP_NEARESTLG = 22, - THR_COMP_NEARLG = 23, + THR_COMP_ZEROLG, + THR_COMP_NEARESTLG, + THR_COMP_NEARLG, - THR_COMP_ZEROLA = 24, - THR_COMP_NEARESTLA = 25, - THR_COMP_NEARLA = 26, + THR_COMP_ZEROLA, + THR_COMP_NEARESTLA, + THR_COMP_NEARLA, - THR_COMP_ZEROGA = 27, - THR_COMP_NEARESTGA = 28, - THR_COMP_NEARGA = 29, + THR_COMP_ZEROGA, + THR_COMP_NEARESTGA, + THR_COMP_NEARGA, - THR_COMP_NEWLG = 30, - THR_COMP_NEWLA = 31, - THR_COMP_NEWGA = 32, + THR_COMP_NEWLG, + THR_COMP_NEWLA, + THR_COMP_NEWGA, - THR_COMP_SPLITLG = 33, - THR_COMP_SPLITLA = 34, - THR_COMP_SPLITGA = 35, + THR_COMP_SPLITLG, + THR_COMP_SPLITLA, + THR_COMP_SPLITGA, } THR_MODES; @@ -472,6 +485,8 @@ typedef struct VP8_COMP MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS]; int mbgraph_n_frames; // number of frames filled in the above int static_mb_pct; // % forced skip mbs by segmentation + int seg0_progress, seg0_idx, seg0_cnt; + int ref_pred_count[3][2]; int decimation_factor; int decimation_count; diff --git a/vp8/encoder/ratectrl.c b/vp8/encoder/ratectrl.c index f51fe6fb2..864dd6573 100644 --- a/vp8/encoder/ratectrl.c +++ b/vp8/encoder/ratectrl.c @@ -33,13 +33,13 @@ extern const MV_REFERENCE_FRAME vp8_ref_frame_order[MAX_MODES]; #ifdef MODE_STATS -extern int y_modes[VP8_YMODES]; -extern int uv_modes[VP8_UV_MODES]; -extern int b_modes[B_MODE_COUNT]; +extern unsigned int y_modes[VP8_YMODES]; +extern unsigned int uv_modes[VP8_UV_MODES]; +extern unsigned int b_modes[B_MODE_COUNT]; -extern int inter_y_modes[MB_MODE_COUNT]; -extern int inter_uv_modes[VP8_UV_MODES]; -extern int inter_b_modes[B_MODE_COUNT]; +extern unsigned int inter_y_modes[MB_MODE_COUNT]; +extern unsigned int inter_uv_modes[VP8_UV_MODES]; +extern unsigned int inter_b_modes[B_MODE_COUNT]; #endif // Bits Per MB at different Q (Multiplied by 512) diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c index cceeb7617..0caa4c73d 100644 --- a/vp8/encoder/rdopt.c +++ b/vp8/encoder/rdopt.c @@ -100,6 +100,14 @@ const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES] = V_PRED, H_PRED, +#if CONFIG_NEWINTRAMODES + D45_PRED, + D135_PRED, + D117_PRED, + D153_PRED, + D27_PRED, + D63_PRED, +#endif TM_PRED, NEWMV, @@ -154,6 +162,14 @@ const MV_REFERENCE_FRAME vp8_ref_frame_order[MAX_MODES] = INTRA_FRAME, INTRA_FRAME, +#if CONFIG_NEWINTRAMODES + INTRA_FRAME, + INTRA_FRAME, + INTRA_FRAME, + INTRA_FRAME, + INTRA_FRAME, + INTRA_FRAME, +#endif INTRA_FRAME, LAST_FRAME, @@ -191,9 +207,13 @@ const MV_REFERENCE_FRAME vp8_ref_frame_order[MAX_MODES] = const MV_REFERENCE_FRAME vp8_second_ref_frame_order[MAX_MODES] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +#if CONFIG_NEWINTRAMODES + 0, 0, + 0, 0, + 0, 0, +#endif + 0, 0, 0, 0, 0, 0, 0, 0, 0, /* compound prediction modes */ GOLDEN_FRAME, @@ -898,7 +918,6 @@ static int rd_pick_intra4x4block( // Do we need to do this for mode2 also? if (mode==B_LD_PRED || mode==B_VL_PRED) continue; - rate = bmode_costs[mode]; #if CONFIG_COMP_INTRA_PRED @@ -2562,7 +2581,66 @@ static void set_i8x8_block_modes(MACROBLOCK *x, int modes[2][4]) } } -void vp8_estimate_ref_frame_costs(VP8_COMP *cpi, unsigned int * ref_costs ) +extern void calc_ref_probs( int * count, vp8_prob * probs ); +static void estimate_curframe_refprobs(VP8_COMP *cpi, vp8_prob mod_refprobs[3], int pred_ref) +{ + int norm_cnt[MAX_REF_FRAMES]; + const int *const rfct = cpi->count_mb_ref_frame_usage; + int intra_count = rfct[INTRA_FRAME]; + int last_count = rfct[LAST_FRAME]; + int gf_count = rfct[GOLDEN_FRAME]; + int arf_count = rfct[ALTREF_FRAME]; + + // Work out modified reference frame probabilities to use where prediction + // of the reference frame fails + if (pred_ref == INTRA_FRAME) + { + norm_cnt[0] = 0; + norm_cnt[1] = last_count; + norm_cnt[2] = gf_count; + norm_cnt[3] = arf_count; + calc_ref_probs( norm_cnt, mod_refprobs ); + mod_refprobs[0] = 0; // This branch implicit + } + else if (pred_ref == LAST_FRAME) + { + norm_cnt[0] = intra_count; + norm_cnt[1] = 0; + norm_cnt[2] = gf_count; + norm_cnt[3] = arf_count; + calc_ref_probs( norm_cnt, mod_refprobs); + mod_refprobs[1] = 0; // This branch implicit + } + else if (pred_ref == GOLDEN_FRAME) + { + norm_cnt[0] = intra_count; + norm_cnt[1] = last_count; + norm_cnt[2] = 0; + norm_cnt[3] = arf_count; + calc_ref_probs( norm_cnt, mod_refprobs ); + mod_refprobs[2] = 0; // This branch implicit + } + else + { + norm_cnt[0] = intra_count; + norm_cnt[1] = last_count; + norm_cnt[2] = gf_count; + norm_cnt[3] = 0; + calc_ref_probs( norm_cnt, mod_refprobs ); + mod_refprobs[2] = 0; // This branch implicit + } +} + +static __inline unsigned weighted_cost(vp8_prob *tab0, vp8_prob *tab1, int idx, int val, int weight) +{ + unsigned cost0 = tab0[idx] ? vp8_cost_bit(tab0[idx], val) : 0; + unsigned cost1 = tab1[idx] ? vp8_cost_bit(tab1[idx], val) : 0; + // weight is 16-bit fixed point, so this basically calculates: + // 0.5 + weight * cost1 + (1.0 - weight) * cost0 + return (0x8000 + weight * cost1 + (0x10000 - weight) * cost0) >> 16; +} + +static void vp8_estimate_ref_frame_costs(VP8_COMP *cpi, int segment_id, unsigned int * ref_costs ) { VP8_COMMON *cm = &cpi->common; MACROBLOCKD *xd = &cpi->mb.e_mbd; @@ -2571,47 +2649,87 @@ void vp8_estimate_ref_frame_costs(VP8_COMP *cpi, unsigned int * ref_costs ) unsigned int cost; int pred_ref ; int pred_flag; + int pred_ctx ; int i; + int tot_count; - vp8_prob pred_prob; + vp8_prob pred_prob, new_pred_prob; + int seg_ref_active; + int seg_ref_count = 0; + seg_ref_active = segfeature_active( xd, + segment_id, + SEG_LVL_REF_FRAME ); + + if ( seg_ref_active ) + { + seg_ref_count = check_segref( xd, segment_id, INTRA_FRAME ) + + check_segref( xd, segment_id, LAST_FRAME ) + + check_segref( xd, segment_id, GOLDEN_FRAME ) + + check_segref( xd, segment_id, ALTREF_FRAME ); + } // Get the predicted reference for this mb pred_ref = get_pred_ref( cm, xd ); - // Get the context probability for the prediction flag + // Get the context probability for the prediction flag (based on last frame) pred_prob = get_pred_prob( cm, xd, PRED_REF ); + // Predict probability for current frame based on stats so far + pred_ctx = get_pred_context(cm, xd, PRED_REF); + tot_count = cpi->ref_pred_count[pred_ctx][0] + cpi->ref_pred_count[pred_ctx][1]; + if ( tot_count ) + { + new_pred_prob = + ( cpi->ref_pred_count[pred_ctx][0] * 255 + (tot_count >> 1)) / tot_count; + new_pred_prob += !new_pred_prob; + } + else + new_pred_prob = 128; + // Get the set of probabilities to use if prediction fails mod_refprobs = cm->mod_refprobs[pred_ref]; // For each possible selected reference frame work out a cost. - // TODO: correct handling of costs if segment indicates only a subset of - // reference frames are allowed... though mostly this should come out - // in the wash. for ( i = 0; i < MAX_REF_FRAMES; i++ ) { - pred_flag = (i == pred_ref); - - // Get the prediction for the current mb - cost = vp8_cost_bit( pred_prob, pred_flag ); - - // for incorrectly predicted cases - if ( ! pred_flag ) + if (seg_ref_active && seg_ref_count == 1) + { + cost = 0; + } + else { - if ( mod_refprobs[0] ) - cost += vp8_cost_bit( mod_refprobs[0], (i != INTRA_FRAME) ); + pred_flag = (i == pred_ref); + + // Get the prediction for the current mb + cost = weighted_cost(&pred_prob, &new_pred_prob, 0, + pred_flag, cpi->seg0_progress); + if (cost > 1024) cost = 768; // i.e. account for 4 bits max. - // Inter coded - if (i != INTRA_FRAME) + // for incorrectly predicted cases + if ( ! pred_flag ) { - if ( mod_refprobs[1] ) - cost += vp8_cost_bit( mod_refprobs[1], (i != LAST_FRAME) ); + vp8_prob curframe_mod_refprobs[3]; - if (i != LAST_FRAME) + if (cpi->seg0_progress) + { + estimate_curframe_refprobs(cpi, curframe_mod_refprobs, pred_ref); + } + else { - if ( mod_refprobs[2] ) - cost += vp8_cost_bit( mod_refprobs[2], - (i != GOLDEN_FRAME)); + vpx_memset(curframe_mod_refprobs, 0, sizeof(curframe_mod_refprobs)); + } + + cost += weighted_cost(mod_refprobs, curframe_mod_refprobs, 0, + (i != INTRA_FRAME), cpi->seg0_progress); + if (i != INTRA_FRAME) + { + cost += weighted_cost(mod_refprobs, curframe_mod_refprobs, 1, + (i != LAST_FRAME), cpi->seg0_progress); + if (i != LAST_FRAME) + { + cost += weighted_cost(mod_refprobs, curframe_mod_refprobs, 2, + (i != GOLDEN_FRAME), cpi->seg0_progress); + } } } } @@ -2800,7 +2918,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int // Get estimates of reference frame costs for each reference frame // that depend on the current prediction etc. - vp8_estimate_ref_frame_costs( cpi, ref_costs ); + vp8_estimate_ref_frame_costs( cpi, segment_id, ref_costs ); for (mode_index = 0; mode_index < MAX_MODES; mode_index++) { @@ -3017,6 +3135,14 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int vp8_cost_bit( get_pred_prob( cm, xd, PRED_COMP ), 0 ); } break; +#if CONFIG_NEWINTRAMODES + case D45_PRED: + case D135_PRED: + case D117_PRED: + case D153_PRED: + case D27_PRED: + case D63_PRED: +#endif case DC_PRED: case V_PRED: case H_PRED: |