Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 10 | */ |
| 11 | #ifndef AV1_AV1_IFACE_COMMON_H_ |
| 12 | #define AV1_AV1_IFACE_COMMON_H_ |
| 13 | |
| 14 | #include "aom_ports/mem.h" |
| 15 | |
| 16 | static void yuvconfig2image(aom_image_t *img, const YV12_BUFFER_CONFIG *yv12, |
| 17 | void *user_priv) { |
| 18 | /** aom_img_wrap() doesn't allow specifying independent strides for |
| 19 | * the Y, U, and V planes, nor other alignment adjustments that |
| 20 | * might be representable by a YV12_BUFFER_CONFIG, so we just |
| 21 | * initialize all the fields.*/ |
| 22 | int bps; |
| 23 | if (!yv12->subsampling_y) { |
| 24 | if (!yv12->subsampling_x) { |
| 25 | img->fmt = AOM_IMG_FMT_I444; |
| 26 | bps = 24; |
| 27 | } else { |
| 28 | img->fmt = AOM_IMG_FMT_I422; |
| 29 | bps = 16; |
| 30 | } |
| 31 | } else { |
| 32 | if (!yv12->subsampling_x) { |
| 33 | img->fmt = AOM_IMG_FMT_I440; |
| 34 | bps = 16; |
| 35 | } else { |
| 36 | img->fmt = AOM_IMG_FMT_I420; |
| 37 | bps = 12; |
| 38 | } |
| 39 | } |
| 40 | img->cs = yv12->color_space; |
| 41 | img->range = yv12->color_range; |
| 42 | img->bit_depth = 8; |
| 43 | img->w = yv12->y_stride; |
Yaowu Xu | 671f2bd | 2016-09-30 15:07:57 -0700 | [diff] [blame] | 44 | img->h = ALIGN_POWER_OF_TWO(yv12->y_height + 2 * AOM_BORDER_IN_PIXELS, 3); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | img->d_w = yv12->y_crop_width; |
| 46 | img->d_h = yv12->y_crop_height; |
| 47 | img->r_w = yv12->render_width; |
| 48 | img->r_h = yv12->render_height; |
| 49 | img->x_chroma_shift = yv12->subsampling_x; |
| 50 | img->y_chroma_shift = yv12->subsampling_y; |
| 51 | img->planes[AOM_PLANE_Y] = yv12->y_buffer; |
| 52 | img->planes[AOM_PLANE_U] = yv12->u_buffer; |
| 53 | img->planes[AOM_PLANE_V] = yv12->v_buffer; |
| 54 | img->planes[AOM_PLANE_ALPHA] = NULL; |
| 55 | img->stride[AOM_PLANE_Y] = yv12->y_stride; |
| 56 | img->stride[AOM_PLANE_U] = yv12->uv_stride; |
| 57 | img->stride[AOM_PLANE_V] = yv12->uv_stride; |
| 58 | img->stride[AOM_PLANE_ALPHA] = yv12->y_stride; |
| 59 | #if CONFIG_AOM_HIGHBITDEPTH |
| 60 | if (yv12->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 61 | // aom_image_t uses byte strides and a pointer to the first byte |
| 62 | // of the image. |
| 63 | img->fmt = (aom_img_fmt_t)(img->fmt | AOM_IMG_FMT_HIGHBITDEPTH); |
| 64 | img->bit_depth = yv12->bit_depth; |
| 65 | img->planes[AOM_PLANE_Y] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->y_buffer); |
| 66 | img->planes[AOM_PLANE_U] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->u_buffer); |
| 67 | img->planes[AOM_PLANE_V] = (uint8_t *)CONVERT_TO_SHORTPTR(yv12->v_buffer); |
| 68 | img->planes[AOM_PLANE_ALPHA] = NULL; |
| 69 | img->stride[AOM_PLANE_Y] = 2 * yv12->y_stride; |
| 70 | img->stride[AOM_PLANE_U] = 2 * yv12->uv_stride; |
| 71 | img->stride[AOM_PLANE_V] = 2 * yv12->uv_stride; |
| 72 | img->stride[AOM_PLANE_ALPHA] = 2 * yv12->y_stride; |
| 73 | } |
| 74 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 75 | img->bps = bps; |
| 76 | img->user_priv = user_priv; |
| 77 | img->img_data = yv12->buffer_alloc; |
| 78 | img->img_data_owner = 0; |
| 79 | img->self_allocd = 0; |
| 80 | } |
| 81 | |
| 82 | static aom_codec_err_t image2yuvconfig(const aom_image_t *img, |
| 83 | YV12_BUFFER_CONFIG *yv12) { |
| 84 | yv12->y_buffer = img->planes[AOM_PLANE_Y]; |
| 85 | yv12->u_buffer = img->planes[AOM_PLANE_U]; |
| 86 | yv12->v_buffer = img->planes[AOM_PLANE_V]; |
| 87 | |
| 88 | yv12->y_crop_width = img->d_w; |
| 89 | yv12->y_crop_height = img->d_h; |
| 90 | yv12->render_width = img->r_w; |
| 91 | yv12->render_height = img->r_h; |
| 92 | yv12->y_width = img->d_w; |
| 93 | yv12->y_height = img->d_h; |
| 94 | |
| 95 | yv12->uv_width = |
| 96 | img->x_chroma_shift == 1 ? (1 + yv12->y_width) / 2 : yv12->y_width; |
| 97 | yv12->uv_height = |
| 98 | img->y_chroma_shift == 1 ? (1 + yv12->y_height) / 2 : yv12->y_height; |
| 99 | yv12->uv_crop_width = yv12->uv_width; |
| 100 | yv12->uv_crop_height = yv12->uv_height; |
| 101 | |
| 102 | yv12->y_stride = img->stride[AOM_PLANE_Y]; |
| 103 | yv12->uv_stride = img->stride[AOM_PLANE_U]; |
| 104 | yv12->color_space = img->cs; |
| 105 | yv12->color_range = img->range; |
| 106 | |
| 107 | #if CONFIG_AOM_HIGHBITDEPTH |
| 108 | if (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) { |
| 109 | // In aom_image_t |
| 110 | // planes point to uint8 address of start of data |
| 111 | // stride counts uint8s to reach next row |
| 112 | // In YV12_BUFFER_CONFIG |
| 113 | // y_buffer, u_buffer, v_buffer point to uint16 address of data |
| 114 | // stride and border counts in uint16s |
| 115 | // This means that all the address calculations in the main body of code |
| 116 | // should work correctly. |
| 117 | // However, before we do any pixel operations we need to cast the address |
| 118 | // to a uint16 ponter and double its value. |
| 119 | yv12->y_buffer = CONVERT_TO_BYTEPTR(yv12->y_buffer); |
| 120 | yv12->u_buffer = CONVERT_TO_BYTEPTR(yv12->u_buffer); |
| 121 | yv12->v_buffer = CONVERT_TO_BYTEPTR(yv12->v_buffer); |
| 122 | yv12->y_stride >>= 1; |
| 123 | yv12->uv_stride >>= 1; |
| 124 | yv12->flags = YV12_FLAG_HIGHBITDEPTH; |
| 125 | } else { |
| 126 | yv12->flags = 0; |
| 127 | } |
| 128 | yv12->border = (yv12->y_stride - img->w) / 2; |
| 129 | #else |
| 130 | yv12->border = (img->stride[AOM_PLANE_Y] - img->w) / 2; |
| 131 | #endif // CONFIG_AOM_HIGHBITDEPTH |
| 132 | yv12->subsampling_x = img->x_chroma_shift; |
| 133 | yv12->subsampling_y = img->y_chroma_shift; |
| 134 | return AOM_CODEC_OK; |
| 135 | } |
| 136 | |
| 137 | static AOM_REFFRAME ref_frame_to_av1_reframe(aom_ref_frame_type_t frame) { |
| 138 | switch (frame) { |
| 139 | case AOM_LAST_FRAME: return AOM_LAST_FLAG; |
| 140 | case AOM_GOLD_FRAME: return AOM_GOLD_FLAG; |
| 141 | case AOM_ALTR_FRAME: return AOM_ALT_FLAG; |
| 142 | } |
| 143 | assert(0 && "Invalid Reference Frame"); |
| 144 | return AOM_LAST_FLAG; |
| 145 | } |
| 146 | #endif // AV1_AV1_IFACE_COMMON_H_ |