blob: d60883cc25dd4126f06335ea29c21d1590ac0bc8 [file] [log] [blame]
John Koleszarb3c350a2013-03-13 12:15:43 -07001/*
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
Dmitry Kovalev50e54c12013-04-01 18:23:04 -070013static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12,
14 void *user_priv) {
John Koleszarb3c350a2013-03-13 12:15:43 -070015 /** 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.*/
Dmitry Kovalev49d8bdc2014-04-29 16:12:44 -070019 const int ss_x = yv12->uv_crop_width < yv12->y_crop_width;
20 const int ss_y = yv12->uv_crop_height < yv12->y_crop_height;
21 int bps;
22 if (!ss_y) {
23 if (!ss_x) {
John Koleszarda584362013-05-06 15:52:06 -070024 img->fmt = VPX_IMG_FMT_I444;
25 bps = 24;
26 } else {
27 img->fmt = VPX_IMG_FMT_I422;
28 bps = 16;
29 }
30 } else {
31 img->fmt = VPX_IMG_FMT_I420;
Dmitry Kovalev49d8bdc2014-04-29 16:12:44 -070032 bps = 12;
John Koleszarda584362013-05-06 15:52:06 -070033 }
John Koleszarb3c350a2013-03-13 12:15:43 -070034 img->w = yv12->y_stride;
hkuang437004c2014-01-10 13:10:39 -080035 img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3);
John Koleszarda584362013-05-06 15:52:06 -070036 img->d_w = yv12->y_crop_width;
37 img->d_h = yv12->y_crop_height;
Dmitry Kovalev49d8bdc2014-04-29 16:12:44 -070038 img->x_chroma_shift = ss_x;
39 img->y_chroma_shift = ss_y;
John Koleszarb3c350a2013-03-13 12:15:43 -070040 img->planes[VPX_PLANE_Y] = yv12->y_buffer;
41 img->planes[VPX_PLANE_U] = yv12->u_buffer;
42 img->planes[VPX_PLANE_V] = yv12->v_buffer;
Dmitry Kovalevb7a4f8a2013-05-15 16:29:20 -070043 img->planes[VPX_PLANE_ALPHA] = yv12->alpha_buffer;
John Koleszarb3c350a2013-03-13 12:15:43 -070044 img->stride[VPX_PLANE_Y] = yv12->y_stride;
45 img->stride[VPX_PLANE_U] = yv12->uv_stride;
46 img->stride[VPX_PLANE_V] = yv12->uv_stride;
Dmitry Kovalevb7a4f8a2013-05-15 16:29:20 -070047 img->stride[VPX_PLANE_ALPHA] = yv12->alpha_stride;
John Koleszarda584362013-05-06 15:52:06 -070048 img->bps = bps;
John Koleszarb3c350a2013-03-13 12:15:43 -070049 img->user_priv = user_priv;
50 img->img_data = yv12->buffer_alloc;
51 img->img_data_owner = 0;
52 img->self_allocd = 0;
53}
54
Dmitry Kovalevb7a4f8a2013-05-15 16:29:20 -070055static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
56 YV12_BUFFER_CONFIG *yv12) {
57 yv12->y_buffer = img->planes[VPX_PLANE_Y];
58 yv12->u_buffer = img->planes[VPX_PLANE_U];
59 yv12->v_buffer = img->planes[VPX_PLANE_V];
60 yv12->alpha_buffer = img->planes[VPX_PLANE_ALPHA];
61
62 yv12->y_crop_width = img->d_w;
63 yv12->y_crop_height = img->d_h;
64 yv12->y_width = img->d_w;
65 yv12->y_height = img->d_h;
66
67 yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2
68 : yv12->y_width;
69 yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2
70 : yv12->y_height;
71
72 yv12->alpha_width = yv12->alpha_buffer ? img->d_w : 0;
73 yv12->alpha_height = yv12->alpha_buffer ? img->d_h : 0;
74
75 yv12->y_stride = img->stride[VPX_PLANE_Y];
76 yv12->uv_stride = img->stride[VPX_PLANE_U];
77 yv12->alpha_stride = yv12->alpha_buffer ? img->stride[VPX_PLANE_ALPHA] : 0;
78
79 yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2;
John Koleszar679e4ab2013-05-15 17:55:08 -070080#if CONFIG_ALPHA
Adrian Grange82f6af62014-01-22 09:36:07 -080081 // For development purposes, force alpha to hold the same data as Y for now.
John Koleszar679e4ab2013-05-15 17:55:08 -070082 yv12->alpha_buffer = yv12->y_buffer;
83 yv12->alpha_width = yv12->y_width;
84 yv12->alpha_height = yv12->y_height;
85 yv12->alpha_stride = yv12->y_stride;
86#endif
Dmitry Kovalevb7a4f8a2013-05-15 16:29:20 -070087 return VPX_CODEC_OK;
88}
89
Dmitry Kovalev50e54c12013-04-01 18:23:04 -070090#endif // VP9_VP9_IFACE_COMMON_H_