From c70e8cf21628cf204dda74bec70218b5cde9b827 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Fri, 13 Feb 2015 10:39:17 +0800 Subject: [PATCH] FS-7500: add yuv2rgb --- src/include/switch_core_video.h | 1 + src/switch_core_video.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h index 748d658a3f..9b31aea212 100644 --- a/src/include/switch_core_video.h +++ b/src/include/switch_core_video.h @@ -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_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_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, const char *font_color, const char *bgcolor, uint16_t font_size, double angle, switch_memory_pool_t *pool); diff --git a/src/switch_core_video.c b/src/switch_core_video.c index 3ee1433b70..a1bed8cf7b 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -78,6 +78,10 @@ SWITCH_DECLARE(void) switch_img_free(switch_image_t **img) #define MIN(a,b) ((a) < (b) ? (a) : (b)) #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 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); } +#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_rgb_color_t rgb = { 0 };