1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/common/vp9_extend.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,143 @@ 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 "vpx_mem/vpx_mem.h" 1.15 + 1.16 +#include "vp9/common/vp9_common.h" 1.17 +#include "vp9/common/vp9_extend.h" 1.18 + 1.19 +static void copy_and_extend_plane(const uint8_t *src, int src_pitch, 1.20 + uint8_t *dst, int dst_pitch, 1.21 + int w, int h, 1.22 + int extend_top, int extend_left, 1.23 + int extend_bottom, int extend_right) { 1.24 + int i, linesize; 1.25 + 1.26 + // copy the left and right most columns out 1.27 + const uint8_t *src_ptr1 = src; 1.28 + const uint8_t *src_ptr2 = src + w - 1; 1.29 + uint8_t *dst_ptr1 = dst - extend_left; 1.30 + uint8_t *dst_ptr2 = dst + w; 1.31 + 1.32 + for (i = 0; i < h; i++) { 1.33 + vpx_memset(dst_ptr1, src_ptr1[0], extend_left); 1.34 + vpx_memcpy(dst_ptr1 + extend_left, src_ptr1, w); 1.35 + vpx_memset(dst_ptr2, src_ptr2[0], extend_right); 1.36 + src_ptr1 += src_pitch; 1.37 + src_ptr2 += src_pitch; 1.38 + dst_ptr1 += dst_pitch; 1.39 + dst_ptr2 += dst_pitch; 1.40 + } 1.41 + 1.42 + // Now copy the top and bottom lines into each line of the respective 1.43 + // borders 1.44 + src_ptr1 = dst - extend_left; 1.45 + src_ptr2 = dst + dst_pitch * (h - 1) - extend_left; 1.46 + dst_ptr1 = dst + dst_pitch * (-extend_top) - extend_left; 1.47 + dst_ptr2 = dst + dst_pitch * (h) - extend_left; 1.48 + linesize = extend_left + extend_right + w; 1.49 + 1.50 + for (i = 0; i < extend_top; i++) { 1.51 + vpx_memcpy(dst_ptr1, src_ptr1, linesize); 1.52 + dst_ptr1 += dst_pitch; 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 += dst_pitch; 1.58 + } 1.59 +} 1.60 + 1.61 +void vp9_copy_and_extend_frame(const YV12_BUFFER_CONFIG *src, 1.62 + YV12_BUFFER_CONFIG *dst) { 1.63 + // Extend src frame in buffer 1.64 + // Altref filtering assumes 16 pixel extension 1.65 + const int et_y = 16; 1.66 + const int el_y = 16; 1.67 + // Motion estimation may use src block variance with the block size up 1.68 + // to 64x64, so the right and bottom need to be extended to 64 multiple 1.69 + // or up to 16, whichever is greater. 1.70 + const int eb_y = MAX(ALIGN_POWER_OF_TWO(src->y_width, 6) - src->y_width, 1.71 + 16); 1.72 + const int er_y = MAX(ALIGN_POWER_OF_TWO(src->y_height, 6) - src->y_height, 1.73 + 16); 1.74 + const int uv_width_subsampling = (src->uv_width != src->y_width); 1.75 + const int uv_height_subsampling = (src->uv_height != src->y_height); 1.76 + const int et_uv = et_y >> uv_height_subsampling; 1.77 + const int el_uv = el_y >> uv_width_subsampling; 1.78 + const int eb_uv = eb_y >> uv_height_subsampling; 1.79 + const int er_uv = er_y >> uv_width_subsampling; 1.80 + 1.81 +#if CONFIG_ALPHA 1.82 + const int et_a = dst->border >> (dst->alpha_height != dst->y_height); 1.83 + const int el_a = dst->border >> (dst->alpha_width != dst->y_width); 1.84 + const int eb_a = et_a + dst->alpha_height - src->alpha_height; 1.85 + const int er_a = el_a + dst->alpha_width - src->alpha_width; 1.86 + 1.87 + copy_and_extend_plane(src->alpha_buffer, src->alpha_stride, 1.88 + dst->alpha_buffer, dst->alpha_stride, 1.89 + src->alpha_width, src->alpha_height, 1.90 + et_a, el_a, eb_a, er_a); 1.91 +#endif 1.92 + 1.93 + copy_and_extend_plane(src->y_buffer, src->y_stride, 1.94 + dst->y_buffer, dst->y_stride, 1.95 + src->y_width, src->y_height, 1.96 + et_y, el_y, eb_y, er_y); 1.97 + 1.98 + copy_and_extend_plane(src->u_buffer, src->uv_stride, 1.99 + dst->u_buffer, dst->uv_stride, 1.100 + src->uv_width, src->uv_height, 1.101 + et_uv, el_uv, eb_uv, er_uv); 1.102 + 1.103 + copy_and_extend_plane(src->v_buffer, src->uv_stride, 1.104 + dst->v_buffer, dst->uv_stride, 1.105 + src->uv_width, src->uv_height, 1.106 + et_uv, el_uv, eb_uv, er_uv); 1.107 +} 1.108 + 1.109 +void vp9_copy_and_extend_frame_with_rect(const YV12_BUFFER_CONFIG *src, 1.110 + YV12_BUFFER_CONFIG *dst, 1.111 + int srcy, int srcx, 1.112 + int srch, int srcw) { 1.113 + // If the side is not touching the bounder then don't extend. 1.114 + const int et_y = srcy ? 0 : dst->border; 1.115 + const int el_y = srcx ? 0 : dst->border; 1.116 + const int eb_y = srcy + srch != src->y_height ? 0 : 1.117 + dst->border + dst->y_height - src->y_height; 1.118 + const int er_y = srcx + srcw != src->y_width ? 0 : 1.119 + dst->border + dst->y_width - src->y_width; 1.120 + const int src_y_offset = srcy * src->y_stride + srcx; 1.121 + const int dst_y_offset = srcy * dst->y_stride + srcx; 1.122 + 1.123 + const int et_uv = ROUND_POWER_OF_TWO(et_y, 1); 1.124 + const int el_uv = ROUND_POWER_OF_TWO(el_y, 1); 1.125 + const int eb_uv = ROUND_POWER_OF_TWO(eb_y, 1); 1.126 + const int er_uv = ROUND_POWER_OF_TWO(er_y, 1); 1.127 + const int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1); 1.128 + const int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1); 1.129 + const int srch_uv = ROUND_POWER_OF_TWO(srch, 1); 1.130 + const int srcw_uv = ROUND_POWER_OF_TWO(srcw, 1); 1.131 + 1.132 + copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride, 1.133 + dst->y_buffer + dst_y_offset, dst->y_stride, 1.134 + srcw, srch, 1.135 + et_y, el_y, eb_y, er_y); 1.136 + 1.137 + copy_and_extend_plane(src->u_buffer + src_uv_offset, src->uv_stride, 1.138 + dst->u_buffer + dst_uv_offset, dst->uv_stride, 1.139 + srcw_uv, srch_uv, 1.140 + et_uv, el_uv, eb_uv, er_uv); 1.141 + 1.142 + copy_and_extend_plane(src->v_buffer + src_uv_offset, src->uv_stride, 1.143 + dst->v_buffer + dst_uv_offset, dst->uv_stride, 1.144 + srcw_uv, srch_uv, 1.145 + et_uv, el_uv, eb_uv, er_uv); 1.146 +}