media/libvpx/vp8/common/postproc.c

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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
michael@0 12 #include "vpx_config.h"
michael@0 13 #include "vp8_rtcd.h"
michael@0 14 #include "vpx_scale_rtcd.h"
michael@0 15 #include "vpx_scale/yv12config.h"
michael@0 16 #include "postproc.h"
michael@0 17 #include "common.h"
michael@0 18 #include "vpx_scale/vpx_scale.h"
michael@0 19 #include "systemdependent.h"
michael@0 20
michael@0 21 #include <limits.h>
michael@0 22 #include <math.h>
michael@0 23 #include <stdlib.h>
michael@0 24 #include <stdio.h>
michael@0 25
michael@0 26 #define RGB_TO_YUV(t) \
michael@0 27 ( (0.257*(float)(t>>16)) + (0.504*(float)(t>>8&0xff)) + (0.098*(float)(t&0xff)) + 16), \
michael@0 28 (-(0.148*(float)(t>>16)) - (0.291*(float)(t>>8&0xff)) + (0.439*(float)(t&0xff)) + 128), \
michael@0 29 ( (0.439*(float)(t>>16)) - (0.368*(float)(t>>8&0xff)) - (0.071*(float)(t&0xff)) + 128)
michael@0 30
michael@0 31 /* global constants */
michael@0 32 #if CONFIG_POSTPROC_VISUALIZER
michael@0 33 static const unsigned char MB_PREDICTION_MODE_colors[MB_MODE_COUNT][3] =
michael@0 34 {
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(0x228B22) }, /* ForestGreen */
michael@0 39 { RGB_TO_YUV(0x006400) }, /* DarkGreen */
michael@0 40 { RGB_TO_YUV(0x98F5FF) }, /* Cadet Blue */
michael@0 41 { RGB_TO_YUV(0x6CA6CD) }, /* Sky Blue */
michael@0 42 { RGB_TO_YUV(0x00008B) }, /* Dark blue */
michael@0 43 { RGB_TO_YUV(0x551A8B) }, /* Purple */
michael@0 44 { RGB_TO_YUV(0xFF0000) } /* Red */
michael@0 45 };
michael@0 46
michael@0 47 static const unsigned char B_PREDICTION_MODE_colors[B_MODE_COUNT][3] =
michael@0 48 {
michael@0 49 { RGB_TO_YUV(0x6633ff) }, /* Purple */
michael@0 50 { RGB_TO_YUV(0xcc33ff) }, /* Magenta */
michael@0 51 { RGB_TO_YUV(0xff33cc) }, /* Pink */
michael@0 52 { RGB_TO_YUV(0xff3366) }, /* Coral */
michael@0 53 { RGB_TO_YUV(0x3366ff) }, /* Blue */
michael@0 54 { RGB_TO_YUV(0xed00f5) }, /* Dark Blue */
michael@0 55 { RGB_TO_YUV(0x2e00b8) }, /* Dark Purple */
michael@0 56 { RGB_TO_YUV(0xff6633) }, /* Orange */
michael@0 57 { RGB_TO_YUV(0x33ccff) }, /* Light Blue */
michael@0 58 { RGB_TO_YUV(0x8ab800) }, /* Green */
michael@0 59 { RGB_TO_YUV(0xffcc33) }, /* Light Orange */
michael@0 60 { RGB_TO_YUV(0x33ffcc) }, /* Aqua */
michael@0 61 { RGB_TO_YUV(0x66ff33) }, /* Light Green */
michael@0 62 { RGB_TO_YUV(0xccff33) }, /* Yellow */
michael@0 63 };
michael@0 64
michael@0 65 static const unsigned char MV_REFERENCE_FRAME_colors[MAX_REF_FRAMES][3] =
michael@0 66 {
michael@0 67 { RGB_TO_YUV(0x00ff00) }, /* Blue */
michael@0 68 { RGB_TO_YUV(0x0000ff) }, /* Green */
michael@0 69 { RGB_TO_YUV(0xffff00) }, /* Yellow */
michael@0 70 { RGB_TO_YUV(0xff0000) }, /* Red */
michael@0 71 };
michael@0 72 #endif
michael@0 73
michael@0 74 static const short kernel5[] =
michael@0 75 {
michael@0 76 1, 1, 4, 1, 1
michael@0 77 };
michael@0 78
michael@0 79 const short vp8_rv[] =
michael@0 80 {
michael@0 81 8, 5, 2, 2, 8, 12, 4, 9, 8, 3,
michael@0 82 0, 3, 9, 0, 0, 0, 8, 3, 14, 4,
michael@0 83 10, 1, 11, 14, 1, 14, 9, 6, 12, 11,
michael@0 84 8, 6, 10, 0, 0, 8, 9, 0, 3, 14,
michael@0 85 8, 11, 13, 4, 2, 9, 0, 3, 9, 6,
michael@0 86 1, 2, 3, 14, 13, 1, 8, 2, 9, 7,
michael@0 87 3, 3, 1, 13, 13, 6, 6, 5, 2, 7,
michael@0 88 11, 9, 11, 8, 7, 3, 2, 0, 13, 13,
michael@0 89 14, 4, 12, 5, 12, 10, 8, 10, 13, 10,
michael@0 90 4, 14, 4, 10, 0, 8, 11, 1, 13, 7,
michael@0 91 7, 14, 6, 14, 13, 2, 13, 5, 4, 4,
michael@0 92 0, 10, 0, 5, 13, 2, 12, 7, 11, 13,
michael@0 93 8, 0, 4, 10, 7, 2, 7, 2, 2, 5,
michael@0 94 3, 4, 7, 3, 3, 14, 14, 5, 9, 13,
michael@0 95 3, 14, 3, 6, 3, 0, 11, 8, 13, 1,
michael@0 96 13, 1, 12, 0, 10, 9, 7, 6, 2, 8,
michael@0 97 5, 2, 13, 7, 1, 13, 14, 7, 6, 7,
michael@0 98 9, 6, 10, 11, 7, 8, 7, 5, 14, 8,
michael@0 99 4, 4, 0, 8, 7, 10, 0, 8, 14, 11,
michael@0 100 3, 12, 5, 7, 14, 3, 14, 5, 2, 6,
michael@0 101 11, 12, 12, 8, 0, 11, 13, 1, 2, 0,
michael@0 102 5, 10, 14, 7, 8, 0, 4, 11, 0, 8,
michael@0 103 0, 3, 10, 5, 8, 0, 11, 6, 7, 8,
michael@0 104 10, 7, 13, 9, 2, 5, 1, 5, 10, 2,
michael@0 105 4, 3, 5, 6, 10, 8, 9, 4, 11, 14,
michael@0 106 0, 10, 0, 5, 13, 2, 12, 7, 11, 13,
michael@0 107 8, 0, 4, 10, 7, 2, 7, 2, 2, 5,
michael@0 108 3, 4, 7, 3, 3, 14, 14, 5, 9, 13,
michael@0 109 3, 14, 3, 6, 3, 0, 11, 8, 13, 1,
michael@0 110 13, 1, 12, 0, 10, 9, 7, 6, 2, 8,
michael@0 111 5, 2, 13, 7, 1, 13, 14, 7, 6, 7,
michael@0 112 9, 6, 10, 11, 7, 8, 7, 5, 14, 8,
michael@0 113 4, 4, 0, 8, 7, 10, 0, 8, 14, 11,
michael@0 114 3, 12, 5, 7, 14, 3, 14, 5, 2, 6,
michael@0 115 11, 12, 12, 8, 0, 11, 13, 1, 2, 0,
michael@0 116 5, 10, 14, 7, 8, 0, 4, 11, 0, 8,
michael@0 117 0, 3, 10, 5, 8, 0, 11, 6, 7, 8,
michael@0 118 10, 7, 13, 9, 2, 5, 1, 5, 10, 2,
michael@0 119 4, 3, 5, 6, 10, 8, 9, 4, 11, 14,
michael@0 120 3, 8, 3, 7, 8, 5, 11, 4, 12, 3,
michael@0 121 11, 9, 14, 8, 14, 13, 4, 3, 1, 2,
michael@0 122 14, 6, 5, 4, 4, 11, 4, 6, 2, 1,
michael@0 123 5, 8, 8, 12, 13, 5, 14, 10, 12, 13,
michael@0 124 0, 9, 5, 5, 11, 10, 13, 9, 10, 13,
michael@0 125 };
michael@0 126
michael@0 127 extern void vp8_blit_text(const char *msg, unsigned char *address, const int pitch);
michael@0 128 extern void vp8_blit_line(int x0, int x1, int y0, int y1, unsigned char *image, const int pitch);
michael@0 129 /***********************************************************************************************************
michael@0 130 */
michael@0 131 void vp8_post_proc_down_and_across_mb_row_c
michael@0 132 (
michael@0 133 unsigned char *src_ptr,
michael@0 134 unsigned char *dst_ptr,
michael@0 135 int src_pixels_per_line,
michael@0 136 int dst_pixels_per_line,
michael@0 137 int cols,
michael@0 138 unsigned char *f,
michael@0 139 int size
michael@0 140 )
michael@0 141 {
michael@0 142 unsigned char *p_src, *p_dst;
michael@0 143 int row;
michael@0 144 int col;
michael@0 145 unsigned char v;
michael@0 146 unsigned char d[4];
michael@0 147
michael@0 148 for (row = 0; row < size; row++)
michael@0 149 {
michael@0 150 /* post_proc_down for one row */
michael@0 151 p_src = src_ptr;
michael@0 152 p_dst = dst_ptr;
michael@0 153
michael@0 154 for (col = 0; col < cols; col++)
michael@0 155 {
michael@0 156 unsigned char p_above2 = p_src[col - 2 * src_pixels_per_line];
michael@0 157 unsigned char p_above1 = p_src[col - src_pixels_per_line];
michael@0 158 unsigned char p_below1 = p_src[col + src_pixels_per_line];
michael@0 159 unsigned char p_below2 = p_src[col + 2 * src_pixels_per_line];
michael@0 160
michael@0 161 v = p_src[col];
michael@0 162
michael@0 163 if ((abs(v - p_above2) < f[col]) && (abs(v - p_above1) < f[col])
michael@0 164 && (abs(v - p_below1) < f[col]) && (abs(v - p_below2) < f[col]))
michael@0 165 {
michael@0 166 unsigned char k1, k2, k3;
michael@0 167 k1 = (p_above2 + p_above1 + 1) >> 1;
michael@0 168 k2 = (p_below2 + p_below1 + 1) >> 1;
michael@0 169 k3 = (k1 + k2 + 1) >> 1;
michael@0 170 v = (k3 + v + 1) >> 1;
michael@0 171 }
michael@0 172
michael@0 173 p_dst[col] = v;
michael@0 174 }
michael@0 175
michael@0 176 /* now post_proc_across */
michael@0 177 p_src = dst_ptr;
michael@0 178 p_dst = dst_ptr;
michael@0 179
michael@0 180 p_src[-2] = p_src[-1] = p_src[0];
michael@0 181 p_src[cols] = p_src[cols + 1] = p_src[cols - 1];
michael@0 182
michael@0 183 for (col = 0; col < cols; col++)
michael@0 184 {
michael@0 185 v = p_src[col];
michael@0 186
michael@0 187 if ((abs(v - p_src[col - 2]) < f[col])
michael@0 188 && (abs(v - p_src[col - 1]) < f[col])
michael@0 189 && (abs(v - p_src[col + 1]) < f[col])
michael@0 190 && (abs(v - p_src[col + 2]) < f[col]))
michael@0 191 {
michael@0 192 unsigned char k1, k2, k3;
michael@0 193 k1 = (p_src[col - 2] + p_src[col - 1] + 1) >> 1;
michael@0 194 k2 = (p_src[col + 2] + p_src[col + 1] + 1) >> 1;
michael@0 195 k3 = (k1 + k2 + 1) >> 1;
michael@0 196 v = (k3 + v + 1) >> 1;
michael@0 197 }
michael@0 198
michael@0 199 d[col & 3] = v;
michael@0 200
michael@0 201 if (col >= 2)
michael@0 202 p_dst[col - 2] = d[(col - 2) & 3];
michael@0 203 }
michael@0 204
michael@0 205 /* handle the last two pixels */
michael@0 206 p_dst[col - 2] = d[(col - 2) & 3];
michael@0 207 p_dst[col - 1] = d[(col - 1) & 3];
michael@0 208
michael@0 209 /* next row */
michael@0 210 src_ptr += src_pixels_per_line;
michael@0 211 dst_ptr += dst_pixels_per_line;
michael@0 212 }
michael@0 213 }
michael@0 214
michael@0 215 static int q2mbl(int x)
michael@0 216 {
michael@0 217 if (x < 20) x = 20;
michael@0 218
michael@0 219 x = 50 + (x - 50) * 10 / 8;
michael@0 220 return x * x / 3;
michael@0 221 }
michael@0 222 void vp8_mbpost_proc_across_ip_c(unsigned char *src, int pitch, int rows, int cols, int flimit)
michael@0 223 {
michael@0 224 int r, c, i;
michael@0 225
michael@0 226 unsigned char *s = src;
michael@0 227 unsigned char d[16];
michael@0 228
michael@0 229 for (r = 0; r < rows; r++)
michael@0 230 {
michael@0 231 int sumsq = 0;
michael@0 232 int sum = 0;
michael@0 233
michael@0 234 for (i = -8; i<0; i++)
michael@0 235 s[i]=s[0];
michael@0 236
michael@0 237 /* 17 avoids valgrind warning - we buffer values in c in d
michael@0 238 * and only write them when we've read 8 ahead...
michael@0 239 */
michael@0 240 for (i = cols; i<cols+17; i++)
michael@0 241 s[i]=s[cols-1];
michael@0 242
michael@0 243 for (i = -8; i <= 6; i++)
michael@0 244 {
michael@0 245 sumsq += s[i] * s[i];
michael@0 246 sum += s[i];
michael@0 247 d[i+8] = 0;
michael@0 248 }
michael@0 249
michael@0 250 for (c = 0; c < cols + 8; c++)
michael@0 251 {
michael@0 252 int x = s[c+7] - s[c-8];
michael@0 253 int y = s[c+7] + s[c-8];
michael@0 254
michael@0 255 sum += x;
michael@0 256 sumsq += x * y;
michael@0 257
michael@0 258 d[c&15] = s[c];
michael@0 259
michael@0 260 if (sumsq * 15 - sum * sum < flimit)
michael@0 261 {
michael@0 262 d[c&15] = (8 + sum + s[c]) >> 4;
michael@0 263 }
michael@0 264
michael@0 265 s[c-8] = d[(c-8)&15];
michael@0 266 }
michael@0 267
michael@0 268 s += pitch;
michael@0 269 }
michael@0 270 }
michael@0 271
michael@0 272
michael@0 273 void vp8_mbpost_proc_down_c(unsigned char *dst, int pitch, int rows, int cols, int flimit)
michael@0 274 {
michael@0 275 int r, c, i;
michael@0 276 const short *rv3 = &vp8_rv[63&rand()];
michael@0 277
michael@0 278 for (c = 0; c < cols; c++ )
michael@0 279 {
michael@0 280 unsigned char *s = &dst[c];
michael@0 281 int sumsq = 0;
michael@0 282 int sum = 0;
michael@0 283 unsigned char d[16];
michael@0 284 const short *rv2 = rv3 + ((c * 17) & 127);
michael@0 285
michael@0 286 for (i = -8; i < 0; i++)
michael@0 287 s[i*pitch]=s[0];
michael@0 288
michael@0 289 /* 17 avoids valgrind warning - we buffer values in c in d
michael@0 290 * and only write them when we've read 8 ahead...
michael@0 291 */
michael@0 292 for (i = rows; i < rows+17; i++)
michael@0 293 s[i*pitch]=s[(rows-1)*pitch];
michael@0 294
michael@0 295 for (i = -8; i <= 6; i++)
michael@0 296 {
michael@0 297 sumsq += s[i*pitch] * s[i*pitch];
michael@0 298 sum += s[i*pitch];
michael@0 299 }
michael@0 300
michael@0 301 for (r = 0; r < rows + 8; r++)
michael@0 302 {
michael@0 303 sumsq += s[7*pitch] * s[ 7*pitch] - s[-8*pitch] * s[-8*pitch];
michael@0 304 sum += s[7*pitch] - s[-8*pitch];
michael@0 305 d[r&15] = s[0];
michael@0 306
michael@0 307 if (sumsq * 15 - sum * sum < flimit)
michael@0 308 {
michael@0 309 d[r&15] = (rv2[r&127] + sum + s[0]) >> 4;
michael@0 310 }
michael@0 311
michael@0 312 s[-8*pitch] = d[(r-8)&15];
michael@0 313 s += pitch;
michael@0 314 }
michael@0 315 }
michael@0 316 }
michael@0 317
michael@0 318 static void vp8_de_mblock(YV12_BUFFER_CONFIG *post,
michael@0 319 int q)
michael@0 320 {
michael@0 321 vp8_mbpost_proc_across_ip(post->y_buffer, post->y_stride, post->y_height,
michael@0 322 post->y_width, q2mbl(q));
michael@0 323 vp8_mbpost_proc_down(post->y_buffer, post->y_stride, post->y_height,
michael@0 324 post->y_width, q2mbl(q));
michael@0 325 }
michael@0 326
michael@0 327 void vp8_deblock(VP8_COMMON *cm,
michael@0 328 YV12_BUFFER_CONFIG *source,
michael@0 329 YV12_BUFFER_CONFIG *post,
michael@0 330 int q,
michael@0 331 int low_var_thresh,
michael@0 332 int flag)
michael@0 333 {
michael@0 334 double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065;
michael@0 335 int ppl = (int)(level + .5);
michael@0 336
michael@0 337 const MODE_INFO *mode_info_context = cm->show_frame_mi;
michael@0 338 int mbr, mbc;
michael@0 339
michael@0 340 /* The pixel thresholds are adjusted according to if or not the macroblock
michael@0 341 * is a skipped block. */
michael@0 342 unsigned char *ylimits = cm->pp_limits_buffer;
michael@0 343 unsigned char *uvlimits = cm->pp_limits_buffer + 16 * cm->mb_cols;
michael@0 344 (void) low_var_thresh;
michael@0 345 (void) flag;
michael@0 346
michael@0 347 if (ppl > 0)
michael@0 348 {
michael@0 349 for (mbr = 0; mbr < cm->mb_rows; mbr++)
michael@0 350 {
michael@0 351 unsigned char *ylptr = ylimits;
michael@0 352 unsigned char *uvlptr = uvlimits;
michael@0 353 for (mbc = 0; mbc < cm->mb_cols; mbc++)
michael@0 354 {
michael@0 355 unsigned char mb_ppl;
michael@0 356
michael@0 357 if (mode_info_context->mbmi.mb_skip_coeff)
michael@0 358 mb_ppl = (unsigned char)ppl >> 1;
michael@0 359 else
michael@0 360 mb_ppl = (unsigned char)ppl;
michael@0 361
michael@0 362 vpx_memset(ylptr, mb_ppl, 16);
michael@0 363 vpx_memset(uvlptr, mb_ppl, 8);
michael@0 364
michael@0 365 ylptr += 16;
michael@0 366 uvlptr += 8;
michael@0 367 mode_info_context++;
michael@0 368 }
michael@0 369 mode_info_context++;
michael@0 370
michael@0 371 vp8_post_proc_down_and_across_mb_row(
michael@0 372 source->y_buffer + 16 * mbr * source->y_stride,
michael@0 373 post->y_buffer + 16 * mbr * post->y_stride, source->y_stride,
michael@0 374 post->y_stride, source->y_width, ylimits, 16);
michael@0 375
michael@0 376 vp8_post_proc_down_and_across_mb_row(
michael@0 377 source->u_buffer + 8 * mbr * source->uv_stride,
michael@0 378 post->u_buffer + 8 * mbr * post->uv_stride, source->uv_stride,
michael@0 379 post->uv_stride, source->uv_width, uvlimits, 8);
michael@0 380 vp8_post_proc_down_and_across_mb_row(
michael@0 381 source->v_buffer + 8 * mbr * source->uv_stride,
michael@0 382 post->v_buffer + 8 * mbr * post->uv_stride, source->uv_stride,
michael@0 383 post->uv_stride, source->uv_width, uvlimits, 8);
michael@0 384 }
michael@0 385 } else
michael@0 386 {
michael@0 387 vp8_yv12_copy_frame(source, post);
michael@0 388 }
michael@0 389 }
michael@0 390
michael@0 391 #if !(CONFIG_TEMPORAL_DENOISING)
michael@0 392 void vp8_de_noise(VP8_COMMON *cm,
michael@0 393 YV12_BUFFER_CONFIG *source,
michael@0 394 YV12_BUFFER_CONFIG *post,
michael@0 395 int q,
michael@0 396 int low_var_thresh,
michael@0 397 int flag)
michael@0 398 {
michael@0 399 double level = 6.0e-05 * q * q * q - .0067 * q * q + .306 * q + .0065;
michael@0 400 int ppl = (int)(level + .5);
michael@0 401 int mb_rows = source->y_width >> 4;
michael@0 402 int mb_cols = source->y_height >> 4;
michael@0 403 unsigned char *limits = cm->pp_limits_buffer;;
michael@0 404 int mbr, mbc;
michael@0 405 (void) post;
michael@0 406 (void) low_var_thresh;
michael@0 407 (void) flag;
michael@0 408
michael@0 409 vpx_memset(limits, (unsigned char)ppl, 16 * mb_cols);
michael@0 410
michael@0 411 /* TODO: The original code don't filter the 2 outer rows and columns. */
michael@0 412 for (mbr = 0; mbr < mb_rows; mbr++)
michael@0 413 {
michael@0 414 vp8_post_proc_down_and_across_mb_row(
michael@0 415 source->y_buffer + 16 * mbr * source->y_stride,
michael@0 416 source->y_buffer + 16 * mbr * source->y_stride,
michael@0 417 source->y_stride, source->y_stride, source->y_width, limits, 16);
michael@0 418
michael@0 419 vp8_post_proc_down_and_across_mb_row(
michael@0 420 source->u_buffer + 8 * mbr * source->uv_stride,
michael@0 421 source->u_buffer + 8 * mbr * source->uv_stride,
michael@0 422 source->uv_stride, source->uv_stride, source->uv_width, limits, 8);
michael@0 423 vp8_post_proc_down_and_across_mb_row(
michael@0 424 source->v_buffer + 8 * mbr * source->uv_stride,
michael@0 425 source->v_buffer + 8 * mbr * source->uv_stride,
michael@0 426 source->uv_stride, source->uv_stride, source->uv_width, limits, 8);
michael@0 427 }
michael@0 428 }
michael@0 429 #endif
michael@0 430
michael@0 431 double vp8_gaussian(double sigma, double mu, double x)
michael@0 432 {
michael@0 433 return 1 / (sigma * sqrt(2.0 * 3.14159265)) *
michael@0 434 (exp(-(x - mu) * (x - mu) / (2 * sigma * sigma)));
michael@0 435 }
michael@0 436
michael@0 437 static void fillrd(struct postproc_state *state, int q, int a)
michael@0 438 {
michael@0 439 char char_dist[300];
michael@0 440
michael@0 441 double sigma;
michael@0 442 int i;
michael@0 443
michael@0 444 vp8_clear_system_state();
michael@0 445
michael@0 446
michael@0 447 sigma = a + .5 + .6 * (63 - q) / 63.0;
michael@0 448
michael@0 449 /* set up a lookup table of 256 entries that matches
michael@0 450 * a gaussian distribution with sigma determined by q.
michael@0 451 */
michael@0 452 {
michael@0 453 int next, j;
michael@0 454
michael@0 455 next = 0;
michael@0 456
michael@0 457 for (i = -32; i < 32; i++)
michael@0 458 {
michael@0 459 const int v = (int)(.5 + 256 * vp8_gaussian(sigma, 0, i));
michael@0 460
michael@0 461 if (v)
michael@0 462 {
michael@0 463 for (j = 0; j < v; j++)
michael@0 464 {
michael@0 465 char_dist[next+j] = (char) i;
michael@0 466 }
michael@0 467
michael@0 468 next = next + j;
michael@0 469 }
michael@0 470
michael@0 471 }
michael@0 472
michael@0 473 for (; next < 256; next++)
michael@0 474 char_dist[next] = 0;
michael@0 475
michael@0 476 }
michael@0 477
michael@0 478 for (i = 0; i < 3072; i++)
michael@0 479 {
michael@0 480 state->noise[i] = char_dist[rand() & 0xff];
michael@0 481 }
michael@0 482
michael@0 483 for (i = 0; i < 16; i++)
michael@0 484 {
michael@0 485 state->blackclamp[i] = -char_dist[0];
michael@0 486 state->whiteclamp[i] = -char_dist[0];
michael@0 487 state->bothclamp[i] = -2 * char_dist[0];
michael@0 488 }
michael@0 489
michael@0 490 state->last_q = q;
michael@0 491 state->last_noise = a;
michael@0 492 }
michael@0 493
michael@0 494 /****************************************************************************
michael@0 495 *
michael@0 496 * ROUTINE : plane_add_noise_c
michael@0 497 *
michael@0 498 * INPUTS : unsigned char *Start starting address of buffer to add gaussian
michael@0 499 * noise to
michael@0 500 * unsigned int Width width of plane
michael@0 501 * unsigned int Height height of plane
michael@0 502 * int Pitch distance between subsequent lines of frame
michael@0 503 * int q quantizer used to determine amount of noise
michael@0 504 * to add
michael@0 505 *
michael@0 506 * OUTPUTS : None.
michael@0 507 *
michael@0 508 * RETURNS : void.
michael@0 509 *
michael@0 510 * FUNCTION : adds gaussian noise to a plane of pixels
michael@0 511 *
michael@0 512 * SPECIAL NOTES : None.
michael@0 513 *
michael@0 514 ****************************************************************************/
michael@0 515 void vp8_plane_add_noise_c(unsigned char *Start, char *noise,
michael@0 516 char blackclamp[16],
michael@0 517 char whiteclamp[16],
michael@0 518 char bothclamp[16],
michael@0 519 unsigned int Width, unsigned int Height, int Pitch)
michael@0 520 {
michael@0 521 unsigned int i, j;
michael@0 522
michael@0 523 for (i = 0; i < Height; i++)
michael@0 524 {
michael@0 525 unsigned char *Pos = Start + i * Pitch;
michael@0 526 char *Ref = (char *)(noise + (rand() & 0xff));
michael@0 527
michael@0 528 for (j = 0; j < Width; j++)
michael@0 529 {
michael@0 530 if (Pos[j] < blackclamp[0])
michael@0 531 Pos[j] = blackclamp[0];
michael@0 532
michael@0 533 if (Pos[j] > 255 + whiteclamp[0])
michael@0 534 Pos[j] = 255 + whiteclamp[0];
michael@0 535
michael@0 536 Pos[j] += Ref[j];
michael@0 537 }
michael@0 538 }
michael@0 539 }
michael@0 540
michael@0 541 /* Blend the macro block with a solid colored square. Leave the
michael@0 542 * edges unblended to give distinction to macro blocks in areas
michael@0 543 * filled with the same color block.
michael@0 544 */
michael@0 545 void vp8_blend_mb_inner_c (unsigned char *y, unsigned char *u, unsigned char *v,
michael@0 546 int y_1, int u_1, int v_1, int alpha, int stride)
michael@0 547 {
michael@0 548 int i, j;
michael@0 549 int y1_const = y_1*((1<<16)-alpha);
michael@0 550 int u1_const = u_1*((1<<16)-alpha);
michael@0 551 int v1_const = v_1*((1<<16)-alpha);
michael@0 552
michael@0 553 y += 2*stride + 2;
michael@0 554 for (i = 0; i < 12; i++)
michael@0 555 {
michael@0 556 for (j = 0; j < 12; j++)
michael@0 557 {
michael@0 558 y[j] = (y[j]*alpha + y1_const)>>16;
michael@0 559 }
michael@0 560 y += stride;
michael@0 561 }
michael@0 562
michael@0 563 stride >>= 1;
michael@0 564
michael@0 565 u += stride + 1;
michael@0 566 v += stride + 1;
michael@0 567
michael@0 568 for (i = 0; i < 6; i++)
michael@0 569 {
michael@0 570 for (j = 0; j < 6; j++)
michael@0 571 {
michael@0 572 u[j] = (u[j]*alpha + u1_const)>>16;
michael@0 573 v[j] = (v[j]*alpha + v1_const)>>16;
michael@0 574 }
michael@0 575 u += stride;
michael@0 576 v += stride;
michael@0 577 }
michael@0 578 }
michael@0 579
michael@0 580 /* Blend only the edge of the macro block. Leave center
michael@0 581 * unblended to allow for other visualizations to be layered.
michael@0 582 */
michael@0 583 void vp8_blend_mb_outer_c (unsigned char *y, unsigned char *u, unsigned char *v,
michael@0 584 int y_1, int u_1, int v_1, int alpha, int stride)
michael@0 585 {
michael@0 586 int i, j;
michael@0 587 int y1_const = y_1*((1<<16)-alpha);
michael@0 588 int u1_const = u_1*((1<<16)-alpha);
michael@0 589 int v1_const = v_1*((1<<16)-alpha);
michael@0 590
michael@0 591 for (i = 0; i < 2; i++)
michael@0 592 {
michael@0 593 for (j = 0; j < 16; j++)
michael@0 594 {
michael@0 595 y[j] = (y[j]*alpha + y1_const)>>16;
michael@0 596 }
michael@0 597 y += stride;
michael@0 598 }
michael@0 599
michael@0 600 for (i = 0; i < 12; i++)
michael@0 601 {
michael@0 602 y[0] = (y[0]*alpha + y1_const)>>16;
michael@0 603 y[1] = (y[1]*alpha + y1_const)>>16;
michael@0 604 y[14] = (y[14]*alpha + y1_const)>>16;
michael@0 605 y[15] = (y[15]*alpha + y1_const)>>16;
michael@0 606 y += stride;
michael@0 607 }
michael@0 608
michael@0 609 for (i = 0; i < 2; i++)
michael@0 610 {
michael@0 611 for (j = 0; j < 16; j++)
michael@0 612 {
michael@0 613 y[j] = (y[j]*alpha + y1_const)>>16;
michael@0 614 }
michael@0 615 y += stride;
michael@0 616 }
michael@0 617
michael@0 618 stride >>= 1;
michael@0 619
michael@0 620 for (j = 0; j < 8; j++)
michael@0 621 {
michael@0 622 u[j] = (u[j]*alpha + u1_const)>>16;
michael@0 623 v[j] = (v[j]*alpha + v1_const)>>16;
michael@0 624 }
michael@0 625 u += stride;
michael@0 626 v += stride;
michael@0 627
michael@0 628 for (i = 0; i < 6; i++)
michael@0 629 {
michael@0 630 u[0] = (u[0]*alpha + u1_const)>>16;
michael@0 631 v[0] = (v[0]*alpha + v1_const)>>16;
michael@0 632
michael@0 633 u[7] = (u[7]*alpha + u1_const)>>16;
michael@0 634 v[7] = (v[7]*alpha + v1_const)>>16;
michael@0 635
michael@0 636 u += stride;
michael@0 637 v += stride;
michael@0 638 }
michael@0 639
michael@0 640 for (j = 0; j < 8; j++)
michael@0 641 {
michael@0 642 u[j] = (u[j]*alpha + u1_const)>>16;
michael@0 643 v[j] = (v[j]*alpha + v1_const)>>16;
michael@0 644 }
michael@0 645 }
michael@0 646
michael@0 647 void vp8_blend_b_c (unsigned char *y, unsigned char *u, unsigned char *v,
michael@0 648 int y_1, int u_1, int v_1, int alpha, int stride)
michael@0 649 {
michael@0 650 int i, j;
michael@0 651 int y1_const = y_1*((1<<16)-alpha);
michael@0 652 int u1_const = u_1*((1<<16)-alpha);
michael@0 653 int v1_const = v_1*((1<<16)-alpha);
michael@0 654
michael@0 655 for (i = 0; i < 4; i++)
michael@0 656 {
michael@0 657 for (j = 0; j < 4; j++)
michael@0 658 {
michael@0 659 y[j] = (y[j]*alpha + y1_const)>>16;
michael@0 660 }
michael@0 661 y += stride;
michael@0 662 }
michael@0 663
michael@0 664 stride >>= 1;
michael@0 665
michael@0 666 for (i = 0; i < 2; i++)
michael@0 667 {
michael@0 668 for (j = 0; j < 2; j++)
michael@0 669 {
michael@0 670 u[j] = (u[j]*alpha + u1_const)>>16;
michael@0 671 v[j] = (v[j]*alpha + v1_const)>>16;
michael@0 672 }
michael@0 673 u += stride;
michael@0 674 v += stride;
michael@0 675 }
michael@0 676 }
michael@0 677
michael@0 678 static void constrain_line (int x_0, int *x_1, int y_0, int *y_1, int width, int height)
michael@0 679 {
michael@0 680 int dx;
michael@0 681 int dy;
michael@0 682
michael@0 683 if (*x_1 > width)
michael@0 684 {
michael@0 685 dx = *x_1 - x_0;
michael@0 686 dy = *y_1 - y_0;
michael@0 687
michael@0 688 *x_1 = width;
michael@0 689 if (dx)
michael@0 690 *y_1 = ((width-x_0)*dy)/dx + y_0;
michael@0 691 }
michael@0 692 if (*x_1 < 0)
michael@0 693 {
michael@0 694 dx = *x_1 - x_0;
michael@0 695 dy = *y_1 - y_0;
michael@0 696
michael@0 697 *x_1 = 0;
michael@0 698 if (dx)
michael@0 699 *y_1 = ((0-x_0)*dy)/dx + y_0;
michael@0 700 }
michael@0 701 if (*y_1 > height)
michael@0 702 {
michael@0 703 dx = *x_1 - x_0;
michael@0 704 dy = *y_1 - y_0;
michael@0 705
michael@0 706 *y_1 = height;
michael@0 707 if (dy)
michael@0 708 *x_1 = ((height-y_0)*dx)/dy + x_0;
michael@0 709 }
michael@0 710 if (*y_1 < 0)
michael@0 711 {
michael@0 712 dx = *x_1 - x_0;
michael@0 713 dy = *y_1 - y_0;
michael@0 714
michael@0 715 *y_1 = 0;
michael@0 716 if (dy)
michael@0 717 *x_1 = ((0-y_0)*dx)/dy + x_0;
michael@0 718 }
michael@0 719 }
michael@0 720
michael@0 721 #if CONFIG_POSTPROC
michael@0 722 int vp8_post_proc_frame(VP8_COMMON *oci, YV12_BUFFER_CONFIG *dest, vp8_ppflags_t *ppflags)
michael@0 723 {
michael@0 724 int q = oci->filter_level * 10 / 6;
michael@0 725 int flags = ppflags->post_proc_flag;
michael@0 726 int deblock_level = ppflags->deblocking_level;
michael@0 727 int noise_level = ppflags->noise_level;
michael@0 728
michael@0 729 if (!oci->frame_to_show)
michael@0 730 return -1;
michael@0 731
michael@0 732 if (q > 63)
michael@0 733 q = 63;
michael@0 734
michael@0 735 if (!flags)
michael@0 736 {
michael@0 737 *dest = *oci->frame_to_show;
michael@0 738
michael@0 739 /* handle problem with extending borders */
michael@0 740 dest->y_width = oci->Width;
michael@0 741 dest->y_height = oci->Height;
michael@0 742 dest->uv_height = dest->y_height / 2;
michael@0 743 oci->postproc_state.last_base_qindex = oci->base_qindex;
michael@0 744 oci->postproc_state.last_frame_valid = 1;
michael@0 745 return 0;
michael@0 746 }
michael@0 747
michael@0 748 /* Allocate post_proc_buffer_int if needed */
michael@0 749 if ((flags & VP8D_MFQE) && !oci->post_proc_buffer_int_used)
michael@0 750 {
michael@0 751 if ((flags & VP8D_DEBLOCK) || (flags & VP8D_DEMACROBLOCK))
michael@0 752 {
michael@0 753 int width = (oci->Width + 15) & ~15;
michael@0 754 int height = (oci->Height + 15) & ~15;
michael@0 755
michael@0 756 if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer_int,
michael@0 757 width, height, VP8BORDERINPIXELS))
michael@0 758 vpx_internal_error(&oci->error, VPX_CODEC_MEM_ERROR,
michael@0 759 "Failed to allocate MFQE framebuffer");
michael@0 760
michael@0 761 oci->post_proc_buffer_int_used = 1;
michael@0 762
michael@0 763 /* insure that postproc is set to all 0's so that post proc
michael@0 764 * doesn't pull random data in from edge
michael@0 765 */
michael@0 766 vpx_memset((&oci->post_proc_buffer_int)->buffer_alloc,128,(&oci->post_proc_buffer)->frame_size);
michael@0 767
michael@0 768 }
michael@0 769 }
michael@0 770
michael@0 771 vp8_clear_system_state();
michael@0 772
michael@0 773 if ((flags & VP8D_MFQE) &&
michael@0 774 oci->postproc_state.last_frame_valid &&
michael@0 775 oci->current_video_frame >= 2 &&
michael@0 776 oci->postproc_state.last_base_qindex < 60 &&
michael@0 777 oci->base_qindex - oci->postproc_state.last_base_qindex >= 20)
michael@0 778 {
michael@0 779 vp8_multiframe_quality_enhance(oci);
michael@0 780 if (((flags & VP8D_DEBLOCK) || (flags & VP8D_DEMACROBLOCK)) &&
michael@0 781 oci->post_proc_buffer_int_used)
michael@0 782 {
michael@0 783 vp8_yv12_copy_frame(&oci->post_proc_buffer, &oci->post_proc_buffer_int);
michael@0 784 if (flags & VP8D_DEMACROBLOCK)
michael@0 785 {
michael@0 786 vp8_deblock(oci, &oci->post_proc_buffer_int, &oci->post_proc_buffer,
michael@0 787 q + (deblock_level - 5) * 10, 1, 0);
michael@0 788 vp8_de_mblock(&oci->post_proc_buffer,
michael@0 789 q + (deblock_level - 5) * 10);
michael@0 790 }
michael@0 791 else if (flags & VP8D_DEBLOCK)
michael@0 792 {
michael@0 793 vp8_deblock(oci, &oci->post_proc_buffer_int, &oci->post_proc_buffer,
michael@0 794 q, 1, 0);
michael@0 795 }
michael@0 796 }
michael@0 797 /* Move partially towards the base q of the previous frame */
michael@0 798 oci->postproc_state.last_base_qindex = (3*oci->postproc_state.last_base_qindex + oci->base_qindex)>>2;
michael@0 799 }
michael@0 800 else if (flags & VP8D_DEMACROBLOCK)
michael@0 801 {
michael@0 802 vp8_deblock(oci, oci->frame_to_show, &oci->post_proc_buffer,
michael@0 803 q + (deblock_level - 5) * 10, 1, 0);
michael@0 804 vp8_de_mblock(&oci->post_proc_buffer, q + (deblock_level - 5) * 10);
michael@0 805
michael@0 806 oci->postproc_state.last_base_qindex = oci->base_qindex;
michael@0 807 }
michael@0 808 else if (flags & VP8D_DEBLOCK)
michael@0 809 {
michael@0 810 vp8_deblock(oci, oci->frame_to_show, &oci->post_proc_buffer,
michael@0 811 q, 1, 0);
michael@0 812 oci->postproc_state.last_base_qindex = oci->base_qindex;
michael@0 813 }
michael@0 814 else
michael@0 815 {
michael@0 816 vp8_yv12_copy_frame(oci->frame_to_show, &oci->post_proc_buffer);
michael@0 817 oci->postproc_state.last_base_qindex = oci->base_qindex;
michael@0 818 }
michael@0 819 oci->postproc_state.last_frame_valid = 1;
michael@0 820
michael@0 821 if (flags & VP8D_ADDNOISE)
michael@0 822 {
michael@0 823 if (oci->postproc_state.last_q != q
michael@0 824 || oci->postproc_state.last_noise != noise_level)
michael@0 825 {
michael@0 826 fillrd(&oci->postproc_state, 63 - q, noise_level);
michael@0 827 }
michael@0 828
michael@0 829 vp8_plane_add_noise
michael@0 830 (oci->post_proc_buffer.y_buffer,
michael@0 831 oci->postproc_state.noise,
michael@0 832 oci->postproc_state.blackclamp,
michael@0 833 oci->postproc_state.whiteclamp,
michael@0 834 oci->postproc_state.bothclamp,
michael@0 835 oci->post_proc_buffer.y_width, oci->post_proc_buffer.y_height,
michael@0 836 oci->post_proc_buffer.y_stride);
michael@0 837 }
michael@0 838
michael@0 839 #if CONFIG_POSTPROC_VISUALIZER
michael@0 840 if (flags & VP8D_DEBUG_TXT_FRAME_INFO)
michael@0 841 {
michael@0 842 char message[512];
michael@0 843 sprintf(message, "F%1dG%1dQ%3dF%3dP%d_s%dx%d",
michael@0 844 (oci->frame_type == KEY_FRAME),
michael@0 845 oci->refresh_golden_frame,
michael@0 846 oci->base_qindex,
michael@0 847 oci->filter_level,
michael@0 848 flags,
michael@0 849 oci->mb_cols, oci->mb_rows);
michael@0 850 vp8_blit_text(message, oci->post_proc_buffer.y_buffer, oci->post_proc_buffer.y_stride);
michael@0 851 }
michael@0 852
michael@0 853 if (flags & VP8D_DEBUG_TXT_MBLK_MODES)
michael@0 854 {
michael@0 855 int i, j;
michael@0 856 unsigned char *y_ptr;
michael@0 857 YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
michael@0 858 int mb_rows = post->y_height >> 4;
michael@0 859 int mb_cols = post->y_width >> 4;
michael@0 860 int mb_index = 0;
michael@0 861 MODE_INFO *mi = oci->mi;
michael@0 862
michael@0 863 y_ptr = post->y_buffer + 4 * post->y_stride + 4;
michael@0 864
michael@0 865 /* vp8_filter each macro block */
michael@0 866 for (i = 0; i < mb_rows; i++)
michael@0 867 {
michael@0 868 for (j = 0; j < mb_cols; j++)
michael@0 869 {
michael@0 870 char zz[4];
michael@0 871
michael@0 872 sprintf(zz, "%c", mi[mb_index].mbmi.mode + 'a');
michael@0 873
michael@0 874 vp8_blit_text(zz, y_ptr, post->y_stride);
michael@0 875 mb_index ++;
michael@0 876 y_ptr += 16;
michael@0 877 }
michael@0 878
michael@0 879 mb_index ++; /* border */
michael@0 880 y_ptr += post->y_stride * 16 - post->y_width;
michael@0 881
michael@0 882 }
michael@0 883 }
michael@0 884
michael@0 885 if (flags & VP8D_DEBUG_TXT_DC_DIFF)
michael@0 886 {
michael@0 887 int i, j;
michael@0 888 unsigned char *y_ptr;
michael@0 889 YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
michael@0 890 int mb_rows = post->y_height >> 4;
michael@0 891 int mb_cols = post->y_width >> 4;
michael@0 892 int mb_index = 0;
michael@0 893 MODE_INFO *mi = oci->mi;
michael@0 894
michael@0 895 y_ptr = post->y_buffer + 4 * post->y_stride + 4;
michael@0 896
michael@0 897 /* vp8_filter each macro block */
michael@0 898 for (i = 0; i < mb_rows; i++)
michael@0 899 {
michael@0 900 for (j = 0; j < mb_cols; j++)
michael@0 901 {
michael@0 902 char zz[4];
michael@0 903 int dc_diff = !(mi[mb_index].mbmi.mode != B_PRED &&
michael@0 904 mi[mb_index].mbmi.mode != SPLITMV &&
michael@0 905 mi[mb_index].mbmi.mb_skip_coeff);
michael@0 906
michael@0 907 if (oci->frame_type == KEY_FRAME)
michael@0 908 sprintf(zz, "a");
michael@0 909 else
michael@0 910 sprintf(zz, "%c", dc_diff + '0');
michael@0 911
michael@0 912 vp8_blit_text(zz, y_ptr, post->y_stride);
michael@0 913 mb_index ++;
michael@0 914 y_ptr += 16;
michael@0 915 }
michael@0 916
michael@0 917 mb_index ++; /* border */
michael@0 918 y_ptr += post->y_stride * 16 - post->y_width;
michael@0 919
michael@0 920 }
michael@0 921 }
michael@0 922
michael@0 923 if (flags & VP8D_DEBUG_TXT_RATE_INFO)
michael@0 924 {
michael@0 925 char message[512];
michael@0 926 sprintf(message, "Bitrate: %10.2f framerate: %10.2f ", oci->bitrate, oci->framerate);
michael@0 927 vp8_blit_text(message, oci->post_proc_buffer.y_buffer, oci->post_proc_buffer.y_stride);
michael@0 928 }
michael@0 929
michael@0 930 /* Draw motion vectors */
michael@0 931 if ((flags & VP8D_DEBUG_DRAW_MV) && ppflags->display_mv_flag)
michael@0 932 {
michael@0 933 YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
michael@0 934 int width = post->y_width;
michael@0 935 int height = post->y_height;
michael@0 936 unsigned char *y_buffer = oci->post_proc_buffer.y_buffer;
michael@0 937 int y_stride = oci->post_proc_buffer.y_stride;
michael@0 938 MODE_INFO *mi = oci->mi;
michael@0 939 int x0, y0;
michael@0 940
michael@0 941 for (y0 = 0; y0 < height; y0 += 16)
michael@0 942 {
michael@0 943 for (x0 = 0; x0 < width; x0 += 16)
michael@0 944 {
michael@0 945 int x1, y1;
michael@0 946
michael@0 947 if (!(ppflags->display_mv_flag & (1<<mi->mbmi.mode)))
michael@0 948 {
michael@0 949 mi++;
michael@0 950 continue;
michael@0 951 }
michael@0 952
michael@0 953 if (mi->mbmi.mode == SPLITMV)
michael@0 954 {
michael@0 955 switch (mi->mbmi.partitioning)
michael@0 956 {
michael@0 957 case 0 : /* mv_top_bottom */
michael@0 958 {
michael@0 959 union b_mode_info *bmi = &mi->bmi[0];
michael@0 960 MV *mv = &bmi->mv.as_mv;
michael@0 961
michael@0 962 x1 = x0 + 8 + (mv->col >> 3);
michael@0 963 y1 = y0 + 4 + (mv->row >> 3);
michael@0 964
michael@0 965 constrain_line (x0+8, &x1, y0+4, &y1, width, height);
michael@0 966 vp8_blit_line (x0+8, x1, y0+4, y1, y_buffer, y_stride);
michael@0 967
michael@0 968 bmi = &mi->bmi[8];
michael@0 969
michael@0 970 x1 = x0 + 8 + (mv->col >> 3);
michael@0 971 y1 = y0 +12 + (mv->row >> 3);
michael@0 972
michael@0 973 constrain_line (x0+8, &x1, y0+12, &y1, width, height);
michael@0 974 vp8_blit_line (x0+8, x1, y0+12, y1, y_buffer, y_stride);
michael@0 975
michael@0 976 break;
michael@0 977 }
michael@0 978 case 1 : /* mv_left_right */
michael@0 979 {
michael@0 980 union b_mode_info *bmi = &mi->bmi[0];
michael@0 981 MV *mv = &bmi->mv.as_mv;
michael@0 982
michael@0 983 x1 = x0 + 4 + (mv->col >> 3);
michael@0 984 y1 = y0 + 8 + (mv->row >> 3);
michael@0 985
michael@0 986 constrain_line (x0+4, &x1, y0+8, &y1, width, height);
michael@0 987 vp8_blit_line (x0+4, x1, y0+8, y1, y_buffer, y_stride);
michael@0 988
michael@0 989 bmi = &mi->bmi[2];
michael@0 990
michael@0 991 x1 = x0 +12 + (mv->col >> 3);
michael@0 992 y1 = y0 + 8 + (mv->row >> 3);
michael@0 993
michael@0 994 constrain_line (x0+12, &x1, y0+8, &y1, width, height);
michael@0 995 vp8_blit_line (x0+12, x1, y0+8, y1, y_buffer, y_stride);
michael@0 996
michael@0 997 break;
michael@0 998 }
michael@0 999 case 2 : /* mv_quarters */
michael@0 1000 {
michael@0 1001 union b_mode_info *bmi = &mi->bmi[0];
michael@0 1002 MV *mv = &bmi->mv.as_mv;
michael@0 1003
michael@0 1004 x1 = x0 + 4 + (mv->col >> 3);
michael@0 1005 y1 = y0 + 4 + (mv->row >> 3);
michael@0 1006
michael@0 1007 constrain_line (x0+4, &x1, y0+4, &y1, width, height);
michael@0 1008 vp8_blit_line (x0+4, x1, y0+4, y1, y_buffer, y_stride);
michael@0 1009
michael@0 1010 bmi = &mi->bmi[2];
michael@0 1011
michael@0 1012 x1 = x0 +12 + (mv->col >> 3);
michael@0 1013 y1 = y0 + 4 + (mv->row >> 3);
michael@0 1014
michael@0 1015 constrain_line (x0+12, &x1, y0+4, &y1, width, height);
michael@0 1016 vp8_blit_line (x0+12, x1, y0+4, y1, y_buffer, y_stride);
michael@0 1017
michael@0 1018 bmi = &mi->bmi[8];
michael@0 1019
michael@0 1020 x1 = x0 + 4 + (mv->col >> 3);
michael@0 1021 y1 = y0 +12 + (mv->row >> 3);
michael@0 1022
michael@0 1023 constrain_line (x0+4, &x1, y0+12, &y1, width, height);
michael@0 1024 vp8_blit_line (x0+4, x1, y0+12, y1, y_buffer, y_stride);
michael@0 1025
michael@0 1026 bmi = &mi->bmi[10];
michael@0 1027
michael@0 1028 x1 = x0 +12 + (mv->col >> 3);
michael@0 1029 y1 = y0 +12 + (mv->row >> 3);
michael@0 1030
michael@0 1031 constrain_line (x0+12, &x1, y0+12, &y1, width, height);
michael@0 1032 vp8_blit_line (x0+12, x1, y0+12, y1, y_buffer, y_stride);
michael@0 1033 break;
michael@0 1034 }
michael@0 1035 default :
michael@0 1036 {
michael@0 1037 union b_mode_info *bmi = mi->bmi;
michael@0 1038 int bx0, by0;
michael@0 1039
michael@0 1040 for (by0 = y0; by0 < (y0+16); by0 += 4)
michael@0 1041 {
michael@0 1042 for (bx0 = x0; bx0 < (x0+16); bx0 += 4)
michael@0 1043 {
michael@0 1044 MV *mv = &bmi->mv.as_mv;
michael@0 1045
michael@0 1046 x1 = bx0 + 2 + (mv->col >> 3);
michael@0 1047 y1 = by0 + 2 + (mv->row >> 3);
michael@0 1048
michael@0 1049 constrain_line (bx0+2, &x1, by0+2, &y1, width, height);
michael@0 1050 vp8_blit_line (bx0+2, x1, by0+2, y1, y_buffer, y_stride);
michael@0 1051
michael@0 1052 bmi++;
michael@0 1053 }
michael@0 1054 }
michael@0 1055 }
michael@0 1056 }
michael@0 1057 }
michael@0 1058 else if (mi->mbmi.mode >= NEARESTMV)
michael@0 1059 {
michael@0 1060 MV *mv = &mi->mbmi.mv.as_mv;
michael@0 1061 const int lx0 = x0 + 8;
michael@0 1062 const int ly0 = y0 + 8;
michael@0 1063
michael@0 1064 x1 = lx0 + (mv->col >> 3);
michael@0 1065 y1 = ly0 + (mv->row >> 3);
michael@0 1066
michael@0 1067 if (x1 != lx0 && y1 != ly0)
michael@0 1068 {
michael@0 1069 constrain_line (lx0, &x1, ly0-1, &y1, width, height);
michael@0 1070 vp8_blit_line (lx0, x1, ly0-1, y1, y_buffer, y_stride);
michael@0 1071
michael@0 1072 constrain_line (lx0, &x1, ly0+1, &y1, width, height);
michael@0 1073 vp8_blit_line (lx0, x1, ly0+1, y1, y_buffer, y_stride);
michael@0 1074 }
michael@0 1075 else
michael@0 1076 vp8_blit_line (lx0, x1, ly0, y1, y_buffer, y_stride);
michael@0 1077 }
michael@0 1078
michael@0 1079 mi++;
michael@0 1080 }
michael@0 1081 mi++;
michael@0 1082 }
michael@0 1083 }
michael@0 1084
michael@0 1085 /* Color in block modes */
michael@0 1086 if ((flags & VP8D_DEBUG_CLR_BLK_MODES)
michael@0 1087 && (ppflags->display_mb_modes_flag || ppflags->display_b_modes_flag))
michael@0 1088 {
michael@0 1089 int y, x;
michael@0 1090 YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
michael@0 1091 int width = post->y_width;
michael@0 1092 int height = post->y_height;
michael@0 1093 unsigned char *y_ptr = oci->post_proc_buffer.y_buffer;
michael@0 1094 unsigned char *u_ptr = oci->post_proc_buffer.u_buffer;
michael@0 1095 unsigned char *v_ptr = oci->post_proc_buffer.v_buffer;
michael@0 1096 int y_stride = oci->post_proc_buffer.y_stride;
michael@0 1097 MODE_INFO *mi = oci->mi;
michael@0 1098
michael@0 1099 for (y = 0; y < height; y += 16)
michael@0 1100 {
michael@0 1101 for (x = 0; x < width; x += 16)
michael@0 1102 {
michael@0 1103 int Y = 0, U = 0, V = 0;
michael@0 1104
michael@0 1105 if (mi->mbmi.mode == B_PRED &&
michael@0 1106 ((ppflags->display_mb_modes_flag & B_PRED) || ppflags->display_b_modes_flag))
michael@0 1107 {
michael@0 1108 int by, bx;
michael@0 1109 unsigned char *yl, *ul, *vl;
michael@0 1110 union b_mode_info *bmi = mi->bmi;
michael@0 1111
michael@0 1112 yl = y_ptr + x;
michael@0 1113 ul = u_ptr + (x>>1);
michael@0 1114 vl = v_ptr + (x>>1);
michael@0 1115
michael@0 1116 for (by = 0; by < 16; by += 4)
michael@0 1117 {
michael@0 1118 for (bx = 0; bx < 16; bx += 4)
michael@0 1119 {
michael@0 1120 if ((ppflags->display_b_modes_flag & (1<<mi->mbmi.mode))
michael@0 1121 || (ppflags->display_mb_modes_flag & B_PRED))
michael@0 1122 {
michael@0 1123 Y = B_PREDICTION_MODE_colors[bmi->as_mode][0];
michael@0 1124 U = B_PREDICTION_MODE_colors[bmi->as_mode][1];
michael@0 1125 V = B_PREDICTION_MODE_colors[bmi->as_mode][2];
michael@0 1126
michael@0 1127 vp8_blend_b
michael@0 1128 (yl+bx, ul+(bx>>1), vl+(bx>>1), Y, U, V, 0xc000, y_stride);
michael@0 1129 }
michael@0 1130 bmi++;
michael@0 1131 }
michael@0 1132
michael@0 1133 yl += y_stride*4;
michael@0 1134 ul += y_stride*1;
michael@0 1135 vl += y_stride*1;
michael@0 1136 }
michael@0 1137 }
michael@0 1138 else if (ppflags->display_mb_modes_flag & (1<<mi->mbmi.mode))
michael@0 1139 {
michael@0 1140 Y = MB_PREDICTION_MODE_colors[mi->mbmi.mode][0];
michael@0 1141 U = MB_PREDICTION_MODE_colors[mi->mbmi.mode][1];
michael@0 1142 V = MB_PREDICTION_MODE_colors[mi->mbmi.mode][2];
michael@0 1143
michael@0 1144 vp8_blend_mb_inner
michael@0 1145 (y_ptr+x, u_ptr+(x>>1), v_ptr+(x>>1), Y, U, V, 0xc000, y_stride);
michael@0 1146 }
michael@0 1147
michael@0 1148 mi++;
michael@0 1149 }
michael@0 1150 y_ptr += y_stride*16;
michael@0 1151 u_ptr += y_stride*4;
michael@0 1152 v_ptr += y_stride*4;
michael@0 1153
michael@0 1154 mi++;
michael@0 1155 }
michael@0 1156 }
michael@0 1157
michael@0 1158 /* Color in frame reference blocks */
michael@0 1159 if ((flags & VP8D_DEBUG_CLR_FRM_REF_BLKS) && ppflags->display_ref_frame_flag)
michael@0 1160 {
michael@0 1161 int y, x;
michael@0 1162 YV12_BUFFER_CONFIG *post = &oci->post_proc_buffer;
michael@0 1163 int width = post->y_width;
michael@0 1164 int height = post->y_height;
michael@0 1165 unsigned char *y_ptr = oci->post_proc_buffer.y_buffer;
michael@0 1166 unsigned char *u_ptr = oci->post_proc_buffer.u_buffer;
michael@0 1167 unsigned char *v_ptr = oci->post_proc_buffer.v_buffer;
michael@0 1168 int y_stride = oci->post_proc_buffer.y_stride;
michael@0 1169 MODE_INFO *mi = oci->mi;
michael@0 1170
michael@0 1171 for (y = 0; y < height; y += 16)
michael@0 1172 {
michael@0 1173 for (x = 0; x < width; x +=16)
michael@0 1174 {
michael@0 1175 int Y = 0, U = 0, V = 0;
michael@0 1176
michael@0 1177 if (ppflags->display_ref_frame_flag & (1<<mi->mbmi.ref_frame))
michael@0 1178 {
michael@0 1179 Y = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][0];
michael@0 1180 U = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][1];
michael@0 1181 V = MV_REFERENCE_FRAME_colors[mi->mbmi.ref_frame][2];
michael@0 1182
michael@0 1183 vp8_blend_mb_outer
michael@0 1184 (y_ptr+x, u_ptr+(x>>1), v_ptr+(x>>1), Y, U, V, 0xc000, y_stride);
michael@0 1185 }
michael@0 1186
michael@0 1187 mi++;
michael@0 1188 }
michael@0 1189 y_ptr += y_stride*16;
michael@0 1190 u_ptr += y_stride*4;
michael@0 1191 v_ptr += y_stride*4;
michael@0 1192
michael@0 1193 mi++;
michael@0 1194 }
michael@0 1195 }
michael@0 1196 #endif
michael@0 1197
michael@0 1198 *dest = oci->post_proc_buffer;
michael@0 1199
michael@0 1200 /* handle problem with extending borders */
michael@0 1201 dest->y_width = oci->Width;
michael@0 1202 dest->y_height = oci->Height;
michael@0 1203 dest->uv_height = dest->y_height / 2;
michael@0 1204 return 0;
michael@0 1205 }
michael@0 1206 #endif

mercurial