tests: image: fix conversion from RGB to YUV.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Fri, 23 Aug 2013 14:25:39 +0000 (16:25 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Fri, 23 Aug 2013 17:00:37 +0000 (19:00 +0200)
Fix RGB to YUV conversion to preserve full data range.

tests/image.c

index 3abcaf8..361874c 100644 (file)
@@ -276,9 +276,9 @@ static inline guint32 argb2yuv(guint32 color)
     const gint32 g = (color >>  8) & 0xff;
     const gint32 b = (color      ) & 0xff;
 
-    const guint32 y = (( 263 * r + 516 * g + 100 * b) >> 10) +  16;
-    const guint32 u = ((-152 * r - 298 * g + 450 * b) >> 10) + 128;
-    const guint32 v = (( 450 * r - 376 * g -  73 * b) >> 10) + 128;
+    const guint32 y = (( 306 * r + 601 * g + 116 * b) >> 10);
+    const guint32 u = ((-172 * r - 339 * g + 512 * b) >> 10) + 128;
+    const guint32 v = (( 512 * r - 428 * g -  83 * b) >> 10) + 128;
 
     return (y << 16) | (u << 8) | v;
 }