Search
lxdream.org :: lxdream/src/pvr2/texcache.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/texcache.c
changeset 282:01e53698ff38
prev270:1e151174ef51
next284:808617ee7135
author nkeynes
date Sun Jan 14 11:43:00 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change First cut of YUV converter
file annotate diff log raw
1.1 --- a/src/pvr2/texcache.c Thu Jan 11 06:51:11 2007 +0000
1.2 +++ b/src/pvr2/texcache.c Sun Jan 14 11:43:00 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: texcache.c,v 1.9 2007-01-11 06:51:11 nkeynes Exp $
1.6 + * $Id: texcache.c,v 1.10 2007-01-14 11:43:00 nkeynes Exp $
1.7 *
1.8 * Texture cache. Responsible for maintaining a working set of OpenGL
1.9 * textures.
1.10 @@ -280,6 +280,42 @@
1.11 }
1.12 }
1.13
1.14 +static inline uint32_t yuv_to_rgb32( float y, float u, float v )
1.15 +{
1.16 + u -= 128;
1.17 + v -= 128;
1.18 + int r = (int)(y + v*1.375);
1.19 + int g = (int)(y - u*0.34375 - v*0.6875);
1.20 + int b = (int)(y + u*1.71875);
1.21 + if( r > 255 ) { r = 255; } else if( r < 0 ) { r = 0; }
1.22 + if( g > 255 ) { g = 255; } else if( g < 0 ) { g = 0; }
1.23 + if( b > 255 ) { b = 255; } else if( b < 0 ) { b = 0; }
1.24 + return 0xFF000000 | (r<<24) | (g<<16) | (b<<16);
1.25 +}
1.26 +
1.27 +
1.28 +/**
1.29 + * Convert non-twiddled YUV texture data into RGB32 data - most GL implementations don't
1.30 + * directly support this format unfortunately. The input data is formatted as
1.31 + * 32 bits = 2 horizontal pixels, UYVY. This is currently done rather inefficiently
1.32 + * in floating point.
1.33 + */
1.34 +static void yuv_decode( int width, int height, uint32_t *input, uint32_t *output )
1.35 +{
1.36 + int x, y;
1.37 + uint32_t *p = input;
1.38 + for( y=0; y<height; y++ ) {
1.39 + for( x=0; x<width; x+=2 ) {
1.40 + float u = (float)(*p & 0xFF);
1.41 + float y0 = (float)( (*p>>8)&0xFF );
1.42 + float v = (float)( (*p>>16)&0xFF );
1.43 + float y1 = (float)( (*p>>24)&0xFF );
1.44 + *output++ = yuv_to_rgb32( y0, u, v );
1.45 + *output++ = yuv_to_rgb32( y1, u, v );
1.46 + }
1.47 + }
1.48 +}
1.49 +
1.50 /**
1.51 * Load texture data from the given address and parameters into the currently
1.52 * bound OpenGL texture.
1.53 @@ -343,7 +379,10 @@
1.54 type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
1.55 break;
1.56 case PVR2_TEX_FORMAT_YUV422:
1.57 - ERROR( "YUV textures not supported" );
1.58 + bytes <<= 2;
1.59 + intFormat = GL_RGBA8;
1.60 + format = GL_BGRA;
1.61 + type = GL_UNSIGNED_INT_8_8_8_8_REV;
1.62 break;
1.63 case PVR2_TEX_FORMAT_BUMPMAP:
1.64 ERROR( "Bumpmap not supported" );
1.65 @@ -385,6 +424,11 @@
1.66 detwiddle_pal8_to_16( 0, 0, mip_width, mip_width, &p,
1.67 (uint16_t *)data, (uint16_t *)palette );
1.68 }
1.69 + } else if( tex_format == PVR2_TEX_FORMAT_YUV422 ) {
1.70 + int inputlength = ((mip_width*mip_height)<<1);
1.71 + char tmp[inputlength];
1.72 + pvr2_vram64_read( tmp, texture_addr, inputlength );
1.73 + yuv_decode( mip_width, mip_height, tmp, (uint32_t *)&data );
1.74 } else if( PVR2_TEX_IS_COMPRESSED(mode) ) {
1.75 int inputlength = ((mip_width*mip_height) >> 2);
1.76 char tmp[inputlength];
.