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

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

Issue 1302353004: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 3 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/encoder/vp9_resize.c ('k') | source/libvpx/vp9/encoder/vp9_speed_features.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) 2015 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 int vp9_skin_pixel(const uint8_t y, const uint8_t cb, const uint8_t cr) { 44 int vp9_skin_pixel(const uint8_t y, const uint8_t cb, const uint8_t cr) {
45 if (y < y_low || y > y_high) 45 if (y < y_low || y > y_high)
46 return 0; 46 return 0;
47 else 47 else
48 return (evaluate_skin_color_difference(cb, cr) < skin_threshold); 48 return (evaluate_skin_color_difference(cb, cr) < skin_threshold);
49 } 49 }
50 50
51 #ifdef OUTPUT_YUV_SKINMAP 51 #ifdef OUTPUT_YUV_SKINMAP
52 // For viewing skin map on input source. 52 // For viewing skin map on input source.
53 void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) { 53 void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) {
54 int i, j, mi_row, mi_col; 54 int i, j, mi_row, mi_col, num_bl;
55 VP9_COMMON *const cm = &cpi->common; 55 VP9_COMMON *const cm = &cpi->common;
56 uint8_t *y; 56 uint8_t *y;
57 const uint8_t *src_y = cpi->Source->y_buffer; 57 const uint8_t *src_y = cpi->Source->y_buffer;
58 const uint8_t *src_u = cpi->Source->u_buffer; 58 const uint8_t *src_u = cpi->Source->u_buffer;
59 const uint8_t *src_v = cpi->Source->v_buffer; 59 const uint8_t *src_v = cpi->Source->v_buffer;
60 const int src_ystride = cpi->Source->y_stride; 60 const int src_ystride = cpi->Source->y_stride;
61 const int src_uvstride = cpi->Source->uv_stride; 61 const int src_uvstride = cpi->Source->uv_stride;
62 int y_bsize = 16; // Use 8x8 or 16x16.
63 int uv_bsize = y_bsize >> 1;
64 int ypos = y_bsize >> 1;
65 int uvpos = uv_bsize >> 1;
66 int shy = (y_bsize == 8) ? 3 : 4;
67 int shuv = shy - 1;
68 int fac = y_bsize / 8;
69 // Use center pixel or average of center 2x2 pixels.
70 int mode_filter = 1;
62 YV12_BUFFER_CONFIG skinmap; 71 YV12_BUFFER_CONFIG skinmap;
63 memset(&skinmap, 0, sizeof(YV12_BUFFER_CONFIG)); 72 memset(&skinmap, 0, sizeof(YV12_BUFFER_CONFIG));
64 if (vp9_alloc_frame_buffer(&skinmap, cm->width, cm->height, 73 if (vpx_alloc_frame_buffer(&skinmap, cm->width, cm->height,
65 cm->subsampling_x, cm->subsampling_y, 74 cm->subsampling_x, cm->subsampling_y,
66 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment)) { 75 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment)) {
67 vp9_free_frame_buffer(&skinmap); 76 vpx_free_frame_buffer(&skinmap);
68 return; 77 return;
69 } 78 }
70 memset(skinmap.buffer_alloc, 128, skinmap.frame_size); 79 memset(skinmap.buffer_alloc, 128, skinmap.frame_size);
71 y = skinmap.y_buffer; 80 y = skinmap.y_buffer;
72 // Loop through 8x8 blocks and set skin map based on center pixel of block. 81 // Loop through blocks and set skin map based on center pixel of block.
73 // Set y to white for skin block, otherwise set to source with gray scale. 82 // Set y to white for skin block, otherwise set to source with gray scale.
74 // Ignore rightmost/bottom boundary blocks. 83 // Ignore rightmost/bottom boundary blocks.
75 for (mi_row = 0; mi_row < cm->mi_rows - 1; ++mi_row) { 84 for (mi_row = 0; mi_row < cm->mi_rows - 1; mi_row += fac) {
76 for (mi_col = 0; mi_col < cm->mi_cols - 1; ++mi_col) { 85 num_bl = 0;
77 // Use middle pixel for each 8x8 block for skin detection. 86 for (mi_col = 0; mi_col < cm->mi_cols - 1; mi_col += fac) {
78 // If middle pixel is skin, assign whole 8x8 block to skin. 87 // Select pixel for each block for skin detection.
79 const uint8_t ysource = src_y[4 * src_ystride + 4]; 88 // Use center pixel, or 2x2 average at center.
80 const uint8_t usource = src_u[2 * src_uvstride + 2]; 89 uint8_t ysource = src_y[ypos * src_ystride + ypos];
81 const uint8_t vsource = src_v[2 * src_uvstride + 2]; 90 uint8_t usource = src_u[uvpos * src_uvstride + uvpos];
91 uint8_t vsource = src_v[uvpos * src_uvstride + uvpos];
92 uint8_t ysource2 = src_y[(ypos + 1) * src_ystride + ypos];
93 uint8_t usource2 = src_u[(uvpos + 1) * src_uvstride + uvpos];
94 uint8_t vsource2 = src_v[(uvpos + 1) * src_uvstride + uvpos];
95 uint8_t ysource3 = src_y[ypos * src_ystride + (ypos + 1)];
96 uint8_t usource3 = src_u[uvpos * src_uvstride + (uvpos + 1)];
97 uint8_t vsource3 = src_v[uvpos * src_uvstride + (uvpos + 1)];
98 uint8_t ysource4 = src_y[(ypos + 1) * src_ystride + (ypos + 1)];
99 uint8_t usource4 = src_u[(uvpos + 1) * src_uvstride + (uvpos + 1)];
100 uint8_t vsource4 = src_v[(uvpos + 1) * src_uvstride + (uvpos + 1)];
101 if (mode_filter == 1) {
102 ysource = (ysource + ysource2 + ysource3 + ysource4) >> 2;
103 usource = (usource + usource2 + usource3 + usource4) >> 2;
104 vsource = (vsource + vsource2 + vsource3 + vsource4) >> 2;
105 }
82 const int is_skin = vp9_skin_pixel(ysource, usource, vsource); 106 const int is_skin = vp9_skin_pixel(ysource, usource, vsource);
83 for (i = 0; i < 8; i++) { 107 for (i = 0; i < y_bsize; i++) {
84 for (j = 0; j < 8; j++) { 108 for (j = 0; j < y_bsize; j++) {
85 if (is_skin) 109 if (is_skin)
86 y[i * src_ystride + j] = 255; 110 y[i * src_ystride + j] = 255;
87 else 111 else
88 y[i * src_ystride + j] = src_y[i * src_ystride + j]; 112 y[i * src_ystride + j] = src_y[i * src_ystride + j];
89 } 113 }
90 } 114 }
91 y += 8; 115 num_bl++;
92 src_y += 8; 116 y += y_bsize;
93 src_u += 4; 117 src_y += y_bsize;
94 src_v += 4; 118 src_u += uv_bsize;
119 src_v += uv_bsize;
95 } 120 }
96 y += (src_ystride << 3) - ((cm->mi_cols - 1) << 3); 121 y += (src_ystride << shy) - (num_bl << shy);
97 src_y += (src_ystride << 3) - ((cm->mi_cols - 1) << 3); 122 src_y += (src_ystride << shy) - (num_bl << shy);
98 src_u += (src_uvstride << 2) - ((cm->mi_cols - 1) << 2); 123 src_u += (src_uvstride << shuv) - (num_bl << shuv);
99 src_v += (src_uvstride << 2) - ((cm->mi_cols - 1) << 2); 124 src_v += (src_uvstride << shuv) - (num_bl << shuv);
100 } 125 }
101 vp9_write_yuv_frame_420(&skinmap, yuv_skinmap_file); 126 vp9_write_yuv_frame_420(&skinmap, yuv_skinmap_file);
102 vp9_free_frame_buffer(&skinmap); 127 vpx_free_frame_buffer(&skinmap);
103 } 128 }
104 #endif 129 #endif
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_resize.c ('k') | source/libvpx/vp9/encoder/vp9_speed_features.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698