Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: source/libvpx/vp8/common/variance_c.c

Issue 1162573005: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/libvpx/vp8/common/variance.h ('k') | source/libvpx/vp8/common/x86/variance_impl_mmx.asm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "./vp8_rtcd.h"
12 #include "filter.h"
13 #include "variance.h"
11 14
12 #include "variance.h" 15 /* This is a bad idea.
13 #include "filter.h" 16 * ctz = count trailing zeros */
14 17 static int ctz(int a) {
15 18 int b = 0;
16 unsigned int vp8_get_mb_ss_c 19 while (a != 1) {
17 ( 20 a >>= 1;
18 const short *src_ptr 21 b++;
19 ) 22 }
20 { 23 return b;
21 unsigned int i = 0, sum = 0;
22
23 do
24 {
25 sum += (src_ptr[i] * src_ptr[i]);
26 i++;
27 }
28 while (i < 256);
29
30 return sum;
31 } 24 }
32 25
33 26 static unsigned int variance(
34 static void variance(
35 const unsigned char *src_ptr, 27 const unsigned char *src_ptr,
36 int source_stride, 28 int source_stride,
37 const unsigned char *ref_ptr, 29 const unsigned char *ref_ptr,
38 int recon_stride, 30 int recon_stride,
39 int w, 31 int w,
40 int h, 32 int h,
41 unsigned int *sse, 33 unsigned int *sse)
42 int *sum)
43 { 34 {
44 int i, j; 35 int i, j;
45 int diff; 36 int diff, sum;
46 37
47 *sum = 0; 38 sum = 0;
48 *sse = 0; 39 *sse = 0;
49 40
50 for (i = 0; i < h; i++) 41 for (i = 0; i < h; i++)
51 { 42 {
52 for (j = 0; j < w; j++) 43 for (j = 0; j < w; j++)
53 { 44 {
54 diff = src_ptr[j] - ref_ptr[j]; 45 diff = src_ptr[j] - ref_ptr[j];
55 *sum += diff; 46 sum += diff;
56 *sse += diff * diff; 47 *sse += diff * diff;
57 } 48 }
58 49
59 src_ptr += source_stride; 50 src_ptr += source_stride;
60 ref_ptr += recon_stride; 51 ref_ptr += recon_stride;
61 } 52 }
53
54 return (*sse - (((unsigned int)sum * sum) >> (int)((ctz(w) + ctz(h)))));
62 } 55 }
63 56
64
65 unsigned int vp8_variance16x16_c(
66 const unsigned char *src_ptr,
67 int source_stride,
68 const unsigned char *ref_ptr,
69 int recon_stride,
70 unsigned int *sse)
71 {
72 unsigned int var;
73 int avg;
74
75
76 variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 16, &var, &avg);
77 *sse = var;
78 return (var - (((unsigned int)avg * avg) >> 8));
79 }
80
81 unsigned int vp8_variance8x16_c(
82 const unsigned char *src_ptr,
83 int source_stride,
84 const unsigned char *ref_ptr,
85 int recon_stride,
86 unsigned int *sse)
87 {
88 unsigned int var;
89 int avg;
90
91
92 variance(src_ptr, source_stride, ref_ptr, recon_stride, 8, 16, &var, &avg);
93 *sse = var;
94 return (var - (((unsigned int)avg * avg) >> 7));
95 }
96
97 unsigned int vp8_variance16x8_c(
98 const unsigned char *src_ptr,
99 int source_stride,
100 const unsigned char *ref_ptr,
101 int recon_stride,
102 unsigned int *sse)
103 {
104 unsigned int var;
105 int avg;
106
107
108 variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 8, &var, &avg);
109 *sse = var;
110 return (var - (((unsigned int)avg * avg) >> 7));
111 }
112
113
114 unsigned int vp8_variance8x8_c(
115 const unsigned char *src_ptr,
116 int source_stride,
117 const unsigned char *ref_ptr,
118 int recon_stride,
119 unsigned int *sse)
120 {
121 unsigned int var;
122 int avg;
123
124
125 variance(src_ptr, source_stride, ref_ptr, recon_stride, 8, 8, &var, &avg);
126 *sse = var;
127 return (var - (((unsigned int)avg * avg) >> 6));
128 }
129
130 unsigned int vp8_variance4x4_c(
131 const unsigned char *src_ptr,
132 int source_stride,
133 const unsigned char *ref_ptr,
134 int recon_stride,
135 unsigned int *sse)
136 {
137 unsigned int var;
138 int avg;
139
140
141 variance(src_ptr, source_stride, ref_ptr, recon_stride, 4, 4, &var, &avg);
142 *sse = var;
143 return (var - (((unsigned int)avg * avg) >> 4));
144 }
145
146
147 unsigned int vp8_mse16x16_c(
148 const unsigned char *src_ptr,
149 int source_stride,
150 const unsigned char *ref_ptr,
151 int recon_stride,
152 unsigned int *sse)
153 {
154 unsigned int var;
155 int avg;
156
157 variance(src_ptr, source_stride, ref_ptr, recon_stride, 16, 16, &var, &avg);
158 *sse = var;
159 return var;
160 }
161
162
163 /**************************************************************************** 57 /****************************************************************************
164 * 58 *
165 * ROUTINE : filter_block2d_bil_first_pass 59 * ROUTINE : filter_block2d_bil_first_pass
166 * 60 *
167 * INPUTS : UINT8 *src_ptr : Pointer to source block. 61 * INPUTS : UINT8 *src_ptr : Pointer to source block.
168 * UINT32 src_pixels_per_line : Stride of input block. 62 * UINT32 src_pixels_per_line : Stride of input block.
169 * UINT32 pixel_step : Offset between filter input sampl es (see notes). 63 * UINT32 pixel_step : Offset between filter input sampl es (see notes).
170 * UINT32 output_height : Input block height. 64 * UINT32 output_height : Input block height.
171 * UINT32 output_width : Input block width. 65 * UINT32 output_width : Input block width.
172 * INT32 *vp8_filter : Array of 2 bi-linear filter ta ps. 66 * INT32 *vp8_filter : Array of 2 bi-linear filter ta ps.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 190
297 HFilter = vp8_bilinear_filters[xoffset]; 191 HFilter = vp8_bilinear_filters[xoffset];
298 VFilter = vp8_bilinear_filters[yoffset]; 192 VFilter = vp8_bilinear_filters[yoffset];
299 193
300 /* First filter 1d Horizontal */ 194 /* First filter 1d Horizontal */
301 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 5 , 4, HFilter); 195 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 5 , 4, HFilter);
302 196
303 /* Now filter Verticaly */ 197 /* Now filter Verticaly */
304 var_filter_block2d_bil_second_pass(FData3, temp2, 4, 4, 4, 4, VFilter); 198 var_filter_block2d_bil_second_pass(FData3, temp2, 4, 4, 4, 4, VFilter);
305 199
306 return vp8_variance4x4_c(temp2, 4, dst_ptr, dst_pixels_per_line, sse); 200 return variance(temp2, 4, dst_ptr, dst_pixels_per_line, 4, 4, sse);
307 } 201 }
308 202
309 203
310 unsigned int vp8_sub_pixel_variance8x8_c 204 unsigned int vp8_sub_pixel_variance8x8_c
311 ( 205 (
312 const unsigned char *src_ptr, 206 const unsigned char *src_ptr,
313 int src_pixels_per_line, 207 int src_pixels_per_line,
314 int xoffset, 208 int xoffset,
315 int yoffset, 209 int yoffset,
316 const unsigned char *dst_ptr, 210 const unsigned char *dst_ptr,
317 int dst_pixels_per_line, 211 int dst_pixels_per_line,
318 unsigned int *sse 212 unsigned int *sse
319 ) 213 )
320 { 214 {
321 unsigned short FData3[9*8]; /* Temp data bufffer used in filtering */ 215 unsigned short FData3[9*8]; /* Temp data bufffer used in filtering */
322 unsigned char temp2[20*16]; 216 unsigned char temp2[20*16];
323 const short *HFilter, *VFilter; 217 const short *HFilter, *VFilter;
324 218
325 HFilter = vp8_bilinear_filters[xoffset]; 219 HFilter = vp8_bilinear_filters[xoffset];
326 VFilter = vp8_bilinear_filters[yoffset]; 220 VFilter = vp8_bilinear_filters[yoffset];
327 221
328 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 9 , 8, HFilter); 222 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 9 , 8, HFilter);
329 var_filter_block2d_bil_second_pass(FData3, temp2, 8, 8, 8, 8, VFilter); 223 var_filter_block2d_bil_second_pass(FData3, temp2, 8, 8, 8, 8, VFilter);
330 224
331 return vp8_variance8x8_c(temp2, 8, dst_ptr, dst_pixels_per_line, sse); 225 return variance(temp2, 8, dst_ptr, dst_pixels_per_line, 8, 8, sse);
332 } 226 }
333 227
334 unsigned int vp8_sub_pixel_variance16x16_c 228 unsigned int vp8_sub_pixel_variance16x16_c
335 ( 229 (
336 const unsigned char *src_ptr, 230 const unsigned char *src_ptr,
337 int src_pixels_per_line, 231 int src_pixels_per_line,
338 int xoffset, 232 int xoffset,
339 int yoffset, 233 int yoffset,
340 const unsigned char *dst_ptr, 234 const unsigned char *dst_ptr,
341 int dst_pixels_per_line, 235 int dst_pixels_per_line,
342 unsigned int *sse 236 unsigned int *sse
343 ) 237 )
344 { 238 {
345 unsigned short FData3[17*16]; /* Temp data bufffer used in filtering */ 239 unsigned short FData3[17*16]; /* Temp data bufffer used in filtering */
346 unsigned char temp2[20*16]; 240 unsigned char temp2[20*16];
347 const short *HFilter, *VFilter; 241 const short *HFilter, *VFilter;
348 242
349 HFilter = vp8_bilinear_filters[xoffset]; 243 HFilter = vp8_bilinear_filters[xoffset];
350 VFilter = vp8_bilinear_filters[yoffset]; 244 VFilter = vp8_bilinear_filters[yoffset];
351 245
352 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 1 7, 16, HFilter); 246 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 1 7, 16, HFilter);
353 var_filter_block2d_bil_second_pass(FData3, temp2, 16, 16, 16, 16, VFilter); 247 var_filter_block2d_bil_second_pass(FData3, temp2, 16, 16, 16, 16, VFilter);
354 248
355 return vp8_variance16x16_c(temp2, 16, dst_ptr, dst_pixels_per_line, sse); 249 return variance(temp2, 16, dst_ptr, dst_pixels_per_line, 16, 16, sse);
356 } 250 }
357 251
358 252
359 unsigned int vp8_variance_halfpixvar16x16_h_c( 253 unsigned int vp8_variance_halfpixvar16x16_h_c(
360 const unsigned char *src_ptr, 254 const unsigned char *src_ptr,
361 int source_stride, 255 int source_stride,
362 const unsigned char *ref_ptr, 256 const unsigned char *ref_ptr,
363 int recon_stride, 257 int recon_stride,
364 unsigned int *sse) 258 unsigned int *sse)
365 { 259 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 unsigned short FData3[16*9]; /* Temp data bufffer used in filtering */ 315 unsigned short FData3[16*9]; /* Temp data bufffer used in filtering */
422 unsigned char temp2[20*16]; 316 unsigned char temp2[20*16];
423 const short *HFilter, *VFilter; 317 const short *HFilter, *VFilter;
424 318
425 HFilter = vp8_bilinear_filters[xoffset]; 319 HFilter = vp8_bilinear_filters[xoffset];
426 VFilter = vp8_bilinear_filters[yoffset]; 320 VFilter = vp8_bilinear_filters[yoffset];
427 321
428 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 9 , 16, HFilter); 322 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 9 , 16, HFilter);
429 var_filter_block2d_bil_second_pass(FData3, temp2, 16, 16, 8, 16, VFilter); 323 var_filter_block2d_bil_second_pass(FData3, temp2, 16, 16, 8, 16, VFilter);
430 324
431 return vp8_variance16x8_c(temp2, 16, dst_ptr, dst_pixels_per_line, sse); 325 return variance(temp2, 16, dst_ptr, dst_pixels_per_line, 16, 8, sse);
432 } 326 }
433 327
434 unsigned int vp8_sub_pixel_variance8x16_c 328 unsigned int vp8_sub_pixel_variance8x16_c
435 ( 329 (
436 const unsigned char *src_ptr, 330 const unsigned char *src_ptr,
437 int src_pixels_per_line, 331 int src_pixels_per_line,
438 int xoffset, 332 int xoffset,
439 int yoffset, 333 int yoffset,
440 const unsigned char *dst_ptr, 334 const unsigned char *dst_ptr,
441 int dst_pixels_per_line, 335 int dst_pixels_per_line,
442 unsigned int *sse 336 unsigned int *sse
443 ) 337 )
444 { 338 {
445 unsigned short FData3[9*16]; /* Temp data bufffer used in filtering */ 339 unsigned short FData3[9*16]; /* Temp data bufffer used in filtering */
446 unsigned char temp2[20*16]; 340 unsigned char temp2[20*16];
447 const short *HFilter, *VFilter; 341 const short *HFilter, *VFilter;
448 342
449 343
450 HFilter = vp8_bilinear_filters[xoffset]; 344 HFilter = vp8_bilinear_filters[xoffset];
451 VFilter = vp8_bilinear_filters[yoffset]; 345 VFilter = vp8_bilinear_filters[yoffset];
452 346
453 347
454 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 1 7, 8, HFilter); 348 var_filter_block2d_bil_first_pass(src_ptr, FData3, src_pixels_per_line, 1, 1 7, 8, HFilter);
455 var_filter_block2d_bil_second_pass(FData3, temp2, 8, 8, 16, 8, VFilter); 349 var_filter_block2d_bil_second_pass(FData3, temp2, 8, 8, 16, 8, VFilter);
456 350
457 return vp8_variance8x16_c(temp2, 8, dst_ptr, dst_pixels_per_line, sse); 351 return variance(temp2, 8, dst_ptr, dst_pixels_per_line, 8, 16, sse);
458 } 352 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/common/variance.h ('k') | source/libvpx/vp8/common/x86/variance_impl_mmx.asm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698