| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 
| 3  * | 3  * | 
| 4  *  Use of this source code is governed by a BSD-style license | 4  *  Use of this source code is governed by a BSD-style license | 
| 5  *  that can be found in the LICENSE file in the root of the source | 5  *  that can be found in the LICENSE file in the root of the source | 
| 6  *  tree. An additional intellectual property rights grant can be found | 6  *  tree. An additional intellectual property rights grant can be found | 
| 7  *  in the file PATENTS.  All contributing project authors may | 7  *  in the file PATENTS.  All contributing project authors may | 
| 8  *  be found in the AUTHORS file in the root of the source tree. | 8  *  be found in the AUTHORS file in the root of the source tree. | 
| 9  */ | 9  */ | 
| 10 | 10 | 
| 11 | 11 | 
| 12 #include <math.h> | 12 #include <math.h> | 
| 13 #include <stdio.h> | 13 #include <stdio.h> | 
| 14 #include <string.h> | 14 #include <string.h> | 
| 15 #include <assert.h> | 15 #include <assert.h> | 
| 16 #include "onyx_int.h" | 16 #include "onyx_int.h" | 
| 17 #include "tokenize.h" | 17 #include "tokenize.h" | 
| 18 #include "vpx_mem/vpx_mem.h" | 18 #include "vpx_mem/vpx_mem.h" | 
| 19 | 19 | 
| 20 /* Global event counters used for accumulating statistics across several | 20 /* Global event counters used for accumulating statistics across several | 
| 21    compressions, then generating context.c = initial stats. */ | 21    compressions, then generating context.c = initial stats. */ | 
| 22 | 22 | 
| 23 #ifdef ENTROPY_STATS | 23 #ifdef ENTROPY_STATS | 
| 24 _int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef
     _tokens]; | 24 _int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTR
     OPY_TOKENS]; | 
| 25 #endif | 25 #endif | 
| 26 void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) ; | 26 void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) ; | 
| 27 void vp8_fix_contexts(MACROBLOCKD *x); | 27 void vp8_fix_contexts(MACROBLOCKD *x); | 
| 28 | 28 | 
| 29 static TOKENVALUE dct_value_tokens[DCT_MAX_VALUE*2]; | 29 static TOKENVALUE dct_value_tokens[DCT_MAX_VALUE*2]; | 
| 30 const TOKENVALUE *vp8_dct_value_tokens_ptr; | 30 const TOKENVALUE *vp8_dct_value_tokens_ptr; | 
| 31 static int dct_value_cost[DCT_MAX_VALUE*2]; | 31 static int dct_value_cost[DCT_MAX_VALUE*2]; | 
| 32 const int *vp8_dct_value_cost_ptr; | 32 const int *vp8_dct_value_cost_ptr; | 
| 33 #if 0 | 33 #if 0 | 
| 34 int skip_true_count = 0; | 34 int skip_true_count = 0; | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 88 | 88 | 
| 89     } | 89     } | 
| 90     while (++i < DCT_MAX_VALUE); | 90     while (++i < DCT_MAX_VALUE); | 
| 91 | 91 | 
| 92     vp8_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE; | 92     vp8_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE; | 
| 93     vp8_dct_value_cost_ptr   = dct_value_cost + DCT_MAX_VALUE; | 93     vp8_dct_value_cost_ptr   = dct_value_cost + DCT_MAX_VALUE; | 
| 94 } | 94 } | 
| 95 | 95 | 
| 96 static void tokenize2nd_order_b | 96 static void tokenize2nd_order_b | 
| 97 ( | 97 ( | 
| 98     const BLOCKD *const b, | 98     MACROBLOCKD *x, | 
| 99     TOKENEXTRA **tp, | 99     TOKENEXTRA **tp, | 
| 100     const int type,     /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */ |  | 
| 101     const FRAME_TYPE frametype, |  | 
| 102     ENTROPY_CONTEXT *a, |  | 
| 103     ENTROPY_CONTEXT *l, |  | 
| 104     VP8_COMP *cpi | 100     VP8_COMP *cpi | 
| 105 ) | 101 ) | 
| 106 { | 102 { | 
| 107     int pt; /* near block/prev token context index */ | 103     int pt;             /* near block/prev token context index */ | 
| 108     int c = 0;          /* start at DC */ | 104     int c;              /* start at DC */ | 
| 109     const int eob = b->eob;     /* one beyond last nonzero coeff */ | 105     TOKENEXTRA *t = *tp;/* store tokens starting here */ | 
| 110     TOKENEXTRA *t = *tp;        /* store tokens starting here */ | 106     const BLOCKD *b; | 
| 111     int x; | 107     const short *qcoeff_ptr; | 
| 112     const short *qcoeff_ptr = b->qcoeff; | 108     ENTROPY_CONTEXT * a; | 
|  | 109     ENTROPY_CONTEXT * l; | 
|  | 110     int band, rc, v, token; | 
|  | 111 | 
|  | 112     b = x->block + 24; | 
|  | 113     qcoeff_ptr = b->qcoeff; | 
|  | 114     a = (ENTROPY_CONTEXT *)x->above_context + 8; | 
|  | 115     l = (ENTROPY_CONTEXT *)x->left_context + 8; | 
|  | 116 | 
| 113     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 117     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 
| 114 | 118 | 
| 115     do | 119     for (c = 0; c < b->eob; c++) | 
| 116     { | 120     { | 
| 117         const int band = vp8_coef_bands[c]; | 121         rc = vp8_default_zig_zag1d[c]; | 
|  | 122         band = vp8_coef_bands[c]; | 
|  | 123         v = qcoeff_ptr[rc]; | 
| 118 | 124 | 
| 119         if (c < eob) | 125         t->Extra = vp8_dct_value_tokens_ptr[v].Extra; | 
| 120         { | 126         token    = vp8_dct_value_tokens_ptr[v].Token; | 
| 121             int rc = vp8_default_zig_zag1d[c]; |  | 
| 122             const int v = qcoeff_ptr[rc]; |  | 
| 123 | 127 | 
| 124             assert(-DCT_MAX_VALUE <= v  &&  v < (DCT_MAX_VALUE)); | 128         t->Token = token; | 
|  | 129         t->context_tree = cpi->common.fc.coef_probs [1] [band] [pt]; | 
| 125 | 130 | 
| 126             t->Extra = vp8_dct_value_tokens_ptr[v].Extra; | 131         t->skip_eob_node = ((pt == 0) && (band > 0)); | 
| 127             x        = vp8_dct_value_tokens_ptr[v].Token; |  | 
| 128         } |  | 
| 129         else |  | 
| 130             x = DCT_EOB_TOKEN; |  | 
| 131 | 132 | 
| 132         t->Token = x; | 133         ++cpi->coef_counts       [1] [band] [pt] [token]; | 
| 133         t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt]; |  | 
| 134 | 134 | 
| 135         t->skip_eob_node = pt == 0 && ((band > 0 && type > 0) || (band > 1 && ty
     pe == 0)); | 135         pt = vp8_prev_token_class[token]; | 
|  | 136         t++; | 
|  | 137     } | 
|  | 138     if (c < 16) | 
|  | 139     { | 
|  | 140         band = vp8_coef_bands[c]; | 
|  | 141         t->Token = DCT_EOB_TOKEN; | 
|  | 142         t->context_tree = cpi->common.fc.coef_probs [1] [band] [pt]; | 
| 136 | 143 | 
| 137         ++cpi->coef_counts       [type] [band] [pt] [x]; | 144         t->skip_eob_node = ((pt == 0) && (band > 0)); | 
|  | 145 | 
|  | 146         ++cpi->coef_counts       [1] [band] [pt] [DCT_EOB_TOKEN]; | 
|  | 147 | 
|  | 148         t++; | 
| 138     } | 149     } | 
| 139     while (pt = vp8_prev_token_class[x], ++t, c < eob  &&  ++c < 16); |  | 
| 140 | 150 | 
| 141     *tp = t; | 151     *tp = t; | 
| 142     pt = (c != !type); /* 0 <-> all coeff data is zero */ | 152     pt = (c != 0); /* 0 <-> all coeff data is zero */ | 
| 143     *a = *l = pt; | 153     *a = *l = pt; | 
| 144 | 154 | 
| 145 } | 155 } | 
| 146 | 156 | 
| 147 static void tokenize1st_order_b | 157 static void tokenize1st_order_b | 
| 148 ( | 158 ( | 
| 149     const BLOCKD *const b, | 159     MACROBLOCKD *x, | 
| 150     TOKENEXTRA **tp, | 160     TOKENEXTRA **tp, | 
| 151     const int type,     /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */ | 161     int type,           /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */ | 
| 152     const FRAME_TYPE frametype, |  | 
| 153     ENTROPY_CONTEXT *a, |  | 
| 154     ENTROPY_CONTEXT *l, |  | 
| 155     VP8_COMP *cpi | 162     VP8_COMP *cpi | 
| 156 ) | 163 ) | 
| 157 { | 164 { | 
| 158     int pt; /* near block/prev token context index */ | 165     unsigned int block; | 
| 159     int c = type ? 0 : 1;       /* start at DC unless type 0 */ | 166     const BLOCKD *b; | 
| 160     const int eob = b->eob;     /* one beyond last nonzero coeff */ | 167     int pt;             /* near block/prev token context index */ | 
| 161     TOKENEXTRA *t = *tp;        /* store tokens starting here */ | 168     int c; | 
| 162     int x; | 169     int token; | 
| 163     const short *qcoeff_ptr = b->qcoeff; | 170     TOKENEXTRA *t = *tp;/* store tokens starting here */ | 
| 164     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 171     const short *qcoeff_ptr; | 
|  | 172     ENTROPY_CONTEXT * a; | 
|  | 173     ENTROPY_CONTEXT * l; | 
|  | 174     int band, rc, v; | 
|  | 175     int tmp1, tmp2; | 
| 165 | 176 | 
| 166     do | 177     b = x->block; | 
|  | 178     /* Luma */ | 
|  | 179     for (block = 0; block < 16; block++, b++) | 
| 167     { | 180     { | 
| 168         const int band = vp8_coef_bands[c]; | 181         tmp1 = vp8_block2above[block]; | 
|  | 182         tmp2 = vp8_block2left[block]; | 
|  | 183         qcoeff_ptr = b->qcoeff; | 
|  | 184         a = (ENTROPY_CONTEXT *)x->above_context + tmp1; | 
|  | 185         l = (ENTROPY_CONTEXT *)x->left_context + tmp2; | 
| 169 | 186 | 
| 170         x = DCT_EOB_TOKEN; | 187         VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 
| 171 | 188 | 
| 172         if (c < eob) | 189         c = type ? 0 : 1; | 
|  | 190 | 
|  | 191         for (; c < b->eob; c++) | 
| 173         { | 192         { | 
| 174             int rc = vp8_default_zig_zag1d[c]; | 193             rc = vp8_default_zig_zag1d[c]; | 
| 175             const int v = qcoeff_ptr[rc]; | 194             band = vp8_coef_bands[c]; | 
| 176 | 195             v = qcoeff_ptr[rc]; | 
| 177             assert(-DCT_MAX_VALUE <= v  &&  v < (DCT_MAX_VALUE)); |  | 
| 178 | 196 | 
| 179             t->Extra = vp8_dct_value_tokens_ptr[v].Extra; | 197             t->Extra = vp8_dct_value_tokens_ptr[v].Extra; | 
| 180             x        = vp8_dct_value_tokens_ptr[v].Token; | 198             token    = vp8_dct_value_tokens_ptr[v].Token; | 
|  | 199 | 
|  | 200             t->Token = token; | 
|  | 201             t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt]; | 
|  | 202 | 
|  | 203             t->skip_eob_node = pt == 0 && | 
|  | 204                 ((band > 0 && type > 0) || (band > 1 && type == 0)); | 
|  | 205 | 
|  | 206             ++cpi->coef_counts       [type] [band] [pt] [token]; | 
|  | 207 | 
|  | 208             pt = vp8_prev_token_class[token]; | 
|  | 209             t++; | 
| 181         } | 210         } | 
|  | 211         if (c < 16) | 
|  | 212         { | 
|  | 213             band = vp8_coef_bands[c]; | 
|  | 214             t->Token = DCT_EOB_TOKEN; | 
|  | 215             t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt]; | 
| 182 | 216 | 
| 183         t->Token = x; | 217             t->skip_eob_node = pt == 0 && | 
| 184         t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt]; | 218                 ((band > 0 && type > 0) || (band > 1 && type == 0)); | 
| 185 | 219 | 
| 186         t->skip_eob_node = pt == 0 && ((band > 0 && type > 0) || (band > 1 && ty
     pe == 0)); | 220             ++cpi->coef_counts       [type] [band] [pt] [DCT_EOB_TOKEN]; | 
| 187 | 221 | 
| 188         ++cpi->coef_counts       [type] [band] [pt] [x]; | 222             t++; | 
|  | 223         } | 
|  | 224         *tp = t; | 
|  | 225         pt = (c != !type); /* 0 <-> all coeff data is zero */ | 
|  | 226         *a = *l = pt; | 
|  | 227 | 
| 189     } | 228     } | 
| 190     while (pt = vp8_prev_token_class[x], ++t, c < eob  &&  ++c < 16); | 229     /* Chroma */ | 
|  | 230     for (block = 16; block < 24; block++, b++) | 
|  | 231     { | 
|  | 232         tmp1 = vp8_block2above[block]; | 
|  | 233         tmp2 = vp8_block2left[block]; | 
|  | 234         qcoeff_ptr = b->qcoeff; | 
|  | 235         a = (ENTROPY_CONTEXT *)x->above_context + tmp1; | 
|  | 236         l = (ENTROPY_CONTEXT *)x->left_context + tmp2; | 
| 191 | 237 | 
| 192     *tp = t; | 238         VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 
| 193     pt = (c != !type); /* 0 <-> all coeff data is zero */ | 239 | 
| 194     *a = *l = pt; | 240         for (c = 0; c < b->eob; c++) | 
|  | 241         { | 
|  | 242             rc = vp8_default_zig_zag1d[c]; | 
|  | 243             band = vp8_coef_bands[c]; | 
|  | 244             v = qcoeff_ptr[rc]; | 
|  | 245 | 
|  | 246             t->Extra = vp8_dct_value_tokens_ptr[v].Extra; | 
|  | 247             token    = vp8_dct_value_tokens_ptr[v].Token; | 
|  | 248 | 
|  | 249             t->Token = token; | 
|  | 250             t->context_tree = cpi->common.fc.coef_probs [2] [band] [pt]; | 
|  | 251 | 
|  | 252             t->skip_eob_node = ((pt == 0) && (band > 0)); | 
|  | 253 | 
|  | 254             ++cpi->coef_counts       [2] [band] [pt] [token]; | 
|  | 255 | 
|  | 256             pt = vp8_prev_token_class[token]; | 
|  | 257             t++; | 
|  | 258         } | 
|  | 259         if (c < 16) | 
|  | 260         { | 
|  | 261             band = vp8_coef_bands[c]; | 
|  | 262             t->Token = DCT_EOB_TOKEN; | 
|  | 263             t->context_tree = cpi->common.fc.coef_probs [2] [band] [pt]; | 
|  | 264 | 
|  | 265             t->skip_eob_node = ((pt == 0) && (band > 0)); | 
|  | 266 | 
|  | 267             ++cpi->coef_counts       [2] [band] [pt] [DCT_EOB_TOKEN]; | 
|  | 268 | 
|  | 269             t++; | 
|  | 270         } | 
|  | 271         *tp = t; | 
|  | 272         pt = (c != 0); /* 0 <-> all coeff data is zero */ | 
|  | 273         *a = *l = pt; | 
|  | 274     } | 
| 195 | 275 | 
| 196 } | 276 } | 
| 197 | 277 | 
| 198 | 278 | 
| 199 static int mb_is_skippable(MACROBLOCKD *x) | 279 static int mb_is_skippable(MACROBLOCKD *x, int has_y2_block) | 
| 200 { | 280 { | 
| 201     int has_y2_block; |  | 
| 202     int skip = 1; | 281     int skip = 1; | 
| 203     int i = 0; | 282     int i = 0; | 
| 204 | 283 | 
| 205     has_y2_block = (x->mode_info_context->mbmi.mode != B_PRED |  | 
| 206                     && x->mode_info_context->mbmi.mode != SPLITMV); |  | 
| 207     if (has_y2_block) | 284     if (has_y2_block) | 
| 208     { | 285     { | 
| 209         for (i = 0; i < 16; i++) | 286         for (i = 0; i < 16; i++) | 
| 210             skip &= (x->block[i].eob < 2); | 287             skip &= (x->block[i].eob < 2); | 
| 211     } | 288     } | 
| 212 | 289 | 
| 213     for (; i < 24 + has_y2_block; i++) | 290     for (; i < 24 + has_y2_block; i++) | 
| 214         skip &= (!x->block[i].eob); | 291         skip &= (!x->block[i].eob); | 
| 215 | 292 | 
| 216     return skip; | 293     return skip; | 
| 217 } | 294 } | 
| 218 | 295 | 
| 219 | 296 | 
| 220 void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) | 297 void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) | 
| 221 { | 298 { | 
| 222     ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)x->above_context; |  | 
| 223     ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)x->left_context; |  | 
| 224     int plane_type; | 299     int plane_type; | 
| 225     int b; | 300     int has_y2_block; | 
| 226 | 301 | 
| 227     TOKENEXTRA *start = *t; | 302     has_y2_block = (x->mode_info_context->mbmi.mode != B_PRED | 
| 228     TOKENEXTRA *tp = *t; | 303                     && x->mode_info_context->mbmi.mode != SPLITMV); | 
| 229 | 304 | 
| 230     x->mode_info_context->mbmi.dc_diff = 1; | 305     x->mode_info_context->mbmi.mb_skip_coeff = mb_is_skippable(x, has_y2_block); | 
| 231 |  | 
| 232 #if 0 |  | 
| 233 |  | 
| 234     if (x->mbmi.force_no_skip) |  | 
| 235     { |  | 
| 236         x->mbmi.mb_skip_coeff = 1; |  | 
| 237         //reset for next_mb. |  | 
| 238         x->mbmi.force_no_skip = 0; |  | 
| 239     } |  | 
| 240 |  | 
| 241 #endif |  | 
| 242 |  | 
| 243 #if 1 |  | 
| 244 |  | 
| 245     x->mode_info_context->mbmi.mb_skip_coeff = mb_is_skippable(x); |  | 
| 246     if (x->mode_info_context->mbmi.mb_skip_coeff) | 306     if (x->mode_info_context->mbmi.mb_skip_coeff) | 
| 247     { | 307     { | 
| 248 |  | 
| 249         cpi->skip_true_count++; | 308         cpi->skip_true_count++; | 
| 250 | 309 | 
| 251         if (!cpi->common.mb_no_coeff_skip) | 310         if (!cpi->common.mb_no_coeff_skip) | 
| 252             vp8_stuff_mb(cpi, x, t) ; | 311             vp8_stuff_mb(cpi, x, t) ; | 
| 253         else | 312         else | 
| 254         { | 313         { | 
| 255             vp8_fix_contexts(x); | 314             vp8_fix_contexts(x); | 
| 256         } | 315         } | 
| 257 | 316 | 
| 258         if (x->mode_info_context->mbmi.mode != B_PRED && x->mode_info_context->m
     bmi.mode != SPLITMV) |  | 
| 259             x->mode_info_context->mbmi.dc_diff = 0; |  | 
| 260         else |  | 
| 261             x->mode_info_context->mbmi.dc_diff = 1; |  | 
| 262 |  | 
| 263 |  | 
| 264         return; | 317         return; | 
| 265     } | 318     } | 
| 266 | 319 | 
| 267     cpi->skip_false_count++; | 320     cpi->skip_false_count++; | 
| 268 #endif |  | 
| 269 #if 0 |  | 
| 270     vpx_memcpy(cpi->coef_counts_backup, cpi->coef_counts, sizeof(cpi->coef_count
     s)); |  | 
| 271 #endif |  | 
| 272 | 321 | 
| 273     if (x->mode_info_context->mbmi.mode == B_PRED || x->mode_info_context->mbmi.
     mode == SPLITMV) | 322     plane_type = 3; | 
|  | 323     if(has_y2_block) | 
| 274     { | 324     { | 
| 275         plane_type = 3; | 325         tokenize2nd_order_b(x, t, cpi); | 
| 276     } |  | 
| 277     else |  | 
| 278     { |  | 
| 279         tokenize2nd_order_b(x->block + 24, t, 1, x->frame_type, |  | 
| 280                    A + vp8_block2above[24], L + vp8_block2left[24], cpi); |  | 
| 281         plane_type = 0; | 326         plane_type = 0; | 
| 282 | 327 | 
| 283     } | 328     } | 
| 284 | 329 | 
| 285     for (b = 0; b < 16; b++) | 330     tokenize1st_order_b(x, t, plane_type, cpi); | 
| 286         tokenize1st_order_b(x->block + b, t, plane_type, x->frame_type, |  | 
| 287                             A + vp8_block2above[b], |  | 
| 288                             L + vp8_block2left[b], cpi); |  | 
| 289 | 331 | 
| 290     for (b = 16; b < 24; b++) |  | 
| 291         tokenize1st_order_b(x->block + b, t, 2, x->frame_type, |  | 
| 292                             A + vp8_block2above[b], |  | 
| 293                             L + vp8_block2left[b], cpi); |  | 
| 294 |  | 
| 295 #if 0 |  | 
| 296 |  | 
| 297     if (cpi->common.mb_no_coeff_skip) |  | 
| 298     { |  | 
| 299         int skip = 1; |  | 
| 300 |  | 
| 301         while ((tp != *t) && skip) |  | 
| 302         { |  | 
| 303             skip = (skip && (tp->Token == DCT_EOB_TOKEN)); |  | 
| 304             tp ++; |  | 
| 305         } |  | 
| 306 |  | 
| 307         if (skip != x->mbmi.mb_skip_coeff) |  | 
| 308             skip += 0; |  | 
| 309 |  | 
| 310         x->mbmi.mb_skip_coeff = skip; |  | 
| 311 |  | 
| 312         if (x->mbmi.mb_skip_coeff == 1) |  | 
| 313         { |  | 
| 314             x->mbmi.dc_diff = 0; |  | 
| 315             //redo the coutnts |  | 
| 316             vpx_memcpy(cpi->coef_counts, cpi->coef_counts_backup, sizeof(cpi->co
     ef_counts)); |  | 
| 317 |  | 
| 318             *t = start; |  | 
| 319             cpi->skip_true_count++; |  | 
| 320             //skip_true_count++; |  | 
| 321         } |  | 
| 322         else |  | 
| 323         { |  | 
| 324 |  | 
| 325             cpi->skip_false_count++; |  | 
| 326             //skip_false_count++; |  | 
| 327         } |  | 
| 328     } |  | 
| 329 |  | 
| 330 #endif |  | 
| 331 } | 332 } | 
| 332 | 333 | 
| 333 | 334 | 
| 334 #ifdef ENTROPY_STATS | 335 #ifdef ENTROPY_STATS | 
| 335 | 336 | 
| 336 void init_context_counters(void) | 337 void init_context_counters(void) | 
| 337 { | 338 { | 
| 338     vpx_memset(context_counters, 0, sizeof(context_counters)); | 339     vpx_memset(context_counters, 0, sizeof(context_counters)); | 
| 339 } | 340 } | 
| 340 | 341 | 
| 341 void print_context_counters() | 342 void print_context_counters() | 
| 342 { | 343 { | 
| 343 | 344 | 
| 344     int type, band, pt, t; | 345     int type, band, pt, t; | 
| 345 | 346 | 
| 346     FILE *const f = fopen("context.c", "w"); | 347     FILE *const f = fopen("context.c", "w"); | 
| 347 | 348 | 
| 348     fprintf(f, "#include \"entropy.h\"\n"); | 349     fprintf(f, "#include \"entropy.h\"\n"); | 
| 349 | 350 | 
| 350     fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n"); | 351     fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n"); | 
| 351 | 352 | 
| 352     fprintf(f, "int Contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8
     _coef_tokens];\n\n"); | 353     fprintf(f, "int Contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX
     _ENTROPY_TOKENS];\n\n"); | 
| 353 | 354 | 
| 354     fprintf(f, "const int default_contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_
     CONTEXTS] [vp8_coef_tokens] = {"); | 355     fprintf(f, "const int default_contexts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_
     CONTEXTS] [MAX_ENTROPY_TOKENS] = {"); | 
| 355 | 356 | 
| 356 # define Comma( X) (X? ",":"") | 357 # define Comma( X) (X? ",":"") | 
| 357 | 358 | 
| 358     type = 0; | 359     type = 0; | 
| 359 | 360 | 
| 360     do | 361     do | 
| 361     { | 362     { | 
| 362         fprintf(f, "%s\n  { /* block Type %d */", Comma(type), type); | 363         fprintf(f, "%s\n  { /* block Type %d */", Comma(type), type); | 
| 363 | 364 | 
| 364         band = 0; | 365         band = 0; | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 377 | 378 | 
| 378                 do | 379                 do | 
| 379                 { | 380                 { | 
| 380                     const _int64 x = context_counters [type] [band] [pt] [t]; | 381                     const _int64 x = context_counters [type] [band] [pt] [t]; | 
| 381                     const int y = (int) x; | 382                     const int y = (int) x; | 
| 382 | 383 | 
| 383                     assert(x == (_int64) y);  /* no overflow handling yet */ | 384                     assert(x == (_int64) y);  /* no overflow handling yet */ | 
| 384                     fprintf(f, "%s %d", Comma(t), y); | 385                     fprintf(f, "%s %d", Comma(t), y); | 
| 385 | 386 | 
| 386                 } | 387                 } | 
| 387                 while (++t < vp8_coef_tokens); | 388                 while (++t < MAX_ENTROPY_TOKENS); | 
| 388 | 389 | 
| 389                 fprintf(f, "}"); | 390                 fprintf(f, "}"); | 
| 390             } | 391             } | 
| 391             while (++pt < PREV_COEF_CONTEXTS); | 392             while (++pt < PREV_COEF_CONTEXTS); | 
| 392 | 393 | 
| 393             fprintf(f, "\n    }"); | 394             fprintf(f, "\n    }"); | 
| 394 | 395 | 
| 395         } | 396         } | 
| 396         while (++band < COEF_BANDS); | 397         while (++band < COEF_BANDS); | 
| 397 | 398 | 
| 398         fprintf(f, "\n  }"); | 399         fprintf(f, "\n  }"); | 
| 399     } | 400     } | 
| 400     while (++type < BLOCK_TYPES); | 401     while (++type < BLOCK_TYPES); | 
| 401 | 402 | 
| 402     fprintf(f, "\n};\n"); | 403     fprintf(f, "\n};\n"); | 
| 403     fclose(f); | 404     fclose(f); | 
| 404 } | 405 } | 
| 405 #endif | 406 #endif | 
| 406 | 407 | 
| 407 | 408 | 
| 408 void vp8_tokenize_initialize() | 409 void vp8_tokenize_initialize() | 
| 409 { | 410 { | 
| 410     fill_value_tokens(); | 411     fill_value_tokens(); | 
| 411 } | 412 } | 
| 412 | 413 | 
| 413 | 414 | 
| 414 static __inline void stuff2nd_order_b | 415 static __inline void stuff2nd_order_b | 
| 415 ( | 416 ( | 
| 416     const BLOCKD *const b, |  | 
| 417     TOKENEXTRA **tp, | 417     TOKENEXTRA **tp, | 
| 418     const int type,     /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */ |  | 
| 419     const FRAME_TYPE frametype, |  | 
| 420     ENTROPY_CONTEXT *a, | 418     ENTROPY_CONTEXT *a, | 
| 421     ENTROPY_CONTEXT *l, | 419     ENTROPY_CONTEXT *l, | 
| 422     VP8_COMP *cpi | 420     VP8_COMP *cpi | 
| 423 ) | 421 ) | 
| 424 { | 422 { | 
| 425     int pt; /* near block/prev token context index */ | 423     int pt; /* near block/prev token context index */ | 
| 426     TOKENEXTRA *t = *tp;        /* store tokens starting here */ | 424     TOKENEXTRA *t = *tp;        /* store tokens starting here */ | 
| 427     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 425     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 
| 428     (void) frametype; |  | 
| 429     (void) type; |  | 
| 430     (void) b; |  | 
| 431 | 426 | 
| 432     t->Token = DCT_EOB_TOKEN; | 427     t->Token = DCT_EOB_TOKEN; | 
| 433     t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt]; | 428     t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt]; | 
| 434     t->skip_eob_node = 0; | 429     t->skip_eob_node = 0; | 
| 435     ++cpi->coef_counts       [1] [0] [pt] [DCT_EOB_TOKEN]; | 430     ++cpi->coef_counts       [1] [0] [pt] [DCT_EOB_TOKEN]; | 
| 436     ++t; | 431     ++t; | 
| 437 | 432 | 
| 438     *tp = t; | 433     *tp = t; | 
| 439     pt = 0; | 434     pt = 0; | 
| 440     *a = *l = pt; | 435     *a = *l = pt; | 
| 441 | 436 | 
| 442 } | 437 } | 
| 443 | 438 | 
| 444 static __inline void stuff1st_order_b | 439 static __inline void stuff1st_order_b | 
| 445 ( | 440 ( | 
| 446     const BLOCKD *const b, |  | 
| 447     TOKENEXTRA **tp, | 441     TOKENEXTRA **tp, | 
| 448     const int type,     /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */ |  | 
| 449     const FRAME_TYPE frametype, |  | 
| 450     ENTROPY_CONTEXT *a, | 442     ENTROPY_CONTEXT *a, | 
| 451     ENTROPY_CONTEXT *l, | 443     ENTROPY_CONTEXT *l, | 
| 452     VP8_COMP *cpi | 444     VP8_COMP *cpi | 
| 453 ) | 445 ) | 
| 454 { | 446 { | 
| 455     int pt; /* near block/prev token context index */ | 447     int pt; /* near block/prev token context index */ | 
| 456     TOKENEXTRA *t = *tp;        /* store tokens starting here */ | 448     TOKENEXTRA *t = *tp;        /* store tokens starting here */ | 
| 457     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 449     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 
| 458     (void) frametype; |  | 
| 459     (void) type; |  | 
| 460     (void) b; |  | 
| 461 | 450 | 
| 462     t->Token = DCT_EOB_TOKEN; | 451     t->Token = DCT_EOB_TOKEN; | 
| 463     t->context_tree = cpi->common.fc.coef_probs [0] [1] [pt]; | 452     t->context_tree = cpi->common.fc.coef_probs [0] [1] [pt]; | 
| 464     t->skip_eob_node = 0; | 453     t->skip_eob_node = 0; | 
| 465     ++cpi->coef_counts       [0] [1] [pt] [DCT_EOB_TOKEN]; | 454     ++cpi->coef_counts       [0] [1] [pt] [DCT_EOB_TOKEN]; | 
| 466     ++t; | 455     ++t; | 
| 467     *tp = t; | 456     *tp = t; | 
| 468     pt = 0; /* 0 <-> all coeff data is zero */ | 457     pt = 0; /* 0 <-> all coeff data is zero */ | 
| 469     *a = *l = pt; | 458     *a = *l = pt; | 
| 470 | 459 | 
| 471 } | 460 } | 
| 472 static __inline | 461 static __inline | 
| 473 void stuff1st_order_buv | 462 void stuff1st_order_buv | 
| 474 ( | 463 ( | 
| 475     const BLOCKD *const b, |  | 
| 476     TOKENEXTRA **tp, | 464     TOKENEXTRA **tp, | 
| 477     const int type,     /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */ |  | 
| 478     const FRAME_TYPE frametype, |  | 
| 479     ENTROPY_CONTEXT *a, | 465     ENTROPY_CONTEXT *a, | 
| 480     ENTROPY_CONTEXT *l, | 466     ENTROPY_CONTEXT *l, | 
| 481     VP8_COMP *cpi | 467     VP8_COMP *cpi | 
| 482 ) | 468 ) | 
| 483 { | 469 { | 
| 484     int pt; /* near block/prev token context index */ | 470     int pt; /* near block/prev token context index */ | 
| 485     TOKENEXTRA *t = *tp;        /* store tokens starting here */ | 471     TOKENEXTRA *t = *tp;        /* store tokens starting here */ | 
| 486     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 472     VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); | 
| 487     (void) frametype; |  | 
| 488     (void) type; |  | 
| 489     (void) b; |  | 
| 490 | 473 | 
| 491     t->Token = DCT_EOB_TOKEN; | 474     t->Token = DCT_EOB_TOKEN; | 
| 492     t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt]; | 475     t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt]; | 
| 493     t->skip_eob_node = 0; | 476     t->skip_eob_node = 0; | 
| 494     ++cpi->coef_counts[2] [0] [pt] [DCT_EOB_TOKEN]; | 477     ++cpi->coef_counts[2] [0] [pt] [DCT_EOB_TOKEN]; | 
| 495     ++t; | 478     ++t; | 
| 496     *tp = t; | 479     *tp = t; | 
| 497     pt = 0; /* 0 <-> all coeff data is zero */ | 480     pt = 0; /* 0 <-> all coeff data is zero */ | 
| 498     *a = *l = pt; | 481     *a = *l = pt; | 
| 499 | 482 | 
| 500 } | 483 } | 
| 501 | 484 | 
| 502 void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) | 485 void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) | 
| 503 { | 486 { | 
| 504     ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)x->above_context; | 487     ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)x->above_context; | 
| 505     ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)x->left_context; | 488     ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)x->left_context; | 
| 506     int plane_type; | 489     int plane_type; | 
| 507     int b; | 490     int b; | 
| 508 | 491 | 
| 509     stuff2nd_order_b(x->block + 24, t, 1, x->frame_type, | 492     stuff2nd_order_b(t, | 
| 510                      A + vp8_block2above[24], L + vp8_block2left[24], cpi); | 493                      A + vp8_block2above[24], L + vp8_block2left[24], cpi); | 
| 511     plane_type = 0; | 494     plane_type = 0; | 
| 512 | 495 | 
| 513 |  | 
| 514     if (x->mode_info_context->mbmi.mode != B_PRED && x->mode_info_context->mbmi.
     mode != SPLITMV) |  | 
| 515         x->mode_info_context->mbmi.dc_diff = 0; |  | 
| 516     else |  | 
| 517         x->mode_info_context->mbmi.dc_diff = 1; |  | 
| 518 |  | 
| 519 |  | 
| 520     for (b = 0; b < 16; b++) | 496     for (b = 0; b < 16; b++) | 
| 521         stuff1st_order_b(x->block + b, t, plane_type, x->frame_type, | 497         stuff1st_order_b(t, | 
| 522                          A + vp8_block2above[b], | 498                          A + vp8_block2above[b], | 
| 523                          L + vp8_block2left[b], cpi); | 499                          L + vp8_block2left[b], cpi); | 
| 524 | 500 | 
| 525     for (b = 16; b < 24; b++) | 501     for (b = 16; b < 24; b++) | 
| 526         stuff1st_order_buv(x->block + b, t, 2, x->frame_type, | 502         stuff1st_order_buv(t, | 
| 527                            A + vp8_block2above[b], | 503                            A + vp8_block2above[b], | 
| 528                            L + vp8_block2left[b], cpi); | 504                            L + vp8_block2left[b], cpi); | 
| 529 | 505 | 
| 530 } | 506 } | 
| 531 void vp8_fix_contexts(MACROBLOCKD *x) | 507 void vp8_fix_contexts(MACROBLOCKD *x) | 
| 532 { | 508 { | 
| 533     /* Clear entropy contexts for Y2 blocks */ | 509     /* Clear entropy contexts for Y2 blocks */ | 
| 534     if (x->mode_info_context->mbmi.mode != B_PRED && x->mode_info_context->mbmi.
     mode != SPLITMV) | 510     if (x->mode_info_context->mbmi.mode != B_PRED && x->mode_info_context->mbmi.
     mode != SPLITMV) | 
| 535     { | 511     { | 
| 536         vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)); | 512         vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)); | 
| 537         vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)); | 513         vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)); | 
| 538     } | 514     } | 
| 539     else | 515     else | 
| 540     { | 516     { | 
| 541         vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1); | 517         vpx_memset(x->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1); | 
| 542         vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1); | 518         vpx_memset(x->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES)-1); | 
| 543     } | 519     } | 
| 544 | 520 | 
| 545 } | 521 } | 
| OLD | NEW | 
|---|