blob: 34cf71552e6467a86d629c875167f8dace176232 [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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 Koleszar0ea50ce2010-05-18 11:58:33 -040010 */
11
James Zernf42d52e2011-02-16 17:54:49 -080012/*!\file
Yaowu Xuf883b422016-08-30 14:01:10 -070013 * \brief Describes the aom image descriptor and associated operations
John Koleszar0ea50ce2010-05-18 11:58:33 -040014 *
15 */
Yaowu Xuf883b422016-08-30 14:01:10 -070016#ifndef AOM_AOM_IMAGE_H_
17#define AOM_AOM_IMAGE_H_
James Zernec7f2132014-01-18 12:16:11 -080018
John Koleszar0ea50ce2010-05-18 11:58:33 -040019#ifdef __cplusplus
20extern "C" {
21#endif
22
clang-format83a52072016-08-08 20:22:13 -070023/*!\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 Xuf883b422016-08-30 14:01:10 -070031#define AOM_IMAGE_ABI_VERSION (4) /**<\hideinitializer*/
John Koleszar0ea50ce2010-05-18 11:58:33 -040032
Yaowu Xuf883b422016-08-30 14:01:10 -070033#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 Koleszar0ea50ce2010-05-18 11:58:33 -040037
anorkin76fb1262017-03-22 15:12:12 -070038#include "./aom_config.h"
39
clang-format83a52072016-08-08 20:22:13 -070040/*!\brief List of supported image formats */
Yaowu Xuf883b422016-08-30 14:01:10 -070041typedef 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 Koleszar0ea50ce2010-05-18 11:58:33 -040071
clang-format83a52072016-08-08 20:22:13 -070072/*!\brief List of supported color spaces */
Yaowu Xuf883b422016-08-30 14:01:10 -070073typedef 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 */
anorkin76fb1262017-03-22 15:12:12 -070079#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
93typedef 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 Koleszar0ea50ce2010-05-18 11:58:33 -0400101
clang-format83a52072016-08-08 20:22:13 -0700102/*!\brief List of supported color range */
Yaowu Xuf883b422016-08-30 14:01:10 -0700103typedef 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 Xu6b223fc2015-01-09 13:04:48 -0800107
anorkin76fb1262017-03-22 15:12:12 -0700108#if CONFIG_COLORSPACE_HEADERS
109typedef 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-format83a52072016-08-08 20:22:13 -0700118/**\brief Image Descriptor */
Yaowu Xuf883b422016-08-30 14:01:10 -0700119typedef struct aom_image {
anorkin76fb1262017-03-22 15:12:12 -0700120 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 Xuf883b422016-08-30 14:01:10 -0700126 aom_color_range_t range; /**< Color Range */
Yaowu Xu56842952015-10-16 16:25:08 -0700127
clang-format83a52072016-08-08 20:22:13 -0700128 /* 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 Koleszar0ea50ce2010-05-18 11:58:33 -0400132
clang-format83a52072016-08-08 20:22:13 -0700133 /* Image display dimensions */
134 unsigned int d_w; /**< Displayed image width */
135 unsigned int d_h; /**< Displayed image height */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400136
clang-format83a52072016-08-08 20:22:13 -0700137 /* Image intended rendering dimensions */
138 unsigned int r_w; /**< Intended rendering image width */
139 unsigned int r_h; /**< Intended rendering image height */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400140
clang-format83a52072016-08-08 20:22:13 -0700141 /* Chroma subsampling info */
142 unsigned int x_chroma_shift; /**< subsampling order, X */
143 unsigned int y_chroma_shift; /**< subsampling order, Y */
Ronald S. Bultje812945a2015-09-25 21:51:55 -0400144
clang-format83a52072016-08-08 20:22:13 -0700145/* Image data pointers. */
Yaowu Xuf883b422016-08-30 14:01:10 -0700146#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-format83a52072016-08-08 20:22:13 -0700151 unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */
152 int stride[4]; /**< stride between rows for each plane */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400153
clang-format83a52072016-08-08 20:22:13 -0700154 int bps; /**< bits per sample (for packed formats) */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400155
clang-format83a52072016-08-08 20:22:13 -0700156 /*!\brief The following member may be set by the application to associate
157 * data with this image.
John Koleszarc6b90392012-07-13 15:21:29 -0700158 */
clang-format83a52072016-08-08 20:22:13 -0700159 void *user_priv;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400160
clang-format83a52072016-08-08 20:22:13 -0700161 /* 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 Koleszar0ea50ce2010-05-18 11:58:33 -0400165
clang-format83a52072016-08-08 20:22:13 -0700166 void *fb_priv; /**< Frame buffer data associated with the image. */
Yaowu Xuf883b422016-08-30 14:01:10 -0700167} aom_image_t; /**< alias for struct aom_image */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400168
clang-format83a52072016-08-08 20:22:13 -0700169/**\brief Representation of a rectangle on a surface */
Yaowu Xuf883b422016-08-30 14:01:10 -0700170typedef struct aom_image_rect {
clang-format83a52072016-08-08 20:22:13 -0700171 unsigned int x; /**< leftmost column */
172 unsigned int y; /**< topmost row */
173 unsigned int w; /**< width */
174 unsigned int h; /**< height */
Yaowu Xuf883b422016-08-30 14:01:10 -0700175} aom_image_rect_t; /**< alias for struct aom_image_rect */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400176
clang-format83a52072016-08-08 20:22:13 -0700177/*!\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 Xuf883b422016-08-30 14:01:10 -0700195aom_image_t *aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt,
clang-format83a52072016-08-08 20:22:13 -0700196 unsigned int d_w, unsigned int d_h,
197 unsigned int align);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400198
clang-format83a52072016-08-08 20:22:13 -0700199/*!\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 Xuf883b422016-08-30 14:01:10 -0700218aom_image_t *aom_img_wrap(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w,
clang-format83a52072016-08-08 20:22:13 -0700219 unsigned int d_h, unsigned int align,
220 unsigned char *img_data);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400221
clang-format83a52072016-08-08 20:22:13 -0700222/*!\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 Xuf883b422016-08-30 14:01:10 -0700235int aom_img_set_rect(aom_image_t *img, unsigned int x, unsigned int y,
clang-format83a52072016-08-08 20:22:13 -0700236 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 Xuf883b422016-08-30 14:01:10 -0700245void aom_img_flip(aom_image_t *img);
clang-format83a52072016-08-08 20:22:13 -0700246
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 Xuf883b422016-08-30 14:01:10 -0700253void aom_img_free(aom_image_t *img);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400254
John Koleszar0ea50ce2010-05-18 11:58:33 -0400255#ifdef __cplusplus
James Zernec7f2132014-01-18 12:16:11 -0800256} // extern "C"
257#endif
258
Yaowu Xuf883b422016-08-30 14:01:10 -0700259#endif // AOM_AOM_IMAGE_H_