1 /* 2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved 3 * 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. 10 */ 11 12 /*!\file 13 * \brief Describes the aom image descriptor and associated operations 14 * 15 */ 16 #ifndef AOM_AOM_AOM_IMAGE_H_ 17 #define AOM_AOM_AOM_IMAGE_H_ 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 #include "aom/aom_integer.h" 24 25 /*!\brief Current ABI version number 26 * 27 * \internal 28 * If this file is altered in any way that changes the ABI, this value 29 * must be bumped. Examples include, but are not limited to, changing 30 * types, removing or reassigning enums, adding/removing/rearranging 31 * fields to structures 32 */ 33 #define AOM_IMAGE_ABI_VERSION (9) /**<\hideinitializer*/ 34 35 #define AOM_IMG_FMT_PLANAR 0x100 /**< Image is a planar format. */ 36 #define AOM_IMG_FMT_UV_FLIP 0x200 /**< V plane precedes U in memory. */ 37 /** 0x400 used to signal alpha channel, skipping for backwards compatibility. */ 38 #define AOM_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */ 39 40 /*!\brief List of supported image formats */ 41 typedef enum aom_img_fmt { 42 AOM_IMG_FMT_NONE, 43 AOM_IMG_FMT_YV12 = 44 AOM_IMG_FMT_PLANAR | AOM_IMG_FMT_UV_FLIP | 1, /**< planar YVU */ 45 AOM_IMG_FMT_I420 = AOM_IMG_FMT_PLANAR | 2, 46 AOM_IMG_FMT_AOMYV12 = AOM_IMG_FMT_PLANAR | AOM_IMG_FMT_UV_FLIP | 47 3, /** < planar 4:2:0 format with aom color space */ 48 AOM_IMG_FMT_AOMI420 = AOM_IMG_FMT_PLANAR | 4, 49 AOM_IMG_FMT_I422 = AOM_IMG_FMT_PLANAR | 5, 50 AOM_IMG_FMT_I444 = AOM_IMG_FMT_PLANAR | 6, 51 /*!\brief Allows detection of the presence of AOM_IMG_FMT_NV12 at compile time. 52 */ 53 #define AOM_HAVE_IMG_FMT_NV12 1 54 AOM_IMG_FMT_NV12 = 55 AOM_IMG_FMT_PLANAR | 7, /**< 4:2:0 with U and V interleaved */ 56 AOM_IMG_FMT_I42016 = AOM_IMG_FMT_I420 | AOM_IMG_FMT_HIGHBITDEPTH, 57 AOM_IMG_FMT_YV1216 = AOM_IMG_FMT_YV12 | AOM_IMG_FMT_HIGHBITDEPTH, 58 AOM_IMG_FMT_I42216 = AOM_IMG_FMT_I422 | AOM_IMG_FMT_HIGHBITDEPTH, 59 AOM_IMG_FMT_I44416 = AOM_IMG_FMT_I444 | AOM_IMG_FMT_HIGHBITDEPTH, 60 } aom_img_fmt_t; /**< alias for enum aom_img_fmt */ 61 62 /*!\brief List of supported color primaries */ 63 typedef enum aom_color_primaries { 64 AOM_CICP_CP_RESERVED_0 = 0, /**< For future use */ 65 AOM_CICP_CP_BT_709 = 1, /**< BT.709 */ 66 AOM_CICP_CP_UNSPECIFIED = 2, /**< Unspecified */ 67 AOM_CICP_CP_RESERVED_3 = 3, /**< For future use */ 68 AOM_CICP_CP_BT_470_M = 4, /**< BT.470 System M (historical) */ 69 AOM_CICP_CP_BT_470_B_G = 5, /**< BT.470 System B, G (historical) */ 70 AOM_CICP_CP_BT_601 = 6, /**< BT.601 */ 71 AOM_CICP_CP_SMPTE_240 = 7, /**< SMPTE 240 */ 72 AOM_CICP_CP_GENERIC_FILM = 73 8, /**< Generic film (color filters using illuminant C) */ 74 AOM_CICP_CP_BT_2020 = 9, /**< BT.2020, BT.2100 */ 75 AOM_CICP_CP_XYZ = 10, /**< SMPTE 428 (CIE 1921 XYZ) */ 76 AOM_CICP_CP_SMPTE_431 = 11, /**< SMPTE RP 431-2 */ 77 AOM_CICP_CP_SMPTE_432 = 12, /**< SMPTE EG 432-1 */ 78 AOM_CICP_CP_RESERVED_13 = 13, /**< For future use (values 13 - 21) */ 79 AOM_CICP_CP_EBU_3213 = 22, /**< EBU Tech. 3213-E */ 80 AOM_CICP_CP_RESERVED_23 = 23 /**< For future use (values 23 - 255) */ 81 } aom_color_primaries_t; /**< alias for enum aom_color_primaries */ 82 83 /*!\brief List of supported transfer functions */ 84 typedef enum aom_transfer_characteristics { 85 AOM_CICP_TC_RESERVED_0 = 0, /**< For future use */ 86 AOM_CICP_TC_BT_709 = 1, /**< BT.709 */ 87 AOM_CICP_TC_UNSPECIFIED = 2, /**< Unspecified */ 88 AOM_CICP_TC_RESERVED_3 = 3, /**< For future use */ 89 AOM_CICP_TC_BT_470_M = 4, /**< BT.470 System M (historical) */ 90 AOM_CICP_TC_BT_470_B_G = 5, /**< BT.470 System B, G (historical) */ 91 AOM_CICP_TC_BT_601 = 6, /**< BT.601 */ 92 AOM_CICP_TC_SMPTE_240 = 7, /**< SMPTE 240 M */ 93 AOM_CICP_TC_LINEAR = 8, /**< Linear */ 94 AOM_CICP_TC_LOG_100 = 9, /**< Logarithmic (100 : 1 range) */ 95 AOM_CICP_TC_LOG_100_SQRT10 = 96 10, /**< Logarithmic (100 * Sqrt(10) : 1 range) */ 97 AOM_CICP_TC_IEC_61966 = 11, /**< IEC 61966-2-4 */ 98 AOM_CICP_TC_BT_1361 = 12, /**< BT.1361 */ 99 AOM_CICP_TC_SRGB = 13, /**< sRGB or sYCC*/ 100 AOM_CICP_TC_BT_2020_10_BIT = 14, /**< BT.2020 10-bit systems */ 101 AOM_CICP_TC_BT_2020_12_BIT = 15, /**< BT.2020 12-bit systems */ 102 AOM_CICP_TC_SMPTE_2084 = 16, /**< SMPTE ST 2084, ITU BT.2100 PQ */ 103 AOM_CICP_TC_SMPTE_428 = 17, /**< SMPTE ST 428 */ 104 AOM_CICP_TC_HLG = 18, /**< BT.2100 HLG, ARIB STD-B67 */ 105 AOM_CICP_TC_RESERVED_19 = 19 /**< For future use (values 19-255) */ 106 } aom_transfer_characteristics_t; /**< alias for enum aom_transfer_function */ 107 108 /*!\brief List of supported matrix coefficients */ 109 typedef enum aom_matrix_coefficients { 110 AOM_CICP_MC_IDENTITY = 0, /**< Identity matrix */ 111 AOM_CICP_MC_BT_709 = 1, /**< BT.709 */ 112 AOM_CICP_MC_UNSPECIFIED = 2, /**< Unspecified */ 113 AOM_CICP_MC_RESERVED_3 = 3, /**< For future use */ 114 AOM_CICP_MC_FCC = 4, /**< US FCC 73.628 */ 115 AOM_CICP_MC_BT_470_B_G = 5, /**< BT.470 System B, G (historical) */ 116 AOM_CICP_MC_BT_601 = 6, /**< BT.601 */ 117 AOM_CICP_MC_SMPTE_240 = 7, /**< SMPTE 240 M */ 118 AOM_CICP_MC_SMPTE_YCGCO = 8, /**< YCgCo */ 119 AOM_CICP_MC_BT_2020_NCL = 120 9, /**< BT.2020 non-constant luminance, BT.2100 YCbCr */ 121 AOM_CICP_MC_BT_2020_CL = 10, /**< BT.2020 constant luminance */ 122 AOM_CICP_MC_SMPTE_2085 = 11, /**< SMPTE ST 2085 YDzDx */ 123 AOM_CICP_MC_CHROMAT_NCL = 124 12, /**< Chromaticity-derived non-constant luminance */ 125 AOM_CICP_MC_CHROMAT_CL = 13, /**< Chromaticity-derived constant luminance */ 126 AOM_CICP_MC_ICTCP = 14, /**< BT.2100 ICtCp */ 127 AOM_CICP_MC_RESERVED_15 = 15 /**< For future use (values 15-255) */ 128 } aom_matrix_coefficients_t; 129 130 /*!\brief List of supported color range */ 131 typedef enum aom_color_range { 132 AOM_CR_STUDIO_RANGE = 0, /**<- Y [16..235], UV [16..240] (bit depth 8) */ 133 /**<- Y [64..940], UV [64..960] (bit depth 10) */ 134 /**<- Y [256..3760], UV [256..3840] (bit depth 12) */ 135 AOM_CR_FULL_RANGE = 1 /**<- YUV/RGB [0..255] (bit depth 8) */ 136 /**<- YUV/RGB [0..1023] (bit depth 10) */ 137 /**<- YUV/RGB [0..4095] (bit depth 12) */ 138 } aom_color_range_t; /**< alias for enum aom_color_range */ 139 140 /*!\brief List of chroma sample positions */ 141 typedef enum aom_chroma_sample_position { 142 AOM_CSP_UNKNOWN = 0, /**< Unknown */ 143 AOM_CSP_VERTICAL = 1, /**< Horizontally co-located with luma(0, 0)*/ 144 /**< sample, between two vertical samples */ 145 AOM_CSP_COLOCATED = 2, /**< Co-located with luma(0, 0) sample */ 146 AOM_CSP_RESERVED = 3 /**< Reserved value */ 147 } aom_chroma_sample_position_t; /**< alias for enum aom_transfer_function */ 148 149 /*!\brief List of insert flags for Metadata 150 * 151 * These flags control how the library treats metadata during encode. 152 * 153 * While encoding, when metadata is added to an aom_image via 154 * aom_img_add_metadata(), the flag passed along with the metadata will 155 * determine where the metadata OBU will be placed in the encoded OBU stream. 156 * Metadata will be emitted into the output stream within the next temporal unit 157 * if it satisfies the specified insertion flag. 158 * 159 * During decoding, when the library encounters a metadata OBU, it is always 160 * flagged as AOM_MIF_ANY_FRAME and emitted with the next output aom_image. 161 */ 162 typedef enum aom_metadata_insert_flags { 163 AOM_MIF_NON_KEY_FRAME = 0, /**< Adds metadata if it's not keyframe */ 164 AOM_MIF_KEY_FRAME = 1, /**< Adds metadata only if it's a keyframe */ 165 AOM_MIF_ANY_FRAME = 2 /**< Adds metadata to any type of frame */ 166 } aom_metadata_insert_flags_t; 167 168 /*!\brief Array of aom_metadata structs for an image. */ 169 typedef struct aom_metadata_array aom_metadata_array_t; 170 171 /*!\brief Metadata payload. */ 172 typedef struct aom_metadata { 173 uint32_t type; /**< Metadata type */ 174 uint8_t *payload; /**< Metadata payload data */ 175 size_t sz; /**< Metadata payload size */ 176 aom_metadata_insert_flags_t insert_flag; /**< Metadata insertion flag */ 177 } aom_metadata_t; 178 179 /**\brief Image Descriptor */ 180 typedef struct aom_image { 181 aom_img_fmt_t fmt; /**< Image Format */ 182 aom_color_primaries_t cp; /**< CICP Color Primaries */ 183 aom_transfer_characteristics_t tc; /**< CICP Transfer Characteristics */ 184 aom_matrix_coefficients_t mc; /**< CICP Matrix Coefficients */ 185 int monochrome; /**< Whether image is monochrome */ 186 aom_chroma_sample_position_t csp; /**< chroma sample position */ 187 aom_color_range_t range; /**< Color Range */ 188 189 /* Image storage dimensions */ 190 unsigned int w; /**< Stored image width */ 191 unsigned int h; /**< Stored image height */ 192 unsigned int bit_depth; /**< Stored image bit-depth */ 193 194 /* Image display dimensions */ 195 unsigned int d_w; /**< Displayed image width */ 196 unsigned int d_h; /**< Displayed image height */ 197 198 /* Image intended rendering dimensions */ 199 unsigned int r_w; /**< Intended rendering image width */ 200 unsigned int r_h; /**< Intended rendering image height */ 201 202 /* Chroma subsampling info */ 203 unsigned int x_chroma_shift; /**< subsampling order, X */ 204 unsigned int y_chroma_shift; /**< subsampling order, Y */ 205 206 /* Image data pointers. */ 207 #define AOM_PLANE_PACKED 0 /**< To be used for all packed formats */ 208 #define AOM_PLANE_Y 0 /**< Y (Luminance) plane */ 209 #define AOM_PLANE_U 1 /**< U (Chroma) plane */ 210 #define AOM_PLANE_V 2 /**< V (Chroma) plane */ 211 /* planes[AOM_PLANE_V] = NULL and stride[AOM_PLANE_V] = 0 when fmt == 212 * AOM_IMG_FMT_NV12 */ 213 unsigned char *planes[3]; /**< pointer to the top left pixel for each plane */ 214 int stride[3]; /**< stride between rows for each plane */ 215 size_t sz; /**< data size */ 216 217 int bps; /**< bits per sample (for packed formats) */ 218 219 int temporal_id; /**< Temporal layer Id of image */ 220 int spatial_id; /**< Spatial layer Id of image */ 221 222 /*!\brief The following member may be set by the application to associate 223 * data with this image. 224 */ 225 void *user_priv; 226 227 /* The following members should be treated as private. */ 228 unsigned char *img_data; /**< private */ 229 int img_data_owner; /**< private */ 230 int self_allocd; /**< private */ 231 232 aom_metadata_array_t 233 *metadata; /**< Metadata payloads associated with the image. */ 234 235 void *fb_priv; /**< Frame buffer data associated with the image. */ 236 } aom_image_t; /**< alias for struct aom_image */ 237 238 /*!\brief Open a descriptor, allocating storage for the underlying image 239 * 240 * Returns a descriptor for storing an image of the given format. The 241 * storage for the image is allocated on the heap. 242 * 243 * \param[in] img Pointer to storage for descriptor. If this parameter 244 * is NULL, the storage for the descriptor will be 245 * allocated on the heap. 246 * \param[in] fmt Format for the image 247 * \param[in] d_w Width of the image 248 * \param[in] d_h Height of the image 249 * \param[in] align Alignment, in bytes, of the image buffer and 250 * each row in the image (stride). 251 * 252 * \return Returns a pointer to the initialized image descriptor. If the img 253 * parameter is non-null, the value of the img parameter will be 254 * returned. 255 */ 256 aom_image_t *aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, 257 unsigned int d_w, unsigned int d_h, 258 unsigned int align); 259 260 /*!\brief Open a descriptor, using existing storage for the underlying image 261 * 262 * Returns a descriptor for storing an image of the given format. The 263 * storage for the image has been allocated elsewhere, and a descriptor is 264 * desired to "wrap" that storage. 265 * 266 * \param[in] img Pointer to storage for descriptor. If this parameter 267 * is NULL, the storage for the descriptor will be 268 * allocated on the heap. 269 * \param[in] fmt Format for the image 270 * \param[in] d_w Width of the image 271 * \param[in] d_h Height of the image 272 * \param[in] align Alignment, in bytes, of each row in the image 273 * (stride). 274 * \param[in] img_data Storage to use for the image 275 * 276 * \return Returns a pointer to the initialized image descriptor. If the img 277 * parameter is non-null, the value of the img parameter will be 278 * returned. 279 */ 280 aom_image_t *aom_img_wrap(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, 281 unsigned int d_h, unsigned int align, 282 unsigned char *img_data); 283 284 /*!\brief Open a descriptor, allocating storage for the underlying image with a 285 * border 286 * 287 * Returns a descriptor for storing an image of the given format and its 288 * borders. The storage for the image is allocated on the heap. 289 * 290 * \param[in] img Pointer to storage for descriptor. If this parameter 291 * is NULL, the storage for the descriptor will be 292 * allocated on the heap. 293 * \param[in] fmt Format for the image 294 * \param[in] d_w Width of the image 295 * \param[in] d_h Height of the image 296 * \param[in] align Alignment, in bytes, of the image buffer and 297 * each row in the image (stride). 298 * \param[in] size_align Alignment, in pixels, of the image width and height. 299 * \param[in] border A border that is padded on four sides of the image. 300 * 301 * \return Returns a pointer to the initialized image descriptor. If the img 302 * parameter is non-null, the value of the img parameter will be 303 * returned. 304 */ 305 aom_image_t *aom_img_alloc_with_border(aom_image_t *img, aom_img_fmt_t fmt, 306 unsigned int d_w, unsigned int d_h, 307 unsigned int align, 308 unsigned int size_align, 309 unsigned int border); 310 311 /*!\brief Set the rectangle identifying the displayed portion of the image 312 * 313 * Updates the displayed rectangle (aka viewport) on the image surface to 314 * match the specified coordinates and size. Specifically, sets img->d_w, 315 * img->d_h, and elements of the img->planes[] array. 316 * 317 * \param[in] img Image descriptor 318 * \param[in] x leftmost column 319 * \param[in] y topmost row 320 * \param[in] w width 321 * \param[in] h height 322 * \param[in] border A border that is padded on four sides of the image. 323 * 324 * \return 0 if the requested rectangle is valid, nonzero (-1) otherwise. 325 */ 326 int aom_img_set_rect(aom_image_t *img, unsigned int x, unsigned int y, 327 unsigned int w, unsigned int h, unsigned int border); 328 329 /*!\brief Flip the image vertically (top for bottom) 330 * 331 * Adjusts the image descriptor's pointers and strides to make the image 332 * be referenced upside-down. 333 * 334 * \param[in] img Image descriptor 335 */ 336 void aom_img_flip(aom_image_t *img); 337 338 /*!\brief Close an image descriptor 339 * 340 * Frees all allocated storage associated with an image descriptor. 341 * 342 * \param[in] img Image descriptor 343 */ 344 void aom_img_free(aom_image_t *img); 345 346 /*!\brief Get the width of a plane 347 * 348 * Get the width of a plane of an image 349 * 350 * \param[in] img Image descriptor 351 * \param[in] plane Plane index 352 */ 353 int aom_img_plane_width(const aom_image_t *img, int plane); 354 355 /*!\brief Get the height of a plane 356 * 357 * Get the height of a plane of an image 358 * 359 * \param[in] img Image descriptor 360 * \param[in] plane Plane index 361 */ 362 int aom_img_plane_height(const aom_image_t *img, int plane); 363 364 /*!\brief Add metadata to image. 365 * 366 * Adds metadata to aom_image_t. 367 * Function makes a copy of the provided data parameter. 368 * Metadata insertion point is controlled by insert_flag. 369 * 370 * \param[in] img Image descriptor 371 * \param[in] type Metadata type 372 * \param[in] data Metadata contents 373 * \param[in] sz Metadata contents size 374 * \param[in] insert_flag Metadata insert flag 375 * 376 * \return Returns 0 on success. If img or data is NULL, sz is 0, or memory 377 * allocation fails, it returns -1. 378 */ 379 int aom_img_add_metadata(aom_image_t *img, uint32_t type, const uint8_t *data, 380 size_t sz, aom_metadata_insert_flags_t insert_flag); 381 382 /*!\brief Return a metadata payload stored within the image metadata array. 383 * 384 * Gets the metadata (aom_metadata_t) at the indicated index in the image 385 * metadata array. 386 * 387 * \param[in] img Pointer to image descriptor to get metadata from 388 * \param[in] index Metadata index to get from metadata array 389 * 390 * \return Returns a const pointer to the selected metadata, if img and/or index 391 * is invalid, it returns NULL. 392 */ 393 const aom_metadata_t *aom_img_get_metadata(const aom_image_t *img, 394 size_t index); 395 396 /*!\brief Return the number of metadata blocks within the image. 397 * 398 * Gets the number of metadata blocks contained within the provided image 399 * metadata array. 400 * 401 * \param[in] img Pointer to image descriptor to get metadata number 402 * from. 403 * 404 * \return Returns the size of the metadata array. If img or metadata is NULL, 405 * it returns 0. 406 */ 407 size_t aom_img_num_metadata(const aom_image_t *img); 408 409 /*!\brief Remove metadata from image. 410 * 411 * Removes all metadata in image metadata list and sets metadata list pointer 412 * to NULL. 413 * 414 * \param[in] img Image descriptor 415 */ 416 void aom_img_remove_metadata(aom_image_t *img); 417 418 /*!\brief Allocate memory for aom_metadata struct. 419 * 420 * Allocates storage for the metadata payload, sets its type and copies the 421 * payload data into the aom_metadata struct. A metadata payload buffer of size 422 * sz is allocated and sz bytes are copied from data into the payload buffer. 423 * 424 * \param[in] type Metadata type 425 * \param[in] data Metadata data pointer 426 * \param[in] sz Metadata size 427 * \param[in] insert_flag Metadata insert flag 428 * 429 * \return Returns the newly allocated aom_metadata struct. If data is NULL, 430 * sz is 0, or memory allocation fails, it returns NULL. 431 */ 432 aom_metadata_t *aom_img_metadata_alloc(uint32_t type, const uint8_t *data, 433 size_t sz, 434 aom_metadata_insert_flags_t insert_flag); 435 436 /*!\brief Free metadata struct. 437 * 438 * Free metadata struct and its buffer. 439 * 440 * \param[in] metadata Metadata struct pointer 441 */ 442 void aom_img_metadata_free(aom_metadata_t *metadata); 443 444 #ifdef __cplusplus 445 } // extern "C" 446 #endif 447 448 #endif // AOM_AOM_AOM_IMAGE_H_ 449