OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 |
| 12 #ifndef VP9_COMMON_VP9_BLOCKD_H_ |
| 13 #define VP9_COMMON_VP9_BLOCKD_H_ |
| 14 |
| 15 void vpx_log(const char *format, ...); |
| 16 |
| 17 #include "vpx_ports/config.h" |
| 18 #include "vpx_scale/yv12config.h" |
| 19 #include "vp9/common/vp9_mv.h" |
| 20 #include "vp9/common/vp9_treecoder.h" |
| 21 #include "vp9/common/vp9_subpixel.h" |
| 22 #include "vpx_ports/mem.h" |
| 23 #include "vp9/common/vp9_common.h" |
| 24 |
| 25 #define TRUE 1 |
| 26 #define FALSE 0 |
| 27 |
| 28 // #define MODE_STATS |
| 29 |
| 30 /*#define DCPRED 1*/ |
| 31 #define DCPREDSIMTHRESH 0 |
| 32 #define DCPREDCNTTHRESH 3 |
| 33 |
| 34 #define MB_FEATURE_TREE_PROBS 3 |
| 35 #define PREDICTION_PROBS 3 |
| 36 |
| 37 #define MBSKIP_CONTEXTS 3 |
| 38 |
| 39 #define MAX_MB_SEGMENTS 4 |
| 40 |
| 41 #define MAX_REF_LF_DELTAS 4 |
| 42 #define MAX_MODE_LF_DELTAS 4 |
| 43 |
| 44 /* Segment Feature Masks */ |
| 45 #define SEGMENT_DELTADATA 0 |
| 46 #define SEGMENT_ABSDATA 1 |
| 47 #define MAX_MV_REFS 9 |
| 48 |
| 49 typedef struct { |
| 50 int r, c; |
| 51 } POS; |
| 52 |
| 53 typedef enum PlaneType { |
| 54 PLANE_TYPE_Y_NO_DC = 0, |
| 55 PLANE_TYPE_Y2, |
| 56 PLANE_TYPE_UV, |
| 57 PLANE_TYPE_Y_WITH_DC, |
| 58 } PLANE_TYPE; |
| 59 |
| 60 typedef char ENTROPY_CONTEXT; |
| 61 typedef struct { |
| 62 ENTROPY_CONTEXT y1[4]; |
| 63 ENTROPY_CONTEXT u[2]; |
| 64 ENTROPY_CONTEXT v[2]; |
| 65 ENTROPY_CONTEXT y2; |
| 66 } ENTROPY_CONTEXT_PLANES; |
| 67 |
| 68 extern const unsigned char vp9_block2left[25]; |
| 69 extern const unsigned char vp9_block2above[25]; |
| 70 extern const unsigned char vp9_block2left_8x8[25]; |
| 71 extern const unsigned char vp9_block2above_8x8[25]; |
| 72 |
| 73 #define VP9_COMBINEENTROPYCONTEXTS( Dest, A, B) \ |
| 74 Dest = ((A)!=0) + ((B)!=0); |
| 75 |
| 76 typedef enum { |
| 77 KEY_FRAME = 0, |
| 78 INTER_FRAME = 1 |
| 79 } FRAME_TYPE; |
| 80 |
| 81 typedef enum |
| 82 { |
| 83 SIXTAP = 0, |
| 84 BILINEAR = 1, |
| 85 EIGHTTAP = 2, |
| 86 EIGHTTAP_SHARP = 3, |
| 87 SWITCHABLE /* should be the last one */ |
| 88 } INTERPOLATIONFILTERTYPE; |
| 89 |
| 90 typedef enum |
| 91 { |
| 92 DC_PRED, /* average of above and left pixels */ |
| 93 V_PRED, /* vertical prediction */ |
| 94 H_PRED, /* horizontal prediction */ |
| 95 D45_PRED, /* Directional 45 deg prediction [anti-clockwise from 0 d
eg hor] */ |
| 96 D135_PRED, /* Directional 135 deg prediction [anti-clockwise from 0 d
eg hor] */ |
| 97 D117_PRED, /* Directional 112 deg prediction [anti-clockwise from 0 d
eg hor] */ |
| 98 D153_PRED, /* Directional 157 deg prediction [anti-clockwise from 0 d
eg hor] */ |
| 99 D27_PRED, /* Directional 22 deg prediction [anti-clockwise from 0 d
eg hor] */ |
| 100 D63_PRED, /* Directional 67 deg prediction [anti-clockwise from 0 d
eg hor] */ |
| 101 TM_PRED, /* Truemotion prediction */ |
| 102 I8X8_PRED, /* 8x8 based prediction, each 8x8 has its own prediction m
ode */ |
| 103 B_PRED, /* block based prediction, each block has its own predicti
on mode */ |
| 104 |
| 105 NEARESTMV, |
| 106 NEARMV, |
| 107 ZEROMV, |
| 108 NEWMV, |
| 109 SPLITMV, |
| 110 |
| 111 MB_MODE_COUNT |
| 112 } MB_PREDICTION_MODE; |
| 113 |
| 114 // Segment level features. |
| 115 typedef enum { |
| 116 SEG_LVL_ALT_Q = 0, // Use alternate Quantizer .... |
| 117 SEG_LVL_ALT_LF = 1, // Use alternate loop filter value... |
| 118 SEG_LVL_REF_FRAME = 2, // Optional Segment reference frame |
| 119 SEG_LVL_MODE = 3, // Optional Segment mode |
| 120 SEG_LVL_EOB = 4, // EOB end stop marker. |
| 121 SEG_LVL_TRANSFORM = 5, // Block transform size. |
| 122 SEG_LVL_MAX = 6 // Number of MB level features supported |
| 123 |
| 124 } SEG_LVL_FEATURES; |
| 125 |
| 126 // Segment level features. |
| 127 typedef enum { |
| 128 TX_4X4, // 4x4 dct transform |
| 129 TX_8X8, // 8x8 dct transform |
| 130 TX_16X16, // 16x16 dct transform |
| 131 TX_SIZE_MAX // Number of different transforms available |
| 132 } TX_SIZE; |
| 133 |
| 134 typedef enum { |
| 135 DCT_DCT = 0, // DCT in both horizontal and vertical |
| 136 ADST_DCT = 1, // ADST in vertical, DCT in horizontal |
| 137 DCT_ADST = 2, // DCT in vertical, ADST in horizontal |
| 138 ADST_ADST = 3 // ADST in both directions |
| 139 } TX_TYPE; |
| 140 |
| 141 #define VP9_YMODES (B_PRED + 1) |
| 142 #define VP9_UV_MODES (TM_PRED + 1) |
| 143 #define VP9_I8X8_MODES (TM_PRED + 1) |
| 144 #define VP9_I32X32_MODES (TM_PRED + 1) |
| 145 |
| 146 #define VP9_MVREFS (1 + SPLITMV - NEARESTMV) |
| 147 |
| 148 #if CONFIG_LOSSLESS |
| 149 #define WHT_UPSCALE_FACTOR 3 |
| 150 #define Y2_WHT_UPSCALE_FACTOR 2 |
| 151 #endif |
| 152 |
| 153 typedef enum { |
| 154 B_DC_PRED, /* average of above and left pixels */ |
| 155 B_TM_PRED, |
| 156 |
| 157 B_VE_PRED, /* vertical prediction */ |
| 158 B_HE_PRED, /* horizontal prediction */ |
| 159 |
| 160 B_LD_PRED, |
| 161 B_RD_PRED, |
| 162 |
| 163 B_VR_PRED, |
| 164 B_VL_PRED, |
| 165 B_HD_PRED, |
| 166 B_HU_PRED, |
| 167 #if CONFIG_NEWBINTRAMODES |
| 168 B_CONTEXT_PRED, |
| 169 #endif |
| 170 |
| 171 LEFT4X4, |
| 172 ABOVE4X4, |
| 173 ZERO4X4, |
| 174 NEW4X4, |
| 175 |
| 176 B_MODE_COUNT |
| 177 } B_PREDICTION_MODE; |
| 178 |
| 179 #define VP9_BINTRAMODES (LEFT4X4) |
| 180 #define VP9_SUBMVREFS (1 + NEW4X4 - LEFT4X4) |
| 181 |
| 182 #if CONFIG_NEWBINTRAMODES |
| 183 /* The number of B_PRED intra modes that are replaced by B_CONTEXT_PRED */ |
| 184 #define CONTEXT_PRED_REPLACEMENTS 0 |
| 185 #define VP9_KF_BINTRAMODES (VP9_BINTRAMODES - 1) |
| 186 #define VP9_NKF_BINTRAMODES (VP9_BINTRAMODES - CONTEXT_PRED_REPLACEMENTS) |
| 187 #else |
| 188 #define VP9_KF_BINTRAMODES (VP9_BINTRAMODES) /* 10 */ |
| 189 #define VP9_NKF_BINTRAMODES (VP9_BINTRAMODES) /* 10 */ |
| 190 #endif |
| 191 |
| 192 typedef enum { |
| 193 PARTITIONING_16X8 = 0, |
| 194 PARTITIONING_8X16, |
| 195 PARTITIONING_8X8, |
| 196 PARTITIONING_4X4, |
| 197 NB_PARTITIONINGS, |
| 198 } SPLITMV_PARTITIONING_TYPE; |
| 199 |
| 200 /* For keyframes, intra block modes are predicted by the (already decoded) |
| 201 modes for the Y blocks to the left and above us; for interframes, there |
| 202 is a single probability table. */ |
| 203 |
| 204 union b_mode_info { |
| 205 struct { |
| 206 B_PREDICTION_MODE first; |
| 207 TX_TYPE tx_type; |
| 208 #if CONFIG_COMP_INTRA_PRED |
| 209 B_PREDICTION_MODE second; |
| 210 #endif |
| 211 #if CONFIG_NEWBINTRAMODES |
| 212 B_PREDICTION_MODE context; |
| 213 #endif |
| 214 } as_mode; |
| 215 struct { |
| 216 int_mv first; |
| 217 int_mv second; |
| 218 } as_mv; |
| 219 }; |
| 220 |
| 221 typedef enum { |
| 222 NONE = -1, |
| 223 INTRA_FRAME = 0, |
| 224 LAST_FRAME = 1, |
| 225 GOLDEN_FRAME = 2, |
| 226 ALTREF_FRAME = 3, |
| 227 MAX_REF_FRAMES = 4 |
| 228 } MV_REFERENCE_FRAME; |
| 229 |
| 230 typedef struct { |
| 231 MB_PREDICTION_MODE mode, uv_mode; |
| 232 #if CONFIG_COMP_INTRA_PRED |
| 233 MB_PREDICTION_MODE second_mode, second_uv_mode; |
| 234 #endif |
| 235 #if CONFIG_COMP_INTERINTRA_PRED |
| 236 MB_PREDICTION_MODE interintra_mode, interintra_uv_mode; |
| 237 #endif |
| 238 MV_REFERENCE_FRAME ref_frame, second_ref_frame; |
| 239 TX_SIZE txfm_size; |
| 240 int_mv mv[2]; // for each reference frame used |
| 241 int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REFS]; |
| 242 int_mv best_mv, best_second_mv; |
| 243 #if CONFIG_NEW_MVREF |
| 244 int best_index, best_second_index; |
| 245 #endif |
| 246 |
| 247 int mb_mode_context[MAX_REF_FRAMES]; |
| 248 |
| 249 SPLITMV_PARTITIONING_TYPE partitioning; |
| 250 unsigned char mb_skip_coeff; /* does this mb ha
s coefficients at all, 1=no coefficients, 0=need decode tokens */ |
| 251 unsigned char need_to_clamp_mvs; |
| 252 unsigned char need_to_clamp_secondmv; |
| 253 unsigned char segment_id; /* Which set of segmentation parame
ters should be used for this MB */ |
| 254 |
| 255 // Flags used for prediction status of various bistream signals |
| 256 unsigned char seg_id_predicted; |
| 257 unsigned char ref_predicted; |
| 258 |
| 259 // Indicates if the mb is part of the image (1) vs border (0) |
| 260 // This can be useful in determining whether the MB provides |
| 261 // a valid predictor |
| 262 unsigned char mb_in_image; |
| 263 |
| 264 #if CONFIG_PRED_FILTER |
| 265 // Flag to turn prediction signal filter on(1)/off(0 ) at the MB level |
| 266 unsigned int pred_filter_enabled; |
| 267 #endif |
| 268 INTERPOLATIONFILTERTYPE interp_filter; |
| 269 |
| 270 #if CONFIG_SUPERBLOCKS |
| 271 // FIXME need a SB array of 4 MB_MODE_INFOs that |
| 272 // only needs one encoded_as_sb. |
| 273 unsigned char encoded_as_sb; |
| 274 #endif |
| 275 } MB_MODE_INFO; |
| 276 |
| 277 typedef struct { |
| 278 MB_MODE_INFO mbmi; |
| 279 union b_mode_info bmi[16]; |
| 280 } MODE_INFO; |
| 281 |
| 282 typedef struct blockd { |
| 283 short *qcoeff; |
| 284 short *dqcoeff; |
| 285 unsigned char *predictor; |
| 286 short *diff; |
| 287 short *dequant; |
| 288 |
| 289 /* 16 Y blocks, 4 U blocks, 4 V blocks each with 16 entries */ |
| 290 unsigned char **base_pre; |
| 291 unsigned char **base_second_pre; |
| 292 int pre; |
| 293 int pre_stride; |
| 294 |
| 295 unsigned char **base_dst; |
| 296 int dst; |
| 297 int dst_stride; |
| 298 |
| 299 int eob; |
| 300 |
| 301 union b_mode_info bmi; |
| 302 } BLOCKD; |
| 303 |
| 304 typedef struct macroblockd { |
| 305 DECLARE_ALIGNED(16, short, diff[400]); /* from idct diff */ |
| 306 DECLARE_ALIGNED(16, unsigned char, predictor[384]); |
| 307 DECLARE_ALIGNED(16, short, qcoeff[400]); |
| 308 DECLARE_ALIGNED(16, short, dqcoeff[400]); |
| 309 DECLARE_ALIGNED(16, unsigned short, eobs[25]); |
| 310 |
| 311 /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */ |
| 312 BLOCKD block[25]; |
| 313 int fullpixel_mask; |
| 314 |
| 315 YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */ |
| 316 struct { |
| 317 uint8_t *y_buffer, *u_buffer, *v_buffer; |
| 318 } second_pre; |
| 319 YV12_BUFFER_CONFIG dst; |
| 320 |
| 321 MODE_INFO *prev_mode_info_context; |
| 322 MODE_INFO *mode_info_context; |
| 323 int mode_info_stride; |
| 324 |
| 325 FRAME_TYPE frame_type; |
| 326 |
| 327 int up_available; |
| 328 int left_available; |
| 329 |
| 330 /* Y,U,V,Y2 */ |
| 331 ENTROPY_CONTEXT_PLANES *above_context; |
| 332 ENTROPY_CONTEXT_PLANES *left_context; |
| 333 |
| 334 /* 0 indicates segmentation at MB level is not enabled. Otherwise the individu
al bits indicate which features are active. */ |
| 335 unsigned char segmentation_enabled; |
| 336 |
| 337 /* 0 (do not update) 1 (update) the macroblock segmentation map. */ |
| 338 unsigned char update_mb_segmentation_map; |
| 339 |
| 340 /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */ |
| 341 unsigned char update_mb_segmentation_data; |
| 342 |
| 343 /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */ |
| 344 unsigned char mb_segment_abs_delta; |
| 345 |
| 346 /* Per frame flags that define which MB level features (such as quantizer or l
oop filter level) */ |
| 347 /* are enabled and when enabled the proabilities used to decode the per MB fla
gs in MB_MODE_INFO */ |
| 348 |
| 349 // Probability Tree used to code Segment number |
| 350 vp9_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS]; |
| 351 |
| 352 #if CONFIG_NEW_MVREF |
| 353 vp9_prob mb_mv_ref_id_probs[MAX_REF_FRAMES][3]; |
| 354 #endif |
| 355 |
| 356 // Segment features |
| 357 signed char segment_feature_data[MAX_MB_SEGMENTS][SEG_LVL_MAX]; |
| 358 unsigned int segment_feature_mask[MAX_MB_SEGMENTS]; |
| 359 |
| 360 /* mode_based Loop filter adjustment */ |
| 361 unsigned char mode_ref_lf_delta_enabled; |
| 362 unsigned char mode_ref_lf_delta_update; |
| 363 |
| 364 /* Delta values have the range +/- MAX_LOOP_FILTER */ |
| 365 signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra
, Last, GF, ARF */ |
| 366 signed char ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra
, Last, GF, ARF */ |
| 367 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED
, ZERO_MV, MV, SPLIT */ |
| 368 signed char mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED
, ZERO_MV, MV, SPLIT */ |
| 369 |
| 370 /* Distance of MB away from frame edges */ |
| 371 int mb_to_left_edge; |
| 372 int mb_to_right_edge; |
| 373 int mb_to_top_edge; |
| 374 int mb_to_bottom_edge; |
| 375 |
| 376 unsigned int frames_since_golden; |
| 377 unsigned int frames_till_alt_ref_frame; |
| 378 |
| 379 /* Inverse transform function pointers. */ |
| 380 void (*inv_xform4x4_1_x8)(short *input, short *output, int pitch); |
| 381 void (*inv_xform4x4_x8)(short *input, short *output, int pitch); |
| 382 void (*inv_walsh4x4_1)(short *in, short *out); |
| 383 void (*inv_walsh4x4_lossless)(short *in, short *out); |
| 384 |
| 385 |
| 386 vp9_subpix_fn_t subpixel_predict; |
| 387 vp9_subpix_fn_t subpixel_predict8x4; |
| 388 vp9_subpix_fn_t subpixel_predict8x8; |
| 389 vp9_subpix_fn_t subpixel_predict16x16; |
| 390 vp9_subpix_fn_t subpixel_predict_avg; |
| 391 vp9_subpix_fn_t subpixel_predict_avg8x4; |
| 392 vp9_subpix_fn_t subpixel_predict_avg8x8; |
| 393 vp9_subpix_fn_t subpixel_predict_avg16x16; |
| 394 int allow_high_precision_mv; |
| 395 |
| 396 int corrupted; |
| 397 |
| 398 #if !CONFIG_SUPERBLOCKS && (ARCH_X86 || ARCH_X86_64) |
| 399 /* This is an intermediate buffer currently used in sub-pixel motion search |
| 400 * to keep a copy of the reference area. This buffer can be used for other |
| 401 * purpose. |
| 402 */ |
| 403 DECLARE_ALIGNED(32, unsigned char, y_buf[22 * 32]); |
| 404 #endif |
| 405 |
| 406 int mb_index; // Index of the MB in the SB (0..3) |
| 407 int q_index; |
| 408 |
| 409 } MACROBLOCKD; |
| 410 |
| 411 #define ACTIVE_HT 110 // quantization stepsize threshold |
| 412 |
| 413 #define ACTIVE_HT8 300 |
| 414 |
| 415 #define ACTIVE_HT16 300 |
| 416 |
| 417 // convert MB_PREDICTION_MODE to B_PREDICTION_MODE |
| 418 static B_PREDICTION_MODE pred_mode_conv(MB_PREDICTION_MODE mode) { |
| 419 B_PREDICTION_MODE b_mode; |
| 420 switch (mode) { |
| 421 case DC_PRED: |
| 422 b_mode = B_DC_PRED; |
| 423 break; |
| 424 case V_PRED: |
| 425 b_mode = B_VE_PRED; |
| 426 break; |
| 427 case H_PRED: |
| 428 b_mode = B_HE_PRED; |
| 429 break; |
| 430 case TM_PRED: |
| 431 b_mode = B_TM_PRED; |
| 432 break; |
| 433 case D45_PRED: |
| 434 b_mode = B_LD_PRED; |
| 435 break; |
| 436 case D135_PRED: |
| 437 b_mode = B_RD_PRED; |
| 438 break; |
| 439 case D117_PRED: |
| 440 b_mode = B_VR_PRED; |
| 441 break; |
| 442 case D153_PRED: |
| 443 b_mode = B_HD_PRED; |
| 444 break; |
| 445 case D27_PRED: |
| 446 b_mode = B_HU_PRED; |
| 447 break; |
| 448 case D63_PRED: |
| 449 b_mode = B_VL_PRED; |
| 450 break; |
| 451 default : |
| 452 // for debug purpose, to be removed after full testing |
| 453 assert(0); |
| 454 break; |
| 455 } |
| 456 return b_mode; |
| 457 } |
| 458 |
| 459 // transform mapping |
| 460 static TX_TYPE txfm_map(B_PREDICTION_MODE bmode) { |
| 461 // map transform type |
| 462 TX_TYPE tx_type; |
| 463 switch (bmode) { |
| 464 case B_TM_PRED : |
| 465 case B_RD_PRED : |
| 466 tx_type = ADST_ADST; |
| 467 break; |
| 468 |
| 469 case B_VE_PRED : |
| 470 case B_VR_PRED : |
| 471 tx_type = ADST_DCT; |
| 472 break; |
| 473 |
| 474 case B_HE_PRED : |
| 475 case B_HD_PRED : |
| 476 case B_HU_PRED : |
| 477 tx_type = DCT_ADST; |
| 478 break; |
| 479 |
| 480 #if CONFIG_NEWBINTRAMODES |
| 481 case B_CONTEXT_PRED: |
| 482 assert(0); |
| 483 break; |
| 484 #endif |
| 485 |
| 486 default : |
| 487 tx_type = DCT_DCT; |
| 488 break; |
| 489 } |
| 490 return tx_type; |
| 491 } |
| 492 |
| 493 #define USE_ADST_FOR_I16X16_8X8 0 |
| 494 #define USE_ADST_FOR_I16X16_4X4 0 |
| 495 #define USE_ADST_FOR_I8X8_4X4 1 |
| 496 #define USE_ADST_PERIPHERY_ONLY 1 |
| 497 |
| 498 static TX_TYPE get_tx_type_4x4(const MACROBLOCKD *xd, const BLOCKD *b) { |
| 499 // TODO(debargha): explore different patterns for ADST usage when blocksize |
| 500 // is smaller than the prediction size |
| 501 TX_TYPE tx_type = DCT_DCT; |
| 502 int ib = (int)(b - xd->block); |
| 503 if (ib >= 16) |
| 504 return tx_type; |
| 505 #if CONFIG_SUPERBLOCKS |
| 506 // TODO(rbultje, debargha): Explore ADST usage for superblocks |
| 507 if (xd->mode_info_context->mbmi.encoded_as_sb) |
| 508 return tx_type; |
| 509 #endif |
| 510 if (xd->mode_info_context->mbmi.mode == B_PRED && |
| 511 xd->q_index < ACTIVE_HT) { |
| 512 tx_type = txfm_map( |
| 513 #if CONFIG_NEWBINTRAMODES |
| 514 b->bmi.as_mode.first == B_CONTEXT_PRED ? b->bmi.as_mode.context : |
| 515 #endif |
| 516 b->bmi.as_mode.first); |
| 517 } else if (xd->mode_info_context->mbmi.mode == I8X8_PRED && |
| 518 xd->q_index < ACTIVE_HT) { |
| 519 #if USE_ADST_FOR_I8X8_4X4 |
| 520 #if USE_ADST_PERIPHERY_ONLY |
| 521 // Use ADST for periphery blocks only |
| 522 int ic = (ib & 10); |
| 523 b += ic - ib; |
| 524 tx_type = (ic != 10) ? |
| 525 txfm_map(pred_mode_conv((MB_PREDICTION_MODE)b->bmi.as_mode.first)) : |
| 526 DCT_DCT; |
| 527 #else |
| 528 // Use ADST |
| 529 tx_type = txfm_map(pred_mode_conv( |
| 530 (MB_PREDICTION_MODE)b->bmi.as_mode.first)); |
| 531 #endif |
| 532 #else |
| 533 // Use 2D DCT |
| 534 tx_type = DCT_DCT; |
| 535 #endif |
| 536 } else if (xd->mode_info_context->mbmi.mode < I8X8_PRED && |
| 537 xd->q_index < ACTIVE_HT) { |
| 538 #if USE_ADST_FOR_I16X16_4X4 |
| 539 #if USE_ADST_PERIPHERY_ONLY |
| 540 // Use ADST for periphery blocks only |
| 541 tx_type = (ib < 4 || ((ib & 3) == 0)) ? |
| 542 txfm_map(pred_mode_conv(xd->mode_info_context->mbmi.mode)) : DCT_DCT; |
| 543 #else |
| 544 // Use ADST |
| 545 tx_type = txfm_map(pred_mode_conv(xd->mode_info_context->mbmi.mode)); |
| 546 #endif |
| 547 #else |
| 548 // Use 2D DCT |
| 549 tx_type = DCT_DCT; |
| 550 #endif |
| 551 } |
| 552 return tx_type; |
| 553 } |
| 554 |
| 555 static TX_TYPE get_tx_type_8x8(const MACROBLOCKD *xd, const BLOCKD *b) { |
| 556 // TODO(debargha): explore different patterns for ADST usage when blocksize |
| 557 // is smaller than the prediction size |
| 558 TX_TYPE tx_type = DCT_DCT; |
| 559 int ib = (int)(b - xd->block); |
| 560 if (ib >= 16) |
| 561 return tx_type; |
| 562 #if CONFIG_SUPERBLOCKS |
| 563 // TODO(rbultje, debargha): Explore ADST usage for superblocks |
| 564 if (xd->mode_info_context->mbmi.encoded_as_sb) |
| 565 return tx_type; |
| 566 #endif |
| 567 if (xd->mode_info_context->mbmi.mode == I8X8_PRED && |
| 568 xd->q_index < ACTIVE_HT8) { |
| 569 // TODO(rbultje): MB_PREDICTION_MODE / B_PREDICTION_MODE should be merged |
| 570 // or the relationship otherwise modified to address this type conversion. |
| 571 tx_type = txfm_map(pred_mode_conv( |
| 572 (MB_PREDICTION_MODE)b->bmi.as_mode.first)); |
| 573 } else if (xd->mode_info_context->mbmi.mode < I8X8_PRED && |
| 574 xd->q_index < ACTIVE_HT8) { |
| 575 #if USE_ADST_FOR_I8X8_4X4 |
| 576 #if USE_ADST_PERIPHERY_ONLY |
| 577 // Use ADST for periphery blocks only |
| 578 tx_type = (ib != 10) ? |
| 579 txfm_map(pred_mode_conv(xd->mode_info_context->mbmi.mode)) : DCT_DCT; |
| 580 #else |
| 581 // Use ADST |
| 582 tx_type = txfm_map(pred_mode_conv(xd->mode_info_context->mbmi.mode)); |
| 583 #endif |
| 584 #else |
| 585 // Use 2D DCT |
| 586 tx_type = DCT_DCT; |
| 587 #endif |
| 588 } |
| 589 return tx_type; |
| 590 } |
| 591 |
| 592 static TX_TYPE get_tx_type_16x16(const MACROBLOCKD *xd, const BLOCKD *b) { |
| 593 TX_TYPE tx_type = DCT_DCT; |
| 594 int ib = (int)(b - xd->block); |
| 595 if (ib >= 16) |
| 596 return tx_type; |
| 597 #if CONFIG_SUPERBLOCKS |
| 598 // TODO(rbultje, debargha): Explore ADST usage for superblocks |
| 599 if (xd->mode_info_context->mbmi.encoded_as_sb) |
| 600 return tx_type; |
| 601 #endif |
| 602 if (xd->mode_info_context->mbmi.mode < I8X8_PRED && |
| 603 xd->q_index < ACTIVE_HT16) { |
| 604 tx_type = txfm_map(pred_mode_conv(xd->mode_info_context->mbmi.mode)); |
| 605 } |
| 606 return tx_type; |
| 607 } |
| 608 |
| 609 static TX_TYPE get_tx_type(const MACROBLOCKD *xd, const BLOCKD *b) { |
| 610 TX_TYPE tx_type = DCT_DCT; |
| 611 int ib = (int)(b - xd->block); |
| 612 if (ib >= 16) |
| 613 return tx_type; |
| 614 if (xd->mode_info_context->mbmi.txfm_size == TX_16X16) { |
| 615 tx_type = get_tx_type_16x16(xd, b); |
| 616 } |
| 617 if (xd->mode_info_context->mbmi.txfm_size == TX_8X8) { |
| 618 ib = (ib & 8) + ((ib & 4) >> 1); |
| 619 tx_type = get_tx_type_8x8(xd, &xd->block[ib]); |
| 620 } |
| 621 if (xd->mode_info_context->mbmi.txfm_size == TX_4X4) { |
| 622 tx_type = get_tx_type_4x4(xd, b); |
| 623 } |
| 624 return tx_type; |
| 625 } |
| 626 |
| 627 static int get_2nd_order_usage(const MACROBLOCKD *xd) { |
| 628 int has_2nd_order = (xd->mode_info_context->mbmi.mode != SPLITMV && |
| 629 xd->mode_info_context->mbmi.mode != I8X8_PRED && |
| 630 xd->mode_info_context->mbmi.mode != B_PRED && |
| 631 xd->mode_info_context->mbmi.txfm_size != TX_16X16); |
| 632 if (has_2nd_order) |
| 633 has_2nd_order = (get_tx_type(xd, xd->block) == DCT_DCT); |
| 634 return has_2nd_order; |
| 635 } |
| 636 |
| 637 extern void vp9_build_block_doffsets(MACROBLOCKD *xd); |
| 638 extern void vp9_setup_block_dptrs(MACROBLOCKD *xd); |
| 639 |
| 640 static void update_blockd_bmi(MACROBLOCKD *xd) { |
| 641 int i; |
| 642 int is_4x4; |
| 643 is_4x4 = (xd->mode_info_context->mbmi.mode == SPLITMV) || |
| 644 (xd->mode_info_context->mbmi.mode == I8X8_PRED) || |
| 645 (xd->mode_info_context->mbmi.mode == B_PRED); |
| 646 |
| 647 if (is_4x4) { |
| 648 for (i = 0; i < 16; i++) { |
| 649 xd->block[i].bmi = xd->mode_info_context->bmi[i]; |
| 650 } |
| 651 } |
| 652 } |
| 653 #endif /* __INC_BLOCKD_H */ |
OLD | NEW |