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: #include michael@0: #include "./vpx_config.h" michael@0: #include "vpx/vpx_integer.h" michael@0: #include "vpx_mem/vpx_mem.h" michael@0: #include "vpx_scale/yv12config.h" michael@0: michael@0: static void extend_plane(uint8_t *const src, int src_stride, michael@0: int width, int height, michael@0: int extend_top, int extend_left, michael@0: int extend_bottom, int extend_right) { michael@0: int i; michael@0: const int linesize = extend_left + extend_right + width; michael@0: michael@0: /* copy the left and right most columns out */ michael@0: uint8_t *src_ptr1 = src; michael@0: uint8_t *src_ptr2 = src + width - 1; michael@0: uint8_t *dst_ptr1 = src - extend_left; michael@0: uint8_t *dst_ptr2 = src + width; michael@0: michael@0: for (i = 0; i < height; ++i) { michael@0: vpx_memset(dst_ptr1, src_ptr1[0], extend_left); michael@0: vpx_memset(dst_ptr2, src_ptr2[0], extend_right); michael@0: src_ptr1 += src_stride; michael@0: src_ptr2 += src_stride; michael@0: dst_ptr1 += src_stride; michael@0: dst_ptr2 += src_stride; 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 = src - extend_left; michael@0: src_ptr2 = src + src_stride * (height - 1) - extend_left; michael@0: dst_ptr1 = src + src_stride * -extend_top - extend_left; michael@0: dst_ptr2 = src + src_stride * height - extend_left; michael@0: michael@0: for (i = 0; i < extend_top; ++i) { michael@0: vpx_memcpy(dst_ptr1, src_ptr1, linesize); michael@0: dst_ptr1 += src_stride; michael@0: } michael@0: michael@0: for (i = 0; i < extend_bottom; ++i) { michael@0: vpx_memcpy(dst_ptr2, src_ptr2, linesize); michael@0: dst_ptr2 += src_stride; michael@0: } michael@0: } michael@0: michael@0: void vp8_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) { michael@0: assert(ybf->y_height - ybf->y_crop_height < 16); michael@0: assert(ybf->y_width - ybf->y_crop_width < 16); michael@0: assert(ybf->y_height - ybf->y_crop_height >= 0); michael@0: assert(ybf->y_width - ybf->y_crop_width >= 0); michael@0: michael@0: extend_plane(ybf->y_buffer, ybf->y_stride, michael@0: ybf->y_crop_width, ybf->y_crop_height, michael@0: ybf->border, ybf->border, michael@0: ybf->border + ybf->y_height - ybf->y_crop_height, michael@0: ybf->border + ybf->y_width - ybf->y_crop_width); michael@0: michael@0: extend_plane(ybf->u_buffer, ybf->uv_stride, michael@0: (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, michael@0: ybf->border / 2, ybf->border / 2, michael@0: (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, michael@0: (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); michael@0: michael@0: extend_plane(ybf->v_buffer, ybf->uv_stride, michael@0: (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, michael@0: ybf->border / 2, ybf->border / 2, michael@0: (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, michael@0: (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); michael@0: } michael@0: michael@0: #if CONFIG_VP9 michael@0: static void extend_frame(YV12_BUFFER_CONFIG *const ybf, michael@0: int subsampling_x, int subsampling_y, michael@0: int ext_size) { michael@0: const int c_w = ybf->uv_crop_width; michael@0: const int c_h = ybf->uv_crop_height; michael@0: const int c_ext_size = ext_size >> 1; michael@0: const int c_et = c_ext_size; michael@0: const int c_el = c_ext_size; michael@0: const int c_eb = c_ext_size + ybf->uv_height - ybf->uv_crop_height; michael@0: const int c_er = c_ext_size + ybf->uv_width - ybf->uv_crop_width; michael@0: michael@0: assert(ybf->y_height - ybf->y_crop_height < 16); michael@0: assert(ybf->y_width - ybf->y_crop_width < 16); michael@0: assert(ybf->y_height - ybf->y_crop_height >= 0); michael@0: assert(ybf->y_width - ybf->y_crop_width >= 0); michael@0: michael@0: extend_plane(ybf->y_buffer, ybf->y_stride, michael@0: ybf->y_crop_width, ybf->y_crop_height, michael@0: ext_size, ext_size, michael@0: ext_size + ybf->y_height - ybf->y_crop_height, michael@0: ext_size + ybf->y_width - ybf->y_crop_width); michael@0: michael@0: extend_plane(ybf->u_buffer, ybf->uv_stride, michael@0: c_w, c_h, c_et, c_el, c_eb, c_er); michael@0: michael@0: extend_plane(ybf->v_buffer, ybf->uv_stride, michael@0: c_w, c_h, c_et, c_el, c_eb, c_er); michael@0: } michael@0: michael@0: void vp9_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, michael@0: int subsampling_x, int subsampling_y) { michael@0: extend_frame(ybf, subsampling_x, subsampling_y, ybf->border); michael@0: } michael@0: michael@0: void vp9_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf, michael@0: int subsampling_x, int subsampling_y) { michael@0: const int inner_bw = (ybf->border > VP9INNERBORDERINPIXELS) ? michael@0: VP9INNERBORDERINPIXELS : ybf->border; michael@0: extend_frame(ybf, subsampling_x, subsampling_y, inner_bw); michael@0: } michael@0: #endif // CONFIG_VP9 michael@0: michael@0: // Copies the source image into the destination image and updates the michael@0: // destination's UMV borders. michael@0: // Note: The frames are assumed to be identical in size. michael@0: void vp8_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_ybc, michael@0: YV12_BUFFER_CONFIG *dst_ybc) { michael@0: int row; michael@0: const uint8_t *src = src_ybc->y_buffer; michael@0: uint8_t *dst = dst_ybc->y_buffer; michael@0: michael@0: #if 0 michael@0: /* These assertions are valid in the codec, but the libvpx-tester uses michael@0: * this code slightly differently. michael@0: */ michael@0: assert(src_ybc->y_width == dst_ybc->y_width); michael@0: assert(src_ybc->y_height == dst_ybc->y_height); michael@0: #endif michael@0: michael@0: for (row = 0; row < src_ybc->y_height; ++row) { michael@0: vpx_memcpy(dst, src, src_ybc->y_width); michael@0: src += src_ybc->y_stride; michael@0: dst += dst_ybc->y_stride; michael@0: } michael@0: michael@0: src = src_ybc->u_buffer; michael@0: dst = dst_ybc->u_buffer; michael@0: michael@0: for (row = 0; row < src_ybc->uv_height; ++row) { michael@0: vpx_memcpy(dst, src, src_ybc->uv_width); michael@0: src += src_ybc->uv_stride; michael@0: dst += dst_ybc->uv_stride; michael@0: } michael@0: michael@0: src = src_ybc->v_buffer; michael@0: dst = dst_ybc->v_buffer; michael@0: michael@0: for (row = 0; row < src_ybc->uv_height; ++row) { michael@0: vpx_memcpy(dst, src, src_ybc->uv_width); michael@0: src += src_ybc->uv_stride; michael@0: dst += dst_ybc->uv_stride; michael@0: } michael@0: michael@0: vp8_yv12_extend_frame_borders_c(dst_ybc); michael@0: } michael@0: michael@0: void vpx_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc, michael@0: YV12_BUFFER_CONFIG *dst_ybc) { michael@0: int row; michael@0: const uint8_t *src = src_ybc->y_buffer; michael@0: uint8_t *dst = dst_ybc->y_buffer; michael@0: michael@0: for (row = 0; row < src_ybc->y_height; ++row) { michael@0: vpx_memcpy(dst, src, src_ybc->y_width); michael@0: src += src_ybc->y_stride; michael@0: dst += dst_ybc->y_stride; michael@0: } michael@0: }