提交 0697db4f authored 作者: Anthony Minessale's avatar Anthony Minessale 提交者: Michael Jerris

FS-7506 FS-7513: set banner with video_banner_text variable set before calling…

FS-7506 FS-7513: set banner with video_banner_text variable set before calling in, NEEDS DOCS params are parsable inside a {} string
上级 9d7eef28
...@@ -153,9 +153,9 @@ libfreeswitch_spandsp_la_SOURCES = libs/spandsp/src/plc.c libs/spandsp/src/alloc ...@@ -153,9 +153,9 @@ libfreeswitch_spandsp_la_SOURCES = libs/spandsp/src/plc.c libs/spandsp/src/alloc
libfreeswitch_spandsp_la_CFLAGS = -Ilibs/spandsp/src $(CORE_CFLAGS) $(AM_CFLAGS) libfreeswitch_spandsp_la_CFLAGS = -Ilibs/spandsp/src $(CORE_CFLAGS) $(AM_CFLAGS)
CORE_LIBS+=libfreeswitch_spandsp.la CORE_LIBS+=libfreeswitch_spandsp.la
lib_LTLIBRARIES = libfreeswitch.la lib_LTLIBRARIES = libfreeswitch.la
libfreeswitch_la_CFLAGS = $(CORE_CFLAGS) $(SQLITE_CFLAGS) $(CURL_CFLAGS) $(PCRE_CFLAGS) $(SPEEX_CFLAGS) $(LIBEDIT_CFLAGS) $(openssl_CFLAGS) $(AM_CFLAGS) libfreeswitch_la_CFLAGS = $(CORE_CFLAGS) $(SQLITE_CFLAGS) $(FREETYPE_CFLAGS) $(CURL_CFLAGS) $(PCRE_CFLAGS) $(SPEEX_CFLAGS) $(LIBEDIT_CFLAGS) $(openssl_CFLAGS) $(AM_CFLAGS)
libfreeswitch_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) $(PLATFORM_CORE_LDFLAGS) -no-undefined libfreeswitch_la_LDFLAGS = -version-info 1:0:0 $(AM_LDFLAGS) $(PLATFORM_CORE_LDFLAGS) -no-undefined
libfreeswitch_la_LIBADD = $(CORE_LIBS) $(APR_LIBS) $(SQLITE_LIBS) $(CURL_LIBS) $(PCRE_LIBS) $(SPEEX_LIBS) $(LIBEDIT_LIBS) $(openssl_LIBS) $(VPX_LIBS) $(PLATFORM_CORE_LIBS) libfreeswitch_la_LIBADD = $(CORE_LIBS) $(APR_LIBS) $(SQLITE_LIBS) $(FREETYPE_LIBS) $(CURL_LIBS) $(PCRE_LIBS) $(SPEEX_LIBS) $(LIBEDIT_LIBS) $(openssl_LIBS) $(VPX_LIBS) $(PLATFORM_CORE_LIBS)
libfreeswitch_la_DEPENDENCIES = $(BUILT_SOURCES) libfreeswitch_la_DEPENDENCIES = $(BUILT_SOURCES)
if HAVE_ODBC if HAVE_ODBC
...@@ -215,6 +215,8 @@ library_include_HEADERS = \ ...@@ -215,6 +215,8 @@ library_include_HEADERS = \
src/include/switch_curl.h \ src/include/switch_curl.h \
src/include/switch_json.h \ src/include/switch_json.h \
src/include/switch_stfu.h \ src/include/switch_stfu.h \
src/include/switch_utf8.h \
src/include/switch_vpx.h \
libs/libteletone/src/libteletone_detect.h \ libs/libteletone/src/libteletone_detect.h \
libs/libteletone/src/libteletone_generate.h \ libs/libteletone/src/libteletone_generate.h \
libs/libteletone/src/libteletone.h \ libs/libteletone/src/libteletone.h \
...@@ -293,6 +295,7 @@ libfreeswitch_la_SOURCES = \ ...@@ -293,6 +295,7 @@ libfreeswitch_la_SOURCES = \
src/switch_curl.c \ src/switch_curl.c \
src/switch_hashtable.c\ src/switch_hashtable.c\
src/switch_stfu.c \ src/switch_stfu.c \
src/switch_utf8.c \
libs/libtpl-1.5/src/tpl.c \ libs/libtpl-1.5/src/tpl.c \
libs/libteletone/src/libteletone_detect.c \ libs/libteletone/src/libteletone_detect.c \
libs/libteletone/src/libteletone_generate.c \ libs/libteletone/src/libteletone_generate.c \
......
...@@ -1192,6 +1192,7 @@ module_enabled() { ...@@ -1192,6 +1192,7 @@ module_enabled() {
grep -v -e "\#" -e "^\$" modules.conf | sed -e "s|^.*/||" | grep "^${1}\$" >/dev/null grep -v -e "\#" -e "^\$" modules.conf | sed -e "s|^.*/||" | grep "^${1}\$" >/dev/null
} }
PKG_CHECK_MODULES([FREETYPE], [freetype2 >= 2.4.9])
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.6.20]) PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.6.20])
PKG_CHECK_MODULES([CURL], [libcurl >= 7.19]) PKG_CHECK_MODULES([CURL], [libcurl >= 7.19])
PKG_CHECK_MODULES([PCRE], [libpcre >= 7.8]) PKG_CHECK_MODULES([PCRE], [libpcre >= 7.8])
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Anthony Minessale II <anthm@freeswitch.org>
* *
* *
* switch_core_video.h -- Core Video header * switch_core_video.h -- Core Video header
...@@ -35,32 +36,14 @@ ...@@ -35,32 +36,14 @@
opportunity to thank libvpx for all the awesome stuff it does and for making my life much easier. opportunity to thank libvpx for all the awesome stuff it does and for making my life much easier.
*/ */
#ifndef SWITCH_VIDEO_H #ifndef SWITCH_VIDEO_H
#define SWITCH_VIDEO_H #define SWITCH_VIDEO_H
#include "vpx/vpx_image.h" #include <switch.h>
#include "vpx/vpx_integer.h"
SWITCH_BEGIN_EXTERN_C SWITCH_BEGIN_EXTERN_C
#define SWITCH_IMG_FMT_PLANAR VPX_IMG_FMT_PLANAR
#define SWITCH_IMG_FMT_UV_FLIP VPX_IMG_FMT_UV_FLIP
#define SWITCH_IMG_FMT_HAS_ALPHA VPX_IMG_FMT_HAS_ALPHA
#define SWITCH_PLANE_PACKED VPX_PLANE_PACKED
#define SWITCH_PLANE_Y VPX_PLANE_Y
#define SWITCH_PLANE_U VPX_PLANE_U
#define SWITCH_PLANE_V VPX_PLANE_V
#define SWITCH_PLANE_ALPHA VPX_PLANE_ALPHA
#ifndef VPX_IMG_FMT_HIGH /* not available in libvpx 1.3.0 (see commit hash e97aea28) */
#define VPX_IMG_FMT_HIGH 0x800 /**< Image uses 16bit framebuffer */
#endif
#define SWITCH_IMG_FMT_HIGH VPX_IMG_FMT_HIGH
#define SWITCH_IMG_FMT_I420 VPX_IMG_FMT_I420
typedef struct switch_yuv_color_s { typedef struct switch_yuv_color_s {
uint8_t y; uint8_t y;
uint8_t u; uint8_t u;
...@@ -68,9 +51,6 @@ typedef struct switch_yuv_color_s { ...@@ -68,9 +51,6 @@ typedef struct switch_yuv_color_s {
} switch_yuv_color_t; } switch_yuv_color_t;
typedef vpx_img_fmt_t switch_img_fmt_t;
typedef vpx_image_t switch_image_t;
/**\brief Representation of a rectangle on a surface */ /**\brief Representation of a rectangle on a surface */
typedef struct switch_image_rect { typedef struct switch_image_rect {
...@@ -80,6 +60,7 @@ typedef struct switch_image_rect { ...@@ -80,6 +60,7 @@ typedef struct switch_image_rect {
unsigned int h; /**< height */ unsigned int h; /**< height */
} switch_image_rect_t; } switch_image_rect_t;
/*!\brief Open a descriptor, allocating storage for the underlying image /*!\brief Open a descriptor, allocating storage for the underlying image
* *
* Returns a descriptor for storing an image of the given format. The * Returns a descriptor for storing an image of the given format. The
...@@ -193,7 +174,16 @@ SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, i ...@@ -193,7 +174,16 @@ SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, i
SWITCH_DECLARE(void) switch_img_draw_pixel(switch_image_t *img, int x, int y, switch_yuv_color_t color); SWITCH_DECLARE(void) switch_img_draw_pixel(switch_image_t *img, int x, int y, switch_yuv_color_t color);
SWITCH_DECLARE(void) switch_color_set(switch_yuv_color_t *color, char *color_str); SWITCH_DECLARE(void) switch_color_set(switch_yuv_color_t *color, const char *color_str);
SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_create(switch_img_txt_handle_t **handleP, const char *font_family,
const char *font_color, uint16_t font_size, double angle, switch_memory_pool_t *pool);
SWITCH_DECLARE(void) switch_img_txt_handle_destroy(switch_img_txt_handle_t **handleP);
SWITCH_DECLARE(switch_status_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, uint16_t font_size, double angle);
/** @} */ /** @} */
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include <switch.h> #include <switch.h>
#include <switch_json.h> #include <switch_json.h>
#include <switch_core_video.h> #include <switch_vpx.h>
SWITCH_BEGIN_EXTERN_C SWITCH_BEGIN_EXTERN_C
#define SWITCH_ENT_ORIGINATE_DELIM ":_:" #define SWITCH_ENT_ORIGINATE_DELIM ":_:"
...@@ -2215,8 +2215,6 @@ typedef switch_status_t (*switch_core_codec_control_func_t) (switch_codec_t *cod ...@@ -2215,8 +2215,6 @@ typedef switch_status_t (*switch_core_codec_control_func_t) (switch_codec_t *cod
void **ret_data); void **ret_data);
typedef switch_status_t (*switch_image_write_callback_t) (switch_core_session_t *session, switch_frame_t *frame, switch_image_t *img, void *user_data);
typedef switch_status_t (*switch_core_codec_init_func_t) (switch_codec_t *, switch_codec_flag_t, const switch_codec_settings_t *codec_settings); typedef switch_status_t (*switch_core_codec_init_func_t) (switch_codec_t *, switch_codec_flag_t, const switch_codec_settings_t *codec_settings);
typedef switch_status_t (*switch_core_codec_fmtp_parse_func_t) (const char *fmtp, switch_codec_fmtp_t *codec_fmtp); typedef switch_status_t (*switch_core_codec_fmtp_parse_func_t) (const char *fmtp, switch_codec_fmtp_t *codec_fmtp);
typedef switch_status_t (*switch_core_codec_destroy_func_t) (switch_codec_t *); typedef switch_status_t (*switch_core_codec_destroy_func_t) (switch_codec_t *);
...@@ -2501,6 +2499,8 @@ typedef struct switch_waitlist_s { ...@@ -2501,6 +2499,8 @@ typedef struct switch_waitlist_s {
struct switch_vb_s; struct switch_vb_s;
typedef struct switch_vb_s switch_vb_t; typedef struct switch_vb_s switch_vb_t;
struct switch_img_txt_handle_s;
typedef struct switch_img_txt_handle_s switch_img_txt_handle_t;
SWITCH_END_EXTERN_C SWITCH_END_EXTERN_C
#endif #endif
......
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Seven Du <dujinfang@gmail.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Anthony Minessale II <anthm@freeswitch.org>
*
*
* switch_utf8.h UTf8
*
*/
/*
Basic UTF-8 manipulation routines
by Jeff Bezanson
placed in the public domain Fall 2005
This code is designed to provide the utilities you need to manipulate
UTF-8 as an internal string encoding. These functions do not perform the
error checking normally needed when handling UTF-8 data, so if you happen
to be from the Unicode Consortium you will want to flay me alive.
I do this because error checking can be performed at the boundaries (I/O),
with these routines reserved for higher performance on data known to be
valid.
*/
#include <switch.h>
/* is c the start of a utf8 sequence? */
#define isutf(c) (((c)&0xC0)!=0x80)
/* convert UTF-8 data to wide character */
SWITCH_DECLARE(int) switch_u8_toucs(uint32_t *dest, int sz, char *src, int srcsz);
/* the opposite conversion */
SWITCH_DECLARE(int) switch_u8_toutf8(char *dest, int sz, uint32_t *src, int srcsz);
/* single character to UTF-8 */
SWITCH_DECLARE(int) switch_u8_wc_toutf8(char *dest, uint32_t ch);
/* character number to byte offset */
SWITCH_DECLARE(int) switch_u8_offset(char *str, int charnum);
/* byte offset to character number */
SWITCH_DECLARE(int) switch_u8_charnum(char *s, int offset);
/* return next character, updating an index variable */
SWITCH_DECLARE(uint32_t) switch_u8_nextchar(char *s, int *i);
/* move to next character */
SWITCH_DECLARE(void) switch_u8_inc(char *s, int *i);
/* move to previous character */
SWITCH_DECLARE(void) switch_u8_dec(char *s, int *i);
/* returns length of next utf-8 sequence */
SWITCH_DECLARE(int) switch_u8_seqlen(char *s);
/* assuming src points to the character after a backslash, read an
escape sequence, storing the result in dest and returning the number of
input characters processed */
SWITCH_DECLARE(int) switch_u8_read_escape_sequence(char *src, uint32_t *dest);
/* given a wide character, convert it to an ASCII escape sequence stored in
buf, where buf is "sz" bytes. returns the number of characters output.*/
SWITCH_DECLARE(int) switch_u8_escape_wchar(char *buf, int sz, uint32_t ch);
/* convert a string "src" containing escape sequences to UTF-8 */
SWITCH_DECLARE(int) switch_u8_unescape(char *buf, int sz, char *src);
/* convert UTF-8 "src" to ASCII with escape sequences.
if escape_quotes is nonzero, quote characters will be preceded by
backslashes as well. */
SWITCH_DECLARE(int) switch_u8_escape(char *buf, int sz, char *src, int escape_quotes);
/* utility predicates used by the above */
int octal_digit(char c);
int hex_digit(char c);
/* return a pointer to the first occurrence of ch in s, or NULL if not
found. character index of found character returned in *charn. */
SWITCH_DECLARE(char *) switch_u8_strchr(char *s, uint32_t ch, int *charn);
/* same as the above, but searches a buffer of a given size instead of
a NUL-terminated string. */
SWITCH_DECLARE(char *) switch_u8_memchr(char *s, uint32_t ch, size_t sz, int *charn);
/* count the number of characters in a UTF-8 string */
SWITCH_DECLARE(int) switch_u8_strlen(char *s);
SWITCH_DECLARE(int) switch_u8_is_locale_utf8(char *locale);
/* printf where the format string and arguments may be in UTF-8.
you can avoid this function and just use ordinary printf() if the current
locale is UTF-8. */
SWITCH_DECLARE(int) switch_u8_vprintf(char *fmt, va_list ap);
SWITCH_DECLARE(int) switch_u8_printf(char *fmt, ...);
SWITCH_DECLARE(uint32_t) switch_u8_get_char(char *s, int *i);
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Seven Du <dujinfang@gmail.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* switch_vpx.h -- vpx resources
*
*/
/*! \file switch_vpx.h
\brief vpx resources
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.
*/
#ifndef SWITCH_VPX_H
#define SWITCH_VPX_H
#include <switch.h>
#include "vpx/vpx_image.h"
#include "vpx/vpx_integer.h"
SWITCH_BEGIN_EXTERN_C
#define SWITCH_IMG_FMT_PLANAR VPX_IMG_FMT_PLANAR
#define SWITCH_IMG_FMT_UV_FLIP VPX_IMG_FMT_UV_FLIP
#define SWITCH_IMG_FMT_HAS_ALPHA VPX_IMG_FMT_HAS_ALPHA
#define SWITCH_PLANE_PACKED VPX_PLANE_PACKED
#define SWITCH_PLANE_Y VPX_PLANE_Y
#define SWITCH_PLANE_U VPX_PLANE_U
#define SWITCH_PLANE_V VPX_PLANE_V
#define SWITCH_PLANE_ALPHA VPX_PLANE_ALPHA
#ifndef VPX_IMG_FMT_HIGH /* not available in libvpx 1.3.0 (see commit hash e97aea28) */
#define VPX_IMG_FMT_HIGH 0x800 /**< Image uses 16bit framebuffer */
#endif
#define SWITCH_IMG_FMT_HIGH VPX_IMG_FMT_HIGH
#define SWITCH_IMG_FMT_I420 VPX_IMG_FMT_I420
typedef vpx_img_fmt_t switch_img_fmt_t;
typedef vpx_image_t switch_image_t;
SWITCH_END_EXTERN_C
#endif
/* For Emacs:
* Local Variables:
* mode:c
* indent-tabs-mode:t
* tab-width:4
* c-basic-offset:4
* End:
* For VIM:
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
*/
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Anthony Minessale II <anthm@freeswitch.org>
* *
* *
* switch_core_video.c -- Core Video * switch_core_video.c -- Core Video
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
*/ */
#include <switch.h> #include <switch.h>
#include <switch_utf8.h>
SWITCH_DECLARE(switch_image_t *)switch_img_alloc(switch_image_t *img, SWITCH_DECLARE(switch_image_t *)switch_img_alloc(switch_image_t *img,
...@@ -247,7 +249,7 @@ SWITCH_DECLARE(void) switch_img_add_text(void *buffer, int w, int x, int y, char ...@@ -247,7 +249,7 @@ SWITCH_DECLARE(void) switch_img_add_text(void *buffer, int w, int x, int y, char
} }
} }
SWITCH_DECLARE(void) switch_color_set(switch_yuv_color_t *color, char *color_str) SWITCH_DECLARE(void) switch_color_set(switch_yuv_color_t *color, const char *color_str)
{ {
uint8_t y = 134; uint8_t y = 134;
uint8_t u = 128; uint8_t u = 128;
...@@ -256,8 +258,13 @@ SWITCH_DECLARE(void) switch_color_set(switch_yuv_color_t *color, char *color_str ...@@ -256,8 +258,13 @@ SWITCH_DECLARE(void) switch_color_set(switch_yuv_color_t *color, char *color_str
if (color_str != NULL && strlen(color_str) == 7) { if (color_str != NULL && strlen(color_str) == 7) {
uint8_t red, green, blue; uint8_t red, green, blue;
char str[7]; char str[7];
int i;
color_str++; color_str++;
strncpy(str, color_str, 6); strncpy(str, color_str, 6);
for(i = 0; i < 6; i++) {
str[i] = switch_toupper(str[i]);
}
red = (str[0] >= 'A' ? (str[0] - 'A' + 10) * 16 : (str[0] - '0') * 16) + (str[1] >= 'A' ? (str[1] - 'A' + 10) : (str[0] - '0')); red = (str[0] >= 'A' ? (str[0] - 'A' + 10) * 16 : (str[0] - '0') * 16) + (str[1] >= 'A' ? (str[1] - 'A' + 10) : (str[0] - '0'));
green = (str[2] >= 'A' ? (str[2] - 'A' + 10) * 16 : (str[2] - '0') * 16) + (str[3] >= 'A' ? (str[3] - 'A' + 10) : (str[0] - '0')); green = (str[2] >= 'A' ? (str[2] - 'A' + 10) * 16 : (str[2] - '0') * 16) + (str[3] >= 'A' ? (str[3] - 'A' + 10) : (str[0] - '0'));
blue = (str[4] >= 'A' ? (str[4] - 'A' + 10) * 16 : (str[4] - '0') * 16) + (str[5] >= 'A' ? (str[5] - 'A' + 10) : (str[0] - '0')); blue = (str[4] >= 'A' ? (str[4] - 'A' + 10) * 16 : (str[4] - '0') * 16) + (str[5] >= 'A' ? (str[5] - 'A' + 10) : (str[0] - '0'));
...@@ -273,6 +280,194 @@ SWITCH_DECLARE(void) switch_color_set(switch_yuv_color_t *color, char *color_str ...@@ -273,6 +280,194 @@ SWITCH_DECLARE(void) switch_color_set(switch_yuv_color_t *color, char *color_str
color->v = v; color->v = v;
} }
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
struct switch_img_txt_handle_s {
FT_Library library;
FT_Face face;
char *font_family;
double angle;
uint16_t font_size;
switch_yuv_color_t color;
switch_image_t *img;
switch_memory_pool_t *pool;
int free_pool;
};
SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_create(switch_img_txt_handle_t **handleP, const char *font_family,
const char *font_color, uint16_t font_size, double angle, switch_memory_pool_t *pool)
{
int free_pool = 0;
switch_img_txt_handle_t *new_handle;
if (!pool) {
free_pool = 1;
switch_core_new_memory_pool(&pool);
}
new_handle = switch_core_alloc(pool, sizeof(*new_handle));
if (FT_Init_FreeType(&new_handle->library)) {
return SWITCH_STATUS_FALSE;
}
new_handle->pool = pool;
new_handle->free_pool = free_pool;
new_handle->font_family = switch_core_strdup(new_handle->pool, font_family);
new_handle->font_size = font_size;
new_handle->angle = angle;
switch_color_set(&new_handle->color, font_color);
*handleP = new_handle;
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(void) switch_img_txt_handle_destroy(switch_img_txt_handle_t **handleP)
{
switch_img_txt_handle_t *old_handle = *handleP;
switch_memory_pool_t *pool;
*handleP = NULL;
if (old_handle->library) {
FT_Done_FreeType(old_handle->library);
old_handle->library = NULL;
}
pool = old_handle->pool;
if (old_handle->free_pool) {
switch_core_destroy_memory_pool(&pool);
pool = NULL;
old_handle = NULL;
}
}
static void draw_bitmap(switch_image_t *img, FT_Bitmap* bitmap, FT_Int x, FT_Int y, switch_yuv_color_t color)
{
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
switch (bitmap->pixel_mode) {
case FT_PIXEL_MODE_GRAY: // it should always be GRAY since we use FT_LOAD_RENDER?
break;
case FT_PIXEL_MODE_NONE:
case FT_PIXEL_MODE_MONO:
case FT_PIXEL_MODE_GRAY2:
case FT_PIXEL_MODE_GRAY4:
case FT_PIXEL_MODE_LCD:
case FT_PIXEL_MODE_LCD_V:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "unsupported pixel mode %d\n", bitmap->pixel_mode);
return;
}
for ( i = x, p = 0; i < x_max; i++, p++ ) {
for ( j = y, q = 0; j < y_max; j++, q++ ) {
if ( i < 0 || j < 0 || i >= img->d_w || j >= img->d_h) continue;
if (bitmap->buffer[q * bitmap->width + p] > 128) {
switch_img_draw_pixel(img, i, j, color);
}
}
}
}
SWITCH_DECLARE(switch_status_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, uint16_t font_size, double angle)
{
FT_GlyphSlot slot;
FT_Matrix matrix; /* transformation matrix */
FT_Vector pen; /* untransformed origin */
FT_Error error;
int target_height;
int index = 0;
FT_ULong ch;
FT_Face face;
if (zstr(text)) return SWITCH_STATUS_FALSE;
if (font_family) {
handle->font_family = switch_core_strdup(handle->pool, font_family);
} else {
font_family = handle->font_family;
}
if (font_size) {
handle->font_size = font_size;
} else {
font_size = handle->font_size;
}
if (font_color) {
switch_color_set(&handle->color, font_color);
}
handle->angle = angle;
//angle = 0; (45.0 / 360 ) * 3.14159 * 2;
target_height = img->d_h;
error = FT_New_Face(handle->library, font_family, 0, &face); /* create face object */
if (error) {printf("WTF %s %d\n", font_family, __LINE__); return SWITCH_STATUS_FALSE;}
/* use 50pt at 100dpi */
error = FT_Set_Char_Size(face, 64 * font_size, 0, 96, 96); /* set character size */
if (error) {printf("WTF %d\n", __LINE__); return SWITCH_STATUS_FALSE;}
slot = face->glyph;
/* set up matrix */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
pen.x = x * 64;
pen.y = (target_height - y) * 64;
while(*(text + index)) {
ch = switch_u8_get_char((char *)text, &index);
if (ch == '\n') {
pen.x = x * 64;
pen.y -= (font_size + font_size / 4) * 64;
continue;
}
/* set transformation */
FT_Set_Transform(face, &matrix, &pen);
/* load glyph image into the slot (erase previous one) */
error = FT_Load_Char(face, ch, FT_LOAD_RENDER);
if (error) continue;
/* now, draw to our target surface (convert position) */
draw_bitmap(img, &slot->bitmap, slot->bitmap_left, target_height - slot->bitmap_top + font_size, handle->color);
/* increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
FT_Done_Face(face);
return SWITCH_STATUS_SUCCESS;
}
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论