OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 static int sse_diff_thresh(BLOCK_SIZE bs, int increase_denoising, | 56 static int sse_diff_thresh(BLOCK_SIZE bs, int increase_denoising, |
57 int motion_magnitude) { | 57 int motion_magnitude) { |
58 if (motion_magnitude > | 58 if (motion_magnitude > |
59 noise_motion_thresh(bs, increase_denoising)) { | 59 noise_motion_thresh(bs, increase_denoising)) { |
60 return 0; | 60 return 0; |
61 } else { | 61 } else { |
62 return (1 << num_pels_log2_lookup[bs]) * 20; | 62 return (1 << num_pels_log2_lookup[bs]) * 20; |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 int total_adj_strong_thresh(BLOCK_SIZE bs, int increase_denoising) { | |
67 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2); | |
68 } | |
69 | |
70 static int total_adj_weak_thresh(BLOCK_SIZE bs, int increase_denoising) { | 66 static int total_adj_weak_thresh(BLOCK_SIZE bs, int increase_denoising) { |
71 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2); | 67 return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2); |
72 } | 68 } |
73 | 69 |
74 // TODO(jackychen): If increase_denoising is enabled in the future, | 70 // TODO(jackychen): If increase_denoising is enabled in the future, |
75 // we might need to update the code for calculating 'total_adj' in | 71 // we might need to update the code for calculating 'total_adj' in |
76 // case the C code is not bit-exact with corresponding sse2 code. | 72 // case the C code is not bit-exact with corresponding sse2 code. |
77 int vp9_denoiser_filter_c(const uint8_t *sig, int sig_stride, | 73 int vp9_denoiser_filter_c(const uint8_t *sig, int sig_stride, |
78 const uint8_t *mc_avg, | 74 const uint8_t *mc_avg, |
79 int mc_avg_stride, | 75 int mc_avg_stride, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 adj = adj_val[0]; | 113 adj = adj_val[0]; |
118 break; | 114 break; |
119 case 8: case 9: case 10: case 11: | 115 case 8: case 9: case 10: case 11: |
120 case 12: case 13: case 14: case 15: | 116 case 12: case 13: case 14: case 15: |
121 adj = adj_val[1]; | 117 adj = adj_val[1]; |
122 break; | 118 break; |
123 default: | 119 default: |
124 adj = adj_val[2]; | 120 adj = adj_val[2]; |
125 } | 121 } |
126 if (diff > 0) { | 122 if (diff > 0) { |
127 avg[c] = MIN(UINT8_MAX, sig[c] + adj); | 123 avg[c] = VPXMIN(UINT8_MAX, sig[c] + adj); |
128 total_adj += adj; | 124 total_adj += adj; |
129 } else { | 125 } else { |
130 avg[c] = MAX(0, sig[c] - adj); | 126 avg[c] = VPXMAX(0, sig[c] - adj); |
131 total_adj -= adj; | 127 total_adj -= adj; |
132 } | 128 } |
133 } | 129 } |
134 } | 130 } |
135 sig += sig_stride; | 131 sig += sig_stride; |
136 avg += avg_stride; | 132 avg += avg_stride; |
137 mc_avg += mc_avg_stride; | 133 mc_avg += mc_avg_stride; |
138 } | 134 } |
139 | 135 |
140 // If the strong filter did not modify the signal too much, we're all set. | 136 // If the strong filter did not modify the signal too much, we're all set. |
(...skipping 16 matching lines...) Expand all Loading... |
157 for (c = 0; c < (4 << b_width_log2_lookup[bs]); ++c) { | 153 for (c = 0; c < (4 << b_width_log2_lookup[bs]); ++c) { |
158 diff = mc_avg[c] - sig[c]; | 154 diff = mc_avg[c] - sig[c]; |
159 adj = abs(diff); | 155 adj = abs(diff); |
160 if (adj > delta) { | 156 if (adj > delta) { |
161 adj = delta; | 157 adj = delta; |
162 } | 158 } |
163 if (diff > 0) { | 159 if (diff > 0) { |
164 // Diff positive means we made positive adjustment above | 160 // Diff positive means we made positive adjustment above |
165 // (in first try/attempt), so now make negative adjustment to bring | 161 // (in first try/attempt), so now make negative adjustment to bring |
166 // denoised signal down. | 162 // denoised signal down. |
167 avg[c] = MAX(0, avg[c] - adj); | 163 avg[c] = VPXMAX(0, avg[c] - adj); |
168 total_adj -= adj; | 164 total_adj -= adj; |
169 } else { | 165 } else { |
170 // Diff negative means we made negative adjustment above | 166 // Diff negative means we made negative adjustment above |
171 // (in first try/attempt), so now make positive adjustment to bring | 167 // (in first try/attempt), so now make positive adjustment to bring |
172 // denoised signal up. | 168 // denoised signal up. |
173 avg[c] = MIN(UINT8_MAX, avg[c] + adj); | 169 avg[c] = VPXMIN(UINT8_MAX, avg[c] + adj); |
174 total_adj += adj; | 170 total_adj += adj; |
175 } | 171 } |
176 } | 172 } |
177 sig += sig_stride; | 173 sig += sig_stride; |
178 avg += avg_stride; | 174 avg += avg_stride; |
179 mc_avg += mc_avg_stride; | 175 mc_avg += mc_avg_stride; |
180 } | 176 } |
181 | 177 |
182 // We can use the filter if it has been sufficiently dampened | 178 // We can use the filter if it has been sufficiently dampened |
183 if (abs(total_adj) <= total_adj_weak_thresh(bs, increase_denoising)) { | 179 if (abs(total_adj) <= total_adj_weak_thresh(bs, increase_denoising)) { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 int ssx, int ssy, | 424 int ssx, int ssy, |
429 #if CONFIG_VP9_HIGHBITDEPTH | 425 #if CONFIG_VP9_HIGHBITDEPTH |
430 int use_highbitdepth, | 426 int use_highbitdepth, |
431 #endif | 427 #endif |
432 int border) { | 428 int border) { |
433 int i, fail; | 429 int i, fail; |
434 const int legacy_byte_alignment = 0; | 430 const int legacy_byte_alignment = 0; |
435 assert(denoiser != NULL); | 431 assert(denoiser != NULL); |
436 | 432 |
437 for (i = 0; i < MAX_REF_FRAMES; ++i) { | 433 for (i = 0; i < MAX_REF_FRAMES; ++i) { |
438 fail = vp9_alloc_frame_buffer(&denoiser->running_avg_y[i], width, height, | 434 fail = vpx_alloc_frame_buffer(&denoiser->running_avg_y[i], width, height, |
439 ssx, ssy, | 435 ssx, ssy, |
440 #if CONFIG_VP9_HIGHBITDEPTH | 436 #if CONFIG_VP9_HIGHBITDEPTH |
441 use_highbitdepth, | 437 use_highbitdepth, |
442 #endif | 438 #endif |
443 border, legacy_byte_alignment); | 439 border, legacy_byte_alignment); |
444 if (fail) { | 440 if (fail) { |
445 vp9_denoiser_free(denoiser); | 441 vp9_denoiser_free(denoiser); |
446 return 1; | 442 return 1; |
447 } | 443 } |
448 #ifdef OUTPUT_YUV_DENOISED | 444 #ifdef OUTPUT_YUV_DENOISED |
449 make_grayscale(&denoiser->running_avg_y[i]); | 445 make_grayscale(&denoiser->running_avg_y[i]); |
450 #endif | 446 #endif |
451 } | 447 } |
452 | 448 |
453 fail = vp9_alloc_frame_buffer(&denoiser->mc_running_avg_y, width, height, | 449 fail = vpx_alloc_frame_buffer(&denoiser->mc_running_avg_y, width, height, |
454 ssx, ssy, | 450 ssx, ssy, |
455 #if CONFIG_VP9_HIGHBITDEPTH | 451 #if CONFIG_VP9_HIGHBITDEPTH |
456 use_highbitdepth, | 452 use_highbitdepth, |
457 #endif | 453 #endif |
458 border, legacy_byte_alignment); | 454 border, legacy_byte_alignment); |
459 if (fail) { | 455 if (fail) { |
460 vp9_denoiser_free(denoiser); | 456 vp9_denoiser_free(denoiser); |
461 return 1; | 457 return 1; |
462 } | 458 } |
463 #ifdef OUTPUT_YUV_DENOISED | 459 #ifdef OUTPUT_YUV_DENOISED |
464 make_grayscale(&denoiser->running_avg_y[i]); | 460 make_grayscale(&denoiser->running_avg_y[i]); |
465 #endif | 461 #endif |
466 denoiser->increase_denoising = 0; | 462 denoiser->increase_denoising = 0; |
467 denoiser->frame_buffer_initialized = 1; | 463 denoiser->frame_buffer_initialized = 1; |
468 | 464 |
469 return 0; | 465 return 0; |
470 } | 466 } |
471 | 467 |
472 void vp9_denoiser_free(VP9_DENOISER *denoiser) { | 468 void vp9_denoiser_free(VP9_DENOISER *denoiser) { |
473 int i; | 469 int i; |
474 denoiser->frame_buffer_initialized = 0; | 470 denoiser->frame_buffer_initialized = 0; |
475 if (denoiser == NULL) { | 471 if (denoiser == NULL) { |
476 return; | 472 return; |
477 } | 473 } |
478 for (i = 0; i < MAX_REF_FRAMES; ++i) { | 474 for (i = 0; i < MAX_REF_FRAMES; ++i) { |
479 vp9_free_frame_buffer(&denoiser->running_avg_y[i]); | 475 vpx_free_frame_buffer(&denoiser->running_avg_y[i]); |
480 } | 476 } |
481 vp9_free_frame_buffer(&denoiser->mc_running_avg_y); | 477 vpx_free_frame_buffer(&denoiser->mc_running_avg_y); |
482 } | 478 } |
483 | 479 |
484 #ifdef OUTPUT_YUV_DENOISED | 480 #ifdef OUTPUT_YUV_DENOISED |
485 static void make_grayscale(YV12_BUFFER_CONFIG *yuv) { | 481 static void make_grayscale(YV12_BUFFER_CONFIG *yuv) { |
486 int r, c; | 482 int r, c; |
487 uint8_t *u = yuv->u_buffer; | 483 uint8_t *u = yuv->u_buffer; |
488 uint8_t *v = yuv->v_buffer; | 484 uint8_t *v = yuv->v_buffer; |
489 | 485 |
490 for (r = 0; r < yuv->uv_height; ++r) { | 486 for (r = 0; r < yuv->uv_height; ++r) { |
491 for (c = 0; c < yuv->uv_width; ++c) { | 487 for (c = 0; c < yuv->uv_width; ++c) { |
492 u[c] = UINT8_MAX / 2; | 488 u[c] = UINT8_MAX / 2; |
493 v[c] = UINT8_MAX / 2; | 489 v[c] = UINT8_MAX / 2; |
494 } | 490 } |
495 u += yuv->uv_stride; | 491 u += yuv->uv_stride; |
496 v += yuv->uv_stride; | 492 v += yuv->uv_stride; |
497 } | 493 } |
498 } | 494 } |
499 #endif | 495 #endif |
OLD | NEW |