vpx_image.h 10 KB

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