]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7500: add yuv2rgb
authorSeven Du <dujinfang@gmail.com>
Fri, 13 Feb 2015 02:39:17 +0000 (10:39 +0800)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:01 +0000 (12:47 -0500)
src/include/switch_core_video.h
src/switch_core_video.c

index 748d658a3f68168b4b2943bdb7d2555639c7b9b7..9b31aea2123bb3fed9acc146b292f876378370ed 100644 (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_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);
index 3ee1433b70adcf3c6cb53f01268cdb42f02a6979..a1bed8cf7bc0f339a65878d7ca46f36de239df9f 100644 (file)
@@ -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 };