OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #ifndef VP9_VP9_IFACE_COMMON_H_ | 10 #ifndef VP9_VP9_IFACE_COMMON_H_ |
11 #define VP9_VP9_IFACE_COMMON_H_ | 11 #define VP9_VP9_IFACE_COMMON_H_ |
12 | 12 |
13 static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12, | 13 static void yuvconfig2image(vpx_image_t *img, const YV12_BUFFER_CONFIG *yv12, |
14 void *user_priv) { | 14 void *user_priv) { |
15 /** vpx_img_wrap() doesn't allow specifying independent strides for | 15 /** vpx_img_wrap() doesn't allow specifying independent strides for |
16 * the Y, U, and V planes, nor other alignment adjustments that | 16 * the Y, U, and V planes, nor other alignment adjustments that |
17 * might be representable by a YV12_BUFFER_CONFIG, so we just | 17 * might be representable by a YV12_BUFFER_CONFIG, so we just |
18 * initialize all the fields.*/ | 18 * initialize all the fields.*/ |
19 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; | 19 int bps; |
22 if (!ss_y) { | 20 if (!yv12->subsampling_y) { |
23 if (!ss_x) { | 21 if (!yv12->subsampling_x) { |
24 img->fmt = VPX_IMG_FMT_I444; | 22 img->fmt = VPX_IMG_FMT_I444; |
25 bps = 24; | 23 bps = 24; |
26 } else { | 24 } else { |
27 img->fmt = VPX_IMG_FMT_I422; | 25 img->fmt = VPX_IMG_FMT_I422; |
28 bps = 16; | 26 bps = 16; |
29 } | 27 } |
30 } else { | 28 } else { |
31 img->fmt = VPX_IMG_FMT_I420; | 29 if (!yv12->subsampling_x) { |
32 bps = 12; | 30 img->fmt = VPX_IMG_FMT_I440; |
| 31 bps = 16; |
| 32 } else { |
| 33 img->fmt = VPX_IMG_FMT_I420; |
| 34 bps = 12; |
| 35 } |
33 } | 36 } |
34 img->bit_depth = 8; | 37 img->bit_depth = 8; |
35 img->w = yv12->y_stride; | 38 img->w = yv12->y_stride; |
36 img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3); | 39 img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * VP9_ENC_BORDER_IN_PIXELS, 3); |
37 img->d_w = yv12->y_crop_width; | 40 img->d_w = yv12->y_crop_width; |
38 img->d_h = yv12->y_crop_height; | 41 img->d_h = yv12->y_crop_height; |
39 img->x_chroma_shift = ss_x; | 42 img->x_chroma_shift = yv12->subsampling_x; |
40 img->y_chroma_shift = ss_y; | 43 img->y_chroma_shift = yv12->subsampling_y; |
41 img->planes[VPX_PLANE_Y] = yv12->y_buffer; | 44 img->planes[VPX_PLANE_Y] = yv12->y_buffer; |
42 img->planes[VPX_PLANE_U] = yv12->u_buffer; | 45 img->planes[VPX_PLANE_U] = yv12->u_buffer; |
43 img->planes[VPX_PLANE_V] = yv12->v_buffer; | 46 img->planes[VPX_PLANE_V] = yv12->v_buffer; |
44 img->planes[VPX_PLANE_ALPHA] = NULL; | 47 img->planes[VPX_PLANE_ALPHA] = NULL; |
45 img->stride[VPX_PLANE_Y] = yv12->y_stride; | 48 img->stride[VPX_PLANE_Y] = yv12->y_stride; |
46 img->stride[VPX_PLANE_U] = yv12->uv_stride; | 49 img->stride[VPX_PLANE_U] = yv12->uv_stride; |
47 img->stride[VPX_PLANE_V] = yv12->uv_stride; | 50 img->stride[VPX_PLANE_V] = yv12->uv_stride; |
48 img->stride[VPX_PLANE_ALPHA] = yv12->y_stride; | 51 img->stride[VPX_PLANE_ALPHA] = yv12->y_stride; |
| 52 #if CONFIG_VP9_HIGHBITDEPTH |
| 53 if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 54 // vpx_image_t uses byte strides and a pointer to the first byte |
| 55 // of the image. |
| 56 img->fmt |= VPX_IMG_FMT_HIGHBITDEPTH; |
| 57 img->bit_depth = yv12->bit_depth; |
| 58 img->planes[VPX_PLANE_Y] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->y_buffer); |
| 59 img->planes[VPX_PLANE_U] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->u_buffer); |
| 60 img->planes[VPX_PLANE_V] = (uint8_t*)CONVERT_TO_SHORTPTR(yv12->v_buffer); |
| 61 img->planes[VPX_PLANE_ALPHA] = NULL; |
| 62 img->stride[VPX_PLANE_Y] = 2 * yv12->y_stride; |
| 63 img->stride[VPX_PLANE_U] = 2 * yv12->uv_stride; |
| 64 img->stride[VPX_PLANE_V] = 2 * yv12->uv_stride; |
| 65 img->stride[VPX_PLANE_ALPHA] = 2 * yv12->y_stride; |
| 66 } |
| 67 #endif // CONFIG_VP9_HIGHBITDEPTH |
49 img->bps = bps; | 68 img->bps = bps; |
50 img->user_priv = user_priv; | 69 img->user_priv = user_priv; |
51 img->img_data = yv12->buffer_alloc; | 70 img->img_data = yv12->buffer_alloc; |
52 img->img_data_owner = 0; | 71 img->img_data_owner = 0; |
53 img->self_allocd = 0; | 72 img->self_allocd = 0; |
54 } | 73 } |
55 | 74 |
56 static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, | 75 static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img, |
57 YV12_BUFFER_CONFIG *yv12) { | 76 YV12_BUFFER_CONFIG *yv12) { |
58 yv12->y_buffer = img->planes[VPX_PLANE_Y]; | 77 yv12->y_buffer = img->planes[VPX_PLANE_Y]; |
59 yv12->u_buffer = img->planes[VPX_PLANE_U]; | 78 yv12->u_buffer = img->planes[VPX_PLANE_U]; |
60 yv12->v_buffer = img->planes[VPX_PLANE_V]; | 79 yv12->v_buffer = img->planes[VPX_PLANE_V]; |
61 | 80 |
62 yv12->y_crop_width = img->d_w; | 81 yv12->y_crop_width = img->d_w; |
63 yv12->y_crop_height = img->d_h; | 82 yv12->y_crop_height = img->d_h; |
64 yv12->y_width = img->d_w; | 83 yv12->y_width = img->d_w; |
65 yv12->y_height = img->d_h; | 84 yv12->y_height = img->d_h; |
66 | 85 |
67 yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2 | 86 yv12->uv_width = img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2 |
68 : yv12->y_width; | 87 : yv12->y_width; |
69 yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 | 88 yv12->uv_height = img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 |
70 : yv12->y_height; | 89 : yv12->y_height; |
| 90 yv12->uv_crop_width = yv12->uv_width; |
| 91 yv12->uv_crop_height = yv12->uv_height; |
71 | 92 |
72 yv12->y_stride = img->stride[VPX_PLANE_Y]; | 93 yv12->y_stride = img->stride[VPX_PLANE_Y]; |
73 yv12->uv_stride = img->stride[VPX_PLANE_U]; | 94 yv12->uv_stride = img->stride[VPX_PLANE_U]; |
74 | 95 |
| 96 #if CONFIG_VP9_HIGHBITDEPTH |
| 97 if (img->fmt & VPX_IMG_FMT_HIGHBITDEPTH) { |
| 98 // In vpx_image_t |
| 99 // planes point to uint8 address of start of data |
| 100 // stride counts uint8s to reach next row |
| 101 // In YV12_BUFFER_CONFIG |
| 102 // y_buffer, u_buffer, v_buffer point to uint16 address of data |
| 103 // stride and border counts in uint16s |
| 104 // This means that all the address calculations in the main body of code |
| 105 // should work correctly. |
| 106 // However, before we do any pixel operations we need to cast the address |
| 107 // to a uint16 ponter and double its value. |
| 108 yv12->y_buffer = CONVERT_TO_BYTEPTR(yv12->y_buffer); |
| 109 yv12->u_buffer = CONVERT_TO_BYTEPTR(yv12->u_buffer); |
| 110 yv12->v_buffer = CONVERT_TO_BYTEPTR(yv12->v_buffer); |
| 111 yv12->y_stride >>= 1; |
| 112 yv12->uv_stride >>= 1; |
| 113 yv12->flags = YV12_FLAG_HIGHBITDEPTH; |
| 114 } else { |
| 115 yv12->flags = 0; |
| 116 } |
| 117 yv12->border = (yv12->y_stride - img->w) / 2; |
| 118 #else |
75 yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2; | 119 yv12->border = (img->stride[VPX_PLANE_Y] - img->w) / 2; |
| 120 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 121 yv12->subsampling_x = img->x_chroma_shift; |
| 122 yv12->subsampling_y = img->y_chroma_shift; |
76 return VPX_CODEC_OK; | 123 return VPX_CODEC_OK; |
77 } | 124 } |
78 | 125 |
79 #endif // VP9_VP9_IFACE_COMMON_H_ | 126 #endif // VP9_VP9_IFACE_COMMON_H_ |
OLD | NEW |