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 15 /**************************************************************************** 16 * Exports 17 ****************************************************************************/ 18 19 /**************************************************************************** 20 * 21 ****************************************************************************/ 22 int 23 vp8_yv12_de_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf) 24 { 25 if (ybf) 26 { 27 duck_free(ybf->buffer_alloc); 28 29 ybf->buffer_alloc = 0; 30 } 31 else 32 { 33 return -1; 34 } 35 36 return 0; 37 } 38 39 /**************************************************************************** 40 * 41 ****************************************************************************/ 42 int 43 vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int border) 44 { 45 /*NOTE:*/ 46 47 int yplane_size = (height + 2 * border) * (width + 2 * border); 48 int uvplane_size = ((1 + height) / 2 + border) * ((1 + width) / 2 + border); 49 50 if (ybf) 51 { 52 vp8_yv12_de_alloc_frame_buffer(ybf); 53 54 ybf->y_width = width; 55 ybf->y_height = height; 56 ybf->y_stride = width + 2 * border; 57 58 ybf->uv_width = (1 + width) / 2; 59 ybf->uv_height = (1 + height) / 2; 60 ybf->uv_stride = ybf->uv_width + border; 61 62 ybf->border = border; 63 ybf->frame_size = yplane_size + 2 * uvplane_size; 64 65 /* Added 2 extra lines to framebuffer so that copy12x12 doesn't fail 66 * when we have a large motion vector in V on the last v block. 67 * Note : We never use these pixels anyway so this doesn't hurt. 68 */ 69 ybf->buffer_alloc = (unsigned char *) duck_memalign(32, ybf->frame_size + (ybf->y_stride * 2) + 32, 0); 70 71 if (ybf->buffer_alloc == NULL) 72 return -1; 73 74 ybf->y_buffer = ybf->buffer_alloc + (border * ybf->y_stride) + border; 75 76 if (yplane_size & 0xf) 77 yplane_size += 16 - (yplane_size & 0xf); 78 79 ybf->u_buffer = ybf->buffer_alloc + yplane_size + (border / 2 * ybf->uv_stride) + border / 2; 80 ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size + (border / 2 * ybf->uv_stride) + border / 2; 81 82 ybf->corrupted = 0; /* assume not currupted by errors */ 83 } 84 else 85 { 86 return -2; 87 } 88 89 return 0; 90 } 91