From: Wim Taymans Date: Mon, 4 Jun 2012 14:13:48 +0000 (+0200) Subject: videoconvert: fix 0_255 handling X-Git-Tag: 1.19.3~511^2~6386 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=93c3a747557100dd7f59bb4061253d8a13a4e4a1;p=platform%2Fupstream%2Fgstreamer.git videoconvert: fix 0_255 handling We also need to apply an offset to the Cb and Cr samples in the 0-255 case. --- diff --git a/gst/videoconvert/videoconvert.c b/gst/videoconvert/videoconvert.c index 8afba95..76d5ab4 100644 --- a/gst/videoconvert/videoconvert.c +++ b/gst/videoconvert/videoconvert.c @@ -221,18 +221,38 @@ videoconvert_convert_compute_matrix (VideoConvert * convert) else use_16 = FALSE; - color_matrix_set_identity (&dst); /* 1, bring color components to [0..1.0] range */ switch (in_info->colorimetry.range) { case GST_VIDEO_COLOR_RANGE_0_255: - if (use_16) - color_matrix_scale_components (&dst, (1 / 65535.0), (1 / 65535.0), - (1 / 65535.0)); - else - color_matrix_scale_components (&dst, (1 / 255.0), (1 / 255.0), - (1 / 255.0)); + switch (in_info->finfo->unpack_format) { + case GST_VIDEO_FORMAT_AYUV: + case GST_VIDEO_FORMAT_AYUV64: + GST_DEBUG ("using 0-255 input range YUV"); + if (use_16) { + color_matrix_offset_components (&dst, 0, -32768, -32768); + color_matrix_scale_components (&dst, (1 / 65535.0), (1 / 65535.0), + (1 / 65535.0)); + } else { + color_matrix_offset_components (&dst, 0, -128, -128); + color_matrix_scale_components (&dst, (1 / 255.0), (1 / 255.0), + (1 / 255.0)); + } + break; + case GST_VIDEO_FORMAT_ARGB: + case GST_VIDEO_FORMAT_ARGB64: + GST_DEBUG ("using 0-255 input range RGB"); + if (use_16) + color_matrix_scale_components (&dst, (1 / 65535.0), (1 / 65535.0), + (1 / 65535.0)); + else + color_matrix_scale_components (&dst, (1 / 255.0), (1 / 255.0), + (1 / 255.0)); + break; + default: + break; + } break; default: case GST_VIDEO_COLOR_RANGE_16_235: @@ -240,6 +260,7 @@ videoconvert_convert_compute_matrix (VideoConvert * convert) switch (in_info->finfo->unpack_format) { case GST_VIDEO_FORMAT_AYUV: case GST_VIDEO_FORMAT_AYUV64: + GST_DEBUG ("using 16-235 input range YUV"); if (use_16) { color_matrix_offset_components (&dst, -4096, -32768, -32768); color_matrix_scale_components (&dst, (1 / 56064.0), (1 / 57344.0), @@ -252,6 +273,7 @@ videoconvert_convert_compute_matrix (VideoConvert * convert) break; case GST_VIDEO_FORMAT_ARGB: case GST_VIDEO_FORMAT_ARGB64: + GST_DEBUG ("using 16-235 input range RGB"); if (use_16) { color_matrix_offset_components (&dst, -4096, -4096, -4096); color_matrix_scale_components (&dst, (1 / 56064.0), (1 / 56064.0), @@ -316,6 +338,31 @@ videoconvert_convert_compute_matrix (VideoConvert * convert) /* 8, bring color components to nominal range */ switch (out_info->colorimetry.range) { case GST_VIDEO_COLOR_RANGE_0_255: + switch (out_info->finfo->unpack_format) { + case GST_VIDEO_FORMAT_AYUV: + case GST_VIDEO_FORMAT_AYUV64: + GST_DEBUG ("using 0-255 output range YUV"); + if (use_16) { + color_matrix_scale_components (&dst, 65535.0, 65535.0, 65535.0); + color_matrix_offset_components (&dst, 0, 32768, 32768); + } else { + color_matrix_scale_components (&dst, 255.0, 255.0, 255.0); + color_matrix_offset_components (&dst, 0, 128, 128); + } + break; + case GST_VIDEO_FORMAT_ARGB: + case GST_VIDEO_FORMAT_ARGB64: + GST_DEBUG ("using 0-255 output range RGB"); + if (use_16) + color_matrix_scale_components (&dst, 65535.0, 65535.0, 65535.0); + else + color_matrix_scale_components (&dst, 255.0, 255.0, 255.0); + break; + default: + break; + } + break; + GST_DEBUG ("using 0-255 output range"); if (use_16) color_matrix_scale_components (&dst, 65535.0, 65535.0, 65535.0); else @@ -326,6 +373,7 @@ videoconvert_convert_compute_matrix (VideoConvert * convert) switch (out_info->finfo->unpack_format) { case GST_VIDEO_FORMAT_AYUV: case GST_VIDEO_FORMAT_AYUV64: + GST_DEBUG ("using 16-235 output range YUV"); if (use_16) { color_matrix_scale_components (&dst, 56064.0, 57344.0, 57344.0); color_matrix_offset_components (&dst, 4096, 32768, 32768); @@ -336,6 +384,7 @@ videoconvert_convert_compute_matrix (VideoConvert * convert) break; case GST_VIDEO_FORMAT_ARGB: case GST_VIDEO_FORMAT_ARGB64: + GST_DEBUG ("using 16-235 output range RGB"); if (use_16) { color_matrix_scale_components (&dst, 56064.0, 56064.0, 56064.0); color_matrix_offset_components (&dst, 4096, 4096, 4096);