vpx_image.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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_VPX_IMAGE_H_
  15. #define VPX_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 (5) /**<\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 in memory. */
  30. #define VPX_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel. */
  31. #define VPX_IMG_FMT_HIGHBITDEPTH 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_YV12 =
  36. VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 1, /**< planar YVU */
  37. VPX_IMG_FMT_I420 = VPX_IMG_FMT_PLANAR | 2,
  38. VPX_IMG_FMT_I422 = VPX_IMG_FMT_PLANAR | 5,
  39. VPX_IMG_FMT_I444 = VPX_IMG_FMT_PLANAR | 6,
  40. VPX_IMG_FMT_I440 = VPX_IMG_FMT_PLANAR | 7,
  41. VPX_IMG_FMT_I42016 = VPX_IMG_FMT_I420 | VPX_IMG_FMT_HIGHBITDEPTH,
  42. VPX_IMG_FMT_I42216 = VPX_IMG_FMT_I422 | VPX_IMG_FMT_HIGHBITDEPTH,
  43. VPX_IMG_FMT_I44416 = VPX_IMG_FMT_I444 | VPX_IMG_FMT_HIGHBITDEPTH,
  44. VPX_IMG_FMT_I44016 = VPX_IMG_FMT_I440 | VPX_IMG_FMT_HIGHBITDEPTH
  45. } vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */
  46. /*!\brief List of supported color spaces */
  47. typedef enum vpx_color_space {
  48. VPX_CS_UNKNOWN = 0, /**< Unknown */
  49. VPX_CS_BT_601 = 1, /**< BT.601 */
  50. VPX_CS_BT_709 = 2, /**< BT.709 */
  51. VPX_CS_SMPTE_170 = 3, /**< SMPTE.170 */
  52. VPX_CS_SMPTE_240 = 4, /**< SMPTE.240 */
  53. VPX_CS_BT_2020 = 5, /**< BT.2020 */
  54. VPX_CS_RESERVED = 6, /**< Reserved */
  55. VPX_CS_SRGB = 7 /**< sRGB */
  56. } vpx_color_space_t; /**< alias for enum vpx_color_space */
  57. /*!\brief List of supported color range */
  58. typedef enum vpx_color_range {
  59. VPX_CR_STUDIO_RANGE = 0, /**< Y [16..235], UV [16..240] */
  60. VPX_CR_FULL_RANGE = 1 /**< YUV/RGB [0..255] */
  61. } vpx_color_range_t; /**< alias for enum vpx_color_range */
  62. /**\brief Image Descriptor */
  63. typedef struct vpx_image {
  64. vpx_img_fmt_t fmt; /**< Image Format */
  65. vpx_color_space_t cs; /**< Color Space */
  66. vpx_color_range_t range; /**< Color Range */
  67. /* Image storage dimensions */
  68. unsigned int w; /**< Stored image width */
  69. unsigned int h; /**< Stored image height */
  70. unsigned int bit_depth; /**< Stored image bit-depth */
  71. /* Image display dimensions */
  72. unsigned int d_w; /**< Displayed image width */
  73. unsigned int d_h; /**< Displayed image height */
  74. /* Image intended rendering dimensions */
  75. unsigned int r_w; /**< Intended rendering image width */
  76. unsigned int r_h; /**< Intended rendering image height */
  77. /* Chroma subsampling info */
  78. unsigned int x_chroma_shift; /**< subsampling order, X */
  79. unsigned int y_chroma_shift; /**< subsampling order, Y */
  80. /* Image data pointers. */
  81. #define VPX_PLANE_PACKED 0 /**< To be used for all packed formats */
  82. #define VPX_PLANE_Y 0 /**< Y (Luminance) plane */
  83. #define VPX_PLANE_U 1 /**< U (Chroma) plane */
  84. #define VPX_PLANE_V 2 /**< V (Chroma) plane */
  85. #define VPX_PLANE_ALPHA 3 /**< A (Transparency) plane */
  86. unsigned char *planes[4]; /**< pointer to the top left pixel for each plane */
  87. int stride[4]; /**< stride between rows for each plane */
  88. int bps; /**< bits per sample (for packed formats) */
  89. /*!\brief The following member may be set by the application to associate
  90. * data with this image.
  91. */
  92. void *user_priv;
  93. /* The following members should be treated as private. */
  94. unsigned char *img_data; /**< private */
  95. int img_data_owner; /**< private */
  96. int self_allocd; /**< private */
  97. void *fb_priv; /**< Frame buffer data associated with the image. */
  98. } vpx_image_t; /**< alias for struct vpx_image */
  99. /**\brief Representation of a rectangle on a surface */
  100. typedef struct vpx_image_rect {
  101. unsigned int x; /**< leftmost column */
  102. unsigned int y; /**< topmost row */
  103. unsigned int w; /**< width */
  104. unsigned int h; /**< height */
  105. } vpx_image_rect_t; /**< alias for struct vpx_image_rect */
  106. /*!\brief Open a descriptor, allocating storage for the underlying image
  107. *
  108. * Returns a descriptor for storing an image of the given format. The
  109. * storage for the descriptor is allocated on the heap.
  110. *
  111. * \param[in] img Pointer to storage for descriptor. If this parameter
  112. * is NULL, the storage for the descriptor will be
  113. * allocated on the heap.
  114. * \param[in] fmt Format for the image
  115. * \param[in] d_w Width of the image
  116. * \param[in] d_h Height of the image
  117. * \param[in] align Alignment, in bytes, of the image buffer and
  118. * each row in the image(stride).
  119. *
  120. * \return Returns a pointer to the initialized image descriptor. If the img
  121. * parameter is non-null, the value of the img parameter will be
  122. * returned.
  123. */
  124. vpx_image_t *vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt,
  125. unsigned int d_w, unsigned int d_h,
  126. unsigned int align);
  127. /*!\brief Open a descriptor, using existing storage for the underlying image
  128. *
  129. * Returns a descriptor for storing an image of the given format. The
  130. * storage for descriptor has been allocated elsewhere, and a descriptor is
  131. * desired to "wrap" that storage.
  132. *
  133. * \param[in] img Pointer to storage for descriptor. If this
  134. * parameter is NULL, the storage for the descriptor
  135. * will be allocated on the heap.
  136. * \param[in] fmt Format for the image
  137. * \param[in] d_w Width of the image
  138. * \param[in] d_h Height of the image
  139. * \param[in] stride_align Alignment, in bytes, of each row in the image.
  140. * \param[in] img_data Storage to use for the image
  141. *
  142. * \return Returns a pointer to the initialized image descriptor. If the img
  143. * parameter is non-null, the value of the img parameter will be
  144. * returned.
  145. */
  146. vpx_image_t *vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w,
  147. unsigned int d_h, unsigned int stride_align,
  148. unsigned char *img_data);
  149. /*!\brief Set the rectangle identifying the displayed portion of the image
  150. *
  151. * Updates the displayed rectangle (aka viewport) on the image surface to
  152. * match the specified coordinates and size.
  153. *
  154. * \param[in] img Image descriptor
  155. * \param[in] x leftmost column
  156. * \param[in] y topmost row
  157. * \param[in] w width
  158. * \param[in] h height
  159. *
  160. * \return 0 if the requested rectangle is valid, nonzero otherwise.
  161. */
  162. int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y,
  163. unsigned int w, unsigned int h);
  164. /*!\brief Flip the image vertically (top for bottom)
  165. *
  166. * Adjusts the image descriptor's pointers and strides to make the image
  167. * be referenced upside-down.
  168. *
  169. * \param[in] img Image descriptor
  170. */
  171. void vpx_img_flip(vpx_image_t *img);
  172. /*!\brief Close an image descriptor
  173. *
  174. * Frees all allocated storage associated with an image descriptor.
  175. *
  176. * \param[in] img Image descriptor
  177. */
  178. void vpx_img_free(vpx_image_t *img);
  179. #ifdef __cplusplus
  180. } // extern "C"
  181. #endif
  182. #endif // VPX_VPX_VPX_IMAGE_H_