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