2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "vpx_scale/yv12config.h"
|
|
|
|
#include "vpx_mem/vpx_mem.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Exports
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
int
|
|
|
|
vp8_yv12_de_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf)
|
|
|
|
{
|
|
|
|
if (ybf)
|
|
|
|
{
|
2011-07-11 20:42:28 +02:00
|
|
|
vpx_free(ybf->buffer_alloc);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-07-11 20:42:28 +02:00
|
|
|
/* buffer_alloc isn't accessed by most functions. Rather y_buffer,
|
|
|
|
u_buffer and v_buffer point to buffer_alloc and are used. Clear out
|
|
|
|
all of this so that a freed pointer isn't inadvertently used */
|
|
|
|
vpx_memset (ybf, 0, sizeof (YV12_BUFFER_CONFIG));
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
int
|
|
|
|
vp8_yv12_alloc_frame_buffer(YV12_BUFFER_CONFIG *ybf, int width, int height, int border)
|
|
|
|
{
|
2010-10-28 01:04:02 +02:00
|
|
|
/*NOTE:*/
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (ybf)
|
|
|
|
{
|
Increase chrow row alignment to 16 bytes.
This is done by expanding luma row to 32-byte alignment, since
there is currently a bunch of code that assumes that
uv_stride == y_stride/2 (see, for example, vp8/common/postproc.c,
common/reconinter.c, common/arm/neon/recon16x16mb_neon.asm,
encoder/temporal_filter.c, and possibly others; I haven't done a
full audit).
It also uses replaces the hardcoded border of 16 in a number of
encoder buffers with VP8BORDERINPIXELS (currently 32), as the
chroma rows start at an offset of border/2.
Together, these two changes have the nice advantage that simply
dumping the frame memory as a contiguous blob produces a valid,
if padded, image.
Change-Id: Iaf5ea722ae5c82d5daa50f6e2dade9de753f1003
2011-07-20 19:20:31 +02:00
|
|
|
int y_stride = ((width + 2 * border) + 31) & ~31;
|
|
|
|
int yplane_size = (height + 2 * border) * y_stride;
|
2011-07-11 20:42:28 +02:00
|
|
|
int uv_width = width >> 1;
|
|
|
|
int uv_height = height >> 1;
|
Increase chrow row alignment to 16 bytes.
This is done by expanding luma row to 32-byte alignment, since
there is currently a bunch of code that assumes that
uv_stride == y_stride/2 (see, for example, vp8/common/postproc.c,
common/reconinter.c, common/arm/neon/recon16x16mb_neon.asm,
encoder/temporal_filter.c, and possibly others; I haven't done a
full audit).
It also uses replaces the hardcoded border of 16 in a number of
encoder buffers with VP8BORDERINPIXELS (currently 32), as the
chroma rows start at an offset of border/2.
Together, these two changes have the nice advantage that simply
dumping the frame memory as a contiguous blob produces a valid,
if padded, image.
Change-Id: Iaf5ea722ae5c82d5daa50f6e2dade9de753f1003
2011-07-20 19:20:31 +02:00
|
|
|
/** There is currently a bunch of code which assumes
|
|
|
|
* uv_stride == y_stride/2, so enforce this here. */
|
|
|
|
int uv_stride = y_stride >> 1;
|
|
|
|
int uvplane_size = (uv_height + border) * uv_stride;
|
2011-07-11 20:42:28 +02:00
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
vp8_yv12_de_alloc_frame_buffer(ybf);
|
|
|
|
|
Increase chrow row alignment to 16 bytes.
This is done by expanding luma row to 32-byte alignment, since
there is currently a bunch of code that assumes that
uv_stride == y_stride/2 (see, for example, vp8/common/postproc.c,
common/reconinter.c, common/arm/neon/recon16x16mb_neon.asm,
encoder/temporal_filter.c, and possibly others; I haven't done a
full audit).
It also uses replaces the hardcoded border of 16 in a number of
encoder buffers with VP8BORDERINPIXELS (currently 32), as the
chroma rows start at an offset of border/2.
Together, these two changes have the nice advantage that simply
dumping the frame memory as a contiguous blob produces a valid,
if padded, image.
Change-Id: Iaf5ea722ae5c82d5daa50f6e2dade9de753f1003
2011-07-20 19:20:31 +02:00
|
|
|
/** Only support allocating buffers that have a height and width that
|
|
|
|
* are multiples of 16, and a border that's a multiple of 32.
|
|
|
|
* The border restriction is required to get 16-byte alignment of the
|
|
|
|
* start of the chroma rows without intoducing an arbitrary gap
|
|
|
|
* between planes, which would break the semantics of things like
|
|
|
|
* vpx_img_set_rect(). */
|
|
|
|
if ((width & 0xf) | (height & 0xf) | (border & 0x1f))
|
2011-07-11 20:42:28 +02:00
|
|
|
return -3;
|
|
|
|
|
2010-05-18 17:58:33 +02:00
|
|
|
ybf->y_width = width;
|
|
|
|
ybf->y_height = height;
|
Increase chrow row alignment to 16 bytes.
This is done by expanding luma row to 32-byte alignment, since
there is currently a bunch of code that assumes that
uv_stride == y_stride/2 (see, for example, vp8/common/postproc.c,
common/reconinter.c, common/arm/neon/recon16x16mb_neon.asm,
encoder/temporal_filter.c, and possibly others; I haven't done a
full audit).
It also uses replaces the hardcoded border of 16 in a number of
encoder buffers with VP8BORDERINPIXELS (currently 32), as the
chroma rows start at an offset of border/2.
Together, these two changes have the nice advantage that simply
dumping the frame memory as a contiguous blob produces a valid,
if padded, image.
Change-Id: Iaf5ea722ae5c82d5daa50f6e2dade9de753f1003
2011-07-20 19:20:31 +02:00
|
|
|
ybf->y_stride = y_stride;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2011-07-11 20:42:28 +02:00
|
|
|
ybf->uv_width = uv_width;
|
|
|
|
ybf->uv_height = uv_height;
|
Increase chrow row alignment to 16 bytes.
This is done by expanding luma row to 32-byte alignment, since
there is currently a bunch of code that assumes that
uv_stride == y_stride/2 (see, for example, vp8/common/postproc.c,
common/reconinter.c, common/arm/neon/recon16x16mb_neon.asm,
encoder/temporal_filter.c, and possibly others; I haven't done a
full audit).
It also uses replaces the hardcoded border of 16 in a number of
encoder buffers with VP8BORDERINPIXELS (currently 32), as the
chroma rows start at an offset of border/2.
Together, these two changes have the nice advantage that simply
dumping the frame memory as a contiguous blob produces a valid,
if padded, image.
Change-Id: Iaf5ea722ae5c82d5daa50f6e2dade9de753f1003
2011-07-20 19:20:31 +02:00
|
|
|
ybf->uv_stride = uv_stride;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
ybf->border = border;
|
|
|
|
ybf->frame_size = yplane_size + 2 * uvplane_size;
|
|
|
|
|
2011-07-11 20:42:28 +02:00
|
|
|
ybf->buffer_alloc = (unsigned char *) vpx_memalign(32, ybf->frame_size);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
if (ybf->buffer_alloc == NULL)
|
|
|
|
return -1;
|
|
|
|
|
Increase chrow row alignment to 16 bytes.
This is done by expanding luma row to 32-byte alignment, since
there is currently a bunch of code that assumes that
uv_stride == y_stride/2 (see, for example, vp8/common/postproc.c,
common/reconinter.c, common/arm/neon/recon16x16mb_neon.asm,
encoder/temporal_filter.c, and possibly others; I haven't done a
full audit).
It also uses replaces the hardcoded border of 16 in a number of
encoder buffers with VP8BORDERINPIXELS (currently 32), as the
chroma rows start at an offset of border/2.
Together, these two changes have the nice advantage that simply
dumping the frame memory as a contiguous blob produces a valid,
if padded, image.
Change-Id: Iaf5ea722ae5c82d5daa50f6e2dade9de753f1003
2011-07-20 19:20:31 +02:00
|
|
|
ybf->y_buffer = ybf->buffer_alloc + (border * y_stride) + border;
|
|
|
|
ybf->u_buffer = ybf->buffer_alloc + yplane_size + (border / 2 * uv_stride) + border / 2;
|
|
|
|
ybf->v_buffer = ybf->buffer_alloc + yplane_size + uvplane_size + (border / 2 * uv_stride) + border / 2;
|
2010-12-16 16:46:31 +01:00
|
|
|
|
|
|
|
ybf->corrupted = 0; /* assume not currupted by errors */
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|