blob: b2f75e6391e45111cb2eef7254eb669d4cad310b [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
clang-format83a52072016-08-08 20:22:13 -070038/*!\brief List of supported image formats */
Yaowu Xuf883b422016-08-30 14:01:10 -070039typedef enum aom_img_fmt {
40 AOM_IMG_FMT_NONE,
41 AOM_IMG_FMT_RGB24, /**< 24 bit per pixel packed RGB */
42 AOM_IMG_FMT_RGB32, /**< 32 bit per pixel packed 0RGB */
43 AOM_IMG_FMT_RGB565, /**< 16 bit per pixel, 565 */
44 AOM_IMG_FMT_RGB555, /**< 16 bit per pixel, 555 */
45 AOM_IMG_FMT_UYVY, /**< UYVY packed YUV */
46 AOM_IMG_FMT_YUY2, /**< YUYV packed YUV */
47 AOM_IMG_FMT_YVYU, /**< YVYU packed YUV */
48 AOM_IMG_FMT_BGR24, /**< 24 bit per pixel packed BGR */
49 AOM_IMG_FMT_RGB32_LE, /**< 32 bit packed BGR0 */
50 AOM_IMG_FMT_ARGB, /**< 32 bit packed ARGB, alpha=255 */
51 AOM_IMG_FMT_ARGB_LE, /**< 32 bit packed BGRA, alpha=255 */
52 AOM_IMG_FMT_RGB565_LE, /**< 16 bit per pixel, gggbbbbb rrrrrggg */
53 AOM_IMG_FMT_RGB555_LE, /**< 16 bit per pixel, gggbbbbb 0rrrrrgg */
54 AOM_IMG_FMT_YV12 =
55 AOM_IMG_FMT_PLANAR | AOM_IMG_FMT_UV_FLIP | 1, /**< planar YVU */
56 AOM_IMG_FMT_I420 = AOM_IMG_FMT_PLANAR | 2,
57 AOM_IMG_FMT_AOMYV12 = AOM_IMG_FMT_PLANAR | AOM_IMG_FMT_UV_FLIP |
58 3, /** < planar 4:2:0 format with aom color space */
59 AOM_IMG_FMT_AOMI420 = AOM_IMG_FMT_PLANAR | 4,
60 AOM_IMG_FMT_I422 = AOM_IMG_FMT_PLANAR | 5,
61 AOM_IMG_FMT_I444 = AOM_IMG_FMT_PLANAR | 6,
62 AOM_IMG_FMT_I440 = AOM_IMG_FMT_PLANAR | 7,
63 AOM_IMG_FMT_444A = AOM_IMG_FMT_PLANAR | AOM_IMG_FMT_HAS_ALPHA | 6,
64 AOM_IMG_FMT_I42016 = AOM_IMG_FMT_I420 | AOM_IMG_FMT_HIGHBITDEPTH,
65 AOM_IMG_FMT_I42216 = AOM_IMG_FMT_I422 | AOM_IMG_FMT_HIGHBITDEPTH,
66 AOM_IMG_FMT_I44416 = AOM_IMG_FMT_I444 | AOM_IMG_FMT_HIGHBITDEPTH,
67 AOM_IMG_FMT_I44016 = AOM_IMG_FMT_I440 | AOM_IMG_FMT_HIGHBITDEPTH
68} aom_img_fmt_t; /**< alias for enum aom_img_fmt */
John Koleszar0ea50ce2010-05-18 11:58:33 -040069
clang-format83a52072016-08-08 20:22:13 -070070/*!\brief List of supported color spaces */
Yaowu Xuf883b422016-08-30 14:01:10 -070071typedef enum aom_color_space {
72 AOM_CS_UNKNOWN = 0, /**< Unknown */
73 AOM_CS_BT_601 = 1, /**< BT.601 */
74 AOM_CS_BT_709 = 2, /**< BT.709 */
75 AOM_CS_SMPTE_170 = 3, /**< SMPTE.170 */
76 AOM_CS_SMPTE_240 = 4, /**< SMPTE.240 */
77 AOM_CS_BT_2020 = 5, /**< BT.2020 */
78 AOM_CS_RESERVED = 6, /**< Reserved */
79 AOM_CS_SRGB = 7 /**< sRGB */
80} aom_color_space_t; /**< alias for enum aom_color_space */
John Koleszar0ea50ce2010-05-18 11:58:33 -040081
clang-format83a52072016-08-08 20:22:13 -070082/*!\brief List of supported color range */
Yaowu Xuf883b422016-08-30 14:01:10 -070083typedef enum aom_color_range {
84 AOM_CR_STUDIO_RANGE = 0, /**< Y [16..235], UV [16..240] */
85 AOM_CR_FULL_RANGE = 1 /**< YUV/RGB [0..255] */
86} aom_color_range_t; /**< alias for enum aom_color_range */
Yaowu Xu6b223fc2015-01-09 13:04:48 -080087
clang-format83a52072016-08-08 20:22:13 -070088/**\brief Image Descriptor */
Yaowu Xuf883b422016-08-30 14:01:10 -070089typedef struct aom_image {
90 aom_img_fmt_t fmt; /**< Image Format */
91 aom_color_space_t cs; /**< Color Space */
92 aom_color_range_t range; /**< Color Range */
Yaowu Xu56842952015-10-16 16:25:08 -070093
clang-format83a52072016-08-08 20:22:13 -070094 /* Image storage dimensions */
95 unsigned int w; /**< Stored image width */
96 unsigned int h; /**< Stored image height */
97 unsigned int bit_depth; /**< Stored image bit-depth */
John Koleszar0ea50ce2010-05-18 11:58:33 -040098
clang-format83a52072016-08-08 20:22:13 -070099 /* Image display dimensions */
100 unsigned int d_w; /**< Displayed image width */
101 unsigned int d_h; /**< Displayed image height */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400102
clang-format83a52072016-08-08 20:22:13 -0700103 /* Image intended rendering dimensions */
104 unsigned int r_w; /**< Intended rendering image width */
105 unsigned int r_h; /**< Intended rendering image height */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400106
clang-format83a52072016-08-08 20:22:13 -0700107 /* Chroma subsampling info */
108 unsigned int x_chroma_shift; /**< subsampling order, X */
109 unsigned int y_chroma_shift; /**< subsampling order, Y */
Ronald S. Bultje812945a2015-09-25 21:51:55 -0400110
clang-format83a52072016-08-08 20:22:13 -0700111/* Image data pointers. */
Yaowu Xuf883b422016-08-30 14:01:10 -0700112#define AOM_PLANE_PACKED 0 /**< To be used for all packed formats */
113#define AOM_PLANE_Y 0 /**< Y (Luminance) plane */
114#define AOM_PLANE_U 1 /**< U (Chroma) plane */
115#define AOM_PLANE_V 2 /**< V (Chroma) plane */
116#define AOM_PLANE_ALPHA 3 /**< A (Transparency) plane */
clang-format83a52072016-08-08 20:22:13 -0700117 unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */
118 int stride[4]; /**< stride between rows for each plane */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400119
clang-format83a52072016-08-08 20:22:13 -0700120 int bps; /**< bits per sample (for packed formats) */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400121
clang-format83a52072016-08-08 20:22:13 -0700122 /*!\brief The following member may be set by the application to associate
123 * data with this image.
John Koleszarc6b90392012-07-13 15:21:29 -0700124 */
clang-format83a52072016-08-08 20:22:13 -0700125 void *user_priv;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400126
clang-format83a52072016-08-08 20:22:13 -0700127 /* The following members should be treated as private. */
128 unsigned char *img_data; /**< private */
129 int img_data_owner; /**< private */
130 int self_allocd; /**< private */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400131
clang-format83a52072016-08-08 20:22:13 -0700132 void *fb_priv; /**< Frame buffer data associated with the image. */
Yaowu Xuf883b422016-08-30 14:01:10 -0700133} aom_image_t; /**< alias for struct aom_image */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400134
clang-format83a52072016-08-08 20:22:13 -0700135/**\brief Representation of a rectangle on a surface */
Yaowu Xuf883b422016-08-30 14:01:10 -0700136typedef struct aom_image_rect {
clang-format83a52072016-08-08 20:22:13 -0700137 unsigned int x; /**< leftmost column */
138 unsigned int y; /**< topmost row */
139 unsigned int w; /**< width */
140 unsigned int h; /**< height */
Yaowu Xuf883b422016-08-30 14:01:10 -0700141} aom_image_rect_t; /**< alias for struct aom_image_rect */
John Koleszar0ea50ce2010-05-18 11:58:33 -0400142
clang-format83a52072016-08-08 20:22:13 -0700143/*!\brief Open a descriptor, allocating storage for the underlying image
144 *
145 * Returns a descriptor for storing an image of the given format. The
146 * storage for the descriptor is allocated on the heap.
147 *
148 * \param[in] img Pointer to storage for descriptor. If this parameter
149 * is NULL, the storage for the descriptor will be
150 * allocated on the heap.
151 * \param[in] fmt Format for the image
152 * \param[in] d_w Width of the image
153 * \param[in] d_h Height of the image
154 * \param[in] align Alignment, in bytes, of the image buffer and
155 * each row in the image(stride).
156 *
157 * \return Returns a pointer to the initialized image descriptor. If the img
158 * parameter is non-null, the value of the img parameter will be
159 * returned.
160 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700161aom_image_t *aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt,
clang-format83a52072016-08-08 20:22:13 -0700162 unsigned int d_w, unsigned int d_h,
163 unsigned int align);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400164
clang-format83a52072016-08-08 20:22:13 -0700165/*!\brief Open a descriptor, using existing storage for the underlying image
166 *
167 * Returns a descriptor for storing an image of the given format. The
168 * storage for descriptor has been allocated elsewhere, and a descriptor is
169 * desired to "wrap" that storage.
170 *
171 * \param[in] img Pointer to storage for descriptor. If this parameter
172 * is NULL, the storage for the descriptor will be
173 * allocated on the heap.
174 * \param[in] fmt Format for the image
175 * \param[in] d_w Width of the image
176 * \param[in] d_h Height of the image
177 * \param[in] align Alignment, in bytes, of each row in the image.
178 * \param[in] img_data Storage to use for the image
179 *
180 * \return Returns a pointer to the initialized image descriptor. If the img
181 * parameter is non-null, the value of the img parameter will be
182 * returned.
183 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700184aom_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 -0700185 unsigned int d_h, unsigned int align,
186 unsigned char *img_data);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400187
clang-format83a52072016-08-08 20:22:13 -0700188/*!\brief Set the rectangle identifying the displayed portion of the image
189 *
190 * Updates the displayed rectangle (aka viewport) on the image surface to
191 * match the specified coordinates and size.
192 *
193 * \param[in] img Image descriptor
194 * \param[in] x leftmost column
195 * \param[in] y topmost row
196 * \param[in] w width
197 * \param[in] h height
198 *
199 * \return 0 if the requested rectangle is valid, nonzero otherwise.
200 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700201int aom_img_set_rect(aom_image_t *img, unsigned int x, unsigned int y,
clang-format83a52072016-08-08 20:22:13 -0700202 unsigned int w, unsigned int h);
203
204/*!\brief Flip the image vertically (top for bottom)
205 *
206 * Adjusts the image descriptor's pointers and strides to make the image
207 * be referenced upside-down.
208 *
209 * \param[in] img Image descriptor
210 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700211void aom_img_flip(aom_image_t *img);
clang-format83a52072016-08-08 20:22:13 -0700212
213/*!\brief Close an image descriptor
214 *
215 * Frees all allocated storage associated with an image descriptor.
216 *
217 * \param[in] img Image descriptor
218 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700219void aom_img_free(aom_image_t *img);
John Koleszar0ea50ce2010-05-18 11:58:33 -0400220
John Koleszar0ea50ce2010-05-18 11:58:33 -0400221#ifdef __cplusplus
James Zernec7f2132014-01-18 12:16:11 -0800222} // extern "C"
223#endif
224
Yaowu Xuf883b422016-08-30 14:01:10 -0700225#endif // AOM_AOM_IMAGE_H_