vpx_image.h 11 KB

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