media/libvpx/vp9/common/vp9_postproc.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 <math.h>
michael@0 12 #include <stdlib.h>
michael@0 13 #include <stdio.h>
michael@0 14
michael@0 15 #include "./vpx_config.h"
michael@0 16 #include "vpx_scale/yv12config.h"
michael@0 17 #include "vp9/common/vp9_postproc.h"
michael@0 18 #include "vp9/common/vp9_textblit.h"
michael@0 19 #include "vpx_scale/vpx_scale.h"
michael@0 20 #include "vp9/common/vp9_systemdependent.h"
michael@0 21 #include "./vp9_rtcd.h"
michael@0 22 #include "./vpx_scale_rtcd.h"
michael@0 23
michael@0 24 #define RGB_TO_YUV(t) \
michael@0 25 ( (0.257*(float)(t >> 16)) + (0.504*(float)(t >> 8 & 0xff)) + \
michael@0 26 (0.098*(float)(t & 0xff)) + 16), \
michael@0 27 (-(0.148*(float)(t >> 16)) - (0.291*(float)(t >> 8 & 0xff)) + \
michael@0 28 (0.439*(float)(t & 0xff)) + 128), \
michael@0 29 ( (0.439*(float)(t >> 16)) - (0.368*(float)(t >> 8 & 0xff)) - \
michael@0 30 (0.071*(float)(t & 0xff)) + 128)
michael@0 31
michael@0 32 /* global constants */
michael@0 33 #if 0 && CONFIG_POSTPROC_VISUALIZER
michael@0 34 static const unsigned char MB_PREDICTION_MODE_colors[MB_MODE_COUNT][3] = {
michael@0 35 { RGB_TO_YUV(0x98FB98) }, /* PaleGreen */
michael@0 36 { RGB_TO_YUV(0x00FF00) }, /* Green */
michael@0 37 { RGB_TO_YUV(0xADFF2F) }, /* GreenYellow */
michael@0 38 { RGB_TO_YUV(0x8F0000) }, /* Dark Red */
michael@0 39 { RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */
michael@0 40 { RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */
michael@0 41 { RGB_TO_YUV(0x008F8F) }, /* Dark Cyan */
michael@0 42 { RGB_TO_YUV(0x8F0000) }, /* Dark Red */
michael@0 43 { RGB_TO_YUV(0x8F0000) }, /* Dark Red */
michael@0 44 { RGB_TO_YUV(0x228B22) }, /* ForestGreen */
michael@0 45 { RGB_TO_YUV(0x006400) }, /* DarkGreen */
michael@0 46 { RGB_TO_YUV(0x98F5FF) }, /* Cadet Blue */
michael@0 47 { RGB_TO_YUV(0x6CA6CD) }, /* Sky Blue */
michael@0 48 { RGB_TO_YUV(0x00008B) }, /* Dark blue */
michael@0 49 { RGB_TO_YUV(0x551A8B) }, /* Purple */
michael@0 50 { RGB_TO_YUV(0xFF0000) } /* Red */
michael@0 51 { RGB_TO_YUV(0xCC33FF) }, /* Magenta */
michael@0 52 };
michael@0 53
michael@0 54 static const unsigned char B_PREDICTION_MODE_colors[INTRA_MODES][3] = {
michael@0 55 { RGB_TO_YUV(0x6633ff) }, /* Purple */
michael@0 56 { RGB_TO_YUV(0xcc33ff) }, /* Magenta */
michael@0 57 { RGB_TO_YUV(0xff33cc) }, /* Pink */
michael@0 58 { RGB_TO_YUV(0xff3366) }, /* Coral */
michael@0 59 { RGB_TO_YUV(0x3366ff) }, /* Blue */
michael@0 60 { RGB_TO_YUV(0xed00f5) }, /* Dark Blue */
michael@0 61 { RGB_TO_YUV(0x2e00b8) }, /* Dark Purple */
michael@0 62 { RGB_TO_YUV(0xff6633) }, /* Orange */
michael@0 63 { RGB_TO_YUV(0x33ccff) }, /* Light Blue */
michael@0 64 { RGB_TO_YUV(0x8ab800) }, /* Green */
michael@0 65 { RGB_TO_YUV(0xffcc33) }, /* Light Orange */
michael@0 66 { RGB_TO_YUV(0x33ffcc) }, /* Aqua */
michael@0 67 { RGB_TO_YUV(0x66ff33) }, /* Light Green */
michael@0 68 { RGB_TO_YUV(0xccff33) }, /* Yellow */
michael@0 69 };
michael@0 70
michael@0 71 static const unsigned char MV_REFERENCE_FRAME_colors[MAX_REF_FRAMES][3] = {
michael@0 72 { RGB_TO_YUV(0x00ff00) }, /* Blue */
michael@0 73 { RGB_TO_YUV(0x0000ff) }, /* Green */
michael@0 74 { RGB_TO_YUV(0xffff00) }, /* Yellow */
michael@0 75 { RGB_TO_YUV(0xff0000) }, /* Red */
michael@0 76 };
michael@0 77 #endif
michael@0 78
michael@0 79 static const short kernel5[] = {
michael@0 80 1, 1, 4, 1, 1
michael@0 81 };
michael@0 82
michael@0 83 const short vp9_rv[] = {
michael@0 84 8, 5, 2, 2, 8, 12, 4, 9, 8, 3,
michael@0 85 0, 3, 9, 0, 0, 0, 8, 3, 14, 4,
michael@0 86 10, 1, 11, 14, 1, 14, 9, 6, 12, 11,
michael@0 87 8, 6, 10, 0, 0, 8, 9, 0, 3, 14,
michael@0 88 8, 11, 13, 4, 2, 9, 0, 3, 9, 6,
michael@0 89 1, 2, 3, 14, 13, 1, 8, 2, 9, 7,
michael@0 90 3, 3, 1, 13, 13, 6, 6, 5, 2, 7,
michael@0 91 11, 9, 11, 8, 7, 3, 2, 0, 13, 13,
michael@0 92 14, 4, 12, 5, 12, 10, 8, 10, 13, 10,
michael@0 93 4, 14, 4, 10, 0, 8, 11, 1, 13, 7,
michael@0 94 7, 14, 6, 14, 13, 2, 13, 5, 4, 4,
michael@0 95 0, 10, 0, 5, 13, 2, 12, 7, 11, 13,
michael@0 96 8, 0, 4, 10, 7, 2, 7, 2, 2, 5,
michael@0 97 3, 4, 7, 3, 3, 14, 14, 5, 9, 13,
michael@0 98 3, 14, 3, 6, 3, 0, 11, 8, 13, 1,
michael@0 99 13, 1, 12, 0, 10, 9, 7, 6, 2, 8,
michael@0 100 5, 2, 13, 7, 1, 13, 14, 7, 6, 7,
michael@0 101 9, 6, 10, 11, 7, 8, 7, 5, 14, 8,
michael@0 102 4, 4, 0, 8, 7, 10, 0, 8, 14, 11,
michael@0 103 3, 12, 5, 7, 14, 3, 14, 5, 2, 6,
michael@0 104 11, 12, 12, 8, 0, 11, 13, 1, 2, 0,
michael@0 105 5, 10, 14, 7, 8, 0, 4, 11, 0, 8,
michael@0 106 0, 3, 10, 5, 8, 0, 11, 6, 7, 8,
michael@0 107 10, 7, 13, 9, 2, 5, 1, 5, 10, 2,
michael@0 108 4, 3, 5, 6, 10, 8, 9, 4, 11, 14,
michael@0 109 0, 10, 0, 5, 13, 2, 12, 7, 11, 13,
michael@0 110 8, 0, 4, 10, 7, 2, 7, 2, 2, 5,
michael@0 111 3, 4, 7, 3, 3, 14, 14, 5, 9, 13,
michael@0 112 3, 14, 3, 6, 3, 0, 11, 8, 13, 1,
michael@0 113 13, 1, 12, 0, 10, 9, 7, 6, 2, 8,
michael@0 114 5, 2, 13, 7, 1, 13, 14, 7, 6, 7,
michael@0 115 9, 6, 10, 11, 7, 8, 7, 5, 14, 8,
michael@0 116 4, 4, 0, 8, 7, 10, 0, 8, 14, 11,
michael@0 117 3, 12, 5, 7, 14, 3, 14, 5, 2, 6,
michael@0 118 11, 12, 12, 8, 0, 11, 13, 1, 2, 0,
michael@0 119 5, 10, 14, 7, 8, 0, 4, 11, 0, 8,
michael@0 120 0, 3, 10, 5, 8, 0, 11, 6, 7, 8,
michael@0 121 10, 7, 13, 9, 2, 5, 1, 5, 10, 2,
michael@0 122 4, 3, 5, 6, 10, 8, 9, 4, 11, 14,
michael@0 123 3, 8, 3, 7, 8, 5, 11, 4, 12, 3,
michael@0 124 11, 9, 14, 8, 14, 13, 4, 3, 1, 2,
michael@0 125 14, 6, 5, 4, 4, 11, 4, 6, 2, 1,
michael@0 126 5, 8, 8, 12, 13, 5, 14, 10, 12, 13,
michael@0 127 0, 9, 5, 5, 11, 10, 13, 9, 10, 13,
michael@0 128 };
michael@0 129
michael@0 130
michael@0 131 /****************************************************************************
michael@0 132 */
michael@0 133 void vp9_post_proc_down_and_across_c(const uint8_t *src_ptr,
michael@0 134 uint8_t *dst_ptr,
michael@0 135 int src_pixels_per_line,
michael@0 136 int dst_pixels_per_line,
michael@0 137 int rows,
michael@0 138 int cols,
michael@0 139 int flimit) {
michael@0 140 uint8_t const *p_src;
michael@0 141 uint8_t *p_dst;
michael@0 142 int row;
michael@0 143 int col;
michael@0 144 int i;
michael@0 145 int v;
michael@0 146 int pitch = src_pixels_per_line;
michael@0 147 uint8_t d[8];
michael@0 148 (void)dst_pixels_per_line;
michael@0 149
michael@0 150 for (row = 0; row < rows; row++) {
michael@0 151 /* post_proc_down for one row */
michael@0 152 p_src = src_ptr;
michael@0 153 p_dst = dst_ptr;
michael@0 154
michael@0 155 for (col = 0; col < cols; col++) {
michael@0 156 int kernel = 4;
michael@0 157 int v = p_src[col];
michael@0 158
michael@0 159 for (i = -2; i <= 2; i++) {
michael@0 160 if (abs(v - p_src[col + i * pitch]) > flimit)
michael@0 161 goto down_skip_convolve;
michael@0 162
michael@0 163 kernel += kernel5[2 + i] * p_src[col + i * pitch];
michael@0 164 }
michael@0 165
michael@0 166 v = (kernel >> 3);
michael@0 167 down_skip_convolve:
michael@0 168 p_dst[col] = v;
michael@0 169 }
michael@0 170
michael@0 171 /* now post_proc_across */
michael@0 172 p_src = dst_ptr;
michael@0 173 p_dst = dst_ptr;
michael@0 174
michael@0 175 for (i = 0; i < 8; i++)
michael@0 176 d[i] = p_src[i];
michael@0 177
michael@0 178 for (col = 0; col < cols; col++) {
michael@0 179 int kernel = 4;
michael@0 180 v = p_src[col];
michael@0 181
michael@0 182 d[col & 7] = v;
michael@0 183
michael@0 184 for (i = -2; i <= 2; i++) {
michael@0 185 if (abs(v - p_src[col + i]) > flimit)
michael@0 186 goto across_skip_convolve;
michael@0 187
michael@0 188 kernel += kernel5[2 + i] * p_src[col + i];
michael@0 189 }
michael@0 190
michael@0 191 d[col & 7] = (kernel >> 3);
michael@0 192 across_skip_convolve:
michael@0 193
michael@0 194 if (col >= 2)
michael@0 195 p_dst[col - 2] = d[(col - 2) & 7];
michael@0 196 }
michael@0 197
michael@0 198 /* handle the last two pixels */
michael@0 199 p_dst[col - 2] = d[(col - 2) & 7];
michael@0 200 p_dst[col - 1] = d[(col - 1) & 7];
michael@0 201
michael@0 202
michael@0 203 /* next row */
michael@0 204 src_ptr += pitch;
michael@0 205 dst_ptr += pitch;
michael@0 206 }
michael@0 207 }
michael@0 208
michael@0 209 static int q2mbl(int x) {
michael@0 210 if (x < 20) x = 20;
michael@0 211
michael@0 212 x = 50 + (x - 50) * 10 / 8;
michael@0 213 return x * x / 3;
michael@0 214 }
michael@0 215
michael@0 216 void vp9_mbpost_proc_across_ip_c(uint8_t *src, int pitch,
michael@0 217 int rows, int cols, int flimit) {
michael@0 218 int r, c, i;
michael@0 219
michael@0 220 uint8_t *s = src;
michael@0 221 uint8_t d[16];
michael@0 222
michael@0 223
michael@0 224 for (r = 0; r < rows; r++) {
michael@0 225 int sumsq = 0;
michael@0 226 int sum = 0;
michael@0 227
michael@0 228 for (i = -8; i <= 6; i++) {
michael@0 229 sumsq += s[i] * s[i];
michael@0 230 sum += s[i];
michael@0 231 d[i + 8] = 0;
michael@0 232 }
michael@0 233
michael@0 234 for (c = 0; c < cols + 8; c++) {
michael@0 235 int x = s[c + 7] - s[c - 8];
michael@0 236 int y = s[c + 7] + s[c - 8];
michael@0 237
michael@0 238 sum += x;
michael@0 239 sumsq += x * y;
michael@0 240
michael@0 241 d[c & 15] = s[c];
michael@0 242
michael@0 243 if (sumsq * 15 - sum * sum < flimit) {
michael@0 244 d[c & 15] = (8 + sum + s[c]) >> 4;
michael@0 245 }
michael@0 246
michael@0 247 s[c - 8] = d[(c - 8) & 15];
michael@0 248 }
michael@0 249
michael@0 250 s += pitch;
michael@0 251 }
michael@0 252 }
michael@0 253
michael@0 254 void vp9_mbpost_proc_down_c(uint8_t *dst, int pitch,
michael@0 255 int rows, int cols, int flimit) {
michael@0 256 int r, c, i;
michael@0 257 const short *rv3 = &vp9_rv[63 & rand()]; // NOLINT
michael@0 258
michael@0 259 for (c = 0; c < cols; c++) {
michael@0 260 uint8_t *s = &dst[c];
michael@0 261 int sumsq = 0;
michael@0 262 int sum = 0;
michael@0 263 uint8_t d[16];
michael@0 264 const short *rv2 = rv3 + ((c * 17) & 127);
michael@0 265
michael@0 266 for (i = -8; i <= 6; i++) {
michael@0 267 sumsq += s[i * pitch] * s[i * pitch];
michael@0 268 sum += s[i * pitch];
michael@0 269 }
michael@0 270
michael@0 271 for (r = 0; r < rows + 8; r++) {
michael@0 272 sumsq += s[7 * pitch] * s[ 7 * pitch] - s[-8 * pitch] * s[-8 * pitch];
michael@0 273 sum += s[7 * pitch] - s[-8 * pitch];
michael@0 274 d[r & 15] = s[0];
michael@0 275
michael@0 276 if (sumsq * 15 - sum * sum < flimit) {
michael@0 277 d[r & 15] = (rv2[r & 127] + sum + s[0]) >> 4;
michael@0 278 }
michael@0 279
michael@0 280 s[-8 * pitch] = d[(r - 8) & 15];
michael@0 281 s += pitch;
michael@0 282 }
michael@0 283 }
michael@0 284 }
michael@0 285
michael@0 286 static void deblock_and_de_macro_block(YV12_BUFFER_CONFIG *source,
michael@0 287 YV12_BUFFER_CONFIG *post,
michael@0 288 int q,
michael@0 289 int low_var_thresh,
michael@0 290 int flag) {
michael@0 291 double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065;
michael@0 292 int ppl = (int)(level + .5);
michael@0 293 (void) low_var_thresh;
michael@0 294 (void) flag;
michael@0 295
michael@0 296 vp9_post_proc_down_and_across(source->y_buffer, post->y_buffer,
michael@0 297 source->y_stride, post->y_stride,
michael@0 298 source->y_height, source->y_width, ppl);
michael@0 299
michael@0 300 vp9_mbpost_proc_across_ip(post->y_buffer, post->y_stride, post->y_height,
michael@0 301 post->y_width, q2mbl(q));
michael@0 302
michael@0 303 vp9_mbpost_proc_down(post->y_buffer, post->y_stride, post->y_height,
michael@0 304 post->y_width, q2mbl(q));
michael@0 305
michael@0 306 vp9_post_proc_down_and_across(source->u_buffer, post->u_buffer,
michael@0 307 source->uv_stride, post->uv_stride,
michael@0 308 source->uv_height, source->uv_width, ppl);
michael@0 309 vp9_post_proc_down_and_across(source->v_buffer, post->v_buffer,
michael@0 310 source->uv_stride, post->uv_stride,
michael@0 311 source->uv_height, source->uv_width, ppl);
michael@0 312 }
michael@0 313
michael@0 314 void vp9_deblock(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
michael@0 315 int q) {
michael@0 316 const int ppl = (int)(6.0e-05 * q * q * q - 0.0067 * q * q + 0.306 * q
michael@0 317 + 0.0065 + 0.5);
michael@0 318 int i;
michael@0 319
michael@0 320 const uint8_t *const srcs[4] = {src->y_buffer, src->u_buffer, src->v_buffer,
michael@0 321 src->alpha_buffer};
michael@0 322 const int src_strides[4] = {src->y_stride, src->uv_stride, src->uv_stride,
michael@0 323 src->alpha_stride};
michael@0 324 const int src_widths[4] = {src->y_width, src->uv_width, src->uv_width,
michael@0 325 src->alpha_width};
michael@0 326 const int src_heights[4] = {src->y_height, src->uv_height, src->uv_height,
michael@0 327 src->alpha_height};
michael@0 328
michael@0 329 uint8_t *const dsts[4] = {dst->y_buffer, dst->u_buffer, dst->v_buffer,
michael@0 330 dst->alpha_buffer};
michael@0 331 const int dst_strides[4] = {dst->y_stride, dst->uv_stride, dst->uv_stride,
michael@0 332 dst->alpha_stride};
michael@0 333
michael@0 334 for (i = 0; i < MAX_MB_PLANE; ++i)
michael@0 335 vp9_post_proc_down_and_across(srcs[i], dsts[i],
michael@0 336 src_strides[i], dst_strides[i],
michael@0 337 src_heights[i], src_widths[i], ppl);
michael@0 338 }
michael@0 339
michael@0 340 void vp9_denoise(const YV12_BUFFER_CONFIG *src, YV12_BUFFER_CONFIG *dst,
michael@0 341 int q) {
michael@0 342 const int ppl = (int)(6.0e-05 * q * q * q - 0.0067 * q * q + 0.306 * q
michael@0 343 + 0.0065 + 0.5);
michael@0 344 int i;
michael@0 345
michael@0 346 const uint8_t *const srcs[4] = {src->y_buffer, src->u_buffer, src->v_buffer,
michael@0 347 src->alpha_buffer};
michael@0 348 const int src_strides[4] = {src->y_stride, src->uv_stride, src->uv_stride,
michael@0 349 src->alpha_stride};
michael@0 350 const int src_widths[4] = {src->y_width, src->uv_width, src->uv_width,
michael@0 351 src->alpha_width};
michael@0 352 const int src_heights[4] = {src->y_height, src->uv_height, src->uv_height,
michael@0 353 src->alpha_height};
michael@0 354
michael@0 355 uint8_t *const dsts[4] = {dst->y_buffer, dst->u_buffer, dst->v_buffer,
michael@0 356 dst->alpha_buffer};
michael@0 357 const int dst_strides[4] = {dst->y_stride, dst->uv_stride, dst->uv_stride,
michael@0 358 dst->alpha_stride};
michael@0 359
michael@0 360 for (i = 0; i < MAX_MB_PLANE; ++i) {
michael@0 361 const int src_stride = src_strides[i];
michael@0 362 const uint8_t *const src = srcs[i] + 2 * src_stride + 2;
michael@0 363 const int src_width = src_widths[i] - 4;
michael@0 364 const int src_height = src_heights[i] - 4;
michael@0 365
michael@0 366 const int dst_stride = dst_strides[i];
michael@0 367 uint8_t *const dst = dsts[i] + 2 * dst_stride + 2;
michael@0 368
michael@0 369 vp9_post_proc_down_and_across(src, dst, src_stride, dst_stride,
michael@0 370 src_height, src_width, ppl);
michael@0 371 }
michael@0 372 }
michael@0 373
michael@0 374 double vp9_gaussian(double sigma, double mu, double x) {
michael@0 375 return 1 / (sigma * sqrt(2.0 * 3.14159265)) *
michael@0 376 (exp(-(x - mu) * (x - mu) / (2 * sigma * sigma)));
michael@0 377 }
michael@0 378
michael@0 379 static void fillrd(struct postproc_state *state, int q, int a) {
michael@0 380 char char_dist[300];
michael@0 381
michael@0 382 double sigma;
michael@0 383 int ai = a, qi = q, i;
michael@0 384
michael@0 385 vp9_clear_system_state();
michael@0 386
michael@0 387 sigma = ai + .5 + .6 * (63 - qi) / 63.0;
michael@0 388
michael@0 389 /* set up a lookup table of 256 entries that matches
michael@0 390 * a gaussian distribution with sigma determined by q.
michael@0 391 */
michael@0 392 {
michael@0 393 double i;
michael@0 394 int next, j;
michael@0 395
michael@0 396 next = 0;
michael@0 397
michael@0 398 for (i = -32; i < 32; i++) {
michael@0 399 int a = (int)(.5 + 256 * vp9_gaussian(sigma, 0, i));
michael@0 400
michael@0 401 if (a) {
michael@0 402 for (j = 0; j < a; j++) {
michael@0 403 char_dist[next + j] = (char) i;
michael@0 404 }
michael@0 405
michael@0 406 next = next + j;
michael@0 407 }
michael@0 408 }
michael@0 409
michael@0 410 for (; next < 256; next++)
michael@0 411 char_dist[next] = 0;
michael@0 412 }
michael@0 413
michael@0 414 for (i = 0; i < 3072; i++) {
michael@0 415 state->noise[i] = char_dist[rand() & 0xff]; // NOLINT
michael@0 416 }
michael@0 417
michael@0 418 for (i = 0; i < 16; i++) {
michael@0 419 state->blackclamp[i] = -char_dist[0];
michael@0 420 state->whiteclamp[i] = -char_dist[0];
michael@0 421 state->bothclamp[i] = -2 * char_dist[0];
michael@0 422 }
michael@0 423
michael@0 424 state->last_q = q;
michael@0 425 state->last_noise = a;
michael@0 426 }
michael@0 427
michael@0 428 /****************************************************************************
michael@0 429 *
michael@0 430 * ROUTINE : plane_add_noise_c
michael@0 431 *
michael@0 432 * INPUTS : unsigned char *Start starting address of buffer to
michael@0 433 * add gaussian noise to
michael@0 434 * unsigned int width width of plane
michael@0 435 * unsigned int height height of plane
michael@0 436 * int pitch distance between subsequent lines of frame
michael@0 437 * int q quantizer used to determine amount of noise
michael@0 438 * to add
michael@0 439 *
michael@0 440 * OUTPUTS : None.
michael@0 441 *
michael@0 442 * RETURNS : void.
michael@0 443 *
michael@0 444 * FUNCTION : adds gaussian noise to a plane of pixels
michael@0 445 *
michael@0 446 * SPECIAL NOTES : None.
michael@0 447 *
michael@0 448 ****************************************************************************/
michael@0 449 void vp9_plane_add_noise_c(uint8_t *start, char *noise,
michael@0 450 char blackclamp[16],
michael@0 451 char whiteclamp[16],
michael@0 452 char bothclamp[16],
michael@0 453 unsigned int width, unsigned int height, int pitch) {
michael@0 454 unsigned int i, j;
michael@0 455
michael@0 456 for (i = 0; i < height; i++) {
michael@0 457 uint8_t *pos = start + i * pitch;
michael@0 458 char *ref = (char *)(noise + (rand() & 0xff)); // NOLINT
michael@0 459
michael@0 460 for (j = 0; j < width; j++) {
michael@0 461 if (pos[j] < blackclamp[0])
michael@0 462 pos[j] = blackclamp[0];
michael@0 463
michael@0 464 if (pos[j] > 255 + whiteclamp[0])
michael@0 465 pos[j] = 255 + whiteclamp[0];
michael@0 466
michael@0 467 pos[j] += ref[j];
michael@0 468 }
michael@0 469 }
michael@0 470 }
michael@0 471
michael@0 472 /* Blend the macro block with a solid colored square. Leave the
michael@0 473 * edges unblended to give distinction to macro blocks in areas
michael@0 474 * filled with the same color block.
michael@0 475 */
michael@0 476 void vp9_blend_mb_inner_c(uint8_t *y, uint8_t *u, uint8_t *v,
michael@0 477 int y1, int u1, int v1, int alpha, int stride) {
michael@0 478 int i, j;
michael@0 479 int y1_const = y1 * ((1 << 16) - alpha);
michael@0 480 int u1_const = u1 * ((1 << 16) - alpha);
michael@0 481 int v1_const = v1 * ((1 << 16) - alpha);
michael@0 482
michael@0 483 y += 2 * stride + 2;
michael@0 484 for (i = 0; i < 12; i++) {
michael@0 485 for (j = 0; j < 12; j++) {
michael@0 486 y[j] = (y[j] * alpha + y1_const) >> 16;
michael@0 487 }
michael@0 488 y += stride;
michael@0 489 }
michael@0 490
michael@0 491 stride >>= 1;
michael@0 492
michael@0 493 u += stride + 1;
michael@0 494 v += stride + 1;
michael@0 495
michael@0 496 for (i = 0; i < 6; i++) {
michael@0 497 for (j = 0; j < 6; j++) {
michael@0 498 u[j] = (u[j] * alpha + u1_const) >> 16;
michael@0 499 v[j] = (v[j] * alpha + v1_const) >> 16;
michael@0 500 }
michael@0 501 u += stride;
michael@0 502 v += stride;
michael@0 503 }
michael@0 504 }
michael@0 505
michael@0 506 /* Blend only the edge of the macro block. Leave center
michael@0 507 * unblended to allow for other visualizations to be layered.
michael@0 508 */
michael@0 509 void vp9_blend_mb_outer_c(uint8_t *y, uint8_t *u, uint8_t *v,
michael@0 510 int y1, int u1, int v1, int alpha, int stride) {
michael@0 511 int i, j;
michael@0 512 int y1_const = y1 * ((1 << 16) - alpha);
michael@0 513 int u1_const = u1 * ((1 << 16) - alpha);
michael@0 514 int v1_const = v1 * ((1 << 16) - alpha);
michael@0 515
michael@0 516 for (i = 0; i < 2; i++) {
michael@0 517 for (j = 0; j < 16; j++) {
michael@0 518 y[j] = (y[j] * alpha + y1_const) >> 16;
michael@0 519 }
michael@0 520 y += stride;
michael@0 521 }
michael@0 522
michael@0 523 for (i = 0; i < 12; i++) {
michael@0 524 y[0] = (y[0] * alpha + y1_const) >> 16;
michael@0 525 y[1] = (y[1] * alpha + y1_const) >> 16;
michael@0 526 y[14] = (y[14] * alpha + y1_const) >> 16;
michael@0 527 y[15] = (y[15] * alpha + y1_const) >> 16;
michael@0 528 y += stride;
michael@0 529 }
michael@0 530
michael@0 531 for (i = 0; i < 2; i++) {
michael@0 532 for (j = 0; j < 16; j++) {
michael@0 533 y[j] = (y[j] * alpha + y1_const) >> 16;
michael@0 534 }
michael@0 535 y += stride;
michael@0 536 }
michael@0 537
michael@0 538 stride >>= 1;
michael@0 539
michael@0 540 for (j = 0; j < 8; j++) {
michael@0 541 u[j] = (u[j] * alpha + u1_const) >> 16;
michael@0 542 v[j] = (v[j] * alpha + v1_const) >> 16;
michael@0 543 }
michael@0 544 u += stride;
michael@0 545 v += stride;
michael@0 546
michael@0 547 for (i = 0; i < 6; i++) {
michael@0 548 u[0] = (u[0] * alpha + u1_const) >> 16;
michael@0 549 v[0] = (v[0] * alpha + v1_const) >> 16;
michael@0 550
michael@0 551 u[7] = (u[7] * alpha + u1_const) >> 16;
michael@0 552 v[7] = (v[7] * alpha + v1_const) >> 16;
michael@0 553
michael@0 554 u += stride;
michael@0 555 v += stride;
michael@0 556 }
michael@0 557
michael@0 558 for (j = 0; j < 8; j++) {
michael@0 559 u[j] = (u[j] * alpha + u1_const) >> 16;
michael@0 560 v[j] = (v[j] * alpha + v1_const) >> 16;
michael@0 561 }
michael@0 562 }
michael@0 563
michael@0 564 void vp9_blend_b_c(uint8_t *y, uint8_t *u, uint8_t *v,
michael@0 565 int y1, int u1, int v1, int alpha, int stride) {
michael@0 566 int i, j;
michael@0 567 int y1_const = y1 * ((1 << 16) - alpha);
michael@0 568 int u1_const = u1 * ((1 << 16) - alpha);
michael@0 569 int v1_const = v1 * ((1 << 16) - alpha);
michael@0 570
michael@0 571 for (i = 0; i < 4; i++) {
michael@0 572 for (j = 0; j < 4; j++) {
michael@0 573 y[j] = (y[j] * alpha + y1_const) >> 16;
michael@0 574 }
michael@0 575 y += stride;
michael@0 576 }
michael@0 577
michael@0 578 stride >>= 1;
michael@0 579
michael@0 580 for (i = 0; i < 2; i++) {
michael@0 581 for (j = 0; j < 2; j++) {
michael@0 582 u[j] = (u[j] * alpha + u1_const) >> 16;
michael@0 583 v[j] = (v[j] * alpha + v1_const) >> 16;
michael@0 584 }
michael@0 585 u += stride;
michael@0 586 v += stride;
michael@0 587 }
michael@0 588 }
michael@0 589
michael@0 590 static void constrain_line(int x0, int *x1, int y0, int *y1,
michael@0 591 int width, int height) {
michael@0 592 int dx;
michael@0 593 int dy;
michael@0 594
michael@0 595 if (*x1 > width) {
michael@0 596 dx = *x1 - x0;
michael@0 597 dy = *y1 - y0;
michael@0 598
michael@0 599 *x1 = width;
michael@0 600 if (dx)
michael@0 601 *y1 = ((width - x0) * dy) / dx + y0;
michael@0 602 }
michael@0 603 if (*x1 < 0) {
michael@0 604 dx = *x1 - x0;
michael@0 605 dy = *y1 - y0;
michael@0 606
michael@0 607 *x1 = 0;
michael@0 608 if (dx)
michael@0 609 *y1 = ((0 - x0) * dy) / dx + y0;
michael@0 610 }
michael@0 611 if (*y1 > height) {
michael@0 612 dx = *x1 - x0;
michael@0 613 dy = *y1 - y0;
michael@0 614
michael@0 615 *y1 = height;
michael@0 616 if (dy)
michael@0 617 *x1 = ((height - y0) * dx) / dy + x0;
michael@0 618 }
michael@0 619 if (*y1 < 0) {
michael@0 620 dx = *x1 - x0;
michael@0 621 dy = *y1 - y0;
michael@0 622
michael@0 623 *y1 = 0;
michael@0 624 if (dy)
michael@0 625 *x1 = ((0 - y0) * dx) / dy + x0;
michael@0 626 }
michael@0 627 }
michael@0 628
michael@0 629 int vp9_post_proc_frame(struct VP9Common *cm,
michael@0 630 YV12_BUFFER_CONFIG *dest, vp9_ppflags_t *ppflags) {
michael@0 631 int q = cm->lf.filter_level * 10 / 6;
michael@0 632 int flags = ppflags->post_proc_flag;
michael@0 633 int deblock_level = ppflags->deblocking_level;
michael@0 634 int noise_level = ppflags->noise_level;
michael@0 635
michael@0 636 if (!cm->frame_to_show)
michael@0 637 return -1;
michael@0 638
michael@0 639 if (q > 63)
michael@0 640 q = 63;
michael@0 641
michael@0 642 if (!flags) {
michael@0 643 *dest = *cm->frame_to_show;
michael@0 644 return 0;
michael@0 645 }
michael@0 646
michael@0 647 #if ARCH_X86||ARCH_X86_64
michael@0 648 vpx_reset_mmx_state();
michael@0 649 #endif
michael@0 650
michael@0 651 if (flags & VP9D_DEMACROBLOCK) {
michael@0 652 deblock_and_de_macro_block(cm->frame_to_show, &cm->post_proc_buffer,
michael@0 653 q + (deblock_level - 5) * 10, 1, 0);
michael@0 654 } else if (flags & VP9D_DEBLOCK) {
michael@0 655 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer, q);
michael@0 656 } else {
michael@0 657 vp8_yv12_copy_frame(cm->frame_to_show, &cm->post_proc_buffer);
michael@0 658 }
michael@0 659
michael@0 660 if (flags & VP9D_ADDNOISE) {
michael@0 661 if (cm->postproc_state.last_q != q
michael@0 662 || cm->postproc_state.last_noise != noise_level) {
michael@0 663 fillrd(&cm->postproc_state, 63 - q, noise_level);
michael@0 664 }
michael@0 665
michael@0 666 vp9_plane_add_noise(cm->post_proc_buffer.y_buffer,
michael@0 667 cm->postproc_state.noise,
michael@0 668 cm->postproc_state.blackclamp,
michael@0 669 cm->postproc_state.whiteclamp,
michael@0 670 cm->postproc_state.bothclamp,
michael@0 671 cm->post_proc_buffer.y_width,
michael@0 672 cm->post_proc_buffer.y_height,
michael@0 673 cm->post_proc_buffer.y_stride);
michael@0 674 }
michael@0 675
michael@0 676 #if 0 && CONFIG_POSTPROC_VISUALIZER
michael@0 677 if (flags & VP9D_DEBUG_TXT_FRAME_INFO) {
michael@0 678 char message[512];
michael@0 679 snprintf(message, sizeof(message) -1,
michael@0 680 "F%1dG%1dQ%3dF%3dP%d_s%dx%d",
michael@0 681 (cm->frame_type == KEY_FRAME),
michael@0 682 cm->refresh_golden_frame,
michael@0 683 cm->base_qindex,
michael@0 684 cm->filter_level,
michael@0 685 flags,
michael@0 686 cm->mb_cols, cm->mb_rows);
michael@0 687 vp9_blit_text(message, cm->post_proc_buffer.y_buffer,
michael@0 688 cm->post_proc_buffer.y_stride);
michael@0 689 }
michael@0 690
michael@0 691 if (flags & VP9D_DEBUG_TXT_MBLK_MODES) {
michael@0 692 int i, j;
michael@0 693 uint8_t *y_ptr;
michael@0 694 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer;
michael@0 695 int mb_rows = post->y_height >> 4;
michael@0 696 int mb_cols = post->y_width >> 4;
michael@0 697 int mb_index = 0;
michael@0 698 MODE_INFO *mi = cm->mi;
michael@0 699
michael@0 700 y_ptr = post->y_buffer + 4 * post->y_stride + 4;
michael@0 701
michael@0 702 /* vp9_filter each macro block */
michael@0 703 for (i = 0; i < mb_rows; i++) {
michael@0 704 for (j = 0; j < mb_cols; j++) {
michael@0 705 char zz[4];
michael@0 706
michael@0 707 snprintf(zz, sizeof(zz) - 1, "%c", mi[mb_index].mbmi.mode + 'a');
michael@0 708
michael@0 709 vp9_blit_text(zz, y_ptr, post->y_stride);
michael@0 710 mb_index++;
michael@0 711 y_ptr += 16;
michael@0 712 }
michael@0 713
michael@0 714 mb_index++; /* border */
michael@0 715 y_ptr += post->y_stride * 16 - post->y_width;
michael@0 716 }
michael@0 717 }
michael@0 718
michael@0 719 if (flags & VP9D_DEBUG_TXT_DC_DIFF) {
michael@0 720 int i, j;
michael@0 721 uint8_t *y_ptr;
michael@0 722 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer;
michael@0 723 int mb_rows = post->y_height >> 4;
michael@0 724 int mb_cols = post->y_width >> 4;
michael@0 725 int mb_index = 0;
michael@0 726 MODE_INFO *mi = cm->mi;
michael@0 727
michael@0 728 y_ptr = post->y_buffer + 4 * post->y_stride + 4;
michael@0 729
michael@0 730 /* vp9_filter each macro block */
michael@0 731 for (i = 0; i < mb_rows; i++) {
michael@0 732 for (j = 0; j < mb_cols; j++) {
michael@0 733 char zz[4];
michael@0 734 int dc_diff = !(mi[mb_index].mbmi.mode != I4X4_PRED &&
michael@0 735 mi[mb_index].mbmi.mode != SPLITMV &&
michael@0 736 mi[mb_index].mbmi.skip_coeff);
michael@0 737
michael@0 738 if (cm->frame_type == KEY_FRAME)
michael@0 739 snprintf(zz, sizeof(zz) - 1, "a");
michael@0 740 else
michael@0 741 snprintf(zz, sizeof(zz) - 1, "%c", dc_diff + '0');
michael@0 742
michael@0 743 vp9_blit_text(zz, y_ptr, post->y_stride);
michael@0 744 mb_index++;
michael@0 745 y_ptr += 16;
michael@0 746 }
michael@0 747
michael@0 748 mb_index++; /* border */
michael@0 749 y_ptr += post->y_stride * 16 - post->y_width;
michael@0 750 }
michael@0 751 }
michael@0 752
michael@0 753 if (flags & VP9D_DEBUG_TXT_RATE_INFO) {
michael@0 754 char message[512];
michael@0 755 snprintf(message, sizeof(message),
michael@0 756 "Bitrate: %10.2f framerate: %10.2f ",
michael@0 757 cm->bitrate, cm->framerate);
michael@0 758 vp9_blit_text(message, cm->post_proc_buffer.y_buffer,
michael@0 759 cm->post_proc_buffer.y_stride);
michael@0 760 }
michael@0 761
michael@0 762 /* Draw motion vectors */
michael@0 763 if ((flags & VP9D_DEBUG_DRAW_MV) && ppflags->display_mv_flag) {
michael@0 764 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer;
michael@0 765 int width = post->y_width;
michael@0 766 int height = post->y_height;
michael@0 767 uint8_t *y_buffer = cm->post_proc_buffer.y_buffer;
michael@0 768 int y_stride = cm->post_proc_buffer.y_stride;
michael@0 769 MODE_INFO *mi = cm->mi;
michael@0 770 int x0, y0;
michael@0 771
michael@0 772 for (y0 = 0; y0 < height; y0 += 16) {
michael@0 773 for (x0 = 0; x0 < width; x0 += 16) {
michael@0 774 int x1, y1;
michael@0 775
michael@0 776 if (!(ppflags->display_mv_flag & (1 << mi->mbmi.mode))) {
michael@0 777 mi++;
michael@0 778 continue;
michael@0 779 }
michael@0 780
michael@0 781 if (mi->mbmi.mode == SPLITMV) {
michael@0 782 switch (mi->mbmi.partitioning) {
michael@0 783 case PARTITIONING_16X8 : { /* mv_top_bottom */
michael@0 784 union b_mode_info *bmi = &mi->bmi[0];
michael@0 785 MV *mv = &bmi->mv.as_mv;
michael@0 786
michael@0 787 x1 = x0 + 8 + (mv->col >> 3);
michael@0 788 y1 = y0 + 4 + (mv->row >> 3);
michael@0 789
michael@0 790 constrain_line(x0 + 8, &x1, y0 + 4, &y1, width, height);
michael@0 791 vp9_blit_line(x0 + 8, x1, y0 + 4, y1, y_buffer, y_stride);
michael@0 792
michael@0 793 bmi = &mi->bmi[8];
michael@0 794
michael@0 795 x1 = x0 + 8 + (mv->col >> 3);
michael@0 796 y1 = y0 + 12 + (mv->row >> 3);
michael@0 797
michael@0 798 constrain_line(x0 + 8, &x1, y0 + 12, &y1, width, height);
michael@0 799 vp9_blit_line(x0 + 8, x1, y0 + 12, y1, y_buffer, y_stride);
michael@0 800
michael@0 801 break;
michael@0 802 }
michael@0 803 case PARTITIONING_8X16 : { /* mv_left_right */
michael@0 804 union b_mode_info *bmi = &mi->bmi[0];
michael@0 805 MV *mv = &bmi->mv.as_mv;
michael@0 806
michael@0 807 x1 = x0 + 4 + (mv->col >> 3);
michael@0 808 y1 = y0 + 8 + (mv->row >> 3);
michael@0 809
michael@0 810 constrain_line(x0 + 4, &x1, y0 + 8, &y1, width, height);
michael@0 811 vp9_blit_line(x0 + 4, x1, y0 + 8, y1, y_buffer, y_stride);
michael@0 812
michael@0 813 bmi = &mi->bmi[2];
michael@0 814
michael@0 815 x1 = x0 + 12 + (mv->col >> 3);
michael@0 816 y1 = y0 + 8 + (mv->row >> 3);
michael@0 817
michael@0 818 constrain_line(x0 + 12, &x1, y0 + 8, &y1, width, height);
michael@0 819 vp9_blit_line(x0 + 12, x1, y0 + 8, y1, y_buffer, y_stride);
michael@0 820
michael@0 821 break;
michael@0 822 }
michael@0 823 case PARTITIONING_8X8 : { /* mv_quarters */
michael@0 824 union b_mode_info *bmi = &mi->bmi[0];
michael@0 825 MV *mv = &bmi->mv.as_mv;
michael@0 826
michael@0 827 x1 = x0 + 4 + (mv->col >> 3);
michael@0 828 y1 = y0 + 4 + (mv->row >> 3);
michael@0 829
michael@0 830 constrain_line(x0 + 4, &x1, y0 + 4, &y1, width, height);
michael@0 831 vp9_blit_line(x0 + 4, x1, y0 + 4, y1, y_buffer, y_stride);
michael@0 832
michael@0 833 bmi = &mi->bmi[2];
michael@0 834
michael@0 835 x1 = x0 + 12 + (mv->col >> 3);
michael@0 836 y1 = y0 + 4 + (mv->row >> 3);
michael@0 837
michael@0 838 constrain_line(x0 + 12, &x1, y0 + 4, &y1, width, height);
michael@0 839 vp9_blit_line(x0 + 12, x1, y0 + 4, y1, y_buffer, y_stride);
michael@0 840
michael@0 841 bmi = &mi->bmi[8];
michael@0 842
michael@0 843 x1 = x0 + 4 + (mv->col >> 3);
michael@0 844 y1 = y0 + 12 + (mv->row >> 3);
michael@0 845
michael@0 846 constrain_line(x0 + 4, &x1, y0 + 12, &y1, width, height);
michael@0 847 vp9_blit_line(x0 + 4, x1, y0 + 12, y1, y_buffer, y_stride);
michael@0 848
michael@0 849 bmi = &mi->bmi[10];
michael@0 850
michael@0 851 x1 = x0 + 12 + (mv->col >> 3);
michael@0 852 y1 = y0 + 12 + (mv->row >> 3);
michael@0 853
michael@0 854 constrain_line(x0 + 12, &x1, y0 + 12, &y1, width, height);
michael@0 855 vp9_blit_line(x0 + 12, x1, y0 + 12, y1, y_buffer, y_stride);
michael@0 856 break;
michael@0 857 }
michael@0 858 case PARTITIONING_4X4:
michael@0 859 default : {
michael@0 860 union b_mode_info *bmi = mi->bmi;
michael@0 861 int bx0, by0;
michael@0 862
michael@0 863 for (by0 = y0; by0 < (y0 + 16); by0 += 4) {
michael@0 864 for (bx0 = x0; bx0 < (x0 + 16); bx0 += 4) {
michael@0 865 MV *mv = &bmi->mv.as_mv;
michael@0 866
michael@0 867 x1 = bx0 + 2 + (mv->col >> 3);
michael@0 868 y1 = by0 + 2 + (mv->row >> 3);
michael@0 869
michael@0 870 constrain_line(bx0 + 2, &x1, by0 + 2, &y1, width, height);
michael@0 871 vp9_blit_line(bx0 + 2, x1, by0 + 2, y1, y_buffer, y_stride);
michael@0 872
michael@0 873 bmi++;
michael@0 874 }
michael@0 875 }
michael@0 876 }
michael@0 877 }
michael@0 878 } else if (is_inter_mode(mi->mbmi.mode)) {
michael@0 879 MV *mv = &mi->mbmi.mv.as_mv;
michael@0 880 const int lx0 = x0 + 8;
michael@0 881 const int ly0 = y0 + 8;
michael@0 882
michael@0 883 x1 = lx0 + (mv->col >> 3);
michael@0 884 y1 = ly0 + (mv->row >> 3);
michael@0 885
michael@0 886 if (x1 != lx0 && y1 != ly0) {
michael@0 887 constrain_line(lx0, &x1, ly0 - 1, &y1, width, height);
michael@0 888 vp9_blit_line(lx0, x1, ly0 - 1, y1, y_buffer, y_stride);
michael@0 889
michael@0 890 constrain_line(lx0, &x1, ly0 + 1, &y1, width, height);
michael@0 891 vp9_blit_line(lx0, x1, ly0 + 1, y1, y_buffer, y_stride);
michael@0 892 } else {
michael@0 893 vp9_blit_line(lx0, x1, ly0, y1, y_buffer, y_stride);
michael@0 894 }
michael@0 895 }
michael@0 896
michael@0 897 mi++;
michael@0 898 }
michael@0 899 mi++;
michael@0 900 }
michael@0 901 }
michael@0 902
michael@0 903 /* Color in block modes */
michael@0 904 if ((flags & VP9D_DEBUG_CLR_BLK_MODES)
michael@0 905 && (ppflags->display_mb_modes_flag || ppflags->display_b_modes_flag)) {
michael@0 906 int y, x;
michael@0 907 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer;
michael@0 908 int width = post->y_width;
michael@0 909 int height = post->y_height;
michael@0 910 uint8_t *y_ptr = cm->post_proc_buffer.y_buffer;
michael@0 911 uint8_t *u_ptr = cm->post_proc_buffer.u_buffer;
michael@0 912 uint8_t *v_ptr = cm->post_proc_buffer.v_buffer;
michael@0 913 int y_stride = cm->post_proc_buffer.y_stride;
michael@0 914 MODE_INFO *mi = cm->mi;
michael@0 915
michael@0 916 for (y = 0; y < height; y += 16) {
michael@0 917 for (x = 0; x < width; x += 16) {
michael@0 918 int Y = 0, U = 0, V = 0;
michael@0 919
michael@0 920 if (mi->mbmi.mode == I4X4_PRED &&
michael@0 921 ((ppflags->display_mb_modes_flag & I4X4_PRED) ||
michael@0 922 ppflags->display_b_modes_flag)) {
michael@0 923 int by, bx;
michael@0 924 uint8_t *yl, *ul, *vl;
michael@0 925 union b_mode_info *bmi = mi->bmi;
michael@0 926
michael@0 927 yl = y_ptr + x;
michael@0 928 ul = u_ptr + (x >> 1);
michael@0 929 vl = v_ptr + (x >> 1);
michael@0 930
michael@0 931 for (by = 0; by < 16; by += 4) {
michael@0 932 for (bx = 0; bx < 16; bx += 4) {
michael@0 933 if ((ppflags->display_b_modes_flag & (1 << mi->mbmi.mode))
michael@0 934 || (ppflags->display_mb_modes_flag & I4X4_PRED)) {
michael@0 935 Y = B_PREDICTION_MODE_colors[bmi->as_mode][0];
michael@0 936 U = B_PREDICTION_MODE_colors[bmi->as_mode][1];
michael@0 937 V = B_PREDICTION_MODE_colors[bmi->as_mode][2];
michael@0 938
michael@0 939 vp9_blend_b(yl + bx, ul + (bx >> 1), vl + (bx >> 1), Y, U, V,
michael@0 940 0xc000, y_stride);
michael@0 941 }
michael@0 942 bmi++;
michael@0 943 }
michael@0 944
michael@0 945 yl += y_stride * 4;
michael@0 946 ul += y_stride * 1;
michael@0 947 vl += y_stride * 1;
michael@0 948 }
michael@0 949 } else if (ppflags->display_mb_modes_flag & (1 << mi->mbmi.mode)) {
michael@0 950 Y = MB_PREDICTION_MODE_colors[mi->mbmi.mode][0];
michael@0 951 U = MB_PREDICTION_MODE_colors[mi->mbmi.mode][1];
michael@0 952 V = MB_PREDICTION_MODE_colors[mi->mbmi.mode][2];
michael@0 953
michael@0 954 vp9_blend_mb_inner(y_ptr + x, u_ptr + (x >> 1), v_ptr + (x >> 1),
michael@0 955 Y, U, V, 0xc000, y_stride);
michael@0 956 }
michael@0 957
michael@0 958 mi++;
michael@0 959 }
michael@0 960 y_ptr += y_stride * 16;
michael@0 961 u_ptr += y_stride * 4;
michael@0 962 v_ptr += y_stride * 4;
michael@0 963
michael@0 964 mi++;
michael@0 965 }
michael@0 966 }
michael@0 967
michael@0 968 /* Color in frame reference blocks */
michael@0 969 if ((flags & VP9D_DEBUG_CLR_FRM_REF_BLKS) &&
michael@0 970 ppflags->display_ref_frame_flag) {
michael@0 971 int y, x;
michael@0 972 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer;
michael@0 973 int width = post->y_width;
michael@0 974 int height = post->y_height;
michael@0 975 uint8_t *y_ptr = cm->post_proc_buffer.y_buffer;
michael@0 976 uint8_t *u_ptr = cm->post_proc_buffer.u_buffer;
michael@0 977 uint8_t *v_ptr = cm->post_proc_buffer.v_buffer;
michael@0 978 int y_stride = cm->post_proc_buffer.y_stride;
michael@0 979 MODE_INFO *mi = cm->mi;
michael@0 980
michael@0 981 for (y = 0; y < height; y += 16) {
michael@0 982 for (x = 0; x < width; x += 16) {
michael@0 983 int Y = 0, U = 0, V = 0;
michael@0 984
michael@0 985 if (ppflags->display_ref_frame_flag & (1 << mi->mbmi.ref_frame)) {
michael@0 986 Y = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][0];
michael@0 987 U = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][1];
michael@0 988 V = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][2];
michael@0 989
michael@0 990 vp9_blend_mb_outer(y_ptr + x, u_ptr + (x >> 1), v_ptr + (x >> 1),
michael@0 991 Y, U, V, 0xc000, y_stride);
michael@0 992 }
michael@0 993
michael@0 994 mi++;
michael@0 995 }
michael@0 996 y_ptr += y_stride * 16;
michael@0 997 u_ptr += y_stride * 4;
michael@0 998 v_ptr += y_stride * 4;
michael@0 999
michael@0 1000 mi++;
michael@0 1001 }
michael@0 1002 }
michael@0 1003 #endif
michael@0 1004
michael@0 1005 *dest = cm->post_proc_buffer;
michael@0 1006
michael@0 1007 /* handle problem with extending borders */
michael@0 1008 dest->y_width = cm->width;
michael@0 1009 dest->y_height = cm->height;
michael@0 1010 dest->uv_width = dest->y_width >> cm->subsampling_x;
michael@0 1011 dest->uv_height = dest->y_height >> cm->subsampling_y;
michael@0 1012
michael@0 1013 return 0;
michael@0 1014 }

mercurial