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