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