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

Side by Side Diff: source/libvpx/vp9/encoder/vp9_temporal_filter.c

Issue 11974002: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
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 11
12 #include "vp9/common/vp9_onyxc_int.h" 12 #include "vp9/common/vp9_onyxc_int.h"
13 #include "vp9/encoder/vp9_onyx_int.h" 13 #include "vp9/encoder/vp9_onyx_int.h"
14 #include "vp9/common/vp9_systemdependent.h" 14 #include "vp9/common/vp9_systemdependent.h"
15 #include "vp9/encoder/vp9_quantize.h" 15 #include "vp9/encoder/vp9_quantize.h"
16 #include "vp9/common/vp9_alloccommon.h" 16 #include "vp9/common/vp9_alloccommon.h"
17 #include "vp9/encoder/vp9_mcomp.h" 17 #include "vp9/encoder/vp9_mcomp.h"
18 #include "vp9/encoder/vp9_firstpass.h" 18 #include "vp9/encoder/vp9_firstpass.h"
19 #include "vp9/encoder/vp9_psnr.h" 19 #include "vp9/encoder/vp9_psnr.h"
20 #include "vpx_scale/vpxscale.h" 20 #include "vpx_scale/vpx_scale.h"
21 #include "vp9/common/vp9_extend.h" 21 #include "vp9/common/vp9_extend.h"
22 #include "vp9/encoder/vp9_ratectrl.h" 22 #include "vp9/encoder/vp9_ratectrl.h"
23 #include "vp9/common/vp9_quant_common.h" 23 #include "vp9/common/vp9_quant_common.h"
24 #include "vp9/encoder/vp9_segmentation.h" 24 #include "vp9/encoder/vp9_segmentation.h"
25 #include "vpx_mem/vpx_mem.h" 25 #include "vpx_mem/vpx_mem.h"
26 #include "vp9/common/vp9_swapyv12buffer.h" 26 #include "vp9/common/vp9_swapyv12buffer.h"
27 #include "vpx_ports/vpx_timer.h" 27 #include "vpx_ports/vpx_timer.h"
28 28
29 #include <math.h> 29 #include <math.h>
30 #include <limits.h> 30 #include <limits.h>
31 31
32 #define ALT_REF_MC_ENABLED 1 // dis/enable MC in AltRef filtering 32 #define ALT_REF_MC_ENABLED 1 // dis/enable MC in AltRef filtering
33 #define ALT_REF_SUBPEL_ENABLED 1 // dis/enable subpel in MC AltRef filtering 33 #define ALT_REF_SUBPEL_ENABLED 1 // dis/enable subpel in MC AltRef filtering
34 34
35 #if VP9_TEMPORAL_ALT_REF 35 #if VP9_TEMPORAL_ALT_REF
36 36
37 37
38 static void temporal_filter_predictors_mb_c 38 static void temporal_filter_predictors_mb_c(MACROBLOCKD *xd,
39 ( 39 uint8_t *y_mb_ptr,
40 MACROBLOCKD *xd, 40 uint8_t *u_mb_ptr,
41 unsigned char *y_mb_ptr, 41 uint8_t *v_mb_ptr,
42 unsigned char *u_mb_ptr, 42 int stride,
43 unsigned char *v_mb_ptr, 43 int mv_row,
44 int stride, 44 int mv_col,
45 int mv_row, 45 uint8_t *pred) {
46 int mv_col,
47 unsigned char *pred
48 ) {
49 int offset; 46 int offset;
50 unsigned char *yptr, *uptr, *vptr; 47 uint8_t *yptr, *uptr, *vptr;
51 int omv_row, omv_col; 48 int omv_row, omv_col;
52 49
53 // Y 50 // Y
54 yptr = y_mb_ptr + (mv_row >> 3) * stride + (mv_col >> 3); 51 yptr = y_mb_ptr + (mv_row >> 3) * stride + (mv_col >> 3);
55 52
56 if ((mv_row | mv_col) & 7) { 53 if ((mv_row | mv_col) & 7) {
57 xd->subpixel_predict16x16(yptr, stride, 54 xd->subpixel_predict16x16(yptr, stride,
58 (mv_col & 7) << 1, (mv_row & 7) << 1, &pred[0], 16) ; 55 (mv_col & 7) << 1, (mv_row & 7) << 1, &pred[0], 16) ;
59 } else { 56 } else {
60 vp9_copy_mem16x16(yptr, stride, &pred[0], 16); 57 vp9_copy_mem16x16(yptr, stride, &pred[0], 16);
61 } 58 }
62 59
63 // U & V 60 // U & V
64 omv_row = mv_row; 61 omv_row = mv_row;
65 omv_col = mv_col; 62 omv_col = mv_col;
66 mv_row >>= 1; 63 mv_row >>= 1;
67 mv_col >>= 1; 64 mv_col >>= 1;
68 stride = (stride + 1) >> 1; 65 stride = (stride + 1) >> 1;
69 offset = (mv_row >> 3) * stride + (mv_col >> 3); 66 offset = (mv_row >> 3) * stride + (mv_col >> 3);
70 uptr = u_mb_ptr + offset; 67 uptr = u_mb_ptr + offset;
71 vptr = v_mb_ptr + offset; 68 vptr = v_mb_ptr + offset;
72 69
73 if ((omv_row | omv_col) & 15) { 70 if ((omv_row | omv_col) & 15) {
74 xd->subpixel_predict8x8(uptr, stride, 71 xd->subpixel_predict8x8(uptr, stride,
75 (omv_col & 15), (omv_row & 15), &pred[256], 8); 72 (omv_col & 15), (omv_row & 15), &pred[256], 8);
76 xd->subpixel_predict8x8(vptr, stride, 73 xd->subpixel_predict8x8(vptr, stride,
77 (omv_col & 15), (omv_row & 15), &pred[320], 8); 74 (omv_col & 15), (omv_row & 15), &pred[320], 8);
78 } 75 } else {
79 else {
80 vp9_copy_mem8x8(uptr, stride, &pred[256], 8); 76 vp9_copy_mem8x8(uptr, stride, &pred[256], 8);
81 vp9_copy_mem8x8(vptr, stride, &pred[320], 8); 77 vp9_copy_mem8x8(vptr, stride, &pred[320], 8);
82 } 78 }
83 } 79 }
84 void vp9_temporal_filter_apply_c 80
85 ( 81 void vp9_temporal_filter_apply_c(uint8_t *frame1,
86 unsigned char *frame1, 82 unsigned int stride,
87 unsigned int stride, 83 uint8_t *frame2,
88 unsigned char *frame2, 84 unsigned int block_size,
89 unsigned int block_size, 85 int strength,
90 int strength, 86 int filter_weight,
91 int filter_weight, 87 unsigned int *accumulator,
92 unsigned int *accumulator, 88 uint16_t *count) {
93 unsigned short *count
94 ) {
95 unsigned int i, j, k; 89 unsigned int i, j, k;
96 int modifier; 90 int modifier;
97 int byte = 0; 91 int byte = 0;
98 92
99 for (i = 0, k = 0; i < block_size; i++) { 93 for (i = 0, k = 0; i < block_size; i++) {
100 for (j = 0; j < block_size; j++, k++) { 94 for (j = 0; j < block_size; j++, k++) {
101 95
102 int src_byte = frame1[byte]; 96 int src_byte = frame1[byte];
103 int pixel_value = *frame2++; 97 int pixel_value = *frame2++;
104 98
(...skipping 17 matching lines...) Expand all
122 116
123 byte++; 117 byte++;
124 } 118 }
125 119
126 byte += stride - block_size; 120 byte += stride - block_size;
127 } 121 }
128 } 122 }
129 123
130 #if ALT_REF_MC_ENABLED 124 #if ALT_REF_MC_ENABLED
131 125
132 static int temporal_filter_find_matching_mb_c 126 static int temporal_filter_find_matching_mb_c(VP9_COMP *cpi,
133 ( 127 YV12_BUFFER_CONFIG *arf_frame,
134 VP9_COMP *cpi, 128 YV12_BUFFER_CONFIG *frame_ptr,
135 YV12_BUFFER_CONFIG *arf_frame, 129 int mb_offset,
136 YV12_BUFFER_CONFIG *frame_ptr, 130 int error_thresh) {
137 int mb_offset,
138 int error_thresh
139 ) {
140 MACROBLOCK *x = &cpi->mb; 131 MACROBLOCK *x = &cpi->mb;
141 int step_param; 132 int step_param;
142 int further_steps;
143 int sadpb = x->sadperbit16; 133 int sadpb = x->sadperbit16;
144 int bestsme = INT_MAX; 134 int bestsme = INT_MAX;
145 135
146 BLOCK *b = &x->block[0]; 136 BLOCK *b = &x->block[0];
147 BLOCKD *d = &x->e_mbd.block[0]; 137 BLOCKD *d = &x->e_mbd.block[0];
148 int_mv best_ref_mv1; 138 int_mv best_ref_mv1;
149 int_mv best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */ 139 int_mv best_ref_mv1_full; /* full-pixel value of best_ref_mv1 */
150 140
151 // Save input state 141 // Save input state
152 unsigned char **base_src = b->base_src; 142 uint8_t **base_src = b->base_src;
153 int src = b->src; 143 int src = b->src;
154 int src_stride = b->src_stride; 144 int src_stride = b->src_stride;
155 unsigned char **base_pre = d->base_pre; 145 uint8_t **base_pre = d->base_pre;
156 int pre = d->pre; 146 int pre = d->pre;
157 int pre_stride = d->pre_stride; 147 int pre_stride = d->pre_stride;
158 148
159 best_ref_mv1.as_int = 0; 149 best_ref_mv1.as_int = 0;
160 best_ref_mv1_full.as_mv.col = best_ref_mv1.as_mv.col >> 3; 150 best_ref_mv1_full.as_mv.col = best_ref_mv1.as_mv.col >> 3;
161 best_ref_mv1_full.as_mv.row = best_ref_mv1.as_mv.row >> 3; 151 best_ref_mv1_full.as_mv.row = best_ref_mv1.as_mv.row >> 3;
162 152
163 // Setup frame pointers 153 // Setup frame pointers
164 b->base_src = &arf_frame->y_buffer; 154 b->base_src = &arf_frame->y_buffer;
165 b->src_stride = arf_frame->y_stride; 155 b->src_stride = arf_frame->y_stride;
166 b->src = mb_offset; 156 b->src = mb_offset;
167 157
168 d->base_pre = &frame_ptr->y_buffer; 158 d->base_pre = &frame_ptr->y_buffer;
169 d->pre_stride = frame_ptr->y_stride; 159 d->pre_stride = frame_ptr->y_stride;
170 d->pre = mb_offset; 160 d->pre = mb_offset;
171 161
172 // Further step/diamond searches as necessary 162 // Further step/diamond searches as necessary
173 if (cpi->Speed < 8) { 163 if (cpi->Speed < 8) {
174 step_param = cpi->sf.first_step + 164 step_param = cpi->sf.first_step +
175 ((cpi->Speed > 5) ? 1 : 0); 165 ((cpi->Speed > 5) ? 1 : 0);
176 further_steps =
177 (cpi->sf.max_step_search_steps - 1) - step_param;
178 } else { 166 } else {
179 step_param = cpi->sf.first_step + 2; 167 step_param = cpi->sf.first_step + 2;
180 further_steps = 0;
181 } 168 }
182 169
183 /*cpi->sf.search_method == HEX*/ 170 /*cpi->sf.search_method == HEX*/
184 // TODO Check that the 16x16 vf & sdf are selected here 171 // TODO Check that the 16x16 vf & sdf are selected here
185 // Ignore mv costing by sending NULL pointer instead of cost arrays 172 // Ignore mv costing by sending NULL pointer instead of cost arrays
186 bestsme = vp9_hex_search(x, b, d, &best_ref_mv1_full, &d->bmi.as_mv.first, 173 bestsme = vp9_hex_search(x, b, d, &best_ref_mv1_full, &d->bmi.as_mv.first,
187 step_param, sadpb, &cpi->fn_ptr[BLOCK_16X16], 174 step_param, sadpb, &cpi->fn_ptr[BLOCK_16X16],
188 NULL, NULL, NULL, NULL, 175 NULL, NULL, NULL, NULL,
189 &best_ref_mv1); 176 &best_ref_mv1);
190 177
(...skipping 18 matching lines...) Expand all
209 b->src = src; 196 b->src = src;
210 b->src_stride = src_stride; 197 b->src_stride = src_stride;
211 d->base_pre = base_pre; 198 d->base_pre = base_pre;
212 d->pre = pre; 199 d->pre = pre;
213 d->pre_stride = pre_stride; 200 d->pre_stride = pre_stride;
214 201
215 return bestsme; 202 return bestsme;
216 } 203 }
217 #endif 204 #endif
218 205
219 static void temporal_filter_iterate_c 206 static void temporal_filter_iterate_c(VP9_COMP *cpi,
220 ( 207 int frame_count,
221 VP9_COMP *cpi, 208 int alt_ref_index,
222 int frame_count, 209 int strength) {
223 int alt_ref_index,
224 int strength
225 ) {
226 int byte; 210 int byte;
227 int frame; 211 int frame;
228 int mb_col, mb_row; 212 int mb_col, mb_row;
229 unsigned int filter_weight; 213 unsigned int filter_weight;
230 int mb_cols = cpi->common.mb_cols; 214 int mb_cols = cpi->common.mb_cols;
231 int mb_rows = cpi->common.mb_rows; 215 int mb_rows = cpi->common.mb_rows;
232 int mb_y_offset = 0; 216 int mb_y_offset = 0;
233 int mb_uv_offset = 0; 217 int mb_uv_offset = 0;
234 DECLARE_ALIGNED_ARRAY(16, unsigned int, accumulator, 16 * 16 + 8 * 8 + 8 * 8); 218 DECLARE_ALIGNED_ARRAY(16, unsigned int, accumulator, 16 * 16 + 8 * 8 + 8 * 8);
235 DECLARE_ALIGNED_ARRAY(16, unsigned short, count, 16 * 16 + 8 * 8 + 8 * 8); 219 DECLARE_ALIGNED_ARRAY(16, uint16_t, count, 16 * 16 + 8 * 8 + 8 * 8);
236 MACROBLOCKD *mbd = &cpi->mb.e_mbd; 220 MACROBLOCKD *mbd = &cpi->mb.e_mbd;
237 YV12_BUFFER_CONFIG *f = cpi->frames[alt_ref_index]; 221 YV12_BUFFER_CONFIG *f = cpi->frames[alt_ref_index];
238 unsigned char *dst1, *dst2; 222 uint8_t *dst1, *dst2;
239 DECLARE_ALIGNED_ARRAY(16, unsigned char, predictor, 16 * 16 + 8 * 8 + 8 * 8); 223 DECLARE_ALIGNED_ARRAY(16, uint8_t, predictor, 16 * 16 + 8 * 8 + 8 * 8);
240 224
241 // Save input state 225 // Save input state
242 unsigned char *y_buffer = mbd->pre.y_buffer; 226 uint8_t *y_buffer = mbd->pre.y_buffer;
243 unsigned char *u_buffer = mbd->pre.u_buffer; 227 uint8_t *u_buffer = mbd->pre.u_buffer;
244 unsigned char *v_buffer = mbd->pre.v_buffer; 228 uint8_t *v_buffer = mbd->pre.v_buffer;
245 229
246 for (mb_row = 0; mb_row < mb_rows; mb_row++) { 230 for (mb_row = 0; mb_row < mb_rows; mb_row++) {
247 #if ALT_REF_MC_ENABLED 231 #if ALT_REF_MC_ENABLED
248 // Source frames are extended to 16 pixels. This is different than 232 // Source frames are extended to 16 pixels. This is different than
249 // L/A/G reference frames that have a border of 32 (VP9BORDERINPIXELS) 233 // L/A/G reference frames that have a border of 32 (VP9BORDERINPIXELS)
250 // A 6/8 tap filter is used for motion search. This requires 2 pixels 234 // A 6/8 tap filter is used for motion search. This requires 2 pixels
251 // before and 3 pixels after. So the largest Y mv on a border would 235 // before and 3 pixels after. So the largest Y mv on a border would
252 // then be 16 - VP9_INTERP_EXTEND. The UV blocks are half the size of the 236 // then be 16 - VP9_INTERP_EXTEND. The UV blocks are half the size of the
253 // Y and therefore only extended by 8. The largest mv that a UV block 237 // Y and therefore only extended by 8. The largest mv that a UV block
254 // can support is 8 - VP9_INTERP_EXTEND. A UV mv is half of a Y mv. 238 // can support is 8 - VP9_INTERP_EXTEND. A UV mv is half of a Y mv.
255 // (16 - VP9_INTERP_EXTEND) >> 1 which is greater than 239 // (16 - VP9_INTERP_EXTEND) >> 1 which is greater than
256 // 8 - VP9_INTERP_EXTEND. 240 // 8 - VP9_INTERP_EXTEND.
257 // To keep the mv in play for both Y and UV planes the max that it 241 // To keep the mv in play for both Y and UV planes the max that it
258 // can be on a border is therefore 16 - (2*VP9_INTERP_EXTEND+1). 242 // can be on a border is therefore 16 - (2*VP9_INTERP_EXTEND+1).
259 cpi->mb.mv_row_min = -((mb_row * 16) + (17 - 2 * VP9_INTERP_EXTEND)); 243 cpi->mb.mv_row_min = -((mb_row * 16) + (17 - 2 * VP9_INTERP_EXTEND));
260 cpi->mb.mv_row_max = ((cpi->common.mb_rows - 1 - mb_row) * 16) 244 cpi->mb.mv_row_max = ((cpi->common.mb_rows - 1 - mb_row) * 16)
261 + (17 - 2 * VP9_INTERP_EXTEND); 245 + (17 - 2 * VP9_INTERP_EXTEND);
262 #endif 246 #endif
263 247
264 for (mb_col = 0; mb_col < mb_cols; mb_col++) { 248 for (mb_col = 0; mb_col < mb_cols; mb_col++) {
265 int i, j, k; 249 int i, j, k;
266 int stride; 250 int stride;
267 251
268 vpx_memset(accumulator, 0, 384 * sizeof(unsigned int)); 252 vpx_memset(accumulator, 0, 384 * sizeof(unsigned int));
269 vpx_memset(count, 0, 384 * sizeof(unsigned short)); 253 vpx_memset(count, 0, 384 * sizeof(uint16_t));
270 254
271 #if ALT_REF_MC_ENABLED 255 #if ALT_REF_MC_ENABLED
272 cpi->mb.mv_col_min = -((mb_col * 16) + (17 - 2 * VP9_INTERP_EXTEND)); 256 cpi->mb.mv_col_min = -((mb_col * 16) + (17 - 2 * VP9_INTERP_EXTEND));
273 cpi->mb.mv_col_max = ((cpi->common.mb_cols - 1 - mb_col) * 16) 257 cpi->mb.mv_col_max = ((cpi->common.mb_cols - 1 - mb_col) * 16)
274 + (17 - 2 * VP9_INTERP_EXTEND); 258 + (17 - 2 * VP9_INTERP_EXTEND);
275 #endif 259 #endif
276 260
277 for (frame = 0; frame < frame_count; frame++) { 261 for (frame = 0; frame < frame_count; frame++) {
278 if (cpi->frames[frame] == NULL) 262 if (cpi->frames[frame] == NULL)
279 continue; 263 continue;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // Normalize filter output to produce AltRef frame 318 // Normalize filter output to produce AltRef frame
335 dst1 = cpi->alt_ref_buffer.y_buffer; 319 dst1 = cpi->alt_ref_buffer.y_buffer;
336 stride = cpi->alt_ref_buffer.y_stride; 320 stride = cpi->alt_ref_buffer.y_stride;
337 byte = mb_y_offset; 321 byte = mb_y_offset;
338 for (i = 0, k = 0; i < 16; i++) { 322 for (i = 0, k = 0; i < 16; i++) {
339 for (j = 0; j < 16; j++, k++) { 323 for (j = 0; j < 16; j++, k++) {
340 unsigned int pval = accumulator[k] + (count[k] >> 1); 324 unsigned int pval = accumulator[k] + (count[k] >> 1);
341 pval *= cpi->fixed_divide[count[k]]; 325 pval *= cpi->fixed_divide[count[k]];
342 pval >>= 19; 326 pval >>= 19;
343 327
344 dst1[byte] = (unsigned char)pval; 328 dst1[byte] = (uint8_t)pval;
345 329
346 // move to next pixel 330 // move to next pixel
347 byte++; 331 byte++;
348 } 332 }
349 333
350 byte += stride - 16; 334 byte += stride - 16;
351 } 335 }
352 336
353 dst1 = cpi->alt_ref_buffer.u_buffer; 337 dst1 = cpi->alt_ref_buffer.u_buffer;
354 dst2 = cpi->alt_ref_buffer.v_buffer; 338 dst2 = cpi->alt_ref_buffer.v_buffer;
355 stride = cpi->alt_ref_buffer.uv_stride; 339 stride = cpi->alt_ref_buffer.uv_stride;
356 byte = mb_uv_offset; 340 byte = mb_uv_offset;
357 for (i = 0, k = 256; i < 8; i++) { 341 for (i = 0, k = 256; i < 8; i++) {
358 for (j = 0; j < 8; j++, k++) { 342 for (j = 0; j < 8; j++, k++) {
359 int m = k + 64; 343 int m = k + 64;
360 344
361 // U 345 // U
362 unsigned int pval = accumulator[k] + (count[k] >> 1); 346 unsigned int pval = accumulator[k] + (count[k] >> 1);
363 pval *= cpi->fixed_divide[count[k]]; 347 pval *= cpi->fixed_divide[count[k]];
364 pval >>= 19; 348 pval >>= 19;
365 dst1[byte] = (unsigned char)pval; 349 dst1[byte] = (uint8_t)pval;
366 350
367 // V 351 // V
368 pval = accumulator[m] + (count[m] >> 1); 352 pval = accumulator[m] + (count[m] >> 1);
369 pval *= cpi->fixed_divide[count[m]]; 353 pval *= cpi->fixed_divide[count[m]];
370 pval >>= 19; 354 pval >>= 19;
371 dst2[byte] = (unsigned char)pval; 355 dst2[byte] = (uint8_t)pval;
372 356
373 // move to next pixel 357 // move to next pixel
374 byte++; 358 byte++;
375 } 359 }
376 360
377 byte += stride - 8; 361 byte += stride - 8;
378 } 362 }
379 363
380 mb_y_offset += 16; 364 mb_y_offset += 16;
381 mb_uv_offset += 8; 365 mb_uv_offset += 8;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 cpi->frames[frames_to_blur - 1 - frame] = &buf->img; 473 cpi->frames[frames_to_blur - 1 - frame] = &buf->img;
490 } 474 }
491 475
492 temporal_filter_iterate_c( 476 temporal_filter_iterate_c(
493 cpi, 477 cpi,
494 frames_to_blur, 478 frames_to_blur,
495 frames_to_blur_backward, 479 frames_to_blur_backward,
496 strength); 480 strength);
497 } 481 }
498 #endif 482 #endif
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_temporal_filter.h ('k') | source/libvpx/vp9/encoder/vp9_tokenize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698