Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_variance.c

Issue 592203002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_variance.h ('k') | source/libvpx/vp9/vp9_common.mk » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 for (i = 0; i < height; i++) { 260 for (i = 0; i < height; i++) {
261 for (j = 0; j < width; j++) { 261 for (j = 0; j < width; j++) {
262 const int tmp = pred[j] + ref[j]; 262 const int tmp = pred[j] + ref[j];
263 comp_pred[j] = ROUND_POWER_OF_TWO(tmp, 1); 263 comp_pred[j] = ROUND_POWER_OF_TWO(tmp, 1);
264 } 264 }
265 comp_pred += width; 265 comp_pred += width;
266 pred += width; 266 pred += width;
267 ref += ref_stride; 267 ref += ref_stride;
268 } 268 }
269 } 269 }
270
271 #if CONFIG_VP9_HIGHBITDEPTH
272 void high_variance64(const uint8_t *a8, int a_stride,
273 const uint8_t *b8, int b_stride,
274 int w, int h, uint64_t *sse,
275 uint64_t *sum) {
276 int i, j;
277
278 uint16_t *a = CONVERT_TO_SHORTPTR(a8);
279 uint16_t *b = CONVERT_TO_SHORTPTR(b8);
280 *sum = 0;
281 *sse = 0;
282
283 for (i = 0; i < h; i++) {
284 for (j = 0; j < w; j++) {
285 const int diff = a[j] - b[j];
286 *sum += diff;
287 *sse += diff * diff;
288 }
289 a += a_stride;
290 b += b_stride;
291 }
292 }
293
294 void high_variance(const uint8_t *a8, int a_stride,
295 const uint8_t *b8, int b_stride,
296 int w, int h, unsigned int *sse,
297 int *sum) {
298 uint64_t sse_long = 0;
299 uint64_t sum_long = 0;
300 high_variance64(a8, a_stride, b8, b_stride, w, h, &sse_long, &sum_long);
301 *sse = sse_long;
302 *sum = sum_long;
303 }
304
305 void high_10_variance(const uint8_t *a8, int a_stride,
306 const uint8_t *b8, int b_stride,
307 int w, int h, unsigned int *sse,
308 int *sum) {
309 uint64_t sse_long = 0;
310 uint64_t sum_long = 0;
311 high_variance64(a8, a_stride, b8, b_stride, w, h, &sse_long, &sum_long);
312 *sum = ROUND_POWER_OF_TWO(sum_long, 2);
313 *sse = ROUND_POWER_OF_TWO(sse_long, 4);
314 }
315
316 void high_12_variance(const uint8_t *a8, int a_stride,
317 const uint8_t *b8, int b_stride,
318 int w, int h, unsigned int *sse,
319 int *sum) {
320 uint64_t sse_long = 0;
321 uint64_t sum_long = 0;
322 high_variance64(a8, a_stride, b8, b_stride, w, h, &sse_long, &sum_long);
323 *sum = ROUND_POWER_OF_TWO(sum_long, 4);
324 *sse = ROUND_POWER_OF_TWO(sse_long, 8);
325 }
326
327 static void high_var_filter_block2d_bil_first_pass(
328 const uint8_t *src_ptr8,
329 uint16_t *output_ptr,
330 unsigned int src_pixels_per_line,
331 int pixel_step,
332 unsigned int output_height,
333 unsigned int output_width,
334 const int16_t *vp9_filter) {
335 unsigned int i, j;
336 uint16_t *src_ptr = CONVERT_TO_SHORTPTR(src_ptr8);
337 for (i = 0; i < output_height; i++) {
338 for (j = 0; j < output_width; j++) {
339 output_ptr[j] =
340 ROUND_POWER_OF_TWO((int)src_ptr[0] * vp9_filter[0] +
341 (int)src_ptr[pixel_step] * vp9_filter[1],
342 FILTER_BITS);
343
344 src_ptr++;
345 }
346
347 // Next row...
348 src_ptr += src_pixels_per_line - output_width;
349 output_ptr += output_width;
350 }
351 }
352
353 static void high_var_filter_block2d_bil_second_pass(
354 const uint16_t *src_ptr,
355 uint16_t *output_ptr,
356 unsigned int src_pixels_per_line,
357 unsigned int pixel_step,
358 unsigned int output_height,
359 unsigned int output_width,
360 const int16_t *vp9_filter) {
361 unsigned int i, j;
362
363 for (i = 0; i < output_height; i++) {
364 for (j = 0; j < output_width; j++) {
365 output_ptr[j] =
366 ROUND_POWER_OF_TWO((int)src_ptr[0] * vp9_filter[0] +
367 (int)src_ptr[pixel_step] * vp9_filter[1],
368 FILTER_BITS);
369 src_ptr++;
370 }
371
372 src_ptr += src_pixels_per_line - output_width;
373 output_ptr += output_width;
374 }
375 }
376
377 #define HIGH_VAR(W, H) \
378 unsigned int vp9_high_variance##W##x##H##_c(const uint8_t *a, int a_stride, \
379 const uint8_t *b, int b_stride, \
380 unsigned int *sse) { \
381 int sum; \
382 high_variance(a, a_stride, b, b_stride, W, H, sse, &sum); \
383 return *sse - (((int64_t)sum * sum) / (W * H)); \
384 } \
385 \
386 unsigned int vp9_high_10_variance##W##x##H##_c(const uint8_t *a, int a_stride, \
387 const uint8_t *b, int b_stride, \
388 unsigned int *sse) { \
389 int sum; \
390 high_10_variance(a, a_stride, b, b_stride, W, H, sse, &sum); \
391 return *sse - (((int64_t)sum * sum) / (W * H)); \
392 } \
393 \
394 unsigned int vp9_high_12_variance##W##x##H##_c(const uint8_t *a, int a_stride, \
395 const uint8_t *b, int b_stride, \
396 unsigned int *sse) { \
397 int sum; \
398 high_12_variance(a, a_stride, b, b_stride, W, H, sse, &sum); \
399 return *sse - (((int64_t)sum * sum) / (W * H)); \
400 }
401
402 #define HIGH_SUBPIX_VAR(W, H) \
403 unsigned int vp9_high_sub_pixel_variance##W##x##H##_c( \
404 const uint8_t *src, int src_stride, \
405 int xoffset, int yoffset, \
406 const uint8_t *dst, int dst_stride, \
407 unsigned int *sse) { \
408 uint16_t fdata3[(H + 1) * W]; \
409 uint16_t temp2[H * W]; \
410 \
411 high_var_filter_block2d_bil_first_pass(src, fdata3, src_stride, 1, H + 1, \
412 W, BILINEAR_FILTERS_2TAP(xoffset)); \
413 high_var_filter_block2d_bil_second_pass(fdata3, temp2, W, W, H, W, \
414 BILINEAR_FILTERS_2TAP(yoffset)); \
415 \
416 return vp9_high_variance##W##x##H##_c(CONVERT_TO_BYTEPTR(temp2), W, dst, \
417 dst_stride, sse); \
418 } \
419 \
420 unsigned int vp9_high_10_sub_pixel_variance##W##x##H##_c( \
421 const uint8_t *src, int src_stride, \
422 int xoffset, int yoffset, \
423 const uint8_t *dst, int dst_stride, \
424 unsigned int *sse) { \
425 uint16_t fdata3[(H + 1) * W]; \
426 uint16_t temp2[H * W]; \
427 \
428 high_var_filter_block2d_bil_first_pass(src, fdata3, src_stride, 1, H + 1, \
429 W, BILINEAR_FILTERS_2TAP(xoffset)); \
430 high_var_filter_block2d_bil_second_pass(fdata3, temp2, W, W, H, W, \
431 BILINEAR_FILTERS_2TAP(yoffset)); \
432 \
433 return vp9_high_10_variance##W##x##H##_c(CONVERT_TO_BYTEPTR(temp2), W, dst, \
434 dst_stride, sse); \
435 } \
436 \
437 unsigned int vp9_high_12_sub_pixel_variance##W##x##H##_c( \
438 const uint8_t *src, int src_stride, \
439 int xoffset, int yoffset, \
440 const uint8_t *dst, int dst_stride, \
441 unsigned int *sse) { \
442 uint16_t fdata3[(H + 1) * W]; \
443 uint16_t temp2[H * W]; \
444 \
445 high_var_filter_block2d_bil_first_pass(src, fdata3, src_stride, 1, H + 1, \
446 W, BILINEAR_FILTERS_2TAP(xoffset)); \
447 high_var_filter_block2d_bil_second_pass(fdata3, temp2, W, W, H, W, \
448 BILINEAR_FILTERS_2TAP(yoffset)); \
449 \
450 return vp9_high_12_variance##W##x##H##_c(CONVERT_TO_BYTEPTR(temp2), W, dst, \
451 dst_stride, sse); \
452 }
453
454 #define HIGH_SUBPIX_AVG_VAR(W, H) \
455 unsigned int vp9_high_sub_pixel_avg_variance##W##x##H##_c( \
456 const uint8_t *src, int src_stride, \
457 int xoffset, int yoffset, \
458 const uint8_t *dst, int dst_stride, \
459 unsigned int *sse, \
460 const uint8_t *second_pred) { \
461 uint16_t fdata3[(H + 1) * W]; \
462 uint16_t temp2[H * W]; \
463 DECLARE_ALIGNED_ARRAY(16, uint16_t, temp3, H * W); \
464 \
465 high_var_filter_block2d_bil_first_pass(src, fdata3, src_stride, 1, H + 1, \
466 W, BILINEAR_FILTERS_2TAP(xoffset)); \
467 high_var_filter_block2d_bil_second_pass(fdata3, temp2, W, W, H, W, \
468 BILINEAR_FILTERS_2TAP(yoffset)); \
469 \
470 vp9_high_comp_avg_pred(temp3, second_pred, W, H, CONVERT_TO_BYTEPTR(temp2), \
471 W); \
472 \
473 return vp9_high_variance##W##x##H##_c(CONVERT_TO_BYTEPTR(temp3), W, dst, \
474 dst_stride, sse); \
475 } \
476 \
477 unsigned int vp9_high_10_sub_pixel_avg_variance##W##x##H##_c( \
478 const uint8_t *src, int src_stride, \
479 int xoffset, int yoffset, \
480 const uint8_t *dst, int dst_stride, \
481 unsigned int *sse, \
482 const uint8_t *second_pred) { \
483 uint16_t fdata3[(H + 1) * W]; \
484 uint16_t temp2[H * W]; \
485 DECLARE_ALIGNED_ARRAY(16, uint16_t, temp3, H * W); \
486 \
487 high_var_filter_block2d_bil_first_pass(src, fdata3, src_stride, 1, H + 1, \
488 W, BILINEAR_FILTERS_2TAP(xoffset)); \
489 high_var_filter_block2d_bil_second_pass(fdata3, temp2, W, W, H, W, \
490 BILINEAR_FILTERS_2TAP(yoffset)); \
491 \
492 vp9_high_comp_avg_pred(temp3, second_pred, W, H, CONVERT_TO_BYTEPTR(temp2), \
493 W); \
494 \
495 return vp9_high_10_variance##W##x##H##_c(CONVERT_TO_BYTEPTR(temp3), W, dst, \
496 dst_stride, sse); \
497 } \
498 \
499 unsigned int vp9_high_12_sub_pixel_avg_variance##W##x##H##_c( \
500 const uint8_t *src, int src_stride, \
501 int xoffset, int yoffset, \
502 const uint8_t *dst, int dst_stride, \
503 unsigned int *sse, \
504 const uint8_t *second_pred) { \
505 uint16_t fdata3[(H + 1) * W]; \
506 uint16_t temp2[H * W]; \
507 DECLARE_ALIGNED_ARRAY(16, uint16_t, temp3, H * W); \
508 \
509 high_var_filter_block2d_bil_first_pass(src, fdata3, src_stride, 1, H + 1, \
510 W, BILINEAR_FILTERS_2TAP(xoffset)); \
511 high_var_filter_block2d_bil_second_pass(fdata3, temp2, W, W, H, W, \
512 BILINEAR_FILTERS_2TAP(yoffset)); \
513 \
514 vp9_high_comp_avg_pred(temp3, second_pred, W, H, CONVERT_TO_BYTEPTR(temp2), \
515 W); \
516 \
517 return vp9_high_12_variance##W##x##H##_c(CONVERT_TO_BYTEPTR(temp3), W, dst, \
518 dst_stride, sse); \
519 }
520
521 #define HIGH_GET_VAR(S) \
522 void vp9_high_get##S##x##S##var_c(const uint8_t *src, int src_stride, \
523 const uint8_t *ref, int ref_stride, \
524 unsigned int *sse, int *sum) { \
525 high_variance(src, src_stride, ref, ref_stride, S, S, sse, sum); \
526 } \
527 \
528 void vp9_high_10_get##S##x##S##var_c(const uint8_t *src, int src_stride, \
529 const uint8_t *ref, int ref_stride, \
530 unsigned int *sse, int *sum) { \
531 high_10_variance(src, src_stride, ref, ref_stride, S, S, sse, sum); \
532 } \
533 \
534 void vp9_high_12_get##S##x##S##var_c(const uint8_t *src, int src_stride, \
535 const uint8_t *ref, int ref_stride, \
536 unsigned int *sse, int *sum) { \
537 high_12_variance(src, src_stride, ref, ref_stride, S, S, sse, sum); \
538 }
539
540 #define HIGH_MSE(W, H) \
541 unsigned int vp9_high_mse##W##x##H##_c(const uint8_t *src, int src_stride, \
542 const uint8_t *ref, int ref_stride, \
543 unsigned int *sse) { \
544 int sum; \
545 high_variance(src, src_stride, ref, ref_stride, W, H, sse, &sum); \
546 return *sse; \
547 } \
548 \
549 unsigned int vp9_high_10_mse##W##x##H##_c(const uint8_t *src, int src_stride, \
550 const uint8_t *ref, int ref_stride, \
551 unsigned int *sse) { \
552 int sum; \
553 high_10_variance(src, src_stride, ref, ref_stride, W, H, sse, &sum); \
554 return *sse; \
555 } \
556 \
557 unsigned int vp9_high_12_mse##W##x##H##_c(const uint8_t *src, int src_stride, \
558 const uint8_t *ref, int ref_stride, \
559 unsigned int *sse) { \
560 int sum; \
561 high_12_variance(src, src_stride, ref, ref_stride, W, H, sse, &sum); \
562 return *sse; \
563 }
564
565 HIGH_GET_VAR(8)
566 HIGH_GET_VAR(16)
567
568 HIGH_MSE(16, 16)
569 HIGH_MSE(16, 8)
570 HIGH_MSE(8, 16)
571 HIGH_MSE(8, 8)
572
573 HIGH_VAR(4, 4)
574 HIGH_SUBPIX_VAR(4, 4)
575 HIGH_SUBPIX_AVG_VAR(4, 4)
576
577 HIGH_VAR(4, 8)
578 HIGH_SUBPIX_VAR(4, 8)
579 HIGH_SUBPIX_AVG_VAR(4, 8)
580
581 HIGH_VAR(8, 4)
582 HIGH_SUBPIX_VAR(8, 4)
583 HIGH_SUBPIX_AVG_VAR(8, 4)
584
585 HIGH_VAR(8, 8)
586 HIGH_SUBPIX_VAR(8, 8)
587 HIGH_SUBPIX_AVG_VAR(8, 8)
588
589 HIGH_VAR(8, 16)
590 HIGH_SUBPIX_VAR(8, 16)
591 HIGH_SUBPIX_AVG_VAR(8, 16)
592
593 HIGH_VAR(16, 8)
594 HIGH_SUBPIX_VAR(16, 8)
595 HIGH_SUBPIX_AVG_VAR(16, 8)
596
597 HIGH_VAR(16, 16)
598 HIGH_SUBPIX_VAR(16, 16)
599 HIGH_SUBPIX_AVG_VAR(16, 16)
600
601 HIGH_VAR(16, 32)
602 HIGH_SUBPIX_VAR(16, 32)
603 HIGH_SUBPIX_AVG_VAR(16, 32)
604
605 HIGH_VAR(32, 16)
606 HIGH_SUBPIX_VAR(32, 16)
607 HIGH_SUBPIX_AVG_VAR(32, 16)
608
609 HIGH_VAR(32, 32)
610 HIGH_SUBPIX_VAR(32, 32)
611 HIGH_SUBPIX_AVG_VAR(32, 32)
612
613 HIGH_VAR(32, 64)
614 HIGH_SUBPIX_VAR(32, 64)
615 HIGH_SUBPIX_AVG_VAR(32, 64)
616
617 HIGH_VAR(64, 32)
618 HIGH_SUBPIX_VAR(64, 32)
619 HIGH_SUBPIX_AVG_VAR(64, 32)
620
621 HIGH_VAR(64, 64)
622 HIGH_SUBPIX_VAR(64, 64)
623 HIGH_SUBPIX_AVG_VAR(64, 64)
624
625 void vp9_high_comp_avg_pred(uint16_t *comp_pred, const uint8_t *pred8,
626 int width, int height, const uint8_t *ref8,
627 int ref_stride) {
628 int i, j;
629 uint16_t *pred = CONVERT_TO_SHORTPTR(pred8);
630 uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
631 for (i = 0; i < height; i++) {
632 for (j = 0; j < width; j++) {
633 const int tmp = pred[j] + ref[j];
634 comp_pred[j] = ROUND_POWER_OF_TWO(tmp, 1);
635 }
636 comp_pred += width;
637 pred += width;
638 ref += ref_stride;
639 }
640 }
641 #endif // CONFIG_VP9_HIGHBITDEPTH
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_variance.h ('k') | source/libvpx/vp9/vp9_common.mk » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698