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 107 aom_transfer_characteristics */ 108 109 /*!\brief List of supported matrix coefficients */ 110 typedef enum aom_matrix_coefficients { 111 AOM_CICP_MC_IDENTITY = 0, /**< Identity matrix */ 112 AOM_CICP_MC_BT_709 = 1, /**< BT.709 */ 113 AOM_CICP_MC_UNSPECIFIED = 2, /**< Unspecified */ 114 AOM_CICP_MC_RESERVED_3 = 3, /**< For future use */ 115 AOM_CICP_MC_FCC = 4, /**< US FCC 73.628 */ 116 AOM_CICP_MC_BT_470_B_G = 5, /**< BT.470 System B, G (historical) */ 117 AOM_CICP_MC_BT_601 = 6, /**< BT.601 */ 118 AOM_CICP_MC_SMPTE_240 = 7, /**< SMPTE 240 M */ 119 AOM_CICP_MC_SMPTE_YCGCO = 8, /**< YCgCo */ 120 AOM_CICP_MC_BT_2020_NCL = 121 9, /**< BT.2020 non-constant luminance, BT.2100 YCbCr */ 122 AOM_CICP_MC_BT_2020_CL = 10, /**< BT.2020 constant luminance */ 123 AOM_CICP_MC_SMPTE_2085 = 11, /**< SMPTE ST 2085 YDzDx */ 124 AOM_CICP_MC_CHROMAT_NCL = 125 12, /**< Chromaticity-derived non-constant luminance */ 126 AOM_CICP_MC_CHROMAT_CL = 13, /**< Chromaticity-derived constant luminance */ 127 AOM_CICP_MC_ICTCP = 14, /**< BT.2100 ICtCp */ 128 AOM_CICP_MC_RESERVED_15 = 15 /**< For future use (values 15-255) */ 129 } aom_matrix_coefficients_t; /**< alias for enum aom_matrix_coefficients */ 130 131 /*!\brief List of supported color range */ 132 typedef enum aom_color_range { 133 AOM_CR_STUDIO_RANGE = 0, /**<- Y [16..235], UV [16..240] (bit depth 8) */ 134 /**<- Y [64..940], UV [64..960] (bit depth 10) */ 135 /**<- Y [256..3760], UV [256..3840] (bit depth 12) */ 136 AOM_CR_FULL_RANGE = 1 /**<- YUV/RGB [0..255] (bit depth 8) */ 137 /**<- YUV/RGB [0..1023] (bit depth 10) */ 138 /**<- YUV/RGB [0..4095] (bit depth 12) */ 139 } aom_color_range_t; /**< alias for enum aom_color_range */ 140 141 /*!\brief List of chroma sample positions */ 142 typedef enum aom_chroma_sample_position { 143 AOM_CSP_UNKNOWN = 0, /**< Unknown */ 144 AOM_CSP_VERTICAL = 1, /**< Horizontally co-located with luma(0, 0)*/ 145 /**< sample, between two vertical samples */ 146 AOM_CSP_COLOCATED = 2, /**< Co-located with luma(0, 0) sample */ 147 AOM_CSP_RESERVED = 3 /**< Reserved value */ 148 } aom_chroma_sample_position_t; /**< alias for enum aom_chroma_sample_position 149 */ 150 151 /*!\brief List of insert flags for Metadata 152 * 153 * These flags control how the library treats metadata during encode. 154 * 155 * While encoding, when metadata is added to an aom_image via 156 * aom_img_add_metadata(), the flag passed along with the metadata will 157 * determine where the metadata OBU will be placed in the encoded OBU stream. 158 * Metadata will be emitted into the output stream within the next temporal unit 159 * if it satisfies the specified insertion flag. 160 * 161 * During decoding, when the library encounters a metadata OBU, it is always 162 * flagged as AOM_MIF_ANY_FRAME and emitted with the next output aom_image. 163 */ 164 typedef enum aom_metadata_insert_flags { 165 AOM_MIF_NON_KEY_FRAME = 0, /**< Adds metadata if it's not keyframe */ 166 AOM_MIF_KEY_FRAME = 1, /**< Adds metadata only if it's a keyframe */ 167 AOM_MIF_ANY_FRAME = 2 /**< Adds metadata to any type of frame */ 168 } aom_metadata_insert_flags_t; 169 170 /*!\brief Array of aom_metadata structs for an image. */ 171 typedef struct aom_metadata_array aom_metadata_array_t; 172 173 /*!\brief Metadata payload. */ 174 typedef struct aom_metadata { 175 uint32_t type; /**< Metadata type */ 176 uint8_t *payload; /**< Metadata payload data */ 177 size_t sz; /**< Metadata payload size */ 178 aom_metadata_insert_flags_t insert_flag; /**< Metadata insertion flag */ 179 } aom_metadata_t; 180 181 /**\brief Image Descriptor */ 182 typedef struct aom_image { 183 aom_img_fmt_t fmt; /**< Image Format */ 184 aom_color_primaries_t cp; /**< CICP Color Primaries */ 185 aom_transfer_characteristics_t tc; /**< CICP Transfer Characteristics */ 186 aom_matrix_coefficients_t mc; /**< CICP Matrix Coefficients */ 187 int monochrome; /**< Whether image is monochrome */ 188 aom_chroma_sample_position_t csp; /**< chroma sample position */ 189 aom_color_range_t range; /**< Color Range */ 190 191 /* Image storage dimensions */ 192 unsigned int w; /**< Stored image width */ 193 unsigned int h; /**< Stored image height */ 194 unsigned int bit_depth; /**< Stored image bit-depth */ 195 196 /* Image display dimensions */ 197 unsigned int d_w; /**< Displayed image width */ 198 unsigned int d_h; /**< Displayed image height */ 199 200 /* Image intended rendering dimensions */ 201 unsigned int r_w; /**< Intended rendering image width */ 202 unsigned int r_h; /**< Intended rendering image height */ 203 204 /* Chroma subsampling info */ 205 unsigned int x_chroma_shift; /**< subsampling order, X */ 206 unsigned int y_chroma_shift; /**< subsampling order, Y */ 207 208 /* Image data pointers. */ 209 #define AOM_PLANE_PACKED 0 /**< To be used for all packed formats */ 210 #define AOM_PLANE_Y 0 /**< Y (Luminance) plane */ 211 #define AOM_PLANE_U 1 /**< U (Chroma) plane */ 212 #define AOM_PLANE_V 2 /**< V (Chroma) plane */ 213 /* planes[AOM_PLANE_V] = NULL and stride[AOM_PLANE_V] = 0 when fmt == 214 * AOM_IMG_FMT_NV12 */ 215 unsigned char *planes[3]; /**< pointer to the top left pixel for each plane */ 216 int stride[3]; /**< stride between rows for each plane */ 217 size_t sz; /**< data size */ 218 219 int bps; /**< bits per sample (for packed formats) */ 220 221 int temporal_id; /**< Temporal layer Id of image */ 222 int spatial_id; /**< Spatial layer Id of image */ 223 224 /*!\brief The following member may be set by the application to associate 225 * data with this image. 226 */ 227 void *user_priv; 228 229 /* The following members should be treated as private. */ 230 unsigned char *img_data; /**< private */ 231 int img_data_owner; /**< private */ 232 int self_allocd; /**< private */ 233 234 aom_metadata_array_t 235 *metadata; /**< Metadata payloads associated with the image. */ 236 237 void *fb_priv; /**< Frame buffer data associated with the image. */ 238 } aom_image_t; /**< alias for struct aom_image */ 239 240 /*!\brief Open a descriptor, allocating storage for the underlying image 241 * 242 * Returns a descriptor for storing an image of the given format. The 243 * storage for the image is allocated on the heap. 244 * 245 * \param[in] img Pointer to storage for descriptor. If this parameter 246 * is NULL, the storage for the descriptor will be 247 * allocated on the heap. 248 * \param[in] fmt Format for the image 249 * \param[in] d_w Width of the image. Must not exceed 0x08000000 250 * (2^27). 251 * \param[in] d_h Height of the image. Must not exceed 0x08000000 252 * (2^27). 253 * \param[in] align Alignment, in bytes, of the image buffer and 254 * each row in the image (stride). Must not exceed 255 * 65536. 256 * 257 * \return Returns a pointer to the initialized image descriptor. If the img 258 * parameter is non-null, the value of the img parameter will be 259 * returned. 260 */ 261 aom_image_t *aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, 262 unsigned int d_w, unsigned int d_h, 263 unsigned int align); 264 265 /*!\brief Open a descriptor, using existing storage for the underlying image 266 * 267 * Returns a descriptor for storing an image of the given format. The 268 * storage for the image has been allocated elsewhere, and a descriptor is 269 * desired to "wrap" that storage. 270 * 271 * \param[in] img Pointer to storage for descriptor. If this parameter 272 * is NULL, the storage for the descriptor will be 273 * allocated on the heap. 274 * \param[in] fmt Format for the image 275 * \param[in] d_w Width of the image. Must not exceed 0x08000000 276 * (2^27). 277 * \param[in] d_h Height of the image. Must not exceed 0x08000000 278 * (2^27). 279 * \param[in] align Alignment, in bytes, of each row in the image 280 * (stride). Must not exceed 65536. 281 * \param[in] img_data Storage to use for the image. The storage must 282 * outlive the returned image descriptor; it can be 283 * disposed of after calling aom_img_free(). 284 * 285 * \return Returns a pointer to the initialized image descriptor. If the img 286 * parameter is non-null, the value of the img parameter will be 287 * returned. 288 */ 289 aom_image_t *aom_img_wrap(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, 290 unsigned int d_h, unsigned int align, 291 unsigned char *img_data); 292 293 /*!\brief Open a descriptor, allocating storage for the underlying image with a 294 * border 295 * 296 * Returns a descriptor for storing an image of the given format and its 297 * borders. The storage for the image is allocated on the heap. 298 * 299 * \param[in] img Pointer to storage for descriptor. If this parameter 300 * is NULL, the storage for the descriptor will be 301 * allocated on the heap. 302 * \param[in] fmt Format for the image 303 * \param[in] d_w Width of the image. Must not exceed 0x08000000 304 * (2^27). 305 * \param[in] d_h Height of the image. Must not exceed 0x08000000 306 * (2^27). 307 * \param[in] align Alignment, in bytes, of the image buffer and 308 * each row in the image (stride). Must not exceed 309 * 65536. 310 * \param[in] size_align Alignment, in pixels, of the image width and height. 311 * Must not exceed 65536. 312 * \param[in] border A border that is padded on four sides of the image. 313 * Must not exceed 65536. 314 * 315 * \return Returns a pointer to the initialized image descriptor. If the img 316 * parameter is non-null, the value of the img parameter will be 317 * returned. 318 */ 319 aom_image_t *aom_img_alloc_with_border(aom_image_t *img, aom_img_fmt_t fmt, 320 unsigned int d_w, unsigned int d_h, 321 unsigned int align, 322 unsigned int size_align, 323 unsigned int border); 324 325 /*!\brief Set the rectangle identifying the displayed portion of the image 326 * 327 * Updates the displayed rectangle (aka viewport) on the image surface to 328 * match the specified coordinates and size. Specifically, sets img->d_w, 329 * img->d_h, and elements of the img->planes[] array. 330 * 331 * \param[in] img Image descriptor 332 * \param[in] x leftmost column 333 * \param[in] y topmost row 334 * \param[in] w width 335 * \param[in] h height 336 * \param[in] border A border that is padded on four sides of the image. 337 * 338 * \return 0 if the requested rectangle is valid, nonzero (-1) otherwise. 339 */ 340 int aom_img_set_rect(aom_image_t *img, unsigned int x, unsigned int y, 341 unsigned int w, unsigned int h, unsigned int border); 342 343 /*!\brief Flip the image vertically (top for bottom) 344 * 345 * Adjusts the image descriptor's pointers and strides to make the image 346 * be referenced upside-down. 347 * 348 * \param[in] img Image descriptor 349 */ 350 void aom_img_flip(aom_image_t *img); 351 352 /*!\brief Close an image descriptor 353 * 354 * Frees all allocated storage associated with an image descriptor. 355 * 356 * \param[in] img Image descriptor 357 */ 358 void aom_img_free(aom_image_t *img); 359 360 /*!\brief Get the width of a plane 361 * 362 * Get the width of a plane of an image 363 * 364 * \param[in] img Image descriptor 365 * \param[in] plane Plane index 366 */ 367 int aom_img_plane_width(const aom_image_t *img, int plane); 368 369 /*!\brief Get the height of a plane 370 * 371 * Get the height of a plane of an image 372 * 373 * \param[in] img Image descriptor 374 * \param[in] plane Plane index 375 */ 376 int aom_img_plane_height(const aom_image_t *img, int plane); 377 378 /*!\brief Add metadata to image. 379 * 380 * Adds metadata to aom_image_t. 381 * Function makes a copy of the provided data parameter. 382 * Metadata insertion point is controlled by insert_flag. 383 * 384 * \param[in] img Image descriptor 385 * \param[in] type Metadata type 386 * \param[in] data Metadata contents 387 * \param[in] sz Metadata contents size 388 * \param[in] insert_flag Metadata insert flag 389 * 390 * \return Returns 0 on success. If img or data is NULL, sz is 0, or memory 391 * allocation fails, it returns -1. 392 */ 393 int aom_img_add_metadata(aom_image_t *img, uint32_t type, const uint8_t *data, 394 size_t sz, aom_metadata_insert_flags_t insert_flag); 395 396 /*!\brief Return a metadata payload stored within the image metadata array. 397 * 398 * Gets the metadata (aom_metadata_t) at the indicated index in the image 399 * metadata array. 400 * 401 * \param[in] img Pointer to image descriptor to get metadata from 402 * \param[in] index Metadata index to get from metadata array 403 * 404 * \return Returns a const pointer to the selected metadata, if img and/or index 405 * is invalid, it returns NULL. 406 */ 407 const aom_metadata_t *aom_img_get_metadata(const aom_image_t *img, 408 size_t index); 409 410 /*!\brief Return the number of metadata blocks within the image. 411 * 412 * Gets the number of metadata blocks contained within the provided image 413 * metadata array. 414 * 415 * \param[in] img Pointer to image descriptor to get metadata number 416 * from. 417 * 418 * \return Returns the size of the metadata array. If img or metadata is NULL, 419 * it returns 0. 420 */ 421 size_t aom_img_num_metadata(const aom_image_t *img); 422 423 /*!\brief Remove metadata from image. 424 * 425 * Removes all metadata in image metadata list and sets metadata list pointer 426 * to NULL. 427 * 428 * \param[in] img Image descriptor 429 */ 430 void aom_img_remove_metadata(aom_image_t *img); 431 432 /*!\brief Allocate memory for aom_metadata struct. 433 * 434 * Allocates storage for the metadata payload, sets its type and copies the 435 * payload data into the aom_metadata struct. A metadata payload buffer of size 436 * sz is allocated and sz bytes are copied from data into the payload buffer. 437 * 438 * \param[in] type Metadata type 439 * \param[in] data Metadata data pointer 440 * \param[in] sz Metadata size 441 * \param[in] insert_flag Metadata insert flag 442 * 443 * \return Returns the newly allocated aom_metadata struct. If data is NULL, 444 * sz is 0, or memory allocation fails, it returns NULL. 445 */ 446 aom_metadata_t *aom_img_metadata_alloc(uint32_t type, const uint8_t *data, 447 size_t sz, 448 aom_metadata_insert_flags_t insert_flag); 449 450 /*!\brief Free metadata struct. 451 * 452 * Free metadata struct and its buffer. 453 * 454 * \param[in] metadata Metadata struct pointer 455 */ 456 void aom_img_metadata_free(aom_metadata_t *metadata); 457 458 #ifdef __cplusplus 459 } // extern "C" 460 #endif 461 462 #endif // AOM_AOM_AOM_IMAGE_H_ 463