FreeSWITCH API Documentation  1.7.0
switch_core_video.h
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Seven Du <dujinfang@gmail.com>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  * Anthony Minessale II <anthm@freeswitch.org>
26  *
27  *
28  * switch_core_video.h -- Core Video header
29  *
30  */
31 /*! \file switch_core_video.h
32  \brief video includes header
33 
34  The things powered by libvpx are renamed into the switch_ namespace to provide a cleaner
35  look to things and helps me to document what parts of video I am using I'd like to take this
36  opportunity to thank libvpx for all the awesome stuff it does and for making my life much easier.
37 
38 */
39 
40 #ifndef SWITCH_VIDEO_H
41 #define SWITCH_VIDEO_H
42 
43 #include <switch.h>
44 
46 
47 typedef enum {
59 
60 typedef enum {
66 
67 typedef struct switch_yuv_color_s {
68  uint8_t y;
69  uint8_t u;
70  uint8_t v;
72 
73 typedef struct switch_rgb_color_s {
74  uint8_t a;
75  uint8_t r;
76  uint8_t g;
77  uint8_t b;
79 
80 /**\brief Representation of a rectangle on a surface */
81 typedef struct switch_image_rect {
82  unsigned int x; /**< leftmost column */
83  unsigned int y; /**< topmost row */
84  unsigned int w; /**< width */
85  unsigned int h; /**< height */
87 
88 typedef enum {
91 
92 struct switch_png_opaque_s;
93 typedef struct switch_png_opaque_s switch_png_opaque_t;
94 typedef struct switch_png_s {
96  int w;
97  int h;
98 } switch_png_t;
99 
100 typedef enum {
101  SRM_NONE = 0, // No rotation.
102  SRM_90 = 90, // Rotate 90 degrees clockwise.
103  SRM_180 = 180, // Rotate 180 degrees.
104  SRM_270 = 270, // Rotate 270 degrees clockwise.
106 
107 
108 /*!\brief Open a descriptor, allocating storage for the underlying image
109 *
110 * Returns a descriptor for storing an image of the given format. The
111 * storage for the descriptor is allocated on the heap.
112 *
113 * \param[in] img Pointer to storage for descriptor. If this parameter
114 * is NULL, the storage for the descriptor will be
115 * allocated on the heap.
116 * \param[in] fmt Format for the image
117 * \param[in] d_w Width of the image
118 * \param[in] d_h Height of the image
119 * \param[in] align Alignment, in bytes, of the image buffer and
120 * each row in the image(stride).
121 *
122 * \return Returns a pointer to the initialized image descriptor. If the img
123 * parameter is non-null, the value of the img parameter will be
124 * returned.
125 */
127  switch_img_fmt_t fmt,
128  unsigned int d_w,
129  unsigned int d_h,
130  unsigned int align);
131 
132 /*!\brief Open a descriptor, using existing storage for the underlying image
133 *
134 * Returns a descriptor for storing an image of the given format. The
135 * storage for descriptor has been allocated elsewhere, and a descriptor is
136 * desired to "wrap" that storage.
137 *
138 * \param[in] img Pointer to storage for descriptor. If this parameter
139 * is NULL, the storage for the descriptor will be
140 * allocated on the heap.
141 * \param[in] fmt Format for the image
142 * \param[in] d_w Width of the image
143 * \param[in] d_h Height of the image
144 * \param[in] align Alignment, in bytes, of each row in the image.
145 * \param[in] img_data Storage to use for the image
146 *
147 * \return Returns a pointer to the initialized image descriptor. If the img
148 * parameter is non-null, the value of the img parameter will be
149 * returned.
150 */
152  switch_img_fmt_t fmt,
153  unsigned int d_w,
154  unsigned int d_h,
155  unsigned int align,
156  unsigned char *img_data);
157 
158 
159 /*!\brief Set the rectangle identifying the displayed portion of the image
160 *
161 * Updates the displayed rectangle (aka viewport) on the image surface to
162 * match the specified coordinates and size.
163 *
164 * \param[in] img Image descriptor
165 * \param[in] x leftmost column
166 * \param[in] y topmost row
167 * \param[in] w width
168 * \param[in] h height
169 *
170 * \return 0 if the requested rectangle is valid, nonzero otherwise.
171 */
173  unsigned int x,
174  unsigned int y,
175  unsigned int w,
176  unsigned int h);
177 
178 /*!\brief patch a small img to a big IMG at position x,y
179 *
180 * Both IMG and img must be non-NULL
181 *
182 * \param[in] IMG The BIG Image descriptor
183 * \param[in] img The small Image descriptor
184 * \param[in] x Leftmost pos to patch to
185 * \param[in] y Topmost pos to patch to
186 */
187 SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y);
188 
189 
190 /*!\brief patch part of a small img (x,y,w,h) to a big IMG at position X,Y
191 *
192 * Both IMG and img must be non-NULL
193 *
194 * \param[in] IMG The BIG Image descriptor
195 * \param[in] X Leftmost pos to patch to IMG
196 * \param[in] Y Topmost pos to patch to IMG
197 * \param[in] img The small Image descriptor
198 * \param[in] x Leftmost pos to be read from img
199 * \param[in] y Topmost pos to be read from
200 * \param[in] w Max width to be read from img
201 * \param[in] h Max height to be read from img
202 */
203 
204 SWITCH_DECLARE(void) switch_img_patch_rect(switch_image_t *IMG, int X, int Y, switch_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h);
205 
206 /*!\brief Copy image to a new image
207 *
208 * if new_img is NULL, a new image is allocated
209 * if new_img is not NULL but not the same size as img,
210 * new_img is destroyed and a new new_img is allocated
211 * else, copy the img data to the new_img
212 *
213 * \param[in] img Image descriptor
214 * \param[out] new_img New Image descriptor, NULL if out of memory
215 */
216 
219 
220 /*!\brief Flip the image vertically (top for bottom)
221 *
222 * Adjusts the image descriptor's pointers and strides to make the image
223 * be referenced upside-down.
224 *
225 * \param[in] img Image descriptor
226 *
227 * \return 0 if the requested rectangle is valid, nonzero otherwise.
228 */
230 
231 /*!\brief Close an image descriptor
232 *
233 * Frees all allocated storage associated with an image descriptor.
234 *
235 * \param[in] img pointer to pointer of Image descriptor
236 */
238 
239 SWITCH_DECLARE(void) switch_img_draw_text(switch_image_t *IMG, int x, int y, switch_rgb_color_t color, uint16_t font_size, char *text);
240 
241 SWITCH_DECLARE(void) switch_img_add_text(void *buffer, int w, int x, int y, char *s);
242 
243 /*!\brief Copy part of an image to a new image
244 *
245 *
246 * \param[in] img Image descriptor
247 * \param[in] x Leftmost pos to be read from
248 * \param[in] y Topmost pos to be read from
249 * \param[in] w Max width to be read from
250 * \param[in] h Max height to be read from
251 *
252 * \return NULL if failed to copy, otherwise a valid image descriptor.
253 */
254 SWITCH_DECLARE(switch_image_t *) switch_img_copy_rect(switch_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h);
255 
256 /*!\brief Fill image with color
257 *
258 * \param[in] img Image descriptor
259 * \param[in] x Leftmost pos to be read from
260 * \param[in] y Topmost pos to be read from
261 * \param[in] w Max width to be read from
262 * \param[in] h Max height to be read from
263 * \param[in] color RGB color
264 */
265 SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color);
266 
267 /*!\brief Set RGB color with a string
268 *
269 * Color string should be in #RRGGBB format
270 *
271 * \param[out] color RGB color pointer
272 * \param[in] color_str Color string in #RRGGBB format
273 */
274 SWITCH_DECLARE(void) switch_color_set_rgb(switch_rgb_color_t *color, const char *color_str);
275 
276 /*!\brief Set YUV color with a string
277 *
278 * Color string should be in #RRGGBB format
279 *
280 * \param[out] color YUV color pointer
281 * \param[in] color_str Color string in #RRGGBB format
282 */
283 SWITCH_DECLARE(void) switch_color_set_yuv(switch_yuv_color_t *color, const char *color_str);
284 
285 /*!\brief Created a text handle
286 *
287 * \param[out] handleP Pointer to the text handle pointer
288 * \param[in] font_family Font family
289 * \param[in] font_color Font color in #RRGGBB format
290 * \param[in] bgcolor Background color in #RRGGBB format
291 * \param[in] font_size Font size in point
292 * \param[in] angle Angle to rotate
293 * \param[in] pool APR memory pool
294 */
296  const char *font_color, const char *bgcolor, uint16_t font_size, double angle, switch_memory_pool_t *pool);
297 
298 /*!\brief Free a text handle
299 *
300 * \param[in] handleP Pointer to the text handle pointer
301 */
303 
304 /*!\brief Render text to an img
305 *
306 * \param[in] handle Pointer to the text handle pointer
307 * \param[in] img The image to be render text on
308 * \param[in] x Leftmost position
309 * \param[in] y Topmost position
310 * \param[in] text Text to render
311 * \param[in] font_family Font to use, NULL to use the handle font
312 * \param[in] font_color Font color, NULL to use the handle color
313 * \param[in] bgcolor Background color, NULL for transparency
314 * \param[in] font_size Font size in point
315 * \param[in] angle Angle to rotate
316 */
317 
319  int x, int y, const char *text,
320  const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle);
321 
322 
324 
326 SWITCH_DECLARE(switch_image_t *) switch_img_read_png(const char *file_name, switch_img_fmt_t img_fmt);
328 SWITCH_DECLARE(switch_status_t) switch_png_open(switch_png_t **pngP, const char *file_name);
330 
331 /*!\brief put a small img over a big IMG at position x,y, with alpha transparency
332 *
333 * Both IMG and img must be non-NULL
334 *
335 * \param[in] IMG The BIG Image descriptor
336 * \param[in] img The small Image descriptor
337 * \param[in] x Leftmost pos
338 * \param[in] y Topmost pos
339 * \param[in] percent Alaha value from 0(completely transparent) to 100(opaque)
340 */
341 SWITCH_DECLARE(void) switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t percent);
342 
343 SWITCH_DECLARE(switch_status_t) switch_img_scale(switch_image_t *src, switch_image_t **destP, int width, int height);
347 SWITCH_DECLARE(void) switch_img_find_position(switch_img_position_t pos, int sw, int sh, int iw, int ih, int *xP, int *yP);
348 
349 /*!\brief convert img to raw format
350 *
351 * dest should be pre-allocated and big enough for the target fmt
352 *
353 * \param[in] src The image descriptor
354 * \param[in] dest The target memory address
355 * \param[in] size The size of target memory address used for bounds check
356 * \param[in] fmt The target format
357 */
359 /*!\brief convert raw memory to switch_img_t
360 *
361 * if dest is NULL then a new img is created, user should destroy it later,
362 * otherwize it will re-used the dest img, and the dest img size must match the src width and height,
363 * width and height can be 0 in the latter case and it will figure out according to the dest img
364 *
365 * \param[in] dest The image descriptor
366 * \param[in] src The raw data memory address
367 * \param[in] fmt The raw data format
368 * \param[in] width The raw data width
369 * \param[in] height The raw data height
370 */
371 SWITCH_DECLARE(switch_status_t) switch_img_from_raw(switch_image_t *dest, void *src, switch_img_fmt_t fmt, int width, int height);
372 SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, switch_bool_t full, const char *text);
373 
374 SWITCH_DECLARE(switch_image_t *) switch_img_read_file(const char* file_name);
375 SWITCH_DECLARE(switch_status_t) switch_img_letterbox(switch_image_t *img, switch_image_t **imgP, int width, int height, const char *color);
377 
378 /*!\brief I420 to I420 Copy*/
379 
380 SWITCH_DECLARE(switch_status_t) switch_I420_copy(const uint8_t* src_y, int src_stride_y,
381  const uint8_t* src_u, int src_stride_u,
382  const uint8_t* src_v, int src_stride_v,
383  uint8_t* dst_y, int dst_stride_y,
384  uint8_t* dst_u, int dst_stride_u,
385  uint8_t* dst_v, int dst_stride_v,
386  int width, int height);
387 SWITCH_DECLARE(switch_status_t) switch_I420_copy2(uint8_t *src_planes[], int src_stride[],
388  uint8_t *dst_planes[], int dst_stride[],
389  int width, int height);
390 /** @} */
391 
393 #endif
394 /* For Emacs:
395  * Local Variables:
396  * mode:c
397  * indent-tabs-mode:t
398  * tab-width:4
399  * c-basic-offset:4
400  * End:
401  * For VIM:
402  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
403  */
switch_status_t switch_I420_copy2(uint8_t *src_planes[], int src_stride[], uint8_t *dst_planes[], int dst_stride[], int width, int height)
Image Descriptor.
Definition: switch_image.h:88
void switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y)
patch a small img to a big IMG at position x,y
void switch_img_patch_rect(switch_image_t *IMG, int X, int Y, switch_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
patch part of a small img (x,y,w,h) to a big IMG at position X,Y
switch_img_position_t parse_img_position(const char *name)
void switch_img_free(switch_image_t **img)
Close an image descriptor.
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
void switch_color_set_yuv(switch_yuv_color_t *color, const char *color_str)
Set YUV color with a string.
switch_bool_t switch_core_has_video(void)
struct switch_png_s switch_png_t
switch_status_t switch_img_from_raw(switch_image_t *dest, void *src, switch_img_fmt_t fmt, int width, int height)
convert raw memory to switch_img_t
switch_bool_t
Definition: switch_types.h:405
switch_memory_pool_t * pool
Representation of a rectangle on a surface.
switch_status_t switch_img_txt_handle_create(switch_img_txt_handle_t **handleP, const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle, switch_memory_pool_t *pool)
Created a text handle.
void switch_img_find_position(switch_img_position_t pos, int sw, int sh, int iw, int ih, int *xP, int *yP)
switch_image_t * switch_img_alloc(switch_image_t *img, switch_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
void switch_png_free(switch_png_t **pngP)
struct switch_image_rect switch_image_rect_t
Representation of a rectangle on a surface.
switch_png_opaque_t * pvt
switch_img_fit_t parse_img_fit(const char *name)
void switch_img_rotate_copy(switch_image_t *img, switch_image_t **new_img, switch_image_rotation_mode_t mode)
switch_img_fit_t
void switch_img_draw_text(switch_image_t *IMG, int x, int y, switch_rgb_color_t color, uint16_t font_size, char *text)
switch_img_position_t
void switch_img_copy(switch_image_t *img, switch_image_t **new_img)
Copy image to a new image.
switch_status_t switch_img_fit(switch_image_t **srcP, int width, int height, switch_img_fit_t fit)
switch_byte_t switch_byte_t uint32_t switch_bitpack_mode_t mode
switch_image_t * switch_img_read_png(const char *file_name, switch_img_fmt_t img_fmt)
switch_status_t switch_png_patch_img(switch_png_t *use_png, switch_image_t *img, int x, int y)
uintptr_t switch_size_t
switch_image_t * switch_img_copy_rect(switch_image_t *img, uint32_t x, uint32_t y, uint32_t w, uint32_t h)
Copy part of an image to a new image.
struct switch_png_opaque_s switch_png_opaque_t
switch_status_t switch_img_scale(switch_image_t *src, switch_image_t **destP, int width, int height)
void switch_img_patch_hole(switch_image_t *IMG, switch_image_t *img, int x, int y, switch_image_rect_t *rect)
switch_status_t switch_img_letterbox(switch_image_t *img, switch_image_t **imgP, int width, int height, const char *color)
void switch_color_set_rgb(switch_rgb_color_t *color, const char *color_str)
Set RGB color with a string.
vpx_img_fmt_t switch_img_fmt_t
Definition: switch_vpx.h:91
switch_status_t switch_I420_copy(const uint8_t *src_y, int src_stride_y, const uint8_t *src_u, int src_stride_u, const uint8_t *src_v, int src_stride_v, uint8_t *dst_y, int dst_stride_y, uint8_t *dst_u, int dst_stride_u, uint8_t *dst_v, int dst_stride_v, int width, int height)
I420 to I420 Copy.
struct switch_rgb_color_s switch_rgb_color_t
switch_status_t
Common return values.
void switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color)
Fill image with color.
switch_status_t switch_png_open(switch_png_t **pngP, const char *file_name)
Main Library Header.
void switch_img_txt_handle_destroy(switch_img_txt_handle_t **handleP)
Free a text handle.
#define SWITCH_DECLARE(type)
switch_convert_fmt_t
switch_status_t switch_img_to_raw(switch_image_t *src, void *dest, switch_size_t size, switch_img_fmt_t fmt)
convert img to raw format
struct apr_pool_t switch_memory_pool_t
switch_status_t switch_img_write_png(switch_image_t *img, char *file_name)
switch_image_t * switch_img_read_file(const char *file_name)
switch_image_rotation_mode_t
void switch_img_overlay(switch_image_t *IMG, switch_image_t *img, int x, int y, uint8_t percent)
put a small img over a big IMG at position x,y, with alpha transparency
switch_image_t * switch_img_write_text_img(int w, int h, switch_bool_t full, const char *text)
void switch_img_add_text(void *buffer, int w, int x, int y, char *s)
struct switch_yuv_color_s switch_yuv_color_t
void switch_img_rotate(switch_image_t **img, switch_image_rotation_mode_t mode)
Flip the image vertically (top for bottom)
switch_image_t * switch_img_wrap(switch_image_t *img, switch_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.
uint32_t switch_img_txt_handle_render(switch_img_txt_handle_t *handle, switch_image_t *img, int x, int y, const char *text, const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle)
Render text to an img.
int switch_img_set_rect(switch_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.
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42