vpx_image.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 /** < planar 4:2:0 format with vpx color space */
  51. }
  52. vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */
  53. #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT
  54. #define IMG_FMT_PLANAR VPX_IMG_FMT_PLANAR /**< \deprecated Use #VPX_IMG_FMT_PLANAR */
  55. #define IMG_FMT_UV_FLIP VPX_IMG_FMT_UV_FLIP /**< \deprecated Use #VPX_IMG_FMT_UV_FLIP */
  56. #define IMG_FMT_HAS_ALPHA VPX_IMG_FMT_HAS_ALPHA /**< \deprecated Use #VPX_IMG_FMT_HAS_ALPHA */
  57. /*!\brief Deprecated list of supported image formats
  58. * \deprecated New code should use #vpx_img_fmt
  59. */
  60. #define img_fmt vpx_img_fmt
  61. /*!\brief alias for enum img_fmt.
  62. * \deprecated New code should use #vpx_img_fmt_t
  63. */
  64. #define img_fmt_t vpx_img_fmt_t
  65. #define IMG_FMT_NONE VPX_IMG_FMT_NONE /**< \deprecated Use #VPX_IMG_FMT_NONE */
  66. #define IMG_FMT_RGB24 VPX_IMG_FMT_RGB24 /**< \deprecated Use #VPX_IMG_FMT_RGB24 */
  67. #define IMG_FMT_RGB32 VPX_IMG_FMT_RGB32 /**< \deprecated Use #VPX_IMG_FMT_RGB32 */
  68. #define IMG_FMT_RGB565 VPX_IMG_FMT_RGB565 /**< \deprecated Use #VPX_IMG_FMT_RGB565 */
  69. #define IMG_FMT_RGB555 VPX_IMG_FMT_RGB555 /**< \deprecated Use #VPX_IMG_FMT_RGB555 */
  70. #define IMG_FMT_UYVY VPX_IMG_FMT_UYVY /**< \deprecated Use #VPX_IMG_FMT_UYVY */
  71. #define IMG_FMT_YUY2 VPX_IMG_FMT_YUY2 /**< \deprecated Use #VPX_IMG_FMT_YUY2 */
  72. #define IMG_FMT_YVYU VPX_IMG_FMT_YVYU /**< \deprecated Use #VPX_IMG_FMT_YVYU */
  73. #define IMG_FMT_BGR24 VPX_IMG_FMT_BGR24 /**< \deprecated Use #VPX_IMG_FMT_BGR24 */
  74. #define IMG_FMT_RGB32_LE VPX_IMG_FMT_RGB32_LE /**< \deprecated Use #VPX_IMG_FMT_RGB32_LE */
  75. #define IMG_FMT_ARGB VPX_IMG_FMT_ARGB /**< \deprecated Use #VPX_IMG_FMT_ARGB */
  76. #define IMG_FMT_ARGB_LE VPX_IMG_FMT_ARGB_LE /**< \deprecated Use #VPX_IMG_FMT_ARGB_LE */
  77. #define IMG_FMT_RGB565_LE VPX_IMG_FMT_RGB565_LE /**< \deprecated Use #VPX_IMG_FMT_RGB565_LE */
  78. #define IMG_FMT_RGB555_LE VPX_IMG_FMT_RGB555_LE /**< \deprecated Use #VPX_IMG_FMT_RGB555_LE */
  79. #define IMG_FMT_YV12 VPX_IMG_FMT_YV12 /**< \deprecated Use #VPX_IMG_FMT_YV12 */
  80. #define IMG_FMT_I420 VPX_IMG_FMT_I420 /**< \deprecated Use #VPX_IMG_FMT_I420 */
  81. #define IMG_FMT_VPXYV12 VPX_IMG_FMT_VPXYV12 /**< \deprecated Use #VPX_IMG_FMT_VPXYV12 */
  82. #define IMG_FMT_VPXI420 VPX_IMG_FMT_VPXI420 /**< \deprecated Use #VPX_IMG_FMT_VPXI420 */
  83. #endif /* VPX_CODEC_DISABLE_COMPAT */
  84. /**\brief Image Descriptor */
  85. typedef struct vpx_image {
  86. vpx_img_fmt_t fmt; /**< Image Format */
  87. /* Image storage dimensions */
  88. unsigned int w; /**< Stored image width */
  89. unsigned int h; /**< Stored image height */
  90. /* Image display dimensions */
  91. unsigned int d_w; /**< Displayed image width */
  92. unsigned int d_h; /**< Displayed image height */
  93. /* Chroma subsampling info */
  94. unsigned int x_chroma_shift; /**< subsampling order, X */
  95. unsigned int y_chroma_shift; /**< subsampling order, Y */
  96. /* Image data pointers. */
  97. #define VPX_PLANE_PACKED 0 /**< To be used for all packed formats */
  98. #define VPX_PLANE_Y 0 /**< Y (Luminance) plane */
  99. #define VPX_PLANE_U 1 /**< U (Chroma) plane */
  100. #define VPX_PLANE_V 2 /**< V (Chroma) plane */
  101. #define VPX_PLANE_ALPHA 3 /**< A (Transparency) plane */
  102. #if !defined(VPX_CODEC_DISABLE_COMPAT) || !VPX_CODEC_DISABLE_COMPAT
  103. #define PLANE_PACKED VPX_PLANE_PACKED
  104. #define PLANE_Y VPX_PLANE_Y
  105. #define PLANE_U VPX_PLANE_U
  106. #define PLANE_V VPX_PLANE_V
  107. #define PLANE_ALPHA VPX_PLANE_ALPHA
  108. #endif
  109. unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */
  110. int stride[4]; /**< stride between rows for each plane */
  111. int bps; /**< bits per sample (for packed formats) */
  112. /* The following member may be set by the application to associate data
  113. * with this image.
  114. */
  115. void *user_priv; /**< may be set by the application to associate data
  116. * with this image. */
  117. /* The following members should be treated as private. */
  118. unsigned char *img_data; /**< private */
  119. int img_data_owner; /**< private */
  120. int self_allocd; /**< private */
  121. } vpx_image_t; /**< alias for struct vpx_image */
  122. /**\brief Representation of a rectangle on a surface */
  123. typedef struct vpx_image_rect {
  124. unsigned int x; /**< leftmost column */
  125. unsigned int y; /**< topmost row */
  126. unsigned int w; /**< width */
  127. unsigned int h; /**< height */
  128. } vpx_image_rect_t; /**< alias for struct vpx_image_rect */
  129. /*!\brief Open a descriptor, allocating storage for the underlying image
  130. *
  131. * Returns a descriptor for storing an image of the given format. The
  132. * storage for the descriptor is allocated on the heap.
  133. *
  134. * \param[in] img Pointer to storage for descriptor. If this parameter
  135. * is NULL, the storage for the descriptor will be
  136. * allocated on the heap.
  137. * \param[in] fmt Format for the image
  138. * \param[in] d_w Width of the image
  139. * \param[in] d_h Height of the image
  140. * \param[in] align Alignment, in bytes, of the image buffer and
  141. * each row in the image(stride).
  142. *
  143. * \return Returns a pointer to the initialized image descriptor. If the img
  144. * parameter is non-null, the value of the img parameter will be
  145. * returned.
  146. */
  147. vpx_image_t *vpx_img_alloc(vpx_image_t *img,
  148. vpx_img_fmt_t fmt,
  149. unsigned int d_w,
  150. unsigned int d_h,
  151. unsigned int align);
  152. /*!\brief Open a descriptor, using existing storage for the underlying image
  153. *
  154. * Returns a descriptor for storing an image of the given format. The
  155. * storage for descriptor has been allocated elsewhere, and a descriptor is
  156. * desired to "wrap" that storage.
  157. *
  158. * \param[in] img Pointer to storage for descriptor. If this parameter
  159. * is NULL, the storage for the descriptor will be
  160. * allocated on the heap.
  161. * \param[in] fmt Format for the image
  162. * \param[in] d_w Width of the image
  163. * \param[in] d_h Height of the image
  164. * \param[in] align Alignment, in bytes, of each row in the image.
  165. * \param[in] img_data Storage to use for the image
  166. *
  167. * \return Returns a pointer to the initialized image descriptor. If the img
  168. * parameter is non-null, the value of the img parameter will be
  169. * returned.
  170. */
  171. vpx_image_t *vpx_img_wrap(vpx_image_t *img,
  172. vpx_img_fmt_t fmt,
  173. unsigned int d_w,
  174. unsigned int d_h,
  175. unsigned int align,
  176. unsigned char *img_data);
  177. /*!\brief Set the rectangle identifying the displayed portion of the image
  178. *
  179. * Updates the displayed rectangle (aka viewport) on the image surface to
  180. * match the specified coordinates and size.
  181. *
  182. * \param[in] img Image descriptor
  183. * \param[in] x leftmost column
  184. * \param[in] y topmost row
  185. * \param[in] w width
  186. * \param[in] h height
  187. *
  188. * \return 0 if the requested rectangle is valid, nonzero otherwise.
  189. */
  190. int vpx_img_set_rect(vpx_image_t *img,
  191. unsigned int x,
  192. unsigned int y,
  193. unsigned int w,
  194. unsigned int h);
  195. /*!\brief Flip the image vertically (top for bottom)
  196. *
  197. * Adjusts the image descriptor's pointers and strides to make the image
  198. * be referenced upside-down.
  199. *
  200. * \param[in] img Image descriptor
  201. */
  202. void vpx_img_flip(vpx_image_t *img);
  203. /*!\brief Close an image descriptor
  204. *
  205. * Frees all allocated storage associated with an image descriptor.
  206. *
  207. * \param[in] img Image descriptor
  208. */
  209. void vpx_img_free(vpx_image_t *img);
  210. #endif
  211. #ifdef __cplusplus
  212. }
  213. #endif