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

Side by Side Diff: source/libvpx/vp9/common/vp9_postproc.c

Issue 1124333011: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: only update to last nights LKGR Created 5 years, 7 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/vp9/common/vp9_onyxc_int.h ('k') | source/libvpx/vp9/common/vp9_pred_common.c » ('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
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 void vp9_post_proc_down_and_across_c(const uint8_t *src_ptr, 85 void vp9_post_proc_down_and_across_c(const uint8_t *src_ptr,
86 uint8_t *dst_ptr, 86 uint8_t *dst_ptr,
87 int src_pixels_per_line, 87 int src_pixels_per_line,
88 int dst_pixels_per_line, 88 int dst_pixels_per_line,
89 int rows, 89 int rows,
90 int cols, 90 int cols,
91 int flimit) { 91 int flimit) {
92 uint8_t const *p_src; 92 uint8_t const *p_src;
93 uint8_t *p_dst; 93 uint8_t *p_dst;
94 int row; 94 int row, col, i, v, kernel;
95 int col;
96 int i;
97 int v;
98 int pitch = src_pixels_per_line; 95 int pitch = src_pixels_per_line;
99 uint8_t d[8]; 96 uint8_t d[8];
100 (void)dst_pixels_per_line; 97 (void)dst_pixels_per_line;
101 98
102 for (row = 0; row < rows; row++) { 99 for (row = 0; row < rows; row++) {
103 /* post_proc_down for one row */ 100 /* post_proc_down for one row */
104 p_src = src_ptr; 101 p_src = src_ptr;
105 p_dst = dst_ptr; 102 p_dst = dst_ptr;
106 103
107 for (col = 0; col < cols; col++) { 104 for (col = 0; col < cols; col++) {
108 int kernel = 4; 105 kernel = 4;
109 int v = p_src[col]; 106 v = p_src[col];
110 107
111 for (i = -2; i <= 2; i++) { 108 for (i = -2; i <= 2; i++) {
112 if (abs(v - p_src[col + i * pitch]) > flimit) 109 if (abs(v - p_src[col + i * pitch]) > flimit)
113 goto down_skip_convolve; 110 goto down_skip_convolve;
114 111
115 kernel += kernel5[2 + i] * p_src[col + i * pitch]; 112 kernel += kernel5[2 + i] * p_src[col + i * pitch];
116 } 113 }
117 114
118 v = (kernel >> 3); 115 v = (kernel >> 3);
119 down_skip_convolve: 116 down_skip_convolve:
120 p_dst[col] = v; 117 p_dst[col] = v;
121 } 118 }
122 119
123 /* now post_proc_across */ 120 /* now post_proc_across */
124 p_src = dst_ptr; 121 p_src = dst_ptr;
125 p_dst = dst_ptr; 122 p_dst = dst_ptr;
126 123
127 for (i = 0; i < 8; i++) 124 for (i = 0; i < 8; i++)
128 d[i] = p_src[i]; 125 d[i] = p_src[i];
129 126
130 for (col = 0; col < cols; col++) { 127 for (col = 0; col < cols; col++) {
131 int kernel = 4; 128 kernel = 4;
132 v = p_src[col]; 129 v = p_src[col];
133 130
134 d[col & 7] = v; 131 d[col & 7] = v;
135 132
136 for (i = -2; i <= 2; i++) { 133 for (i = -2; i <= 2; i++) {
137 if (abs(v - p_src[col + i]) > flimit) 134 if (abs(v - p_src[col + i]) > flimit)
138 goto across_skip_convolve; 135 goto across_skip_convolve;
139 136
140 kernel += kernel5[2 + i] * p_src[col + i]; 137 kernel += kernel5[2 + i] * p_src[col + i];
141 } 138 }
(...skipping 19 matching lines...) Expand all
161 #if CONFIG_VP9_HIGHBITDEPTH 158 #if CONFIG_VP9_HIGHBITDEPTH
162 void vp9_highbd_post_proc_down_and_across_c(const uint16_t *src_ptr, 159 void vp9_highbd_post_proc_down_and_across_c(const uint16_t *src_ptr,
163 uint16_t *dst_ptr, 160 uint16_t *dst_ptr,
164 int src_pixels_per_line, 161 int src_pixels_per_line,
165 int dst_pixels_per_line, 162 int dst_pixels_per_line,
166 int rows, 163 int rows,
167 int cols, 164 int cols,
168 int flimit) { 165 int flimit) {
169 uint16_t const *p_src; 166 uint16_t const *p_src;
170 uint16_t *p_dst; 167 uint16_t *p_dst;
171 int row; 168 int row, col, i, v, kernel;
172 int col;
173 int i;
174 int v;
175 int pitch = src_pixels_per_line; 169 int pitch = src_pixels_per_line;
176 uint16_t d[8]; 170 uint16_t d[8];
177 171
178 for (row = 0; row < rows; row++) { 172 for (row = 0; row < rows; row++) {
179 // post_proc_down for one row. 173 // post_proc_down for one row.
180 p_src = src_ptr; 174 p_src = src_ptr;
181 p_dst = dst_ptr; 175 p_dst = dst_ptr;
182 176
183 for (col = 0; col < cols; col++) { 177 for (col = 0; col < cols; col++) {
184 int kernel = 4; 178 kernel = 4;
185 int v = p_src[col]; 179 v = p_src[col];
186 180
187 for (i = -2; i <= 2; i++) { 181 for (i = -2; i <= 2; i++) {
188 if (abs(v - p_src[col + i * pitch]) > flimit) 182 if (abs(v - p_src[col + i * pitch]) > flimit)
189 goto down_skip_convolve; 183 goto down_skip_convolve;
190 184
191 kernel += kernel5[2 + i] * p_src[col + i * pitch]; 185 kernel += kernel5[2 + i] * p_src[col + i * pitch];
192 } 186 }
193 187
194 v = (kernel >> 3); 188 v = (kernel >> 3);
195 189
196 down_skip_convolve: 190 down_skip_convolve:
197 p_dst[col] = v; 191 p_dst[col] = v;
198 } 192 }
199 193
200 /* now post_proc_across */ 194 /* now post_proc_across */
201 p_src = dst_ptr; 195 p_src = dst_ptr;
202 p_dst = dst_ptr; 196 p_dst = dst_ptr;
203 197
204 for (i = 0; i < 8; i++) 198 for (i = 0; i < 8; i++)
205 d[i] = p_src[i]; 199 d[i] = p_src[i];
206 200
207 for (col = 0; col < cols; col++) { 201 for (col = 0; col < cols; col++) {
208 int kernel = 4; 202 kernel = 4;
209 v = p_src[col]; 203 v = p_src[col];
210 204
211 d[col & 7] = v; 205 d[col & 7] = v;
212 206
213 for (i = -2; i <= 2; i++) { 207 for (i = -2; i <= 2; i++) {
214 if (abs(v - p_src[col + i]) > flimit) 208 if (abs(v - p_src[col + i]) > flimit)
215 goto across_skip_convolve; 209 goto across_skip_convolve;
216 210
217 kernel += kernel5[2 + i] * p_src[col + i]; 211 kernel += kernel5[2 + i] * p_src[col + i];
218 } 212 }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 for (i = 0; i < MAX_MB_PLANE; ++i) { 505 for (i = 0; i < MAX_MB_PLANE; ++i) {
512 const int src_stride = src_strides[i]; 506 const int src_stride = src_strides[i];
513 const int src_width = src_widths[i] - 4; 507 const int src_width = src_widths[i] - 4;
514 const int src_height = src_heights[i] - 4; 508 const int src_height = src_heights[i] - 4;
515 const int dst_stride = dst_strides[i]; 509 const int dst_stride = dst_strides[i];
516 510
517 #if CONFIG_VP9_HIGHBITDEPTH 511 #if CONFIG_VP9_HIGHBITDEPTH
518 assert((src->flags & YV12_FLAG_HIGHBITDEPTH) == 512 assert((src->flags & YV12_FLAG_HIGHBITDEPTH) ==
519 (dst->flags & YV12_FLAG_HIGHBITDEPTH)); 513 (dst->flags & YV12_FLAG_HIGHBITDEPTH));
520 if (src->flags & YV12_FLAG_HIGHBITDEPTH) { 514 if (src->flags & YV12_FLAG_HIGHBITDEPTH) {
521 const uint16_t *const src = CONVERT_TO_SHORTPTR(srcs[i] + 2 * src_stride 515 const uint16_t *const src_plane = CONVERT_TO_SHORTPTR(
522 + 2); 516 srcs[i] + 2 * src_stride + 2);
523 uint16_t *const dst = CONVERT_TO_SHORTPTR(dsts[i] + 2 * dst_stride + 2); 517 uint16_t *const dst_plane = CONVERT_TO_SHORTPTR(
524 vp9_highbd_post_proc_down_and_across(src, dst, src_stride, dst_stride, 518 dsts[i] + 2 * dst_stride + 2);
525 src_height, src_width, ppl); 519 vp9_highbd_post_proc_down_and_across(src_plane, dst_plane, src_stride,
520 dst_stride, src_height, src_width,
521 ppl);
526 } else { 522 } else {
527 const uint8_t *const src = srcs[i] + 2 * src_stride + 2; 523 const uint8_t *const src_plane = srcs[i] + 2 * src_stride + 2;
528 uint8_t *const dst = dsts[i] + 2 * dst_stride + 2; 524 uint8_t *const dst_plane = dsts[i] + 2 * dst_stride + 2;
529 525
530 vp9_post_proc_down_and_across(src, dst, src_stride, dst_stride, 526 vp9_post_proc_down_and_across(src_plane, dst_plane, src_stride,
531 src_height, src_width, ppl); 527 dst_stride, src_height, src_width, ppl);
532 } 528 }
533 #else 529 #else
534 const uint8_t *const src = srcs[i] + 2 * src_stride + 2; 530 const uint8_t *const src_plane = srcs[i] + 2 * src_stride + 2;
535 uint8_t *const dst = dsts[i] + 2 * dst_stride + 2; 531 uint8_t *const dst_plane = dsts[i] + 2 * dst_stride + 2;
536 vp9_post_proc_down_and_across(src, dst, src_stride, dst_stride, 532 vp9_post_proc_down_and_across(src_plane, dst_plane, src_stride, dst_stride,
537 src_height, src_width, ppl); 533 src_height, src_width, ppl);
538 #endif 534 #endif
539 } 535 }
540 } 536 }
541 537
542 static double gaussian(double sigma, double mu, double x) { 538 static double gaussian(double sigma, double mu, double x) {
543 return 1 / (sigma * sqrt(2.0 * 3.14159265)) * 539 return 1 / (sigma * sqrt(2.0 * 3.14159265)) *
544 (exp(-(x - mu) * (x - mu) / (2 * sigma * sigma))); 540 (exp(-(x - mu) * (x - mu) / (2 * sigma * sigma)));
545 } 541 }
546 542
547 static void fillrd(struct postproc_state *state, int q, int a) { 543 static void fillrd(struct postproc_state *state, int q, int a) {
548 char char_dist[300]; 544 char char_dist[300];
549 545
550 double sigma; 546 double sigma;
551 int ai = a, qi = q, i; 547 int ai = a, qi = q, i;
552 548
553 vp9_clear_system_state(); 549 vp9_clear_system_state();
554 550
555 sigma = ai + .5 + .6 * (63 - qi) / 63.0; 551 sigma = ai + .5 + .6 * (63 - qi) / 63.0;
556 552
557 /* set up a lookup table of 256 entries that matches 553 /* set up a lookup table of 256 entries that matches
558 * a gaussian distribution with sigma determined by q. 554 * a gaussian distribution with sigma determined by q.
559 */ 555 */
560 { 556 {
561 double i;
562 int next, j; 557 int next, j;
563 558
564 next = 0; 559 next = 0;
565 560
566 for (i = -32; i < 32; i++) { 561 for (i = -32; i < 32; i++) {
567 int a = (int)(0.5 + 256 * gaussian(sigma, 0, i)); 562 int a_i = (int)(0.5 + 256 * gaussian(sigma, 0, i));
568 563
569 if (a) { 564 if (a_i) {
570 for (j = 0; j < a; j++) { 565 for (j = 0; j < a_i; j++) {
571 char_dist[next + j] = (char) i; 566 char_dist[next + j] = (char) i;
572 } 567 }
573 568
574 next = next + j; 569 next = next + j;
575 } 570 }
576 } 571 }
577 572
578 for (; next < 256; next++) 573 for (; next < 256; next++)
579 char_dist[next] = 0; 574 char_dist[next] = 0;
580 } 575 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 644
650 // Alloc memory for prev_mip in the first frame. 645 // Alloc memory for prev_mip in the first frame.
651 if (cm->current_video_frame == 1) { 646 if (cm->current_video_frame == 1) {
652 cm->postproc_state.last_base_qindex = cm->base_qindex; 647 cm->postproc_state.last_base_qindex = cm->base_qindex;
653 cm->postproc_state.last_frame_valid = 1; 648 cm->postproc_state.last_frame_valid = 1;
654 ppstate->prev_mip = vpx_calloc(cm->mi_alloc_size, sizeof(*cm->mip)); 649 ppstate->prev_mip = vpx_calloc(cm->mi_alloc_size, sizeof(*cm->mip));
655 if (!ppstate->prev_mip) { 650 if (!ppstate->prev_mip) {
656 return 1; 651 return 1;
657 } 652 }
658 ppstate->prev_mi = ppstate->prev_mip + cm->mi_stride + 1; 653 ppstate->prev_mi = ppstate->prev_mip + cm->mi_stride + 1;
659 vpx_memset(ppstate->prev_mip, 0, 654 memset(ppstate->prev_mip, 0,
660 cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); 655 cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip));
661 } 656 }
662 657
663 // Allocate post_proc_buffer_int if needed. 658 // Allocate post_proc_buffer_int if needed.
664 if ((flags & VP9D_MFQE) && !cm->post_proc_buffer_int.buffer_alloc) { 659 if ((flags & VP9D_MFQE) && !cm->post_proc_buffer_int.buffer_alloc) {
665 if ((flags & VP9D_DEMACROBLOCK) || (flags & VP9D_DEBLOCK)) { 660 if ((flags & VP9D_DEMACROBLOCK) || (flags & VP9D_DEBLOCK)) {
666 const int width = ALIGN_POWER_OF_TWO(cm->width, 4); 661 const int width = ALIGN_POWER_OF_TWO(cm->width, 4);
667 const int height = ALIGN_POWER_OF_TWO(cm->height, 4); 662 const int height = ALIGN_POWER_OF_TWO(cm->height, 4);
668 663
669 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer_int, width, height, 664 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer_int, width, height,
670 cm->subsampling_x, cm->subsampling_y, 665 cm->subsampling_x, cm->subsampling_y,
671 #if CONFIG_VP9_HIGHBITDEPTH 666 #if CONFIG_VP9_HIGHBITDEPTH
672 cm->use_highbitdepth, 667 cm->use_highbitdepth,
673 #endif // CONFIG_VP9_HIGHBITDEPTH 668 #endif // CONFIG_VP9_HIGHBITDEPTH
674 VP9_ENC_BORDER_IN_PIXELS, 669 VP9_ENC_BORDER_IN_PIXELS,
675 cm->byte_alignment) < 0) { 670 cm->byte_alignment) < 0) {
676 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 671 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
677 "Failed to allocate MFQE framebuffer"); 672 "Failed to allocate MFQE framebuffer");
678 } 673 }
679 674
680 // Ensure that postproc is set to all 0s so that post proc 675 // Ensure that postproc is set to all 0s so that post proc
681 // doesn't pull random data in from edge. 676 // doesn't pull random data in from edge.
682 vpx_memset(cm->post_proc_buffer_int.buffer_alloc, 128, 677 memset(cm->post_proc_buffer_int.buffer_alloc, 128,
683 cm->post_proc_buffer.frame_size); 678 cm->post_proc_buffer.frame_size);
684 } 679 }
685 } 680 }
686 681
687 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, cm->width, cm->height, 682 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, cm->width, cm->height,
688 cm->subsampling_x, cm->subsampling_y, 683 cm->subsampling_x, cm->subsampling_y,
689 #if CONFIG_VP9_HIGHBITDEPTH 684 #if CONFIG_VP9_HIGHBITDEPTH
690 cm->use_highbitdepth, 685 cm->use_highbitdepth,
691 #endif 686 #endif
692 VP9_DEC_BORDER_IN_PIXELS, cm->byte_alignment, 687 VP9_DEC_BORDER_IN_PIXELS, cm->byte_alignment,
693 NULL, NULL, NULL) < 0) 688 NULL, NULL, NULL) < 0)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 /* handle problem with extending borders */ 738 /* handle problem with extending borders */
744 dest->y_width = cm->width; 739 dest->y_width = cm->width;
745 dest->y_height = cm->height; 740 dest->y_height = cm->height;
746 dest->uv_width = dest->y_width >> cm->subsampling_x; 741 dest->uv_width = dest->y_width >> cm->subsampling_x;
747 dest->uv_height = dest->y_height >> cm->subsampling_y; 742 dest->uv_height = dest->y_height >> cm->subsampling_y;
748 743
749 swap_mi_and_prev_mi(cm); 744 swap_mi_and_prev_mi(cm);
750 return 0; 745 return 0;
751 } 746 }
752 #endif // CONFIG_VP9_POSTPROC 747 #endif // CONFIG_VP9_POSTPROC
OLDNEW
« no previous file with comments | « source/libvpx/vp9/common/vp9_onyxc_int.h ('k') | source/libvpx/vp9/common/vp9_pred_common.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698