summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-03-09 20:51:21 -0600
committerBrian Paul <[email protected]>2009-04-01 20:24:22 -0600
commitefe3d10aea305c89e66decfb5a9012feb7a4695c (patch)
treea61c5fadaf4983cc3c318b21ff4ddb5d66d82a32 /src/mesa/main
parent611128365dad65216a4d4be973393ba2c526bd18 (diff)
mesa: simplify ycbcr->rgb conversion code
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/texformat_tmp.h46
1 files changed, 14 insertions, 32 deletions
diff --git a/src/mesa/main/texformat_tmp.h b/src/mesa/main/texformat_tmp.h
index f98e8576294..d0d38046082 100644
--- a/src/mesa/main/texformat_tmp.h
+++ b/src/mesa/main/texformat_tmp.h
@@ -1334,9 +1334,9 @@ static void store_texel_signed_rgba8888_rev(struct gl_texture_image *texImage,
/* MESA_FORMAT_YCBCR *********************************************************/
-/* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
-/* We convert YCbCr to RGB here */
-/* XXX this may break if GLchan != GLubyte */
+/* Fetch texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats.
+ * We convert YCbCr to RGB here.
+ */
static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
@@ -1346,19 +1346,10 @@ static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
const GLubyte cb = *src0 & 0xff; /* chroma U */
const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
const GLubyte cr = *src1 & 0xff; /* chroma V */
- GLfloat r, g, b;
- if (i & 1) {
- /* odd pixel: use y1,cr,cb */
- r = 1.164 * (y1-16) + 1.596 * (cr-128);
- g = 1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128);
- b = 1.164 * (y1-16) + 2.018 * (cb-128);
- }
- else {
- /* even pixel: use y0,cr,cb */
- r = 1.164 * (y0-16) + 1.596 * (cr-128);
- g = 1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128);
- b = 1.164 * (y0-16) + 2.018 * (cb-128);
- }
+ const GLfloat y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
+ GLfloat r = 1.164 * (y - 16) + 1.596 * (cr - 128);
+ GLfloat g = 1.164 * (y - 16) - 0.813 * (cr - 128) - 0.391 * (cb - 128);
+ GLfloat b = 1.164 * (y - 16) + 2.018 * (cb - 128);
r *= (1.0 / 255.0F);
g *= (1.0 / 255.0F);
b *= (1.0 / 255.0F);
@@ -1384,9 +1375,9 @@ static void store_texel_ycbcr(struct gl_texture_image *texImage,
/* MESA_FORMAT_YCBCR_REV *****************************************************/
-/* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
-/* We convert YCbCr to RGB here */
-/* XXX this may break if GLchan != GLubyte */
+/* Fetch texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats.
+ * We convert YCbCr to RGB here.
+ */
static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
GLint i, GLint j, GLint k, GLfloat *texel )
{
@@ -1396,19 +1387,10 @@ static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
const GLubyte y1 = *src1 & 0xff; /* luminance */
const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
- GLfloat r, g, b;
- if (i & 1) {
- /* odd pixel: use y1,cr,cb */
- r = 1.164 * (y1-16) + 1.596 * (cr-128);
- g = 1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128);
- b = 1.164 * (y1-16) + 2.018 * (cb-128);
- }
- else {
- /* even pixel: use y0,cr,cb */
- r = 1.164 * (y0-16) + 1.596 * (cr-128);
- g = 1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128);
- b = 1.164 * (y0-16) + 2.018 * (cb-128);
- }
+ const GLfloat y = (i & 1) ? y1 : y0; /* choose even/odd luminance */
+ GLfloat r = 1.164 * (y - 16) + 1.596 * (cr - 128);
+ GLfloat g = 1.164 * (y - 16) - 0.813 * (cr - 128) - 0.391 * (cb - 128);
+ GLfloat b = 1.164 * (y - 16) + 2.018 * (cb - 128);
r *= (1.0 / 255.0F);
g *= (1.0 / 255.0F);
b *= (1.0 / 255.0F);