From: Jerome Jiang Date: Thu, 8 Jun 2017 23:07:02 +0000 (-0700) Subject: Remove duplication on vp8/9_write_yuv_frame. X-Git-Tag: v1.7.0~400^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff2d220d210acad9f28cafdd4238c078e6edb263;p=libvpx Remove duplication on vp8/9_write_yuv_frame. Change-Id: Ib3546032a27c715bf509c0e24d26a189bc829da8 --- diff --git a/vp8/common/skin_detection.c b/vp8/common/skin_detection.c index ed8f983a8..fbf87651e 100644 --- a/vp8/common/skin_detection.c +++ b/vp8/common/skin_detection.c @@ -12,6 +12,7 @@ #include "vp8/common/alloccommon.h" #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_mem/vpx_mem.h" +#include "vpx_util/vpx_write_yuv_frame.h" int compute_skin_block(const uint8_t *y, const uint8_t *u, const uint8_t *v, int stride, int strideuv, int consec_zeromv, @@ -94,7 +95,7 @@ void compute_skin_map(VP8_COMP *const cpi, FILE *yuv_skinmap_file) { src_u += (src_uvstride << 3) - (num_bl << 3); src_v += (src_uvstride << 3) - (num_bl << 3); } - vp8_write_yuv_frame(yuv_skinmap_file, &skinmap); + vpx_write_yuv_frame(yuv_skinmap_file, &skinmap); vpx_free_frame_buffer(&skinmap); } #endif // OUTPUT_YUV_SKINMAP diff --git a/vp8/common/skin_detection.h b/vp8/common/skin_detection.h index 1fe233212..1d72eeb02 100644 --- a/vp8/common/skin_detection.h +++ b/vp8/common/skin_detection.h @@ -29,7 +29,6 @@ int compute_skin_block(const uint8_t *y, const uint8_t *u, const uint8_t *v, #ifdef OUTPUT_YUV_SKINMAP // For viewing skin map on input source. void compute_skin_map(struct VP8_COMP *const cpi, FILE *yuv_skinmap_file); -extern void vp8_write_yuv_frame(FILE *f, YV12_BUFFER_CONFIG *s); #endif #ifdef __cplusplus diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 9a9f3d1f8..d5a534946 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -2484,35 +2484,6 @@ int vp8_update_entropy(VP8_COMP *cpi, int update) { return 0; } -#if defined(OUTPUT_YUV_SRC) || defined(OUTPUT_YUV_DENOISED) || \ - defined(OUTPUT_YUV_SKINMAP) -void vp8_write_yuv_frame(FILE *yuv_file, YV12_BUFFER_CONFIG *s) { - unsigned char *src = s->y_buffer; - int h = s->y_crop_height; - - do { - fwrite(src, s->y_width, 1, yuv_file); - src += s->y_stride; - } while (--h); - - src = s->u_buffer; - h = s->uv_crop_height; - - do { - fwrite(src, s->uv_width, 1, yuv_file); - src += s->uv_stride; - } while (--h); - - src = s->v_buffer; - h = s->uv_crop_height; - - do { - fwrite(src, s->uv_width, 1, yuv_file); - src += s->uv_stride; - } while (--h); -} -#endif - static void scale_and_extend_source(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi) { VP8_COMMON *cm = &cpi->common; diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index c7793488f..bf33168e7 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -2581,39 +2581,6 @@ int vp9_update_entropy(VP9_COMP *cpi, int update) { return 0; } -#if defined(OUTPUT_YUV_DENOISED) || defined(OUTPUT_YUV_SKINMAP) -// The denoiser buffer is allocated as a YUV 440 buffer. This function writes it -// as YUV 420. We simply use the top-left pixels of the UV buffers, since we do -// not denoise the UV channels at this time. If ever we implement UV channel -// denoising we will have to modify this. -// TODO(jianj): Remove the duplicated one in vp8 and move it to vpx_util. -void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f) { - uint8_t *src = s->y_buffer; - int h = s->y_crop_height; - - do { - fwrite(src, s->y_width, 1, f); - src += s->y_stride; - } while (--h); - - src = s->u_buffer; - h = s->uv_crop_height; - - do { - fwrite(src, s->uv_width, 1, f); - src += s->uv_stride; - } while (--h); - - src = s->v_buffer; - h = s->uv_crop_height; - - do { - fwrite(src, s->uv_width, 1, f); - src += s->uv_stride; - } while (--h); -} -#endif - #ifdef OUTPUT_YUV_REC void vp9_write_yuv_rec_frame(VP9_COMMON *cm) { YV12_BUFFER_CONFIG *s = cm->frame_to_show; diff --git a/vp9/encoder/vp9_skin_detection.c b/vp9/encoder/vp9_skin_detection.c index 4cdac723a..175503ed4 100644 --- a/vp9/encoder/vp9_skin_detection.c +++ b/vp9/encoder/vp9_skin_detection.c @@ -130,7 +130,7 @@ void vp9_compute_skin_map(VP9_COMP *const cpi, FILE *yuv_skinmap_file) { 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); + vpx_write_yuv_frame(yuv_skinmap_file, &skinmap); vpx_free_frame_buffer(&skinmap); } #endif diff --git a/vp9/encoder/vp9_skin_detection.h b/vp9/encoder/vp9_skin_detection.h index 1c6a081f4..bb7ef87d8 100644 --- a/vp9/encoder/vp9_skin_detection.h +++ b/vp9/encoder/vp9_skin_detection.h @@ -13,6 +13,7 @@ #include "vp9/common/vp9_blockd.h" #include "vpx_dsp/skin_detection.h" +#include "vpx_util/vpx_write_yuv_frame.h" #ifdef __cplusplus extern "C" { @@ -27,7 +28,6 @@ int vp9_compute_skin_block(const uint8_t *y, const uint8_t *u, const uint8_t *v, #ifdef OUTPUT_YUV_SKINMAP // For viewing skin map on input source. void vp9_compute_skin_map(struct VP9_COMP *const cpi, FILE *yuv_skinmap_file); -extern void vp9_write_yuv_frame_420(YV12_BUFFER_CONFIG *s, FILE *f); #endif #ifdef __cplusplus diff --git a/vpx_util/vpx_util.mk b/vpx_util/vpx_util.mk index c0ef8d336..d48e4cc2f 100644 --- a/vpx_util/vpx_util.mk +++ b/vpx_util/vpx_util.mk @@ -12,3 +12,5 @@ UTIL_SRCS-yes += vpx_util.mk UTIL_SRCS-yes += vpx_thread.c UTIL_SRCS-yes += vpx_thread.h UTIL_SRCS-yes += endian_inl.h +UTIL_SRCS-yes += vpx_write_yuv_frame.h +UTIL_SRCS-yes += vpx_write_yuv_frame.c diff --git a/vpx_util/vpx_write_yuv_frame.c b/vpx_util/vpx_write_yuv_frame.c new file mode 100644 index 000000000..ab6855811 --- /dev/null +++ b/vpx_util/vpx_write_yuv_frame.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "vpx_dsp/skin_detection.h" +#include "vpx_util/vpx_write_yuv_frame.h" + +void vpx_write_yuv_frame(FILE *yuv_file, YV12_BUFFER_CONFIG *s) { +#if defined(OUTPUT_YUV_SRC) || defined(OUTPUT_YUV_DENOISED) || \ + defined(OUTPUT_YUV_SKINMAP) + + unsigned char *src = s->y_buffer; + int h = s->y_crop_height; + + do { + fwrite(src, s->y_width, 1, yuv_file); + src += s->y_stride; + } while (--h); + + src = s->u_buffer; + h = s->uv_crop_height; + + do { + fwrite(src, s->uv_width, 1, yuv_file); + src += s->uv_stride; + } while (--h); + + src = s->v_buffer; + h = s->uv_crop_height; + + do { + fwrite(src, s->uv_width, 1, yuv_file); + src += s->uv_stride; + } while (--h); + +#else + (void)yuv_file; + (void)s; +#endif +} diff --git a/vpx_util/vpx_write_yuv_frame.h b/vpx_util/vpx_write_yuv_frame.h new file mode 100644 index 000000000..1cb702981 --- /dev/null +++ b/vpx_util/vpx_write_yuv_frame.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_UTIL_VPX_WRITE_YUV_FRAME_H_ +#define VPX_UTIL_VPX_WRITE_YUV_FRAME_H_ + +#include +#include "vpx_scale/yv12config.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void vpx_write_yuv_frame(FILE *yuv_file, YV12_BUFFER_CONFIG *s); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // VPX_UTIL_VPX_WRITE_YUV_FRAME_H_