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 282 * 283 * \return Returns a pointer to the initialized image descriptor. If the img 284 * parameter is non-null, the value of the img parameter will be 285 * returned. 286 */ 287 aom_image_t *aom_img_wrap(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, 288 unsigned int d_h, unsigned int align, 289 unsigned char *img_data); 290 291 /*!\brief Open a descriptor, allocating storage for the underlying image with a 292 * border 293 * 294 * Returns a descriptor for storing an image of the given format and its 295 * borders. The storage for the image is allocated on the heap. 296 * 297 * \param[in] img Pointer to storage for descriptor. If this parameter 298 * is NULL, the storage for the descriptor will be 299 * allocated on the heap. 300 * \param[in] fmt Format for the image 301 * \param[in] d_w Width of the image. Must not exceed 0x08000000 302 * (2^27). 303 * \param[in] d_h Height of the image. Must not exceed 0x08000000 304 * (2^27). 305 * \param[in] align Alignment, in bytes, of the image buffer and 306 * each row in the image (stride). Must not exceed 307 * 65536. 308 * \param[in] size_align Alignment, in pixels, of the image width and height. 309 * Must not exceed 65536. 310 * \param[in] border A border that is padded on four sides of the image. 311 * Must not exceed 65536. 312 * 313 * \return Returns a pointer to the initialized image descriptor. If the img 314 * parameter is non-null, the value of the img parameter will be 315 * returned. 316 */ 317 aom_image_t *aom_img_alloc_with_border(aom_image_t *img, aom_img_fmt_t fmt, 318 unsigned int d_w, unsigned int d_h, 319 unsigned int align, 320 unsigned int size_align, 321 unsigned int border); 322 323 /*!\brief Set the rectangle identifying the displayed portion of the image 324 * 325 * Updates the displayed rectangle (aka viewport) on the image surface to 326 * match the specified coordinates and size. Specifically, sets img->d_w, 327 * img->d_h, and elements of the img->planes[] array. 328 * 329 * \param[in] img Image descriptor 330 * \param[in] x leftmost column 331 * \param[in] y topmost row 332 * \param[in] w width 333 * \param[in] h height 334 * \param[in] border A border that is padded on four sides of the image. 335 * 336 * \return 0 if the requested rectangle is valid, nonzero (-1) otherwise. 337 */ 338 int aom_img_set_rect(aom_image_t *img, unsigned int x, unsigned int y, 339 unsigned int w, unsigned int h, unsigned int border); 340 341 /*!\brief Flip the image vertically (top for bottom) 342 * 343 * Adjusts the image descriptor's pointers and strides to make the image 344 * be referenced upside-down. 345 * 346 * \param[in] img Image descriptor 347 */ 348 void aom_img_flip(aom_image_t *img); 349 350 /*!\brief Close an image descriptor 351 * 352 * Frees all allocated storage associated with an image descriptor. 353 * 354 * \param[in] img Image descriptor 355 */ 356 void aom_img_free(aom_image_t *img); 357 358 /*!\brief Get the width of a plane 359 * 360 * Get the width of a plane of an image 361 * 362 * \param[in] img Image descriptor 363 * \param[in] plane Plane index 364 */ 365 int aom_img_plane_width(const aom_image_t *img, int plane); 366 367 /*!\brief Get the height of a plane 368 * 369 * Get the height of a plane of an image 370 * 371 * \param[in] img Image descriptor 372 * \param[in] plane Plane index 373 */ 374 int aom_img_plane_height(const aom_image_t *img, int plane); 375 376 /*!\brief Add metadata to image. 377 * 378 * Adds metadata to aom_image_t. 379 * Function makes a copy of the provided data parameter. 380 * Metadata insertion point is controlled by insert_flag. 381 * 382 * \param[in] img Image descriptor 383 * \param[in] type Metadata type 384 * \param[in] data Metadata contents 385 * \param[in] sz Metadata contents size 386 * \param[in] insert_flag Metadata insert flag 387 * 388 * \return Returns 0 on success. If img or data is NULL, sz is 0, or memory 389 * allocation fails, it returns -1. 390 */ 391 int aom_img_add_metadata(aom_image_t *img, uint32_t type, const uint8_t *data, 392 size_t sz, aom_metadata_insert_flags_t insert_flag); 393 394 /*!\brief Return a metadata payload stored within the image metadata array. 395 * 396 * Gets the metadata (aom_metadata_t) at the indicated index in the image 397 * metadata array. 398 * 399 * \param[in] img Pointer to image descriptor to get metadata from 400 * \param[in] index Metadata index to get from metadata array 401 * 402 * \return Returns a const pointer to the selected metadata, if img and/or index 403 * is invalid, it returns NULL. 404 */ 405 const aom_metadata_t *aom_img_get_metadata(const aom_image_t *img, 406 size_t index); 407 408 /*!\brief Return the number of metadata blocks within the image. 409 * 410 * Gets the number of metadata blocks contained within the provided image 411 * metadata array. 412 * 413 * \param[in] img Pointer to image descriptor to get metadata number 414 * from. 415 * 416 * \return Returns the size of the metadata array. If img or metadata is NULL, 417 * it returns 0. 418 */ 419 size_t aom_img_num_metadata(const aom_image_t *img); 420 421 /*!\brief Remove metadata from image. 422 * 423 * Removes all metadata in image metadata list and sets metadata list pointer 424 * to NULL. 425 * 426 * \param[in] img Image descriptor 427 */ 428 void aom_img_remove_metadata(aom_image_t *img); 429 430 /*!\brief Allocate memory for aom_metadata struct. 431 * 432 * Allocates storage for the metadata payload, sets its type and copies the 433 * payload data into the aom_metadata struct. A metadata payload buffer of size 434 * sz is allocated and sz bytes are copied from data into the payload buffer. 435 * 436 * \param[in] type Metadata type 437 * \param[in] data Metadata data pointer 438 * \param[in] sz Metadata size 439 * \param[in] insert_flag Metadata insert flag 440 * 441 * \return Returns the newly allocated aom_metadata struct. If data is NULL, 442 * sz is 0, or memory allocation fails, it returns NULL. 443 */ 444 aom_metadata_t *aom_img_metadata_alloc(uint32_t type, const uint8_t *data, 445 size_t sz, 446 aom_metadata_insert_flags_t insert_flag); 447 448 /*!\brief Free metadata struct. 449 * 450 * Free metadata struct and its buffer. 451 * 452 * \param[in] metadata Metadata struct pointer 453 */ 454 void aom_img_metadata_free(aom_metadata_t *metadata); 455 456 #ifdef __cplusplus 457 } // extern "C" 458 #endif 459 460 #endif // AOM_AOM_AOM_IMAGE_H_ 461