michael@0: /* michael@0: * Copyright (c) 2013 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: #ifndef VP9_VP9_IFACE_COMMON_H_ michael@0: #define VP9_VP9_IFACE_COMMON_H_ michael@0: michael@0: static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12, michael@0: void *user_priv) { michael@0: /** vpx_img_wrap() doesn't allow specifying independent strides for michael@0: * the Y, U, and V planes, nor other alignment adjustments that michael@0: * might be representable by a YV12_BUFFER_CONFIG, so we just michael@0: * initialize all the fields.*/ michael@0: int bps = 12; michael@0: if (yv12->uv_height == yv12->y_height) { michael@0: if (yv12->uv_width == yv12->y_width) { michael@0: img->fmt = VPX_IMG_FMT_I444; michael@0: bps = 24; michael@0: } else { michael@0: img->fmt = VPX_IMG_FMT_I422; michael@0: bps = 16; michael@0: } michael@0: } else { michael@0: img->fmt = VPX_IMG_FMT_I420; michael@0: } michael@0: img->w = yv12->y_stride; michael@0: img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9BORDERINPIXELS, 3); michael@0: img->d_w = yv12->y_crop_width; michael@0: img->d_h = yv12->y_crop_height; michael@0: img->x_chroma_shift = yv12->uv_width < yv12->y_width; michael@0: img->y_chroma_shift = yv12->uv_height < yv12->y_height; michael@0: img->planes[VPX_PLANE_Y] = yv12->y_buffer; michael@0: img->planes[VPX_PLANE_U] = yv12->u_buffer; michael@0: img->planes[VPX_PLANE_V] = yv12->v_buffer; michael@0: img->planes[VPX_PLANE_ALPHA] = yv12->alpha_buffer; michael@0: img->stride[VPX_PLANE_Y] = yv12->y_stride; michael@0: img->stride[VPX_PLANE_U] = yv12->uv_stride; michael@0: img->stride[VPX_PLANE_V] = yv12->uv_stride; michael@0: img->stride[VPX_PLANE_ALPHA] = yv12->alpha_stride; michael@0: img->bps = bps; michael@0: img->user_priv = user_priv; michael@0: img->img_data = yv12->buffer_alloc; michael@0: img->img_data_owner = 0; michael@0: img->self_allocd = 0; michael@0: } michael@0: michael@0: static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, michael@0: YV12_BUFFER_CONFIG *yv12) { michael@0: yv12->y_buffer = img->planes[VPX_PLANE_Y]; michael@0: yv12->u_buffer = img->planes[VPX_PLANE_U]; michael@0: yv12->v_buffer = img->planes[VPX_PLANE_V]; michael@0: yv12->alpha_buffer = img->planes[VPX_PLANE_ALPHA]; michael@0: michael@0: yv12->y_crop_width = img->d_w; michael@0: yv12->y_crop_height = img->d_h; michael@0: yv12->y_width = img->d_w; michael@0: yv12->y_height = img->d_h; michael@0: michael@0: yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2 michael@0: : yv12->y_width; michael@0: yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 michael@0: : yv12->y_height; michael@0: michael@0: yv12->alpha_width = yv12->alpha_buffer ? img->d_w : 0; michael@0: yv12->alpha_height = yv12->alpha_buffer ? img->d_h : 0; michael@0: michael@0: yv12->y_stride = img->stride[VPX_PLANE_Y]; michael@0: yv12->uv_stride = img->stride[VPX_PLANE_U]; michael@0: yv12->alpha_stride = yv12->alpha_buffer ? img->stride[VPX_PLANE_ALPHA] : 0; michael@0: michael@0: yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2; michael@0: #if CONFIG_ALPHA michael@0: // For development purposes, force alpha to hold the same data a Y for now. michael@0: yv12->alpha_buffer = yv12->y_buffer; michael@0: yv12->alpha_width = yv12->y_width; michael@0: yv12->alpha_height = yv12->y_height; michael@0: yv12->alpha_stride = yv12->y_stride; michael@0: #endif michael@0: return VPX_CODEC_OK; michael@0: } michael@0: michael@0: #endif // VP9_VP9_IFACE_COMMON_H_