media/libvpx/vp9/common/vp9_reconintra.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11 #include "./vpx_config.h"
michael@0 12
michael@0 13 #include "vpx_mem/vpx_mem.h"
michael@0 14 #include "vpx_ports/vpx_once.h"
michael@0 15
michael@0 16 #include "./vp9_rtcd.h"
michael@0 17
michael@0 18 #include "vp9/common/vp9_reconintra.h"
michael@0 19 #include "vp9/common/vp9_onyxc_int.h"
michael@0 20
michael@0 21 const TX_TYPE mode2txfm_map[MB_MODE_COUNT] = {
michael@0 22 DCT_DCT, // DC
michael@0 23 ADST_DCT, // V
michael@0 24 DCT_ADST, // H
michael@0 25 DCT_DCT, // D45
michael@0 26 ADST_ADST, // D135
michael@0 27 ADST_DCT, // D117
michael@0 28 DCT_ADST, // D153
michael@0 29 DCT_ADST, // D207
michael@0 30 ADST_DCT, // D63
michael@0 31 ADST_ADST, // TM
michael@0 32 DCT_DCT, // NEARESTMV
michael@0 33 DCT_DCT, // NEARMV
michael@0 34 DCT_DCT, // ZEROMV
michael@0 35 DCT_DCT // NEWMV
michael@0 36 };
michael@0 37
michael@0 38 #define intra_pred_sized(type, size) \
michael@0 39 void vp9_##type##_predictor_##size##x##size##_c(uint8_t *dst, \
michael@0 40 ptrdiff_t stride, \
michael@0 41 const uint8_t *above, \
michael@0 42 const uint8_t *left) { \
michael@0 43 type##_predictor(dst, stride, size, above, left); \
michael@0 44 }
michael@0 45
michael@0 46 #define intra_pred_allsizes(type) \
michael@0 47 intra_pred_sized(type, 4) \
michael@0 48 intra_pred_sized(type, 8) \
michael@0 49 intra_pred_sized(type, 16) \
michael@0 50 intra_pred_sized(type, 32)
michael@0 51
michael@0 52 static INLINE void d207_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 53 const uint8_t *above, const uint8_t *left) {
michael@0 54 int r, c;
michael@0 55
michael@0 56 // first column
michael@0 57 for (r = 0; r < bs - 1; ++r)
michael@0 58 dst[r * stride] = ROUND_POWER_OF_TWO(left[r] + left[r + 1], 1);
michael@0 59 dst[(bs - 1) * stride] = left[bs - 1];
michael@0 60 dst++;
michael@0 61
michael@0 62 // second column
michael@0 63 for (r = 0; r < bs - 2; ++r)
michael@0 64 dst[r * stride] = ROUND_POWER_OF_TWO(left[r] + left[r + 1] * 2 +
michael@0 65 left[r + 2], 2);
michael@0 66 dst[(bs - 2) * stride] = ROUND_POWER_OF_TWO(left[bs - 2] +
michael@0 67 left[bs - 1] * 3, 2);
michael@0 68 dst[(bs - 1) * stride] = left[bs - 1];
michael@0 69 dst++;
michael@0 70
michael@0 71 // rest of last row
michael@0 72 for (c = 0; c < bs - 2; ++c)
michael@0 73 dst[(bs - 1) * stride + c] = left[bs - 1];
michael@0 74
michael@0 75 for (r = bs - 2; r >= 0; --r)
michael@0 76 for (c = 0; c < bs - 2; ++c)
michael@0 77 dst[r * stride + c] = dst[(r + 1) * stride + c - 2];
michael@0 78 }
michael@0 79 intra_pred_allsizes(d207)
michael@0 80
michael@0 81 static INLINE void d63_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 82 const uint8_t *above, const uint8_t *left) {
michael@0 83 int r, c;
michael@0 84 for (r = 0; r < bs; ++r) {
michael@0 85 for (c = 0; c < bs; ++c)
michael@0 86 dst[c] = r & 1 ? ROUND_POWER_OF_TWO(above[r/2 + c] +
michael@0 87 above[r/2 + c + 1] * 2 +
michael@0 88 above[r/2 + c + 2], 2)
michael@0 89 : ROUND_POWER_OF_TWO(above[r/2 + c] +
michael@0 90 above[r/2 + c + 1], 1);
michael@0 91 dst += stride;
michael@0 92 }
michael@0 93 }
michael@0 94 intra_pred_allsizes(d63)
michael@0 95
michael@0 96 static INLINE void d45_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 97 const uint8_t *above, const uint8_t *left) {
michael@0 98 int r, c;
michael@0 99 for (r = 0; r < bs; ++r) {
michael@0 100 for (c = 0; c < bs; ++c)
michael@0 101 dst[c] = r + c + 2 < bs * 2 ? ROUND_POWER_OF_TWO(above[r + c] +
michael@0 102 above[r + c + 1] * 2 +
michael@0 103 above[r + c + 2], 2)
michael@0 104 : above[bs * 2 - 1];
michael@0 105 dst += stride;
michael@0 106 }
michael@0 107 }
michael@0 108 intra_pred_allsizes(d45)
michael@0 109
michael@0 110 static INLINE void d117_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 111 const uint8_t *above, const uint8_t *left) {
michael@0 112 int r, c;
michael@0 113
michael@0 114 // first row
michael@0 115 for (c = 0; c < bs; c++)
michael@0 116 dst[c] = ROUND_POWER_OF_TWO(above[c - 1] + above[c], 1);
michael@0 117 dst += stride;
michael@0 118
michael@0 119 // second row
michael@0 120 dst[0] = ROUND_POWER_OF_TWO(left[0] + above[-1] * 2 + above[0], 2);
michael@0 121 for (c = 1; c < bs; c++)
michael@0 122 dst[c] = ROUND_POWER_OF_TWO(above[c - 2] + above[c - 1] * 2 + above[c], 2);
michael@0 123 dst += stride;
michael@0 124
michael@0 125 // the rest of first col
michael@0 126 dst[0] = ROUND_POWER_OF_TWO(above[-1] + left[0] * 2 + left[1], 2);
michael@0 127 for (r = 3; r < bs; ++r)
michael@0 128 dst[(r - 2) * stride] = ROUND_POWER_OF_TWO(left[r - 3] + left[r - 2] * 2 +
michael@0 129 left[r - 1], 2);
michael@0 130
michael@0 131 // the rest of the block
michael@0 132 for (r = 2; r < bs; ++r) {
michael@0 133 for (c = 1; c < bs; c++)
michael@0 134 dst[c] = dst[-2 * stride + c - 1];
michael@0 135 dst += stride;
michael@0 136 }
michael@0 137 }
michael@0 138 intra_pred_allsizes(d117)
michael@0 139
michael@0 140 static INLINE void d135_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 141 const uint8_t *above, const uint8_t *left) {
michael@0 142 int r, c;
michael@0 143 dst[0] = ROUND_POWER_OF_TWO(left[0] + above[-1] * 2 + above[0], 2);
michael@0 144 for (c = 1; c < bs; c++)
michael@0 145 dst[c] = ROUND_POWER_OF_TWO(above[c - 2] + above[c - 1] * 2 + above[c], 2);
michael@0 146
michael@0 147 dst[stride] = ROUND_POWER_OF_TWO(above[-1] + left[0] * 2 + left[1], 2);
michael@0 148 for (r = 2; r < bs; ++r)
michael@0 149 dst[r * stride] = ROUND_POWER_OF_TWO(left[r - 2] + left[r - 1] * 2 +
michael@0 150 left[r], 2);
michael@0 151
michael@0 152 dst += stride;
michael@0 153 for (r = 1; r < bs; ++r) {
michael@0 154 for (c = 1; c < bs; c++)
michael@0 155 dst[c] = dst[-stride + c - 1];
michael@0 156 dst += stride;
michael@0 157 }
michael@0 158 }
michael@0 159 intra_pred_allsizes(d135)
michael@0 160
michael@0 161 static INLINE void d153_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 162 const uint8_t *above, const uint8_t *left) {
michael@0 163 int r, c;
michael@0 164 dst[0] = ROUND_POWER_OF_TWO(above[-1] + left[0], 1);
michael@0 165 for (r = 1; r < bs; r++)
michael@0 166 dst[r * stride] = ROUND_POWER_OF_TWO(left[r - 1] + left[r], 1);
michael@0 167 dst++;
michael@0 168
michael@0 169 dst[0] = ROUND_POWER_OF_TWO(left[0] + above[-1] * 2 + above[0], 2);
michael@0 170 dst[stride] = ROUND_POWER_OF_TWO(above[-1] + left[0] * 2 + left[1], 2);
michael@0 171 for (r = 2; r < bs; r++)
michael@0 172 dst[r * stride] = ROUND_POWER_OF_TWO(left[r - 2] + left[r - 1] * 2 +
michael@0 173 left[r], 2);
michael@0 174 dst++;
michael@0 175
michael@0 176 for (c = 0; c < bs - 2; c++)
michael@0 177 dst[c] = ROUND_POWER_OF_TWO(above[c - 1] + above[c] * 2 + above[c + 1], 2);
michael@0 178 dst += stride;
michael@0 179
michael@0 180 for (r = 1; r < bs; ++r) {
michael@0 181 for (c = 0; c < bs - 2; c++)
michael@0 182 dst[c] = dst[-stride + c - 2];
michael@0 183 dst += stride;
michael@0 184 }
michael@0 185 }
michael@0 186 intra_pred_allsizes(d153)
michael@0 187
michael@0 188 static INLINE void v_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 189 const uint8_t *above, const uint8_t *left) {
michael@0 190 int r;
michael@0 191
michael@0 192 for (r = 0; r < bs; r++) {
michael@0 193 vpx_memcpy(dst, above, bs);
michael@0 194 dst += stride;
michael@0 195 }
michael@0 196 }
michael@0 197 intra_pred_allsizes(v)
michael@0 198
michael@0 199 static INLINE void h_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 200 const uint8_t *above, const uint8_t *left) {
michael@0 201 int r;
michael@0 202
michael@0 203 for (r = 0; r < bs; r++) {
michael@0 204 vpx_memset(dst, left[r], bs);
michael@0 205 dst += stride;
michael@0 206 }
michael@0 207 }
michael@0 208 intra_pred_allsizes(h)
michael@0 209
michael@0 210 static INLINE void tm_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 211 const uint8_t *above, const uint8_t *left) {
michael@0 212 int r, c;
michael@0 213 int ytop_left = above[-1];
michael@0 214
michael@0 215 for (r = 0; r < bs; r++) {
michael@0 216 for (c = 0; c < bs; c++)
michael@0 217 dst[c] = clip_pixel(left[r] + above[c] - ytop_left);
michael@0 218 dst += stride;
michael@0 219 }
michael@0 220 }
michael@0 221 intra_pred_allsizes(tm)
michael@0 222
michael@0 223 static INLINE void dc_128_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 224 const uint8_t *above, const uint8_t *left) {
michael@0 225 int r;
michael@0 226
michael@0 227 for (r = 0; r < bs; r++) {
michael@0 228 vpx_memset(dst, 128, bs);
michael@0 229 dst += stride;
michael@0 230 }
michael@0 231 }
michael@0 232 intra_pred_allsizes(dc_128)
michael@0 233
michael@0 234 static INLINE void dc_left_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 235 const uint8_t *above,
michael@0 236 const uint8_t *left) {
michael@0 237 int i, r, expected_dc, sum = 0;
michael@0 238
michael@0 239 for (i = 0; i < bs; i++)
michael@0 240 sum += left[i];
michael@0 241 expected_dc = (sum + (bs >> 1)) / bs;
michael@0 242
michael@0 243 for (r = 0; r < bs; r++) {
michael@0 244 vpx_memset(dst, expected_dc, bs);
michael@0 245 dst += stride;
michael@0 246 }
michael@0 247 }
michael@0 248 intra_pred_allsizes(dc_left)
michael@0 249
michael@0 250 static INLINE void dc_top_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 251 const uint8_t *above, const uint8_t *left) {
michael@0 252 int i, r, expected_dc, sum = 0;
michael@0 253
michael@0 254 for (i = 0; i < bs; i++)
michael@0 255 sum += above[i];
michael@0 256 expected_dc = (sum + (bs >> 1)) / bs;
michael@0 257
michael@0 258 for (r = 0; r < bs; r++) {
michael@0 259 vpx_memset(dst, expected_dc, bs);
michael@0 260 dst += stride;
michael@0 261 }
michael@0 262 }
michael@0 263 intra_pred_allsizes(dc_top)
michael@0 264
michael@0 265 static INLINE void dc_predictor(uint8_t *dst, ptrdiff_t stride, int bs,
michael@0 266 const uint8_t *above, const uint8_t *left) {
michael@0 267 int i, r, expected_dc, sum = 0;
michael@0 268 const int count = 2 * bs;
michael@0 269
michael@0 270 for (i = 0; i < bs; i++) {
michael@0 271 sum += above[i];
michael@0 272 sum += left[i];
michael@0 273 }
michael@0 274
michael@0 275 expected_dc = (sum + (count >> 1)) / count;
michael@0 276
michael@0 277 for (r = 0; r < bs; r++) {
michael@0 278 vpx_memset(dst, expected_dc, bs);
michael@0 279 dst += stride;
michael@0 280 }
michael@0 281 }
michael@0 282 intra_pred_allsizes(dc)
michael@0 283 #undef intra_pred_allsizes
michael@0 284
michael@0 285 typedef void (*intra_pred_fn)(uint8_t *dst, ptrdiff_t stride,
michael@0 286 const uint8_t *above, const uint8_t *left);
michael@0 287
michael@0 288 static intra_pred_fn pred[INTRA_MODES][4];
michael@0 289 static intra_pred_fn dc_pred[2][2][4];
michael@0 290
michael@0 291 static void init_intra_pred_fn_ptrs(void) {
michael@0 292 #define intra_pred_allsizes(l, type) \
michael@0 293 l[0] = vp9_##type##_predictor_4x4; \
michael@0 294 l[1] = vp9_##type##_predictor_8x8; \
michael@0 295 l[2] = vp9_##type##_predictor_16x16; \
michael@0 296 l[3] = vp9_##type##_predictor_32x32
michael@0 297
michael@0 298 intra_pred_allsizes(pred[V_PRED], v);
michael@0 299 intra_pred_allsizes(pred[H_PRED], h);
michael@0 300 intra_pred_allsizes(pred[D207_PRED], d207);
michael@0 301 intra_pred_allsizes(pred[D45_PRED], d45);
michael@0 302 intra_pred_allsizes(pred[D63_PRED], d63);
michael@0 303 intra_pred_allsizes(pred[D117_PRED], d117);
michael@0 304 intra_pred_allsizes(pred[D135_PRED], d135);
michael@0 305 intra_pred_allsizes(pred[D153_PRED], d153);
michael@0 306 intra_pred_allsizes(pred[TM_PRED], tm);
michael@0 307
michael@0 308 intra_pred_allsizes(dc_pred[0][0], dc_128);
michael@0 309 intra_pred_allsizes(dc_pred[0][1], dc_top);
michael@0 310 intra_pred_allsizes(dc_pred[1][0], dc_left);
michael@0 311 intra_pred_allsizes(dc_pred[1][1], dc);
michael@0 312
michael@0 313 #undef intra_pred_allsizes
michael@0 314 }
michael@0 315
michael@0 316 static void build_intra_predictors(const uint8_t *ref, int ref_stride,
michael@0 317 uint8_t *dst, int dst_stride,
michael@0 318 MB_PREDICTION_MODE mode, TX_SIZE tx_size,
michael@0 319 int up_available, int left_available,
michael@0 320 int right_available) {
michael@0 321 int i;
michael@0 322 DECLARE_ALIGNED_ARRAY(16, uint8_t, left_col, 64);
michael@0 323 DECLARE_ALIGNED_ARRAY(16, uint8_t, above_data, 128 + 16);
michael@0 324 uint8_t *above_row = above_data + 16;
michael@0 325 const uint8_t *const_above_row = above_row;
michael@0 326 const int bs = 4 << tx_size;
michael@0 327
michael@0 328 // 127 127 127 .. 127 127 127 127 127 127
michael@0 329 // 129 A B .. Y Z
michael@0 330 // 129 C D .. W X
michael@0 331 // 129 E F .. U V
michael@0 332 // 129 G H .. S T T T T T
michael@0 333 // ..
michael@0 334
michael@0 335 once(init_intra_pred_fn_ptrs);
michael@0 336
michael@0 337 // left
michael@0 338 if (left_available) {
michael@0 339 for (i = 0; i < bs; i++)
michael@0 340 left_col[i] = ref[i * ref_stride - 1];
michael@0 341 } else {
michael@0 342 vpx_memset(left_col, 129, bs);
michael@0 343 }
michael@0 344
michael@0 345 // above
michael@0 346 if (up_available) {
michael@0 347 const uint8_t *above_ref = ref - ref_stride;
michael@0 348 if (bs == 4 && right_available && left_available) {
michael@0 349 const_above_row = above_ref;
michael@0 350 } else {
michael@0 351 vpx_memcpy(above_row, above_ref, bs);
michael@0 352 if (bs == 4 && right_available)
michael@0 353 vpx_memcpy(above_row + bs, above_ref + bs, bs);
michael@0 354 else
michael@0 355 vpx_memset(above_row + bs, above_row[bs - 1], bs);
michael@0 356 above_row[-1] = left_available ? above_ref[-1] : 129;
michael@0 357 }
michael@0 358 } else {
michael@0 359 vpx_memset(above_row, 127, bs * 2);
michael@0 360 above_row[-1] = 127;
michael@0 361 }
michael@0 362
michael@0 363 // predict
michael@0 364 if (mode == DC_PRED) {
michael@0 365 dc_pred[left_available][up_available][tx_size](dst, dst_stride,
michael@0 366 const_above_row, left_col);
michael@0 367 } else {
michael@0 368 pred[mode][tx_size](dst, dst_stride, const_above_row, left_col);
michael@0 369 }
michael@0 370 }
michael@0 371
michael@0 372 void vp9_predict_intra_block(const MACROBLOCKD *xd, int block_idx, int bwl_in,
michael@0 373 TX_SIZE tx_size, int mode,
michael@0 374 const uint8_t *ref, int ref_stride,
michael@0 375 uint8_t *dst, int dst_stride) {
michael@0 376 const int bwl = bwl_in - tx_size;
michael@0 377 const int wmask = (1 << bwl) - 1;
michael@0 378 const int have_top = (block_idx >> bwl) || xd->up_available;
michael@0 379 const int have_left = (block_idx & wmask) || xd->left_available;
michael@0 380 const int have_right = ((block_idx & wmask) != wmask);
michael@0 381
michael@0 382 assert(bwl >= 0);
michael@0 383 build_intra_predictors(ref, ref_stride, dst, dst_stride, mode, tx_size,
michael@0 384 have_top, have_left, have_right);
michael@0 385 }

mercurial