diff options
Diffstat (limited to 'xc/extras/Mesa/src/pixel.c')
-rw-r--r-- | xc/extras/Mesa/src/pixel.c | 389 |
1 files changed, 265 insertions, 124 deletions
diff --git a/xc/extras/Mesa/src/pixel.c b/xc/extras/Mesa/src/pixel.c index fd42ba3a9..e70f98414 100644 --- a/xc/extras/Mesa/src/pixel.c +++ b/xc/extras/Mesa/src/pixel.c @@ -3,7 +3,7 @@ * Mesa 3-D graphics library * Version: 3.3 * - * Copyright (C) 1999 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -24,11 +24,6 @@ */ -/* - * glPixelStore, glPixelTransfer, glPixelMap, glPixelZoom, etc. - */ - - #ifdef PC_HEADER #include "all.h" #else @@ -561,6 +556,30 @@ _mesa_PixelTransferf( GLenum pname, GLfloat param ) case GL_DEPTH_BIAS: ctx->Pixel.DepthBias = param; break; + case GL_POST_COLOR_MATRIX_RED_SCALE: + ctx->Pixel.PostColorMatrixRedScale = param; + break; + case GL_POST_COLOR_MATRIX_RED_BIAS: + ctx->Pixel.PostColorMatrixRedBias = param; + break; + case GL_POST_COLOR_MATRIX_GREEN_SCALE: + ctx->Pixel.PostColorMatrixGreenScale = param; + break; + case GL_POST_COLOR_MATRIX_GREEN_BIAS: + ctx->Pixel.PostColorMatrixGreenBias = param; + break; + case GL_POST_COLOR_MATRIX_BLUE_SCALE: + ctx->Pixel.PostColorMatrixBlueScale = param; + break; + case GL_POST_COLOR_MATRIX_BLUE_BIAS: + ctx->Pixel.PostColorMatrixBlueBias = param; + break; + case GL_POST_COLOR_MATRIX_ALPHA_SCALE: + ctx->Pixel.PostColorMatrixAlphaScale = param; + break; + case GL_POST_COLOR_MATRIX_ALPHA_BIAS: + ctx->Pixel.PostColorMatrixAlphaBias = param; + break; default: gl_error( ctx, GL_INVALID_ENUM, "glPixelTransfer(pname)" ); return; @@ -575,6 +594,20 @@ _mesa_PixelTransferf( GLenum pname, GLfloat param ) else { ctx->Pixel.ScaleOrBiasRGBA = GL_FALSE; } + + if (ctx->Pixel.PostColorMatrixRedScale!=1.0F || + ctx->Pixel.PostColorMatrixRedBias!=0.0F || + ctx->Pixel.PostColorMatrixGreenScale!=1.0F || + ctx->Pixel.PostColorMatrixGreenBias!=0.0F || + ctx->Pixel.PostColorMatrixBlueScale!=1.0F || + ctx->Pixel.PostColorMatrixBlueBias!=0.0F || + ctx->Pixel.PostColorMatrixAlphaScale!=1.0F || + ctx->Pixel.PostColorMatrixAlphaBias!=0.0F) { + ctx->Pixel.ScaleOrBiasRGBApcm = GL_TRUE; + } + else { + ctx->Pixel.ScaleOrBiasRGBApcm = GL_FALSE; + } } @@ -586,60 +619,16 @@ _mesa_PixelTransferi( GLenum pname, GLint param ) - -/* - * Pixel processing functions - */ - - -/* - * Apply scale and bias factors to an array of RGBA pixels. - */ -void gl_scale_and_bias_color( const GLcontext *ctx, GLuint n, - GLfloat red[], GLfloat green[], - GLfloat blue[], GLfloat alpha[] ) -{ - GLuint i; - for (i=0;i<n;i++) { - GLfloat r = red[i] * ctx->Pixel.RedScale + ctx->Pixel.RedBias; - GLfloat g = green[i] * ctx->Pixel.GreenScale + ctx->Pixel.GreenBias; - GLfloat b = blue[i] * ctx->Pixel.BlueScale + ctx->Pixel.BlueBias; - GLfloat a = alpha[i] * ctx->Pixel.AlphaScale + ctx->Pixel.AlphaBias; - red[i] = CLAMP( r, 0.0F, 1.0F ); - green[i] = CLAMP( g, 0.0F, 1.0F ); - blue[i] = CLAMP( b, 0.0F, 1.0F ); - alpha[i] = CLAMP( a, 0.0F, 1.0F ); - } -} - - -/* - * Apply scale and bias factors to an array of RGBA pixels. - */ -void gl_scale_and_bias_rgba( const GLcontext *ctx, GLuint n, GLubyte rgba[][4] ) -{ - GLfloat rbias = ctx->Pixel.RedBias * 255.0F; - GLfloat gbias = ctx->Pixel.GreenBias * 255.0F; - GLfloat bbias = ctx->Pixel.BlueBias * 255.0F; - GLfloat abias = ctx->Pixel.AlphaBias * 255.0F; - GLuint i; - for (i=0;i<n;i++) { - GLint r = (GLint) (rgba[i][RCOMP] * ctx->Pixel.RedScale + rbias); - GLint g = (GLint) (rgba[i][GCOMP] * ctx->Pixel.GreenScale + gbias); - GLint b = (GLint) (rgba[i][BCOMP] * ctx->Pixel.BlueScale + bbias); - GLint a = (GLint) (rgba[i][ACOMP] * ctx->Pixel.AlphaScale + abias); - rgba[i][RCOMP] = CLAMP( r, 0, 255 ); - rgba[i][GCOMP] = CLAMP( g, 0, 255 ); - rgba[i][BCOMP] = CLAMP( b, 0, 255 ); - rgba[i][ACOMP] = CLAMP( a, 0, 255 ); - } -} +/**********************************************************************/ +/***** Pixel processing functions ******/ +/**********************************************************************/ /* * Apply scale and bias factors to an array of RGBA pixels. */ -void gl_scale_and_bias_rgba_float( const GLcontext *ctx, GLuint n, GLfloat rgba[][4] ) +void +_mesa_scale_and_bias_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4]) { if (ctx->Pixel.RedScale != 1.0 || ctx->Pixel.RedBias != 0.0) { const GLfloat scale = ctx->Pixel.RedScale; @@ -677,32 +666,10 @@ void gl_scale_and_bias_rgba_float( const GLcontext *ctx, GLuint n, GLfloat rgba[ /* - * Apply pixel mapping to an array of RGBA pixels. - */ -void gl_map_rgba( const GLcontext *ctx, GLuint n, GLubyte rgba[][4] ) -{ - GLfloat rscale = (ctx->Pixel.MapRtoRsize - 1) / 255.0F; - GLfloat gscale = (ctx->Pixel.MapGtoGsize - 1) / 255.0F; - GLfloat bscale = (ctx->Pixel.MapBtoBsize - 1) / 255.0F; - GLfloat ascale = (ctx->Pixel.MapAtoAsize - 1) / 255.0F; - GLuint i; - for (i=0;i<n;i++) { - GLint ir = (GLint) (rgba[i][RCOMP] * rscale); - GLint ig = (GLint) (rgba[i][GCOMP] * gscale); - GLint ib = (GLint) (rgba[i][BCOMP] * bscale); - GLint ia = (GLint) (rgba[i][ACOMP] * ascale); - rgba[i][RCOMP] = (GLint) (ctx->Pixel.MapRtoR[ir] * 255.0F); - rgba[i][GCOMP] = (GLint) (ctx->Pixel.MapGtoG[ig] * 255.0F); - rgba[i][BCOMP] = (GLint) (ctx->Pixel.MapBtoB[ib] * 255.0F); - rgba[i][ACOMP] = (GLint) (ctx->Pixel.MapAtoA[ia] * 255.0F); - } -} - - -/* * Apply pixel mapping to an array of floating point RGBA pixels. */ -void gl_map_rgba_float( const GLcontext *ctx, GLuint n, GLfloat rgba[][4] ) +void +_mesa_map_rgba( const GLcontext *ctx, GLuint n, GLfloat rgba[][4] ) { const GLfloat rscale = ctx->Pixel.MapRtoRsize - 1; const GLfloat gscale = ctx->Pixel.MapGtoGsize - 1; @@ -723,22 +690,210 @@ void gl_map_rgba_float( const GLcontext *ctx, GLuint n, GLfloat rgba[][4] ) /* - * Apply pixel mapping to an array of RGBA pixels. + * Apply the color matrix and post color matrix scaling and biasing. */ -void gl_map_color( const GLcontext *ctx, GLuint n, - GLfloat red[], GLfloat green[], - GLfloat blue[], GLfloat alpha[] ) +void +_mesa_transform_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4]) { - GLfloat rscale = ctx->Pixel.MapRtoRsize - 1; - GLfloat gscale = ctx->Pixel.MapGtoGsize - 1; - GLfloat bscale = ctx->Pixel.MapBtoBsize - 1; - GLfloat ascale = ctx->Pixel.MapAtoAsize - 1; + const GLfloat rs = ctx->Pixel.PostColorMatrixRedScale; + const GLfloat rb = ctx->Pixel.PostColorMatrixRedBias; + const GLfloat gs = ctx->Pixel.PostColorMatrixGreenScale; + const GLfloat gb = ctx->Pixel.PostColorMatrixGreenBias; + const GLfloat bs = ctx->Pixel.PostColorMatrixBlueScale; + const GLfloat bb = ctx->Pixel.PostColorMatrixBlueBias; + const GLfloat as = ctx->Pixel.PostColorMatrixAlphaScale; + const GLfloat ab = ctx->Pixel.PostColorMatrixAlphaBias; + const GLfloat *m = ctx->ColorMatrix.m; GLuint i; - for (i=0;i<n;i++) { - red[i] = ctx->Pixel.MapRtoR[ (GLint) (red[i] * rscale + 0.5F) ]; - green[i] = ctx->Pixel.MapGtoG[ (GLint) (green[i] * gscale + 0.5F) ]; - blue[i] = ctx->Pixel.MapBtoB[ (GLint) (blue[i] * bscale + 0.5F) ]; - alpha[i] = ctx->Pixel.MapAtoA[ (GLint) (alpha[i] * ascale + 0.5F) ]; + for (i = 0; i < n; i++) { + const GLfloat r = rgba[i][RCOMP]; + const GLfloat g = rgba[i][GCOMP]; + const GLfloat b = rgba[i][BCOMP]; + const GLfloat a = rgba[i][ACOMP]; + rgba[i][RCOMP] = (m[0] * r + m[4] * g + m[ 8] * b + m[12] * a) * rs + rb; + rgba[i][GCOMP] = (m[1] * r + m[5] * g + m[ 9] * b + m[13] * a) * gs + gb; + rgba[i][BCOMP] = (m[2] * r + m[6] * g + m[10] * b + m[14] * a) * bs + bb; + rgba[i][ACOMP] = (m[3] * r + m[7] * g + m[11] * b + m[15] * a) * as + ab; + } +} + + +/* + * Apply a color table lookup to an array of colors. + */ +void +_mesa_lookup_rgba(const struct gl_color_table *table, + GLuint n, GLfloat rgba[][4]) +{ + ASSERT(table->TableType == GL_FLOAT); + if (!table->Table) + return; + + switch (table->Format) { + case GL_INTENSITY: + /* replace RGBA with I */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLfloat c = lut[j] * (1.0F / 255.0F); + rgba[i][RCOMP] = rgba[i][GCOMP] = + rgba[i][BCOMP] = rgba[i][ACOMP] = c; + } + + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLfloat c = lut[j]; + rgba[i][RCOMP] = rgba[i][GCOMP] = + rgba[i][BCOMP] = rgba[i][ACOMP] = c; + } + } + break; + case GL_LUMINANCE: + /* replace RGB with L */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLfloat c = lut[j] * (1.0F / 255.0F); + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; + } + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLfloat c = lut[j]; + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = c; + } + } + break; + case GL_ALPHA: + /* replace A with A */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + rgba[i][ACOMP] = lut[j] * (1.0F / 255.0F); + } + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint j = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + rgba[i][ACOMP] = lut[j]; + } + } + break; + case GL_LUMINANCE_ALPHA: + /* replace RGBA with LLLA */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jL = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + GLfloat luminance = lut[jL * 2 + 0] * (1.0F / 255.0F); + GLfloat alpha = lut[jA * 2 + 1] * (1.0F / 255.0F); + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; + rgba[i][ACOMP] = alpha;; + } + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jL = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + GLfloat luminance = lut[jL * 2 + 0]; + GLfloat alpha = lut[jA * 2 + 1]; + rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = luminance; + rgba[i][ACOMP] = alpha;; + } + } + break; + case GL_RGB: + /* replace RGB with RGB */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F); + GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F); + rgba[i][RCOMP] = lut[jR * 3 + 0] * (1.0F / 255.0F); + rgba[i][GCOMP] = lut[jG * 3 + 1] * (1.0F / 255.0F); + rgba[i][BCOMP] = lut[jB * 3 + 2] * (1.0F / 255.0F); + } + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F); + GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F); + rgba[i][RCOMP] = lut[jR * 3 + 0]; + rgba[i][GCOMP] = lut[jG * 3 + 1]; + rgba[i][BCOMP] = lut[jB * 3 + 2]; + } + } + break; + case GL_RGBA: + /* replace RGBA with RGBA */ + if (table->TableType == GL_UNSIGNED_BYTE) { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLubyte *lut = (const GLubyte *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F); + GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F); + GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + rgba[i][RCOMP] = lut[jR * 4 + 0] * (1.0F / 255.0F); + rgba[i][GCOMP] = lut[jG * 4 + 1] * (1.0F / 255.0F); + rgba[i][BCOMP] = lut[jB * 4 + 2] * (1.0F / 255.0F); + rgba[i][ACOMP] = lut[jA * 4 + 3] * (1.0F / 255.0F); + } + } + else { + const GLfloat scale = (GLfloat) (table->Size - 1); + const GLfloat *lut = (const GLfloat *) table->Table; + GLuint i; + for (i = 0; i < n; i++) { + GLint jR = (GLint) (rgba[i][RCOMP] * scale + 0.5F); + GLint jG = (GLint) (rgba[i][GCOMP] * scale + 0.5F); + GLint jB = (GLint) (rgba[i][BCOMP] * scale + 0.5F); + GLint jA = (GLint) (rgba[i][ACOMP] * scale + 0.5F); + rgba[i][RCOMP] = lut[jR * 4 + 0]; + rgba[i][GCOMP] = lut[jG * 4 + 1]; + rgba[i][BCOMP] = lut[jB * 4 + 2]; + rgba[i][ACOMP] = lut[jA * 4 + 3]; + } + } + break; + default: + gl_problem(NULL, "Bad format in _mesa_lookup_rgba"); + return; } } @@ -747,7 +902,8 @@ void gl_map_color( const GLcontext *ctx, GLuint n, /* * Apply color index shift and offset to an array of pixels. */ -void gl_shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] ) +void +_mesa_shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] ) { GLint shift = ctx->Pixel.IndexShift; GLint offset = ctx->Pixel.IndexOffset; @@ -774,7 +930,8 @@ void gl_shift_and_offset_ci( const GLcontext *ctx, GLuint n, GLuint indexes[] ) /* * Apply color index mapping to color indexes. */ -void gl_map_ci( const GLcontext *ctx, GLuint n, GLuint index[] ) +void +_mesa_map_ci( const GLcontext *ctx, GLuint n, GLuint index[] ) { GLuint mask = ctx->Pixel.MapItoIsize - 1; GLuint i; @@ -787,8 +944,9 @@ void gl_map_ci( const GLcontext *ctx, GLuint n, GLuint index[] ) /* * Map color indexes to rgba values. */ -void gl_map_ci_to_rgba( const GLcontext *ctx, GLuint n, const GLuint index[], - GLubyte rgba[][4] ) +void +_mesa_map_ci_to_rgba_ubyte( const GLcontext *ctx, GLuint n, + const GLuint index[], GLubyte rgba[][4] ) { GLuint rmask = ctx->Pixel.MapItoRsize - 1; GLuint gmask = ctx->Pixel.MapItoGsize - 1; @@ -811,8 +969,9 @@ void gl_map_ci_to_rgba( const GLcontext *ctx, GLuint n, const GLuint index[], /* * Map color indexes to float rgba values. */ -void gl_map_ci_to_rgba_float( const GLcontext *ctx, GLuint n, const GLuint index[], - GLfloat rgba[][4] ) +void +_mesa_map_ci_to_rgba( const GLcontext *ctx, GLuint n, + const GLuint index[], GLfloat rgba[][4] ) { GLuint rmask = ctx->Pixel.MapItoRsize - 1; GLuint gmask = ctx->Pixel.MapItoGsize - 1; @@ -835,8 +994,9 @@ void gl_map_ci_to_rgba_float( const GLcontext *ctx, GLuint n, const GLuint index /* * Map 8-bit color indexes to rgb values. */ -void gl_map_ci8_to_rgba( const GLcontext *ctx, GLuint n, const GLubyte index[], - GLubyte rgba[][4] ) +void +_mesa_map_ci8_to_rgba( const GLcontext *ctx, GLuint n, const GLubyte index[], + GLubyte rgba[][4] ) { GLuint rmask = ctx->Pixel.MapItoRsize - 1; GLuint gmask = ctx->Pixel.MapItoGsize - 1; @@ -856,27 +1016,9 @@ void gl_map_ci8_to_rgba( const GLcontext *ctx, GLuint n, const GLubyte index[], } -void gl_map_ci_to_color( const GLcontext *ctx, GLuint n, const GLuint index[], - GLfloat r[], GLfloat g[], - GLfloat b[], GLfloat a[] ) -{ - GLuint rmask = ctx->Pixel.MapItoRsize - 1; - GLuint gmask = ctx->Pixel.MapItoGsize - 1; - GLuint bmask = ctx->Pixel.MapItoBsize - 1; - GLuint amask = ctx->Pixel.MapItoAsize - 1; - GLuint i; - for (i=0;i<n;i++) { - r[i] = ctx->Pixel.MapItoR[index[i] & rmask]; - g[i] = ctx->Pixel.MapItoG[index[i] & gmask]; - b[i] = ctx->Pixel.MapItoB[index[i] & bmask]; - a[i] = ctx->Pixel.MapItoA[index[i] & amask]; - } -} - - - -void gl_shift_and_offset_stencil( const GLcontext *ctx, GLuint n, - GLstencil stencil[] ) +void +_mesa_shift_and_offset_stencil( const GLcontext *ctx, GLuint n, + GLstencil stencil[] ) { GLuint i; GLint shift = ctx->Pixel.IndexShift; @@ -901,8 +1043,8 @@ void gl_shift_and_offset_stencil( const GLcontext *ctx, GLuint n, } - -void gl_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] ) +void +_mesa_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] ) { GLuint mask = ctx->Pixel.MapStoSsize - 1; GLuint i; @@ -910,4 +1052,3 @@ void gl_map_stencil( const GLcontext *ctx, GLuint n, GLstencil stencil[] ) stencil[i] = ctx->Pixel.MapStoS[ stencil[i] & mask ]; } } - |