SWITCH_DECLARE(switch_img_position_t) parse_img_position(const char *name);
SWITCH_DECLARE(void) switch_img_find_position(switch_img_position_t pos, int sw, int sh, int iw, int ih, int *xP, int *yP);
SWITCH_DECLARE(switch_status_t) switch_img_convert(switch_image_t *src, switch_convert_fmt_t fmt, void *dest, switch_size_t *size);
+SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, const char *text);
/** @} */
switch_image_t *cur_img;
switch_image_t *banner_img;
switch_image_t *logo_img;
+ switch_image_t *logo_text_img;
switch_image_t *mute_img;
switch_img_txt_handle_t *txthandle;
conference_file_node_t *fnode;
switch_img_free(&layer->banner_img);
switch_img_free(&layer->logo_img);
+ switch_img_free(&layer->logo_text_img);
layer->banner_patched = 0;
layer->is_avatar = 0;
switch_img_fit(&layer->logo_img, ew, eh);
switch_img_find_position(layer->logo_pos, ew, eh, layer->logo_img->d_w, layer->logo_img->d_h, &ex, &ey);
switch_img_patch(IMG, layer->logo_img, x_pos + ex, y_pos + ey);
+ if (layer->logo_text_img) {
+ int tx = 0, ty = 0;
+ switch_img_find_position(POS_LEFT_BOT,
+ layer->logo_img->d_w, layer->logo_img->d_h, layer->logo_text_img->d_w, layer->logo_text_img->d_h, &tx, &ty);
+ switch_img_patch(IMG, layer->logo_text_img, x_pos + ex + tx, y_pos + ey + ty);
+ }
+
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "insert at %d,%d\n", 0, 0);
if (path) {
switch_img_free(&layer->logo_img);
+ switch_img_free(&layer->logo_text_img);
}
if (*path == '{') {
layer->logo_img = switch_img_read_png(path, SWITCH_IMG_FMT_ARGB);
}
- layer->logo_pos = pos;
+ if (layer->logo_img) {
+ layer->logo_pos = pos;
+
+ if ((var = switch_event_get_header(params, "text"))) {
+ layer->logo_text_img = switch_img_write_text_img(layer->screen_w, layer->screen_h, var);
+ }
+ }
if (params) switch_event_destroy(¶ms);
switch_img_free(&layer->banner_img);
switch_img_free(&layer->logo_img);
+ switch_img_free(&layer->logo_text_img);
layer->banner_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, layer->screen_w, font_size * 2, 1);
if (layer->txthandle) {
layer->banner_patched = 0;
switch_img_free(&layer->banner_img);
switch_img_free(&layer->logo_img);
+ switch_img_free(&layer->logo_text_img);
switch_img_free(&layer->mute_img);
switch_mutex_unlock(conference->canvas->mutex);
#endif
}
+SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, const char *text)
+{
+ const char *fg ="#cccccc";
+ const char *bg = "#142e55";
+ const char *font_face = NULL;
+ const char *fontsz = "4%";
+ const char *txt = "Value Optimized Out!";
+ int argc = 0;
+ char *argv[6] = { 0 };
+ switch_rgb_color_t bgcolor = { 0 };
+ int width, font_size = 0;
+ int len = 0;
+ char *duptxt = strdup(text);
+ switch_img_txt_handle_t *txthandle = NULL;
+ switch_image_t *txtimg = NULL;
+
+ if (strchr(text, ':')) {
+ argc = switch_split(duptxt, ':', argv);
+
+ if (argc > 0) {
+ fg = argv[0];
+ }
+
+ if (argc > 1) {
+ bg = argv[1];
+ }
+
+ if (argc > 2) {
+ font_face = argv[2];
+ }
+
+ if (argc > 3) {
+ fontsz = argv[3];
+ }
+
+ if (argc > 4) {
+ txt = argv[4];
+ }
+ }
+
+ if (!txt) txt = duptxt;
+
+ if (strrchr(fontsz, '%')) {
+ font_size = 1 + ((int) (float)h * (atof(fontsz) / 100.0f));
+ } else {
+ font_size = atoi(fontsz);
+ }
+
+ len = strlen(txt);
+
+ if (len < 5) len = 5;
+
+ width = (int) (float)(font_size * 0.75f * len);
+
+ txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, font_size * 2, 1);
+
+ switch_img_txt_handle_create(&txthandle, font_face, fg, bg, font_size, 0, NULL);
+ switch_color_set_rgb(&bgcolor, bg);
+
+ switch_img_fill(txtimg, 0, 0, txtimg->d_w, txtimg->d_h, &bgcolor);
+ switch_img_txt_handle_render(txthandle,
+ txtimg,
+ font_size / 2, font_size / 2,
+ txt, NULL, fg, bg, 0, 0);
+ switch_img_txt_handle_destroy(&txthandle);
+ return txtimg;
+}
/* WARNING:
patch a big IMG with a rect hole, note this function is WIP ......