From 70684f4d1ba27a2815f970d8c6810ecc10fb2fd5 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Thu, 18 Aug 2011 19:49:08 -0700 Subject: [PATCH] colorspace: Add jpeg color-matrix conversion --- gst/colorspace/colorspace.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/gst/colorspace/colorspace.c b/gst/colorspace/colorspace.c index 15b6caf418..e1f6302757 100644 --- a/gst/colorspace/colorspace.c +++ b/gst/colorspace/colorspace.c @@ -1539,6 +1539,28 @@ matrix_yuv_bt470_6_to_yuv_bt709 (ColorspaceConvert * convert) } } +static void +matrix_yuv_jpeg_to_bt470_6 (ColorspaceConvert * convert) +{ + int i; + int y, u, v; + guint8 *tmpline = convert->tmpline; + + for (i = 0; i < convert->width; i++) { + y = tmpline[i * 4 + 1]; + u = tmpline[i * 4 + 2]; + v = tmpline[i * 4 + 3]; + + y = (220 * y + 16 * 256 + 128) >> 8; + //u = (261 * u + 29 * v - 4367) >> 8; + //v = (19 * u + 262 * v - 3289) >> 8; + + tmpline[i * 4 + 1] = CLAMP (y, 0, 255); + tmpline[i * 4 + 2] = CLAMP (u, 0, 255); + tmpline[i * 4 + 3] = CLAMP (v, 0, 255); + } +} + static void matrix_identity (ColorspaceConvert * convert) { @@ -1750,6 +1772,11 @@ colorspace_convert_lookup_getput (ColorspaceConvert * convert) && convert->to_spec == COLOR_SPEC_YUV_BT709) { convert->matrix = matrix_yuv_bt470_6_to_yuv_bt709; convert->matrix16 = matrix16_yuv_bt470_6_to_yuv_bt709; + } else if (convert->from_spec == COLOR_SPEC_YUV_JPEG + && convert->to_spec == COLOR_SPEC_YUV_BT470_6) { + convert->matrix = matrix_yuv_jpeg_to_bt470_6; + //convert->matrix16 = matrix16_yuv_jpeg_to_bt470_6; + convert->matrix16 = matrix16_identity; } }