1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vpx_scale/generic/yv12extend.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,181 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 +#include <assert.h> 1.15 +#include "./vpx_config.h" 1.16 +#include "vpx/vpx_integer.h" 1.17 +#include "vpx_mem/vpx_mem.h" 1.18 +#include "vpx_scale/yv12config.h" 1.19 + 1.20 +static void extend_plane(uint8_t *const src, int src_stride, 1.21 + int width, int height, 1.22 + int extend_top, int extend_left, 1.23 + int extend_bottom, int extend_right) { 1.24 + int i; 1.25 + const int linesize = extend_left + extend_right + width; 1.26 + 1.27 + /* copy the left and right most columns out */ 1.28 + uint8_t *src_ptr1 = src; 1.29 + uint8_t *src_ptr2 = src + width - 1; 1.30 + uint8_t *dst_ptr1 = src - extend_left; 1.31 + uint8_t *dst_ptr2 = src + width; 1.32 + 1.33 + for (i = 0; i < height; ++i) { 1.34 + vpx_memset(dst_ptr1, src_ptr1[0], extend_left); 1.35 + vpx_memset(dst_ptr2, src_ptr2[0], extend_right); 1.36 + src_ptr1 += src_stride; 1.37 + src_ptr2 += src_stride; 1.38 + dst_ptr1 += src_stride; 1.39 + dst_ptr2 += src_stride; 1.40 + } 1.41 + 1.42 + /* Now copy the top and bottom lines into each line of the respective 1.43 + * borders 1.44 + */ 1.45 + src_ptr1 = src - extend_left; 1.46 + src_ptr2 = src + src_stride * (height - 1) - extend_left; 1.47 + dst_ptr1 = src + src_stride * -extend_top - extend_left; 1.48 + dst_ptr2 = src + src_stride * height - extend_left; 1.49 + 1.50 + for (i = 0; i < extend_top; ++i) { 1.51 + vpx_memcpy(dst_ptr1, src_ptr1, linesize); 1.52 + dst_ptr1 += src_stride; 1.53 + } 1.54 + 1.55 + for (i = 0; i < extend_bottom; ++i) { 1.56 + vpx_memcpy(dst_ptr2, src_ptr2, linesize); 1.57 + dst_ptr2 += src_stride; 1.58 + } 1.59 +} 1.60 + 1.61 +void vp8_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) { 1.62 + assert(ybf->y_height - ybf->y_crop_height < 16); 1.63 + assert(ybf->y_width - ybf->y_crop_width < 16); 1.64 + assert(ybf->y_height - ybf->y_crop_height >= 0); 1.65 + assert(ybf->y_width - ybf->y_crop_width >= 0); 1.66 + 1.67 + extend_plane(ybf->y_buffer, ybf->y_stride, 1.68 + ybf->y_crop_width, ybf->y_crop_height, 1.69 + ybf->border, ybf->border, 1.70 + ybf->border + ybf->y_height - ybf->y_crop_height, 1.71 + ybf->border + ybf->y_width - ybf->y_crop_width); 1.72 + 1.73 + extend_plane(ybf->u_buffer, ybf->uv_stride, 1.74 + (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, 1.75 + ybf->border / 2, ybf->border / 2, 1.76 + (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, 1.77 + (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); 1.78 + 1.79 + extend_plane(ybf->v_buffer, ybf->uv_stride, 1.80 + (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, 1.81 + ybf->border / 2, ybf->border / 2, 1.82 + (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, 1.83 + (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); 1.84 +} 1.85 + 1.86 +#if CONFIG_VP9 1.87 +static void extend_frame(YV12_BUFFER_CONFIG *const ybf, 1.88 + int subsampling_x, int subsampling_y, 1.89 + int ext_size) { 1.90 + const int c_w = ybf->uv_crop_width; 1.91 + const int c_h = ybf->uv_crop_height; 1.92 + const int c_ext_size = ext_size >> 1; 1.93 + const int c_et = c_ext_size; 1.94 + const int c_el = c_ext_size; 1.95 + const int c_eb = c_ext_size + ybf->uv_height - ybf->uv_crop_height; 1.96 + const int c_er = c_ext_size + ybf->uv_width - ybf->uv_crop_width; 1.97 + 1.98 + assert(ybf->y_height - ybf->y_crop_height < 16); 1.99 + assert(ybf->y_width - ybf->y_crop_width < 16); 1.100 + assert(ybf->y_height - ybf->y_crop_height >= 0); 1.101 + assert(ybf->y_width - ybf->y_crop_width >= 0); 1.102 + 1.103 + extend_plane(ybf->y_buffer, ybf->y_stride, 1.104 + ybf->y_crop_width, ybf->y_crop_height, 1.105 + ext_size, ext_size, 1.106 + ext_size + ybf->y_height - ybf->y_crop_height, 1.107 + ext_size + ybf->y_width - ybf->y_crop_width); 1.108 + 1.109 + extend_plane(ybf->u_buffer, ybf->uv_stride, 1.110 + c_w, c_h, c_et, c_el, c_eb, c_er); 1.111 + 1.112 + extend_plane(ybf->v_buffer, ybf->uv_stride, 1.113 + c_w, c_h, c_et, c_el, c_eb, c_er); 1.114 +} 1.115 + 1.116 +void vp9_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, 1.117 + int subsampling_x, int subsampling_y) { 1.118 + extend_frame(ybf, subsampling_x, subsampling_y, ybf->border); 1.119 +} 1.120 + 1.121 +void vp9_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf, 1.122 + int subsampling_x, int subsampling_y) { 1.123 + const int inner_bw = (ybf->border > VP9INNERBORDERINPIXELS) ? 1.124 + VP9INNERBORDERINPIXELS : ybf->border; 1.125 + extend_frame(ybf, subsampling_x, subsampling_y, inner_bw); 1.126 +} 1.127 +#endif // CONFIG_VP9 1.128 + 1.129 +// Copies the source image into the destination image and updates the 1.130 +// destination's UMV borders. 1.131 +// Note: The frames are assumed to be identical in size. 1.132 +void vp8_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_ybc, 1.133 + YV12_BUFFER_CONFIG *dst_ybc) { 1.134 + int row; 1.135 + const uint8_t *src = src_ybc->y_buffer; 1.136 + uint8_t *dst = dst_ybc->y_buffer; 1.137 + 1.138 +#if 0 1.139 + /* These assertions are valid in the codec, but the libvpx-tester uses 1.140 + * this code slightly differently. 1.141 + */ 1.142 + assert(src_ybc->y_width == dst_ybc->y_width); 1.143 + assert(src_ybc->y_height == dst_ybc->y_height); 1.144 +#endif 1.145 + 1.146 + for (row = 0; row < src_ybc->y_height; ++row) { 1.147 + vpx_memcpy(dst, src, src_ybc->y_width); 1.148 + src += src_ybc->y_stride; 1.149 + dst += dst_ybc->y_stride; 1.150 + } 1.151 + 1.152 + src = src_ybc->u_buffer; 1.153 + dst = dst_ybc->u_buffer; 1.154 + 1.155 + for (row = 0; row < src_ybc->uv_height; ++row) { 1.156 + vpx_memcpy(dst, src, src_ybc->uv_width); 1.157 + src += src_ybc->uv_stride; 1.158 + dst += dst_ybc->uv_stride; 1.159 + } 1.160 + 1.161 + src = src_ybc->v_buffer; 1.162 + dst = dst_ybc->v_buffer; 1.163 + 1.164 + for (row = 0; row < src_ybc->uv_height; ++row) { 1.165 + vpx_memcpy(dst, src, src_ybc->uv_width); 1.166 + src += src_ybc->uv_stride; 1.167 + dst += dst_ybc->uv_stride; 1.168 + } 1.169 + 1.170 + vp8_yv12_extend_frame_borders_c(dst_ybc); 1.171 +} 1.172 + 1.173 +void vpx_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc, 1.174 + YV12_BUFFER_CONFIG *dst_ybc) { 1.175 + int row; 1.176 + const uint8_t *src = src_ybc->y_buffer; 1.177 + uint8_t *dst = dst_ybc->y_buffer; 1.178 + 1.179 + for (row = 0; row < src_ybc->y_height; ++row) { 1.180 + vpx_memcpy(dst, src, src_ybc->y_width); 1.181 + src += src_ybc->y_stride; 1.182 + dst += dst_ybc->y_stride; 1.183 + } 1.184 +}