/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_config.h" |
15 | | #include "config/aom_dsp_rtcd.h" |
16 | | |
17 | | uint64_t aom_sum_squares_2d_i16_c(const int16_t *src, int src_stride, int width, |
18 | 0 | int height) { |
19 | 0 | int r, c; |
20 | 0 | uint64_t ss = 0; |
21 | |
|
22 | 0 | for (r = 0; r < height; r++) { |
23 | 0 | for (c = 0; c < width; c++) { |
24 | 0 | const int16_t v = src[c]; |
25 | 0 | ss += v * v; |
26 | 0 | } |
27 | 0 | src += src_stride; |
28 | 0 | } |
29 | |
|
30 | 0 | return ss; |
31 | 0 | } |
32 | | |
33 | 0 | uint64_t aom_sum_squares_i16_c(const int16_t *src, uint32_t n) { |
34 | 0 | uint64_t ss = 0; |
35 | 0 | do { |
36 | 0 | const int16_t v = *src++; |
37 | 0 | ss += v * v; |
38 | 0 | } while (--n); |
39 | |
|
40 | 0 | return ss; |
41 | 0 | } |
42 | | |
43 | 0 | uint64_t aom_var_2d_u8_c(uint8_t *src, int src_stride, int width, int height) { |
44 | 0 | int r, c; |
45 | 0 | uint64_t ss = 0, s = 0; |
46 | |
|
47 | 0 | for (r = 0; r < height; r++) { |
48 | 0 | for (c = 0; c < width; c++) { |
49 | 0 | const uint8_t v = src[c]; |
50 | 0 | ss += v * v; |
51 | 0 | s += v; |
52 | 0 | } |
53 | 0 | src += src_stride; |
54 | 0 | } |
55 | |
|
56 | 0 | return (ss - s * s / (width * height)); |
57 | 0 | } |
58 | | |
59 | | #if CONFIG_AV1_HIGHBITDEPTH |
60 | 0 | uint64_t aom_var_2d_u16_c(uint8_t *src, int src_stride, int width, int height) { |
61 | 0 | uint16_t *srcp = CONVERT_TO_SHORTPTR(src); |
62 | 0 | int r, c; |
63 | 0 | uint64_t ss = 0, s = 0; |
64 | |
|
65 | 0 | for (r = 0; r < height; r++) { |
66 | 0 | for (c = 0; c < width; c++) { |
67 | 0 | const uint16_t v = srcp[c]; |
68 | 0 | ss += v * v; |
69 | 0 | s += v; |
70 | 0 | } |
71 | 0 | srcp += src_stride; |
72 | 0 | } |
73 | |
|
74 | 0 | return (ss - s * s / (width * height)); |
75 | 0 | } |
76 | | #endif // CONFIG_AV1_HIGHBITDEPTH |
77 | | |
78 | | uint64_t aom_sum_sse_2d_i16_c(const int16_t *src, int src_stride, int width, |
79 | 0 | int height, int *sum) { |
80 | 0 | int r, c; |
81 | 0 | int16_t *srcp = (int16_t *)src; |
82 | 0 | int64_t ss = 0; |
83 | |
|
84 | 0 | for (r = 0; r < height; r++) { |
85 | 0 | for (c = 0; c < width; c++) { |
86 | 0 | const int16_t v = srcp[c]; |
87 | 0 | ss += v * v; |
88 | 0 | *sum += v; |
89 | 0 | } |
90 | 0 | srcp += src_stride; |
91 | 0 | } |
92 | 0 | return ss; |
93 | 0 | } |