1ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang/* 2ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * Copyright (c) 2013 The WebM project authors. All Rights Reserved. 3ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * 4ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * Use of this source code is governed by a BSD-style license 5ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * that can be found in the LICENSE file in the root of the source 6ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * tree. An additional intellectual property rights grant can be found 7ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * in the file PATENTS. All contributing project authors may 8ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * be found in the AUTHORS file in the root of the source tree. 9ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang */ 10ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#ifndef VP9_VP9_IFACE_COMMON_H_ 11ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#define VP9_VP9_IFACE_COMMON_H_ 12ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 13ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangstatic void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12, 14ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang void *user_priv) { 15ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang /** vpx_img_wrap() doesn't allow specifying independent strides for 16ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * the Y, U, and V planes, nor other alignment adjustments that 17ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * might be representable by a YV12_BUFFER_CONFIG, so we just 18ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * initialize all the fields.*/ 19ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int bps = 12; 20ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (yv12->uv_height == yv12->y_height) { 21ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang if (yv12->uv_width == yv12->y_width) { 22ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->fmt = VPX_IMG_FMT_I444; 23ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang bps = 24; 24ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } else { 25ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->fmt = VPX_IMG_FMT_I422; 26ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang bps = 16; 27ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } 28ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } else { 29ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->fmt = VPX_IMG_FMT_I420; 30ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } 31ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->w = yv12->y_stride; 32b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3); 33ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->d_w = yv12->y_crop_width; 34ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->d_h = yv12->y_crop_height; 35ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->x_chroma_shift = yv12->uv_width < yv12->y_width; 36ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->y_chroma_shift = yv12->uv_height < yv12->y_height; 37ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->planes[VPX_PLANE_Y] = yv12->y_buffer; 38ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->planes[VPX_PLANE_U] = yv12->u_buffer; 39ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->planes[VPX_PLANE_V] = yv12->v_buffer; 40ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->planes[VPX_PLANE_ALPHA] = yv12->alpha_buffer; 41ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->stride[VPX_PLANE_Y] = yv12->y_stride; 42ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->stride[VPX_PLANE_U] = yv12->uv_stride; 43ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->stride[VPX_PLANE_V] = yv12->uv_stride; 44ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->stride[VPX_PLANE_ALPHA] = yv12->alpha_stride; 45ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->bps = bps; 46ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->user_priv = user_priv; 47ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->img_data = yv12->buffer_alloc; 48ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->img_data_owner = 0; 49ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang img->self_allocd = 0; 50ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} 51ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 52ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangstatic vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, 53ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang YV12_BUFFER_CONFIG *yv12) { 54ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->y_buffer = img->planes[VPX_PLANE_Y]; 55ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->u_buffer = img->planes[VPX_PLANE_U]; 56ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->v_buffer = img->planes[VPX_PLANE_V]; 57ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->alpha_buffer = img->planes[VPX_PLANE_ALPHA]; 58ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 59ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->y_crop_width = img->d_w; 60ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->y_crop_height = img->d_h; 61ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->y_width = img->d_w; 62ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->y_height = img->d_h; 63ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 64ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2 65ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang : yv12->y_width; 66ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 67ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang : yv12->y_height; 68ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 69ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->alpha_width = yv12->alpha_buffer ? img->d_w : 0; 70ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->alpha_height = yv12->alpha_buffer ? img->d_h : 0; 71ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 72ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->y_stride = img->stride[VPX_PLANE_Y]; 73ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->uv_stride = img->stride[VPX_PLANE_U]; 74ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->alpha_stride = yv12->alpha_buffer ? img->stride[VPX_PLANE_ALPHA] : 0; 75ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 76ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2; 77ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#if CONFIG_ALPHA 78b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian // For development purposes, force alpha to hold the same data as Y for now. 79ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->alpha_buffer = yv12->y_buffer; 80ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->alpha_width = yv12->y_width; 81ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->alpha_height = yv12->y_height; 82ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang yv12->alpha_stride = yv12->y_stride; 83ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#endif 84ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang return VPX_CODEC_OK; 85ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} 86ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 87ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#endif // VP9_VP9_IFACE_COMMON_H_ 88