1 /* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "extend.h" 12 #include "vpx_mem/vpx_mem.h" 13 14 static void copy_and_extend_plane(unsigned char *s, /* source */ 15 int sp, /* source pitch */ 16 unsigned char *d, /* destination */ 17 int dp, /* destination pitch */ 18 int h, /* height */ 19 int w, /* width */ 20 int et, /* extend top border */ 21 int el, /* extend left border */ 22 int eb, /* extend bottom border */ 23 int er /* extend right border */ 24 ) { 25 int i; 26 unsigned char *src_ptr1, *src_ptr2; 27 unsigned char *dest_ptr1, *dest_ptr2; 28 int linesize; 29 30 /* copy the left and right most columns out */ 31 src_ptr1 = s; 32 src_ptr2 = s + w - 1; 33 dest_ptr1 = d - el; 34 dest_ptr2 = d + w; 35 36 for (i = 0; i < h; ++i) { 37 memset(dest_ptr1, src_ptr1[0], el); 38 memcpy(dest_ptr1 + el, src_ptr1, w); 39 memset(dest_ptr2, src_ptr2[0], er); 40 src_ptr1 += sp; 41 src_ptr2 += sp; 42 dest_ptr1 += dp; 43 dest_ptr2 += dp; 44 } 45 46 /* Now copy the top and bottom lines into each line of the respective 47 * borders 48 */ 49 src_ptr1 = d - el; 50 src_ptr2 = d + dp * (h - 1) - el; 51 dest_ptr1 = d + dp * (-et) - el; 52 dest_ptr2 = d + dp * (h)-el; 53 linesize = el + er + w; 54 55 for (i = 0; i < et; ++i) { 56 memcpy(dest_ptr1, src_ptr1, linesize); 57 dest_ptr1 += dp; 58 } 59 60 for (i = 0; i < eb; ++i) { 61 memcpy(dest_ptr2, src_ptr2, linesize); 62 dest_ptr2 += dp; 63 } 64 } 65 66 void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src, 67 YV12_BUFFER_CONFIG *dst) { 68 int et = dst->border; 69 int el = dst->border; 70 int eb = dst->border + dst->y_height - src->y_height; 71 int er = dst->border + dst->y_width - src->y_width; 72 73 copy_and_extend_plane(src->y_buffer, src->y_stride, dst->y_buffer, 74 dst->y_stride, src->y_height, src->y_width, et, el, eb, 75 er); 76 77 et = dst->border >> 1; 78 el = dst->border >> 1; 79 eb = (dst->border >> 1) + dst->uv_height - src->uv_height; 80 er = (dst->border >> 1) + dst->uv_width - src->uv_width; 81 82 copy_and_extend_plane(src->u_buffer, src->uv_stride, dst->u_buffer, 83 dst->uv_stride, src->uv_height, src->uv_width, et, el, 84 eb, er); 85 86 copy_and_extend_plane(src->v_buffer, src->uv_stride, dst->v_buffer, 87 dst->uv_stride, src->uv_height, src->uv_width, et, el, 88 eb, er); 89 } 90 91 void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src, 92 YV12_BUFFER_CONFIG *dst, int srcy, 93 int srcx, int srch, int srcw) { 94 int et = dst->border; 95 int el = dst->border; 96 int eb = dst->border + dst->y_height - src->y_height; 97 int er = dst->border + dst->y_width - src->y_width; 98 int src_y_offset = srcy * src->y_stride + srcx; 99 int dst_y_offset = srcy * dst->y_stride + srcx; 100 int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1); 101 int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1); 102 103 /* If the side is not touching the bounder then don't extend. */ 104 if (srcy) et = 0; 105 if (srcx) el = 0; 106 if (srcy + srch != src->y_height) eb = 0; 107 if (srcx + srcw != src->y_width) er = 0; 108 109 copy_and_extend_plane(src->y_buffer + src_y_offset, src->y_stride, 110 dst->y_buffer + dst_y_offset, dst->y_stride, srch, srcw, 111 et, el, eb, er); 112 113 et = (et + 1) >> 1; 114 el = (el + 1) >> 1; 115 eb = (eb + 1) >> 1; 116 er = (er + 1) >> 1; 117 srch = (srch + 1) >> 1; 118 srcw = (srcw + 1) >> 1; 119 120 copy_and_extend_plane(src->u_buffer + src_uv_offset, src->uv_stride, 121 dst->u_buffer + dst_uv_offset, dst->uv_stride, srch, 122 srcw, et, el, eb, er); 123 124 copy_and_extend_plane(src->v_buffer + src_uv_offset, src->uv_stride, 125 dst->v_buffer + dst_uv_offset, dst->uv_stride, srch, 126 srcw, et, el, eb, er); 127 } 128 129 /* note the extension is only for the last row, for intra prediction purpose */ 130 void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr, 131 unsigned char *UPtr, unsigned char *VPtr) { 132 int i; 133 134 YPtr += ybf->y_stride * 14; 135 UPtr += ybf->uv_stride * 6; 136 VPtr += ybf->uv_stride * 6; 137 138 for (i = 0; i < 4; ++i) { 139 YPtr[i] = YPtr[-1]; 140 UPtr[i] = UPtr[-1]; 141 VPtr[i] = VPtr[-1]; 142 } 143 144 YPtr += ybf->y_stride; 145 UPtr += ybf->uv_stride; 146 VPtr += ybf->uv_stride; 147 148 for (i = 0; i < 4; ++i) { 149 YPtr[i] = YPtr[-1]; 150 UPtr[i] = UPtr[-1]; 151 VPtr[i] = VPtr[-1]; 152 } 153 } 154