Merge "Skip computation of distortion in vp8_pick_inter_mode if active_map is used"
[libvpx.git] / vpx_scale / generic / yv12config.c
blobeff594e2d0f6469dddd97515ac67c6db96cd81eb
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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 */
12 #include "vpx_scale/yv12config.h"
13 #include "vpx_mem/vpx_mem.h"
15 /****************************************************************************
16 * Exports
17 ****************************************************************************/
19 /****************************************************************************
21 ****************************************************************************/
22 int
23 vp8_yv12_de_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf)
25 if (ybf)
27 vpx_free(ybf->buffer_alloc);
29 /* buffer_alloc isn't accessed by most functions. Rather y_buffer,
30 u_buffer and v_buffer point to buffer_alloc and are used. Clear out
31 all of this so that a freed pointer isn't inadvertently used */
32 vpx_memset (ybf, 0, sizeof (YV12_BUFFER_CONFIG));
34 else
36 return -1;
39 return 0;
42 /****************************************************************************
44 ****************************************************************************/
45 int
46 vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int border)
48 /*NOTE:*/
50 if (ybf)
52 int y_stride = ((width + 2 * border) + 31) & ~31;
53 int yplane_size = (height + 2 * border) * y_stride;
54 int uv_width = width >> 1;
55 int uv_height = height >> 1;
56 /** There is currently a bunch of code which assumes
57 * uv_stride == y_stride/2, so enforce this here. */
58 int uv_stride = y_stride >> 1;
59 int uvplane_size = (uv_height + border) * uv_stride;
61 vp8_yv12_de_alloc_frame_buffer(ybf);
63 /** Only support allocating buffers that have a height and width that
64 * are multiples of 16, and a border that's a multiple of 32.
65 * The border restriction is required to get 16-byte alignment of the
66 * start of the chroma rows without intoducing an arbitrary gap
67 * between planes, which would break the semantics of things like
68 * vpx_img_set_rect(). */
69 if ((width & 0xf) | (height & 0xf) | (border & 0x1f))
70 return -3;
72 ybf->y_width = width;
73 ybf->y_height = height;
74 ybf->y_stride = y_stride;
76 ybf->uv_width = uv_width;
77 ybf->uv_height = uv_height;
78 ybf->uv_stride = uv_stride;
80 ybf->border = border;
81 ybf->frame_size = yplane_size + 2 * uvplane_size;
83 ybf->buffer_alloc = (unsigned char *) vpx_memalign(32, ybf->frame_size);
85 if (ybf->buffer_alloc == NULL)
86 return -1;
88 ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border;
89 ybf->u_buffer = ybf->buffer_alloc + yplane_size + (border / 2 * uv_stride) + border / 2;
90 ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size + (border / 2 * uv_stride) + border / 2;
92 ybf->corrupted = 0; /* assume not currupted by errors */
94 else
96 return -2;
99 return 0;