michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: /*!\file michael@0: * \brief Describes the vpx image descriptor and associated operations michael@0: * michael@0: */ michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: #ifndef VPX_IMAGE_H michael@0: #define VPX_IMAGE_H michael@0: michael@0: /*!\brief Current ABI version number michael@0: * michael@0: * \internal michael@0: * If this file is altered in any way that changes the ABI, this value michael@0: * must be bumped. Examples include, but are not limited to, changing michael@0: * types, removing or reassigning enums, adding/removing/rearranging michael@0: * fields to structures michael@0: */ michael@0: #define VPX_IMAGE_ABI_VERSION (1) /**<\hideinitializer*/ michael@0: michael@0: michael@0: #define VPX_IMG_FMT_PLANAR 0x100 /**< Image is a planar format */ michael@0: #define VPX_IMG_FMT_UV_FLIP 0x200 /**< V plane precedes U plane in memory */ michael@0: #define VPX_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel component */ michael@0: michael@0: michael@0: /*!\brief List of supported image formats */ michael@0: typedef enum vpx_img_fmt { michael@0: VPX_IMG_FMT_NONE, michael@0: VPX_IMG_FMT_RGB24, /**< 24 bit per pixel packed RGB */ michael@0: VPX_IMG_FMT_RGB32, /**< 32 bit per pixel packed 0RGB */ michael@0: VPX_IMG_FMT_RGB565, /**< 16 bit per pixel, 565 */ michael@0: VPX_IMG_FMT_RGB555, /**< 16 bit per pixel, 555 */ michael@0: VPX_IMG_FMT_UYVY, /**< UYVY packed YUV */ michael@0: VPX_IMG_FMT_YUY2, /**< YUYV packed YUV */ michael@0: VPX_IMG_FMT_YVYU, /**< YVYU packed YUV */ michael@0: VPX_IMG_FMT_BGR24, /**< 24 bit per pixel packed BGR */ michael@0: VPX_IMG_FMT_RGB32_LE, /**< 32 bit packed BGR0 */ michael@0: VPX_IMG_FMT_ARGB, /**< 32 bit packed ARGB, alpha=255 */ michael@0: VPX_IMG_FMT_ARGB_LE, /**< 32 bit packed BGRA, alpha=255 */ michael@0: VPX_IMG_FMT_RGB565_LE, /**< 16 bit per pixel, gggbbbbb rrrrrggg */ michael@0: VPX_IMG_FMT_RGB555_LE, /**< 16 bit per pixel, gggbbbbb 0rrrrrgg */ michael@0: VPX_IMG_FMT_YV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */ michael@0: VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2, michael@0: 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: VPX_IMG_FMT_VPXI420 = VPX_IMG_FMT_PLANAR | 4, michael@0: VPX_IMG_FMT_I422 = VPX_IMG_FMT_PLANAR | 5, michael@0: VPX_IMG_FMT_I444 = VPX_IMG_FMT_PLANAR | 6, michael@0: VPX_IMG_FMT_444A = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_HAS_ALPHA | 7 michael@0: } vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */ michael@0: michael@0: #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT michael@0: #define IMG_FMT_PLANAR VPX_IMG_FMT_PLANAR /**< \deprecated Use #VPX_IMG_FMT_PLANAR */ michael@0: #define IMG_FMT_UV_FLIP VPX_IMG_FMT_UV_FLIP /**< \deprecated Use #VPX_IMG_FMT_UV_FLIP */ michael@0: #define IMG_FMT_HAS_ALPHA VPX_IMG_FMT_HAS_ALPHA /**< \deprecated Use #VPX_IMG_FMT_HAS_ALPHA */ michael@0: michael@0: /*!\brief Deprecated list of supported image formats michael@0: * \deprecated New code should use #vpx_img_fmt michael@0: */ michael@0: #define img_fmt vpx_img_fmt michael@0: /*!\brief alias for enum img_fmt. michael@0: * \deprecated New code should use #vpx_img_fmt_t michael@0: */ michael@0: #define img_fmt_t vpx_img_fmt_t michael@0: michael@0: #define IMG_FMT_NONE VPX_IMG_FMT_NONE /**< \deprecated Use #VPX_IMG_FMT_NONE */ michael@0: #define IMG_FMT_RGB24 VPX_IMG_FMT_RGB24 /**< \deprecated Use #VPX_IMG_FMT_RGB24 */ michael@0: #define IMG_FMT_RGB32 VPX_IMG_FMT_RGB32 /**< \deprecated Use #VPX_IMG_FMT_RGB32 */ michael@0: #define IMG_FMT_RGB565 VPX_IMG_FMT_RGB565 /**< \deprecated Use #VPX_IMG_FMT_RGB565 */ michael@0: #define IMG_FMT_RGB555 VPX_IMG_FMT_RGB555 /**< \deprecated Use #VPX_IMG_FMT_RGB555 */ michael@0: #define IMG_FMT_UYVY VPX_IMG_FMT_UYVY /**< \deprecated Use #VPX_IMG_FMT_UYVY */ michael@0: #define IMG_FMT_YUY2 VPX_IMG_FMT_YUY2 /**< \deprecated Use #VPX_IMG_FMT_YUY2 */ michael@0: #define IMG_FMT_YVYU VPX_IMG_FMT_YVYU /**< \deprecated Use #VPX_IMG_FMT_YVYU */ michael@0: #define IMG_FMT_BGR24 VPX_IMG_FMT_BGR24 /**< \deprecated Use #VPX_IMG_FMT_BGR24 */ michael@0: #define IMG_FMT_RGB32_LE VPX_IMG_FMT_RGB32_LE /**< \deprecated Use #VPX_IMG_FMT_RGB32_LE */ michael@0: #define IMG_FMT_ARGB VPX_IMG_FMT_ARGB /**< \deprecated Use #VPX_IMG_FMT_ARGB */ michael@0: #define IMG_FMT_ARGB_LE VPX_IMG_FMT_ARGB_LE /**< \deprecated Use #VPX_IMG_FMT_ARGB_LE */ michael@0: #define IMG_FMT_RGB565_LE VPX_IMG_FMT_RGB565_LE /**< \deprecated Use #VPX_IMG_FMT_RGB565_LE */ michael@0: #define IMG_FMT_RGB555_LE VPX_IMG_FMT_RGB555_LE /**< \deprecated Use #VPX_IMG_FMT_RGB555_LE */ michael@0: #define IMG_FMT_YV12 VPX_IMG_FMT_YV12 /**< \deprecated Use #VPX_IMG_FMT_YV12 */ michael@0: #define IMG_FMT_I420 VPX_IMG_FMT_I420 /**< \deprecated Use #VPX_IMG_FMT_I420 */ michael@0: #define IMG_FMT_VPXYV12 VPX_IMG_FMT_VPXYV12 /**< \deprecated Use #VPX_IMG_FMT_VPXYV12 */ michael@0: #define IMG_FMT_VPXI420 VPX_IMG_FMT_VPXI420 /**< \deprecated Use #VPX_IMG_FMT_VPXI420 */ michael@0: #endif /* VPX_CODEC_DISABLE_COMPAT */ michael@0: michael@0: /**\brief Image Descriptor */ michael@0: typedef struct vpx_image { michael@0: vpx_img_fmt_t fmt; /**< Image Format */ michael@0: michael@0: /* Image storage dimensions */ michael@0: unsigned int w; /**< Stored image width */ michael@0: unsigned int h; /**< Stored image height */ michael@0: michael@0: /* Image display dimensions */ michael@0: unsigned int d_w; /**< Displayed image width */ michael@0: unsigned int d_h; /**< Displayed image height */ michael@0: michael@0: /* Chroma subsampling info */ michael@0: unsigned int x_chroma_shift; /**< subsampling order, X */ michael@0: unsigned int y_chroma_shift; /**< subsampling order, Y */ michael@0: michael@0: /* Image data pointers. */ michael@0: #define VPX_PLANE_PACKED 0 /**< To be used for all packed formats */ michael@0: #define VPX_PLANE_Y 0 /**< Y (Luminance) plane */ michael@0: #define VPX_PLANE_U 1 /**< U (Chroma) plane */ michael@0: #define VPX_PLANE_V 2 /**< V (Chroma) plane */ michael@0: #define VPX_PLANE_ALPHA 3 /**< A (Transparency) plane */ michael@0: #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT michael@0: #define PLANE_PACKED VPX_PLANE_PACKED michael@0: #define PLANE_Y VPX_PLANE_Y michael@0: #define PLANE_U VPX_PLANE_U michael@0: #define PLANE_V VPX_PLANE_V michael@0: #define PLANE_ALPHA VPX_PLANE_ALPHA michael@0: #endif michael@0: unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */ michael@0: int stride[4]; /**< stride between rows for each plane */ michael@0: michael@0: int bps; /**< bits per sample (for packed formats) */ michael@0: michael@0: /* The following member may be set by the application to associate data michael@0: * with this image. michael@0: */ michael@0: void *user_priv; /**< may be set by the application to associate data michael@0: * with this image. */ michael@0: michael@0: /* The following members should be treated as private. */ michael@0: unsigned char *img_data; /**< private */ michael@0: int img_data_owner; /**< private */ michael@0: int self_allocd; /**< private */ michael@0: } vpx_image_t; /**< alias for struct vpx_image */ michael@0: michael@0: /**\brief Representation of a rectangle on a surface */ michael@0: typedef struct vpx_image_rect { michael@0: unsigned int x; /**< leftmost column */ michael@0: unsigned int y; /**< topmost row */ michael@0: unsigned int w; /**< width */ michael@0: unsigned int h; /**< height */ michael@0: } vpx_image_rect_t; /**< alias for struct vpx_image_rect */ michael@0: michael@0: /*!\brief Open a descriptor, allocating storage for the underlying image michael@0: * michael@0: * Returns a descriptor for storing an image of the given format. The michael@0: * storage for the descriptor is allocated on the heap. michael@0: * michael@0: * \param[in] img Pointer to storage for descriptor. If this parameter michael@0: * is NULL, the storage for the descriptor will be michael@0: * allocated on the heap. michael@0: * \param[in] fmt Format for the image michael@0: * \param[in] d_w Width of the image michael@0: * \param[in] d_h Height of the image michael@0: * \param[in] align Alignment, in bytes, of the image buffer and michael@0: * each row in the image(stride). michael@0: * michael@0: * \return Returns a pointer to the initialized image descriptor. If the img michael@0: * parameter is non-null, the value of the img parameter will be michael@0: * returned. michael@0: */ michael@0: vpx_image_t *vpx_img_alloc(vpx_image_t *img, michael@0: vpx_img_fmt_t fmt, michael@0: unsigned int d_w, michael@0: unsigned int d_h, michael@0: unsigned int align); michael@0: michael@0: /*!\brief Open a descriptor, using existing storage for the underlying image michael@0: * michael@0: * Returns a descriptor for storing an image of the given format. The michael@0: * storage for descriptor has been allocated elsewhere, and a descriptor is michael@0: * desired to "wrap" that storage. michael@0: * michael@0: * \param[in] img Pointer to storage for descriptor. If this parameter michael@0: * is NULL, the storage for the descriptor will be michael@0: * allocated on the heap. michael@0: * \param[in] fmt Format for the image michael@0: * \param[in] d_w Width of the image michael@0: * \param[in] d_h Height of the image michael@0: * \param[in] align Alignment, in bytes, of each row in the image. michael@0: * \param[in] img_data Storage to use for the image michael@0: * michael@0: * \return Returns a pointer to the initialized image descriptor. If the img michael@0: * parameter is non-null, the value of the img parameter will be michael@0: * returned. michael@0: */ michael@0: vpx_image_t *vpx_img_wrap(vpx_image_t *img, michael@0: vpx_img_fmt_t fmt, michael@0: unsigned int d_w, michael@0: unsigned int d_h, michael@0: unsigned int align, michael@0: unsigned char *img_data); michael@0: michael@0: michael@0: /*!\brief Set the rectangle identifying the displayed portion of the image michael@0: * michael@0: * Updates the displayed rectangle (aka viewport) on the image surface to michael@0: * match the specified coordinates and size. michael@0: * michael@0: * \param[in] img Image descriptor michael@0: * \param[in] x leftmost column michael@0: * \param[in] y topmost row michael@0: * \param[in] w width michael@0: * \param[in] h height michael@0: * michael@0: * \return 0 if the requested rectangle is valid, nonzero otherwise. michael@0: */ michael@0: int vpx_img_set_rect(vpx_image_t *img, michael@0: unsigned int x, michael@0: unsigned int y, michael@0: unsigned int w, michael@0: unsigned int h); michael@0: michael@0: michael@0: /*!\brief Flip the image vertically (top for bottom) michael@0: * michael@0: * Adjusts the image descriptor's pointers and strides to make the image michael@0: * be referenced upside-down. michael@0: * michael@0: * \param[in] img Image descriptor michael@0: */ michael@0: void vpx_img_flip(vpx_image_t *img); michael@0: michael@0: /*!\brief Close an image descriptor michael@0: * michael@0: * Frees all allocated storage associated with an image descriptor. michael@0: * michael@0: * \param[in] img Image descriptor michael@0: */ michael@0: void vpx_img_free(vpx_image_t *img); michael@0: michael@0: #endif michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif