From 9622af14dfe4a43f45084b560624aa44e611d8f8 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 14 Feb 2012 20:47:10 +0000 Subject: =?UTF-8?q?Backed=20out=20RGB=E2=86=92YUV=20patch=20=E2=80=93=20AP?= =?UTF-8?q?I=20change.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Anything which uses the COMPUTE_* macros would need to be recompiled because of the use of new tables. This change needs to be conditional somehow, at least externally. --- src/xine-utils/color.c | 3 +-- src/xine-utils/xineutils.h | 10 ++++------ 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/xine-utils/color.c b/src/xine-utils/color.c index 8b37134b7..3c2388c27 100644 --- a/src/xine-utils/color.c +++ b/src/xine-utils/color.c @@ -76,8 +76,7 @@ * next 9 defines. */ -/* convert full range rgb to mpeg range yuv */ -#if 0 +#if 1 #define Y_R (SCALEFACTOR * 0.29900) #define Y_G (SCALEFACTOR * 0.58700) diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 662f39467..5b16e6e3c 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -288,20 +288,18 @@ extern void (*yuy2_to_yv12) unsigned char *v_dst, int v_dst_pitch, int width, int height) XINE_PROTECTED; -/* convert full range rgb to mpeg range yuv */ -#define SCALESHIFT 16 -#define SCALEFACTOR (1<> SCALESHIFT) + 16) + ((y_r_table[r] + y_g_table[g] + y_b_table[b]) / SCALEFACTOR) #define COMPUTE_U(r, g, b) \ (unsigned char) \ - (((u_r_table[r] + u_g_table[g] + u_b_table[b]) >> SCALESHIFT) + CENTERSAMPLE) + ((u_r_table[r] + u_g_table[g] + u_b_table[b]) / SCALEFACTOR + CENTERSAMPLE) #define COMPUTE_V(r, g, b) \ (unsigned char) \ - (((v_r_table[r] + v_g_table[g] + v_b_table[b]) >> SCALESHIFT) + CENTERSAMPLE) + ((v_r_table[r] + v_g_table[g] + v_b_table[b]) / SCALEFACTOR + CENTERSAMPLE) #define UNPACK_BGR15(packed_pixel, r, g, b) \ b = (packed_pixel & 0x7C00) >> 7; \ -- cgit v1.2.3 From 061c58a5d30290c29f25044cbe9bdcf00364f333 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 15 Feb 2012 00:47:40 +0000 Subject: =?UTF-8?q?Improved=20RGB=E2=86=92YUV=20conversion=20v2=20(use=20M?= =?UTF-8?q?PEG=20range=20instead=20of=20full=20range)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Video-out plugins expect MPEG range Y'CbCr data (Y'=16..235, Cb,Cr=16..240). RGB sources (still images and audio visualisation effects) need to be converted first. This patch fixes up the range calculations and corrects an off-by-one in the range for Cb and Cr over commit 68fcd69fb3b6 (which was reverted due to API change). It should also provide a little more accuracy: I've gone back to the source (http://www.itu.int/rec/R-REC-BT.601/) for the conversion information. (We should use float or double here, but that would be an ABI change.) --- src/xine-utils/color.c | 61 +++++++++++++++++++++------------------------- src/xine-utils/xineutils.h | 3 +++ 2 files changed, 31 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/xine-utils/color.c b/src/xine-utils/color.c index 3c2388c27..3ffa790a7 100644 --- a/src/xine-utils/color.c +++ b/src/xine-utils/color.c @@ -66,51 +66,46 @@ /* * In search of the perfect colorspace conversion formulae... - * These are the conversion equations that xine currently uses: + * These are the conversion equations that xine currently uses + * (before normalisation): * * Y = 0.29900 * R + 0.58700 * G + 0.11400 * B * U = -0.16874 * R - 0.33126 * G + 0.50000 * B + 128 * V = 0.50000 * R - 0.41869 * G - 0.08131 * B + 128 - * - * Feel free to experiment with different coefficients by altering the - * next 9 defines. */ -#if 1 +/* +#define Y_R (SCALEFACTOR * 0.29900 * 219.0 / 255.0) +#define Y_G (SCALEFACTOR * 0.58700 * 219.0 / 255.0) +#define Y_B (SCALEFACTOR * 0.11400 * 219.0 / 255.0) -#define Y_R (SCALEFACTOR * 0.29900) -#define Y_G (SCALEFACTOR * 0.58700) -#define Y_B (SCALEFACTOR * 0.11400) +#define U_R (SCALEFACTOR * -0.16874 * 224.0 / 255.0) +#define U_G (SCALEFACTOR * -0.33126 * 224.0 / 255.0) +#define U_B (SCALEFACTOR * 0.50000 * 224.0 / 255.0) -#define U_R (SCALEFACTOR * -0.16874) -#define U_G (SCALEFACTOR * -0.33126) -#define U_B (SCALEFACTOR * 0.50000) +#define V_R (SCALEFACTOR * 0.50000 * 224.0 / 255.0) +#define V_G (SCALEFACTOR * -0.41869 * 224.0 / 255.0) +#define V_B (SCALEFACTOR * -0.08131 * 224.0 / 255.0) +*/ -#define V_R (SCALEFACTOR * 0.50000) -#define V_G (SCALEFACTOR * -0.41869) -#define V_B (SCALEFACTOR * -0.08131) +#define Y_R (SCALEFACTOR * 0.299 * 219.0 / 255.0) +#define Y_G (SCALEFACTOR * 0.587 * 219.0 / 255.0) +#define Y_B (SCALEFACTOR * 0.114 * 219.0 / 255.0) -#else +#define U_R (SCALEFACTOR * -0.299 / 1.772 * 224.0 / 255.0) +#define U_G (SCALEFACTOR * -0.587 / 1.772 * 224.0 / 255.0) +#define U_B (SCALEFACTOR * 0.886 / 1.772 * 224.0 / 255.0) + +#define V_R (SCALEFACTOR * 0.701 / 1.402 * 224.0 / 255.0) +#define V_G (SCALEFACTOR * -0.587 / 1.402 * 224.0 / 255.0) +#define V_B (SCALEFACTOR * -0.114 / 1.402 * 224.0 / 255.0) /* - * Here is another promising set of coefficients. If you use these, you - * must also add 16 to the Y calculation in the COMPUTE_Y macro found - * in xineutils.h. + * With the normalisation factors above, Y needs 16 added. + * This is done during setup, not in the macros in xineutils.h, because + * doing it there would be an API change. */ - -#define Y_R (SCALEFACTOR * 0.257) -#define Y_G (SCALEFACTOR * 0.504) -#define Y_B (SCALEFACTOR * 0.098) - -#define U_R (SCALEFACTOR * -0.148) -#define U_G (SCALEFACTOR * -0.291) -#define U_B (SCALEFACTOR * 0.439) - -#define V_R (SCALEFACTOR * 0.439) -#define V_G (SCALEFACTOR * -0.368) -#define V_B (SCALEFACTOR * -0.071) - -#endif +#define Y_MOD (16 * SCALEFACTOR) /* * Precalculate all of the YUV tables since it requires fewer than @@ -1317,7 +1312,7 @@ void init_yuv_conversion(void) { /* initialize the RGB -> YUV tables */ for (i = 0; i < 256; i++) { - y_r_table[i] = Y_R * i; + y_r_table[i] = Y_R * i + Y_MOD; y_g_table[i] = Y_G * i; y_b_table[i] = Y_B * i; diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 5b16e6e3c..cbf88aeaf 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -291,6 +291,9 @@ extern void (*yuy2_to_yv12) #define SCALEFACTOR 65536 #define CENTERSAMPLE 128 +/* These conversions are normalised for the MPEG Y'CbCr colourspace. + * (Yes, we know that we call it YUV elsewhere.) + */ #define COMPUTE_Y(r, g, b) \ (unsigned char) \ ((y_r_table[r] + y_g_table[g] + y_b_table[b]) / SCALEFACTOR) -- cgit v1.2.3