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

Unified 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, 4 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/libvpx/vp9/encoder/vp9_skin_detection.c
diff --git a/source/libvpx/vp9/encoder/vp9_skin_detection.c b/source/libvpx/vp9/encoder/vp9_skin_detection.c
index 1cb0662834e0bdfda34e2cd445c61bcbcf8f93e3..aaa8ea077ae69782d316c380c5196fca6b13e95e 100644
--- a/source/libvpx/vp9/encoder/vp9_skin_detection.c
+++ b/source/libvpx/vp9/encoder/vp9_skin_detection.c
@@ -51,7 +51,7 @@ int vp9_skin_pixel(const uint8_t y, const uint8_t cb, const uint8_t cr) {
#ifdef OUTPUT_YUV_SKINMAP
// For viewing skin map on input source.
void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) {
- int i, j, mi_row, mi_col;
+ int i, j, mi_row, mi_col, num_bl;
VP9_COMMON *const cm = &cpi->common;
uint8_t *y;
const uint8_t *src_y = cpi->Source->y_buffer;
@@ -59,46 +59,71 @@ void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) {
const uint8_t *src_v = cpi->Source->v_buffer;
const int src_ystride = cpi->Source->y_stride;
const int src_uvstride = cpi->Source->uv_stride;
+ int y_bsize = 16; // Use 8x8 or 16x16.
+ int uv_bsize = y_bsize >> 1;
+ int ypos = y_bsize >> 1;
+ int uvpos = uv_bsize >> 1;
+ int shy = (y_bsize == 8) ? 3 : 4;
+ int shuv = shy - 1;
+ int fac = y_bsize / 8;
+ // Use center pixel or average of center 2x2 pixels.
+ int mode_filter = 1;
YV12_BUFFER_CONFIG skinmap;
memset(&skinmap, 0, sizeof(YV12_BUFFER_CONFIG));
- if (vp9_alloc_frame_buffer(&skinmap, cm->width, cm->height,
+ if (vpx_alloc_frame_buffer(&skinmap, cm->width, cm->height,
cm->subsampling_x, cm->subsampling_y,
VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment)) {
- vp9_free_frame_buffer(&skinmap);
+ vpx_free_frame_buffer(&skinmap);
return;
}
memset(skinmap.buffer_alloc, 128, skinmap.frame_size);
y = skinmap.y_buffer;
- // Loop through 8x8 blocks and set skin map based on center pixel of block.
+ // Loop through blocks and set skin map based on center pixel of block.
// Set y to white for skin block, otherwise set to source with gray scale.
// Ignore rightmost/bottom boundary blocks.
- for (mi_row = 0; mi_row < cm->mi_rows - 1; ++mi_row) {
- for (mi_col = 0; mi_col < cm->mi_cols - 1; ++mi_col) {
- // Use middle pixel for each 8x8 block for skin detection.
- // If middle pixel is skin, assign whole 8x8 block to skin.
- const uint8_t ysource = src_y[4 * src_ystride + 4];
- const uint8_t usource = src_u[2 * src_uvstride + 2];
- const uint8_t vsource = src_v[2 * src_uvstride + 2];
+ for (mi_row = 0; mi_row < cm->mi_rows - 1; mi_row += fac) {
+ num_bl = 0;
+ for (mi_col = 0; mi_col < cm->mi_cols - 1; mi_col += fac) {
+ // Select pixel for each block for skin detection.
+ // Use center pixel, or 2x2 average at center.
+ uint8_t ysource = src_y[ypos * src_ystride + ypos];
+ uint8_t usource = src_u[uvpos * src_uvstride + uvpos];
+ uint8_t vsource = src_v[uvpos * src_uvstride + uvpos];
+ uint8_t ysource2 = src_y[(ypos + 1) * src_ystride + ypos];
+ uint8_t usource2 = src_u[(uvpos + 1) * src_uvstride + uvpos];
+ uint8_t vsource2 = src_v[(uvpos + 1) * src_uvstride + uvpos];
+ uint8_t ysource3 = src_y[ypos * src_ystride + (ypos + 1)];
+ uint8_t usource3 = src_u[uvpos * src_uvstride + (uvpos + 1)];
+ uint8_t vsource3 = src_v[uvpos * src_uvstride + (uvpos + 1)];
+ uint8_t ysource4 = src_y[(ypos + 1) * src_ystride + (ypos + 1)];
+ uint8_t usource4 = src_u[(uvpos + 1) * src_uvstride + (uvpos + 1)];
+ uint8_t vsource4 = src_v[(uvpos + 1) * src_uvstride + (uvpos + 1)];
+ if (mode_filter == 1) {
+ ysource = (ysource + ysource2 + ysource3 + ysource4) >> 2;
+ usource = (usource + usource2 + usource3 + usource4) >> 2;
+ vsource = (vsource + vsource2 + vsource3 + vsource4) >> 2;
+ }
const int is_skin = vp9_skin_pixel(ysource, usource, vsource);
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
+ for (i = 0; i < y_bsize; i++) {
+ for (j = 0; j < y_bsize; j++) {
if (is_skin)
y[i * src_ystride + j] = 255;
else
y[i * src_ystride + j] = src_y[i * src_ystride + j];
}
}
- y += 8;
- src_y += 8;
- src_u += 4;
- src_v += 4;
+ num_bl++;
+ y += y_bsize;
+ src_y += y_bsize;
+ src_u += uv_bsize;
+ src_v += uv_bsize;
}
- y += (src_ystride << 3) - ((cm->mi_cols - 1) << 3);
- src_y += (src_ystride << 3) - ((cm->mi_cols - 1) << 3);
- src_u += (src_uvstride << 2) - ((cm->mi_cols - 1) << 2);
- src_v += (src_uvstride << 2) - ((cm->mi_cols - 1) << 2);
+ y += (src_ystride << shy) - (num_bl << shy);
+ src_y += (src_ystride << shy) - (num_bl << shy);
+ src_u += (src_uvstride << shuv) - (num_bl << shuv);
+ src_v += (src_uvstride << shuv) - (num_bl << shuv);
}
vp9_write_yuv_frame_420(&skinmap, yuv_skinmap_file);
- vp9_free_frame_buffer(&skinmap);
+ vpx_free_frame_buffer(&skinmap);
}
#endif
« 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