michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #include "extend.h" michael@0: #include "vpx_mem/vpx_mem.h" michael@0: michael@0: michael@0: static void copy_and_extend_plane michael@0: ( michael@0: unsigned char *s, /* source */ michael@0: int sp, /* source pitch */ michael@0: unsigned char *d, /* destination */ michael@0: int dp, /* destination pitch */ michael@0: int h, /* height */ michael@0: int w, /* width */ michael@0: int et, /* extend top border */ michael@0: int el, /* extend left border */ michael@0: int eb, /* extend bottom border */ michael@0: int er /* extend right border */ michael@0: ) michael@0: { michael@0: int i; michael@0: unsigned char *src_ptr1, *src_ptr2; michael@0: unsigned char *dest_ptr1, *dest_ptr2; michael@0: int linesize; michael@0: michael@0: /* copy the left and right most columns out */ michael@0: src_ptr1 = s; michael@0: src_ptr2 = s + w - 1; michael@0: dest_ptr1 = d - el; michael@0: dest_ptr2 = d + w; michael@0: michael@0: for (i = 0; i < h; i++) michael@0: { michael@0: vpx_memset(dest_ptr1, src_ptr1[0], el); michael@0: vpx_memcpy(dest_ptr1 + el, src_ptr1, w); michael@0: vpx_memset(dest_ptr2, src_ptr2[0], er); michael@0: src_ptr1 += sp; michael@0: src_ptr2 += sp; michael@0: dest_ptr1 += dp; michael@0: dest_ptr2 += dp; michael@0: } michael@0: michael@0: /* Now copy the top and bottom lines into each line of the respective michael@0: * borders michael@0: */ michael@0: src_ptr1 = d - el; michael@0: src_ptr2 = d + dp * (h - 1) - el; michael@0: dest_ptr1 = d + dp * (-et) - el; michael@0: dest_ptr2 = d + dp * (h) - el; michael@0: linesize = el + er + w; michael@0: michael@0: for (i = 0; i < et; i++) michael@0: { michael@0: vpx_memcpy(dest_ptr1, src_ptr1, linesize); michael@0: dest_ptr1 += dp; michael@0: } michael@0: michael@0: for (i = 0; i < eb; i++) michael@0: { michael@0: vpx_memcpy(dest_ptr2, src_ptr2, linesize); michael@0: dest_ptr2 += dp; michael@0: } michael@0: } michael@0: michael@0: michael@0: void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src, michael@0: YV12_BUFFER_CONFIG *dst) michael@0: { michael@0: int et = dst->border; michael@0: int el = dst->border; michael@0: int eb = dst->border + dst->y_height - src->y_height; michael@0: int er = dst->border + dst->y_width - src->y_width; michael@0: michael@0: copy_and_extend_plane(src->y_buffer, src->y_stride, michael@0: dst->y_buffer, dst->y_stride, michael@0: src->y_height, src->y_width, michael@0: et, el, eb, er); michael@0: michael@0: et = dst->border >> 1; michael@0: el = dst->border >> 1; michael@0: eb = (dst->border >> 1) + dst->uv_height - src->uv_height; michael@0: er = (dst->border >> 1) + dst->uv_width - src->uv_width; michael@0: michael@0: copy_and_extend_plane(src->u_buffer, src->uv_stride, michael@0: dst->u_buffer, dst->uv_stride, michael@0: src->uv_height, src->uv_width, michael@0: et, el, eb, er); michael@0: michael@0: copy_and_extend_plane(src->v_buffer, src->uv_stride, michael@0: dst->v_buffer, dst->uv_stride, michael@0: src->uv_height, src->uv_width, michael@0: et, el, eb, er); michael@0: } michael@0: michael@0: michael@0: void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src, michael@0: YV12_BUFFER_CONFIG *dst, michael@0: int srcy, int srcx, michael@0: int srch, int srcw) michael@0: { michael@0: int et = dst->border; michael@0: int el = dst->border; michael@0: int eb = dst->border + dst->y_height - src->y_height; michael@0: int er = dst->border + dst->y_width - src->y_width; michael@0: int src_y_offset = srcy * src->y_stride + srcx; michael@0: int dst_y_offset = srcy * dst->y_stride + srcx; michael@0: int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1); michael@0: int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1); michael@0: michael@0: /* If the side is not touching the bounder then don't extend. */ michael@0: if (srcy) michael@0: et = 0; michael@0: if (srcx) michael@0: el = 0; michael@0: if (srcy + srch != src->y_height) michael@0: eb = 0; michael@0: if (srcx + srcw != src->y_width) michael@0: er = 0; michael@0: michael@0: copy_and_extend_plane(src->y_buffer + src_y_offset, michael@0: src->y_stride, michael@0: dst->y_buffer + dst_y_offset, michael@0: dst->y_stride, michael@0: srch, srcw, michael@0: et, el, eb, er); michael@0: michael@0: et = (et + 1) >> 1; michael@0: el = (el + 1) >> 1; michael@0: eb = (eb + 1) >> 1; michael@0: er = (er + 1) >> 1; michael@0: srch = (srch + 1) >> 1; michael@0: srcw = (srcw + 1) >> 1; michael@0: michael@0: copy_and_extend_plane(src->u_buffer + src_uv_offset, michael@0: src->uv_stride, michael@0: dst->u_buffer + dst_uv_offset, michael@0: dst->uv_stride, michael@0: srch, srcw, michael@0: et, el, eb, er); michael@0: michael@0: copy_and_extend_plane(src->v_buffer + src_uv_offset, michael@0: src->uv_stride, michael@0: dst->v_buffer + dst_uv_offset, michael@0: dst->uv_stride, michael@0: srch, srcw, michael@0: et, el, eb, er); michael@0: } michael@0: michael@0: michael@0: /* note the extension is only for the last row, for intra prediction purpose */ michael@0: void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, michael@0: unsigned char *YPtr, michael@0: unsigned char *UPtr, michael@0: unsigned char *VPtr) michael@0: { michael@0: int i; michael@0: michael@0: YPtr += ybf->y_stride * 14; michael@0: UPtr += ybf->uv_stride * 6; michael@0: VPtr += ybf->uv_stride * 6; michael@0: michael@0: for (i = 0; i < 4; i++) michael@0: { michael@0: YPtr[i] = YPtr[-1]; michael@0: UPtr[i] = UPtr[-1]; michael@0: VPtr[i] = VPtr[-1]; michael@0: } michael@0: michael@0: YPtr += ybf->y_stride; michael@0: UPtr += ybf->uv_stride; michael@0: VPtr += ybf->uv_stride; michael@0: michael@0: for (i = 0; i < 4; i++) michael@0: { michael@0: YPtr[i] = YPtr[-1]; michael@0: UPtr[i] = UPtr[-1]; michael@0: VPtr[i] = VPtr[-1]; michael@0: } michael@0: }