FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Functions | Variables
switch_core_video.c File Reference
#include <switch.h>
#include <switch_utf8.h>
+ Include dependency graph for switch_core_video.c:

Go to the source code of this file.

Data Structures

struct  pos_el
 
struct  fit_el
 
struct  switch_img_txt_handle_s
 

Macros

#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define CLAMP(val)   MAX(0, MIN(val, 255))
 
#define MAX_GRADIENT   8
 
#define SWITCH_IMG_MAX_WIDTH   1920 * 2
 
#define SWITCH_IMG_MAX_HEIGHT   1080 * 2
 

Functions

static void switch_img_get_rgb_pixel (switch_image_t *img, switch_rgb_color_t *rgb, int x, int y)
 
static void switch_img_draw_pixel (switch_image_t *img, int x, int y, switch_rgb_color_t *color)
 Convert RGB color to YUV. More...
 
switch_img_position_t parse_img_position (const char *name)
 
switch_img_fit_t parse_img_fit (const char *name)
 
switch_bool_t switch_core_has_video (void)
 
switch_image_tswitch_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. More...
 
switch_image_tswitch_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. More...
 
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. More...
 
void switch_img_rotate (switch_image_t **img, switch_image_rotation_mode_t mode)
 Flip the image vertically (top for bottom) More...
 
void switch_img_free (switch_image_t **img)
 Close an image descriptor. More...
 
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 More...
 
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 More...
 
void switch_img_copy (switch_image_t *img, switch_image_t **new_img)
 Copy image to a new image. More...
 
void switch_img_rotate_copy (switch_image_t *img, switch_image_t **new_img, switch_image_rotation_mode_t mode)
 
switch_image_tswitch_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. More...
 
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. More...
 
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 More...
 
static void scv_tag (void *buffer, int w, int x, int y, uint8_t n)
 
void switch_img_add_text (void *buffer, int w, int x, int y, char *s)
 
void switch_color_set_rgb (switch_rgb_color_t *color, const char *str)
 Set RGB color with a string. More...
 
void switch_color_set_yuv (switch_yuv_color_t *color, const char *str)
 Set YUV color with a string. More...
 
static void init_gradient_table (switch_img_txt_handle_t *handle)
 
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. More...
 
void switch_img_txt_handle_destroy (switch_img_txt_handle_t **handleP)
 Free a text handle. More...
 
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. More...
 
switch_image_tswitch_img_write_text_img (int w, int h, switch_bool_t full, const char *text)
 
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_patch_png (switch_image_t *img, int x, int y, const char *file_name)
 
switch_image_tswitch_img_read_png (const char *file_name, switch_img_fmt_t img_fmt)
 
switch_status_t switch_img_write_png (switch_image_t *img, char *file_name)
 
switch_status_t switch_img_letterbox (switch_image_t *img, switch_image_t **imgP, int width, int height, const char *color)
 
switch_status_t switch_img_fit (switch_image_t **srcP, int width, int height, switch_img_fit_t fit)
 
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 More...
 
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 More...
 
switch_status_t switch_img_scale (switch_image_t *src, switch_image_t **destP, int width, int height)
 
void switch_img_find_position (switch_img_position_t pos, int sw, int sh, int iw, int ih, int *xP, int *yP)
 
switch_image_tswitch_img_read_file (const char *file_name)
 
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. More...
 
switch_status_t switch_I420_copy2 (uint8_t *src_planes[], int src_stride[], uint8_t *dst_planes[], int dst_stride[], int width, int height)
 

Variables

static struct pos_el POS_TABLE []
 
static struct fit_el IMG_FIT_TABLE []
 
static uint8_t scv_art [14][16]
 

Macro Definition Documentation

#define CLAMP (   val)    MAX(0, MIN(val, 255))

Definition at line 770 of file switch_core_video.c.

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

Definition at line 286 of file switch_core_video.c.

#define MAX_GRADIENT   8

Definition at line 808 of file switch_core_video.c.

Referenced by init_gradient_table().

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))
#define SWITCH_IMG_MAX_HEIGHT   1080 * 2

Definition at line 1273 of file switch_core_video.c.

#define SWITCH_IMG_MAX_WIDTH   1920 * 2

Definition at line 1272 of file switch_core_video.c.

Function Documentation

static void init_gradient_table ( switch_img_txt_handle_t handle)
static

Definition at line 827 of file switch_core_video.c.

References switch_rgb_color_s::b, switch_img_txt_handle_s::bgcolor, switch_img_txt_handle_s::color, switch_rgb_color_s::g, switch_img_txt_handle_s::gradient_table, MAX_GRADIENT, and switch_rgb_color_s::r.

Referenced by switch_img_txt_handle_create(), and switch_img_txt_handle_render().

828 {
829  int i;
830  switch_rgb_color_t *color;
831 
832  switch_rgb_color_t *c1 = &handle->bgcolor;
833  switch_rgb_color_t *c2 = &handle->color;
834 
835  for (i = 0; i < MAX_GRADIENT; i++) {
836  color = &handle->gradient_table[i];
837  color->r = c1->r + (c2->r - c1->r) * i / MAX_GRADIENT;
838  color->g = c1->g + (c2->g - c1->g) * i / MAX_GRADIENT;
839  color->b = c1->b + (c2->b - c1->b) * i / MAX_GRADIENT;
840  }
841 }
switch_rgb_color_t color
#define MAX_GRADIENT
switch_rgb_color_t bgcolor
switch_rgb_color_t gradient_table[MAX_GRADIENT]
switch_img_fit_t parse_img_fit ( const char *  name)

Definition at line 139 of file switch_core_video.c.

References fit_el::fit, fit_el::name, switch_assert, and SWITCH_FIT_SIZE.

140 {
142  int i;
143 
144  switch_assert(name);
145 
146  for(i = 0; IMG_FIT_TABLE[i].name; i++) {
147  if (!strcasecmp(IMG_FIT_TABLE[i].name, name)) {
148  r = IMG_FIT_TABLE[i].fit;
149  break;
150  }
151  }
152 
153  return r;
154 }
const char * name
switch_img_fit_t
switch_img_fit_t fit
static struct fit_el IMG_FIT_TABLE[]
#define switch_assert(expr)
switch_img_position_t parse_img_position ( const char *  name)

Definition at line 107 of file switch_core_video.c.

References pos_el::name, pos_el::pos, POS_NONE, and switch_assert.

108 {
110  int i;
111 
112  switch_assert(name);
113 
114  for(i = 0; POS_TABLE[i].name; i++) {
115  if (!strcasecmp(POS_TABLE[i].name, name)) {
116  r = POS_TABLE[i].pos;
117  break;
118  }
119  }
120 
121  return r;
122 }
static struct pos_el POS_TABLE[]
switch_img_position_t pos
switch_img_position_t
#define switch_assert(expr)
const char * name
static void scv_tag ( void *  buffer,
int  w,
int  x,
int  y,
uint8_t  n 
)
static

Definition at line 698 of file switch_core_video.c.

Referenced by switch_img_add_text().

699 {
700  int i = 0, j=0;
701  uint8_t *p = buffer;
702 
703  if (n > 13) return;
704 
705  for(i=0; i<8; i++) {
706  for (j=0; j<16; j++) {
707  *( p + (y + j) * w + (x + i)) = (scv_art[n][j] & 0x80 >> i) ? 0xFF : 0x00;
708  }
709  }
710 }
static uint8_t scv_art[14][16]
void switch_color_set_rgb ( switch_rgb_color_t color,
const char *  color_str 
)

Set RGB color with a string.

Color string should be in #RRGGBB format

Parameters
[out]colorRGB color pointer
[in]color_strColor string in #RRGGBB format

Definition at line 734 of file switch_core_video.c.

References zstr.

Referenced by switch_color_set_yuv(), switch_core_media_bug_patch_spy_frame(), switch_img_letterbox(), switch_img_txt_handle_create(), switch_img_txt_handle_render(), switch_img_write_text_img(), and video_helper_thread().

735 {
736  if (zstr(str)) return;
737 
738  if ((*str) == '#' && strlen(str) == 7) {
739  unsigned int r, g, b;
740  sscanf(str, "#%02x%02x%02x", &r, &g, &b);
741  color->r = r;
742  color->g = g;
743  color->b = b;
744  } else {
745  if (!strcmp(str, "red")) {
746  color->r = 255;
747  color->g = 0;
748  color->b = 0;
749  } else if (!strcmp(str, "green")) {
750  color->r = 0;
751  color->g = 255;
752  color->b = 0;
753  } else if (!strcmp(str, "blue")) {
754  color->r = 0;
755  color->g = 0;
756  color->b = 255;
757  }
758  }
759 }
#define zstr(x)
Definition: switch_utils.h:281
void switch_color_set_yuv ( switch_yuv_color_t color,
const char *  color_str 
)

Set YUV color with a string.

Color string should be in #RRGGBB format

Parameters
[out]colorYUV color pointer
[in]color_strColor string in #RRGGBB format

Definition at line 792 of file switch_core_video.c.

References switch_color_set_rgb().

793 {
794 #ifdef SWITCH_HAVE_YUV
795  switch_rgb_color_t rgb = { 0 };
796 
797  switch_color_set_rgb(&rgb, str);
798  switch_color_rgb2yuv(&rgb, color);
799 #endif
800 }
void switch_color_set_rgb(switch_rgb_color_t *color, const char *str)
Set RGB color with a string.
switch_bool_t switch_core_has_video ( void  )

Definition at line 156 of file switch_core_video.c.

References SWITCH_FALSE, and SWITCH_TRUE.

157 {
158 #ifdef SWITCH_HAVE_VPX
159 #ifdef SWITCH_HAVE_YUV
160  return SWITCH_TRUE;
161 #else
162  return SWITCH_FALSE;
163 #endif
164 #else
165  return SWITCH_FALSE;
166 #endif
167 }
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.

Definition at line 2252 of file switch_core_video.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

2259 {
2260 #ifdef SWITCH_HAVE_YUV
2261  int ret = I420Copy(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
2262  dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v,
2263  width, height);
2264  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
2265 #else
2266  return SWITCH_STATUS_FALSE;
2267 #endif
2268 }
switch_status_t switch_I420_copy2 ( uint8_t *  src_planes[],
int  src_stride[],
uint8_t *  dst_planes[],
int  dst_stride[],
int  width,
int  height 
)

Definition at line 2270 of file switch_core_video.c.

References SWITCH_PLANE_U, SWITCH_PLANE_V, SWITCH_PLANE_Y, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

2273 {
2274 #ifdef SWITCH_HAVE_YUV
2275  int ret = I420Copy(src_planes[SWITCH_PLANE_Y], src_stride[SWITCH_PLANE_Y],
2276  src_planes[SWITCH_PLANE_U], src_stride[SWITCH_PLANE_U],
2277  src_planes[SWITCH_PLANE_V], src_stride[SWITCH_PLANE_V],
2278  dst_planes[SWITCH_PLANE_Y], dst_stride[SWITCH_PLANE_Y],
2279  dst_planes[SWITCH_PLANE_U], dst_stride[SWITCH_PLANE_U],
2280  dst_planes[SWITCH_PLANE_V], dst_stride[SWITCH_PLANE_V],
2281  width, height);
2282  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
2283 #else
2284  return SWITCH_STATUS_FALSE;
2285 #endif
2286 }
#define SWITCH_PLANE_V
Definition: switch_vpx.h:55
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
void switch_img_add_text ( void *  buffer,
int  w,
int  x,
int  y,
char *  s 
)

Definition at line 712 of file switch_core_video.c.

References scv_tag().

713 {
714  while (*s) {
715  int index;
716 
717  if (x > w - 8) break;
718 
719  switch (*s) {
720  case '.': index = 10; break;
721  case ':': index = 11; break;
722  case '-': index = 12; break;
723  case ' ': index = 13; break;
724  default:
725  index = *s - 0x30;
726  }
727 
728  scv_tag(buffer, w, x, y, index);
729  x += 8;
730  s++;
731  }
732 }
static void scv_tag(void *buffer, int w, int x, int y, uint8_t n)
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.

Returns a descriptor for storing an image of the given format. The storage for the descriptor is allocated on the heap.

Parameters
[in]imgPointer to storage for descriptor. If this parameter is NULL, the storage for the descriptor will be allocated on the heap.
[in]fmtFormat for the image
[in]d_wWidth of the image
[in]d_hHeight of the image
[in]alignAlignment, in bytes, of the image buffer and each row in the image(stride).
Returns
Returns a pointer to the initialized image descriptor. If the img parameter is non-null, the value of the img parameter will be returned.

Definition at line 169 of file switch_core_video.c.

References SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_GD, switch_img_free(), and vpx_img_alloc().

Referenced by switch_img_copy(), switch_img_from_raw(), switch_img_letterbox(), switch_img_rotate(), switch_img_rotate_copy(), switch_img_scale(), switch_img_write_text_img(), video_bug_thread(), and video_helper_thread().

174 {
175 #ifdef SWITCH_HAVE_VPX
176 #ifdef HAVE_LIBGD
177  if (fmt == SWITCH_IMG_FMT_GD) {
178  gdImagePtr gd = gdImageCreateTrueColor(d_w, d_h);
179 
180  if (!gd) return NULL;
181 
182  switch_img_free(&img);
183  img = (switch_image_t *)vpx_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, 1, 1, 1);
184 
185  if (!img) {
186  gdImageDestroy(gd);
187  return NULL;
188  }
189 
190  img->user_priv = gd;
191  img->d_w = d_w;
192  img->d_h = d_h;
193  img->fmt = SWITCH_IMG_FMT_GD;
194  return img;
195  }
196 #endif
197 
198  return (switch_image_t *)vpx_img_alloc((vpx_image_t *)img, (vpx_img_fmt_t)fmt, d_w, d_h, align);
199 #else
200  return NULL;
201 #endif
202 }
Image Descriptor.
Definition: switch_image.h:88
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.
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
void switch_img_free(switch_image_t **img)
Close an image descriptor.
unsigned int d_w
Definition: switch_image.h:99
#define SWITCH_IMG_FMT_GD
Definition: switch_vpx.h:89
vpx_img_fmt_t fmt
Definition: switch_image.h:89
void * user_priv
Definition: switch_image.h:124
unsigned int d_h
Definition: switch_image.h:100
enum vpx_img_fmt vpx_img_fmt_t
List of supported image formats.
void switch_img_copy ( switch_image_t img,
switch_image_t **  new_img 
)

Copy image to a new image.

if new_img is NULL, a new image is allocated if new_img is not NULL but not the same size as img, new_img is destroyed and a new new_img is allocated else, copy the img data to the new_img

Parameters
[in]imgImage descriptor
[out]new_imgNew Image descriptor, NULL if out of memory

Definition at line 420 of file switch_core_video.c.

References switch_assert, switch_img_alloc(), SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, switch_img_free(), SWITCH_PLANE_PACKED, SWITCH_PLANE_U, SWITCH_PLANE_V, and SWITCH_PLANE_Y.

Referenced by find_free_frame(), switch_core_media_bug_patch_spy_frame(), switch_core_media_bug_push_spy_frame(), switch_core_session_read_video_frame(), switch_core_session_write_video_frame(), switch_frame_dup(), switch_img_copy_rect(), switch_img_letterbox(), and video_write_overlay_callback().

421 {
422  switch_assert(img);
423  switch_assert(new_img);
424 
425 #ifdef SWITCH_HAVE_YUV
426  if (img->fmt != SWITCH_IMG_FMT_I420 && img->fmt != SWITCH_IMG_FMT_ARGB) return;
427 
428  if (*new_img != NULL) {
429  if (img->fmt != (*new_img)->fmt || img->d_w != (*new_img)->d_w || img->d_h != (*new_img)->d_w) {
430  switch_img_free(new_img);
431  }
432  }
433 
434  if (*new_img == NULL) {
435  *new_img = switch_img_alloc(NULL, img->fmt, img->d_w, img->d_h, 1);
436  }
437 
438  switch_assert(*new_img);
439 
440  if (img->fmt == SWITCH_IMG_FMT_I420) {
441  I420Copy(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
444  (*new_img)->planes[SWITCH_PLANE_Y], (*new_img)->stride[SWITCH_PLANE_Y],
445  (*new_img)->planes[SWITCH_PLANE_U], (*new_img)->stride[SWITCH_PLANE_U],
446  (*new_img)->planes[SWITCH_PLANE_V], (*new_img)->stride[SWITCH_PLANE_V],
447  img->d_w, img->d_h);
448  } else if (img->fmt == SWITCH_IMG_FMT_ARGB) {
450  (*new_img)->planes[SWITCH_PLANE_PACKED], (*new_img)->stride[SWITCH_PLANE_PACKED],
451  img->d_w, img->d_h);
452  }
453 #else
454  return;
455 #endif
456 }
#define SWITCH_PLANE_V
Definition: switch_vpx.h:55
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
void switch_img_free(switch_image_t **img)
Close an image descriptor.
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
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
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.
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
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.

Parameters
[in]imgImage descriptor
[in]xLeftmost pos to be read from
[in]yTopmost pos to be read from
[in]wMax width to be read from
[in]hMax height to be read from
Returns
NULL if failed to copy, otherwise a valid image descriptor.

Definition at line 496 of file switch_core_video.c.

References MIN, switch_assert, switch_img_copy(), SWITCH_IMG_FMT_PLANAR, switch_img_free(), switch_img_set_rect(), SWITCH_PLANE_PACKED, SWITCH_PLANE_Y, and vpx_img_wrap().

Referenced by switch_core_media_bug_patch_spy_frame().

497 {
498 #ifdef SWITCH_HAVE_VPX
499  switch_image_t *new_img = NULL, *tmp;
500  uint8_t *data;
501 
502  switch_assert(img);
503 
504  if (x >= img->d_w || y >= img->d_h) return NULL;
505 
506  if (!(img->fmt & SWITCH_IMG_FMT_PLANAR)) {
507  data = img->planes[SWITCH_PLANE_PACKED];
508  } else {
509  data = img->planes[SWITCH_PLANE_Y];
510  }
511 
512  tmp = (switch_image_t *)vpx_img_wrap(NULL, img->fmt, img->d_w, img->d_h, 1, data);
513  if (!tmp) return NULL;
514 
515  w = MIN(img->d_w - x, w);
516  h = MIN(img->d_h - y, h);
517 
518  if (!switch_img_set_rect(tmp, x, y, w, h)) {
519  switch_img_copy(tmp, &new_img);
520  }
521 
522  switch_img_free(&tmp);
523 
524  return new_img;
525 #else
526  return NULL;
527 #endif
528 }
Image Descriptor.
Definition: switch_image.h:88
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
void switch_img_copy(switch_image_t *img, switch_image_t **new_img)
Copy image to a new image.
void switch_img_free(switch_image_t **img)
Close an image descriptor.
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 d_w
Definition: switch_image.h:99
vpx_img_fmt_t fmt
Definition: switch_image.h:89
unsigned char * planes[4]
Definition: switch_image.h:116
#define SWITCH_IMG_FMT_PLANAR
Definition: switch_vpx.h:47
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
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.
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
#define MIN(a, b)
static void switch_img_draw_pixel ( switch_image_t img,
int  x,
int  y,
switch_rgb_color_t color 
)
inlinestatic

Convert RGB color to YUV.

Parameters
[in]rgbRGB color pointer
[out]yuvYUV color pointer

Convert YUV color to RGB

Parameters
[in]yuvYUV color pointer
[out]rgbRGB color pointer

Draw a pixel on an image

Parameters
[in]imgImage descriptor
[in]xleftmost pos
[in]ytopmost pos
[in]colorRGB color

Definition at line 530 of file switch_core_video.c.

References switch_rgb_color_s::a, switch_rgb_color_s::b, vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, switch_rgb_color_s::g, vpx_image::planes, switch_rgb_color_s::r, vpx_image::stride, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_PLANE_PACKED, SWITCH_PLANE_U, SWITCH_PLANE_V, SWITCH_PLANE_Y, switch_yuv_color_s::u, switch_yuv_color_s::v, and switch_yuv_color_s::y.

Referenced by switch_img_overlay(), and switch_img_patch().

531 {
532 #ifdef SWITCH_HAVE_YUV
533  switch_yuv_color_t yuv;
534 
535  if (x < 0 || y < 0 || x >= img->d_w || y >= img->d_h) return;
536 
537  if (img->fmt == SWITCH_IMG_FMT_I420) {
538  switch_color_rgb2yuv(color, &yuv);
539 
540  img->planes[SWITCH_PLANE_Y][y * img->stride[SWITCH_PLANE_Y] + x] = yuv.y;
541 
542  if (((x & 0x1) == 0) && ((y & 0x1) == 0)) {// only draw on even position
543  img->planes[SWITCH_PLANE_U][y / 2 * img->stride[SWITCH_PLANE_U] + x / 2] = yuv.u;
544  img->planes[SWITCH_PLANE_V][y / 2 * img->stride[SWITCH_PLANE_V] + x / 2] = yuv.v;
545  }
546  } else if (img->fmt == SWITCH_IMG_FMT_ARGB) {
547  uint8_t *alpha = img->planes[SWITCH_PLANE_PACKED] + img->d_w * 4 * y + x * 4;
548  *(alpha ) = color->a;
549  *(alpha + 1) = color->r;
550  *(alpha + 2) = color->g;
551  *(alpha + 3) = color->b;
552  }
553 #endif
554 }
#define SWITCH_PLANE_V
Definition: switch_vpx.h:55
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
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
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
unsigned int d_h
Definition: switch_image.h:100
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.

Parameters
[in]imgImage descriptor
[in]xLeftmost pos to be read from
[in]yTopmost pos to be read from
[in]wMax width to be read from
[in]hMax height to be read from
[in]colorRGB color

Definition at line 556 of file switch_core_video.c.

References memset(), MIN, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_PLANE_PACKED, SWITCH_PLANE_U, SWITCH_PLANE_V, SWITCH_PLANE_Y, switch_yuv_color_s::u, switch_yuv_color_s::v, and switch_yuv_color_s::y.

Referenced by switch_core_media_bug_patch_spy_frame(), switch_img_letterbox(), switch_img_write_text_img(), and video_helper_thread().

557 {
558 #ifdef SWITCH_HAVE_YUV
559  int len, i, max_h;
560  switch_yuv_color_t yuv_color;
561 
562  if (x < 0 || y < 0 || x >= img->d_w || y >= img->d_h) return;
563 
564  if (img->fmt == SWITCH_IMG_FMT_I420) {
565  switch_color_rgb2yuv(color, &yuv_color);
566 
567  max_h = MIN(y + h, img->d_h);
568  len = MIN(w, img->d_w - x);
569 
570  if (x & 1) { x++; len--; }
571  if (y & 1) y++;
572  if (len <= 0) return;
573 
574  for (i = y; i < max_h; i++) {
575  memset(img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * i + x, yuv_color.y, len);
576  }
577 
578  if ((len & 1) && (x + len) < img->d_w - 1) len++;
579 
580  len /= 2;
581 
582  for (i = y; i < max_h; i += 2) {
583  memset(img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * (i / 2) + x / 2, yuv_color.u, len);
584  memset(img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * (i / 2) + x / 2, yuv_color.v, len);
585  }
586  } else if (img->fmt == SWITCH_IMG_FMT_ARGB) {
587  for (i = 0; i < img->d_w; i++) {
588  *(img->planes[SWITCH_PLANE_PACKED] + i * 4 ) = color->a;
589  *(img->planes[SWITCH_PLANE_PACKED] + i * 4 + 1) = color->r;
590  *(img->planes[SWITCH_PLANE_PACKED] + i * 4 + 2) = color->g;
591  *(img->planes[SWITCH_PLANE_PACKED] + i * 4 + 3) = color->b;
592  }
593 
594  for (i = 1; i < img->d_h; i++) {
595  memcpy( img->planes[SWITCH_PLANE_PACKED] + i * img->d_w * 4,
596  img->planes[SWITCH_PLANE_PACKED], img->d_w * 4);
597  }
598  }
599 #endif
600 }
#define SWITCH_PLANE_V
Definition: switch_vpx.h:55
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
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
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
unsigned int d_h
Definition: switch_image.h:100
memset(buf, 0, buflen)
#define MIN(a, b)
void switch_img_find_position ( switch_img_position_t  pos,
int  sw,
int  sh,
int  iw,
int  ih,
int *  xP,
int *  yP 
)

Definition at line 2160 of file switch_core_video.c.

References POS_CENTER_BOT, POS_CENTER_MID, POS_CENTER_TOP, POS_LEFT_BOT, POS_LEFT_MID, POS_LEFT_TOP, POS_NONE, POS_RIGHT_BOT, POS_RIGHT_MID, and POS_RIGHT_TOP.

Referenced by switch_core_media_bug_patch_spy_frame(), and video_write_overlay_callback().

2161 {
2162  switch(pos) {
2163  case POS_NONE:
2164  case POS_LEFT_TOP:
2165  *xP = 0;
2166  *yP = 0;
2167  break;
2168  case POS_LEFT_MID:
2169  *xP = 0;
2170  *yP = (sh - ih) / 2;
2171  break;
2172  case POS_LEFT_BOT:
2173  *xP = 0;
2174  *yP = (sh - ih);
2175  break;
2176  case POS_CENTER_TOP:
2177  *xP = (sw - iw) / 2;
2178  *yP = 0;
2179  break;
2180  case POS_CENTER_MID:
2181  *xP = (sw - iw) / 2;
2182  *yP = (sh - ih) / 2;
2183  break;
2184  case POS_CENTER_BOT:
2185  *xP = (sw - iw) / 2;
2186  *yP = (sh - ih);
2187  break;
2188  case POS_RIGHT_TOP:
2189  *xP = (sw - iw);
2190  *yP = 0;
2191  break;
2192  case POS_RIGHT_MID:
2193  *xP = (sw - iw);
2194  *yP = (sh - ih) / 2;
2195  break;
2196  case POS_RIGHT_BOT:
2197  *xP = (sw - iw);
2198  *yP = (sh - ih);
2199  break;
2200  };
2201 
2202 }
switch_status_t switch_img_fit ( switch_image_t **  srcP,
int  width,
int  height,
switch_img_fit_t  fit 
)

Definition at line 1927 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, switch_assert, SWITCH_FIT_SCALE, SWITCH_FIT_SIZE_AND_SCALE, switch_img_free(), switch_img_scale(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_bug_patch_spy_frame(), and video_write_overlay_callback().

1928 {
1929  switch_image_t *src, *tmp = NULL;
1930  int new_w = 0, new_h = 0;
1931 
1932  switch_assert(srcP);
1933  switch_assert(width && height);
1934 
1935  src = *srcP;
1936 
1937  if (!src || (src->d_w == width && src->d_h == height)) {
1938  return SWITCH_STATUS_SUCCESS;
1939  }
1940 
1941  if (fit == SWITCH_FIT_SCALE) {
1942  switch_img_scale(src, &tmp, width, height);
1943  switch_img_free(&src);
1944  *srcP = tmp;
1945  return SWITCH_STATUS_SUCCESS;
1946  }
1947 
1948  new_w = src->d_w;
1949  new_h = src->d_h;
1950 
1951  if (src->d_w < width && src->d_h < height) {
1952  float rw = (float)new_w / width;
1953  float rh = (float)new_h / height;
1954 
1955  if (rw > rh) {
1956  new_h = (int)((float)new_h / rw);
1957  new_w = width;
1958  } else {
1959  new_w = (int)((float)new_w / rh);
1960  new_h = height;
1961  }
1962  } else {
1963  while(new_w > width || new_h > height) {
1964  if (new_w > width) {
1965  double m = (double) width / new_w;
1966  new_w = width;
1967  new_h = (int) (new_h * m);
1968  } else {
1969  double m = (double) height / new_h;
1970  new_h = height;
1971  new_w = (int) (new_w * m);
1972  }
1973  }
1974  }
1975 
1976  if (new_w && new_h) {
1977  if (switch_img_scale(src, &tmp, new_w, new_h) == SWITCH_STATUS_SUCCESS) {
1978  switch_img_free(&src);
1979  *srcP = tmp;
1980 
1981  if (fit == SWITCH_FIT_SIZE_AND_SCALE) {
1982  src = *srcP;
1983  switch_img_scale(src, &tmp, width, height);
1984  switch_img_free(&src);
1985  *srcP = tmp;
1986  }
1987 
1988  return SWITCH_STATUS_SUCCESS;
1989  }
1990  }
1991 
1992  return SWITCH_STATUS_FALSE;
1993 }
Image Descriptor.
Definition: switch_image.h:88
void switch_img_free(switch_image_t **img)
Close an image descriptor.
unsigned int d_w
Definition: switch_image.h:99
switch_status_t switch_img_scale(switch_image_t *src, switch_image_t **destP, int width, int height)
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
void switch_img_free ( switch_image_t **  img)

Close an image descriptor.

Frees all allocated storage associated with an image descriptor.

Parameters
[in]imgpointer to pointer of Image descriptor

Definition at line 264 of file switch_core_video.c.

References SWITCH_IMG_FMT_GD, switch_safe_free, and vpx_img_free().

Referenced by switch_core_media_bug_close(), switch_core_media_bug_patch_spy_frame(), switch_core_session_write_video_frame(), switch_frame_buffer_free(), switch_frame_free(), switch_img_alloc(), switch_img_copy(), switch_img_copy_rect(), switch_img_fit(), switch_img_letterbox(), switch_img_patch_rect(), switch_img_rotate(), switch_img_rotate_copy(), switch_ivr_video_write_overlay_session(), video_bug_thread(), video_helper_thread(), video_write_overlay_callback(), and video_write_thread().

265 {
266 #ifdef SWITCH_HAVE_VPX
267  if (img && *img) {
268  if ((*img)->fmt == SWITCH_IMG_FMT_GD) {
269 #ifdef HAVE_LIBGD
270  gdImageDestroy((gdImagePtr)(*img)->user_priv);
271 #endif
272  } else {
273  switch_safe_free((*img)->user_priv);
274  }
275  vpx_img_free((vpx_image_t *)*img);
276  *img = NULL;
277  }
278 #endif
279 }
void vpx_img_free(vpx_image_t *img)
Close an image descriptor.
Image Descriptor.
Definition: switch_image.h:88
#define SWITCH_IMG_FMT_GD
Definition: switch_vpx.h:89
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
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

if dest is NULL then a new img is created, user should destroy it later, otherwize it will re-used the dest img, and the dest img size must match the src width and height, width and height can be 0 in the latter case and it will figure out according to the dest img

Parameters
[in]destThe image descriptor
[in]srcThe raw data memory address
[in]fmtThe raw data format
[in]widthThe raw data width
[in]heightThe raw data height

Definition at line 2063 of file switch_core_video.c.

References SWITCH_CHANNEL_LOG, switch_img_alloc(), SWITCH_IMG_FMT_I420, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

2064 {
2065 #ifdef SWITCH_HAVE_YUV
2066  uint32_t fourcc;
2067  int ret;
2068 
2069  fourcc = switch_img_fmt2fourcc(fmt);
2070 
2071  if (fourcc == FOURCC_ANY) {
2072  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unsupported format: %d\n", fmt);
2073  return SWITCH_STATUS_FALSE;
2074  }
2075 
2076  if (!dest && width > 0 && height > 0) dest = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
2077  if (!dest) return SWITCH_STATUS_FALSE;
2078 
2079  if (width == 0 || height == 0) {
2080  width = dest->d_w;
2081  height = dest->d_h;
2082  }
2083 
2084 /*
2085  int ConvertToI420(const uint8* src_frame, size_t src_size,
2086  uint8* dst_y, int dst_stride_y,
2087  uint8* dst_u, int dst_stride_u,
2088  uint8* dst_v, int dst_stride_v,
2089  int crop_x, int crop_y,
2090  int src_width, int src_height,
2091  int crop_width, int crop_height,
2092  enum RotationMode rotation,
2093  uint32 format);
2094 
2095  src_size is only used when FOURCC_MJPG which we don't support so always 0
2096 */
2097 
2098  ret = ConvertToI420(src, 0,
2099  dest->planes[0], dest->stride[0],
2100  dest->planes[1], dest->stride[1],
2101  dest->planes[2], dest->stride[2],
2102  0, 0,
2103  width, height,
2104  width, height,
2105  0, fourcc);
2106 
2107  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
2108 #else
2109  return SWITCH_STATUS_FALSE;
2110 #endif
2111 }
#define SWITCH_CHANNEL_LOG
unsigned int d_w
Definition: switch_image.h:99
int stride[4]
Definition: switch_image.h:117
unsigned char * planes[4]
Definition: switch_image.h:116
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.
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
unsigned int d_h
Definition: switch_image.h:100
static void switch_img_get_rgb_pixel ( switch_image_t img,
switch_rgb_color_t rgb,
int  x,
int  y 
)
inlinestatic

Definition at line 614 of file switch_core_video.c.

References switch_rgb_color_s::a, switch_rgb_color_s::b, vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, switch_rgb_color_s::g, vpx_image::planes, switch_rgb_color_s::r, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, and SWITCH_PLANE_PACKED.

Referenced by switch_img_overlay(), and switch_img_patch().

615 {
616 #ifdef SWITCH_HAVE_YUV
617  if (x < 0 || y < 0 || x >= img->d_w || y >= img->d_h) return;
618 
619  if (img->fmt == SWITCH_IMG_FMT_I420) {
620  switch_yuv_color_t yuv;
621 
622  switch_img_get_yuv_pixel(img, &yuv, x, y);
623  switch_color_yuv2rgb(&yuv, rgb);
624  } else if (img->fmt == SWITCH_IMG_FMT_ARGB) {
625  uint8_t *a = img->planes[SWITCH_PLANE_PACKED] + img->d_w * 4 * y + 4 * x;
626  rgb->a = *a;
627  rgb->r = *(++a);
628  rgb->g = *(++a);
629  rgb->b = *(++a);
630  }
631 #endif
632 }
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
unsigned int d_w
Definition: switch_image.h:99
vpx_img_fmt_t fmt
Definition: switch_image.h:89
unsigned char * planes[4]
Definition: switch_image.h:116
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
unsigned int d_h
Definition: switch_image.h:100
switch_status_t switch_img_letterbox ( switch_image_t img,
switch_image_t **  imgP,
int  width,
int  height,
const char *  color 
)

Definition at line 1882 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, switch_assert, switch_color_set_rgb(), switch_img_alloc(), switch_img_copy(), switch_img_fill(), SWITCH_IMG_FMT_I420, switch_img_free(), switch_img_patch(), switch_img_scale(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_session_write_video_frame().

1883 {
1884  int img_w = 0, img_h = 0;
1885  double screen_aspect = 0, img_aspect = 0;
1886  int x_pos = 0;
1887  int y_pos = 0;
1888  switch_image_t *IMG = NULL, *scale_img = NULL;
1889  switch_rgb_color_t bgcolor = { 0 };
1890 
1891  switch_assert(imgP);
1892  *imgP = NULL;
1893 
1894  if (img->d_w == width && img->d_h == height) {
1895  switch_img_copy(img, imgP);
1896  return SWITCH_STATUS_SUCCESS;
1897  }
1898 
1899  IMG = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
1900  switch_color_set_rgb(&bgcolor, color);
1901  switch_img_fill(IMG, 0, 0, IMG->d_w, IMG->d_h, &bgcolor);
1902 
1903  img_w = IMG->d_w;
1904  img_h = IMG->d_h;
1905 
1906  screen_aspect = (double) IMG->d_w / IMG->d_h;
1907  img_aspect = (double) img->d_w / img->d_h;
1908 
1909 
1910  if (screen_aspect > img_aspect) {
1911  img_w = img_aspect * IMG->d_h;
1912  x_pos = (IMG->d_w - img_w) / 2;
1913  } else if (screen_aspect < img_aspect) {
1914  img_h = IMG->d_w / img_aspect;
1915  y_pos = (IMG->d_h - img_h) / 2;
1916  }
1917 
1918  switch_img_scale(img, &scale_img, img_w, img_h);
1919  switch_img_patch(IMG, scale_img, x_pos, y_pos);
1920  switch_img_free(&scale_img);
1921 
1922  *imgP = IMG;
1923 
1924  return SWITCH_STATUS_SUCCESS;
1925 }
Image Descriptor.
Definition: switch_image.h:88
void switch_img_copy(switch_image_t *img, switch_image_t **new_img)
Copy image to a new image.
void switch_img_free(switch_image_t **img)
Close an image descriptor.
unsigned int d_w
Definition: switch_image.h:99
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.
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
switch_status_t switch_img_scale(switch_image_t *src, switch_image_t **destP, int width, int height)
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
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
void switch_color_set_rgb(switch_rgb_color_t *color, const char *str)
Set RGB color with a string.
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.
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

Both IMG and img must be non-NULL

Parameters
[in]IMGThe BIG Image descriptor
[in]imgThe small Image descriptor
[in]xLeftmost pos
[in]yTopmost pos
[in]percentAlaha value from 0(completely transparent) to 100(opaque)

Definition at line 634 of file switch_core_video.c.

References switch_rgb_color_s::b, switch_rgb_color_s::g, MIN, switch_rgb_color_s::r, switch_assert, switch_img_draw_pixel(), SWITCH_IMG_FMT_I420, and switch_img_get_rgb_pixel().

Referenced by video_write_overlay_callback().

635 {
636  int i, j, len, max_h;
637  switch_rgb_color_t RGB = {0}, rgb = {0}, c = {0};
638  int xoff = 0, yoff = 0;
639  uint8_t alpha = (int8_t)((255 * percent) / 100);
640 
641 
643 
644  if (x < 0) {
645  xoff = -x;
646  x = 0;
647  }
648 
649  if (y < 0) {
650  yoff = -y;
651  y = 0;
652  }
653 
654  max_h = MIN(y + img->d_h - yoff, IMG->d_h);
655  len = MIN(img->d_w - xoff, IMG->d_w - x);
656 
657  if (x & 1) { x++; len--; }
658  if (y & 1) y++;
659  if (len <= 0) return;
660 
661  for (i = y; i < max_h; i++) {
662  for (j = 0; j < len; j++) {
663  switch_img_get_rgb_pixel(IMG, &RGB, x + j, i);
664  switch_img_get_rgb_pixel(img, &rgb, j + xoff, i - y + yoff);
665 
666  if (rgb.a > 0) {
667  c.r = ((RGB.r * (255 - alpha)) >> 8) + ((rgb.r * alpha) >> 8);
668  c.g = ((RGB.g * (255 - alpha)) >> 8) + ((rgb.g * alpha) >> 8);
669  c.b = ((RGB.b * (255 - alpha)) >> 8) + ((rgb.b * alpha) >> 8);
670  } else {
671  c.r = RGB.r;
672  c.g = RGB.g;
673  c.b = RGB.b;
674  }
675 
676  switch_img_draw_pixel(IMG, x + j, i, &c);
677  }
678  }
679 }
unsigned int d_w
Definition: switch_image.h:99
vpx_img_fmt_t fmt
Definition: switch_image.h:89
static void switch_img_draw_pixel(switch_image_t *img, int x, int y, switch_rgb_color_t *color)
Convert RGB color to YUV.
static void switch_img_get_rgb_pixel(switch_image_t *img, switch_rgb_color_t *rgb, int x, int y)
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
#define MIN(a, b)
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

Both IMG and img must be non-NULL

Parameters
[in]IMGThe BIG Image descriptor
[in]imgThe small Image descriptor
[in]xLeftmost pos to patch to
[in]yTopmost pos to patch to

Definition at line 289 of file switch_core_video.c.

References switch_rgb_color_s::a, switch_rgb_color_s::b, switch_rgb_color_s::g, MIN, switch_rgb_color_s::r, switch_assert, SWITCH_CHANNEL_LOG, switch_img_draw_pixel(), SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_GD, SWITCH_IMG_FMT_I420, switch_img_get_rgb_pixel(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_PLANE_PACKED, SWITCH_PLANE_U, SWITCH_PLANE_V, and SWITCH_PLANE_Y.

Referenced by switch_core_media_bug_patch_spy_frame(), switch_img_letterbox(), switch_img_patch_rect(), and video_bug_thread().

290 {
291  int i, len, max_h;
292  int xoff = 0, yoff = 0;
293 
295 
296  if (img->fmt == SWITCH_IMG_FMT_ARGB) {
297  int max_w = MIN(img->d_w, IMG->d_w - abs(x));
298  int max_h = MIN(img->d_h, IMG->d_h - abs(y));
299  int j;
300  uint8_t alpha;
301  switch_rgb_color_t *rgb;
302 
303  for (i = 0; i < max_h; i++) {
304  for (j = 0; j < max_w; j++) {
305  alpha = img->planes[SWITCH_PLANE_PACKED][i * img->stride[SWITCH_PLANE_PACKED] + j * 4];
306 
307  if (alpha > 0) {
308  switch_rgb_color_t RGB = { 0 };
309 
310  switch_img_get_rgb_pixel(IMG, &RGB, x + j, y + i);
311  rgb = (switch_rgb_color_t *)(img->planes[SWITCH_PLANE_PACKED] + i * img->stride[SWITCH_PLANE_PACKED] + j * 4);
312 
313  if (alpha < 255) {
314  RGB.a = 255;
315  RGB.r = ((RGB.r * (255 - alpha)) >> 8) + ((rgb->r * alpha) >> 8);
316  RGB.g = ((RGB.g * (255 - alpha)) >> 8) + ((rgb->g * alpha) >> 8);
317  RGB.b = ((RGB.b * (255 - alpha)) >> 8) + ((rgb->b * alpha) >> 8);
318 
319  switch_img_draw_pixel(IMG, x + j, y + i, &RGB);
320  } else {
321  switch_img_draw_pixel(IMG, x + j, y + i, rgb);
322  }
323  }
324  }
325  }
326 
327  return;
328 
329 #ifdef HAVE_LIBGD
330  } else if (img->fmt == SWITCH_IMG_FMT_GD) {
331  gdImagePtr gd = (gdImagePtr)img->user_priv;
332  switch_rgb_color_t rgb_color;
333  int pixel;
334  int i, j;
335 
336  switch_assert(gd);
337 
338  if (!gd->trueColor) {
339  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "GD is experimental, only true color image is supported\n");
340  return;
341  }
342  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "truecolor: %d alpha: %d, transparent? %d\n", gd->trueColor, gd->saveAlphaFlag, gd->transparent);
343 
344  for(i = 0; i < img->d_h; i++) {
345  for(j = 0; j < img->d_w; j++) {
346  pixel = gd->tpixels[i][j];
347  rgb_color.a = 255; // TODO: handle transparent
348  rgb_color.r = gdTrueColorGetRed(pixel);
349  rgb_color.g = gdTrueColorGetGreen(pixel);
350  rgb_color.b = gdTrueColorGetBlue(pixel);
351  switch_img_draw_pixel(IMG, x + j, y + i, &rgb_color);
352  }
353  }
354 
355  return;
356 #endif
357 
358  }
359 
360  if (x < 0) {
361  xoff = -x;
362  x = 0;
363  }
364 
365  if (y < 0) {
366  yoff = -y;
367  y = 0;
368  }
369 
370  max_h = MIN(y + img->d_h - yoff, IMG->d_h);
371  len = MIN(img->d_w - xoff, IMG->d_w - x);
372 
373 
374  if (x & 0x1) { x++; len--; }
375  if (y & 0x1) y++;
376  if (len <= 0) return;
377 
378  for (i = y; i < max_h; i++) {
379  memcpy(IMG->planes[SWITCH_PLANE_Y] + IMG->stride[SWITCH_PLANE_Y] * i + x, img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * (i - y + yoff) + xoff, len);
380  }
381 
382  if ((len & 1) && (x + len) < img->d_w - 1) len++;
383 
384  len /= 2;
385 
386  for (i = y; i < max_h; i += 2) {
387  memcpy(IMG->planes[SWITCH_PLANE_U] + IMG->stride[SWITCH_PLANE_U] * (i / 2) + x / 2, img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * ((i - y + yoff) / 2) + xoff / 2, len);
388  memcpy(IMG->planes[SWITCH_PLANE_V] + IMG->stride[SWITCH_PLANE_V] * (i / 2) + x / 2, img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * ((i - y + yoff) / 2) + xoff / 2, len);
389  }
390 }
#define SWITCH_CHANNEL_LOG
#define SWITCH_PLANE_V
Definition: switch_vpx.h:55
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
unsigned int d_w
Definition: switch_image.h:99
#define SWITCH_IMG_FMT_GD
Definition: switch_vpx.h:89
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
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
static void switch_img_draw_pixel(switch_image_t *img, int x, int y, switch_rgb_color_t *color)
Convert RGB color to YUV.
static void switch_img_get_rgb_pixel(switch_image_t *img, switch_rgb_color_t *rgb, int x, int y)
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void * user_priv
Definition: switch_image.h:124
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
#define MIN(a, b)
void switch_img_patch_hole ( switch_image_t IMG,
switch_image_t img,
int  x,
int  y,
switch_image_rect_t rect 
)

Definition at line 1232 of file switch_core_video.c.

References MIN, switch_assert, SWITCH_IMG_FMT_I420, SWITCH_PLANE_U, SWITCH_PLANE_V, and SWITCH_PLANE_Y.

1233 {
1234  int i, len;
1235 
1238 
1239  len = MIN(img->d_w, IMG->d_w - x);
1240  if (len <= 0) return;
1241 
1242  for (i = y; i < (y + img->d_h) && i < IMG->d_h; i++) {
1243  if (rect && i >= rect->y && i < (rect->y + rect->h)) {
1244  int size = rect->x > x ? rect->x - x : 0;
1245  memcpy(IMG->planes[SWITCH_PLANE_Y] + IMG->stride[SWITCH_PLANE_Y] * i + x, img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * (i - y), size);
1246  size = MIN(img->d_w - rect->w - size, IMG->d_w - (rect->x + rect->w));
1247  memcpy(IMG->planes[SWITCH_PLANE_Y] + IMG->stride[SWITCH_PLANE_Y] * i + rect->x + rect->w, img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * (i - y) + rect->w + (rect->x - x), size);
1248  } else {
1249  memcpy(IMG->planes[SWITCH_PLANE_Y] + IMG->stride[SWITCH_PLANE_Y] * i + x, img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * (i - y), len);
1250  }
1251  }
1252 
1253  len /= 2;
1254 
1255  for (i = y; i < (y + img->d_h) && i < IMG->d_h; i += 2) {
1256  if (rect && i > rect->y && i < (rect->y + rect->h)) {
1257  int size = rect->x > x ? rect->x - x : 0;
1258 
1259  size /= 2;
1260  memcpy(IMG->planes[SWITCH_PLANE_U] + IMG->stride[SWITCH_PLANE_U] * (i / 2) + x / 2, img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * ((i - y) / 2), size);
1261  memcpy(IMG->planes[SWITCH_PLANE_V] + IMG->stride[SWITCH_PLANE_V] * (i / 2) + x / 2, img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * ((i - y) / 2), size);
1262  size = MIN(img->d_w - rect->w - size, IMG->d_w - (rect->x + rect->w)) / 2;
1263  memcpy(IMG->planes[SWITCH_PLANE_U] + IMG->stride[SWITCH_PLANE_U] * (i / 2) + (rect->x + rect->w) / 2, img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * ((i - y) / 2) + (rect->w + (rect->x - x)) / 2, size);
1264  memcpy(IMG->planes[SWITCH_PLANE_V] + IMG->stride[SWITCH_PLANE_V] * (i / 2) + (rect->x + rect->w) / 2, img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * ((i - y) / 2) + (rect->w + (rect->x - x)) / 2, size);
1265  } else {
1266  memcpy(IMG->planes[SWITCH_PLANE_U] + IMG->stride[SWITCH_PLANE_U] * (i / 2) + x / 2, img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * ((i - y) / 2), len);
1267  memcpy(IMG->planes[SWITCH_PLANE_V] + IMG->stride[SWITCH_PLANE_V] * (i / 2) + x / 2, img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * ((i - y) / 2), len);
1268  }
1269  }
1270 }
#define SWITCH_PLANE_V
Definition: switch_vpx.h:55
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
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
#define MIN(a, b)
switch_status_t switch_img_patch_png ( switch_image_t img,
int  x,
int  y,
const char *  file_name 
)

Definition at line 1862 of file switch_core_video.c.

References SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(), and SWITCH_STATUS_FALSE.

1863 {
1864  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This function is not available, libpng not installed\n");
1865  return SWITCH_STATUS_FALSE;
1866 }
#define SWITCH_CHANNEL_LOG
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
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

Both IMG and img must be non-NULL

Parameters
[in]IMGThe BIG Image descriptor
[in]XLeftmost pos to patch to IMG
[in]YTopmost pos to patch to IMG
[in]imgThe small Image descriptor
[in]xLeftmost pos to be read from img
[in]yTopmost pos to be read from
[in]wMax width to be read from img
[in]hMax height to be read from img

Definition at line 392 of file switch_core_video.c.

References MIN, vpx_image::planes, SWITCH_IMG_FMT_PLANAR, switch_img_free(), switch_img_patch(), switch_img_set_rect(), SWITCH_PLANE_PACKED, SWITCH_PLANE_Y, and vpx_img_wrap().

393 {
394 #ifdef SWITCH_HAVE_VPX
395  switch_image_t *tmp;
396  uint8_t *data;
397 
398  if (x >= img->d_w || y >= img->d_h) return;
399 
400  if (!(img->fmt & SWITCH_IMG_FMT_PLANAR)) {
401  data = img->planes[SWITCH_PLANE_PACKED];
402  } else {
403  data = img->planes[SWITCH_PLANE_Y];
404  }
405 
406  tmp = (switch_image_t *)vpx_img_wrap(NULL, img->fmt, img->d_w, img->d_h, 1, data);
407  if (!tmp) return;
408 
409  w = MIN(img->d_w - x, w);
410  h = MIN(img->d_h - y, h);
411 
412  if (!switch_img_set_rect(tmp, x, y, w, h)) {
413  switch_img_patch(IMG, tmp, X, Y);
414  }
415 
416  switch_img_free(&tmp);
417 #endif
418 }
Image Descriptor.
Definition: switch_image.h:88
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
void switch_img_free(switch_image_t **img)
Close an image descriptor.
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 d_w
Definition: switch_image.h:99
vpx_img_fmt_t fmt
Definition: switch_image.h:89
unsigned char * planes[4]
Definition: switch_image.h:116
#define SWITCH_IMG_FMT_PLANAR
Definition: switch_vpx.h:47
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
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.
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
unsigned int d_h
Definition: switch_image.h:100
#define MIN(a, b)
switch_image_t* switch_img_read_file ( const char *  file_name)

Definition at line 2246 of file switch_core_video.c.

2247 {
2248  return NULL;
2249 }
switch_image_t* switch_img_read_png ( const char *  file_name,
switch_img_fmt_t  img_fmt 
)

Definition at line 1868 of file switch_core_video.c.

References SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, and switch_log_printf().

Referenced by switch_ivr_video_write_overlay_session(), and video_helper_thread().

1869 {
1870  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This function is not available, libpng not installed\n");
1871  return NULL;
1872 }
#define SWITCH_CHANNEL_LOG
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void switch_img_rotate ( switch_image_t **  img,
switch_image_rotation_mode_t  mode 
)

Flip the image vertically (top for bottom)

Adjusts the image descriptor's pointers and strides to make the image be referenced upside-down.

Parameters
[in]imgImage descriptor
Returns
0 if the requested rectangle is valid, nonzero otherwise.

Definition at line 231 of file switch_core_video.c.

References vpx_image::planes, SRM_270, SRM_90, vpx_image::stride, switch_assert, switch_img_alloc(), SWITCH_IMG_FMT_I420, switch_img_free(), SWITCH_PLANE_U, SWITCH_PLANE_V, and SWITCH_PLANE_Y.

232 {
233 #ifdef SWITCH_HAVE_YUV
234  switch_image_t *tmp_img;
235 
236  switch_assert(img);
237 
238 
239  if ((*img)->fmt != SWITCH_IMG_FMT_I420) return;
240 
241  if (mode == SRM_90 || mode == SRM_270) {
242  tmp_img = switch_img_alloc(NULL, (*img)->fmt, (*img)->d_h, (*img)->d_w, 1);
243  } else {
244  tmp_img = switch_img_alloc(NULL, (*img)->fmt, (*img)->d_w, (*img)->d_h, 1);
245  }
246 
247  switch_assert(tmp_img);
248 
249  I420Rotate((*img)->planes[SWITCH_PLANE_Y], (*img)->stride[SWITCH_PLANE_Y],
250  (*img)->planes[SWITCH_PLANE_U], (*img)->stride[SWITCH_PLANE_U],
251  (*img)->planes[SWITCH_PLANE_V], (*img)->stride[SWITCH_PLANE_V],
252  tmp_img->planes[SWITCH_PLANE_Y], tmp_img->stride[SWITCH_PLANE_Y],
253  tmp_img->planes[SWITCH_PLANE_U], tmp_img->stride[SWITCH_PLANE_U],
254  tmp_img->planes[SWITCH_PLANE_V], tmp_img->stride[SWITCH_PLANE_V],
255  (*img)->d_w, (*img)->d_h, (int)mode);
256 
257 
258  switch_img_free(img);
259  *img = tmp_img;
260 
261 #endif
262 }
Image Descriptor.
Definition: switch_image.h:88
#define SWITCH_PLANE_V
Definition: switch_vpx.h:55
void switch_img_free(switch_image_t **img)
Close an image descriptor.
int stride[4]
Definition: switch_image.h:117
unsigned char * planes[4]
Definition: switch_image.h:116
switch_byte_t switch_byte_t uint32_t switch_bitpack_mode_t mode
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
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.
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
#define switch_assert(expr)
void switch_img_rotate_copy ( switch_image_t img,
switch_image_t **  new_img,
switch_image_rotation_mode_t  mode 
)

Definition at line 459 of file switch_core_video.c.

References SRM_270, SRM_90, switch_assert, switch_img_alloc(), SWITCH_IMG_FMT_I420, switch_img_free(), SWITCH_PLANE_U, SWITCH_PLANE_V, and SWITCH_PLANE_Y.

460 {
461  switch_assert(img);
462  switch_assert(new_img);
463 
464 #ifdef SWITCH_HAVE_YUV
465  if (img->fmt != SWITCH_IMG_FMT_I420) abort();
466 
467  if (*new_img != NULL) {
468  if (img->fmt != (*new_img)->fmt || img->d_w != (*new_img)->d_w || img->d_h != (*new_img)->d_w) {
469  switch_img_free(new_img);
470  }
471  }
472 
473  if (*new_img == NULL) {
474  if (mode == SRM_90 || mode == SRM_270) {
475  *new_img = switch_img_alloc(NULL, img->fmt, img->d_h, img->d_w, 1);
476  } else {
477  *new_img = switch_img_alloc(NULL, img->fmt, img->d_w, img->d_h, 1);
478  }
479  }
480 
481  switch_assert(*new_img);
482 
483 
484  I420Rotate(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
487  (*new_img)->planes[SWITCH_PLANE_Y], (*new_img)->stride[SWITCH_PLANE_Y],
488  (*new_img)->planes[SWITCH_PLANE_U], (*new_img)->stride[SWITCH_PLANE_U],
489  (*new_img)->planes[SWITCH_PLANE_V], (*new_img)->stride[SWITCH_PLANE_V],
490  img->d_w, img->d_h, (int)mode);
491 #else
492  return;
493 #endif
494 }
#define SWITCH_PLANE_V
Definition: switch_vpx.h:55
void switch_img_free(switch_image_t **img)
Close an image descriptor.
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
switch_byte_t switch_byte_t uint32_t switch_bitpack_mode_t mode
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
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.
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
switch_status_t switch_img_scale ( switch_image_t src,
switch_image_t **  destP,
int  width,
int  height 
)

Definition at line 2113 of file switch_core_video.c.

References vpx_image::fmt, vpx_image::planes, vpx_image::stride, switch_assert, SWITCH_CHANNEL_LOG, switch_img_alloc(), SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_PLANE_PACKED, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_bug_patch_spy_frame(), switch_img_fit(), switch_img_letterbox(), and video_bug_thread().

2114 {
2115 #ifdef SWITCH_HAVE_YUV
2116  switch_image_t *dest = NULL;
2117  int ret = 0;
2118 
2119  if (destP) {
2120  dest = *destP;
2121  }
2122 
2123  if (!dest) dest = switch_img_alloc(NULL, src->fmt, width, height, 1);
2124 
2125  switch_assert(src->fmt == dest->fmt);
2126 
2127  if (src->fmt == SWITCH_IMG_FMT_I420) {
2128  ret = I420Scale(src->planes[0], src->stride[0],
2129  src->planes[1], src->stride[1],
2130  src->planes[2], src->stride[2],
2131  src->d_w, src->d_h,
2132  dest->planes[0], dest->stride[0],
2133  dest->planes[1], dest->stride[1],
2134  dest->planes[2], dest->stride[2],
2135  width, height,
2136  kFilterBox);
2137  } else if (src->fmt == SWITCH_IMG_FMT_ARGB) {
2138  ret = ARGBScale(src->planes[SWITCH_PLANE_PACKED], src->d_w * 4,
2139  src->d_w, src->d_h,
2140  dest->planes[SWITCH_PLANE_PACKED], width * 4,
2141  width, height,
2142  kFilterBox);
2143  }
2144 
2145  if (ret != 0) {
2146  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scaling Error: ret: %d\n", ret);
2147  return SWITCH_STATUS_FALSE;
2148  }
2149 
2150  if (destP) {
2151  *destP = dest;
2152  }
2153 
2154  return SWITCH_STATUS_SUCCESS;
2155 #else
2156  return SWITCH_STATUS_FALSE;
2157 #endif
2158 }
Image Descriptor.
Definition: switch_image.h:88
#define SWITCH_CHANNEL_LOG
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
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
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.
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
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.

Updates the displayed rectangle (aka viewport) on the image surface to match the specified coordinates and size.

Parameters
[in]imgImage descriptor
[in]xleftmost column
[in]ytopmost row
[in]wwidth
[in]hheight
Returns
0 if the requested rectangle is valid, nonzero otherwise.

Definition at line 218 of file switch_core_video.c.

References vpx_img_set_rect().

Referenced by switch_img_copy_rect(), and switch_img_patch_rect().

223 {
224 #ifdef SWITCH_HAVE_VPX
225  return vpx_img_set_rect((vpx_image_t *)img, x, y, w, h);
226 #else
227  return 0;
228 #endif
229 }
Image Descriptor.
Definition: switch_image.h:88
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.
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

dest should be pre-allocated and big enough for the target fmt

Parameters
[in]srcThe image descriptor
[in]destThe target memory address
[in]sizeThe size of target memory address used for bounds check
[in]fmtThe target format

Definition at line 2034 of file switch_core_video.c.

References switch_assert, SWITCH_CHANNEL_LOG, SWITCH_IMG_FMT_I420, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

2035 {
2036 #ifdef SWITCH_HAVE_YUV
2037  uint32_t fourcc;
2038  int ret;
2039 
2040  switch_assert(src->fmt == SWITCH_IMG_FMT_I420); // todo: support other formats
2041  switch_assert(dest);
2042 
2043  fourcc = switch_img_fmt2fourcc(fmt);
2044 
2045  if (fourcc == FOURCC_ANY) {
2046  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unsupported format: %d\n", fmt);
2047  return SWITCH_STATUS_FALSE;
2048  }
2049 
2050  ret = ConvertFromI420(src->planes[0], src->stride[0],
2051  src->planes[1], src->stride[1],
2052  src->planes[2], src->stride[2],
2053  dest, size,
2054  src->d_w, src->d_h,
2055  fourcc);
2056 
2057  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
2058 #else
2059  return SWITCH_STATUS_FALSE;
2060 #endif
2061 }
#define SWITCH_CHANNEL_LOG
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
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
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.

Parameters
[out]handlePPointer to the text handle pointer
[in]font_familyFont family
[in]font_colorFont color in #RRGGBB format
[in]bgcolorBackground color in #RRGGBB format
[in]font_sizeFont size in point
[in]angleAngle to rotate
[in]poolAPR memory pool

Definition at line 843 of file switch_core_video.c.

References switch_img_txt_handle_s::angle, switch_img_txt_handle_s::bgcolor, switch_img_txt_handle_s::color, switch_img_txt_handle_s::font_family, switch_img_txt_handle_s::font_size, switch_directories::fonts_dir, switch_img_txt_handle_s::free_pool, init_gradient_table(), pool, switch_img_txt_handle_s::pool, SWITCH_CHANNEL_LOG, switch_color_set_rgb(), switch_core_alloc, switch_core_destroy_memory_pool, switch_core_new_memory_pool, switch_core_sprintf(), switch_core_strdup, switch_file_exists(), SWITCH_GLOBAL_dirs, switch_is_file_path(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_PATH_SEPARATOR, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and zstr.

Referenced by switch_img_write_text_img().

845 {
846  int free_pool = 0;
847  switch_img_txt_handle_t *new_handle;
848 
849  if (!pool) {
850  free_pool = 1;
852  }
853 
854  new_handle = switch_core_alloc(pool, sizeof(*new_handle));
855 
856 #if SWITCH_HAVE_FREETYPE
857  if (FT_Init_FreeType(&new_handle->library)) {
858  return SWITCH_STATUS_FALSE;
859  }
860 /*#else
861  return SWITCH_STATUS_FALSE; */
862 #endif
863 
864  new_handle->pool = pool;
865  new_handle->free_pool = free_pool;
866 
867  if (zstr(font_family)) {
868  font_family = switch_core_sprintf(new_handle->pool, "%s%s%s",SWITCH_GLOBAL_dirs.fonts_dir, SWITCH_PATH_SEPARATOR, "FreeMono.ttf");
869  }
870 
871  if (!switch_is_file_path(font_family)) {
872  new_handle->font_family = switch_core_sprintf(new_handle->pool, "%s%s%s",SWITCH_GLOBAL_dirs.fonts_dir, SWITCH_PATH_SEPARATOR, font_family);
873  } else {
874  new_handle->font_family = switch_core_strdup(new_handle->pool, font_family);
875  }
876 
877  if (switch_file_exists(new_handle->font_family, new_handle->pool) != SWITCH_STATUS_SUCCESS) {
878  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Font %s does not exist\n", new_handle->font_family);
879  if (free_pool) {
881  }
882  *handleP = NULL;
883  return SWITCH_STATUS_FALSE;
884  }
885 
886  new_handle->font_size = font_size;
887  new_handle->angle = angle;
888 
889  switch_color_set_rgb(&new_handle->color, font_color);
890  switch_color_set_rgb(&new_handle->bgcolor, bgcolor);
891 
892  init_gradient_table(new_handle);
893 
894  *handleP = new_handle;
895 
896  return SWITCH_STATUS_SUCCESS;
897 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:631
switch_rgb_color_t color
#define SWITCH_CHANNEL_LOG
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_memory_pool_t * pool
#define zstr(x)
Definition: switch_utils.h:281
switch_memory_pool_t * pool
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:122
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:682
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:60
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:496
static void init_gradient_table(switch_img_txt_handle_t *handle)
static switch_bool_t switch_is_file_path(const char *file)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
char * switch_core_sprintf(_In_ switch_memory_pool_t *pool, _In_z_ _Printf_format_string_ const char *fmt,...)
printf-style style printing routine. The data is output to a string allocated from the pool ...
void switch_color_set_rgb(switch_rgb_color_t *color, const char *str)
Set RGB color with a string.
switch_rgb_color_t bgcolor
void switch_img_txt_handle_destroy ( switch_img_txt_handle_t **  handleP)

Free a text handle.

Parameters
[in]handlePPointer to the text handle pointer

Definition at line 900 of file switch_core_video.c.

References switch_img_txt_handle_s::free_pool, pool, switch_img_txt_handle_s::pool, switch_assert, and switch_core_destroy_memory_pool.

Referenced by switch_img_write_text_img().

901 {
902  switch_img_txt_handle_t *old_handle;
904 
905  switch_assert(handleP);
906 
907  old_handle = *handleP;
908  *handleP = NULL;
909  if (!old_handle) return;
910 
911 
912 #if SWITCH_HAVE_FREETYPE
913  if (old_handle->library) {
914  FT_Done_FreeType(old_handle->library);
915  old_handle->library = NULL;
916  }
917 #endif
918  pool = old_handle->pool;
919 
920  if (old_handle->free_pool) {
922  pool = NULL;
923  old_handle = NULL;
924  }
925 
926 }
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:640
switch_memory_pool_t * pool
switch_memory_pool_t * pool
struct apr_pool_t switch_memory_pool_t
#define switch_assert(expr)
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.

Parameters
[in]handlePointer to the text handle pointer
[in]imgThe image to be render text on
[in]xLeftmost position
[in]yTopmost position
[in]textText to render
[in]font_familyFont to use, NULL to use the handle font
[in]font_colorFont color, NULL to use the handle color
[in]bgcolorBackground color, NULL for transparency
[in]font_sizeFont size in point
[in]angleAngle to rotate

Definition at line 998 of file switch_core_video.c.

References init_gradient_table(), switch_assert, SWITCH_CHANNEL_LOG, switch_color_set_rgb(), switch_core_strdup, SWITCH_FALSE, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_TRUE, switch_u8_get_char(), and zstr.

Referenced by switch_img_write_text_img().

1002 {
1003 #if SWITCH_HAVE_FREETYPE
1004  FT_GlyphSlot slot;
1005  FT_Matrix matrix; /* transformation matrix */
1006  FT_Vector pen; /* untransformed origin */
1007  FT_Error error;
1008  //int target_height;
1009  int index = 0;
1010  FT_ULong ch;
1011  FT_Face face;
1012  uint32_t width = 0;
1013  int this_x = 0, last_x = 0, space = 0;
1014  uint32_t ret;
1015 
1016  if (zstr(text)) return 0;
1017 
1018  if (!handle) return 0;
1019 
1020  switch_assert(!img || img->fmt == SWITCH_IMG_FMT_I420 || img->fmt == SWITCH_IMG_FMT_ARGB);
1021 
1022  if (font_family) {
1023  handle->font_family = switch_core_strdup(handle->pool, font_family);
1024  } else {
1025  font_family = handle->font_family;
1026  }
1027 
1028  if (font_size) {
1029  handle->font_size = font_size;
1030  } else {
1031  font_size = handle->font_size;
1032  }
1033 
1034  if (font_color) {
1035  switch_color_set_rgb(&handle->color, font_color);
1036  }
1037 
1038  if (bgcolor) {
1039  switch_color_set_rgb(&handle->bgcolor, bgcolor);
1040  handle->use_bgcolor = SWITCH_TRUE;
1041  } else {
1042  handle->use_bgcolor = SWITCH_FALSE;
1043  }
1044 
1045  handle->angle = angle;
1046 
1047  //angle = 0; (45.0 / 360 ) * 3.14159 * 2;
1048 
1049  //target_height = img->d_h;
1050 
1051  error = FT_New_Face(handle->library, font_family, 0, &face); /* create face object */
1052  if (error) {
1053  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to open font %s\n", font_family);
1054  return 0;
1055  }
1056 
1057  /* use 50pt at 100dpi */
1058  error = FT_Set_Char_Size(face, 64 * font_size, 0, 96, 96); /* set character size */
1059  if (error) return 0;
1060 
1061  slot = face->glyph;
1062 
1063  if (handle->use_bgcolor && slot->bitmap.pixel_mode != FT_PIXEL_MODE_MONO) {
1064  init_gradient_table(handle);
1065  }
1066 
1067  /* set up matrix */
1068  matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
1069  matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
1070  matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
1071  matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
1072 
1073  pen.x = x;
1074  pen.y = y;
1075 
1076  while(*(text + index)) {
1077  ch = switch_u8_get_char((char *)text, &index);
1078 
1079  if (ch == '\n') {
1080  pen.x = x;
1081  pen.y += (font_size + font_size / 4);
1082  continue;
1083  }
1084 
1085  /* set transformation */
1086  FT_Set_Transform(face, &matrix, &pen);
1087 
1088  /* load glyph image into the slot (erase previous one) */
1089  error = FT_Load_Char(face, ch, FT_LOAD_RENDER);
1090 
1091  if (error) continue;
1092 
1093  this_x = pen.x + slot->bitmap_left;
1094 
1095  if (img) {
1096  /* now, draw to our target surface (convert position) */
1097  draw_bitmap(handle, img, &slot->bitmap, this_x, pen.y - slot->bitmap_top + font_size);
1098  }
1099 
1100  if (last_x) {
1101  space = this_x - last_x;
1102  } else {
1103  space = 0;
1104  }
1105 
1106  last_x = this_x;
1107 
1108  width += space;
1109 
1110  /* increment pen position */
1111  pen.x += slot->advance.x >> 6;
1112  pen.y += slot->advance.y >> 6;
1113  }
1114 
1115  ret = width + slot->bitmap.width * 5;
1116 
1117  FT_Done_Face(face);
1118 
1119  return ret;
1120 #else
1121  return 0;
1122 #endif
1123 }
switch_rgb_color_t color
#define SWITCH_CHANNEL_LOG
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
#define zstr(x)
Definition: switch_utils.h:281
switch_memory_pool_t * pool
vpx_img_fmt_t fmt
Definition: switch_image.h:89
static void init_gradient_table(switch_img_txt_handle_t *handle)
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
uint32_t switch_u8_get_char(char *s, int *i)
Definition: switch_utf8.c:469
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
#define switch_assert(expr)
void switch_color_set_rgb(switch_rgb_color_t *color, const char *str)
Set RGB color with a string.
switch_rgb_color_t bgcolor
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.

Returns a descriptor for storing an image of the given format. The storage for descriptor has been allocated elsewhere, and a descriptor is desired to "wrap" that storage.

Parameters
[in]imgPointer to storage for descriptor. If this parameter is NULL, the storage for the descriptor will be allocated on the heap.
[in]fmtFormat for the image
[in]d_wWidth of the image
[in]d_hHeight of the image
[in]alignAlignment, in bytes, of each row in the image.
[in]img_dataStorage to use for the image
Returns
Returns a pointer to the initialized image descriptor. If the img parameter is non-null, the value of the img parameter will be returned.

Definition at line 204 of file switch_core_video.c.

References vpx_img_wrap().

210 {
211 #ifdef SWITCH_HAVE_VPX
212  return (switch_image_t *)vpx_img_wrap((vpx_image_t *)img, (vpx_img_fmt_t)fmt, d_w, d_h, align, img_data);
213 #else
214  return NULL;
215 #endif
216 }
Image Descriptor.
Definition: switch_image.h:88
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.
enum vpx_img_fmt vpx_img_fmt_t
List of supported image formats.
switch_status_t switch_img_write_png ( switch_image_t img,
char *  file_name 
)

Definition at line 1874 of file switch_core_video.c.

References SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(), and SWITCH_STATUS_FALSE.

1875 {
1876  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This function is not available, libpng not installed\n");
1877  return SWITCH_STATUS_FALSE;
1878 }
#define SWITCH_CHANNEL_LOG
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_image_t* switch_img_write_text_img ( int  w,
int  h,
switch_bool_t  full,
const char *  text 
)

Definition at line 1125 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, end_of, memset(), vpx_image::planes, switch_assert, switch_color_set_rgb(), switch_img_alloc(), switch_img_fill(), SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, switch_img_txt_handle_create(), switch_img_txt_handle_destroy(), switch_img_txt_handle_render(), SWITCH_PLANE_PACKED, switch_safe_free, switch_split, and zstr.

1126 {
1127  const char *fg ="#cccccc";
1128  const char *bg = "#142e55";
1129  // const char *bg = NULL; // use a NULL bg for transparent
1130  const char *font_face = NULL;
1131  const char *fontsz = "4%";
1132  char *txt = "Value Optimized Out!";
1133  int argc = 0;
1134  char *argv[6] = { 0 };
1135  switch_rgb_color_t bgcolor = { 0 };
1136  int pre_width = 0, width = 0, font_size = 0, height = 0;
1137  int len = 0;
1138  char *duptxt = strdup(text);
1139  switch_img_txt_handle_t *txthandle = NULL;
1140  switch_image_t *txtimg = NULL;
1141  int x = 0, y = 0;
1142 
1143  if (strchr(text, ':')) {
1144  argc = switch_split(duptxt, ':', argv);
1145 
1146  if (argc > 0 && !zstr(argv[0])) {
1147  fg = argv[0];
1148  }
1149 
1150  if (argc > 1 && !zstr(argv[1])) {
1151  bg = argv[1];
1152  }
1153 
1154  if (argc > 2 && !zstr(argv[2])) {
1155  font_face = argv[2];
1156  }
1157 
1158  if (argc > 3 && !zstr(argv[3])) {
1159  fontsz = argv[3];
1160  }
1161 
1162  if (argc > 4) {
1163  txt = argv[4];
1164  }
1165  } else txt = duptxt;
1166 
1167  if (!txt) txt = duptxt;
1168 
1169  if (strrchr(fontsz, '%')) {
1170  font_size = 1 + ((int) (float)h * (atof(fontsz) / 100.0f));
1171  } else {
1172  font_size = atoi(fontsz);
1173  }
1174 
1175  while (*txt == ' ') txt++;
1176  while (end_of(txt) == ' ') end_of(txt) = '\0';
1177 
1178  len = strlen(txt);
1179 
1180  if (len < 5) len = 5;
1181 
1182 
1183  switch_img_txt_handle_create(&txthandle, font_face, fg, bg, font_size, 0, NULL);
1184  switch_color_set_rgb(&bgcolor, bg);
1185 
1186  pre_width = switch_img_txt_handle_render(txthandle,
1187  NULL,
1188  font_size / 2, font_size / 2,
1189  txt, NULL, fg, bg, 0, 0);
1190 
1191  height = font_size * 2;
1192 
1193  if (full && w > width) {
1194  width = w;
1195  } else {
1196  width = pre_width;
1197  }
1198 
1199  if (bg) {
1200  txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
1201  switch_assert(txtimg);
1202  switch_img_fill(txtimg, 0, 0, txtimg->d_w, txtimg->d_h, &bgcolor);
1203  } else {
1204  txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, width, height, 1);
1205  switch_assert(txtimg);
1206  memset(txtimg->planes[SWITCH_PLANE_PACKED], 0, width * height * 4);
1207  }
1208 
1209  x = font_size / 2;
1210  y = font_size / 2;
1211 
1212  if (full) {
1213  x = (txtimg->d_w / 2) - (pre_width / 2);
1214  }
1215 
1216  switch_img_txt_handle_render(txthandle,
1217  txtimg,
1218  x, y,
1219  txt, NULL, fg, bg, 0, 0);
1220  switch_img_txt_handle_destroy(&txthandle);
1221 
1222  switch_safe_free(duptxt);
1223 
1224  return txtimg;
1225 }
Image Descriptor.
Definition: switch_image.h:88
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:342
#define end_of(_s)
Definition: switch_utils.h:616
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
void switch_img_txt_handle_destroy(switch_img_txt_handle_t **handleP)
Free a text handle.
#define zstr(x)
Definition: switch_utils.h:281
unsigned int d_w
Definition: switch_image.h:99
unsigned char * planes[4]
Definition: switch_image.h:116
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
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.
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.
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.
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
void switch_color_set_rgb(switch_rgb_color_t *color, const char *str)
Set RGB color with a string.
memset(buf, 0, buflen)
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.

Variable Documentation

struct fit_el IMG_FIT_TABLE[]
static
Initial value:

Definition at line 131 of file switch_core_video.c.

struct pos_el POS_TABLE[]
static
Initial value:

Definition at line 92 of file switch_core_video.c.

uint8_t scv_art[14][16]
static
Initial value:
= {
{0x00, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x00},
{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00},
{0x00, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00},
{0x00, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x00},
{0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00},
{0x00, 0x7E, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x00},
{0x00, 0x7E, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x00},
{0x00, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00},
{0x00, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x00},
{0x00, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7E, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
}

Definition at line 681 of file switch_core_video.c.