summaryrefslogtreecommitdiff
path: root/xc/extras/Mesa/src/texutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'xc/extras/Mesa/src/texutil.c')
-rw-r--r--xc/extras/Mesa/src/texutil.c184
1 files changed, 141 insertions, 43 deletions
diff --git a/xc/extras/Mesa/src/texutil.c b/xc/extras/Mesa/src/texutil.c
index bf9285a7e..38f4f7fae 100644
--- a/xc/extras/Mesa/src/texutil.c
+++ b/xc/extras/Mesa/src/texutil.c
@@ -26,6 +26,14 @@
* Gareth Hughes <gareth@valinux.com>
*/
+/*
+ * Description:
+ * Functions for texture image conversion. This takes care of converting
+ * typical GL_RGBA/GLubyte textures into hardware-specific formats.
+ * We can handle non-standard row strides and pixel unpacking parameters.
+ */
+
+
#ifdef PC_HEADER
#include "all.h"
#else
@@ -50,7 +58,7 @@
#endif
-struct gl_texture_convert {
+struct convert_info {
GLint xoffset, yoffset, zoffset; /* Subimage offset */
GLint width, height, depth; /* Subimage region */
@@ -66,15 +74,16 @@ struct gl_texture_convert {
GLint index;
};
-typedef GLboolean (*convert_func)( struct gl_texture_convert *convert );
+typedef GLboolean (*convert_func)( const struct convert_info *convert );
+/* bitvalues for convert->index */
#define CONVERT_STRIDE_BIT 0x1
#define CONVERT_UNPACKING_BIT 0x2
/* =============================================================
- * RGBA8888 textures:
+ * Convert to RGBA8888 textures:
*/
#define DST_TYPE GLuint
@@ -117,7 +126,7 @@ typedef GLboolean (*convert_func)( struct gl_texture_convert *convert );
#define CONVERT_RGBA8888( name ) \
static GLboolean \
-convert_##name##_rgba8888( struct gl_texture_convert *convert ) \
+convert_##name##_rgba8888( const struct convert_info *convert ) \
{ \
convert_func *tab; \
GLint index = convert->index; \
@@ -153,7 +162,7 @@ CONVERT_RGBA8888( texsubimage3d )
/* =============================================================
- * ARGB8888 textures:
+ * Convert to ARGB8888 textures:
*/
#define DST_TYPE GLuint
@@ -196,7 +205,7 @@ CONVERT_RGBA8888( texsubimage3d )
#define CONVERT_ARGB8888( name ) \
static GLboolean \
-convert_##name##_argb8888( struct gl_texture_convert *convert ) \
+convert_##name##_argb8888( const struct convert_info *convert ) \
{ \
convert_func *tab; \
GLint index = convert->index; \
@@ -231,11 +240,11 @@ CONVERT_ARGB8888( texsubimage3d )
/* =============================================================
- * RGB888 textures:
+ * Convert to RGB888 textures:
*/
static GLboolean
-convert_texsubimage2d_rgb888( struct gl_texture_convert *convert )
+convert_texsubimage2d_rgb888( const struct convert_info *convert )
{
/* This is a placeholder for now...
*/
@@ -243,7 +252,7 @@ convert_texsubimage2d_rgb888( struct gl_texture_convert *convert )
}
static GLboolean
-convert_texsubimage3d_rgb888( struct gl_texture_convert *convert )
+convert_texsubimage3d_rgb888( const struct convert_info *convert )
{
/* This is a placeholder for now...
*/
@@ -253,7 +262,7 @@ convert_texsubimage3d_rgb888( struct gl_texture_convert *convert )
/* =============================================================
- * RGB565 textures:
+ * Convert to RGB565 textures:
*/
#define DST_TYPE GLushort
@@ -300,7 +309,7 @@ convert_texsubimage3d_rgb888( struct gl_texture_convert *convert )
#define CONVERT_RGB565( name ) \
static GLboolean \
-convert_##name##_rgb565( struct gl_texture_convert *convert ) \
+convert_##name##_rgb565( const struct convert_info *convert ) \
{ \
convert_func *tab; \
GLint index = convert->index; \
@@ -335,7 +344,7 @@ CONVERT_RGB565( texsubimage3d )
/* =============================================================
- * ARGB4444 textures:
+ * Convert to ARGB4444 textures:
*/
#define DST_TYPE GLushort
@@ -368,7 +377,7 @@ CONVERT_RGB565( texsubimage3d )
#define CONVERT_ARGB4444( name ) \
static GLboolean \
-convert_##name##_argb4444( struct gl_texture_convert *convert ) \
+convert_##name##_argb4444( const struct convert_info *convert ) \
{ \
convert_func *tab; \
GLint index = convert->index; \
@@ -398,7 +407,7 @@ CONVERT_ARGB4444( texsubimage3d )
/* =============================================================
- * ARGB1555 textures:
+ * Convert to ARGB1555 textures:
*/
#define DST_TYPE GLushort
@@ -462,7 +471,7 @@ CONVERT_ARGB4444( texsubimage3d )
#define CONVERT_ARGB1555( name ) \
static GLboolean \
-convert_##name##_argb1555( struct gl_texture_convert *convert ) \
+convert_##name##_argb1555( const struct convert_info *convert ) \
{ \
convert_func *tab; \
GLint index = convert->index; \
@@ -497,7 +506,7 @@ CONVERT_ARGB1555( texsubimage3d )
/* =============================================================
- * AL88 textures:
+ * Conver to AL88 textures:
*/
#define DST_TYPE GLushort
@@ -519,7 +528,7 @@ CONVERT_ARGB1555( texsubimage3d )
dst = PACK_COLOR_88_LE( src[0], 0x00 )
#define CONVERT_TEXEL_DWORD( dst, src ) \
- dst = APPEND16( PACK_COLOR_88_LE( src[0], 0x00 ), \
+ dst = APPEND16( PACK_COLOR_88_LE( src[0], 0x00 ), \
PACK_COLOR_88_LE( src[1], 0x00 ) )
#define SRC_TEXEL_BYTES 1
@@ -558,7 +567,7 @@ CONVERT_ARGB1555( texsubimage3d )
#define CONVERT_AL88( name ) \
static GLboolean \
-convert_##name##_al88( struct gl_texture_convert *convert ) \
+convert_##name##_al88( const struct convert_info *convert ) \
{ \
convert_func *tab; \
GLint index = convert->index; \
@@ -598,11 +607,11 @@ CONVERT_AL88( texsubimage3d )
/* =============================================================
- * RGB332 textures:
+ * Convert to RGB332 textures:
*/
static GLboolean
-convert_texsubimage2d_rgb332( struct gl_texture_convert *convert )
+convert_texsubimage2d_rgb332( const struct convert_info *convert )
{
/* This is a placeholder for now...
*/
@@ -610,7 +619,7 @@ convert_texsubimage2d_rgb332( struct gl_texture_convert *convert )
}
static GLboolean
-convert_texsubimage3d_rgb332( struct gl_texture_convert *convert )
+convert_texsubimage3d_rgb332( const struct convert_info *convert )
{
/* This is a placeholder for now...
*/
@@ -620,7 +629,7 @@ convert_texsubimage3d_rgb332( struct gl_texture_convert *convert )
/* =============================================================
- * CI8 (and all other single-byte texel) textures:
+ * Convert to CI8 (and all other single-byte texel) textures:
*/
#define DST_TYPE GLubyte
@@ -638,7 +647,7 @@ convert_texsubimage3d_rgb332( struct gl_texture_convert *convert )
#define CONVERT_CI8( name ) \
static GLboolean \
-convert_##name##_ci8( struct gl_texture_convert *convert ) \
+convert_##name##_ci8( const struct convert_info *convert ) \
{ \
convert_func *tab; \
GLint index = convert->index; \
@@ -664,12 +673,88 @@ CONVERT_CI8( texsubimage2d )
CONVERT_CI8( texsubimage3d )
+/* =============================================================
+ * convert to YCBCR textures:
+ */
+
+#define DST_TYPE GLushort
+#define DST_TEXELS_PER_DWORD 2
+
+#define CONVERT_TEXEL( dst, src ) \
+ dst = (src[0] << 8) | src[1];
+
+#define CONVERT_DIRECT
+
+#define SRC_TEXEL_BYTES 2
+
+#define TAG(x) x##_ycbcr_direct
+#include "texutil_tmp.h"
+
+
+#define CONVERT_YCBCR( name ) \
+static GLboolean \
+convert_##name##_ycbcr( const struct convert_info *convert ) \
+{ \
+ convert_func *tab; \
+ GLint index = convert->index; \
+ \
+ if (convert->format != GL_YCBCR_MESA) { \
+ /* Can't handle this source format/type combination */ \
+ return GL_FALSE; \
+ } \
+ tab = name##_tab_ycbcr_direct; \
+ \
+ return tab[index]( convert ); \
+}
+
+CONVERT_YCBCR( texsubimage2d )
+CONVERT_YCBCR( texsubimage3d )
+
+
+/* =============================================================
+ * convert to YCBCR_REV textures:
+ */
+
+#define DST_TYPE GLushort
+#define DST_TEXELS_PER_DWORD 2
+
+#define CONVERT_TEXEL( dst, src ) \
+ dst = (src[1] << 8) | src[0];
+
+#define CONVERT_DIRECT
+
+#define SRC_TEXEL_BYTES 2
+
+#define TAG(x) x##_ycbcr_rev_direct
+#include "texutil_tmp.h"
+
+
+#define CONVERT_YCBCR_REV( name ) \
+static GLboolean \
+convert_##name##_ycbcr_rev( const struct convert_info *convert ) \
+{ \
+ convert_func *tab; \
+ GLint index = convert->index; \
+ \
+ if (convert->format != GL_YCBCR_MESA) { \
+ /* Can't handle this source format/type combination */ \
+ return GL_FALSE; \
+ } \
+ tab = name##_tab_ycbcr_rev_direct; \
+ \
+ return tab[index]( convert ); \
+}
+
+CONVERT_YCBCR_REV( texsubimage2d )
+CONVERT_YCBCR_REV( texsubimage3d )
+
+
/* =============================================================
- * Global entry points
+ * Tables of texture conversion/packing functions.
*/
-static convert_func gl_convert_texsubimage2d_tab[] = {
+static convert_func convert_texsubimage2d_table[] = {
convert_texsubimage2d_rgba8888,
convert_texsubimage2d_argb8888,
convert_texsubimage2d_rgb888,
@@ -682,9 +767,11 @@ static convert_func gl_convert_texsubimage2d_tab[] = {
convert_texsubimage2d_ci8,
convert_texsubimage2d_ci8,
convert_texsubimage2d_ci8,
+ convert_texsubimage2d_ycbcr,
+ convert_texsubimage2d_ycbcr_rev,
};
-static convert_func gl_convert_texsubimage3d_tab[] = {
+static convert_func convert_texsubimage3d_table[] = {
convert_texsubimage3d_rgba8888,
convert_texsubimage3d_argb8888,
convert_texsubimage3d_rgb888,
@@ -697,6 +784,8 @@ static convert_func gl_convert_texsubimage3d_tab[] = {
convert_texsubimage3d_ci8,
convert_texsubimage3d_ci8,
convert_texsubimage3d_ci8,
+ convert_texsubimage3d_ycbcr,
+ convert_texsubimage3d_ycbcr_rev,
};
@@ -727,21 +816,21 @@ convert_needs_unpacking( const struct gl_pixelstore_attrib *unpacking,
GLboolean
-_mesa_convert_texsubimage1d( GLint mesaFormat,
+_mesa_convert_texsubimage1d( GLint mesaFormat, /* dest */
GLint xoffset,
GLint width,
- GLenum format, GLenum type,
+ GLenum format, GLenum type, /* source */
const struct gl_pixelstore_attrib *unpacking,
const GLvoid *srcImage, GLvoid *dstImage )
{
- struct gl_texture_convert convert;
+ struct convert_info convert;
ASSERT( unpacking );
ASSERT( srcImage );
ASSERT( dstImage );
ASSERT( mesaFormat >= MESA_FORMAT_RGBA8888 );
- ASSERT( mesaFormat <= MESA_FORMAT_CI8 );
+ ASSERT( mesaFormat <= MESA_FORMAT_YCBCR_REV );
/* Make it easier to pass all the parameters around.
*/
@@ -760,7 +849,9 @@ _mesa_convert_texsubimage1d( GLint mesaFormat,
if ( convert_needs_unpacking( unpacking, format, type ) )
convert.index |= CONVERT_UNPACKING_BIT;
- return gl_convert_texsubimage2d_tab[mesaFormat]( &convert );
+ ASSERT(convert.index < 4);
+
+ return convert_texsubimage2d_table[mesaFormat]( &convert );
}
@@ -790,22 +881,22 @@ _mesa_convert_texsubimage1d( GLint mesaFormat,
* destImage - pointer to dest image
*/
GLboolean
-_mesa_convert_texsubimage2d( GLint mesaFormat,
+_mesa_convert_texsubimage2d( GLint mesaFormat, /* dest */
GLint xoffset, GLint yoffset,
GLint width, GLint height,
GLint destImageWidth,
- GLenum format, GLenum type,
+ GLenum format, GLenum type, /* source */
const struct gl_pixelstore_attrib *unpacking,
const GLvoid *srcImage, GLvoid *dstImage )
{
- struct gl_texture_convert convert;
+ struct convert_info convert;
ASSERT( unpacking );
ASSERT( srcImage );
ASSERT( dstImage );
ASSERT( mesaFormat >= MESA_FORMAT_RGBA8888 );
- ASSERT( mesaFormat <= MESA_FORMAT_CI8 );
+ ASSERT( mesaFormat <= MESA_FORMAT_YCBCR_REV );
/* Make it easier to pass all the parameters around.
*/
@@ -814,8 +905,8 @@ _mesa_convert_texsubimage2d( GLint mesaFormat,
convert.width = width;
convert.height = height;
convert.dstImageWidth = destImageWidth;
- convert.format = format;
- convert.type = type;
+ convert.format = format; /* src */
+ convert.type = type; /* src */
convert.unpacking = unpacking;
convert.srcImage = srcImage;
convert.dstImage = dstImage;
@@ -828,26 +919,31 @@ _mesa_convert_texsubimage2d( GLint mesaFormat,
if ( width != destImageWidth )
convert.index |= CONVERT_STRIDE_BIT;
- return gl_convert_texsubimage2d_tab[mesaFormat]( &convert );
+ ASSERT(convert.index < 4);
+
+ ASSERT(mesaFormat < sizeof(convert_texsubimage2d_table) /
+ sizeof(convert_texsubimage2d_table[0]));
+
+ return convert_texsubimage2d_table[mesaFormat]( &convert );
}
GLboolean
-_mesa_convert_texsubimage3d( GLint mesaFormat,
+_mesa_convert_texsubimage3d( GLint mesaFormat, /* dest */
GLint xoffset, GLint yoffset, GLint zoffset,
GLint width, GLint height, GLint depth,
GLint dstImageWidth, GLint dstImageHeight,
- GLenum format, GLenum type,
+ GLenum format, GLenum type, /* source */
const struct gl_pixelstore_attrib *unpacking,
const GLvoid *srcImage, GLvoid *dstImage )
{
- struct gl_texture_convert convert;
+ struct convert_info convert;
ASSERT( unpacking );
ASSERT( srcImage );
ASSERT( dstImage );
ASSERT( mesaFormat >= MESA_FORMAT_RGBA8888 );
- ASSERT( mesaFormat <= MESA_FORMAT_CI8 );
+ ASSERT( mesaFormat <= MESA_FORMAT_YCBCR_REV );
/* Make it easier to pass all the parameters around.
*/
@@ -873,7 +969,9 @@ _mesa_convert_texsubimage3d( GLint mesaFormat,
if ( width != dstImageWidth || height != dstImageHeight )
convert.index |= CONVERT_STRIDE_BIT;
- return gl_convert_texsubimage3d_tab[mesaFormat]( &convert );
+ ASSERT(convert.index < 4);
+
+ return convert_texsubimage3d_table[mesaFormat]( &convert );
}