Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | /*!\file |
michael@0 | 13 | * \brief Describes the vpx image descriptor and associated operations |
michael@0 | 14 | * |
michael@0 | 15 | */ |
michael@0 | 16 | #ifdef __cplusplus |
michael@0 | 17 | extern "C" { |
michael@0 | 18 | #endif |
michael@0 | 19 | |
michael@0 | 20 | #ifndef VPX_IMAGE_H |
michael@0 | 21 | #define VPX_IMAGE_H |
michael@0 | 22 | |
michael@0 | 23 | /*!\brief Current ABI version number |
michael@0 | 24 | * |
michael@0 | 25 | * \internal |
michael@0 | 26 | * If this file is altered in any way that changes the ABI, this value |
michael@0 | 27 | * must be bumped. Examples include, but are not limited to, changing |
michael@0 | 28 | * types, removing or reassigning enums, adding/removing/rearranging |
michael@0 | 29 | * fields to structures |
michael@0 | 30 | */ |
michael@0 | 31 | #define VPX_IMAGE_ABI_VERSION (1) /**<\hideinitializer*/ |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | #define VPX_IMG_FMT_PLANAR 0x100 /**< Image is a planar format */ |
michael@0 | 35 | #define VPX_IMG_FMT_UV_FLIP 0x200 /**< V plane precedes U plane in memory */ |
michael@0 | 36 | #define VPX_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel component */ |
michael@0 | 37 | |
michael@0 | 38 | |
michael@0 | 39 | /*!\brief List of supported image formats */ |
michael@0 | 40 | typedef enum vpx_img_fmt { |
michael@0 | 41 | VPX_IMG_FMT_NONE, |
michael@0 | 42 | VPX_IMG_FMT_RGB24, /**< 24 bit per pixel packed RGB */ |
michael@0 | 43 | VPX_IMG_FMT_RGB32, /**< 32 bit per pixel packed 0RGB */ |
michael@0 | 44 | VPX_IMG_FMT_RGB565, /**< 16 bit per pixel, 565 */ |
michael@0 | 45 | VPX_IMG_FMT_RGB555, /**< 16 bit per pixel, 555 */ |
michael@0 | 46 | VPX_IMG_FMT_UYVY, /**< UYVY packed YUV */ |
michael@0 | 47 | VPX_IMG_FMT_YUY2, /**< YUYV packed YUV */ |
michael@0 | 48 | VPX_IMG_FMT_YVYU, /**< YVYU packed YUV */ |
michael@0 | 49 | VPX_IMG_FMT_BGR24, /**< 24 bit per pixel packed BGR */ |
michael@0 | 50 | VPX_IMG_FMT_RGB32_LE, /**< 32 bit packed BGR0 */ |
michael@0 | 51 | VPX_IMG_FMT_ARGB, /**< 32 bit packed ARGB, alpha=255 */ |
michael@0 | 52 | VPX_IMG_FMT_ARGB_LE, /**< 32 bit packed BGRA, alpha=255 */ |
michael@0 | 53 | VPX_IMG_FMT_RGB565_LE, /**< 16 bit per pixel, gggbbbbb rrrrrggg */ |
michael@0 | 54 | VPX_IMG_FMT_RGB555_LE, /**< 16 bit per pixel, gggbbbbb 0rrrrrgg */ |
michael@0 | 55 | VPX_IMG_FMT_YV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */ |
michael@0 | 56 | VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2, |
michael@0 | 57 | VPX_IMG_FMT_VPXYV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 3, /** < planar 4:2:0 format with vpx color space */ |
michael@0 | 58 | VPX_IMG_FMT_VPXI420 = VPX_IMG_FMT_PLANAR | 4, |
michael@0 | 59 | VPX_IMG_FMT_I422 = VPX_IMG_FMT_PLANAR | 5, |
michael@0 | 60 | VPX_IMG_FMT_I444 = VPX_IMG_FMT_PLANAR | 6, |
michael@0 | 61 | VPX_IMG_FMT_444A = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_HAS_ALPHA | 7 |
michael@0 | 62 | } vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */ |
michael@0 | 63 | |
michael@0 | 64 | #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT |
michael@0 | 65 | #define IMG_FMT_PLANAR VPX_IMG_FMT_PLANAR /**< \deprecated Use #VPX_IMG_FMT_PLANAR */ |
michael@0 | 66 | #define IMG_FMT_UV_FLIP VPX_IMG_FMT_UV_FLIP /**< \deprecated Use #VPX_IMG_FMT_UV_FLIP */ |
michael@0 | 67 | #define IMG_FMT_HAS_ALPHA VPX_IMG_FMT_HAS_ALPHA /**< \deprecated Use #VPX_IMG_FMT_HAS_ALPHA */ |
michael@0 | 68 | |
michael@0 | 69 | /*!\brief Deprecated list of supported image formats |
michael@0 | 70 | * \deprecated New code should use #vpx_img_fmt |
michael@0 | 71 | */ |
michael@0 | 72 | #define img_fmt vpx_img_fmt |
michael@0 | 73 | /*!\brief alias for enum img_fmt. |
michael@0 | 74 | * \deprecated New code should use #vpx_img_fmt_t |
michael@0 | 75 | */ |
michael@0 | 76 | #define img_fmt_t vpx_img_fmt_t |
michael@0 | 77 | |
michael@0 | 78 | #define IMG_FMT_NONE VPX_IMG_FMT_NONE /**< \deprecated Use #VPX_IMG_FMT_NONE */ |
michael@0 | 79 | #define IMG_FMT_RGB24 VPX_IMG_FMT_RGB24 /**< \deprecated Use #VPX_IMG_FMT_RGB24 */ |
michael@0 | 80 | #define IMG_FMT_RGB32 VPX_IMG_FMT_RGB32 /**< \deprecated Use #VPX_IMG_FMT_RGB32 */ |
michael@0 | 81 | #define IMG_FMT_RGB565 VPX_IMG_FMT_RGB565 /**< \deprecated Use #VPX_IMG_FMT_RGB565 */ |
michael@0 | 82 | #define IMG_FMT_RGB555 VPX_IMG_FMT_RGB555 /**< \deprecated Use #VPX_IMG_FMT_RGB555 */ |
michael@0 | 83 | #define IMG_FMT_UYVY VPX_IMG_FMT_UYVY /**< \deprecated Use #VPX_IMG_FMT_UYVY */ |
michael@0 | 84 | #define IMG_FMT_YUY2 VPX_IMG_FMT_YUY2 /**< \deprecated Use #VPX_IMG_FMT_YUY2 */ |
michael@0 | 85 | #define IMG_FMT_YVYU VPX_IMG_FMT_YVYU /**< \deprecated Use #VPX_IMG_FMT_YVYU */ |
michael@0 | 86 | #define IMG_FMT_BGR24 VPX_IMG_FMT_BGR24 /**< \deprecated Use #VPX_IMG_FMT_BGR24 */ |
michael@0 | 87 | #define IMG_FMT_RGB32_LE VPX_IMG_FMT_RGB32_LE /**< \deprecated Use #VPX_IMG_FMT_RGB32_LE */ |
michael@0 | 88 | #define IMG_FMT_ARGB VPX_IMG_FMT_ARGB /**< \deprecated Use #VPX_IMG_FMT_ARGB */ |
michael@0 | 89 | #define IMG_FMT_ARGB_LE VPX_IMG_FMT_ARGB_LE /**< \deprecated Use #VPX_IMG_FMT_ARGB_LE */ |
michael@0 | 90 | #define IMG_FMT_RGB565_LE VPX_IMG_FMT_RGB565_LE /**< \deprecated Use #VPX_IMG_FMT_RGB565_LE */ |
michael@0 | 91 | #define IMG_FMT_RGB555_LE VPX_IMG_FMT_RGB555_LE /**< \deprecated Use #VPX_IMG_FMT_RGB555_LE */ |
michael@0 | 92 | #define IMG_FMT_YV12 VPX_IMG_FMT_YV12 /**< \deprecated Use #VPX_IMG_FMT_YV12 */ |
michael@0 | 93 | #define IMG_FMT_I420 VPX_IMG_FMT_I420 /**< \deprecated Use #VPX_IMG_FMT_I420 */ |
michael@0 | 94 | #define IMG_FMT_VPXYV12 VPX_IMG_FMT_VPXYV12 /**< \deprecated Use #VPX_IMG_FMT_VPXYV12 */ |
michael@0 | 95 | #define IMG_FMT_VPXI420 VPX_IMG_FMT_VPXI420 /**< \deprecated Use #VPX_IMG_FMT_VPXI420 */ |
michael@0 | 96 | #endif /* VPX_CODEC_DISABLE_COMPAT */ |
michael@0 | 97 | |
michael@0 | 98 | /**\brief Image Descriptor */ |
michael@0 | 99 | typedef struct vpx_image { |
michael@0 | 100 | vpx_img_fmt_t fmt; /**< Image Format */ |
michael@0 | 101 | |
michael@0 | 102 | /* Image storage dimensions */ |
michael@0 | 103 | unsigned int w; /**< Stored image width */ |
michael@0 | 104 | unsigned int h; /**< Stored image height */ |
michael@0 | 105 | |
michael@0 | 106 | /* Image display dimensions */ |
michael@0 | 107 | unsigned int d_w; /**< Displayed image width */ |
michael@0 | 108 | unsigned int d_h; /**< Displayed image height */ |
michael@0 | 109 | |
michael@0 | 110 | /* Chroma subsampling info */ |
michael@0 | 111 | unsigned int x_chroma_shift; /**< subsampling order, X */ |
michael@0 | 112 | unsigned int y_chroma_shift; /**< subsampling order, Y */ |
michael@0 | 113 | |
michael@0 | 114 | /* Image data pointers. */ |
michael@0 | 115 | #define VPX_PLANE_PACKED 0 /**< To be used for all packed formats */ |
michael@0 | 116 | #define VPX_PLANE_Y 0 /**< Y (Luminance) plane */ |
michael@0 | 117 | #define VPX_PLANE_U 1 /**< U (Chroma) plane */ |
michael@0 | 118 | #define VPX_PLANE_V 2 /**< V (Chroma) plane */ |
michael@0 | 119 | #define VPX_PLANE_ALPHA 3 /**< A (Transparency) plane */ |
michael@0 | 120 | #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT |
michael@0 | 121 | #define PLANE_PACKED VPX_PLANE_PACKED |
michael@0 | 122 | #define PLANE_Y VPX_PLANE_Y |
michael@0 | 123 | #define PLANE_U VPX_PLANE_U |
michael@0 | 124 | #define PLANE_V VPX_PLANE_V |
michael@0 | 125 | #define PLANE_ALPHA VPX_PLANE_ALPHA |
michael@0 | 126 | #endif |
michael@0 | 127 | unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */ |
michael@0 | 128 | int stride[4]; /**< stride between rows for each plane */ |
michael@0 | 129 | |
michael@0 | 130 | int bps; /**< bits per sample (for packed formats) */ |
michael@0 | 131 | |
michael@0 | 132 | /* The following member may be set by the application to associate data |
michael@0 | 133 | * with this image. |
michael@0 | 134 | */ |
michael@0 | 135 | void *user_priv; /**< may be set by the application to associate data |
michael@0 | 136 | * with this image. */ |
michael@0 | 137 | |
michael@0 | 138 | /* The following members should be treated as private. */ |
michael@0 | 139 | unsigned char *img_data; /**< private */ |
michael@0 | 140 | int img_data_owner; /**< private */ |
michael@0 | 141 | int self_allocd; /**< private */ |
michael@0 | 142 | } vpx_image_t; /**< alias for struct vpx_image */ |
michael@0 | 143 | |
michael@0 | 144 | /**\brief Representation of a rectangle on a surface */ |
michael@0 | 145 | typedef struct vpx_image_rect { |
michael@0 | 146 | unsigned int x; /**< leftmost column */ |
michael@0 | 147 | unsigned int y; /**< topmost row */ |
michael@0 | 148 | unsigned int w; /**< width */ |
michael@0 | 149 | unsigned int h; /**< height */ |
michael@0 | 150 | } vpx_image_rect_t; /**< alias for struct vpx_image_rect */ |
michael@0 | 151 | |
michael@0 | 152 | /*!\brief Open a descriptor, allocating storage for the underlying image |
michael@0 | 153 | * |
michael@0 | 154 | * Returns a descriptor for storing an image of the given format. The |
michael@0 | 155 | * storage for the descriptor is allocated on the heap. |
michael@0 | 156 | * |
michael@0 | 157 | * \param[in] img Pointer to storage for descriptor. If this parameter |
michael@0 | 158 | * is NULL, the storage for the descriptor will be |
michael@0 | 159 | * allocated on the heap. |
michael@0 | 160 | * \param[in] fmt Format for the image |
michael@0 | 161 | * \param[in] d_w Width of the image |
michael@0 | 162 | * \param[in] d_h Height of the image |
michael@0 | 163 | * \param[in] align Alignment, in bytes, of the image buffer and |
michael@0 | 164 | * each row in the image(stride). |
michael@0 | 165 | * |
michael@0 | 166 | * \return Returns a pointer to the initialized image descriptor. If the img |
michael@0 | 167 | * parameter is non-null, the value of the img parameter will be |
michael@0 | 168 | * returned. |
michael@0 | 169 | */ |
michael@0 | 170 | vpx_image_t *vpx_img_alloc(vpx_image_t *img, |
michael@0 | 171 | vpx_img_fmt_t fmt, |
michael@0 | 172 | unsigned int d_w, |
michael@0 | 173 | unsigned int d_h, |
michael@0 | 174 | unsigned int align); |
michael@0 | 175 | |
michael@0 | 176 | /*!\brief Open a descriptor, using existing storage for the underlying image |
michael@0 | 177 | * |
michael@0 | 178 | * Returns a descriptor for storing an image of the given format. The |
michael@0 | 179 | * storage for descriptor has been allocated elsewhere, and a descriptor is |
michael@0 | 180 | * desired to "wrap" that storage. |
michael@0 | 181 | * |
michael@0 | 182 | * \param[in] img Pointer to storage for descriptor. If this parameter |
michael@0 | 183 | * is NULL, the storage for the descriptor will be |
michael@0 | 184 | * allocated on the heap. |
michael@0 | 185 | * \param[in] fmt Format for the image |
michael@0 | 186 | * \param[in] d_w Width of the image |
michael@0 | 187 | * \param[in] d_h Height of the image |
michael@0 | 188 | * \param[in] align Alignment, in bytes, of each row in the image. |
michael@0 | 189 | * \param[in] img_data Storage to use for the image |
michael@0 | 190 | * |
michael@0 | 191 | * \return Returns a pointer to the initialized image descriptor. If the img |
michael@0 | 192 | * parameter is non-null, the value of the img parameter will be |
michael@0 | 193 | * returned. |
michael@0 | 194 | */ |
michael@0 | 195 | vpx_image_t *vpx_img_wrap(vpx_image_t *img, |
michael@0 | 196 | vpx_img_fmt_t fmt, |
michael@0 | 197 | unsigned int d_w, |
michael@0 | 198 | unsigned int d_h, |
michael@0 | 199 | unsigned int align, |
michael@0 | 200 | unsigned char *img_data); |
michael@0 | 201 | |
michael@0 | 202 | |
michael@0 | 203 | /*!\brief Set the rectangle identifying the displayed portion of the image |
michael@0 | 204 | * |
michael@0 | 205 | * Updates the displayed rectangle (aka viewport) on the image surface to |
michael@0 | 206 | * match the specified coordinates and size. |
michael@0 | 207 | * |
michael@0 | 208 | * \param[in] img Image descriptor |
michael@0 | 209 | * \param[in] x leftmost column |
michael@0 | 210 | * \param[in] y topmost row |
michael@0 | 211 | * \param[in] w width |
michael@0 | 212 | * \param[in] h height |
michael@0 | 213 | * |
michael@0 | 214 | * \return 0 if the requested rectangle is valid, nonzero otherwise. |
michael@0 | 215 | */ |
michael@0 | 216 | int vpx_img_set_rect(vpx_image_t *img, |
michael@0 | 217 | unsigned int x, |
michael@0 | 218 | unsigned int y, |
michael@0 | 219 | unsigned int w, |
michael@0 | 220 | unsigned int h); |
michael@0 | 221 | |
michael@0 | 222 | |
michael@0 | 223 | /*!\brief Flip the image vertically (top for bottom) |
michael@0 | 224 | * |
michael@0 | 225 | * Adjusts the image descriptor's pointers and strides to make the image |
michael@0 | 226 | * be referenced upside-down. |
michael@0 | 227 | * |
michael@0 | 228 | * \param[in] img Image descriptor |
michael@0 | 229 | */ |
michael@0 | 230 | void vpx_img_flip(vpx_image_t *img); |
michael@0 | 231 | |
michael@0 | 232 | /*!\brief Close an image descriptor |
michael@0 | 233 | * |
michael@0 | 234 | * Frees all allocated storage associated with an image descriptor. |
michael@0 | 235 | * |
michael@0 | 236 | * \param[in] img Image descriptor |
michael@0 | 237 | */ |
michael@0 | 238 | void vpx_img_free(vpx_image_t *img); |
michael@0 | 239 | |
michael@0 | 240 | #endif |
michael@0 | 241 | #ifdef __cplusplus |
michael@0 | 242 | } |
michael@0 | 243 | #endif |