From 59720fd42a1bcaf6b31076b7c302be006d9b7bad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 6 Oct 2010 16:54:16 +0200 Subject: [PATCH] chromahold: Fix hue calculation for red colors Also make the calculation much more accurate... --- gst/coloreffects/gstchromahold.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gst/coloreffects/gstchromahold.c b/gst/coloreffects/gstchromahold.c index d2770e8..3e8c1fa 100644 --- a/gst/coloreffects/gstchromahold.c +++ b/gst/coloreffects/gstchromahold.c @@ -52,7 +52,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_chroma_hold_debug); #define DEFAULT_TARGET_R 255 #define DEFAULT_TARGET_G 0 #define DEFAULT_TARGET_B 0 -#define DEFAULT_TOLERANCE 2 +#define DEFAULT_TOLERANCE 30 enum { @@ -301,23 +301,24 @@ gst_chroma_hold_set_caps (GstBaseTransform * btrans, static inline gint rgb_to_hue (gint r, gint g, gint b) { - gint m, M, C, h; + gint m, M, C, C2, h; m = MIN (MIN (r, g), b); M = MAX (MAX (r, g), b); C = M - m; + C2 = C >> 1; if (C == 0) { return G_MAXUINT; } else if (M == r) { - h = ((g - b) / C) % 6; + h = ((256 * 60 * (g - b) + C2) / C); } else if (M == g) { - h = ((b - r) / C) + 2; - } else { /* if (M == b) */ - - h = ((r - g) / C) + 4; + h = ((256 * 60 * (b - r) + C2) / C) + 120 * 256; + } else { + /* if (M == b) */ + h = ((256 * 60 * (r - g) + C2) / C) + 240 * 256; } - h = 60 * h; + h >>= 8; if (h >= 360) h -= 360; -- 2.7.4