提交 f6c7421a authored 作者: Seven Du's avatar Seven Du 提交者: Anthony Minessale

FS-7506 FS-7513: refactor with rgb color space to support anti aliasing

上级 a6a8a99d
...@@ -50,7 +50,11 @@ typedef struct switch_yuv_color_s { ...@@ -50,7 +50,11 @@ typedef struct switch_yuv_color_s {
uint8_t v; uint8_t v;
} switch_yuv_color_t; } switch_yuv_color_t;
typedef struct switch_rgb_color_s {
uint8_t r;
uint8_t g;
uint8_t b;
} switch_rgb_color_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 {
...@@ -164,26 +168,28 @@ SWITCH_DECLARE(void) switch_img_flip(switch_image_t *img); ...@@ -164,26 +168,28 @@ SWITCH_DECLARE(void) switch_img_flip(switch_image_t *img);
*/ */
SWITCH_DECLARE(void) switch_img_free(switch_image_t **img); SWITCH_DECLARE(void) switch_img_free(switch_image_t **img);
SWITCH_DECLARE(void) switch_img_draw_text(switch_image_t *IMG, int x, int y, switch_yuv_color_t color, uint16_t font_size, char *text); SWITCH_DECLARE(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_DECLARE(void) switch_img_add_text(void *buffer, int w, int x, int y, char *s); SWITCH_DECLARE(void) switch_img_add_text(void *buffer, int w, int x, int y, char *s);
SWITCH_DECLARE(switch_image_t *) switch_img_copy_rect(switch_image_t *img, int x, int y, int w, int h); SWITCH_DECLARE(switch_image_t *) switch_img_copy_rect(switch_image_t *img, int x, int y, int w, int h);
SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_yuv_color_t color); SWITCH_DECLARE(void) switch_img_fill(switch_image_t *img, int x, int y, int w, int h, switch_rgb_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_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, const char *color_str); SWITCH_DECLARE(void) switch_color_set_rgb(switch_rgb_color_t *color, const char *color_str);
SWITCH_DECLARE(void) switch_color_set_yuv(switch_yuv_color_t *color, const char *color_str);
SWITCH_DECLARE(void) switch_color_rgb2yuv(switch_rgb_color_t *rgb, switch_yuv_color_t *yuv);
SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_create(switch_img_txt_handle_t **handleP, const char *font_family, 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); const char *font_color, const char *bgcolor, 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(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, 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, int x, int y, const char *text,
const char *font_family, const char *font_color, uint16_t font_size, double angle); const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle);
/** @} */ /** @} */
......
...@@ -376,7 +376,7 @@ typedef struct mcu_canvas_s { ...@@ -376,7 +376,7 @@ typedef struct mcu_canvas_s {
int total_layers; int total_layers;
int layers_used; int layers_used;
int layout_floor_id; int layout_floor_id;
switch_yuv_color_t bgcolor; switch_rgb_color_t bgcolor;
switch_mutex_t *mutex; switch_mutex_t *mutex;
switch_mutex_t *cond_mutex; switch_mutex_t *cond_mutex;
switch_mutex_t *cond2_mutex; switch_mutex_t *cond2_mutex;
...@@ -891,9 +891,9 @@ static int mcu_canvas_wake(mcu_canvas_t *mcu_canvas) ...@@ -891,9 +891,9 @@ static int mcu_canvas_wake(mcu_canvas_t *mcu_canvas)
return 0; return 0;
} }
static void reset_image(switch_image_t *img, switch_yuv_color_t *color) static void reset_image(switch_image_t *img, switch_rgb_color_t *color)
{ {
switch_img_fill(img, 0, 0, img->w, img->h, *color); switch_img_fill(img, 0, 0, img->w, img->h, color);
} }
#define SCALE_FACTOR 360.0f #define SCALE_FACTOR 360.0f
...@@ -1004,7 +1004,7 @@ static void scale_and_patch(conference_obj_t *conference, mcu_layer_t *layer) ...@@ -1004,7 +1004,7 @@ static void scale_and_patch(conference_obj_t *conference, mcu_layer_t *layer)
static void set_canvas_bgcolor(mcu_canvas_t *canvas, char *color) static void set_canvas_bgcolor(mcu_canvas_t *canvas, char *color)
{ {
switch_color_set(&canvas->bgcolor, color); switch_color_set_rgb(&canvas->bgcolor, color);
reset_image(canvas->img, &canvas->bgcolor); reset_image(canvas->img, &canvas->bgcolor);
} }
...@@ -1051,7 +1051,7 @@ static void detach_video_layer(conference_member_t *member) ...@@ -1051,7 +1051,7 @@ static void detach_video_layer(conference_member_t *member)
static void layer_set_banner(mcu_canvas_t *canvas, mcu_layer_t *layer, const char *text) static void layer_set_banner(mcu_canvas_t *canvas, mcu_layer_t *layer, const char *text)
{ {
switch_yuv_color_t fgcolor, bgcolor; switch_rgb_color_t fgcolor, bgcolor;
int font_scale = 4; int font_scale = 4;
int font_size = 0; int font_size = 0;
const char *fg = "#cccccc"; const char *fg = "#cccccc";
...@@ -1099,8 +1099,8 @@ static void layer_set_banner(mcu_canvas_t *canvas, mcu_layer_t *layer, const cha ...@@ -1099,8 +1099,8 @@ static void layer_set_banner(mcu_canvas_t *canvas, mcu_layer_t *layer, const cha
font_size = (double)(font_scale / 100.0f) * layer->screen_h; font_size = (double)(font_scale / 100.0f) * layer->screen_h;
switch_color_set(&fgcolor, fg); switch_color_set_rgb(&fgcolor, fg);
switch_color_set(&bgcolor, bg); switch_color_set_rgb(&bgcolor, bg);
switch_img_free(&layer->banner_img); switch_img_free(&layer->banner_img);
layer->banner_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, layer->screen_w, font_size * 2, 1); layer->banner_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, layer->screen_w, font_size * 2, 1);
...@@ -1110,10 +1110,10 @@ static void layer_set_banner(mcu_canvas_t *canvas, mcu_layer_t *layer, const cha ...@@ -1110,10 +1110,10 @@ static void layer_set_banner(mcu_canvas_t *canvas, mcu_layer_t *layer, const cha
switch_img_txt_handle_destroy(&layer->txthandle); switch_img_txt_handle_destroy(&layer->txthandle);
} }
switch_img_txt_handle_create(&layer->txthandle, font_face, fg, font_size, 0, NULL); switch_img_txt_handle_create(&layer->txthandle, font_face, fg, "#000000", font_size, 0, NULL);
reset_image(layer->banner_img, &bgcolor); reset_image(layer->banner_img, &bgcolor);
switch_img_txt_handle_render(layer->txthandle, layer->banner_img, font_size / 2, font_size / 2, text, NULL, NULL, 0, 0); switch_img_txt_handle_render(layer->txthandle, layer->banner_img, font_size / 2, font_size / 2, text, NULL, NULL, NULL, 0, 0);
if (params) switch_event_destroy(&params); if (params) switch_event_destroy(&params);
switch_safe_free(dup); switch_safe_free(dup);
...@@ -1126,7 +1126,7 @@ static switch_status_t attach_video_layer(conference_member_t *member, int idx) ...@@ -1126,7 +1126,7 @@ static switch_status_t attach_video_layer(conference_member_t *member, int idx)
const char *res_id = NULL; const char *res_id = NULL;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
const char *banner = NULL; const char *banner = NULL;
switch_yuv_color_t color; switch_rgb_color_t color;
if (!member->session) abort(); if (!member->session) abort();
...@@ -1169,8 +1169,8 @@ static switch_status_t attach_video_layer(conference_member_t *member, int idx) ...@@ -1169,8 +1169,8 @@ static switch_status_t attach_video_layer(conference_member_t *member, int idx)
} }
switch_color_set(&color, "#000000"); switch_color_set_rgb(&color, "#000000");
switch_img_fill(member->conference->canvas->img, layer->x_pos, layer->y_pos, layer->screen_w, layer->screen_h, color); switch_img_fill(member->conference->canvas->img, layer->x_pos, layer->y_pos, layer->screen_w, layer->screen_h, &color);
end: end:
...@@ -1541,19 +1541,19 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread ...@@ -1541,19 +1541,19 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
} }
} }
if (0) { if (1) {
switch_img_txt_handle_t *txthandle = NULL; switch_img_txt_handle_t *txthandle = NULL;
switch_yuv_color_t color; switch_rgb_color_t color;
switch_img_txt_handle_create(&txthandle, "/usr/share/fonts/truetype/Microsoft/Verdana.ttf", switch_img_txt_handle_create(&txthandle, "/usr/share/fonts/truetype/Microsoft/Verdana.ttf",
"#FFFFFF", 24, 0, NULL); "#FFFFFF", "#000000", 24, 0, NULL);
switch_img_txt_handle_render(txthandle, conference->canvas->img, 10, 10, "W00t this works!", NULL, NULL, 0, 0); switch_img_txt_handle_render(txthandle, conference->canvas->img, 10, 10, "W00t this works!", NULL, NULL, NULL, 0, 0);
switch_color_set(&color, "#FF0000"); switch_color_set_rgb(&color, "#FF0000");
switch_img_fill(conference->canvas->img, 300, 10, 400, 40, color); switch_img_fill(conference->canvas->img, 300, 10, 400, 40, &color);
switch_img_txt_handle_render(txthandle, conference->canvas->img, 300, 22, "W00t this works!", NULL, NULL, 0, 0); switch_img_txt_handle_render(txthandle, conference->canvas->img, 300, 22, "W00t this works!", NULL, NULL, "#FF0000", 0, 0);
switch_img_txt_handle_destroy(&txthandle); switch_img_txt_handle_destroy(&txthandle);
......
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论