2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
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.
10 #ifndef VP10_VP10_IFACE_COMMON_H_
11 #define VP10_VP10_IFACE_COMMON_H_
13 #include "vpx_ports/mem.h"
15 static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12,
17 /** vpx_img_wrap() doesn't allow specifying independent strides for
18 * the Y, U, and V planes, nor other alignment adjustments that
19 * might be representable by a YV12_BUFFER_CONFIG, so we just
20 * initialize all the fields.*/
22 if (!yv12->subsampling_y) {
23 if (!yv12->subsampling_x) {
24 img->fmt = VPX_IMG_FMT_I444;
27 img->fmt = VPX_IMG_FMT_I422;
31 if (!yv12->subsampling_x) {
32 img->fmt = VPX_IMG_FMT_I440;
35 img->fmt = VPX_IMG_FMT_I420;
39 img->cs = yv12->color_space;
41 img->w = yv12->y_stride;
42 img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3);
43 img->d_w = yv12->y_crop_width;
44 img->d_h = yv12->y_crop_height;
45 img->x_chroma_shift = yv12->subsampling_x;
46 img->y_chroma_shift = yv12->subsampling_y;
47 img->planes[VPX_PLANE_Y] = yv12->y_buffer;
48 img->planes[VPX_PLANE_U] = yv12->u_buffer;
49 img->planes[VPX_PLANE_V] = yv12->v_buffer;
50 img->planes[VPX_PLANE_ALPHA] = NULL;
51 img->stride[VPX_PLANE_Y] = yv12->y_stride;
52 img->stride[VPX_PLANE_U] = yv12->uv_stride;
53 img->stride[VPX_PLANE_V] = yv12->uv_stride;
54 img->stride[VPX_PLANE_ALPHA] = yv12->y_stride;
55 #if CONFIG_VP9_HIGHBITDEPTH
56 if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) {
57 // vpx_image_t uses byte strides and a pointer to the first byte
59 img->fmt |= VPX_IMG_FMT_HIGHBITDEPTH;
60 img->bit_depth = yv12->bit_depth;
61 img->planes[VPX_PLANE_Y] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->y_buffer);
62 img->planes[VPX_PLANE_U] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->u_buffer);
63 img->planes[VPX_PLANE_V] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->v_buffer);
64 img->planes[VPX_PLANE_ALPHA] = NULL;
65 img->stride[VPX_PLANE_Y] = 2 * yv12->y_stride;
66 img->stride[VPX_PLANE_U] = 2 * yv12->uv_stride;
67 img->stride[VPX_PLANE_V] = 2 * yv12->uv_stride;
68 img->stride[VPX_PLANE_ALPHA] = 2 * yv12->y_stride;
70 #endif // CONFIG_VP9_HIGHBITDEPTH
72 img->user_priv = user_priv;
73 img->img_data = yv12->buffer_alloc;
74 img->img_data_owner = 0;
78 static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
79 YV12_BUFFER_CONFIG *yv12) {
80 yv12->y_buffer = img->planes[VPX_PLANE_Y];
81 yv12->u_buffer = img->planes[VPX_PLANE_U];
82 yv12->v_buffer = img->planes[VPX_PLANE_V];
84 yv12->y_crop_width = img->d_w;
85 yv12->y_crop_height = img->d_h;
86 yv12->y_width = img->d_w;
87 yv12->y_height = img->d_h;
89 yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2
91 yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2
93 yv12->uv_crop_width = yv12->uv_width;
94 yv12->uv_crop_height = yv12->uv_height;
96 yv12->y_stride = img->stride[VPX_PLANE_Y];
97 yv12->uv_stride = img->stride[VPX_PLANE_U];
98 yv12->color_space = img->cs;
100 #if CONFIG_VP9_HIGHBITDEPTH
101 if (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) {
103 // planes point to uint8 address of start of data
104 // stride counts uint8s to reach next row
105 // In YV12_BUFFER_CONFIG
106 // y_buffer, u_buffer, v_buffer point to uint16 address of data
107 // stride and border counts in uint16s
108 // This means that all the address calculations in the main body of code
109 // should work correctly.
110 // However, before we do any pixel operations we need to cast the address
111 // to a uint16 ponter and double its value.
112 yv12->y_buffer = CONVERT_TO_BYTEPTR(yv12->y_buffer);
113 yv12->u_buffer = CONVERT_TO_BYTEPTR(yv12->u_buffer);
114 yv12->v_buffer = CONVERT_TO_BYTEPTR(yv12->v_buffer);
115 yv12->y_stride >>= 1;
116 yv12->uv_stride >>= 1;
117 yv12->flags = YV12_FLAG_HIGHBITDEPTH;
121 yv12->border = (yv12->y_stride - img->w) / 2;
123 yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2;
124 #endif // CONFIG_VP9_HIGHBITDEPTH
125 yv12->subsampling_x = img->x_chroma_shift;
126 yv12->subsampling_y = img->y_chroma_shift;
130 #endif // VP10_VP10_IFACE_COMMON_H_