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