Merge "Reduce overshoot in 1 pass rate control"
[libvpx.git] / vpx_scale / generic / yv12config.c
blobcb0ab9466b0499837c5c23ce25593a8ec302a031
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 duck_free(ybf->buffer_alloc);
29 ybf->buffer_alloc = 0;
31 else
33 return -1;
36 return 0;
39 /****************************************************************************
41 ****************************************************************************/
42 int
43 vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int border)
45 /*NOTE:*/
47 int yplane_size = (height + 2 * border) * (width + 2 * border);
48 int uvplane_size = ((1 + height) / 2 + border) * ((1 + width) / 2 + border);
50 if (ybf)
52 vp8_yv12_de_alloc_frame_buffer(ybf);
54 ybf->y_width = width;
55 ybf->y_height = height;
56 ybf->y_stride = width + 2 * border;
58 ybf->uv_width = (1 + width) / 2;
59 ybf->uv_height = (1 + height) / 2;
60 ybf->uv_stride = ybf->uv_width + border;
62 ybf->border = border;
63 ybf->frame_size = yplane_size + 2 * uvplane_size;
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.
69 ybf->buffer_alloc = (unsigned char *) duck_memalign(32, ybf->frame_size + (ybf->y_stride * 2) + 32, 0);
71 if (ybf->buffer_alloc == NULL)
72 return -1;
74 ybf->y_buffer = ybf->buffer_alloc + (border * ybf->y_stride) + border;
76 if (yplane_size & 0xf)
77 yplane_size += 16 - (yplane_size & 0xf);
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;
82 ybf->corrupted = 0; /* assume not currupted by errors */
84 else
86 return -2;
89 return 0;