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