FS-7500: add yuv2rgb

This commit is contained in:
Seven Du 2015-02-13 10:39:17 +08:00 committed by Michael Jerris
parent b90ef728f3
commit c70e8cf216
2 changed files with 24 additions and 0 deletions

View File

@ -181,6 +181,7 @@ SWITCH_DECLARE(void) switch_img_draw_pixel(switch_image_t *img, int x, int y, sw
SWITCH_DECLARE(void) switch_color_set_rgb(switch_rgb_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_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(void) switch_color_rgb2yuv(switch_rgb_color_t *rgb, switch_yuv_color_t *yuv);
SWITCH_DECLARE(void) switch_color_yuv2rgb(switch_yuv_color_t *yuv, switch_rgb_color_t *rgb);
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, const char *bgcolor, 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);

View File

@ -78,6 +78,10 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img)
#define MIN(a,b) ((a) < (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif #endif
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
// simple implementation to patch a small img to a big IMG at position x,y // simple implementation to patch a small img to a big IMG at position x,y
SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y) SWITCH_DECLARE(void) switch_img_patch(switch_image_t *IMG, switch_image_t *img, int x, int y)
{ {
@ -298,6 +302,25 @@ SWITCH_DECLARE(void) switch_color_rgb2yuv(switch_rgb_color_t *rgb, switch_yuv_co
yuv->v = (uint8_t)(rgb->r / 2 -((6855 * rgb->g) >> 14) - ((rgb->b * 1337) >> 14) + 128); yuv->v = (uint8_t)(rgb->r / 2 -((6855 * rgb->g) >> 14) - ((rgb->b * 1337) >> 14) + 128);
} }
#define CLAMP(val) MAX(0, MIN(val, 255))
SWITCH_DECLARE(void) switch_color_yuv2rgb(switch_yuv_color_t *yuv, switch_rgb_color_t *rgb)
{
#if 0
int C = yuv->y - 16;
int D = yuv->u - 128;
int E = yuv->v - 128;
rgb->r = CLAMP((298 * C + 409 * E + 128) >> 8);
rgb->g = CLAMP((298 * C - 100 * D - 208 * E + 128) >> 8);
rgb->b = CLAMP((298 * C + 516 * D + 128) >> 8);
#endif
rgb->r = CLAMP( yuv->y + ((22457 * (yuv->v-128)) >> 14));
rgb->g = CLAMP((yuv->y - ((715 * (yuv->v-128)) >> 10) - ((5532 * (yuv->u-128)) >> 14)));
rgb->b = CLAMP((yuv->y + ((28384 * (yuv->u-128)) >> 14)));
}
SWITCH_DECLARE(void) switch_color_set_yuv(switch_yuv_color_t *color, const char *str) SWITCH_DECLARE(void) switch_color_set_yuv(switch_yuv_color_t *color, const char *str)
{ {
switch_rgb_color_t rgb = { 0 }; switch_rgb_color_t rgb = { 0 };