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 /**************************************************************************** 13 * 14 * Module Title : yv12extend.c 15 * 16 * Description : 17 * 18 ***************************************************************************/ 19 20 /**************************************************************************** 21 * Header Files 22 ****************************************************************************/ 23 //#include <stdlib.h> 24 #include "vpx_scale/yv12config.h" 25 #include "vpx_mem/vpx_mem.h" 26 27 /**************************************************************************** 28 * Exports 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * 33 ****************************************************************************/ 34 void 35 vp8_yv12_extend_frame_borders(YV12_BUFFER_CONFIG *ybf) 36 { 37 int i; 38 char *src_ptr1, *src_ptr2; 39 char *dest_ptr1, *dest_ptr2; 40 41 unsigned int Border; 42 int plane_stride; 43 int plane_height; 44 int plane_width; 45 46 /***********/ 47 /* Y Plane */ 48 /***********/ 49 Border = ybf->border; 50 plane_stride = ybf->y_stride; 51 plane_height = ybf->y_height; 52 plane_width = ybf->y_width; 53 54 // copy the left and right most columns out 55 src_ptr1 = ybf->y_buffer; 56 src_ptr2 = src_ptr1 + plane_width - 1; 57 dest_ptr1 = src_ptr1 - Border; 58 dest_ptr2 = src_ptr2 + 1; 59 60 for (i = 0; i < plane_height; i++) 61 { 62 memset(dest_ptr1, src_ptr1[0], Border); 63 memset(dest_ptr2, src_ptr2[0], Border); 64 src_ptr1 += plane_stride; 65 src_ptr2 += plane_stride; 66 dest_ptr1 += plane_stride; 67 dest_ptr2 += plane_stride; 68 } 69 70 // Now copy the top and bottom source lines into each line of the respective borders 71 src_ptr1 = ybf->y_buffer - Border; 72 src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride; 73 dest_ptr1 = src_ptr1 - (Border * plane_stride); 74 dest_ptr2 = src_ptr2 + plane_stride; 75 76 for (i = 0; i < (int)Border; i++) 77 { 78 memcpy(dest_ptr1, src_ptr1, plane_stride); 79 memcpy(dest_ptr2, src_ptr2, plane_stride); 80 dest_ptr1 += plane_stride; 81 dest_ptr2 += plane_stride; 82 } 83 84 plane_stride /= 2; 85 plane_height /= 2; 86 plane_width /= 2; 87 Border /= 2; 88 89 /***********/ 90 /* U Plane */ 91 /***********/ 92 93 // copy the left and right most columns out 94 src_ptr1 = ybf->u_buffer; 95 src_ptr2 = src_ptr1 + plane_width - 1; 96 dest_ptr1 = src_ptr1 - Border; 97 dest_ptr2 = src_ptr2 + 1; 98 99 for (i = 0; i < plane_height; i++) 100 { 101 memset(dest_ptr1, src_ptr1[0], Border); 102 memset(dest_ptr2, src_ptr2[0], Border); 103 src_ptr1 += plane_stride; 104 src_ptr2 += plane_stride; 105 dest_ptr1 += plane_stride; 106 dest_ptr2 += plane_stride; 107 } 108 109 // Now copy the top and bottom source lines into each line of the respective borders 110 src_ptr1 = ybf->u_buffer - Border; 111 src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride; 112 dest_ptr1 = src_ptr1 - (Border * plane_stride); 113 dest_ptr2 = src_ptr2 + plane_stride; 114 115 for (i = 0; i < (int)(Border); i++) 116 { 117 memcpy(dest_ptr1, src_ptr1, plane_stride); 118 memcpy(dest_ptr2, src_ptr2, plane_stride); 119 dest_ptr1 += plane_stride; 120 dest_ptr2 += plane_stride; 121 } 122 123 /***********/ 124 /* V Plane */ 125 /***********/ 126 127 // copy the left and right most columns out 128 src_ptr1 = ybf->v_buffer; 129 src_ptr2 = src_ptr1 + plane_width - 1; 130 dest_ptr1 = src_ptr1 - Border; 131 dest_ptr2 = src_ptr2 + 1; 132 133 for (i = 0; i < plane_height; i++) 134 { 135 memset(dest_ptr1, src_ptr1[0], Border); 136 memset(dest_ptr2, src_ptr2[0], Border); 137 src_ptr1 += plane_stride; 138 src_ptr2 += plane_stride; 139 dest_ptr1 += plane_stride; 140 dest_ptr2 += plane_stride; 141 } 142 143 // Now copy the top and bottom source lines into each line of the respective borders 144 src_ptr1 = ybf->v_buffer - Border; 145 src_ptr2 = src_ptr1 + (plane_height * plane_stride) - plane_stride; 146 dest_ptr1 = src_ptr1 - (Border * plane_stride); 147 dest_ptr2 = src_ptr2 + plane_stride; 148 149 for (i = 0; i < (int)(Border); i++) 150 { 151 memcpy(dest_ptr1, src_ptr1, plane_stride); 152 memcpy(dest_ptr2, src_ptr2, plane_stride); 153 dest_ptr1 += plane_stride; 154 dest_ptr2 += plane_stride; 155 } 156 } 157 /**************************************************************************** 158 * 159 * ROUTINE : vp8_yv12_copy_frame 160 * 161 * INPUTS : 162 * 163 * OUTPUTS : None. 164 * 165 * RETURNS : void 166 * 167 * FUNCTION : Copies the source image into the destination image and 168 * updates the destination's UMV borders. 169 * 170 * SPECIAL NOTES : The frames are assumed to be identical in size. 171 * 172 ****************************************************************************/ 173 void 174 vp8_yv12_copy_frame(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc) 175 { 176 int row; 177 int i; 178 unsigned int *source; 179 _Uncached unsigned int *dest; 180 int height; 181 int width; 182 183 height = src_ybc->y_height + (src_ybc->border * 2); 184 width = src_ybc->y_width + (src_ybc->border * 2); 185 width /= 4; 186 source = (unsigned int *)(src_ybc->y_buffer - (src_ybc->border * src_ybc->y_stride) - src_ybc->border); 187 dest = (_Uncached unsigned int *)(dst_ybc->y_buffer - (dst_ybc->border * dst_ybc->y_stride) - dst_ybc->border); 188 189 for (row = 0; row < height; row++) 190 { 191 for (i = 0; i < width; i++) 192 { 193 dest[i] = source[i]; 194 } 195 196 source += width; 197 dest += width; 198 } 199 200 height = src_ybc->uv_height + (src_ybc->border); 201 width = src_ybc->uv_width + (src_ybc->border); 202 width /= 4; 203 204 source = (unsigned int *)(src_ybc->u_buffer - (src_ybc->border / 2 * src_ybc->uv_stride) - src_ybc->border / 2); 205 dest = (_Uncached unsigned int *)(dst_ybc->u_buffer - (dst_ybc->border / 2 * dst_ybc->uv_stride) - dst_ybc->border / 2); 206 207 for (row = 0; row < height; row++) 208 { 209 for (i = 0; i < width; i++) 210 { 211 dest[i] = source[i]; 212 } 213 214 source += width; 215 dest += width; 216 } 217 218 source = (unsigned int *)(src_ybc->v_buffer - (src_ybc->border / 2 * src_ybc->uv_stride) - src_ybc->border / 2); 219 dest = (_Uncached unsigned int *)(dst_ybc->v_buffer - (dst_ybc->border / 2 * dst_ybc->uv_stride) - dst_ybc->border / 2); 220 221 for (row = 0; row < height; row++) 222 { 223 for (i = 0; i < width; i++) 224 { 225 dest[i] = source[i]; 226 } 227 228 source += width; 229 dest += width; 230 } 231 232 } 233