RTS API Documentation  1.10.11
Data Structures | Macros | Typedefs | Enumerations | Functions
switch_core_video.h File Reference

video includes header More...

#include <switch.h>
+ Include dependency graph for switch_core_video.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  switch_yuv_color_s
 
struct  switch_rgb_color_s
 
struct  switch_hsl_color_s
 
struct  switch_lab_color_t
 
struct  switch_xyz_color_t
 
struct  switch_image_rect
 Representation of a rectangle on a surface. More...
 
struct  switch_png_s
 

Macros

#define CHROMAKEY_MAX_MASK   25
 

Typedefs

typedef struct switch_yuv_color_s switch_yuv_color_t
 
typedef struct switch_rgb_color_s switch_rgb_color_t
 
typedef struct switch_hsl_color_s switch_hsl_color_t
 
typedef struct switch_image_rect switch_image_rect_t
 Representation of a rectangle on a surface. More...
 
typedef struct switch_png_opaque_s switch_png_opaque_t
 
typedef struct switch_png_s switch_png_t
 

Enumerations

enum  switch_core_video_filter_t {
  SCV_FILTER_GRAY_FG = (1 << 0), SCV_FILTER_GRAY_BG = (1 << 1), SCV_FILTER_SEPIA_FG = (1 << 2), SCV_FILTER_SEPIA_BG = (1 << 3),
  SCV_FILTER_8BIT_FG = (1 << 4)
}
 
enum  switch_shade_t {
  SWITCH_SHADE_NONE = 0, SWITCH_SHADE_RED, SWITCH_SHADE_GREEN, SWITCH_SHADE_BLUE,
  SWITCH_SHADE_AUTO
}
 
enum  switch_img_position_t {
  POS_LEFT_TOP = 0, POS_LEFT_MID, POS_LEFT_BOT, POS_CENTER_TOP,
  POS_CENTER_MID, POS_CENTER_BOT, POS_RIGHT_TOP, POS_RIGHT_MID,
  POS_RIGHT_BOT, POS_NONE
}
 
enum  switch_img_fit_t {
  SWITCH_FIT_SIZE, SWITCH_FIT_SCALE, SWITCH_FIT_SIZE_AND_SCALE, SWITCH_FIT_NECESSARY,
  SWITCH_FIT_NONE
}
 
enum  switch_convert_fmt_t { SWITCH_CONVERT_FMT_YUYV = 0 }
 
enum  switch_image_rotation_mode_t { SRM_NONE = 0, SRM_90 = 90, SRM_180 = 180, SRM_270 = 270 }
 

Functions

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_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_attenuate (switch_image_t *img)
 
void switch_img_patch_rgb (switch_image_t *IMG, switch_image_t *img, int x, int y, switch_bool_t noalpha)
 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)
 
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_draw_text (switch_image_t *IMG, int x, int y, switch_rgb_color_t color, uint16_t font_size, char *text)
 
void switch_img_add_text (void *buffer, int w, int x, int y, char *s)
 
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_8bit (switch_image_t *img)
 
void switch_img_gray (switch_image_t *img, int x, int y, int w, int h)
 
void switch_img_sepia (switch_image_t *img, int x, int y, int w, int h)
 
void switch_img_fill_noalpha (switch_image_t *img, int x, int y, int w, int h, switch_rgb_color_t *color)
 
void switch_color_set_rgb (switch_rgb_color_t *color, const char *color_str)
 Set RGB color with a string. More...
 
void switch_color_set_yuv (switch_yuv_color_t *color, const char *color_str)
 Set YUV color with a string. More...
 
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...
 
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_png_patch_img (switch_png_t *use_png, switch_image_t *img, int x, int y)
 
switch_image_tswitch_img_read_png (const char *file_name, switch_img_fmt_t img_fmt)
 
switch_image_tswitch_img_read_png_from_memory (void *mem, size_t size, switch_img_fmt_t img_fmt)
 
switch_status_t switch_img_write_png (switch_image_t *img, char *file_name)
 
switch_status_t switch_png_open (switch_png_t **pngP, const char *file_name)
 
void switch_png_free (switch_png_t **pngP)
 
switch_status_t switch_img_data_url_png (switch_image_t *img, char **urlP)
 
switch_status_t switch_img_data_url (switch_image_t *img, char **urlP, const char *type, int quality)
 
switch_image_tswitch_img_read_from_file (const char *file_name, switch_img_fmt_t img_fmt)
 Read an image file to switch_image_t. More...
 
switch_status_t switch_img_write_to_file (switch_image_t *img, const char *file_name, int quality)
 Write an image file, supported formats png,jpg,bmp,tga,hdr. 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...
 
switch_status_t switch_img_mirror (switch_image_t *src, switch_image_t **destP)
 
switch_status_t switch_img_scale (switch_image_t *src, switch_image_t **destP, int width, int height)
 
switch_status_t switch_img_fit (switch_image_t **srcP, int width, int height, switch_img_fit_t fit)
 
void switch_img_calc_fit (switch_image_t *src, int width, int height, int *new_wP, int *new_hP)
 
switch_img_position_t parse_img_position (const char *name)
 
switch_img_fit_t parse_img_fit (const char *name)
 
void switch_img_find_position (switch_img_position_t pos, int sw, int sh, int iw, int ih, int *xP, int *yP)
 
switch_status_t switch_img_to_raw (switch_image_t *src, void *dest, int stride, switch_img_fmt_t fmt)
 convert img to raw format More...
 
switch_status_t switch_img_from_raw (switch_image_t **destP, void *src, switch_img_fmt_t fmt, int width, int height)
 convert raw memory to switch_img_t More...
 
switch_image_tswitch_img_write_text_img (int w, int h, switch_bool_t full, const char *text)
 
switch_image_tswitch_img_read_file (const 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_bool_t switch_core_has_video (void)
 
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)
 
switch_status_t switch_I420ToARGB (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_argb, int dst_stride_argb, int width, int height)
 I420 to ARGB Convertion. More...
 
switch_status_t switch_RGBAToARGB (const uint8_t *src_frame, int src_stride_frame, uint8_t *dst_argb, int dst_stride_argb, int width, int height)
 
switch_status_t switch_ABGRToARGB (const uint8_t *src_frame, int src_stride_frame, uint8_t *dst_argb, int dst_stride_argb, int width, int height)
 
switch_status_t switch_ARGBToARGB (const uint8_t *src_frame, int src_stride_frame, uint8_t *dst_argb, int dst_stride_argb, int width, int height)
 
void switch_img_chromakey (switch_image_t *img, switch_rgb_color_t *mask, int threshold)
 chromakey an img, img must be RGBA and return modified img More...
 
switch_status_t switch_chromakey_clear_colors (switch_chromakey_t *ck)
 
switch_status_t switch_chromakey_autocolor (switch_chromakey_t *ck, switch_shade_t autocolor, uint32_t threshold)
 
switch_status_t switch_chromakey_add_color (switch_chromakey_t *ck, switch_rgb_color_t *color, uint32_t threshold)
 
switch_status_t switch_chromakey_destroy (switch_chromakey_t **ckP)
 
switch_status_t switch_chromakey_create (switch_chromakey_t **ckP)
 
void switch_chromakey_set_default_threshold (switch_chromakey_t *ck, uint32_t threshold)
 
void switch_chromakey_process (switch_chromakey_t *ck, switch_image_t *img)
 
switch_image_tswitch_chromakey_cache_image (switch_chromakey_t *ck)
 
switch_shade_t switch_chromakey_str2shade (switch_chromakey_t *ck, const char *shade_name)
 
void switch_core_video_parse_filter_string (switch_core_video_filter_t *filters, const char *filter_str)
 

Detailed Description

video includes header

The things powered by libvpx are renamed into the switch_ namespace to provide a cleaner look to things and helps me to document what parts of video I am using I'd like to take this opportunity to thank libvpx for all the awesome stuff it does and for making my life much easier.

Definition in file switch_core_video.h.

Macro Definition Documentation

◆ CHROMAKEY_MAX_MASK

#define CHROMAKEY_MAX_MASK   25

Typedef Documentation

◆ switch_hsl_color_t

◆ switch_image_rect_t

Representation of a rectangle on a surface.

◆ switch_png_opaque_t

typedef struct switch_png_opaque_s switch_png_opaque_t

Definition at line 140 of file switch_core_video.h.

◆ switch_png_t

typedef struct switch_png_s switch_png_t

◆ switch_rgb_color_t

◆ switch_yuv_color_t

Enumeration Type Documentation

◆ switch_convert_fmt_t

Enumerator
SWITCH_CONVERT_FMT_YUYV 

Definition at line 135 of file switch_core_video.h.

◆ switch_core_video_filter_t

Enumerator
SCV_FILTER_GRAY_FG 
SCV_FILTER_GRAY_BG 
SCV_FILTER_SEPIA_FG 
SCV_FILTER_SEPIA_BG 
SCV_FILTER_8BIT_FG 

Definition at line 49 of file switch_core_video.h.

◆ switch_image_rotation_mode_t

Enumerator
SRM_NONE 
SRM_90 
SRM_180 
SRM_270 

Definition at line 147 of file switch_core_video.h.

147  {
148  SRM_NONE = 0, // No rotation.
149  SRM_90 = 90, // Rotate 90 degrees clockwise.
150  SRM_180 = 180, // Rotate 180 degrees.
151  SRM_270 = 270, // Rotate 270 degrees clockwise.
switch_image_rotation_mode_t

◆ switch_img_fit_t

Enumerator
SWITCH_FIT_SIZE 
SWITCH_FIT_SCALE 
SWITCH_FIT_SIZE_AND_SCALE 
SWITCH_FIT_NECESSARY 
SWITCH_FIT_NONE 

Definition at line 79 of file switch_core_video.h.

◆ switch_img_position_t

Enumerator
POS_LEFT_TOP 
POS_LEFT_MID 
POS_LEFT_BOT 
POS_CENTER_TOP 
POS_CENTER_MID 
POS_CENTER_BOT 
POS_RIGHT_TOP 
POS_RIGHT_MID 
POS_RIGHT_BOT 
POS_NONE 

Definition at line 66 of file switch_core_video.h.

◆ switch_shade_t

Enumerator
SWITCH_SHADE_NONE 
SWITCH_SHADE_RED 
SWITCH_SHADE_GREEN 
SWITCH_SHADE_BLUE 
SWITCH_SHADE_AUTO 

Definition at line 58 of file switch_core_video.h.

Function Documentation

◆ parse_img_fit()

switch_img_fit_t parse_img_fit ( const char *  name)

Definition at line 162 of file switch_core_video.c.

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

163 {
165  int i;
166 
168 
169  for(i = 0; IMG_FIT_TABLE[i].name; i++) {
170  if (!strcasecmp(IMG_FIT_TABLE[i].name, name)) {
171  r = IMG_FIT_TABLE[i].fit;
172  break;
173  }
174  }
175 
176  return r;
177 }
const char * name
switch_img_fit_t
switch_img_fit_t fit
static struct fit_el IMG_FIT_TABLE[]
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)

◆ parse_img_position()

switch_img_position_t parse_img_position ( const char *  name)

Definition at line 129 of file switch_core_video.c.

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

130 {
132  int i;
133 
135 
136  for(i = 0; POS_TABLE[i].name; i++) {
137  if (!strcasecmp(POS_TABLE[i].name, name)) {
138  r = POS_TABLE[i].pos;
139  break;
140  }
141  }
142 
143  return r;
144 }
static struct pos_el POS_TABLE[]
switch_img_position_t pos
switch_img_position_t
const char *const name
Definition: switch_cJSON.h:250
#define switch_assert(expr)
const char * name

◆ switch_ABGRToARGB()

switch_status_t switch_ABGRToARGB ( const uint8_t *  src_frame,
int  src_stride_frame,
uint8_t *  dst_argb,
int  dst_stride_argb,
int  width,
int  height 
)

Definition at line 3847 of file switch_core_video.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3850 {
3851 #ifdef SWITCH_HAVE_YUV
3852  int ret = ABGRToARGB(src_frame, src_stride_frame, dst_argb, dst_stride_argb, width, height);
3853 
3854  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
3855 #else
3856  return SWITCH_STATUS_FALSE;
3857 #endif
3858 }

◆ switch_ARGBToARGB()

switch_status_t switch_ARGBToARGB ( const uint8_t *  src_frame,
int  src_stride_frame,
uint8_t *  dst_argb,
int  dst_stride_argb,
int  width,
int  height 
)

Definition at line 3860 of file switch_core_video.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3863 {
3864 #ifdef SWITCH_HAVE_YUV
3865  int ret = ARGBToARGB(src_frame, src_stride_frame, dst_argb, dst_stride_argb, width, height);
3866 
3867  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
3868 #else
3869  return SWITCH_STATUS_FALSE;
3870 #endif
3871 }

◆ switch_chromakey_add_color()

switch_status_t switch_chromakey_add_color ( switch_chromakey_t ck,
switch_rgb_color_t color,
uint32_t  threshold 
)

Definition at line 1054 of file switch_core_video.c.

References switch_chromakey_s::auto_color, switch_rgb_color_s::b, CHROMAKEY_MAX_MASK, switch_rgb_color_s::g, switch_chromakey_s::mask, switch_chromakey_s::mask_len, switch_rgb_color_s::r, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, switch_log_printf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_chromakey_s::thresholds.

Referenced by switch_chromakey_process().

1055 {
1056  switch_assert(ck);
1057 
1058  if (ck->mask_len == CHROMAKEY_MAX_MASK) {
1059  return SWITCH_STATUS_FALSE;
1060  }
1061 
1062  ck->mask[ck->mask_len] = *color;
1063  ck->thresholds[ck->mask_len] = threshold * threshold;
1064  ck->mask_len++;
1065 
1066  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding color %d:%d:%d #%.2x%.2x%.2x\n",
1067  ck->auto_color.r, ck->auto_color.g, ck->auto_color.b, ck->auto_color.r, ck->auto_color.g, ck->auto_color.b);
1068 
1069  return SWITCH_STATUS_SUCCESS;
1070 }
#define SWITCH_CHANNEL_LOG
switch_rgb_color_t auto_color
switch_rgb_color_t mask[CHROMAKEY_MAX_MASK]
#define CHROMAKEY_MAX_MASK
uint32_t thresholds[CHROMAKEY_MAX_MASK]
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)

◆ switch_chromakey_autocolor()

switch_status_t switch_chromakey_autocolor ( switch_chromakey_t ck,
switch_shade_t  autocolor,
uint32_t  threshold 
)

Definition at line 1039 of file switch_core_video.c.

References switch_chromakey_s::auto_color, switch_chromakey_s::autocolor, switch_chromakey_s::cache_img, switch_chromakey_s::dft_thresh, switch_chromakey_s::dft_thresh_squared, memset(), switch_chromakey_s::no_cache, switch_assert, switch_chromakey_clear_colors(), switch_img_free(), and SWITCH_STATUS_SUCCESS.

1040 {
1041  switch_assert(ck);
1042 
1044  ck->autocolor = autocolor;
1045  ck->dft_thresh = threshold;
1046  ck->dft_thresh_squared = threshold * threshold;
1047  switch_img_free(&ck->cache_img);
1048  ck->no_cache = 90;
1049  memset(&ck->auto_color, 0, sizeof(ck->auto_color));
1050 
1051  return SWITCH_STATUS_SUCCESS;
1052 }
switch_image_t * cache_img
switch_rgb_color_t auto_color
switch_status_t switch_chromakey_clear_colors(switch_chromakey_t *ck)
void switch_img_free(switch_image_t **img)
Close an image descriptor.
switch_shade_t autocolor
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_chromakey_cache_image()

switch_image_t* switch_chromakey_cache_image ( switch_chromakey_t ck)

Definition at line 1103 of file switch_core_video.c.

References switch_chromakey_s::cache_img, and switch_assert.

1104 {
1105  switch_assert(ck);
1106 
1107  return ck->cache_img;
1108 }
switch_image_t * cache_img
#define switch_assert(expr)

◆ switch_chromakey_clear_colors()

switch_status_t switch_chromakey_clear_colors ( switch_chromakey_t ck)

Definition at line 1026 of file switch_core_video.c.

References switch_chromakey_s::autocolor, CHROMAKEY_MAX_MASK, switch_chromakey_s::mask, switch_chromakey_s::mask_len, memset(), switch_chromakey_s::no_cache, switch_assert, SWITCH_SHADE_NONE, SWITCH_STATUS_SUCCESS, and switch_chromakey_s::thresholds.

Referenced by switch_chromakey_autocolor().

1027 {
1028  switch_assert(ck);
1029 
1031  ck->mask_len = 0;
1032  memset(ck->mask, 0, sizeof(ck->mask[0]) * CHROMAKEY_MAX_MASK);
1033  memset(ck->thresholds, 0, sizeof(ck->thresholds[0]) * CHROMAKEY_MAX_MASK);
1034  ck->no_cache = 1;
1035 
1036  return SWITCH_STATUS_SUCCESS;
1037 }
switch_rgb_color_t mask[CHROMAKEY_MAX_MASK]
#define CHROMAKEY_MAX_MASK
uint32_t thresholds[CHROMAKEY_MAX_MASK]
switch_shade_t autocolor
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_chromakey_create()

switch_status_t switch_chromakey_create ( switch_chromakey_t **  ckP)

Definition at line 1089 of file switch_core_video.c.

References switch_assert, SWITCH_STATUS_SUCCESS, and switch_zmalloc.

1090 {
1091  switch_chromakey_t *ck;
1092 
1093  switch_assert(ckP);
1094 
1095  switch_zmalloc(ck, sizeof(*ck));
1096 
1097  *ckP = ck;
1098 
1099  return SWITCH_STATUS_SUCCESS;
1100 
1101 }
#define switch_zmalloc(ptr, len)
#define switch_assert(expr)

◆ switch_chromakey_destroy()

switch_status_t switch_chromakey_destroy ( switch_chromakey_t **  ckP)

Definition at line 1072 of file switch_core_video.c.

References switch_chromakey_s::cache_img, switch_assert, switch_img_free(), and SWITCH_STATUS_SUCCESS.

1073 {
1074  switch_chromakey_t *ck;
1075 
1076  switch_assert(ckP);
1077 
1078  ck = *ckP;
1079  *ckP = NULL;
1080 
1081  if (ck) {
1082  switch_img_free(&ck->cache_img);
1083  free(ck);
1084  }
1085 
1086  return SWITCH_STATUS_SUCCESS;
1087 }
switch_image_t * cache_img
void switch_img_free(switch_image_t **img)
Close an image descriptor.
#define switch_assert(expr)

◆ switch_chromakey_process()

void switch_chromakey_process ( switch_chromakey_t ck,
switch_image_t img 
)

Definition at line 1194 of file switch_core_video.c.

References switch_rgb_color_s::a, switch_chromakey_s::auto_color, switch_chromakey_s::autocolor, switch_rgb_color_s::b, b, switch_chromakey_s::bb, switch_chromakey_s::cache_img, switch_chromakey_s::color_count, vpx_image::d_h, vpx_image::d_w, switch_chromakey_s::dft_thresh, vpx_image::fmt, switch_chromakey_s::frames_read, switch_rgb_color_s::g, get_dom(), switch_chromakey_s::gg, switch_chromakey_s::mask, switch_chromakey_s::mask_len, switch_chromakey_s::no_cache, vpx_image::planes, switch_rgb_color_s::r, switch_chromakey_s::rr, switch_assert, switch_chromakey_add_color(), switch_color_distance_cheap(), switch_color_distance_literal(), switch_color_distance_multi(), switch_color_dom_cmp(), switch_img_copy(), SWITCH_IMG_FMT_ARGB, switch_img_free(), SWITCH_PLANE_PACKED, SWITCH_SHADE_AUTO, and switch_chromakey_s::thresholds.

1195 {
1196  uint8_t *pixel, *last_pixel = NULL, *cache_pixel = NULL, *end_pixel = NULL;
1197  int last_hits = 0;
1198  switch_image_t *cache_img;
1199  int same = 0;
1200  int same_same = 0;
1201 
1202 #ifdef DEBUG_CHROMA
1203  int other_img_cached = 0, color_cached = 0, checked = 0, hit_total = 0, total_pixel = 0, delta_hits = 0;
1204 #endif
1205 
1206  switch_assert(ck);
1207  switch_assert(img);
1208 
1209  if (img->fmt != SWITCH_IMG_FMT_ARGB) return;
1210 
1211  pixel = img->planes[SWITCH_PLANE_PACKED];
1212 
1213  cache_img = ck->cache_img;
1214  ck->cache_img = NULL;
1215 
1216  ck->frames_read++;
1217 
1218  if ((ck->frames_read % 300) == 0) {
1219  ck->no_cache = 2;
1220  }
1221 
1222  if (cache_img && (cache_img->d_w != img->d_w || cache_img->d_h != img->d_h)) {
1223  switch_img_free(&cache_img);
1224  }
1225 
1226  if (cache_img) {
1227  cache_pixel = cache_img->planes[SWITCH_PLANE_PACKED];
1228  }
1229 
1230  end_pixel = (img->planes[SWITCH_PLANE_PACKED] + img->d_w * img->d_h * 4);
1231 
1232  if (ck->autocolor) {
1233  ck->color_count = 0;
1234  ck->rr = ck->gg = ck->bb = 0;
1235  }
1236 
1237  for (; pixel < end_pixel; pixel += 4) {
1238  switch_rgb_color_t *color = (switch_rgb_color_t *)pixel;
1239  switch_rgb_color_t *last_color = (switch_rgb_color_t *)last_pixel;
1240  int hits = 0;
1241 
1242 
1243 
1244 #ifdef DEBUG_CHROMA
1245  total_pixel++;
1246 #endif
1247 
1248  if (!ck->no_cache && cache_img && cache_pixel) {
1249  switch_rgb_color_t *cache_color = (switch_rgb_color_t *)cache_pixel;
1250 
1251  if (switch_color_distance_cheap(color, cache_color) < 5) {
1252 #ifdef DEBUG_CHROMA
1253  other_img_cached++;
1254 #endif
1255  color->a = cache_color->a;
1256  goto end;
1257  }
1258  }
1259 
1260 
1261  if (last_color) {
1262  if (switch_color_distance_cheap(color, last_color) < 5) {
1263 
1264  hits = last_hits;
1265 #ifdef DEBUG_CHROMA
1266  color_cached++;
1267 #endif
1268 
1269  same++;
1270  } else {
1271  same = 0;
1272  }
1273  }
1274 
1275  if (!hits) {
1276 
1277  if (ck->autocolor) {
1278  int dom, a, b;
1279 
1280  get_dom(ck->autocolor, color, &dom, &a, &b);
1281 
1282  if (ck->autocolor != SWITCH_SHADE_AUTO) {
1283  //printf("WTF %d\n", ck->dft_thresh);
1284 
1285  int tol = ck->dft_thresh;
1286  int a_tol = tol/6;
1287  int b_tol = tol/6;
1288 
1289  if (dom > a && dom > b && dom > tol) {
1290  if (dom - a > a_tol && dom - b > b_tol) {
1291  hits = 1;
1292  }
1293  }
1294  }
1295  }
1296 
1297  if (!hits && ck->mask_len) {
1298  hits = switch_color_distance_multi(color, ck->mask, ck->mask_len, ck->thresholds);
1299  }
1300 
1301 
1302 #ifdef DEBUG_CHROMA
1303  checked++;
1304 #endif
1305  }
1306 
1307  end:
1308 
1309  if (same > 100 && last_color && switch_color_dom_cmp(color, last_color)) {
1310  same_same++;
1311  } else {
1312  same_same = 0;
1313  }
1314 
1315  if (!hits && ck->autocolor == SWITCH_SHADE_AUTO && (same > 300 || same_same > 50) && ck->no_cache) {
1316  ck->color_count++;
1317  ck->rr += color->r;
1318  ck->gg += color->g;
1319  ck->bb += color->b;
1320  }
1321 
1322  if (cache_pixel) {
1323  cache_pixel += 4;
1324  }
1325 
1326  if (hits) {
1327 #ifdef DEBUG_CHROMA
1328  hit_total++;
1329 #endif
1330  color->a = 0;
1331  }
1332 
1333  last_pixel = pixel;
1334  last_hits = hits;
1335  }
1336 
1337  if (ck->color_count > 1000) {
1338  switch_rgb_color_t *last_color = NULL;
1339  int skip = 0;
1340  int dom, a, b;
1341 
1342  ck->auto_color.r = ck->rr / ck->color_count;
1343  ck->auto_color.g = ck->gg / ck->color_count;
1344  ck->auto_color.b = ck->bb / ck->color_count;
1345 
1346  if (ck->mask_len) {
1347  int i = 0;
1348 
1349  for (i = 0; i < ck->mask_len; i++) {
1350  last_color = &ck->mask[i];
1351 
1352  get_dom(ck->autocolor, &ck->auto_color, &dom, &a, &b);
1353 
1354  if (switch_color_distance_literal(&ck->auto_color, last_color, 10) || !switch_color_dom_cmp(&ck->auto_color, last_color) || (dom - a < 50 || dom - b < 50)) {
1355  skip = 1;
1356  break;
1357  }
1358  }
1359  }
1360 
1361  if (!ck->mask_len || !skip) {
1363  }
1364 
1365  }
1366 
1367  if (ck->no_cache > 0 && ck->mask_len) {
1368  ck->no_cache--;
1369  }
1370 
1371 
1372 #ifdef DEBUG_CHROMA
1373  printf("total %d: other img cache %d color cache %d Checked %d Hit Total %d Delta hits: %d\n", total_pixel, other_img_cached, color_cached, checked, hit_total, delta_hits);
1374 #endif
1375 
1376  if (!ck->no_cache) {
1377  switch_img_copy(img, &ck->cache_img);
1378  }
1379 
1380  switch_img_free(&cache_img);
1381 
1382  return;
1383 }
switch_image_t * cache_img
Image Descriptor.
Definition: switch_image.h:88
switch_rgb_color_t auto_color
switch_status_t switch_chromakey_add_color(switch_chromakey_t *ck, switch_rgb_color_t *color, uint32_t threshold)
switch_rgb_color_t mask[CHROMAKEY_MAX_MASK]
const cJSON *const b
Definition: switch_cJSON.h:243
#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.
#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
static int switch_color_dom_cmp(switch_rgb_color_t *c1, switch_rgb_color_t *c2)
uint32_t thresholds[CHROMAKEY_MAX_MASK]
static void get_dom(switch_shade_t autocolor, switch_rgb_color_t *color, int *domP, int *aP, int *bP)
vpx_img_fmt_t fmt
Definition: switch_image.h:89
unsigned char * planes[4]
Definition: switch_image.h:116
static int switch_color_distance_multi(switch_rgb_color_t *c1, switch_rgb_color_t *clist, int count, uint32_t *thresholds)
compute distance between a color and a list of colors
switch_shade_t autocolor
static int switch_color_distance_literal(switch_rgb_color_t *c1, switch_rgb_color_t *c2, int distance)
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
static int switch_color_distance_cheap(switch_rgb_color_t *c1, switch_rgb_color_t *c2)

◆ switch_chromakey_set_default_threshold()

void switch_chromakey_set_default_threshold ( switch_chromakey_t ck,
uint32_t  threshold 
)

Definition at line 1014 of file switch_core_video.c.

References switch_chromakey_s::dft_thresh, switch_chromakey_s::dft_thresh_squared, switch_chromakey_s::mask_len, and switch_chromakey_s::thresholds.

1015 {
1016  int i;
1017 
1018  ck->dft_thresh = threshold;
1019  ck->dft_thresh_squared = threshold * threshold;
1020 
1021  for (i = 0; i < ck->mask_len; i++) {
1022  if (!ck->thresholds[i]) ck->thresholds[i] = ck->dft_thresh_squared;
1023  }
1024 }
uint32_t thresholds[CHROMAKEY_MAX_MASK]

◆ switch_chromakey_str2shade()

switch_shade_t switch_chromakey_str2shade ( switch_chromakey_t ck,
const char *  shade_name 
)

Definition at line 997 of file switch_core_video.c.

References SWITCH_SHADE_AUTO, SWITCH_SHADE_BLUE, SWITCH_SHADE_GREEN, SWITCH_SHADE_NONE, and SWITCH_SHADE_RED.

998 {
1000 
1001  if (!strcasecmp(shade_name, "red")) {
1002  shade = SWITCH_SHADE_RED;
1003  } else if (!strcasecmp(shade_name, "green")) {
1004  shade = SWITCH_SHADE_GREEN;
1005  } else if (!strcasecmp(shade_name, "blue")) {
1006  shade = SWITCH_SHADE_BLUE;
1007  } else if (!strcasecmp(shade_name, "auto")) {
1008  shade = SWITCH_SHADE_AUTO;
1009  }
1010 
1011  return shade;
1012 }
switch_shade_t

◆ switch_color_set_rgb()

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 1747 of file switch_core_video.c.

References switch_rgb_color_s::a, switch_rgb_color_s::b, b, switch_rgb_color_s::g, switch_rgb_color_s::r, switch_yuv_color_s::u, switch_yuv_color_s::v, switch_yuv_color_s::y, and zstr.

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

1748 {
1749  if (zstr(str)) return;
1750 
1751  if ((*str) == '#' && strlen(str) == 7) {
1752  unsigned int r, g, b;
1753  sscanf(str, "#%02x%02x%02x", &r, &g, &b);
1754  color->r = r;
1755  color->g = g;
1756  color->b = b;
1757  } else {
1758  if (!strcmp(str, "red")) {
1759  color->r = 255;
1760  color->g = 0;
1761  color->b = 0;
1762  } else if (!strcmp(str, "green")) {
1763  color->r = 0;
1764  color->g = 255;
1765  color->b = 0;
1766  } else if (!strcmp(str, "blue")) {
1767  color->r = 0;
1768  color->g = 0;
1769  color->b = 255;
1770  }
1771  }
1772 
1773  color->a = 255;
1774 }
const cJSON *const b
Definition: switch_cJSON.h:243
#define zstr(x)
Definition: switch_utils.h:314

◆ switch_color_set_yuv()

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 1812 of file switch_core_video.c.

References switch_color_set_rgb().

1813 {
1814 #ifdef SWITCH_HAVE_YUV
1815  switch_rgb_color_t rgb = { 0 };
1816 
1817  switch_color_set_rgb(&rgb, str);
1818  switch_color_rgb2yuv(&rgb, color);
1819 #endif
1820 }
void switch_color_set_rgb(switch_rgb_color_t *color, const char *str)
Set RGB color with a string.

◆ switch_core_has_video()

switch_bool_t switch_core_has_video ( void  )

Definition at line 179 of file switch_core_video.c.

References SWITCH_FALSE, and SWITCH_TRUE.

180 {
181 #ifdef SWITCH_HAVE_VPX
182 #ifdef SWITCH_HAVE_YUV
183  return SWITCH_TRUE;
184 #else
185  return SWITCH_FALSE;
186 #endif
187 #else
188  return SWITCH_FALSE;
189 #endif
190 }

◆ switch_core_video_parse_filter_string()

void switch_core_video_parse_filter_string ( switch_core_video_filter_t filters,
const char *  filter_str 
)

Definition at line 3874 of file switch_core_video.c.

References SCV_FILTER_8BIT_FG, SCV_FILTER_GRAY_BG, SCV_FILTER_GRAY_FG, SCV_FILTER_SEPIA_BG, SCV_FILTER_SEPIA_FG, and switch_stristr().

3875 {
3876  *filters = 0;
3877 
3878  if (!filter_str) return;
3879 
3880  if (switch_stristr("fg-gray", filter_str)) {
3881  *filters |= SCV_FILTER_GRAY_FG;
3882  }
3883 
3884  if (switch_stristr("bg-gray", filter_str)) {
3885  *filters |= SCV_FILTER_GRAY_BG;
3886  }
3887 
3888  if (switch_stristr("fg-sepia", filter_str)) {
3889  *filters |= SCV_FILTER_SEPIA_FG;
3890  }
3891 
3892  if (switch_stristr("bg-sepia", filter_str)) {
3893  *filters |= SCV_FILTER_SEPIA_BG;
3894  }
3895 
3896  if (switch_stristr("fg-8bit", filter_str)) {
3897  *filters |= SCV_FILTER_8BIT_FG;
3898  }
3899 }
const char * switch_stristr(const char *instr, const char *str)

◆ switch_I420_copy()

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 3779 of file switch_core_video.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3786 {
3787 #ifdef SWITCH_HAVE_YUV
3788  int ret = I420Copy(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
3789  dst_y, dst_stride_y, dst_u, dst_stride_u, dst_v, dst_stride_v,
3790  width, height);
3791  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
3792 #else
3793  return SWITCH_STATUS_FALSE;
3794 #endif
3795 }

◆ switch_I420_copy2()

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 3797 of file switch_core_video.c.

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

3800 {
3801 #ifdef SWITCH_HAVE_YUV
3802  int ret = I420Copy(src_planes[SWITCH_PLANE_Y], src_stride[SWITCH_PLANE_Y],
3803  src_planes[SWITCH_PLANE_U], src_stride[SWITCH_PLANE_U],
3804  src_planes[SWITCH_PLANE_V], src_stride[SWITCH_PLANE_V],
3805  dst_planes[SWITCH_PLANE_Y], dst_stride[SWITCH_PLANE_Y],
3806  dst_planes[SWITCH_PLANE_U], dst_stride[SWITCH_PLANE_U],
3807  dst_planes[SWITCH_PLANE_V], dst_stride[SWITCH_PLANE_V],
3808  width, height);
3809  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
3810 #else
3811  return SWITCH_STATUS_FALSE;
3812 #endif
3813 }
#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

◆ switch_I420ToARGB()

switch_status_t switch_I420ToARGB ( 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_argb,
int  dst_stride_argb,
int  width,
int  height 
)

I420 to ARGB Convertion.

Definition at line 3815 of file switch_core_video.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3820 {
3821 
3822 #ifdef SWITCH_HAVE_YUV
3823  int ret = I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
3824  dst_argb, dst_stride_argb, width, height);
3825 
3826  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
3827 #else
3828  return SWITCH_STATUS_FALSE;
3829 #endif
3830 }

◆ switch_img_8bit()

void switch_img_8bit ( switch_image_t img)

Definition at line 1464 of file switch_core_video.c.

References switch_rgb_color_s::a, vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, vpx_image::planes, vpx_image::stride, 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.

1465 {
1466 #ifdef SWITCH_HAVE_YUV
1467  int i;
1468 
1469  if (img->fmt == SWITCH_IMG_FMT_ARGB) {
1470  int max_w = img->d_w;
1471  int max_h = img->d_h;
1472  int j;
1473  switch_rgb_color_t *rgb;
1474  uint32_t *bytes;
1475 
1476  for (i = 0; i < max_h; i++) {
1477  for (j = 0; j < max_w; j++) {
1478  rgb = (switch_rgb_color_t *)(img->planes[SWITCH_PLANE_PACKED] + i * img->stride[SWITCH_PLANE_PACKED] + j * 4);
1479  //if (rgb);
1480 
1481 
1482  if (!rgb->a) continue;;
1483 
1484  //rgb->r = rgb->r & 0xE0, rgb->g = rgb->g & 0xE0, rgb->b = rgb->b & 0xC0;
1485  bytes = (uint32_t *) rgb;
1486 
1487 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN
1488  *bytes = *bytes & 0xE0E0C0FF;
1489 #else
1490  *bytes = *bytes & 0xFFC0E0E0;
1491 #endif
1492 
1493  }
1494  }
1495  } else if (img->fmt == SWITCH_IMG_FMT_I420) {
1496  switch_image_t *tmp_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, img->d_w, img->d_h, 1);
1497 
1498  I420ToARGB(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
1502  img->d_w, img->d_h);
1503 
1504  switch_img_8bit(tmp_img);
1505 
1506  ARGBToI420(tmp_img->planes[SWITCH_PLANE_PACKED], tmp_img->stride[SWITCH_PLANE_PACKED],
1510  tmp_img->d_w, tmp_img->d_h);
1511 
1512  switch_img_free(&tmp_img);
1513  }
1514 #endif
1515 }
Image Descriptor.
Definition: switch_image.h:88
void switch_img_8bit(switch_image_t *img)
#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

◆ switch_img_add_text()

void switch_img_add_text ( void *  buffer,
int  w,
int  x,
int  y,
char *  s 
)

Definition at line 1725 of file switch_core_video.c.

References index, and scv_tag().

1726 {
1727  while (*s) {
1728  int index;
1729 
1730  if (x > w - 8) break;
1731 
1732  switch (*s) {
1733  case '.': index = 10; break;
1734  case ':': index = 11; break;
1735  case '-': index = 12; break;
1736  case ' ': index = 13; break;
1737  default:
1738  index = *s - 0x30;
1739  }
1740 
1741  scv_tag(buffer, w, x, y, index);
1742  x += 8;
1743  s++;
1744  }
1745 }
static void scv_tag(void *buffer, int w, int x, int y, uint8_t n)
int index
Definition: switch_cJSON.h:160
char * buffer
Definition: switch_cJSON.h:153

◆ switch_img_alloc()

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 192 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, switch_assert, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_GD, switch_img_free(), vpx_image::user_priv, and vpx_img_alloc().

Referenced by switch_core_session_write_blank_video(), switch_img_8bit(), switch_img_copy(), switch_img_find_position(), switch_img_from_raw(), switch_img_letterbox(), switch_img_mirror(), switch_img_read_from_file(), switch_img_rotate(), switch_img_rotate_copy(), switch_img_scale(), switch_img_write_text_img(), video_bug_thread(), and video_helper_thread().

197 {
198 #ifdef SWITCH_HAVE_VPX
199  switch_image_t *r = NULL;
200 #ifdef HAVE_LIBGD
201  if (fmt == SWITCH_IMG_FMT_GD) {
202  gdImagePtr gd = gdImageCreateTrueColor(d_w, d_h);
203 
204  if (!gd) return NULL;
205 
206  switch_img_free(&img);
207  img = (switch_image_t *)vpx_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, 1, 1, 1);
208 
209  if (!img) {
210  gdImageDestroy(gd);
211  return NULL;
212  }
213 
214  img->user_priv = gd;
215  img->d_w = d_w;
216  img->d_h = d_h;
217  img->fmt = SWITCH_IMG_FMT_GD;
218  return img;
219  }
220 #endif
221 
222  switch_assert(d_w > 0);
223  switch_assert(d_h > 0);
224  r = (switch_image_t *)vpx_img_alloc((vpx_image_t *)img, (vpx_img_fmt_t)fmt, d_w, d_h, align);
225  switch_assert(r);
226  switch_assert(r->d_w == d_w);
227  switch_assert(r->d_h == d_h);
228 
229  return r;
230 #else
231  return NULL;
232 #endif
233 }
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.
int cJSON_bool fmt
Definition: switch_cJSON.h:150
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
The following member may be set by the application to associate data with this image.
Definition: switch_image.h:124
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
enum vpx_img_fmt vpx_img_fmt_t
List of supported image formats.

◆ switch_img_attenuate()

void switch_img_attenuate ( switch_image_t img)

Definition at line 371 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, vpx_image::planes, vpx_image::stride, SWITCH_IMG_FMT_ARGB, SWITCH_PLANE_PACKED, and vpx_image::user_priv.

372 {
373 #ifdef SWITCH_HAVE_YUV
374  if (img->fmt != SWITCH_IMG_FMT_ARGB) {
375  return;
376  }
377 
378  if (img->user_priv) return;
379 
380  img->user_priv = (void *)(intptr_t)1;
381 
382  ARGBAttenuate(img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED],
383  img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED], img->d_w, img->d_h);
384 #else
385  return;
386 #endif
387 
388 }
#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
void * user_priv
The following member may be set by the application to associate data with this image.
Definition: switch_image.h:124
unsigned int d_h
Definition: switch_image.h:100

◆ switch_img_calc_fit()

void switch_img_calc_fit ( switch_image_t src,
int  width,
int  height,
int *  new_wP,
int *  new_hP 
)

Definition at line 3363 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, and switch_assert.

Referenced by switch_img_fit().

3364 {
3365  int new_w, new_h;
3366 
3367  switch_assert(src);
3368 
3369  new_w = src->d_w;
3370  new_h = src->d_h;
3371 
3372  if (src->d_w < width && src->d_h < height) {
3373  float rw = (float)new_w / width;
3374  float rh = (float)new_h / height;
3375 
3376  if (rw > rh) {
3377  new_h = (int)((float)new_h / rw);
3378  new_w = width;
3379  } else {
3380  new_w = (int)((float)new_w / rh);
3381  new_h = height;
3382  }
3383  } else {
3384  while(new_w > width || new_h > height) {
3385  if (new_w > width) {
3386  double m = (double) width / new_w;
3387  new_w = width;
3388  new_h = (int) (new_h * m);
3389  } else {
3390  double m = (double) height / new_h;
3391  new_h = height;
3392  new_w = (int) (new_w * m);
3393  }
3394  }
3395  }
3396 
3397  *new_wP = new_w;
3398  *new_hP = new_h;
3399 }
unsigned int d_w
Definition: switch_image.h:99
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)

◆ switch_img_chromakey()

void switch_img_chromakey ( switch_image_t img,
switch_rgb_color_t mask,
int  threshold 
)

chromakey an img, img must be RGBA and return modified img

Definition at line 1385 of file switch_core_video.c.

References switch_rgb_color_s::a, vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, vpx_image::planes, switch_assert, switch_color_distance(), SWITCH_IMG_FMT_ARGB, and SWITCH_PLANE_PACKED.

1386 {
1387  switch_rgb_color_t *pixel, *last_pixel = NULL;
1388  int last_threshold = 0;
1389  switch_assert(img);
1390 
1391  if (img->fmt != SWITCH_IMG_FMT_ARGB) return;
1392 
1394 
1395  for (; pixel < ((switch_rgb_color_t *)img->planes[SWITCH_PLANE_PACKED] + img->d_w * img->d_h); pixel++) {
1396  int threshold = 0;
1397 
1398  if (last_pixel && (*(uint32_t *)pixel & 0xFFFFFF) == (*(uint32_t *)last_pixel & 0xFFFFFF)) {
1399  threshold = last_threshold;
1400  } else {
1401  threshold = switch_color_distance(pixel, mask);
1402  }
1403 
1404  last_threshold = threshold;
1405  last_pixel = pixel;
1406 
1407  if (threshold) {
1408  pixel->a = 0;
1409  }
1410  }
1411 
1412  return;
1413 }
#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
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
static int switch_color_distance(switch_rgb_color_t *c1, switch_rgb_color_t *c2)
Convert RGB color to YUV.

◆ switch_img_copy()

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 584 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, vpx_image::planes, vpx_image::stride, switch_assert, switch_img_alloc(), SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_ARGB_LE, 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_chromakey_process(), 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(), switch_img_patch_rect(), and video_write_overlay_callback().

585 {
586 #ifdef SWITCH_HAVE_YUV
587  switch_img_fmt_t new_fmt = img->fmt;
588 
589  switch_assert(img);
590  switch_assert(new_img);
591 
592  if (img->fmt != SWITCH_IMG_FMT_I420 && img->fmt != SWITCH_IMG_FMT_ARGB) return;
593 
594  if (*new_img) {
595  new_fmt = (*new_img)->fmt;
596  if ((*new_img)->fmt != SWITCH_IMG_FMT_I420 && (*new_img)->fmt != SWITCH_IMG_FMT_ARGB && (*new_img)->fmt != SWITCH_IMG_FMT_ARGB_LE) return;
597  if (img->d_w != (*new_img)->d_w || img->d_h != (*new_img)->d_h ) {
598  new_fmt = (*new_img)->fmt;
599  switch_img_free(new_img);
600  }
601  }
602 
603  if (*new_img == NULL) {
604  *new_img = switch_img_alloc(NULL, new_fmt, img->d_w, img->d_h, 1);
605  }
606 
607  switch_assert(*new_img);
608 
609  if (img->fmt == SWITCH_IMG_FMT_I420) {
610  if (new_fmt == SWITCH_IMG_FMT_I420) {
611  I420Copy(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
614  (*new_img)->planes[SWITCH_PLANE_Y], (*new_img)->stride[SWITCH_PLANE_Y],
615  (*new_img)->planes[SWITCH_PLANE_U], (*new_img)->stride[SWITCH_PLANE_U],
616  (*new_img)->planes[SWITCH_PLANE_V], (*new_img)->stride[SWITCH_PLANE_V],
617  img->d_w, img->d_h);
618  } else if (new_fmt == SWITCH_IMG_FMT_ARGB) {
619  I420ToARGB(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
622  (*new_img)->planes[SWITCH_PLANE_PACKED], (*new_img)->stride[SWITCH_PLANE_PACKED],
623  img->d_w, img->d_h);
624  } else if (new_fmt == SWITCH_IMG_FMT_ARGB_LE) {
625  I420ToABGR(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
628  (*new_img)->planes[SWITCH_PLANE_PACKED], (*new_img)->stride[SWITCH_PLANE_PACKED],
629  img->d_w, img->d_h);
630  }
631  } else if (img->fmt == SWITCH_IMG_FMT_ARGB) {
632  if (new_fmt == SWITCH_IMG_FMT_ARGB) {
634  (*new_img)->planes[SWITCH_PLANE_PACKED], (*new_img)->stride[SWITCH_PLANE_PACKED],
635  img->d_w, img->d_h);
636  } else if (new_fmt == SWITCH_IMG_FMT_I420) {
637  ARGBToI420(img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED],
638  (*new_img)->planes[SWITCH_PLANE_Y], (*new_img)->stride[SWITCH_PLANE_Y],
639  (*new_img)->planes[SWITCH_PLANE_U], (*new_img)->stride[SWITCH_PLANE_U],
640  (*new_img)->planes[SWITCH_PLANE_V], (*new_img)->stride[SWITCH_PLANE_V],
641  img->d_w, img->d_h);
642  }
643  }
644 #else
645  return;
646 #endif
647 }
#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
vpx_img_fmt_t switch_img_fmt_t
Definition: switch_vpx.h:91
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
#define SWITCH_IMG_FMT_ARGB_LE
Definition: switch_vpx.h:73
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_img_copy_rect()

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 687 of file switch_core_video.c.

References switch_lab_color_t::a, switch_rgb_color_s::b, switch_lab_color_t::b, b, vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, switch_rgb_color_s::g, switch_hsl_color_s::h, if(), switch_hsl_color_s::l, switch_lab_color_t::l, M_PI, MIN, vpx_image::planes, switch_rgb_color_s::r, switch_hsl_color_s::s, switch_assert, switch_img_copy(), SWITCH_IMG_FMT_PLANAR, switch_img_free(), switch_img_set_rect(), SWITCH_PLANE_PACKED, SWITCH_PLANE_Y, vpx_img_wrap(), switch_xyz_color_t::x, switch_xyz_color_t::y, and switch_xyz_color_t::z.

Referenced by switch_core_media_bug_patch_spy_frame().

688 {
689 #ifdef SWITCH_HAVE_VPX
690  switch_image_t *new_img = NULL, *tmp;
691  uint8_t *data;
692 
693  switch_assert(img);
694 
695  if (x >= img->d_w || y >= img->d_h) return NULL;
696 
697  if (!(img->fmt & SWITCH_IMG_FMT_PLANAR)) {
698  data = img->planes[SWITCH_PLANE_PACKED];
699  } else {
700  data = img->planes[SWITCH_PLANE_Y];
701  }
702 
703  tmp = (switch_image_t *)vpx_img_wrap(NULL, img->fmt, img->d_w, img->d_h, 1, data);
704  if (!tmp) return NULL;
705 
706  w = MIN(img->d_w - x, w);
707  h = MIN(img->d_h - y, h);
708 
709  if (!switch_img_set_rect(tmp, x, y, w, h)) {
710  switch_img_copy(tmp, &new_img);
711  }
712 
713  switch_img_free(&tmp);
714 
715  return new_img;
716 #else
717  return NULL;
718 #endif
719 }
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.
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.
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 stride_align, unsigned char *img_data)
Open a descriptor, using existing storage for the underlying image.
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
#define MIN(a, b)

◆ switch_img_data_url()

switch_status_t switch_img_data_url ( switch_image_t img,
char **  urlP,
const char *  type,
int  quality 
)

Definition at line 3241 of file switch_core_video.c.

References buffer, vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, vpx_image::planes, vpx_image::stride, switch_assert, switch_b64_encode(), switch_buffer_create_dynamic(), switch_buffer_destroy(), switch_buffer_get_head_pointer(), switch_buffer_inuse(), SWITCH_CHANNEL_LOG, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_PLANE_PACKED, SWITCH_PLANE_U, SWITCH_PLANE_V, SWITCH_PLANE_Y, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_zmalloc.

3242 {
3243 #ifndef SWITCH_HAVE_YUV
3244  return SWITCH_STATUS_FALSE;
3245 #else
3246  int comp = STBI_rgb;
3247  unsigned char *data = NULL;
3248  int stride_in_bytes = 0;
3249  int ret = 0;
3250  switch_buffer_t *buffer = NULL;
3251  const char *header = NULL;
3252  int header_len = 0;
3253 
3254  if (!type) return SWITCH_STATUS_FALSE;
3255 
3256  if (img->fmt == SWITCH_IMG_FMT_I420) {
3257  comp = STBI_rgb;
3258  stride_in_bytes = img->d_w * 3;
3259 
3260  data = malloc(stride_in_bytes * img->d_h);
3261  switch_assert(data);
3262 
3263  I420ToRAW(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
3266  data, stride_in_bytes,
3267  img->d_w, img->d_h);
3268  } else if (img->fmt == SWITCH_IMG_FMT_ARGB) {
3269  comp = STBI_rgb_alpha;
3270  stride_in_bytes = img->d_w * 4;
3271 
3272  data = malloc(stride_in_bytes * img->d_h);
3273  switch_assert(data);
3274 
3275 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN
3276  ARGBToRGBA(img->planes[SWITCH_PLANE_PACKED], stride_in_bytes, data, stride_in_bytes, img->d_w, img->d_h);
3277 #else
3278  ARGBToABGR(img->planes[SWITCH_PLANE_PACKED], stride_in_bytes, data, stride_in_bytes, img->d_w, img->d_h);
3279 #endif
3280  } else {
3281  return SWITCH_STATUS_FALSE;
3282  }
3283 
3284  switch_buffer_create_dynamic(&buffer, 1024, 1024, 0);
3285 
3286  if (!strcmp(type, "png")) {
3287  header = "data:image/png;base64,";
3288  ret = stbi_write_png_to_func(data_url_write_func, (void *)buffer, img->d_w, img->d_h, comp, (const void *)data, stride_in_bytes);
3289  } else if (!strcmp(type, "jpeg") || !strcmp(type, "jpeg")) {
3290  header = "data:image/jpeg;base64,";
3291  ret = stbi_write_jpg_to_func(data_url_write_func, (void *)buffer, img->d_w, img->d_h, comp, (const void *)data, quality);
3292  } else {
3293  ret = 0;
3294  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unsupported file format [%s]\n", type);
3295  }
3296 
3297  if (ret && switch_buffer_inuse(buffer) > 0) {
3298  switch_size_t blen = switch_buffer_inuse(buffer);
3299  switch_size_t olen = blen * 4 + strlen(header) + 1;
3300  uint8_t *data = switch_buffer_get_head_pointer(buffer);
3301  unsigned char *out = NULL;
3302 
3303  switch_zmalloc(out, olen);
3304  header_len = strlen(header);
3305  memcpy(out, header, header_len);
3306  switch_b64_encode(data, blen, out + header_len, olen - header_len);
3307  *urlP = (char *)out;
3308  }
3309 
3310  free(data);
3311  switch_buffer_destroy(&buffer);
3312 
3314 #endif /* SWITCH_HAVE_YUV */
3315 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_buffer_create_dynamic(_Out_ switch_buffer_t **buffer, _In_ switch_size_t blocksize, _In_ switch_size_t start_len, _In_ switch_size_t max_len)
Allocate a new dynamic switch_buffer.
FILE * out
#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
switch_status_t switch_b64_encode(unsigned char *in, switch_size_t ilen, unsigned char *out, switch_size_t olen)
vpx_img_fmt_t fmt
Definition: switch_image.h:89
#define switch_zmalloc(ptr, len)
unsigned char * planes[4]
Definition: switch_image.h:116
#define SWITCH_PLANE_Y
Definition: switch_vpx.h:53
uintptr_t switch_size_t
#define SWITCH_PLANE_U
Definition: switch_vpx.h:54
#define SWITCH_IMG_FMT_I420
Definition: switch_vpx.h:77
char * buffer
Definition: switch_cJSON.h:153
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_size_t switch_buffer_inuse(_In_ switch_buffer_t *buffer)
Get the in use amount of a switch_buffer_t.
void switch_buffer_destroy(switch_buffer_t **buffer)
Destroy the buffer.
void * switch_buffer_get_head_pointer(switch_buffer_t *buffer)
Definition: switch_buffer.c:57

◆ switch_img_data_url_png()

switch_status_t switch_img_data_url_png ( switch_image_t img,
char **  urlP 
)

Definition at line 3109 of file switch_core_video.c.

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

3110 {
3111  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This function is not available, libpng not installed\n");
3112  return SWITCH_STATUS_FALSE;
3113 }
#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_img_draw_text()

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_fill()

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 1576 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, memset(), MIN, vpx_image::planes, 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_core_media_bug_patch_spy_frame(), switch_core_session_write_blank_video(), switch_img_letterbox(), switch_img_write_text_img(), video_bug_thread(), video_helper_thread(), and video_write_thread().

1577 {
1578 #ifdef SWITCH_HAVE_YUV
1579  int len, i, max_h;
1580  switch_yuv_color_t yuv_color;
1581 
1582  if (x < 0 || y < 0 || x >= img->d_w || y >= img->d_h) return;
1583 
1584  if (img->fmt == SWITCH_IMG_FMT_I420) {
1585  switch_color_rgb2yuv(color, &yuv_color);
1586 
1587  max_h = MIN(y + h, img->d_h);
1588  len = MIN(w, img->d_w - x);
1589 
1590  if (x & 1) { x++; len--; }
1591  if (y & 1) y++;
1592  if (len <= 0) return;
1593 
1594  for (i = y; i < max_h; i++) {
1595  memset(img->planes[SWITCH_PLANE_Y] + img->stride[SWITCH_PLANE_Y] * i + x, yuv_color.y, len);
1596  }
1597 
1598  if ((len & 1) && (x + len) < img->d_w - 1) len++;
1599 
1600  len /= 2;
1601 
1602  for (i = y; i < max_h; i += 2) {
1603  memset(img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * (i / 2) + x / 2, yuv_color.u, len);
1604  memset(img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * (i / 2) + x / 2, yuv_color.v, len);
1605  }
1606  } else if (img->fmt == SWITCH_IMG_FMT_ARGB) {
1607  for (i = 0; i < img->d_w; i++) {
1608  *((switch_rgb_color_t *)img->planes[SWITCH_PLANE_PACKED] + i) = *color;
1609  }
1610 
1611  for (i = 1; i < img->d_h; i++) {
1612  memcpy( img->planes[SWITCH_PLANE_PACKED] + i * img->d_w * 4,
1613  img->planes[SWITCH_PLANE_PACKED], img->d_w * 4);
1614  }
1615  }
1616 #endif
1617 }
#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)

◆ switch_img_fill_noalpha()

void switch_img_fill_noalpha ( switch_image_t img,
int  x,
int  y,
int  w,
int  h,
switch_rgb_color_t color 
)

Definition at line 1437 of file switch_core_video.c.

References switch_rgb_color_s::a, vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, vpx_image::planes, vpx_image::stride, SWITCH_IMG_FMT_ARGB, and SWITCH_PLANE_PACKED.

1438 {
1439 #ifdef SWITCH_HAVE_YUV
1440  int i;
1441 
1442  if (img->fmt == SWITCH_IMG_FMT_ARGB) {
1443  int max_w = img->d_w;
1444  int max_h = img->d_h;
1445  int j;
1446  switch_rgb_color_t *rgb;
1447 
1448  for (i = 0; i < max_h; i++) {
1449  for (j = 0; j < max_w; j++) {
1450  rgb = (switch_rgb_color_t *)(img->planes[SWITCH_PLANE_PACKED] + i * img->stride[SWITCH_PLANE_PACKED] + j * 4);
1451 
1452  if (rgb->a != 0) {
1453  continue;
1454  }
1455 
1456  *rgb = *color;
1457  }
1458  }
1459  }
1460 
1461 #endif
1462 }
#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
unsigned int d_h
Definition: switch_image.h:100

◆ switch_img_find_position()

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 3687 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, 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, POS_RIGHT_TOP, SWITCH_CHANNEL_LOG, SWITCH_DECLARE, switch_img_alloc(), SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_GD, switch_img_free(), switch_img_read_file(), SWITCH_LOG_ERROR, switch_log_printf(), and vpx_image::user_priv.

Referenced by switch_core_media_bug_patch_spy_frame(), video_bug_thread(), and video_write_overlay_callback().

3688 {
3689  switch(pos) {
3690  case POS_NONE:
3691  case POS_LEFT_TOP:
3692  *xP = 0;
3693  *yP = 0;
3694  break;
3695  case POS_LEFT_MID:
3696  *xP = 0;
3697  *yP = (sh - ih) / 2;
3698  break;
3699  case POS_LEFT_BOT:
3700  *xP = 0;
3701  *yP = (sh - ih);
3702  break;
3703  case POS_CENTER_TOP:
3704  *xP = (sw - iw) / 2;
3705  *yP = 0;
3706  break;
3707  case POS_CENTER_MID:
3708  *xP = (sw - iw) / 2;
3709  *yP = (sh - ih) / 2;
3710  break;
3711  case POS_CENTER_BOT:
3712  *xP = (sw - iw) / 2;
3713  *yP = (sh - ih);
3714  break;
3715  case POS_RIGHT_TOP:
3716  *xP = (sw - iw);
3717  *yP = 0;
3718  break;
3719  case POS_RIGHT_MID:
3720  *xP = (sw - iw);
3721  *yP = (sh - ih) / 2;
3722  break;
3723  case POS_RIGHT_BOT:
3724  *xP = (sw - iw);
3725  *yP = (sh - ih);
3726  break;
3727  };
3728 
3729 }

◆ switch_img_fit()

switch_status_t switch_img_fit ( switch_image_t **  srcP,
int  width,
int  height,
switch_img_fit_t  fit 
)

Definition at line 3401 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, fmt, switch_assert, SWITCH_FIT_NECESSARY, SWITCH_FIT_SCALE, SWITCH_FIT_SIZE_AND_SCALE, switch_img_calc_fit(), SWITCH_IMG_FMT_444A, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_ARGB_LE, SWITCH_IMG_FMT_BGR24, SWITCH_IMG_FMT_I420, SWITCH_IMG_FMT_I42016, SWITCH_IMG_FMT_I422, SWITCH_IMG_FMT_I42216, SWITCH_IMG_FMT_I440, SWITCH_IMG_FMT_I44016, SWITCH_IMG_FMT_I444, SWITCH_IMG_FMT_I44416, SWITCH_IMG_FMT_NONE, SWITCH_IMG_FMT_RGB24, SWITCH_IMG_FMT_RGB32, SWITCH_IMG_FMT_RGB32_LE, SWITCH_IMG_FMT_RGB555, SWITCH_IMG_FMT_RGB555_LE, SWITCH_IMG_FMT_RGB565, SWITCH_IMG_FMT_RGB565_LE, SWITCH_IMG_FMT_UYVY, SWITCH_IMG_FMT_VPXI420, SWITCH_IMG_FMT_VPXYV12, SWITCH_IMG_FMT_YUY2, SWITCH_IMG_FMT_YV12, SWITCH_IMG_FMT_YVYU, switch_img_free(), switch_img_scale(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_media_bug_patch_spy_frame(), video_bug_thread(), video_write_overlay_callback(), and video_write_thread().

3402 {
3403  switch_image_t *src, *tmp = NULL;
3404  int new_w = 0, new_h = 0;
3405 
3406  switch_assert(srcP);
3407  switch_assert(width && height);
3408 
3409  src = *srcP;
3410 
3411  if (!src || (src->d_w == width && src->d_h == height)) {
3412  return SWITCH_STATUS_SUCCESS;
3413  }
3414 
3415  if (fit == SWITCH_FIT_NECESSARY && src->d_w <= width && src->d_h < height) {
3416  return SWITCH_STATUS_SUCCESS;
3417  }
3418 
3419  if (fit == SWITCH_FIT_SCALE) {
3420  switch_img_scale(src, &tmp, width, height);
3421  switch_img_free(&src);
3422  *srcP = tmp;
3423  return SWITCH_STATUS_SUCCESS;
3424  }
3425 
3426  switch_img_calc_fit(src, width, height, &new_w, &new_h);
3427 
3428  if (new_w && new_h) {
3429  if (switch_img_scale(src, &tmp, new_w, new_h) == SWITCH_STATUS_SUCCESS) {
3430  switch_img_free(&src);
3431  *srcP = tmp;
3432 
3433  if (fit == SWITCH_FIT_SIZE_AND_SCALE) {
3434  src = *srcP;
3435  tmp = NULL;
3436  switch_img_scale(src, &tmp, width, height);
3437  switch_img_free(&src);
3438  *srcP = tmp;
3439  }
3440 
3441  return SWITCH_STATUS_SUCCESS;
3442  }
3443  }
3444 
3445  return SWITCH_STATUS_FALSE;
3446 }
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_calc_fit(switch_image_t *src, int width, int height, int *new_wP, int *new_hP)

◆ switch_img_free()

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 295 of file switch_core_video.c.

References switch_assert, SWITCH_IMG_FMT_GD, SWITCH_IMG_FMT_I44016, switch_safe_free, and vpx_img_free().

Referenced by flush_video_queue(), switch_chromakey_autocolor(), switch_chromakey_destroy(), switch_chromakey_process(), switch_core_media_bug_destroy(), switch_core_media_bug_patch_spy_frame(), switch_core_session_write_blank_video(), switch_core_session_write_video_frame(), switch_frame_buffer_free(), switch_frame_free(), switch_img_8bit(), switch_img_alloc(), switch_img_copy(), switch_img_copy_rect(), switch_img_find_position(), switch_img_fit(), switch_img_letterbox(), switch_img_mirror(), switch_img_patch_rect(), switch_img_rotate(), switch_img_rotate_copy(), switch_img_scale(), switch_ivr_video_write_overlay_session(), video_bug_thread(), video_helper_thread(), video_write_overlay_callback(), and video_write_thread().

296 {
297 #ifdef SWITCH_HAVE_VPX
298  if (img && *img) {
299  if ((*img)->fmt == SWITCH_IMG_FMT_GD) {
300 #ifdef HAVE_LIBGD
301  gdImageDestroy((gdImagePtr)(*img)->user_priv);
302 #endif
303  } else {
304  if ((int)(intptr_t)(*img)->user_priv != 1) {
305  switch_safe_free((*img)->user_priv);
306  }
307  }
308  switch_assert((*img)->fmt <= SWITCH_IMG_FMT_I44016);
309  switch_assert((*img)->d_w <= 7860 && (*img)->d_w > 0);
310  switch_assert((*img)->d_h <= 4320 && (*img)->d_h > 0);
311  vpx_img_free((vpx_image_t *)*img);
312  *img = NULL;
313  }
314 #endif
315 }
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:885
#define SWITCH_IMG_FMT_I44016
Definition: switch_vpx.h:87
#define switch_assert(expr)

◆ switch_img_from_raw()

switch_status_t switch_img_from_raw ( switch_image_t **  destP,
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 3524 of file switch_core_video.c.

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

3525 {
3526 #ifdef SWITCH_HAVE_YUV
3527  uint32_t fourcc;
3528  int ret = -1;
3529  switch_image_t *dest = NULL;
3530 
3531  if (!destP) {
3532  return SWITCH_STATUS_FALSE;
3533  }
3534 
3535  dest = *destP;
3536 
3537  fourcc = switch_img_fmt2fourcc(fmt);
3538 
3539  if (fourcc == FOURCC_ANY) {
3540  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unsupported format: %d\n", fmt);
3541  return SWITCH_STATUS_FALSE;
3542  }
3543 
3544  if (!dest && width > 0 && height > 0) dest = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
3545  if (!dest) return SWITCH_STATUS_FALSE;
3546 
3547  if (width == 0 || height == 0) {
3548  width = dest->d_w;
3549  height = dest->d_h;
3550  }
3551 
3552 /*
3553  int ConvertToI420(const uint8_t* src_frame, size_t src_size,
3554  uint8_t* dst_y, int dst_stride_y,
3555  uint8_t* dst_u, int dst_stride_u,
3556  uint8_t* dst_v, int dst_stride_v,
3557  int crop_x, int crop_y,
3558  int src_width, int src_height,
3559  int crop_width, int crop_height,
3560  enum RotationMode rotation,
3561  uint32 format);
3562 
3563  src_size is only used when FOURCC_MJPG which we don't support so always 0
3564 */
3565 
3566  if (dest->fmt == SWITCH_IMG_FMT_I420) {
3567  ret = ConvertToI420(src, 0,
3568  dest->planes[0], dest->stride[0],
3569  dest->planes[1], dest->stride[1],
3570  dest->planes[2], dest->stride[2],
3571  0, 0,
3572  width, height,
3573  width, height,
3574  0, fourcc);
3575  } else if (dest->fmt == SWITCH_IMG_FMT_ARGB) {
3576  ConvertToARGB(src, 0,
3577  dest->planes[0], width * 4,
3578  0, 0,
3579  width, height,
3580  width, height,
3581  0, fourcc);
3582  }
3583 
3584  *destP = dest;
3585 
3586  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
3587 #else
3588  return SWITCH_STATUS_FALSE;
3589 #endif
3590 }
Image Descriptor.
Definition: switch_image.h:88
#define SWITCH_CHANNEL_LOG
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
int cJSON_bool fmt
Definition: switch_cJSON.h:150
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

◆ switch_img_gray()

void switch_img_gray ( switch_image_t img,
int  x,
int  y,
int  w,
int  h 
)

Definition at line 1546 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, memset(), MIN, vpx_image::planes, vpx_image::stride, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_PLANE_PACKED, SWITCH_PLANE_U, and SWITCH_PLANE_V.

1547 {
1548 #ifdef SWITCH_HAVE_YUV
1549 
1550  if (x < 0 || y < 0 || x >= img->d_w || y >= img->d_h) return;
1551 
1552  if (img->fmt == SWITCH_IMG_FMT_ARGB) {
1553  ARGBGray(img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED], x, y, w, h);
1554  } else if (img->fmt == SWITCH_IMG_FMT_I420) {
1555  int len, i, max_h;
1556 
1557  max_h = MIN(y + h, img->d_h);
1558  len = MIN(w, img->d_w - x);
1559 
1560  if (x & 1) { x++; len--; }
1561  if (y & 1) y++;
1562  if (len <= 0) return;
1563 
1564  if ((len & 1) && (x + len) < img->d_w - 1) len++;
1565 
1566  len /= 2;
1567 
1568  for (i = y; i < max_h; i += 2) {
1569  memset(img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * (i / 2) + x / 2, 128, len);
1570  memset(img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * (i / 2) + x / 2, 128, len);
1571  }
1572  }
1573 #endif
1574 }
#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_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)

◆ switch_img_letterbox()

switch_status_t switch_img_letterbox ( switch_image_t img,
switch_image_t **  imgP,
int  width,
int  height,
const char *  color 
)

Definition at line 3318 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().

3319 {
3320  int img_w = 0, img_h = 0;
3321  double screen_aspect = 0, img_aspect = 0;
3322  int x_pos = 0;
3323  int y_pos = 0;
3324  switch_image_t *IMG = NULL, *scale_img = NULL;
3325  switch_rgb_color_t bgcolor = { 0 };
3326 
3327  switch_assert(imgP);
3328  *imgP = NULL;
3329 
3330  if (img->d_w == width && img->d_h == height) {
3331  switch_img_copy(img, imgP);
3332  return SWITCH_STATUS_SUCCESS;
3333  }
3334 
3335  IMG = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
3336  switch_color_set_rgb(&bgcolor, color);
3337  switch_img_fill(IMG, 0, 0, IMG->d_w, IMG->d_h, &bgcolor);
3338 
3339  img_w = IMG->d_w;
3340  img_h = IMG->d_h;
3341 
3342  screen_aspect = (double) IMG->d_w / IMG->d_h;
3343  img_aspect = (double) img->d_w / img->d_h;
3344 
3345 
3346  if (screen_aspect > img_aspect) {
3347  img_w = img_aspect * IMG->d_h;
3348  x_pos = (IMG->d_w - img_w) / 2;
3349  } else if (screen_aspect < img_aspect) {
3350  img_h = IMG->d_w / img_aspect;
3351  y_pos = (IMG->d_h - img_h) / 2;
3352  }
3353 
3354  switch_img_scale(img, &scale_img, img_w, img_h);
3355  switch_img_patch(IMG, scale_img, x_pos, y_pos);
3356  switch_img_free(&scale_img);
3357 
3358  *imgP = IMG;
3359 
3360  return SWITCH_STATUS_SUCCESS;
3361 }
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.

◆ switch_img_mirror()

switch_status_t switch_img_mirror ( switch_image_t src,
switch_image_t **  destP 
)

Definition at line 3643 of file switch_core_video.c.

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

3644 {
3645 #ifdef SWITCH_HAVE_YUV
3646  switch_image_t *dest = NULL;
3647  int ret = 0;
3648 
3649  if (!destP) {
3650  return SWITCH_STATUS_FALSE;
3651  }
3652 
3653  dest = *destP;
3654 
3655  if (dest && src->fmt != dest->fmt) switch_img_free(&dest);
3656 
3657  if (!dest) dest = switch_img_alloc(NULL, src->fmt, src->d_w, src->d_h, 1);
3658 
3659  if (src->fmt == SWITCH_IMG_FMT_I420) {
3660  ret = I420Mirror(src->planes[0], src->stride[0],
3661  src->planes[1], src->stride[1],
3662  src->planes[2], src->stride[2],
3663  dest->planes[0], dest->stride[0],
3664  dest->planes[1], dest->stride[1],
3665  dest->planes[2], dest->stride[2],
3666  src->d_w, src->d_h);
3667  } else if (src->fmt == SWITCH_IMG_FMT_ARGB) {
3668  ret = ARGBMirror(src->planes[SWITCH_PLANE_PACKED], src->d_w * 4,
3669  dest->planes[SWITCH_PLANE_PACKED], src->d_w * 4,
3670  src->d_w, src->d_h);
3671 
3672  }
3673 
3674  *destP = dest;
3675 
3676  if (ret != 0) {
3677  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Mirror Error: ret: %d\n", ret);
3678  return SWITCH_STATUS_FALSE;
3679  }
3680 
3681  return SWITCH_STATUS_SUCCESS;
3682 #else
3683  return SWITCH_STATUS_FALSE;
3684 #endif
3685 }
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
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_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

◆ switch_img_overlay()

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 1647 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, 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().

1648 {
1649  int i, j, len, max_h;
1650  switch_rgb_color_t RGB = {0}, rgb = {0}, c = {0};
1651  int xoff = 0, yoff = 0;
1652  uint8_t alpha = (int8_t)((255 * percent) / 100);
1653 
1654 
1656 
1657  if (x < 0) {
1658  xoff = -x;
1659  x = 0;
1660  }
1661 
1662  if (y < 0) {
1663  yoff = -y;
1664  y = 0;
1665  }
1666 
1667  max_h = MIN(y + img->d_h - yoff, IMG->d_h);
1668  len = MIN(img->d_w - xoff, IMG->d_w - x);
1669 
1670  if (x & 1) { x++; len--; }
1671  if (y & 1) y++;
1672  if (len <= 0) return;
1673 
1674  for (i = y; i < max_h; i++) {
1675  for (j = 0; j < len; j++) {
1676  switch_img_get_rgb_pixel(IMG, &RGB, x + j, i);
1677  switch_img_get_rgb_pixel(img, &rgb, j + xoff, i - y + yoff);
1678 
1679  if (rgb.a > 0) {
1680  c.r = ((RGB.r * (255 - alpha)) >> 8) + ((rgb.r * alpha) >> 8);
1681  c.g = ((RGB.g * (255 - alpha)) >> 8) + ((rgb.g * alpha) >> 8);
1682  c.b = ((RGB.b * (255 - alpha)) >> 8) + ((rgb.b * alpha) >> 8);
1683  } else {
1684  c.r = RGB.r;
1685  c.g = RGB.g;
1686  c.b = RGB.b;
1687  }
1688 
1689  switch_img_draw_pixel(IMG, x + j, i, &c);
1690  }
1691  }
1692 }
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)
Draw a pixel on an image.
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)

◆ switch_img_patch()

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 441 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, MIN, vpx_image::planes, switch_rgb_color_s::r, vpx_image::stride, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_FALSE, switch_img_draw_pixel(), SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_GD, SWITCH_IMG_FMT_I420, switch_img_get_rgb_pixel(), switch_img_patch_rgb(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_PLANE_PACKED, SWITCH_PLANE_U, SWITCH_PLANE_V, SWITCH_PLANE_Y, and vpx_image::user_priv.

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

442 {
443  int i, len, max_h;
444  int xoff = 0, yoff = 0;
445 
446  if (img->fmt == SWITCH_IMG_FMT_ARGB && IMG->fmt == SWITCH_IMG_FMT_ARGB) {
447  switch_img_patch_rgb(IMG, img, x, y, SWITCH_FALSE);
448  return;
449  }
450 
452 
453  if (img->fmt == SWITCH_IMG_FMT_ARGB) {
454  int max_w = MIN(img->d_w, IMG->d_w - abs(x));
455  int max_h = MIN(img->d_h, IMG->d_h - abs(y));
456  int j;
457  uint8_t alpha;
458  switch_rgb_color_t *rgb;
459 
460  for (i = 0; i < max_h; i++) {
461  for (j = 0; j < max_w; j++) {
462  rgb = (switch_rgb_color_t *)(img->planes[SWITCH_PLANE_PACKED] + i * img->stride[SWITCH_PLANE_PACKED] + j * 4);
463  alpha = rgb->a;
464 
465  if (alpha == 255) {
466  switch_img_draw_pixel(IMG, x + j, y + i, rgb);
467  } else if (alpha != 0) {
468  switch_rgb_color_t RGB = { 0 };
469 
470  switch_img_get_rgb_pixel(IMG, &RGB, x + j, y + i);
471  RGB.a = 255;
472  RGB.r = ((RGB.r * (255 - alpha)) >> 8) + ((rgb->r * alpha) >> 8);
473  RGB.g = ((RGB.g * (255 - alpha)) >> 8) + ((rgb->g * alpha) >> 8);
474  RGB.b = ((RGB.b * (255 - alpha)) >> 8) + ((rgb->b * alpha) >> 8);
475 
476  switch_img_draw_pixel(IMG, x + j, y + i, &RGB);
477  }
478  }
479  }
480 
481  return;
482 
483 #ifdef HAVE_LIBGD
484  } else if (img->fmt == SWITCH_IMG_FMT_GD) {
485  gdImagePtr gd = (gdImagePtr)img->user_priv;
486  switch_rgb_color_t rgb_color;
487  int pixel;
488  int i, j;
489 
490  switch_assert(gd);
491 
492  if (!gd->trueColor) {
493  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "GD is experimental, only true color image is supported\n");
494  return;
495  }
496  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "truecolor: %d alpha: %d, transparent? %d\n", gd->trueColor, gd->saveAlphaFlag, gd->transparent);
497 
498  for(i = 0; i < img->d_h; i++) {
499  for(j = 0; j < img->d_w; j++) {
500  pixel = gd->tpixels[i][j];
501  rgb_color.a = 255; // TODO: handle transparent
502  rgb_color.r = gdTrueColorGetRed(pixel);
503  rgb_color.g = gdTrueColorGetGreen(pixel);
504  rgb_color.b = gdTrueColorGetBlue(pixel);
505  switch_img_draw_pixel(IMG, x + j, y + i, &rgb_color);
506  }
507  }
508 
509  return;
510 #endif
511 
512  }
513 
514  if (x < 0) {
515  xoff = -x;
516  x = 0;
517  }
518 
519  if (y < 0) {
520  yoff = -y;
521  y = 0;
522  }
523 
524  max_h = MIN(y + img->d_h - yoff, IMG->d_h);
525  len = MIN(img->d_w - xoff, IMG->d_w - x);
526 
527 
528  if (x & 0x1) { x++; len--; }
529  if (y & 0x1) y++;
530  if (len <= 0) return;
531 
532  for (i = y; i < max_h; i++) {
533  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);
534  }
535 
536  if ((len & 1) && (x + len) < img->d_w - 1) len++;
537 
538  len /= 2;
539 
540  for (i = y; i < max_h; i += 2) {
541  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);
542  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);
543  }
544 }
#define SWITCH_CHANNEL_LOG
void switch_img_patch_rgb(switch_image_t *IMG, switch_image_t *img, int x, int y, switch_bool_t noalpha)
patch a small img to a big IMG at position x,y
#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)
Draw a pixel on an image.
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
The following member may be set by the application to associate data with this image.
Definition: switch_image.h:124
unsigned int d_h
Definition: switch_image.h:100
#define switch_assert(expr)
#define MIN(a, b)

◆ switch_img_patch_hole()

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 2274 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, switch_image_rect::h, MIN, vpx_image::planes, vpx_image::stride, switch_assert, SWITCH_IMG_FMT_I420, SWITCH_PLANE_U, SWITCH_PLANE_V, SWITCH_PLANE_Y, switch_image_rect::w, switch_image_rect::x, and switch_image_rect::y.

2275 {
2276  int i, len;
2277 
2280 
2281  len = MIN(img->d_w, IMG->d_w - x);
2282  if (len <= 0) return;
2283 
2284  for (i = y; i < (y + img->d_h) && i < IMG->d_h; i++) {
2285  if (rect && i >= rect->y && i < (rect->y + rect->h)) {
2286  int size = rect->x > x ? rect->x - x : 0;
2287  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);
2288  size = MIN(img->d_w - rect->w - size, IMG->d_w - (rect->x + rect->w));
2289  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);
2290  } else {
2291  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);
2292  }
2293  }
2294 
2295  len /= 2;
2296 
2297  for (i = y; i < (y + img->d_h) && i < IMG->d_h; i += 2) {
2298  if (rect && i > rect->y && i < (rect->y + rect->h)) {
2299  int size = rect->x > x ? rect->x - x : 0;
2300 
2301  size /= 2;
2302  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);
2303  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);
2304  size = MIN(img->d_w - rect->w - size, IMG->d_w - (rect->x + rect->w)) / 2;
2305  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);
2306  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);
2307  } else {
2308  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);
2309  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);
2310  }
2311  }
2312 }
#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_img_patch_rect()

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 546 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, MIN, vpx_image::planes, vpx_image::stride, switch_img_copy(), SWITCH_IMG_FMT_PLANAR, switch_img_free(), switch_img_patch(), switch_img_set_rect(), SWITCH_PLANE_PACKED, SWITCH_PLANE_Y, and vpx_img_wrap().

547 {
548 #ifdef SWITCH_HAVE_VPX
549  switch_image_t *tmp = NULL;
550  uint8_t *data;
551 
552  if (x >= img->d_w || y >= img->d_h) return;
553 
554  if (w == img->d_w && h == img->d_h) {
555  switch_img_patch(IMG, img, X, Y);
556  return;
557  }
558 
559  if (!(img->fmt & SWITCH_IMG_FMT_PLANAR)) {
560  data = img->planes[SWITCH_PLANE_PACKED];
561  } else {
562  data = img->planes[SWITCH_PLANE_Y];
563  }
564 
565  if (img->d_w == img->stride[0]) {
566  tmp = (switch_image_t *)vpx_img_wrap(NULL, img->fmt, img->d_w, img->d_h, 1, data);
567  } else {
568  switch_img_copy(img, &tmp);
569  }
570 
571  if (!tmp) return;
572 
573  w = MIN(img->d_w - x, w);
574  h = MIN(img->d_h - y, h);
575 
576  if (!switch_img_set_rect(tmp, x, y, w, h)) {
577  switch_img_patch(IMG, tmp, X, Y);
578  }
579 
580  switch_img_free(&tmp);
581 #endif
582 }
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.
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_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.
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 stride_align, unsigned char *img_data)
Open a descriptor, using existing storage for the underlying 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_img_patch_rgb()

void switch_img_patch_rgb ( switch_image_t IMG,
switch_image_t img,
int  x,
int  y,
switch_bool_t  noalpha 
)

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
[in]noalphaskip writing to non-transparent pixels

Definition at line 390 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, MIN, vpx_image::planes, vpx_image::stride, SWITCH_IMG_FMT_ARGB, and SWITCH_PLANE_PACKED.

Referenced by switch_img_patch().

391 {
392 #ifdef SWITCH_HAVE_YUV
393  int i;
394 
395  if (noalpha) {
396  switch_img_patch_rgb_noalpha(IMG, img, x, y);
397  return;
398  }
399 
400  if (img->fmt == SWITCH_IMG_FMT_ARGB && IMG->fmt == SWITCH_IMG_FMT_ARGB) {
401  uint8_t* src_argb0 = img->planes[SWITCH_PLANE_PACKED];
402  int src_stride_argb0 = img->stride[SWITCH_PLANE_PACKED];
403  uint8_t* src_argb1 = IMG->planes[SWITCH_PLANE_PACKED];
404  int src_stride_argb1 = IMG->stride[SWITCH_PLANE_PACKED];
405  uint8_t* dst_argb = IMG->planes[SWITCH_PLANE_PACKED];
406  int dst_stride_argb = IMG->stride[SWITCH_PLANE_PACKED];
407  int width = MIN(img->d_w, IMG->d_w - abs(x));
408  int height = MIN(img->d_h, IMG->d_h - abs(y));
409  void (*ARGBBlendRow)(const uint8_t* src_argb, const uint8_t* src_argb1, uint8_t* dst_argb, int width) = GetARGBBlend();
410 
411  // switch_img_attenuate(img);
412 
413  // Coalesce rows. we have same size images, treat as a single row
414  if (src_stride_argb0 == width * 4 &&
415  src_stride_argb1 == width * 4 &&
416  x == 0 && y == 0) {
417  width *= height;
418  height = 1;
419  src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0;
420  }
421 
422  if (y) {
423  src_argb1 += (y * IMG->d_w * 4);
424  dst_argb += (y * IMG->d_w * 4);
425  }
426  if (x) {
427  src_argb1 += (x * 4);
428  dst_argb += (x * 4);
429  }
430 
431  for (i = 0; i < height; ++i) {
432  ARGBBlendRow(src_argb0, src_argb1, dst_argb, width);
433  src_argb0 += src_stride_argb0;
434  src_argb1 += src_stride_argb1;
435  dst_argb += dst_stride_argb;
436  }
437  }
438 #endif
439 }
#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
unsigned int d_h
Definition: switch_image.h:100
#define MIN(a, b)

◆ switch_img_read_file()

switch_image_t* switch_img_read_file ( const char *  file_name)

Definition at line 3773 of file switch_core_video.c.

Referenced by switch_img_find_position().

3774 {
3775  return NULL;
3776 }

◆ switch_img_read_from_file()

switch_image_t* switch_img_read_from_file ( const char *  file_name,
switch_img_fmt_t  img_fmt 
)

Read an image file to switch_image_t.

Definition at line 3117 of file switch_core_video.c.

References vpx_image::planes, vpx_image::stride, switch_assert, switch_img_alloc(), SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_PLANE_PACKED, SWITCH_PLANE_U, SWITCH_PLANE_V, and SWITCH_PLANE_Y.

3118 {
3119 #ifdef SWITCH_HAVE_YUV
3120  int width = 0, height = 0, channels = 0;
3121  int comp = STBI_rgb;
3122  unsigned char *data = NULL;
3123 
3124  if (img_fmt == SWITCH_IMG_FMT_I420) {
3125  comp = STBI_rgb;
3126  } else if (img_fmt == SWITCH_IMG_FMT_ARGB) {
3127  comp = STBI_rgb_alpha;
3128  } else {
3129  return NULL;
3130  }
3131 
3132  data = stbi_load(file_name, &width, &height, &channels, comp);
3133  // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%dx%d channels=%d\n", width, height, channels);
3134 
3135  if (data && width > 0 && height > 0) {
3136  switch_image_t *img = switch_img_alloc(NULL, img_fmt, width, height, 1);
3137  switch_assert(img);
3138 
3139  if (img_fmt == SWITCH_IMG_FMT_I420) {
3140  RAWToI420(data, width * 3,
3144  width, height);
3145  } else if (img_fmt == SWITCH_IMG_FMT_ARGB) {
3146 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN
3147  RGBAToARGB(data, width * 4, img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED], width, height);
3148 #else
3149  ABGRToARGB(data, width * 4, img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED], width, height);
3150 #endif
3151  }
3152 
3153  stbi_image_free(data);
3154 
3155  return img;
3156  } else if (data) {
3157  stbi_image_free(data);
3158  }
3159 #endif
3160 
3161  return NULL;
3162 }
Image Descriptor.
Definition: switch_image.h:88
#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
int stride[4]
Definition: switch_image.h:117
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
#define switch_assert(expr)

◆ switch_img_read_png()

switch_image_t* switch_img_read_png ( const char *  file_name,
switch_img_fmt_t  img_fmt 
)

Definition at line 3097 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().

3098 {
3099  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This function is not available, libpng not installed\n");
3100  return NULL;
3101 }
#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_img_read_png_from_memory()

switch_image_t* switch_img_read_png_from_memory ( void *  mem,
size_t  size,
switch_img_fmt_t  img_fmt 
)

◆ switch_img_rotate()

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 262 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.

263 {
264 #ifdef SWITCH_HAVE_YUV
265  switch_image_t *tmp_img;
266 
267  switch_assert(img);
268 
269 
270  if ((*img)->fmt != SWITCH_IMG_FMT_I420) return;
271 
272  if (mode == SRM_90 || mode == SRM_270) {
273  tmp_img = switch_img_alloc(NULL, (*img)->fmt, (*img)->d_h, (*img)->d_w, 1);
274  } else {
275  tmp_img = switch_img_alloc(NULL, (*img)->fmt, (*img)->d_w, (*img)->d_h, 1);
276  }
277 
278  switch_assert(tmp_img);
279 
280  I420Rotate((*img)->planes[SWITCH_PLANE_Y], (*img)->stride[SWITCH_PLANE_Y],
281  (*img)->planes[SWITCH_PLANE_U], (*img)->stride[SWITCH_PLANE_U],
282  (*img)->planes[SWITCH_PLANE_V], (*img)->stride[SWITCH_PLANE_V],
283  tmp_img->planes[SWITCH_PLANE_Y], tmp_img->stride[SWITCH_PLANE_Y],
284  tmp_img->planes[SWITCH_PLANE_U], tmp_img->stride[SWITCH_PLANE_U],
285  tmp_img->planes[SWITCH_PLANE_V], tmp_img->stride[SWITCH_PLANE_V],
286  (*img)->d_w, (*img)->d_h, (int)mode);
287 
288 
289  switch_img_free(img);
290  *img = tmp_img;
291 
292 #endif
293 }
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)

◆ switch_img_rotate_copy()

void switch_img_rotate_copy ( switch_image_t img,
switch_image_t **  new_img,
switch_image_rotation_mode_t  mode 
)

Definition at line 650 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, 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.

651 {
652  switch_assert(img);
653  switch_assert(new_img);
654 
655 #ifdef SWITCH_HAVE_YUV
656  if (img->fmt != SWITCH_IMG_FMT_I420) abort();
657 
658  if (*new_img != NULL) {
659  if (img->fmt != (*new_img)->fmt || img->d_w != (*new_img)->d_w || img->d_h != (*new_img)->d_h) {
660  switch_img_free(new_img);
661  }
662  }
663 
664  if (*new_img == NULL) {
665  if (mode == SRM_90 || mode == SRM_270) {
666  *new_img = switch_img_alloc(NULL, img->fmt, img->d_h, img->d_w, 1);
667  } else {
668  *new_img = switch_img_alloc(NULL, img->fmt, img->d_w, img->d_h, 1);
669  }
670  }
671 
672  switch_assert(*new_img);
673 
674 
675  I420Rotate(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
678  (*new_img)->planes[SWITCH_PLANE_Y], (*new_img)->stride[SWITCH_PLANE_Y],
679  (*new_img)->planes[SWITCH_PLANE_U], (*new_img)->stride[SWITCH_PLANE_U],
680  (*new_img)->planes[SWITCH_PLANE_V], (*new_img)->stride[SWITCH_PLANE_V],
681  img->d_w, img->d_h, (int)mode);
682 #else
683  return;
684 #endif
685 }
#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_img_scale()

switch_status_t switch_img_scale ( switch_image_t src,
switch_image_t **  destP,
int  width,
int  height 
)

Definition at line 3592 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, 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_img_free(), 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(), and switch_img_letterbox().

3593 {
3594 #ifdef SWITCH_HAVE_YUV
3595  switch_image_t *dest = NULL;
3596  int ret = 0;
3597 
3598  if (!destP) {
3599  return SWITCH_STATUS_FALSE;
3600  }
3601 
3602  dest = *destP;
3603 
3604  switch_assert(width > 0);
3605  switch_assert(height > 0);
3606 
3607  if (dest && src->fmt != dest->fmt) switch_img_free(&dest);
3608 
3609  if (!dest) dest = switch_img_alloc(NULL, src->fmt, width, height, 1);
3610 
3611  if (src->fmt == SWITCH_IMG_FMT_I420) {
3612  ret = I420Scale(src->planes[0], src->stride[0],
3613  src->planes[1], src->stride[1],
3614  src->planes[2], src->stride[2],
3615  src->d_w, src->d_h,
3616  dest->planes[0], dest->stride[0],
3617  dest->planes[1], dest->stride[1],
3618  dest->planes[2], dest->stride[2],
3619  width, height,
3620  kFilterBox);
3621  } else if (src->fmt == SWITCH_IMG_FMT_ARGB) {
3622  ret = ARGBScale(src->planes[SWITCH_PLANE_PACKED], src->d_w * 4,
3623  src->d_w, src->d_h,
3624  dest->planes[SWITCH_PLANE_PACKED], width * 4,
3625  width, height,
3626  kFilterBox);
3627  }
3628 
3629  *destP = dest;
3630 
3631  if (ret != 0) {
3632  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Scaling Error: ret: %d\n", ret);
3633  return SWITCH_STATUS_FALSE;
3634  }
3635 
3636  return SWITCH_STATUS_SUCCESS;
3637 #else
3638  return SWITCH_STATUS_FALSE;
3639 #endif
3640 }
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
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_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)

◆ switch_img_sepia()

void switch_img_sepia ( switch_image_t img,
int  x,
int  y,
int  w,
int  h 
)

Definition at line 1517 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, memset(), MIN, vpx_image::planes, vpx_image::stride, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_PLANE_PACKED, SWITCH_PLANE_U, and SWITCH_PLANE_V.

1518 {
1519 #ifdef SWITCH_HAVE_YUV
1520  if (x < 0 || y < 0 || x >= img->d_w || y >= img->d_h) return;
1521 
1522  if (img->fmt == SWITCH_IMG_FMT_ARGB) {
1523  ARGBSepia(img->planes[SWITCH_PLANE_PACKED], img->stride[SWITCH_PLANE_PACKED], x, y, w, h);
1524  } else if (img->fmt == SWITCH_IMG_FMT_I420) {
1525  int len, i, max_h;
1526 
1527  max_h = MIN(y + h, img->d_h);
1528  len = MIN(w, img->d_w - x);
1529 
1530  if (x & 1) { x++; len--; }
1531  if (y & 1) y++;
1532  if (len <= 0) return;
1533 
1534  if ((len & 1) && (x + len) < img->d_w - 1) len++;
1535 
1536  len /= 2;
1537 
1538  for (i = y; i < max_h; i += 2) {
1539  memset(img->planes[SWITCH_PLANE_U] + img->stride[SWITCH_PLANE_U] * (i / 2) + x / 2, 108, len);
1540  memset(img->planes[SWITCH_PLANE_V] + img->stride[SWITCH_PLANE_V] * (i / 2) + x / 2, 137, len);
1541  }
1542  }
1543 #endif
1544 }
#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_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)

◆ switch_img_set_rect()

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 249 of file switch_core_video.c.

References vpx_img_set_rect().

Referenced by switch_img_copy_rect(), and switch_img_patch_rect().

254 {
255 #ifdef SWITCH_HAVE_VPX
256  return vpx_img_set_rect((vpx_image_t *)img, x, y, w, h);
257 #else
258  return 0;
259 #endif
260 }
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_img_to_raw()

switch_status_t switch_img_to_raw ( switch_image_t src,
void *  dest,
int  stride,
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]strideBytes in a row for the destination. Pass 0 if the buffer has contiguous rows. Can be negative. A multiple of 16 is optimal.
[in]fmtThe target format

Definition at line 3487 of file switch_core_video.c.

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

3488 {
3489 #ifdef SWITCH_HAVE_YUV
3490  uint32_t fourcc;
3491  int ret;
3492 
3493  switch_assert(dest);
3494 
3495  fourcc = switch_img_fmt2fourcc(fmt);
3496 
3497  if (fourcc == FOURCC_ANY) {
3498  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unsupported format: %d\n", fmt);
3499  return SWITCH_STATUS_FALSE;
3500  }
3501 
3502  if (src->fmt == SWITCH_IMG_FMT_I420) {
3503  ret = ConvertFromI420(src->planes[0], src->stride[0],
3504  src->planes[1], src->stride[1],
3505  src->planes[2], src->stride[2],
3506  dest, stride,
3507  src->d_w, src->d_h,
3508  fourcc);
3509  } else if (src->fmt == SWITCH_IMG_FMT_ARGB && fmt == src->fmt) {
3510  ret = ARGBCopy(src->planes[SWITCH_PLANE_PACKED], src->stride[SWITCH_PLANE_PACKED],
3511  dest, stride,
3512  src->d_w, src->d_h);
3513  } else {
3514  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Convertion not supported %d -> %d\n", src->fmt, fmt);
3515  return SWITCH_STATUS_FALSE;
3516  }
3517 
3518  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
3519 #else
3520  return SWITCH_STATUS_FALSE;
3521 #endif
3522 }
#define SWITCH_CHANNEL_LOG
#define SWITCH_PLANE_PACKED
Definition: switch_vpx.h:52
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
int cJSON_bool fmt
Definition: switch_cJSON.h:150
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_img_txt_handle_create()

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 1864 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().

1866 {
1867  int free_pool = 0;
1868  switch_img_txt_handle_t *new_handle;
1869 
1870  if (!pool) {
1871  free_pool = 1;
1873  }
1874 
1875  new_handle = switch_core_alloc(pool, sizeof(*new_handle));
1876 
1877 #if SWITCH_HAVE_FREETYPE
1878  if (FT_Init_FreeType(&new_handle->library)) {
1879  return SWITCH_STATUS_FALSE;
1880  }
1881 /*#else
1882  return SWITCH_STATUS_FALSE; */
1883 #endif
1884 
1885  new_handle->pool = pool;
1886  new_handle->free_pool = free_pool;
1887 
1888  if (zstr(font_family)) {
1889  font_family = switch_core_sprintf(new_handle->pool, "%s%s%s",SWITCH_GLOBAL_dirs.fonts_dir, SWITCH_PATH_SEPARATOR, "FreeSans.ttf");
1890  }
1891 
1892  if (!switch_is_file_path(font_family)) {
1893  new_handle->font_family = switch_core_sprintf(new_handle->pool, "%s%s%s",SWITCH_GLOBAL_dirs.fonts_dir, SWITCH_PATH_SEPARATOR, font_family);
1894  } else {
1895  new_handle->font_family = switch_core_strdup(new_handle->pool, font_family);
1896  }
1897 
1898  if (switch_file_exists(new_handle->font_family, new_handle->pool) != SWITCH_STATUS_SUCCESS) {
1899  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Font %s does not exist\n", new_handle->font_family);
1900 #if SWITCH_HAVE_FREETYPE
1901  if (new_handle->library) {
1902  FT_Done_FreeType(new_handle->library);
1903  new_handle->library = NULL;
1904  }
1905 #endif
1906  if (free_pool) {
1908  }
1909  *handleP = NULL;
1910  return SWITCH_STATUS_FALSE;
1911  }
1912 
1913  new_handle->font_size = font_size;
1914  new_handle->angle = angle;
1915 
1916  switch_color_set_rgb(&new_handle->color, font_color);
1917  switch_color_set_rgb(&new_handle->bgcolor, bgcolor);
1918 
1919  init_gradient_table(new_handle);
1920 
1921  *handleP = new_handle;
1922 
1923  return SWITCH_STATUS_SUCCESS;
1924 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core&#39;s master pool.
Definition: switch_core.h:633
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:733
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_memory_pool_t * pool
#define zstr(x)
Definition: switch_utils.h:314
switch_memory_pool_t * pool
#define SWITCH_PATH_SEPARATOR
Definition: switch_types.h:124
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_directories SWITCH_GLOBAL_dirs
Definition: switch_core.c:82
switch_status_t switch_file_exists(const char *filename, switch_memory_pool_t *pool)
Definition: switch_apr.c:519
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

◆ switch_img_txt_handle_destroy()

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 1927 of file switch_core_video.c.

References switch_rgb_color_s::a, switch_rgb_color_s::b, switch_img_txt_handle_s::color, vpx_image::d_h, vpx_image::d_w, switch_img_txt_handle_s::free_pool, switch_rgb_color_s::g, switch_img_txt_handle_s::gradient_table, MAX_GRADIENT, pool, switch_img_txt_handle_s::pool, switch_rgb_color_s::r, switch_assert, SWITCH_CHANNEL_LOG, switch_core_destroy_memory_pool, switch_img_draw_pixel(), switch_img_get_rgb_pixel(), switch_log_printf(), SWITCH_LOG_WARNING, and switch_img_txt_handle_s::use_bgcolor.

Referenced by switch_img_write_text_img().

1928 {
1929  switch_img_txt_handle_t *old_handle;
1931 
1932  switch_assert(handleP);
1933 
1934  old_handle = *handleP;
1935  *handleP = NULL;
1936  if (!old_handle) return;
1937 
1938 
1939 #if SWITCH_HAVE_FREETYPE
1940  if (old_handle->library) {
1941  FT_Done_FreeType(old_handle->library);
1942  old_handle->library = NULL;
1943  }
1944 #endif
1945  pool = old_handle->pool;
1946 
1947  if (old_handle->free_pool) {
1949  pool = NULL;
1950  old_handle = NULL;
1951  }
1952 
1953 }
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_memory_pool_t * pool
switch_memory_pool_t * pool
struct fspr_pool_t switch_memory_pool_t
#define switch_assert(expr)

◆ switch_img_txt_handle_render()

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 2025 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, vpx_image::fmt, switch_img_txt_handle_s::font_family, switch_img_txt_handle_s::font_size, index, init_gradient_table(), switch_img_txt_handle_s::pool, 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(), switch_img_txt_handle_s::use_bgcolor, and zstr.

Referenced by switch_img_write_text_img().

2029 {
2030 #if SWITCH_HAVE_FREETYPE
2031  FT_GlyphSlot slot;
2032  FT_Matrix matrix; /* transformation matrix */
2033  FT_Vector pen; /* untransformed origin */
2034  FT_Error error;
2035  //int target_height;
2036  int index = 0;
2037  FT_ULong ch;
2038  FT_Face face;
2039  uint32_t width = 0;
2040  int this_x = 0, last_x = 0, space = 0;
2041  uint32_t ret;
2042 
2043  if (zstr(text)) return 0;
2044 
2045  if (!handle) return 0;
2046 
2047  switch_assert(!img || img->fmt == SWITCH_IMG_FMT_I420 || img->fmt == SWITCH_IMG_FMT_ARGB);
2048 
2049  if (font_family) {
2050  handle->font_family = switch_core_strdup(handle->pool, font_family);
2051  } else {
2052  font_family = handle->font_family;
2053  }
2054 
2055  if (font_size) {
2056  handle->font_size = font_size;
2057  } else {
2058  font_size = handle->font_size;
2059  }
2060 
2061  if (font_color) {
2062  switch_color_set_rgb(&handle->color, font_color);
2063  }
2064 
2065  if (bgcolor) {
2066  switch_color_set_rgb(&handle->bgcolor, bgcolor);
2067  handle->use_bgcolor = SWITCH_TRUE;
2068  } else {
2069  handle->use_bgcolor = SWITCH_FALSE;
2070  }
2071 
2072  handle->angle = angle;
2073 
2074  //angle = 0; (45.0 / 360 ) * 3.14159 * 2;
2075 
2076  //target_height = img->d_h;
2077 
2078  error = FT_New_Face(handle->library, font_family, 0, &face); /* create face object */
2079  if (error) {
2080  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to open font %s\n", font_family);
2081  return 0;
2082  }
2083 
2084  error = FT_Set_Char_Size(face, 64 * font_size, 0, 96, 0); /* set character size */
2085  if (error) return 0;
2086 
2087  slot = face->glyph;
2088 
2089  if (handle->use_bgcolor && slot->bitmap.pixel_mode != FT_PIXEL_MODE_MONO) {
2090  init_gradient_table(handle);
2091  }
2092 
2093  /* set up matrix */
2094  matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
2095  matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
2096  matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
2097  matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
2098 
2099  pen.x = x;
2100  pen.y = y;
2101 
2102  while(*(text + index)) {
2103  ch = switch_u8_get_char((char *)text, &index);
2104 
2105  if (ch == '\n') {
2106  pen.x = x;
2107  pen.y += (font_size + font_size / 4);
2108  continue;
2109  }
2110 
2111  /* set transformation */
2112  FT_Set_Transform(face, &matrix, &pen);
2113 
2114  /* load glyph image into the slot (erase previous one) */
2115  error = FT_Load_Char(face, ch, FT_LOAD_RENDER);
2116 
2117  if (error) continue;
2118 
2119  this_x = pen.x + slot->bitmap_left;
2120 
2121  if (img) {
2122  /* now, draw to our target surface (convert position) */
2123  draw_bitmap(handle, img, &slot->bitmap, this_x, pen.y - slot->bitmap_top + font_size);
2124  }
2125 
2126  if (last_x) {
2127  space = this_x - last_x;
2128  } else {
2129  space = 0;
2130  }
2131 
2132  last_x = this_x;
2133 
2134  width += space;
2135 
2136  /* increment pen position */
2137  pen.x += slot->advance.x >> 6;
2138  pen.y += slot->advance.y >> 6;
2139  }
2140 
2141  ret = width + slot->bitmap.width * 5;
2142 
2143  FT_Done_Face(face);
2144 
2145  return ret;
2146 #else
2147  return 0;
2148 #endif
2149 }
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:733
#define SWITCH_IMG_FMT_ARGB
Definition: switch_vpx.h:72
#define zstr(x)
Definition: switch_utils.h:314
switch_memory_pool_t * pool
Definition: cJSON.c:68
int index
Definition: switch_cJSON.h:160
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_img_wrap()

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 235 of file switch_core_video.c.

References vpx_img_wrap().

241 {
242 #ifdef SWITCH_HAVE_VPX
243  return (switch_image_t *)vpx_img_wrap((vpx_image_t *)img, (vpx_img_fmt_t)fmt, d_w, d_h, align, img_data);
244 #else
245  return NULL;
246 #endif
247 }
Image Descriptor.
Definition: switch_image.h:88
int cJSON_bool fmt
Definition: switch_cJSON.h:150
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 stride_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_img_write_png()

switch_status_t switch_img_write_png ( switch_image_t img,
char *  file_name 
)

Definition at line 3103 of file switch_core_video.c.

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

3104 {
3105  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "This function is not available, libpng not installed\n");
3106  return SWITCH_STATUS_FALSE;
3107 }
#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_img_write_text_img()

switch_image_t* switch_img_write_text_img ( int  w,
int  h,
switch_bool_t  full,
const char *  text 
)

Definition at line 2151 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_txt_handle_create(), switch_img_txt_handle_destroy(), switch_img_txt_handle_render(), SWITCH_PLANE_PACKED, switch_safe_free, switch_split, switch_url_decode(), and zstr.

2152 {
2153  const char *fg ="#cccccc";
2154  const char *bg = "#142e55";
2155  // const char *bg = NULL; // use a NULL bg for transparent
2156  const char *font_face = NULL;
2157  const char *fontsz = "4%";
2158  char *txt = "Value Optimized Out!";
2159  int argc = 0;
2160  char *argv[6] = { 0 };
2161  switch_rgb_color_t bgcolor = { 0 };
2162  int pre_width = 0, width = 0, font_size = 0, height = 0;
2163  char *duptxt = strdup(text);
2164  switch_img_txt_handle_t *txthandle = NULL;
2165  switch_image_t *txtimg = NULL;
2166  int x = 0, y = 0;
2167 
2168  if (!duptxt) {
2169  return NULL;
2170  }
2171 
2172  if (strchr(text, ':')) {
2173  argc = switch_split(duptxt, ':', argv);
2174 
2175  if (argc > 0 && !zstr(argv[0])) {
2176  fg = argv[0];
2177  }
2178 
2179  if (argc > 1 && !zstr(argv[1])) {
2180  bg = argv[1];
2181  if (!strcasecmp(bg, "transparent")) {
2182  bg = NULL;
2183  }
2184  }
2185 
2186  if (argc > 2 && !zstr(argv[2])) {
2187  font_face = argv[2];
2188  }
2189 
2190  if (argc > 3 && !zstr(argv[3])) {
2191  fontsz = argv[3];
2192  }
2193 
2194  if (argc > 4) {
2195  txt = argv[4];
2196  }
2197  } else txt = duptxt;
2198 
2199  if (!txt) txt = duptxt;
2200 
2201  if (strrchr(fontsz, '%')) {
2202  font_size = 1 + ((int) (float)h * (atof(fontsz) / 100.0f));
2203  } else {
2204  font_size = atoi(fontsz);
2205  }
2206 
2207  switch_url_decode(txt);
2208 
2209  while (*txt == ' ') txt++;
2210  while (end_of(txt) == ' ') end_of(txt) = '\0';
2211 
2212  switch_img_txt_handle_create(&txthandle, font_face, fg, bg, font_size, 0, NULL);
2213 
2214  pre_width = switch_img_txt_handle_render(txthandle,
2215  NULL,
2216  font_size / 2, font_size / 2,
2217  txt, NULL, fg, bg, 0, 0);
2218 
2219  height = font_size * 2;
2220 
2221  if (full && w > width) {
2222  width = w;
2223  } else {
2224  width = pre_width;
2225  }
2226 
2227  if (width == 0 || height == 0) {
2228  txtimg = NULL;
2229  goto done;
2230  }
2231 
2232  //if (bg) {
2233  // txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, height, 1);
2234  // switch_assert(txtimg);
2235  // switch_img_fill(txtimg, 0, 0, txtimg->d_w, txtimg->d_h, &bgcolor);
2236  //} else {
2237  txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_ARGB, width, height, 1);
2238  switch_assert(txtimg);
2239  //memset(txtimg->planes[SWITCH_PLANE_PACKED], 0, width * height * 4);
2240  if (bg) {
2241  switch_color_set_rgb(&bgcolor, bg);
2242  switch_img_fill(txtimg, 0, 0, txtimg->d_w, txtimg->d_h, &bgcolor);
2243  } else {
2244  memset(txtimg->planes[SWITCH_PLANE_PACKED], 0, width * height * 4);
2245  }
2246  //}
2247 
2248  x = font_size / 2;
2249  y = font_size / 2;
2250 
2251  if (full) {
2252  x = (txtimg->d_w / 2) - (pre_width / 2);
2253  }
2254 
2255  switch_img_txt_handle_render(txthandle,
2256  txtimg,
2257  x, y,
2258  txt, NULL, fg, bg, 0, 0);
2259 
2260  done:
2261 
2262  switch_img_txt_handle_destroy(&txthandle);
2263 
2264  switch_safe_free(duptxt);
2265 
2266  return txtimg;
2267 }
Image Descriptor.
Definition: switch_image.h:88
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:375
#define end_of(_s)
Definition: switch_utils.h:685
#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:314
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:885
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.
char * switch_url_decode(char *s)
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.
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.

◆ switch_img_write_to_file()

switch_status_t switch_img_write_to_file ( switch_image_t img,
const char *  file_name,
int  quality 
)

Write an image file, supported formats png,jpg,bmp,tga,hdr.

Parameters
[in]imgThe image descriptor
[in]file_nameThe file_name to write
[in]qualityOnly used in jpg, 1 ~ 100

Definition at line 3164 of file switch_core_video.c.

References vpx_image::d_h, vpx_image::d_w, vpx_image::fmt, vpx_image::planes, vpx_image::stride, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_IMG_FMT_ARGB, SWITCH_IMG_FMT_I420, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_PLANE_PACKED, SWITCH_PLANE_U, SWITCH_PLANE_V, SWITCH_PLANE_Y, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3165 {
3166 #ifndef SWITCH_HAVE_YUV
3167  return SWITCH_STATUS_FALSE;
3168 #else
3169  int comp = STBI_rgb;
3170  unsigned char *data = NULL;
3171  const char *ext = strrchr(file_name, '.');
3172  int stride_in_bytes = 0;
3173  int ret = 0;
3174 
3175  if (!ext) return SWITCH_STATUS_FALSE;
3176 
3177  ext++;
3178 
3179  if (img->fmt == SWITCH_IMG_FMT_I420) {
3180  comp = STBI_rgb;
3181  stride_in_bytes = img->d_w * 3;
3182 
3183  data = malloc(stride_in_bytes * img->d_h);
3184  switch_assert(data);
3185 
3186  I420ToRAW(img->planes[SWITCH_PLANE_Y], img->stride[SWITCH_PLANE_Y],
3189  data, stride_in_bytes,
3190  img->d_w, img->d_h);
3191  } else if (img->fmt == SWITCH_IMG_FMT_ARGB) {
3192  comp = STBI_rgb_alpha;
3193  stride_in_bytes = img->d_w * 4;
3194 
3195  data = malloc(stride_in_bytes * img->d_h);
3196  switch_assert(data);
3197 
3198 #if SWITCH_BYTE_ORDER == __BIG_ENDIAN
3199  ARGBToRGBA(img->planes[SWITCH_PLANE_PACKED], stride_in_bytes, data, stride_in_bytes, img->d_w, img->d_h);
3200 #else
3201  ARGBToABGR(img->planes[SWITCH_PLANE_PACKED], stride_in_bytes, data, stride_in_bytes, img->d_w, img->d_h);
3202 #endif
3203  } else {
3204  return SWITCH_STATUS_FALSE;
3205  }
3206 
3207  if (!strcasecmp(ext, "png")) {
3208  ret = stbi_write_png(file_name, img->d_w, img->d_h, comp, (const void *)data, stride_in_bytes);
3209  } else if (!strcasecmp(ext, "jpg") || !strcasecmp(ext, "jpeg")) {
3210  ret = stbi_write_jpg(file_name, img->d_w, img->d_h, comp, (const void *)data, quality);
3211  } else if (!strcasecmp(ext, "bmp")) {
3212  ret = stbi_write_bmp(file_name, img->d_w, img->d_h, comp, (const void *)data);
3213  } else if (!strcasecmp(ext, "tga")) {
3214  ret = stbi_write_tga(file_name, img->d_w, img->d_h, comp, (const void *)data);
3215  } else if (!strcasecmp(ext, "hdr")) {
3216  ret = stbi_write_hdr(file_name, img->d_w, img->d_h, comp, (const float *)data);
3217  } else {
3218  ret = 0;
3219  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unsupported file format [%s]", ext);
3220  }
3221 
3222  free(data);
3223 
3225 #endif
3226 }
#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
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
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_png_free()

void switch_png_free ( switch_png_t **  pngP)

◆ switch_png_open()

switch_status_t switch_png_open ( switch_png_t **  pngP,
const char *  file_name 
)

◆ switch_png_patch_img()

switch_status_t switch_png_patch_img ( switch_png_t use_png,
switch_image_t img,
int  x,
int  y 
)

◆ switch_RGBAToARGB()

switch_status_t switch_RGBAToARGB ( const uint8_t *  src_frame,
int  src_stride_frame,
uint8_t *  dst_argb,
int  dst_stride_argb,
int  width,
int  height 
)

Definition at line 3833 of file switch_core_video.c.

References SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

3836 {
3837 #ifdef SWITCH_HAVE_YUV
3838  int ret = RGBAToARGB(src_frame, src_stride_frame, dst_argb, dst_stride_argb, width, height);
3839 
3840  return ret == 0 ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
3841 #else
3842  return SWITCH_STATUS_FALSE;
3843 #endif
3844 }