FreeSWITCH API Documentation  1.7.0
switch_image.h
Go to the documentation of this file.
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 
11 
12 /*!\file
13  * \brief Describes the vpx image descriptor and associated operations
14  *
15  */
16 #ifndef VPX_VPX_IMAGE_H_
17 #define VPX_VPX_IMAGE_H_
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23  /*!\brief Current ABI version number
24  *
25  * \internal
26  * If this file is altered in any way that changes the ABI, this value
27  * must be bumped. Examples include, but are not limited to, changing
28  * types, removing or reassigning enums, adding/removing/rearranging
29  * fields to structures
30  */
31 #define VPX_IMAGE_ABI_VERSION (4) /**<\hideinitializer*/
32 
33 
34 #define VPX_IMG_FMT_PLANAR 0x100 /**< Image is a planar format. */
35 #define VPX_IMG_FMT_UV_FLIP 0x200 /**< V plane precedes U in memory. */
36 #define VPX_IMG_FMT_HAS_ALPHA 0x400 /**< Image has an alpha channel. */
37 #define VPX_IMG_FMT_HIGHBITDEPTH 0x800 /**< Image uses 16bit framebuffer. */
38 
39  /*!\brief List of supported image formats */
40  typedef enum vpx_img_fmt {
42  VPX_IMG_FMT_RGB24, /**< 24 bit per pixel packed RGB */
43  VPX_IMG_FMT_RGB32, /**< 32 bit per pixel packed 0RGB */
44  VPX_IMG_FMT_RGB565, /**< 16 bit per pixel, 565 */
45  VPX_IMG_FMT_RGB555, /**< 16 bit per pixel, 555 */
46  VPX_IMG_FMT_UYVY, /**< UYVY packed YUV */
47  VPX_IMG_FMT_YUY2, /**< YUYV packed YUV */
48  VPX_IMG_FMT_YVYU, /**< YVYU packed YUV */
49  VPX_IMG_FMT_BGR24, /**< 24 bit per pixel packed BGR */
50  VPX_IMG_FMT_RGB32_LE, /**< 32 bit packed BGR0 */
51  VPX_IMG_FMT_ARGB, /**< 32 bit packed ARGB, alpha=255 */
52  VPX_IMG_FMT_ARGB_LE, /**< 32 bit packed BGRA, alpha=255 */
53  VPX_IMG_FMT_RGB565_LE, /**< 16 bit per pixel, gggbbbbb rrrrrggg */
54  VPX_IMG_FMT_RGB555_LE, /**< 16 bit per pixel, gggbbbbb 0rrrrrgg */
57  VPX_IMG_FMT_VPXYV12 = VPX_IMG_FMT_PLANAR | VPX_IMG_FMT_UV_FLIP | 3, /** < planar 4:2:0 format with vpx color space */
67  } vpx_img_fmt_t; /**< alias for enum vpx_img_fmt */
68 
69  /*!\brief List of supported color spaces */
70  typedef enum vpx_color_space {
71  VPX_CS_UNKNOWN = 0, /**< Unknown */
72  VPX_CS_BT_601 = 1, /**< BT.601 */
73  VPX_CS_BT_709 = 2, /**< BT.709 */
74  VPX_CS_SMPTE_170 = 3, /**< SMPTE.170 */
75  VPX_CS_SMPTE_240 = 4, /**< SMPTE.240 */
76  VPX_CS_BT_2020 = 5, /**< BT.2020 */
77  VPX_CS_RESERVED = 6, /**< Reserved */
78  VPX_CS_SRGB = 7 /**< sRGB */
79  } vpx_color_space_t; /**< alias for enum vpx_color_space */
80 
81  /*!\brief List of supported color range */
82  typedef enum vpx_color_range {
83  VPX_CR_STUDIO_RANGE = 0, /**< Y [16..235], UV [16..240] */
84  VPX_CR_FULL_RANGE = 1 /**< YUV/RGB [0..255] */
85  } vpx_color_range_t; /**< alias for enum vpx_color_range */
86 
87  /**\brief Image Descriptor */
88  typedef struct vpx_image {
89  vpx_img_fmt_t fmt; /**< Image Format */
90  vpx_color_space_t cs; /**< Color Space */
91  vpx_color_range_t range; /**< Color Range */
92 
93  /* Image storage dimensions */
94  unsigned int w; /**< Stored image width */
95  unsigned int h; /**< Stored image height */
96  unsigned int bit_depth; /**< Stored image bit-depth */
97 
98  /* Image display dimensions */
99  unsigned int d_w; /**< Displayed image width */
100  unsigned int d_h; /**< Displayed image height */
101 
102  /* Image intended rendering dimensions */
103  unsigned int r_w; /**< Intended rendering image width */
104  unsigned int r_h; /**< Intended rendering image height */
105 
106  /* Chroma subsampling info */
107  unsigned int x_chroma_shift; /**< subsampling order, X */
108  unsigned int y_chroma_shift; /**< subsampling order, Y */
109 
110  /* Image data pointers. */
111 #define VPX_PLANE_PACKED 0 /**< To be used for all packed formats */
112 #define VPX_PLANE_Y 0 /**< Y (Luminance) plane */
113 #define VPX_PLANE_U 1 /**< U (Chroma) plane */
114 #define VPX_PLANE_V 2 /**< V (Chroma) plane */
115 #define VPX_PLANE_ALPHA 3 /**< A (Transparency) plane */
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 
119  int bps; /**< bits per sample (for packed formats) */
120 
121  /* The following member may be set by the application to associate data
122  * with this image.
123  */
124  void *user_priv; /**< may be set by the application to associate data
125  * with this image. */
126 
127  /* The following members should be treated as private. */
128  unsigned char *img_data; /**< private */
129  int img_data_owner; /**< private */
130  int self_allocd; /**< private */
131 
132  void *fb_priv; /**< Frame buffer data associated with the image. */
133  } vpx_image_t; /**< alias for struct vpx_image */
134 
135  /**\brief Representation of a rectangle on a surface */
136  typedef struct vpx_image_rect {
137  unsigned int x; /**< leftmost column */
138  unsigned int y; /**< topmost row */
139  unsigned int w; /**< width */
140  unsigned int h; /**< height */
141  } vpx_image_rect_t; /**< alias for struct vpx_image_rect */
142 
143  /*!\brief Open a descriptor, allocating storage for the underlying image
144  *
145  * Returns a descriptor for storing an image of the given format. The
146  * storage for the descriptor is allocated on the heap.
147  *
148  * \param[in] img Pointer to storage for descriptor. If this parameter
149  * is NULL, the storage for the descriptor will be
150  * allocated on the heap.
151  * \param[in] fmt Format for the image
152  * \param[in] d_w Width of the image
153  * \param[in] d_h Height of the image
154  * \param[in] align Alignment, in bytes, of the image buffer and
155  * each row in the image(stride).
156  *
157  * \return Returns a pointer to the initialized image descriptor. If the img
158  * parameter is non-null, the value of the img parameter will be
159  * returned.
160  */
162  vpx_img_fmt_t fmt,
163  unsigned int d_w,
164  unsigned int d_h,
165  unsigned int align);
166 
167  /*!\brief Open a descriptor, using existing storage for the underlying image
168  *
169  * Returns a descriptor for storing an image of the given format. The
170  * storage for descriptor has been allocated elsewhere, and a descriptor is
171  * desired to "wrap" that storage.
172  *
173  * \param[in] img Pointer to storage for descriptor. If this parameter
174  * is NULL, the storage for the descriptor will be
175  * allocated on the heap.
176  * \param[in] fmt Format for the image
177  * \param[in] d_w Width of the image
178  * \param[in] d_h Height of the image
179  * \param[in] align Alignment, in bytes, of each row in the image.
180  * \param[in] img_data Storage to use for the image
181  *
182  * \return Returns a pointer to the initialized image descriptor. If the img
183  * parameter is non-null, the value of the img parameter will be
184  * returned.
185  */
187  vpx_img_fmt_t fmt,
188  unsigned int d_w,
189  unsigned int d_h,
190  unsigned int align,
191  unsigned char *img_data);
192 
193 
194  /*!\brief Set the rectangle identifying the displayed portion of the image
195  *
196  * Updates the displayed rectangle (aka viewport) on the image surface to
197  * match the specified coordinates and size.
198  *
199  * \param[in] img Image descriptor
200  * \param[in] x leftmost column
201  * \param[in] y topmost row
202  * \param[in] w width
203  * \param[in] h height
204  *
205  * \return 0 if the requested rectangle is valid, nonzero otherwise.
206  */
207  int vpx_img_set_rect(vpx_image_t *img,
208  unsigned int x,
209  unsigned int y,
210  unsigned int w,
211  unsigned int h);
212 
213 
214  /*!\brief Flip the image vertically (top for bottom)
215  *
216  * Adjusts the image descriptor's pointers and strides to make the image
217  * be referenced upside-down.
218  *
219  * \param[in] img Image descriptor
220  */
221  void vpx_img_flip(vpx_image_t *img);
222 
223  /*!\brief Close an image descriptor
224  *
225  * Frees all allocated storage associated with an image descriptor.
226  *
227  * \param[in] img Image descriptor
228  */
229  void vpx_img_free(vpx_image_t *img);
230 
231 #ifdef __cplusplus
232 } // extern "C"
233 #endif
234 
235 #endif // VPX_VPX_IMAGE_H_
unsigned int r_w
Definition: switch_image.h:103
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.
Image Descriptor.
Definition: switch_image.h:88
vpx_color_space
List of supported color spaces.
Definition: switch_image.h:70
vpx_image_t * vpx_img_alloc(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
unsigned int x
Definition: switch_image.h:137
unsigned int r_h
Definition: switch_image.h:104
int vpx_img_set_rect(vpx_image_t *img, unsigned int x, unsigned int y, unsigned int w, unsigned int h)
Set the rectangle identifying the displayed portion of the image.
int self_allocd
Definition: switch_image.h:130
void vpx_img_flip(vpx_image_t *img)
Flip the image vertically (top for bottom)
int img_data_owner
Definition: switch_image.h:129
unsigned int bit_depth
Definition: switch_image.h:96
enum vpx_color_space vpx_color_space_t
List of supported color spaces.
enum vpx_color_range vpx_color_range_t
List of supported color range.
vpx_color_range_t range
Definition: switch_image.h:91
#define VPX_IMG_FMT_PLANAR
Definition: switch_image.h:34
void * fb_priv
Definition: switch_image.h:132
unsigned int y_chroma_shift
Definition: switch_image.h:108
unsigned int x_chroma_shift
Definition: switch_image.h:107
unsigned int y
Definition: switch_image.h:138
Representation of a rectangle on a surface.
Definition: switch_image.h:136
vpx_image_t * vpx_img_wrap(vpx_image_t *img, vpx_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align, unsigned char *img_data)
Open a descriptor, using existing storage for the underlying image.
unsigned int h
Definition: switch_image.h:140
unsigned int d_w
Definition: switch_image.h:99
int stride[4]
Definition: switch_image.h:117
vpx_img_fmt_t fmt
Definition: switch_image.h:89
unsigned char * planes[4]
Definition: switch_image.h:116
unsigned char * img_data
Definition: switch_image.h:128
#define VPX_IMG_FMT_HAS_ALPHA
Definition: switch_image.h:36
struct vpx_image_rect vpx_image_rect_t
Representation of a rectangle on a surface.
struct vpx_image vpx_image_t
Image Descriptor.
unsigned int h
Definition: switch_image.h:95
vpx_color_range
List of supported color range.
Definition: switch_image.h:82
unsigned int w
Definition: switch_image.h:139
vpx_color_space_t cs
Definition: switch_image.h:90
vpx_img_fmt
List of supported image formats.
Definition: switch_image.h:40
#define VPX_IMG_FMT_HIGHBITDEPTH
Definition: switch_image.h:37
void * user_priv
Definition: switch_image.h:124
unsigned int d_h
Definition: switch_image.h:100
unsigned int w
Definition: switch_image.h:94
enum vpx_img_fmt vpx_img_fmt_t
List of supported image formats.
#define VPX_IMG_FMT_UV_FLIP
Definition: switch_image.h:35