John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [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 |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [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. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | f42d52e | 2011-02-16 17:54:49 -0800 | [diff] [blame] | 12 | /*!\file |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 13 | * \brief Describes the aom image descriptor and associated operations |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 14 | * |
| 15 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #ifndef AOM_AOM_IMAGE_H_ |
| 17 | #define AOM_AOM_IMAGE_H_ |
James Zern | ec7f213 | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 18 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 23 | /*!\brief Current ABI version number |
| 24 | * |
| 25 | * \internal |
| 26 | * If this file is altered in any way that changes the ABI, this value |
| 27 | * must be bumped. Examples include, but are not limited to, changing |
| 28 | * types, removing or reassigning enums, adding/removing/rearranging |
| 29 | * fields to structures |
| 30 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 31 | #define AOM_IMAGE_ABI_VERSION (4) /**<\hideinitializer*/ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 32 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 33 | #define AOM_IMG_FMT_PLANAR 0x100 /**< Image is a planar format. */ |
| 34 | #define AOM_IMG_FMT_UV_FLIP 0x200 /**< V plane precedes U in memory. */ |
| 35 | #define AOM_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel. */ |
| 36 | #define AOM_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 37 | |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 38 | #include "./aom_config.h" |
| 39 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 40 | /*!\brief List of supported image formats */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 41 | typedef enum aom_img_fmt { |
| 42 | AOM_IMG_FMT_NONE, |
| 43 | AOM_IMG_FMT_RGB24, /**< 24 bit per pixel packed RGB */ |
| 44 | AOM_IMG_FMT_RGB32, /**< 32 bit per pixel packed 0RGB */ |
| 45 | AOM_IMG_FMT_RGB565, /**< 16 bit per pixel, 565 */ |
| 46 | AOM_IMG_FMT_RGB555, /**< 16 bit per pixel, 555 */ |
| 47 | AOM_IMG_FMT_UYVY, /**< UYVY packed YUV */ |
| 48 | AOM_IMG_FMT_YUY2, /**< YUYV packed YUV */ |
| 49 | AOM_IMG_FMT_YVYU, /**< YVYU packed YUV */ |
| 50 | AOM_IMG_FMT_BGR24, /**< 24 bit per pixel packed BGR */ |
| 51 | AOM_IMG_FMT_RGB32_LE, /**< 32 bit packed BGR0 */ |
| 52 | AOM_IMG_FMT_ARGB, /**< 32 bit packed ARGB, alpha=255 */ |
| 53 | AOM_IMG_FMT_ARGB_LE, /**< 32 bit packed BGRA, alpha=255 */ |
| 54 | AOM_IMG_FMT_RGB565_LE, /**< 16 bit per pixel, gggbbbbb rrrrrggg */ |
| 55 | AOM_IMG_FMT_RGB555_LE, /**< 16 bit per pixel, gggbbbbb 0rrrrrgg */ |
| 56 | AOM_IMG_FMT_YV12 = |
| 57 | AOM_IMG_FMT_PLANAR | AOM_IMG_FMT_UV_FLIP | 1, /**< planar YVU */ |
| 58 | AOM_IMG_FMT_I420 = AOM_IMG_FMT_PLANAR | 2, |
| 59 | AOM_IMG_FMT_AOMYV12 = AOM_IMG_FMT_PLANAR | AOM_IMG_FMT_UV_FLIP | |
| 60 | 3, /** < planar 4:2:0 format with aom color space */ |
| 61 | AOM_IMG_FMT_AOMI420 = AOM_IMG_FMT_PLANAR | 4, |
| 62 | AOM_IMG_FMT_I422 = AOM_IMG_FMT_PLANAR | 5, |
| 63 | AOM_IMG_FMT_I444 = AOM_IMG_FMT_PLANAR | 6, |
| 64 | AOM_IMG_FMT_I440 = AOM_IMG_FMT_PLANAR | 7, |
| 65 | AOM_IMG_FMT_444A = AOM_IMG_FMT_PLANAR | AOM_IMG_FMT_HAS_ALPHA | 6, |
| 66 | AOM_IMG_FMT_I42016 = AOM_IMG_FMT_I420 | AOM_IMG_FMT_HIGHBITDEPTH, |
| 67 | AOM_IMG_FMT_I42216 = AOM_IMG_FMT_I422 | AOM_IMG_FMT_HIGHBITDEPTH, |
| 68 | AOM_IMG_FMT_I44416 = AOM_IMG_FMT_I444 | AOM_IMG_FMT_HIGHBITDEPTH, |
| 69 | AOM_IMG_FMT_I44016 = AOM_IMG_FMT_I440 | AOM_IMG_FMT_HIGHBITDEPTH |
| 70 | } aom_img_fmt_t; /**< alias for enum aom_img_fmt */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 71 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 72 | /*!\brief List of supported color spaces */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | typedef enum aom_color_space { |
| 74 | AOM_CS_UNKNOWN = 0, /**< Unknown */ |
| 75 | AOM_CS_BT_601 = 1, /**< BT.601 */ |
| 76 | AOM_CS_BT_709 = 2, /**< BT.709 */ |
| 77 | AOM_CS_SMPTE_170 = 3, /**< SMPTE.170 */ |
| 78 | AOM_CS_SMPTE_240 = 4, /**< SMPTE.240 */ |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 79 | #if CONFIG_COLORSPACE_HEADERS |
| 80 | AOM_CS_BT_2020_NCL = 5, /**< BT.2020 non-constant luminance (BT.2100) */ |
| 81 | AOM_CS_BT_2020_CL = 6, /**< BT.2020 constant luminance */ |
| 82 | AOM_CS_SRGB = 7, /**< sRGB */ |
| 83 | AOM_CS_ICTCP = 8, /**< ICtCp, ITU-R BT.2100 */ |
| 84 | AOM_CS_RESERVED = 9 /**< Values 9..31 are reserved */ |
| 85 | #else |
| 86 | AOM_CS_BT_2020 = 5, /**< BT.2020 */ |
| 87 | AOM_CS_RESERVED = 6, /**< Reserved */ |
| 88 | AOM_CS_SRGB = 7 /**< sRGB */ |
| 89 | #endif |
| 90 | } aom_color_space_t; /**< alias for enum aom_color_space */ |
| 91 | |
| 92 | #if CONFIG_COLORSPACE_HEADERS |
| 93 | typedef enum aom_transfer_function { |
| 94 | AOM_TF_UNKNOWN = 0, /**< Unknown */ |
| 95 | AOM_TF_BT_709 = 1, /**< BT.709 */ |
| 96 | AOM_TF_PQ = 2, /**< PQ TF BT.2100 / ST.2084 */ |
| 97 | AOM_TF_HLG = 3, /**< Hybrid Log-Gamma */ |
| 98 | AOM_TF_RESERVED = 4 /**< Values 4..31 are reserved */ |
| 99 | } aom_transfer_function_t; /**< alias for enum aom_transfer_function */ |
| 100 | #endif |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 101 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 102 | /*!\brief List of supported color range */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 103 | typedef enum aom_color_range { |
| 104 | AOM_CR_STUDIO_RANGE = 0, /**< Y [16..235], UV [16..240] */ |
| 105 | AOM_CR_FULL_RANGE = 1 /**< YUV/RGB [0..255] */ |
| 106 | } aom_color_range_t; /**< alias for enum aom_color_range */ |
Yaowu Xu | 6b223fc | 2015-01-09 13:04:48 -0800 | [diff] [blame] | 107 | |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 108 | #if CONFIG_COLORSPACE_HEADERS |
| 109 | typedef enum aom_chroma_sample_position { |
| 110 | AOM_CSP_UNKNOWN = 0, /**< Unknown */ |
| 111 | AOM_CSP_VERTICAL = 1, /**< Horizontally co-located with luma(0, 0)*/ |
| 112 | /**< sample, between two vertical samples */ |
| 113 | AOM_CSP_COLOCATED = 2, /**< Co-located with luma(0, 0) sample */ |
| 114 | AOM_CSP_RESERVED = 3 /**< Reserved value */ |
| 115 | } aom_chroma_sample_position_t; /**< alias for enum aom_transfer_function */ |
| 116 | #endif |
| 117 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 118 | /**\brief Image Descriptor */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 119 | typedef struct aom_image { |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 120 | aom_img_fmt_t fmt; /**< Image Format */ |
| 121 | aom_color_space_t cs; /**< Color Space */ |
| 122 | #if CONFIG_COLORSPACE_HEADERS |
| 123 | aom_transfer_function_t tf; /**< transfer function */ |
| 124 | aom_chroma_sample_position_t csp; /**< chroma sample position */ |
| 125 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 126 | aom_color_range_t range; /**< Color Range */ |
Yaowu Xu | 5684295 | 2015-10-16 16:25:08 -0700 | [diff] [blame] | 127 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 128 | /* Image storage dimensions */ |
| 129 | unsigned int w; /**< Stored image width */ |
| 130 | unsigned int h; /**< Stored image height */ |
| 131 | unsigned int bit_depth; /**< Stored image bit-depth */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 132 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 133 | /* Image display dimensions */ |
| 134 | unsigned int d_w; /**< Displayed image width */ |
| 135 | unsigned int d_h; /**< Displayed image height */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 136 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 137 | /* Image intended rendering dimensions */ |
| 138 | unsigned int r_w; /**< Intended rendering image width */ |
| 139 | unsigned int r_h; /**< Intended rendering image height */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 140 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 141 | /* Chroma subsampling info */ |
| 142 | unsigned int x_chroma_shift; /**< subsampling order, X */ |
| 143 | unsigned int y_chroma_shift; /**< subsampling order, Y */ |
Ronald S. Bultje | 812945a | 2015-09-25 21:51:55 -0400 | [diff] [blame] | 144 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 145 | /* Image data pointers. */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 146 | #define AOM_PLANE_PACKED 0 /**< To be used for all packed formats */ |
| 147 | #define AOM_PLANE_Y 0 /**< Y (Luminance) plane */ |
| 148 | #define AOM_PLANE_U 1 /**< U (Chroma) plane */ |
| 149 | #define AOM_PLANE_V 2 /**< V (Chroma) plane */ |
| 150 | #define AOM_PLANE_ALPHA 3 /**< A (Transparency) plane */ |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 151 | unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */ |
| 152 | int stride[4]; /**< stride between rows for each plane */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 153 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 154 | int bps; /**< bits per sample (for packed formats) */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 155 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 156 | /*!\brief The following member may be set by the application to associate |
| 157 | * data with this image. |
John Koleszar | c6b9039 | 2012-07-13 15:21:29 -0700 | [diff] [blame] | 158 | */ |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 159 | void *user_priv; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 160 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 161 | /* The following members should be treated as private. */ |
| 162 | unsigned char *img_data; /**< private */ |
| 163 | int img_data_owner; /**< private */ |
| 164 | int self_allocd; /**< private */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 165 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 166 | void *fb_priv; /**< Frame buffer data associated with the image. */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 167 | } aom_image_t; /**< alias for struct aom_image */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 168 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 169 | /**\brief Representation of a rectangle on a surface */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 170 | typedef struct aom_image_rect { |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 171 | unsigned int x; /**< leftmost column */ |
| 172 | unsigned int y; /**< topmost row */ |
| 173 | unsigned int w; /**< width */ |
| 174 | unsigned int h; /**< height */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 175 | } aom_image_rect_t; /**< alias for struct aom_image_rect */ |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 176 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 177 | /*!\brief Open a descriptor, allocating storage for the underlying image |
| 178 | * |
| 179 | * Returns a descriptor for storing an image of the given format. The |
| 180 | * storage for the descriptor is allocated on the heap. |
| 181 | * |
| 182 | * \param[in] img Pointer to storage for descriptor. If this parameter |
| 183 | * is NULL, the storage for the descriptor will be |
| 184 | * allocated on the heap. |
| 185 | * \param[in] fmt Format for the image |
| 186 | * \param[in] d_w Width of the image |
| 187 | * \param[in] d_h Height of the image |
| 188 | * \param[in] align Alignment, in bytes, of the image buffer and |
| 189 | * each row in the image(stride). |
| 190 | * |
| 191 | * \return Returns a pointer to the initialized image descriptor. If the img |
| 192 | * parameter is non-null, the value of the img parameter will be |
| 193 | * returned. |
| 194 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 195 | aom_image_t *aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 196 | unsigned int d_w, unsigned int d_h, |
| 197 | unsigned int align); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 198 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 199 | /*!\brief Open a descriptor, using existing storage for the underlying image |
| 200 | * |
| 201 | * Returns a descriptor for storing an image of the given format. The |
| 202 | * storage for descriptor has been allocated elsewhere, and a descriptor is |
| 203 | * desired to "wrap" that storage. |
| 204 | * |
| 205 | * \param[in] img Pointer to storage for descriptor. If this parameter |
| 206 | * is NULL, the storage for the descriptor will be |
| 207 | * allocated on the heap. |
| 208 | * \param[in] fmt Format for the image |
| 209 | * \param[in] d_w Width of the image |
| 210 | * \param[in] d_h Height of the image |
| 211 | * \param[in] align Alignment, in bytes, of each row in the image. |
| 212 | * \param[in] img_data Storage to use for the image |
| 213 | * |
| 214 | * \return Returns a pointer to the initialized image descriptor. If the img |
| 215 | * parameter is non-null, the value of the img parameter will be |
| 216 | * returned. |
| 217 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 218 | aom_image_t *aom_img_wrap(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 219 | unsigned int d_h, unsigned int align, |
| 220 | unsigned char *img_data); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 221 | |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 222 | /*!\brief Set the rectangle identifying the displayed portion of the image |
| 223 | * |
| 224 | * Updates the displayed rectangle (aka viewport) on the image surface to |
| 225 | * match the specified coordinates and size. |
| 226 | * |
| 227 | * \param[in] img Image descriptor |
| 228 | * \param[in] x leftmost column |
| 229 | * \param[in] y topmost row |
| 230 | * \param[in] w width |
| 231 | * \param[in] h height |
| 232 | * |
| 233 | * \return 0 if the requested rectangle is valid, nonzero otherwise. |
| 234 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 235 | int aom_img_set_rect(aom_image_t *img, unsigned int x, unsigned int y, |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 236 | unsigned int w, unsigned int h); |
| 237 | |
| 238 | /*!\brief Flip the image vertically (top for bottom) |
| 239 | * |
| 240 | * Adjusts the image descriptor's pointers and strides to make the image |
| 241 | * be referenced upside-down. |
| 242 | * |
| 243 | * \param[in] img Image descriptor |
| 244 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 245 | void aom_img_flip(aom_image_t *img); |
clang-format | 83a5207 | 2016-08-08 20:22:13 -0700 | [diff] [blame] | 246 | |
| 247 | /*!\brief Close an image descriptor |
| 248 | * |
| 249 | * Frees all allocated storage associated with an image descriptor. |
| 250 | * |
| 251 | * \param[in] img Image descriptor |
| 252 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 253 | void aom_img_free(aom_image_t *img); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 254 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 255 | #ifdef __cplusplus |
James Zern | ec7f213 | 2014-01-18 12:16:11 -0800 | [diff] [blame] | 256 | } // extern "C" |
| 257 | #endif |
| 258 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 259 | #endif // AOM_AOM_IMAGE_H_ |