1 /* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 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_I42016 = VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH, 47 VPX_IMG_FMT_I42216 = VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH, 48 VPX_IMG_FMT_I44416 = VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH, 49 VPX_IMG_FMT_I44016 = VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH 50 } vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */ 51 52 /*!\brief List of supported color spaces */ 53 typedef enum vpx_color_space { 54 VPX_CS_UNKNOWN = 0, /**< Unknown */ 55 VPX_CS_BT_601 = 1, /**< BT.601 */ 56 VPX_CS_BT_709 = 2, /**< BT.709 */ 57 VPX_CS_SMPTE_170 = 3, /**< SMPTE.170 */ 58 VPX_CS_SMPTE_240 = 4, /**< SMPTE.240 */ 59 VPX_CS_BT_2020 = 5, /**< BT.2020 */ 60 VPX_CS_RESERVED = 6, /**< Reserved */ 61 VPX_CS_SRGB = 7 /**< sRGB */ 62 } vpx_color_space_t; /**< alias for enum vpx_color_space */ 63 64 /*!\brief List of supported color range */ 65 typedef enum vpx_color_range { 66 VPX_CR_STUDIO_RANGE = 0, /**< Y [16..235], UV [16..240] */ 67 VPX_CR_FULL_RANGE = 1 /**< YUV/RGB [0..255] */ 68 } vpx_color_range_t; /**< alias for enum vpx_color_range */ 69 70 /**\brief Image Descriptor */ 71 typedef struct vpx_image { 72 vpx_img_fmt_t fmt; /**< Image Format */ 73 vpx_color_space_t cs; /**< Color Space */ 74 vpx_color_range_t range; /**< Color Range */ 75 76 /* Image storage dimensions */ 77 unsigned int w; /**< Stored image width */ 78 unsigned int h; /**< Stored image height */ 79 unsigned int bit_depth; /**< Stored image bit-depth */ 80 81 /* Image display dimensions */ 82 unsigned int d_w; /**< Displayed image width */ 83 unsigned int d_h; /**< Displayed image height */ 84 85 /* Image intended rendering dimensions */ 86 unsigned int r_w; /**< Intended rendering image width */ 87 unsigned int r_h; /**< Intended rendering image height */ 88 89 /* Chroma subsampling info */ 90 unsigned int x_chroma_shift; /**< subsampling order, X */ 91 unsigned int y_chroma_shift; /**< subsampling order, Y */ 92 93 /* Image data pointers. */ 94 #define VPX_PLANE_PACKED 0 /**< To be used for all packed formats */ 95 #define VPX_PLANE_Y 0 /**< Y (Luminance) plane */ 96 #define VPX_PLANE_U 1 /**< U (Chroma) plane */ 97 #define VPX_PLANE_V 2 /**< V (Chroma) plane */ 98 #define VPX_PLANE_ALPHA 3 /**< A (Transparency) plane */ 99 unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */ 100 int stride[4]; /**< stride between rows for each plane */ 101 102 int bps; /**< bits per sample (for packed formats) */ 103 104 /*!\brief The following member may be set by the application to associate 105 * data with this image. 106 */ 107 void *user_priv; 108 109 /* The following members should be treated as private. */ 110 unsigned char *img_data; /**< private */ 111 int img_data_owner; /**< private */ 112 int self_allocd; /**< private */ 113 114 void *fb_priv; /**< Frame buffer data associated with the image. */ 115 } vpx_image_t; /**< alias for struct vpx_image */ 116 117 /**\brief Representation of a rectangle on a surface */ 118 typedef struct vpx_image_rect { 119 unsigned int x; /**< leftmost column */ 120 unsigned int y; /**< topmost row */ 121 unsigned int w; /**< width */ 122 unsigned int h; /**< height */ 123 } vpx_image_rect_t; /**< alias for struct vpx_image_rect */ 124 125 /*!\brief Open a descriptor, allocating storage for the underlying image 126 * 127 * Returns a descriptor for storing an image of the given format. The 128 * storage for the descriptor is allocated on the heap. 129 * 130 * \param[in] img Pointer to storage for descriptor. If this parameter 131 * is NULL, the storage for the descriptor will be 132 * allocated on the heap. 133 * \param[in] fmt Format for the image 134 * \param[in] d_w Width of the image 135 * \param[in] d_h Height of the image 136 * \param[in] align Alignment, in bytes, of the image buffer and 137 * each row in the image(stride). 138 * 139 * \return Returns a pointer to the initialized image descriptor. If the img 140 * parameter is non-null, the value of the img parameter will be 141 * returned. 142 */ 143 vpx_image_t *vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, 144 unsigned int d_w, unsigned int d_h, 145 unsigned int align); 146 147 /*!\brief Open a descriptor, using existing storage for the underlying image 148 * 149 * Returns a descriptor for storing an image of the given format. The 150 * storage for descriptor has been allocated elsewhere, and a descriptor is 151 * desired to "wrap" that storage. 152 * 153 * \param[in] img Pointer to storage for descriptor. If this 154 * parameter is NULL, the storage for the descriptor 155 * will be allocated on the heap. 156 * \param[in] fmt Format for the image 157 * \param[in] d_w Width of the image 158 * \param[in] d_h Height of the image 159 * \param[in] stride_align Alignment, in bytes, of each row in the image. 160 * \param[in] img_data Storage to use for the image 161 * 162 * \return Returns a pointer to the initialized image descriptor. If the img 163 * parameter is non-null, the value of the img parameter will be 164 * returned. 165 */ 166 vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, 167 unsigned int d_h, unsigned int stride_align, 168 unsigned char *img_data); 169 170 /*!\brief Set the rectangle identifying the displayed portion of the image 171 * 172 * Updates the displayed rectangle (aka viewport) on the image surface to 173 * match the specified coordinates and size. 174 * 175 * \param[in] img Image descriptor 176 * \param[in] x leftmost column 177 * \param[in] y topmost row 178 * \param[in] w width 179 * \param[in] h height 180 * 181 * \return 0 if the requested rectangle is valid, nonzero otherwise. 182 */ 183 int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y, 184 unsigned int w, unsigned int h); 185 186 /*!\brief Flip the image vertically (top for bottom) 187 * 188 * Adjusts the image descriptor's pointers and strides to make the image 189 * be referenced upside-down. 190 * 191 * \param[in] img Image descriptor 192 */ 193 void vpx_img_flip(vpx_image_t *img); 194 195 /*!\brief Close an image descriptor 196 * 197 * Frees all allocated storage associated with an image descriptor. 198 * 199 * \param[in] img Image descriptor 200 */ 201 void vpx_img_free(vpx_image_t *img); 202 203 #ifdef __cplusplus 204 } // extern "C" 205 #endif 206 207 #endif // VPX_VPX_VPX_IMAGE_H_ 208