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 12 #include "extend.h" 13 #include "vpx_mem/vpx_mem.h" 14 15 16 static void extend_plane_borders 17 ( 18 unsigned char *s, // source 19 int sp, // pitch 20 int h, // height 21 int w, // width 22 int et, // extend top border 23 int el, // extend left border 24 int eb, // extend bottom border 25 int er // extend right border 26 ) 27 { 28 29 int i; 30 unsigned char *src_ptr1, *src_ptr2; 31 unsigned char *dest_ptr1, *dest_ptr2; 32 int linesize; 33 34 // copy the left and right most columns out 35 src_ptr1 = s; 36 src_ptr2 = s + w - 1; 37 dest_ptr1 = s - el; 38 dest_ptr2 = s + w; 39 40 for (i = 0; i < h - 0 + 1; i++) 41 { 42 // Some linkers will complain if we call vpx_memset with el set to a 43 // constant 0. 44 if (el) 45 vpx_memset(dest_ptr1, src_ptr1[0], el); 46 vpx_memset(dest_ptr2, src_ptr2[0], er); 47 src_ptr1 += sp; 48 src_ptr2 += sp; 49 dest_ptr1 += sp; 50 dest_ptr2 += sp; 51 } 52 53 // Now copy the top and bottom source lines into each line of the respective borders 54 src_ptr1 = s - el; 55 src_ptr2 = s + sp * (h - 1) - el; 56 dest_ptr1 = s + sp * (-et) - el; 57 dest_ptr2 = s + sp * (h) - el; 58 linesize = el + er + w + 1; 59 60 for (i = 0; i < (int)et; i++) 61 { 62 vpx_memcpy(dest_ptr1, src_ptr1, linesize); 63 dest_ptr1 += sp; 64 } 65 66 for (i = 0; i < (int)eb; i++) 67 { 68 vpx_memcpy(dest_ptr2, src_ptr2, linesize); 69 dest_ptr2 += sp; 70 } 71 } 72 73 74 void vp8_extend_to_multiple_of16(YV12_BUFFER_CONFIG *ybf, int width, int height) 75 { 76 int er = 0xf & (16 - (width & 0xf)); 77 int eb = 0xf & (16 - (height & 0xf)); 78 79 // check for non multiples of 16 80 if (er != 0 || eb != 0) 81 { 82 extend_plane_borders(ybf->y_buffer, ybf->y_stride, height, width, 0, 0, eb, er); 83 84 //adjust for uv 85 height = (height + 1) >> 1; 86 width = (width + 1) >> 1; 87 er = 0x7 & (8 - (width & 0x7)); 88 eb = 0x7 & (8 - (height & 0x7)); 89 90 if (er || eb) 91 { 92 extend_plane_borders(ybf->u_buffer, ybf->uv_stride, height, width, 0, 0, eb, er); 93 extend_plane_borders(ybf->v_buffer, ybf->uv_stride, height, width, 0, 0, eb, er); 94 } 95 } 96 } 97 98 // note the extension is only for the last row, for intra prediction purpose 99 void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, unsigned char *YPtr, unsigned char *UPtr, unsigned char *VPtr) 100 { 101 int i; 102 103 YPtr += ybf->y_stride * 14; 104 UPtr += ybf->uv_stride * 6; 105 VPtr += ybf->uv_stride * 6; 106 107 for (i = 0; i < 4; i++) 108 { 109 YPtr[i] = YPtr[-1]; 110 UPtr[i] = UPtr[-1]; 111 VPtr[i] = VPtr[-1]; 112 } 113 114 YPtr += ybf->y_stride; 115 UPtr += ybf->uv_stride; 116 VPtr += ybf->uv_stride; 117 118 for (i = 0; i < 4; i++) 119 { 120 YPtr[i] = YPtr[-1]; 121 UPtr[i] = UPtr[-1]; 122 VPtr[i] = VPtr[-1]; 123 } 124 } 125