/src/aom/aom_dsp/sum_squares.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
10 | | */ |
11 | | |
12 | | #include <assert.h> |
13 | | |
14 | | #include "config/aom_dsp_rtcd.h" |
15 | | |
16 | | uint64_t aom_sum_squares_2d_i16_c(const int16_t *src, int src_stride, int width, |
17 | 44.3M | int height) { |
18 | 44.3M | int r, c; |
19 | 44.3M | uint64_t ss = 0; |
20 | | |
21 | 266M | for (r = 0; r < height; r++) { |
22 | 2.54G | for (c = 0; c < width; c++) { |
23 | 2.31G | const int16_t v = src[c]; |
24 | 2.31G | ss += v * v; |
25 | 2.31G | } |
26 | 222M | src += src_stride; |
27 | 222M | } |
28 | | |
29 | 44.3M | return ss; |
30 | 44.3M | } |
31 | | |
32 | 0 | uint64_t aom_sum_squares_i16_c(const int16_t *src, uint32_t n) { |
33 | 0 | uint64_t ss = 0; |
34 | 0 | do { |
35 | 0 | const int16_t v = *src++; |
36 | 0 | ss += v * v; |
37 | 0 | } while (--n); |
38 | |
|
39 | 0 | return ss; |
40 | 0 | } |
41 | | |
42 | 0 | uint64_t aom_var_2d_u8_c(uint8_t *src, int src_stride, int width, int height) { |
43 | 0 | int r, c; |
44 | 0 | uint64_t ss = 0, s = 0; |
45 | |
|
46 | 0 | for (r = 0; r < height; r++) { |
47 | 0 | for (c = 0; c < width; c++) { |
48 | 0 | const uint8_t v = src[c]; |
49 | 0 | ss += v * v; |
50 | 0 | s += v; |
51 | 0 | } |
52 | 0 | src += src_stride; |
53 | 0 | } |
54 | |
|
55 | 0 | return (ss - s * s / (width * height)); |
56 | 0 | } |
57 | | |
58 | 0 | uint64_t aom_var_2d_u16_c(uint8_t *src, int src_stride, int width, int height) { |
59 | 0 | uint16_t *srcp = CONVERT_TO_SHORTPTR(src); |
60 | 0 | int r, c; |
61 | 0 | uint64_t ss = 0, s = 0; |
62 | |
|
63 | 0 | for (r = 0; r < height; r++) { |
64 | 0 | for (c = 0; c < width; c++) { |
65 | 0 | const uint16_t v = srcp[c]; |
66 | 0 | ss += v * v; |
67 | 0 | s += v; |
68 | 0 | } |
69 | 0 | srcp += src_stride; |
70 | 0 | } |
71 | |
|
72 | 0 | return (ss - s * s / (width * height)); |
73 | 0 | } |
74 | | |
75 | | uint64_t aom_sum_sse_2d_i16_c(const int16_t *src, int src_stride, int width, |
76 | 0 | int height, int *sum) { |
77 | 0 | int r, c; |
78 | 0 | int16_t *srcp = (int16_t *)src; |
79 | 0 | int64_t ss = 0; |
80 | |
|
81 | 0 | for (r = 0; r < height; r++) { |
82 | 0 | for (c = 0; c < width; c++) { |
83 | 0 | const int16_t v = srcp[c]; |
84 | 0 | ss += v * v; |
85 | 0 | *sum += v; |
86 | 0 | } |
87 | 0 | srcp += src_stride; |
88 | 0 | } |
89 | 0 | return ss; |
90 | 0 | } |