diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h index e152922675..340d1fa30a 100644 --- a/src/include/switch_core_video.h +++ b/src/include/switch_core_video.h @@ -410,6 +410,7 @@ SWITCH_DECLARE(void) switch_img_overlay(switch_image_t *IMG, switch_image_t *img SWITCH_DECLARE(switch_status_t) switch_img_mirror(switch_image_t *src, switch_image_t **destP); SWITCH_DECLARE(switch_status_t) switch_img_scale(switch_image_t *src, switch_image_t **destP, int width, int height); SWITCH_DECLARE(switch_status_t) switch_img_fit(switch_image_t **srcP, int width, int height, switch_img_fit_t fit); +SWITCH_DECLARE(void) switch_img_calc_fit(switch_image_t *src, int width, int height, int *new_wP, int *new_hP); SWITCH_DECLARE(switch_img_position_t) parse_img_position(const char *name); SWITCH_DECLARE(switch_img_fit_t) parse_img_fit(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); diff --git a/src/switch_core_video.c b/src/switch_core_video.c index e486a22702..1b39ce46a3 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -1872,7 +1872,7 @@ SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_create(switch_img_txt_hand new_handle->free_pool = free_pool; if (zstr(font_family)) { - font_family = switch_core_sprintf(new_handle->pool, "%s%s%s",SWITCH_GLOBAL_dirs.fonts_dir, SWITCH_PATH_SEPARATOR, "FreeMono.ttf"); + font_family = switch_core_sprintf(new_handle->pool, "%s%s%s",SWITCH_GLOBAL_dirs.fonts_dir, SWITCH_PATH_SEPARATOR, "FreeSans.ttf"); } if (!switch_is_file_path(font_family)) { @@ -3110,31 +3110,12 @@ SWITCH_DECLARE(switch_status_t) switch_img_letterbox(switch_image_t *img, switch return SWITCH_STATUS_SUCCESS; } -SWITCH_DECLARE(switch_status_t) switch_img_fit(switch_image_t **srcP, int width, int height, switch_img_fit_t fit) +SWITCH_DECLARE(void) switch_img_calc_fit(switch_image_t *src, int width, int height, int *new_wP, int *new_hP) { - switch_image_t *src, *tmp = NULL; - int new_w = 0, new_h = 0; - - switch_assert(srcP); - switch_assert(width && height); - - src = *srcP; - - if (!src || (src->d_w == width && src->d_h == height)) { - return SWITCH_STATUS_SUCCESS; - } - - if (fit == SWITCH_FIT_NECESSARY && src->d_w <= width && src->d_h < height) { - return SWITCH_STATUS_SUCCESS; - } - - if (fit == SWITCH_FIT_SCALE) { - switch_img_scale(src, &tmp, width, height); - switch_img_free(&src); - *srcP = tmp; - return SWITCH_STATUS_SUCCESS; - } + int new_w, new_h; + switch_assert(src); + new_w = src->d_w; new_h = src->d_h; @@ -3163,6 +3144,37 @@ SWITCH_DECLARE(switch_status_t) switch_img_fit(switch_image_t **srcP, int width, } } + *new_wP = new_w; + *new_hP = new_h; +} + +SWITCH_DECLARE(switch_status_t) switch_img_fit(switch_image_t **srcP, int width, int height, switch_img_fit_t fit) +{ + switch_image_t *src, *tmp = NULL; + int new_w = 0, new_h = 0; + + switch_assert(srcP); + switch_assert(width && height); + + src = *srcP; + + if (!src || (src->d_w == width && src->d_h == height)) { + return SWITCH_STATUS_SUCCESS; + } + + if (fit == SWITCH_FIT_NECESSARY && src->d_w <= width && src->d_h < height) { + return SWITCH_STATUS_SUCCESS; + } + + if (fit == SWITCH_FIT_SCALE) { + switch_img_scale(src, &tmp, width, height); + switch_img_free(&src); + *srcP = tmp; + return SWITCH_STATUS_SUCCESS; + } + + switch_img_calc_fit(src, width, height, &new_w, &new_h); + if (new_w && new_h) { if (switch_img_scale(src, &tmp, new_w, new_h) == SWITCH_STATUS_SUCCESS) { switch_img_free(&src);