media/libvpx/vp8/common/variance_c.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 "variance.h"
michael@0 13 #include "filter.h"
michael@0 14
michael@0 15
michael@0 16 unsigned int vp8_get_mb_ss_c
michael@0 17 (
michael@0 18 const short *src_ptr
michael@0 19 )
michael@0 20 {
michael@0 21 unsigned int i = 0, sum = 0;
michael@0 22
michael@0 23 do
michael@0 24 {
michael@0 25 sum += (src_ptr[i] * src_ptr[i]);
michael@0 26 i++;
michael@0 27 }
michael@0 28 while (i < 256);
michael@0 29
michael@0 30 return sum;
michael@0 31 }
michael@0 32
michael@0 33
michael@0 34 static void variance(
michael@0 35 const unsigned char *src_ptr,
michael@0 36 int source_stride,
michael@0 37 const unsigned char *ref_ptr,
michael@0 38 int recon_stride,
michael@0 39 int w,
michael@0 40 int h,
michael@0 41 unsigned int *sse,
michael@0 42 int *sum)
michael@0 43 {
michael@0 44 int i, j;
michael@0 45 int diff;
michael@0 46
michael@0 47 *sum = 0;
michael@0 48 *sse = 0;
michael@0 49
michael@0 50 for (i = 0; i < h; i++)
michael@0 51 {
michael@0 52 for (j = 0; j < w; j++)
michael@0 53 {
michael@0 54 diff = src_ptr[j] - ref_ptr[j];
michael@0 55 *sum += diff;
michael@0 56 *sse += diff * diff;
michael@0 57 }
michael@0 58
michael@0 59 src_ptr += source_stride;
michael@0 60 ref_ptr += recon_stride;
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64
michael@0 65 unsigned int vp8_variance16x16_c(
michael@0 66 const unsigned char *src_ptr,
michael@0 67 int source_stride,
michael@0 68 const unsigned char *ref_ptr,
michael@0 69 int recon_stride,
michael@0 70 unsigned int *sse)
michael@0 71 {
michael@0 72 unsigned int var;
michael@0 73 int avg;
michael@0 74
michael@0 75
michael@0 76 variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 16, &var, &avg);
michael@0 77 *sse = var;
michael@0 78 return (var - (((unsigned int)avg * avg) >> 8));
michael@0 79 }
michael@0 80
michael@0 81 unsigned int vp8_variance8x16_c(
michael@0 82 const unsigned char *src_ptr,
michael@0 83 int source_stride,
michael@0 84 const unsigned char *ref_ptr,
michael@0 85 int recon_stride,
michael@0 86 unsigned int *sse)
michael@0 87 {
michael@0 88 unsigned int var;
michael@0 89 int avg;
michael@0 90
michael@0 91
michael@0 92 variance(src_ptr, source_stride, ref_ptr, recon_stride, 8, 16, &var, &avg);
michael@0 93 *sse = var;
michael@0 94 return (var - (((unsigned int)avg * avg) >> 7));
michael@0 95 }
michael@0 96
michael@0 97 unsigned int vp8_variance16x8_c(
michael@0 98 const unsigned char *src_ptr,
michael@0 99 int source_stride,
michael@0 100 const unsigned char *ref_ptr,
michael@0 101 int recon_stride,
michael@0 102 unsigned int *sse)
michael@0 103 {
michael@0 104 unsigned int var;
michael@0 105 int avg;
michael@0 106
michael@0 107
michael@0 108 variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 8, &var, &avg);
michael@0 109 *sse = var;
michael@0 110 return (var - (((unsigned int)avg * avg) >> 7));
michael@0 111 }
michael@0 112
michael@0 113
michael@0 114 unsigned int vp8_variance8x8_c(
michael@0 115 const unsigned char *src_ptr,
michael@0 116 int source_stride,
michael@0 117 const unsigned char *ref_ptr,
michael@0 118 int recon_stride,
michael@0 119 unsigned int *sse)
michael@0 120 {
michael@0 121 unsigned int var;
michael@0 122 int avg;
michael@0 123
michael@0 124
michael@0 125 variance(src_ptr, source_stride, ref_ptr, recon_stride, 8, 8, &var, &avg);
michael@0 126 *sse = var;
michael@0 127 return (var - (((unsigned int)avg * avg) >> 6));
michael@0 128 }
michael@0 129
michael@0 130 unsigned int vp8_variance4x4_c(
michael@0 131 const unsigned char *src_ptr,
michael@0 132 int source_stride,
michael@0 133 const unsigned char *ref_ptr,
michael@0 134 int recon_stride,
michael@0 135 unsigned int *sse)
michael@0 136 {
michael@0 137 unsigned int var;
michael@0 138 int avg;
michael@0 139
michael@0 140
michael@0 141 variance(src_ptr, source_stride, ref_ptr, recon_stride, 4, 4, &var, &avg);
michael@0 142 *sse = var;
michael@0 143 return (var - (((unsigned int)avg * avg) >> 4));
michael@0 144 }
michael@0 145
michael@0 146
michael@0 147 unsigned int vp8_mse16x16_c(
michael@0 148 const unsigned char *src_ptr,
michael@0 149 int source_stride,
michael@0 150 const unsigned char *ref_ptr,
michael@0 151 int recon_stride,
michael@0 152 unsigned int *sse)
michael@0 153 {
michael@0 154 unsigned int var;
michael@0 155 int avg;
michael@0 156
michael@0 157 variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 16, &var, &avg);
michael@0 158 *sse = var;
michael@0 159 return var;
michael@0 160 }
michael@0 161
michael@0 162
michael@0 163 /****************************************************************************
michael@0 164 *
michael@0 165 * ROUTINE : filter_block2d_bil_first_pass
michael@0 166 *
michael@0 167 * INPUTS : UINT8 *src_ptr : Pointer to source block.
michael@0 168 * UINT32 src_pixels_per_line : Stride of input block.
michael@0 169 * UINT32 pixel_step : Offset between filter input samples (see notes).
michael@0 170 * UINT32 output_height : Input block height.
michael@0 171 * UINT32 output_width : Input block width.
michael@0 172 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
michael@0 173 *
michael@0 174 * OUTPUTS : INT32 *output_ptr : Pointer to filtered block.
michael@0 175 *
michael@0 176 * RETURNS : void
michael@0 177 *
michael@0 178 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in
michael@0 179 * either horizontal or vertical direction to produce the
michael@0 180 * filtered output block. Used to implement first-pass
michael@0 181 * of 2-D separable filter.
michael@0 182 *
michael@0 183 * SPECIAL NOTES : Produces INT32 output to retain precision for next pass.
michael@0 184 * Two filter taps should sum to VP8_FILTER_WEIGHT.
michael@0 185 * pixel_step defines whether the filter is applied
michael@0 186 * horizontally (pixel_step=1) or vertically (pixel_step=stride).
michael@0 187 * It defines the offset required to move from one input
michael@0 188 * to the next.
michael@0 189 *
michael@0 190 ****************************************************************************/
michael@0 191 static void var_filter_block2d_bil_first_pass
michael@0 192 (
michael@0 193 const unsigned char *src_ptr,
michael@0 194 unsigned short *output_ptr,
michael@0 195 unsigned int src_pixels_per_line,
michael@0 196 int pixel_step,
michael@0 197 unsigned int output_height,
michael@0 198 unsigned int output_width,
michael@0 199 const short *vp8_filter
michael@0 200 )
michael@0 201 {
michael@0 202 unsigned int i, j;
michael@0 203
michael@0 204 for (i = 0; i < output_height; i++)
michael@0 205 {
michael@0 206 for (j = 0; j < output_width; j++)
michael@0 207 {
michael@0 208 /* Apply bilinear filter */
michael@0 209 output_ptr[j] = (((int)src_ptr[0] * vp8_filter[0]) +
michael@0 210 ((int)src_ptr[pixel_step] * vp8_filter[1]) +
michael@0 211 (VP8_FILTER_WEIGHT / 2)) >> VP8_FILTER_SHIFT;
michael@0 212 src_ptr++;
michael@0 213 }
michael@0 214
michael@0 215 /* Next row... */
michael@0 216 src_ptr += src_pixels_per_line - output_width;
michael@0 217 output_ptr += output_width;
michael@0 218 }
michael@0 219 }
michael@0 220
michael@0 221 /****************************************************************************
michael@0 222 *
michael@0 223 * ROUTINE : filter_block2d_bil_second_pass
michael@0 224 *
michael@0 225 * INPUTS : INT32 *src_ptr : Pointer to source block.
michael@0 226 * UINT32 src_pixels_per_line : Stride of input block.
michael@0 227 * UINT32 pixel_step : Offset between filter input samples (see notes).
michael@0 228 * UINT32 output_height : Input block height.
michael@0 229 * UINT32 output_width : Input block width.
michael@0 230 * INT32 *vp8_filter : Array of 2 bi-linear filter taps.
michael@0 231 *
michael@0 232 * OUTPUTS : UINT16 *output_ptr : Pointer to filtered block.
michael@0 233 *
michael@0 234 * RETURNS : void
michael@0 235 *
michael@0 236 * FUNCTION : Applies a 1-D 2-tap bi-linear filter to the source block in
michael@0 237 * either horizontal or vertical direction to produce the
michael@0 238 * filtered output block. Used to implement second-pass
michael@0 239 * of 2-D separable filter.
michael@0 240 *
michael@0 241 * SPECIAL NOTES : Requires 32-bit input as produced by filter_block2d_bil_first_pass.
michael@0 242 * Two filter taps should sum to VP8_FILTER_WEIGHT.
michael@0 243 * pixel_step defines whether the filter is applied
michael@0 244 * horizontally (pixel_step=1) or vertically (pixel_step=stride).
michael@0 245 * It defines the offset required to move from one input
michael@0 246 * to the next.
michael@0 247 *
michael@0 248 ****************************************************************************/
michael@0 249 static void var_filter_block2d_bil_second_pass
michael@0 250 (
michael@0 251 const unsigned short *src_ptr,
michael@0 252 unsigned char *output_ptr,
michael@0 253 unsigned int src_pixels_per_line,
michael@0 254 unsigned int pixel_step,
michael@0 255 unsigned int output_height,
michael@0 256 unsigned int output_width,
michael@0 257 const short *vp8_filter
michael@0 258 )
michael@0 259 {
michael@0 260 unsigned int i, j;
michael@0 261 int Temp;
michael@0 262
michael@0 263 for (i = 0; i < output_height; i++)
michael@0 264 {
michael@0 265 for (j = 0; j < output_width; j++)
michael@0 266 {
michael@0 267 /* Apply filter */
michael@0 268 Temp = ((int)src_ptr[0] * vp8_filter[0]) +
michael@0 269 ((int)src_ptr[pixel_step] * vp8_filter[1]) +
michael@0 270 (VP8_FILTER_WEIGHT / 2);
michael@0 271 output_ptr[j] = (unsigned int)(Temp >> VP8_FILTER_SHIFT);
michael@0 272 src_ptr++;
michael@0 273 }
michael@0 274
michael@0 275 /* Next row... */
michael@0 276 src_ptr += src_pixels_per_line - output_width;
michael@0 277 output_ptr += output_width;
michael@0 278 }
michael@0 279 }
michael@0 280
michael@0 281
michael@0 282 unsigned int vp8_sub_pixel_variance4x4_c
michael@0 283 (
michael@0 284 const unsigned char *src_ptr,
michael@0 285 int src_pixels_per_line,
michael@0 286 int xoffset,
michael@0 287 int yoffset,
michael@0 288 const unsigned char *dst_ptr,
michael@0 289 int dst_pixels_per_line,
michael@0 290 unsigned int *sse
michael@0 291 )
michael@0 292 {
michael@0 293 unsigned char temp2[20*16];
michael@0 294 const short *HFilter, *VFilter;
michael@0 295 unsigned short FData3[5*4]; /* Temp data bufffer used in filtering */
michael@0 296
michael@0 297 HFilter = vp8_bilinear_filters[xoffset];
michael@0 298 VFilter = vp8_bilinear_filters[yoffset];
michael@0 299
michael@0 300 /* First filter 1d Horizontal */
michael@0 301 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 5, 4, HFilter);
michael@0 302
michael@0 303 /* Now filter Verticaly */
michael@0 304 var_filter_block2d_bil_second_pass(FData3, temp2, 4, 4, 4, 4, VFilter);
michael@0 305
michael@0 306 return vp8_variance4x4_c(temp2, 4, dst_ptr, dst_pixels_per_line, sse);
michael@0 307 }
michael@0 308
michael@0 309
michael@0 310 unsigned int vp8_sub_pixel_variance8x8_c
michael@0 311 (
michael@0 312 const unsigned char *src_ptr,
michael@0 313 int src_pixels_per_line,
michael@0 314 int xoffset,
michael@0 315 int yoffset,
michael@0 316 const unsigned char *dst_ptr,
michael@0 317 int dst_pixels_per_line,
michael@0 318 unsigned int *sse
michael@0 319 )
michael@0 320 {
michael@0 321 unsigned short FData3[9*8]; /* Temp data bufffer used in filtering */
michael@0 322 unsigned char temp2[20*16];
michael@0 323 const short *HFilter, *VFilter;
michael@0 324
michael@0 325 HFilter = vp8_bilinear_filters[xoffset];
michael@0 326 VFilter = vp8_bilinear_filters[yoffset];
michael@0 327
michael@0 328 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 9, 8, HFilter);
michael@0 329 var_filter_block2d_bil_second_pass(FData3, temp2, 8, 8, 8, 8, VFilter);
michael@0 330
michael@0 331 return vp8_variance8x8_c(temp2, 8, dst_ptr, dst_pixels_per_line, sse);
michael@0 332 }
michael@0 333
michael@0 334 unsigned int vp8_sub_pixel_variance16x16_c
michael@0 335 (
michael@0 336 const unsigned char *src_ptr,
michael@0 337 int src_pixels_per_line,
michael@0 338 int xoffset,
michael@0 339 int yoffset,
michael@0 340 const unsigned char *dst_ptr,
michael@0 341 int dst_pixels_per_line,
michael@0 342 unsigned int *sse
michael@0 343 )
michael@0 344 {
michael@0 345 unsigned short FData3[17*16]; /* Temp data bufffer used in filtering */
michael@0 346 unsigned char temp2[20*16];
michael@0 347 const short *HFilter, *VFilter;
michael@0 348
michael@0 349 HFilter = vp8_bilinear_filters[xoffset];
michael@0 350 VFilter = vp8_bilinear_filters[yoffset];
michael@0 351
michael@0 352 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 17, 16, HFilter);
michael@0 353 var_filter_block2d_bil_second_pass(FData3, temp2, 16, 16, 16, 16, VFilter);
michael@0 354
michael@0 355 return vp8_variance16x16_c(temp2, 16, dst_ptr, dst_pixels_per_line, sse);
michael@0 356 }
michael@0 357
michael@0 358
michael@0 359 unsigned int vp8_variance_halfpixvar16x16_h_c(
michael@0 360 const unsigned char *src_ptr,
michael@0 361 int source_stride,
michael@0 362 const unsigned char *ref_ptr,
michael@0 363 int recon_stride,
michael@0 364 unsigned int *sse)
michael@0 365 {
michael@0 366 return vp8_sub_pixel_variance16x16_c(src_ptr, source_stride, 4, 0,
michael@0 367 ref_ptr, recon_stride, sse);
michael@0 368 }
michael@0 369
michael@0 370
michael@0 371 unsigned int vp8_variance_halfpixvar16x16_v_c(
michael@0 372 const unsigned char *src_ptr,
michael@0 373 int source_stride,
michael@0 374 const unsigned char *ref_ptr,
michael@0 375 int recon_stride,
michael@0 376 unsigned int *sse)
michael@0 377 {
michael@0 378 return vp8_sub_pixel_variance16x16_c(src_ptr, source_stride, 0, 4,
michael@0 379 ref_ptr, recon_stride, sse);
michael@0 380 }
michael@0 381
michael@0 382
michael@0 383 unsigned int vp8_variance_halfpixvar16x16_hv_c(
michael@0 384 const unsigned char *src_ptr,
michael@0 385 int source_stride,
michael@0 386 const unsigned char *ref_ptr,
michael@0 387 int recon_stride,
michael@0 388 unsigned int *sse)
michael@0 389 {
michael@0 390 return vp8_sub_pixel_variance16x16_c(src_ptr, source_stride, 4, 4,
michael@0 391 ref_ptr, recon_stride, sse);
michael@0 392 }
michael@0 393
michael@0 394
michael@0 395 unsigned int vp8_sub_pixel_mse16x16_c
michael@0 396 (
michael@0 397 const unsigned char *src_ptr,
michael@0 398 int src_pixels_per_line,
michael@0 399 int xoffset,
michael@0 400 int yoffset,
michael@0 401 const unsigned char *dst_ptr,
michael@0 402 int dst_pixels_per_line,
michael@0 403 unsigned int *sse
michael@0 404 )
michael@0 405 {
michael@0 406 vp8_sub_pixel_variance16x16_c(src_ptr, src_pixels_per_line, xoffset, yoffset, dst_ptr, dst_pixels_per_line, sse);
michael@0 407 return *sse;
michael@0 408 }
michael@0 409
michael@0 410 unsigned int vp8_sub_pixel_variance16x8_c
michael@0 411 (
michael@0 412 const unsigned char *src_ptr,
michael@0 413 int src_pixels_per_line,
michael@0 414 int xoffset,
michael@0 415 int yoffset,
michael@0 416 const unsigned char *dst_ptr,
michael@0 417 int dst_pixels_per_line,
michael@0 418 unsigned int *sse
michael@0 419 )
michael@0 420 {
michael@0 421 unsigned short FData3[16*9]; /* Temp data bufffer used in filtering */
michael@0 422 unsigned char temp2[20*16];
michael@0 423 const short *HFilter, *VFilter;
michael@0 424
michael@0 425 HFilter = vp8_bilinear_filters[xoffset];
michael@0 426 VFilter = vp8_bilinear_filters[yoffset];
michael@0 427
michael@0 428 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 9, 16, HFilter);
michael@0 429 var_filter_block2d_bil_second_pass(FData3, temp2, 16, 16, 8, 16, VFilter);
michael@0 430
michael@0 431 return vp8_variance16x8_c(temp2, 16, dst_ptr, dst_pixels_per_line, sse);
michael@0 432 }
michael@0 433
michael@0 434 unsigned int vp8_sub_pixel_variance8x16_c
michael@0 435 (
michael@0 436 const unsigned char *src_ptr,
michael@0 437 int src_pixels_per_line,
michael@0 438 int xoffset,
michael@0 439 int yoffset,
michael@0 440 const unsigned char *dst_ptr,
michael@0 441 int dst_pixels_per_line,
michael@0 442 unsigned int *sse
michael@0 443 )
michael@0 444 {
michael@0 445 unsigned short FData3[9*16]; /* Temp data bufffer used in filtering */
michael@0 446 unsigned char temp2[20*16];
michael@0 447 const short *HFilter, *VFilter;
michael@0 448
michael@0 449
michael@0 450 HFilter = vp8_bilinear_filters[xoffset];
michael@0 451 VFilter = vp8_bilinear_filters[yoffset];
michael@0 452
michael@0 453
michael@0 454 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 17, 8, HFilter);
michael@0 455 var_filter_block2d_bil_second_pass(FData3, temp2, 8, 8, 16, 8, VFilter);
michael@0 456
michael@0 457 return vp8_variance8x16_c(temp2, 8, dst_ptr, dst_pixels_per_line, sse);
michael@0 458 }

mercurial