| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 |
| 11 | /*!\file |
| 12 | * \brief Describes the vpx image descriptor and associated operations |
| 13 | * |
| 14 | */ |
| 15 | #ifndef VPX_VPX_VPX_IMAGE_H_ |
| 16 | #define VPX_VPX_VPX_IMAGE_H_ |
| 17 |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 |
| 22 | /*!\brief Current ABI version number |
| 23 | * |
| 24 | * \internal |
| 25 | * If this file is altered in any way that changes the ABI, this value |
| 26 | * must be bumped. Examples include, but are not limited to, changing |
| 27 | * types, removing or reassigning enums, adding/removing/rearranging |
| 28 | * fields to structures |
| 29 | */ |
| 30 | #define VPX_IMAGE_ABI_VERSION (5) /**<\hideinitializer*/ |
| 31 |
| 32 | #define VPX_IMG_FMT_PLANAR 0x100 /**< Image is a planar format. */ |
| 33 | #define VPX_IMG_FMT_UV_FLIP 0x200 /**< V plane precedes U in memory. */ |
| 34 | #define VPX_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel. */ |
| 35 | #define VPX_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */ |
| 36 |
| 37 | /*!\brief List of supported image formats */ |
| 38 | typedef enum vpx_img_fmt { |
| 39 | VPX_IMG_FMT_NONE, |
| 40 | VPX_IMG_FMT_YV12 = |
| 41 | VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */ |
| 42 | VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2, |
| 43 | VPX_IMG_FMT_I422 = VPX_IMG_FMT_PLANAR | 5, |
| 44 | VPX_IMG_FMT_I444 = VPX_IMG_FMT_PLANAR | 6, |
| 45 | VPX_IMG_FMT_I440 = VPX_IMG_FMT_PLANAR | 7, |
| 46 | VPX_IMG_FMT_NV12 = VPX_IMG_FMT_PLANAR | 9, |
| 47 | VPX_IMG_FMT_I42016 = VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH, |
| 48 | VPX_IMG_FMT_I42216 = VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH, |
| 49 | VPX_IMG_FMT_I44416 = VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH, |
| 50 | VPX_IMG_FMT_I44016 = VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH |
| 51 | } vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */ |
| 52 |
| 53 | /*!\brief List of supported color spaces */ |
| 54 | typedef enum vpx_color_space { |
| 55 | VPX_CS_UNKNOWN = 0, /**< Unknown */ |
| 56 | VPX_CS_BT_601 = 1, /**< BT.601 */ |
| 57 | VPX_CS_BT_709 = 2, /**< BT.709 */ |
| 58 | VPX_CS_SMPTE_170 = 3, /**< SMPTE.170 */ |
| 59 | VPX_CS_SMPTE_240 = 4, /**< SMPTE.240 */ |
| 60 | VPX_CS_BT_2020 = 5, /**< BT.2020 */ |
| 61 | VPX_CS_RESERVED = 6, /**< Reserved */ |
| 62 | VPX_CS_SRGB = 7 /**< sRGB */ |
| 63 | } vpx_color_space_t; /**< alias for enum vpx_color_space */ |
| 64 |
| 65 | /*!\brief List of supported color range */ |
| 66 | typedef enum vpx_color_range { |
| 67 | VPX_CR_STUDIO_RANGE = 0, /**<- Y [16..235], UV [16..240] (bit depth 8) */ |
| 68 | /**<- Y [64..940], UV [64..960] (bit depth 10) */ |
| 69 | /**<- Y [256..3760], UV [256..3840] (bit depth 12) */ |
| 70 | VPX_CR_FULL_RANGE = 1 /**<- YUV/RGB [0..255] (bit depth 8) */ |
| 71 | /**<- YUV/RGB [0..1023] (bit depth 10) */ |
| 72 | /**<- YUV/RGB [0..4095] (bit depth 12) */ |
| 73 | } vpx_color_range_t; /**< alias for enum vpx_color_range */ |
| 74 |
| 75 | /**\brief Image Descriptor */ |
| 76 | typedef struct vpx_image { |
| 77 | vpx_img_fmt_t fmt; /**< Image Format */ |
| 78 | vpx_color_space_t cs; /**< Color Space */ |
| 79 | vpx_color_range_t range; /**< Color Range */ |
| 80 |
| 81 | /* Image storage dimensions */ |
| 82 | unsigned int w; /**< Stored image width */ |
| 83 | unsigned int h; /**< Stored image height */ |
| 84 | unsigned int bit_depth; /**< Stored image bit-depth */ |
| 85 |
| 86 | /* Image display dimensions */ |
| 87 | unsigned int d_w; /**< Displayed image width */ |
| 88 | unsigned int d_h; /**< Displayed image height */ |
| 89 |
| 90 | /* Image intended rendering dimensions */ |
| 91 | unsigned int r_w; /**< Intended rendering image width */ |
| 92 | unsigned int r_h; /**< Intended rendering image height */ |
| 93 |
| 94 | /* Chroma subsampling info */ |
| 95 | unsigned int x_chroma_shift; /**< subsampling order, X */ |
| 96 | unsigned int y_chroma_shift; /**< subsampling order, Y */ |
| 97 |
| 98 | /* Image data pointers. */ |
| 99 | #define VPX_PLANE_PACKED 0 /**< To be used for all packed formats */ |
| 100 | #define VPX_PLANE_Y 0 /**< Y (Luminance) plane */ |
| 101 | #define VPX_PLANE_U 1 /**< U (Chroma) plane */ |
| 102 | #define VPX_PLANE_V 2 /**< V (Chroma) plane */ |
| 103 | #define VPX_PLANE_ALPHA 3 /**< A (Transparency) plane */ |
| 104 | unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */ |
| 105 | int stride[4]; /**< stride between rows for each plane */ |
| 106 |
| 107 | int bps; /**< bits per sample (for packed formats) */ |
| 108 |
| 109 | /*!\brief The following member may be set by the application to associate |
| 110 | * data with this image. |
| 111 | */ |
| 112 | void *user_priv; |
| 113 |
| 114 | /* The following members should be treated as private. */ |
| 115 | unsigned char *img_data; /**< private */ |
| 116 | int img_data_owner; /**< private */ |
| 117 | int self_allocd; /**< private */ |
| 118 |
| 119 | void *fb_priv; /**< Frame buffer data associated with the image. */ |
| 120 | } vpx_image_t; /**< alias for struct vpx_image */ |
| 121 |
| 122 | /**\brief Representation of a rectangle on a surface */ |
| 123 | typedef struct vpx_image_rect { |
| 124 | unsigned int x; /**< leftmost column */ |
| 125 | unsigned int y; /**< topmost row */ |
| 126 | unsigned int w; /**< width */ |
| 127 | unsigned int h; /**< height */ |
| 128 | } vpx_image_rect_t; /**< alias for struct vpx_image_rect */ |
| 129 |
| 130 | /*!\brief Open a descriptor, allocating storage for the underlying image |
| 131 | * |
| 132 | * Returns a descriptor for storing an image of the given format. The |
| 133 | * storage for the image is allocated on the heap. |
| 134 | * |
| 135 | * \param[in] img Pointer to storage for descriptor. If this parameter |
| 136 | * is NULL, the storage for the descriptor will be |
| 137 | * allocated on the heap. |
| 138 | * \param[in] fmt Format for the image |
| 139 | * \param[in] d_w Width of the image. Must not exceed 0x08000000 |
| 140 | * (2^27). |
| 141 | * \param[in] d_h Height of the image. Must not exceed 0x08000000 |
| 142 | * (2^27). |
| 143 | * \param[in] align Alignment, in bytes, of the image buffer and |
| 144 | * each row in the image (stride). Must not exceed |
| 145 | * 65536. |
| 146 | * |
| 147 | * \return Returns a pointer to the initialized image descriptor. If the img |
| 148 | * parameter is non-null, the value of the img parameter will be |
| 149 | * returned. |
| 150 | */ |
| 151 | vpx_image_t *vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, |
| 152 | unsigned int d_w, unsigned int d_h, |
| 153 | unsigned int align); |
| 154 |
| 155 | /*!\brief Open a descriptor, using existing storage for the underlying image |
| 156 | * |
| 157 | * Returns a descriptor for storing an image of the given format. The |
| 158 | * storage for the image has been allocated elsewhere, and a descriptor is |
| 159 | * desired to "wrap" that storage. |
| 160 | * |
| 161 | * \param[in] img Pointer to storage for descriptor. If this |
| 162 | * parameter is NULL, the storage for the descriptor |
| 163 | * will be allocated on the heap. |
| 164 | * \param[in] fmt Format for the image |
| 165 | * \param[in] d_w Width of the image. Must not exceed 0x08000000 |
| 166 | * (2^27). |
| 167 | * \param[in] d_h Height of the image. Must not exceed 0x08000000 |
| 168 | * (2^27). |
| 169 | * \param[in] stride_align Alignment, in bytes, of each row in the image |
| 170 | * (stride). Must not exceed 65536. |
| 171 | * \param[in] img_data Storage to use for the image. The storage must |
| 172 | * outlive the returned image descriptor; it can be |
| 173 | * disposed of after calling vpx_img_free(). |
| 174 | * |
| 175 | * \return Returns a pointer to the initialized image descriptor. If the img |
| 176 | * parameter is non-null, the value of the img parameter will be |
| 177 | * returned. |
| 178 | * |
| 179 | * \note \a img_data is required to have a minimum allocation size that |
| 180 | * satisfies the requirements of the \a fmt, \a d_w, \a d_h and \a |
| 181 | * stride_align parameters. This size can be calculated as follows (see |
| 182 | * \c img_alloc_helper in the vpx_image.c file in the libvpx source tree |
| 183 | * for more detail): |
| 184 | * \code |
| 185 | * align = (1 << x_chroma_shift) - 1; |
| 186 | * w = (d_w + align) & ~align; |
| 187 | * align = (1 << y_chroma_shift) - 1; |
| 188 | * h = (d_h + align) & ~align; |
| 189 | * |
| 190 | * s = (fmt & VPX_IMG_FMT_PLANAR) ? w : (uint64_t)bps * w / 8; |
| 191 | * s = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s * 2 : s; |
| 192 | * s = (s + stride_align - 1) & ~((uint64_t)stride_align - 1); |
| 193 | * s = (fmt & VPX_IMG_FMT_HIGHBITDEPTH) ? s / 2 : s; |
| 194 | * alloc_size = (fmt & VPX_IMG_FMT_PLANAR) ? (uint64_t)h * s * bps / 8 |
| 195 | * : (uint64_t)h * s; |
| 196 | * \endcode |
| 197 | * \a x_chroma_shift, \a y_chroma_shift and \a bps can be obtained by calling |
| 198 | * \ref vpx_img_wrap with a non-\c NULL \a img_data parameter. The \c |
| 199 | * vpx_image_t pointer should \em not be used in other API calls until \em after |
| 200 | * a successful call to \ref vpx_img_wrap with a valid image buffer. For |
| 201 | * example: |
| 202 | * \code |
| 203 | * vpx_img_wrap(img, fmt, d_w, d_h, stride_align, (unsigned char *)1); |
| 204 | * ... calculate buffer size and allocate buffer as described earlier |
| 205 | * vpx_img_wrap(img, fmt, d_w, d_h, stride_align, img_data); |
| 206 | * \endcode |
| 207 | */ |
| 208 | vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, |
| 209 | unsigned int d_h, unsigned int stride_align, |
| 210 | unsigned char *img_data); |
| 211 |
| 212 | /*!\brief Set the rectangle identifying the displayed portion of the image |
| 213 | * |
| 214 | * Updates the displayed rectangle (aka viewport) on the image surface to |
| 215 | * match the specified coordinates and size. Specifically, sets img->d_w, |
| 216 | * img->d_h, and elements of the img->planes[] array. |
| 217 | * |
| 218 | * \param[in] img Image descriptor |
| 219 | * \param[in] x leftmost column |
| 220 | * \param[in] y topmost row |
| 221 | * \param[in] w width |
| 222 | * \param[in] h height |
| 223 | * |
| 224 | * \return 0 if the requested rectangle is valid, nonzero (-1) otherwise. |
| 225 | */ |
| 226 | int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y, |
| 227 | unsigned int w, unsigned int h); |
| 228 |
| 229 | /*!\brief Flip the image vertically (top for bottom) |
| 230 | * |
| 231 | * Adjusts the image descriptor's pointers and strides to make the image |
| 232 | * be referenced upside-down. |
| 233 | * |
| 234 | * \param[in] img Image descriptor |
| 235 | */ |
| 236 | void vpx_img_flip(vpx_image_t *img); |
| 237 |
| 238 | /*!\brief Close an image descriptor |
| 239 | * |
| 240 | * Frees all allocated storage associated with an image descriptor. |
| 241 | * |
| 242 | * \param[in] img Image descriptor |
| 243 | */ |
| 244 | void vpx_img_free(vpx_image_t *img); |
| 245 |
| 246 | #ifdef __cplusplus |
| 247 | } // extern "C" |
| 248 | #endif |
| 249 |
| 250 | #endif // VPX_VPX_VPX_IMAGE_H_ |
| 251 |