/* * Copyright (c) 2016, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
static aom_image_t *img_alloc_helper(
aom_image_t *img, aom_img_fmt_t fmt, unsignedint d_w, unsignedint d_h, unsignedint buf_align, unsignedint stride_align, unsignedint size_align, unsignedint border, unsignedchar *img_data,
aom_alloc_img_data_cb_fn_t alloc_cb, void *cb_priv) { /* NOTE: In this function, bit_depth is either 8 or 16 (if * AOM_IMG_FMT_HIGHBITDEPTH is set), never 10 or 12.
*/ unsignedint xcs, ycs, bps, bit_depth;
if (img != NULL) memset(img, 0, sizeof(aom_image_t));
if (fmt == AOM_IMG_FMT_NONE) goto fail;
/* Impose maximum values on input parameters so that this function can * perform arithmetic operations without worrying about overflows.
*/ if (d_w > 0x08000000 || d_h > 0x08000000 || buf_align > 65536 ||
stride_align > 65536 || size_align > 65536 || border > 65536) { goto fail;
}
/* Treat align==0 like align==1 */ if (!buf_align) buf_align = 1;
/* Validate alignment (must be power of 2) */ if (buf_align & (buf_align - 1)) goto fail;
/* Treat align==0 like align==1 */ if (!stride_align) stride_align = 1;
/* Validate alignment (must be power of 2) */ if (stride_align & (stride_align - 1)) goto fail;
/* Treat align==0 like align==1 */ if (!size_align) size_align = 1;
/* Validate alignment (must be power of 2) */ if (size_align & (size_align - 1)) goto fail;
/* Get sample size for this format */ switch (fmt) { case AOM_IMG_FMT_I420: case AOM_IMG_FMT_YV12: case AOM_IMG_FMT_NV12: case AOM_IMG_FMT_AOMI420: case AOM_IMG_FMT_AOMYV12: bps = 12; break; case AOM_IMG_FMT_I422: bps = 16; break; case AOM_IMG_FMT_I444: bps = 24; break; case AOM_IMG_FMT_YV1216: case AOM_IMG_FMT_I42016: bps = 24; break; case AOM_IMG_FMT_I42216: bps = 32; break; case AOM_IMG_FMT_I44416: bps = 48; break; default: bps = 16; break;
}
/* Get chroma shift values for this format */ switch (fmt) { case AOM_IMG_FMT_I420: case AOM_IMG_FMT_YV12: case AOM_IMG_FMT_NV12: case AOM_IMG_FMT_AOMI420: case AOM_IMG_FMT_AOMYV12: case AOM_IMG_FMT_I422: case AOM_IMG_FMT_I42016: case AOM_IMG_FMT_YV1216: case AOM_IMG_FMT_I42216: xcs = 1; break; default: xcs = 0; break;
}
switch (fmt) { case AOM_IMG_FMT_I420: case AOM_IMG_FMT_YV12: case AOM_IMG_FMT_NV12: case AOM_IMG_FMT_AOMI420: case AOM_IMG_FMT_AOMYV12: case AOM_IMG_FMT_YV1216: case AOM_IMG_FMT_I42016: ycs = 1; break; default: ycs = 0; break;
}
/* Calculate storage sizes given the chroma subsampling */ constunsignedint w = align_image_dimension(d_w, xcs, size_align);
assert(d_w <= w); constunsignedint h = align_image_dimension(d_h, ycs, size_align);
assert(d_h <= h);
uint64_t s = (uint64_t)w + 2 * border;
s = (fmt & AOM_IMG_FMT_PLANAR) ? s : s * bps / bit_depth;
s = s * bit_depth / 8;
s = (s + stride_align - 1) & ~((uint64_t)stride_align - 1); if (s > INT_MAX) goto fail; constint stride_in_bytes = (int)s;
/* Allocate the new image */ if (!img) {
img = (aom_image_t *)calloc(1, sizeof(aom_image_t));
if (fmt == AOM_IMG_FMT_NV12) { // Each row is a row of U and a row of V interleaved, so the stride is twice // as long.
img->stride[AOM_PLANE_U] *= 2;
img->stride[AOM_PLANE_V] = 0;
}
/* Default viewport to entire image. (This aom_img_set_rect call always
* succeeds.) */ int ret = aom_img_set_rect(img, 0, 0, d_w, d_h, border);
assert(ret == 0);
(void)ret; return img;
int aom_img_set_rect(aom_image_t *img, unsignedint x, unsignedint y, unsignedint w, unsignedint h, unsignedint border) { if (x <= UINT_MAX - w && x + w <= img->w && y <= UINT_MAX - h &&
y + h <= img->h) {
img->d_w = w;
img->d_h = h;
img->planes[AOM_PLANE_Y] =
data + x * bytes_per_sample + y * img->stride[AOM_PLANE_Y];
data += ((size_t)img->h + 2 * border) * img->stride[AOM_PLANE_Y];
void aom_img_flip(aom_image_t *img) { /* Note: In the calculation pointer adjustment calculation, we want the * rhs to be promoted to a signed type. Section 6.3.1.8 of the ISO C99 * standard indicates that if the adjustment parameter is unsigned, the * stride parameter will be promoted to unsigned, causing errors when * the lhs is a larger type than the rhs.
*/
img->planes[AOM_PLANE_Y] += (signed)(img->d_h - 1) * img->stride[AOM_PLANE_Y];
img->stride[AOM_PLANE_Y] = -img->stride[AOM_PLANE_Y];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.