variance_c.c 13.6 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
6
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9
10
11
12
 */


#include "variance.h"
13
#include "vp9/common/filter.h"
14
#include "vp9/common/subpelvar.h"
John Koleszar's avatar
John Koleszar committed
15
16


17
18
unsigned int vp9_get_mb_ss_c(const short *src_ptr) {
  unsigned int i, sum = 0;
John Koleszar's avatar
John Koleszar committed
19

20
  for (i = 0; i < 256; i++) {
John Koleszar's avatar
John Koleszar committed
21
    sum += (src_ptr[i] * src_ptr[i]);
22
  }
John Koleszar's avatar
John Koleszar committed
23

John Koleszar's avatar
John Koleszar committed
24
  return sum;
John Koleszar's avatar
John Koleszar committed
25
26
27
28
}



Ronald S. Bultje's avatar
Ronald S. Bultje committed
29
#if CONFIG_SUPERBLOCKS
30
unsigned int vp9_variance32x32_c(const unsigned char *src_ptr,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
31
32
33
34
35
36
37
38
39
                                 int  source_stride,
                                 const unsigned char *ref_ptr,
                                 int  recon_stride,
                                 unsigned int *sse) {
  unsigned int var;
  int avg;

  variance(src_ptr, source_stride, ref_ptr, recon_stride, 32, 32, &var, &avg);
  *sse = var;
40
41
  // TODO(rbultje): in extreme cases these products will rollover.
  return (var - (((unsigned int)avg * avg) >> 10));
Ronald S. Bultje's avatar
Ronald S. Bultje committed
42
43
}
#endif
John Koleszar's avatar
John Koleszar committed
44

45
46
47
48
49
unsigned int vp9_variance16x16_c(const unsigned char *src_ptr,
                                 int  source_stride,
                                 const unsigned char *ref_ptr,
                                 int  recon_stride,
                                 unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
50
51
52
53
54
  unsigned int var;
  int avg;

  variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 16, &var, &avg);
  *sse = var;
55
  return (var - (((unsigned int)avg * avg) >> 8));
John Koleszar's avatar
John Koleszar committed
56
57
}

58
59
60
61
62
unsigned int vp9_variance8x16_c(const unsigned char *src_ptr,
                                int  source_stride,
                                const unsigned char *ref_ptr,
                                int  recon_stride,
                                unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
63
64
65
66
67
  unsigned int var;
  int avg;

  variance(src_ptr, source_stride, ref_ptr, recon_stride, 8, 16, &var, &avg);
  *sse = var;
68
  return (var - (((unsigned int)avg * avg) >> 7));
John Koleszar's avatar
John Koleszar committed
69
70
}

71
72
73
74
75
unsigned int vp9_variance16x8_c(const unsigned char *src_ptr,
                                int  source_stride,
                                const unsigned char *ref_ptr,
                                int  recon_stride,
                                unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
76
77
78
79
80
  unsigned int var;
  int avg;

  variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 8, &var, &avg);
  *sse = var;
81
  return (var - (((unsigned int)avg * avg) >> 7));
John Koleszar's avatar
John Koleszar committed
82
83
84
}


85
86
87
88
89
unsigned int vp9_variance8x8_c(const unsigned char *src_ptr,
                               int  source_stride,
                               const unsigned char *ref_ptr,
                               int  recon_stride,
                               unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
90
91
92
93
94
  unsigned int var;
  int avg;

  variance(src_ptr, source_stride, ref_ptr, recon_stride, 8, 8, &var, &avg);
  *sse = var;
95
  return (var - (((unsigned int)avg * avg) >> 6));
John Koleszar's avatar
John Koleszar committed
96
97
}

98
99
100
101
102
unsigned int vp9_variance4x4_c(const unsigned char *src_ptr,
                               int  source_stride,
                               const unsigned char *ref_ptr,
                               int  recon_stride,
                               unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
103
104
105
106
107
  unsigned int var;
  int avg;

  variance(src_ptr, source_stride, ref_ptr, recon_stride, 4, 4, &var, &avg);
  *sse = var;
108
  return (var - (((unsigned int)avg * avg) >> 4));
John Koleszar's avatar
John Koleszar committed
109
110
111
}


112
113
114
115
116
unsigned int vp9_mse16x16_c(const unsigned char *src_ptr,
                            int  source_stride,
                            const unsigned char *ref_ptr,
                            int  recon_stride,
                            unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
117
118
119
120
121
122
  unsigned int var;
  int avg;

  variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 16, &var, &avg);
  *sse = var;
  return var;
John Koleszar's avatar
John Koleszar committed
123
124
125
}


126
127
128
129
130
131
132
unsigned int vp9_sub_pixel_variance4x4_c(const unsigned char  *src_ptr,
                                         int  src_pixels_per_line,
                                         int  xoffset,
                                         int  yoffset,
                                         const unsigned char *dst_ptr,
                                         int dst_pixels_per_line,
                                         unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
133
134
135
136
  unsigned char  temp2[20 * 16];
  const short *HFilter, *VFilter;
  unsigned short FData3[5 * 4]; // Temp data bufffer used in filtering

137
138
  HFilter = vp9_bilinear_filters[xoffset];
  VFilter = vp9_bilinear_filters[yoffset];
John Koleszar's avatar
John Koleszar committed
139
140
141
142
143
144
145

  // First filter 1d Horizontal
  var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 5, 4, HFilter);

  // Now filter Verticaly
  var_filter_block2d_bil_second_pass(FData3, temp2, 4,  4,  4,  4, VFilter);

146
  return vp9_variance4x4_c(temp2, 4, dst_ptr, dst_pixels_per_line, sse);
John Koleszar's avatar
John Koleszar committed
147
148
149
}


150
151
152
153
154
155
156
unsigned int vp9_sub_pixel_variance8x8_c(const unsigned char  *src_ptr,
                                         int  src_pixels_per_line,
                                         int  xoffset,
                                         int  yoffset,
                                         const unsigned char *dst_ptr,
                                         int dst_pixels_per_line,
                                         unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
157
158
159
160
  unsigned short FData3[9 * 8]; // Temp data bufffer used in filtering
  unsigned char  temp2[20 * 16];
  const short *HFilter, *VFilter;

161
162
  HFilter = vp9_bilinear_filters[xoffset];
  VFilter = vp9_bilinear_filters[yoffset];
John Koleszar's avatar
John Koleszar committed
163
164
165
166

  var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 9, 8, HFilter);
  var_filter_block2d_bil_second_pass(FData3, temp2, 8, 8, 8, 8, VFilter);

167
  return vp9_variance8x8_c(temp2, 8, dst_ptr, dst_pixels_per_line, sse);
John Koleszar's avatar
John Koleszar committed
168
169
}

170
171
172
173
174
175
176
unsigned int vp9_sub_pixel_variance16x16_c(const unsigned char  *src_ptr,
                                           int  src_pixels_per_line,
                                           int  xoffset,
                                           int  yoffset,
                                           const unsigned char *dst_ptr,
                                           int dst_pixels_per_line,
                                           unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
177
178
179
180
  unsigned short FData3[17 * 16]; // Temp data bufffer used in filtering
  unsigned char  temp2[20 * 16];
  const short *HFilter, *VFilter;

181
182
  HFilter = vp9_bilinear_filters[xoffset];
  VFilter = vp9_bilinear_filters[yoffset];
John Koleszar's avatar
John Koleszar committed
183
184
185
186

  var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 17, 16, HFilter);
  var_filter_block2d_bil_second_pass(FData3, temp2, 16, 16, 16, 16, VFilter);

187
  return vp9_variance16x16_c(temp2, 16, dst_ptr, dst_pixels_per_line, sse);
John Koleszar's avatar
John Koleszar committed
188
189
}

Ronald S. Bultje's avatar
Ronald S. Bultje committed
190
#if CONFIG_SUPERBLOCKS
191
unsigned int vp9_sub_pixel_variance32x32_c(const unsigned char  *src_ptr,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
192
193
194
195
196
197
198
199
200
201
                                           int  src_pixels_per_line,
                                           int  xoffset,
                                           int  yoffset,
                                           const unsigned char *dst_ptr,
                                           int dst_pixels_per_line,
                                           unsigned int *sse) {
  unsigned short FData3[33 * 32]; // Temp data bufffer used in filtering
  unsigned char  temp2[36 * 32];
  const short *HFilter, *VFilter;

202
203
  HFilter = vp9_bilinear_filters[xoffset];
  VFilter = vp9_bilinear_filters[yoffset];
Ronald S. Bultje's avatar
Ronald S. Bultje committed
204
205
206
207

  var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 33, 32, HFilter);
  var_filter_block2d_bil_second_pass(FData3, temp2, 32, 32, 32, 32, VFilter);

208
  return vp9_variance32x32_c(temp2, 32, dst_ptr, dst_pixels_per_line, sse);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
209
210
}
#endif
211

212
213
214
215
216
unsigned int vp9_variance_halfpixvar16x16_h_c(const unsigned char *src_ptr,
                                              int  source_stride,
                                              const unsigned char *ref_ptr,
                                              int  recon_stride,
                                              unsigned int *sse) {
217
  return vp9_sub_pixel_variance16x16_c(src_ptr, source_stride, 8, 0,
John Koleszar's avatar
John Koleszar committed
218
                                       ref_ptr, recon_stride, sse);
219
220
}

Ronald S. Bultje's avatar
Ronald S. Bultje committed
221
#if CONFIG_SUPERBLOCKS
222
unsigned int vp9_variance_halfpixvar32x32_h_c(const unsigned char *src_ptr,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
223
224
225
226
                                              int  source_stride,
                                              const unsigned char *ref_ptr,
                                              int  recon_stride,
                                              unsigned int *sse) {
227
  return vp9_sub_pixel_variance32x32_c(src_ptr, source_stride, 8, 0,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
228
229
230
231
                                       ref_ptr, recon_stride, sse);
}
#endif

232

233
unsigned int vp9_variance_halfpixvar16x16_v_c(const unsigned char *src_ptr,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
234
235
236
237
                                              int  source_stride,
                                              const unsigned char *ref_ptr,
                                              int  recon_stride,
                                              unsigned int *sse) {
238
  return vp9_sub_pixel_variance16x16_c(src_ptr, source_stride, 0, 8,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
239
240
241
242
                                       ref_ptr, recon_stride, sse);
}

#if CONFIG_SUPERBLOCKS
243
244
245
246
247
unsigned int vp9_variance_halfpixvar32x32_v_c(const unsigned char *src_ptr,
                                              int  source_stride,
                                              const unsigned char *ref_ptr,
                                              int  recon_stride,
                                              unsigned int *sse) {
248
  return vp9_sub_pixel_variance32x32_c(src_ptr, source_stride, 0, 8,
John Koleszar's avatar
John Koleszar committed
249
                                       ref_ptr, recon_stride, sse);
250
}
Ronald S. Bultje's avatar
Ronald S. Bultje committed
251
#endif
252

253
254
255
256
257
unsigned int vp9_variance_halfpixvar16x16_hv_c(const unsigned char *src_ptr,
                                               int  source_stride,
                                               const unsigned char *ref_ptr,
                                               int  recon_stride,
                                               unsigned int *sse) {
258
  return vp9_sub_pixel_variance16x16_c(src_ptr, source_stride, 8, 8,
John Koleszar's avatar
John Koleszar committed
259
                                       ref_ptr, recon_stride, sse);
260
261
}

Ronald S. Bultje's avatar
Ronald S. Bultje committed
262
#if CONFIG_SUPERBLOCKS
263
unsigned int vp9_variance_halfpixvar32x32_hv_c(const unsigned char *src_ptr,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
264
265
266
267
                                               int  source_stride,
                                               const unsigned char *ref_ptr,
                                               int  recon_stride,
                                               unsigned int *sse) {
268
  return vp9_sub_pixel_variance32x32_c(src_ptr, source_stride, 8, 8,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
269
270
271
                                       ref_ptr, recon_stride, sse);
}
#endif
272

273
274
275
276
277
278
279
280
281
282
unsigned int vp9_sub_pixel_mse16x16_c(const unsigned char  *src_ptr,
                                      int  src_pixels_per_line,
                                      int  xoffset,
                                      int  yoffset,
                                      const unsigned char *dst_ptr,
                                      int dst_pixels_per_line,
                                      unsigned int *sse) {
  vp9_sub_pixel_variance16x16_c(src_ptr, src_pixels_per_line,
                                xoffset, yoffset, dst_ptr,
                                dst_pixels_per_line, sse);
John Koleszar's avatar
John Koleszar committed
283
  return *sse;
John Koleszar's avatar
John Koleszar committed
284
285
}

Ronald S. Bultje's avatar
Ronald S. Bultje committed
286
#if CONFIG_SUPERBLOCKS
287
unsigned int vp9_sub_pixel_mse32x32_c(const unsigned char  *src_ptr,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
288
289
290
291
292
293
                                      int  src_pixels_per_line,
                                      int  xoffset,
                                      int  yoffset,
                                      const unsigned char *dst_ptr,
                                      int dst_pixels_per_line,
                                      unsigned int *sse) {
294
295
296
  vp9_sub_pixel_variance32x32_c(src_ptr, src_pixels_per_line,
                                xoffset, yoffset, dst_ptr,
                                dst_pixels_per_line, sse);
Ronald S. Bultje's avatar
Ronald S. Bultje committed
297
298
299
300
  return *sse;
}
#endif

301
302
303
304
305
306
307
unsigned int vp9_sub_pixel_variance16x8_c(const unsigned char  *src_ptr,
                                          int  src_pixels_per_line,
                                          int  xoffset,
                                          int  yoffset,
                                          const unsigned char *dst_ptr,
                                          int dst_pixels_per_line,
                                          unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
308
309
310
311
  unsigned short FData3[16 * 9];  // Temp data bufffer used in filtering
  unsigned char  temp2[20 * 16];
  const short *HFilter, *VFilter;

312
313
  HFilter = vp9_bilinear_filters[xoffset];
  VFilter = vp9_bilinear_filters[yoffset];
John Koleszar's avatar
John Koleszar committed
314
315
316
317

  var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 9, 16, HFilter);
  var_filter_block2d_bil_second_pass(FData3, temp2, 16, 16, 8, 16, VFilter);

318
  return vp9_variance16x8_c(temp2, 16, dst_ptr, dst_pixels_per_line, sse);
John Koleszar's avatar
John Koleszar committed
319
320
}

321
322
323
324
325
326
327
unsigned int vp9_sub_pixel_variance8x16_c(const unsigned char  *src_ptr,
                                          int  src_pixels_per_line,
                                          int  xoffset,
                                          int  yoffset,
                                          const unsigned char *dst_ptr,
                                          int dst_pixels_per_line,
                                          unsigned int *sse) {
John Koleszar's avatar
John Koleszar committed
328
329
330
  unsigned short FData3[9 * 16];  // Temp data bufffer used in filtering
  unsigned char  temp2[20 * 16];
  const short *HFilter, *VFilter;
John Koleszar's avatar
John Koleszar committed
331

332
333
  HFilter = vp9_bilinear_filters[xoffset];
  VFilter = vp9_bilinear_filters[yoffset];
John Koleszar's avatar
John Koleszar committed
334

335
336
  var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line,
                                    1, 17, 8, HFilter);
John Koleszar's avatar
John Koleszar committed
337
  var_filter_block2d_bil_second_pass(FData3, temp2, 8, 8, 16, 8, VFilter);
John Koleszar's avatar
John Koleszar committed
338

339
  return vp9_variance8x16_c(temp2, 8, dst_ptr, dst_pixels_per_line, sse);
John Koleszar's avatar
John Koleszar committed
340
}
341