replace color table FloatTable boolean with Type enum
[mesa.git] / src / mesa / main / pixel.c
index b6fe7b2123a5ad8eb6367868a156890d9e49e077..f211af91703b0a605cf2cfda2686d90f7d80a8c6 100644 (file)
@@ -1,10 +1,9 @@
-/* $Id: pixel.c,v 1.32 2001/12/04 23:45:31 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  5.1
  *
- * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2003  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"),
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-
-#ifdef PC_HEADER
-#include "all.h"
-#else
 #include "glheader.h"
+#include "imports.h"
 #include "colormac.h"
 #include "context.h"
 #include "macros.h"
-#include "mem.h"
 #include "pixel.h"
 #include "mtypes.h"
-#endif
-
 
 
 /**********************************************************************/
@@ -45,7 +38,7 @@
 
 
 
-void
+void GLAPIENTRY
 _mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -66,7 +59,7 @@ _mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
 /**********************************************************************/
 
 
-void
+void GLAPIENTRY
 _mesa_PixelStorei( GLenum pname, GLint param )
 {
    /* NOTE: this call can't be compiled into the display list */
@@ -146,6 +139,17 @@ _mesa_PixelStorei( GLenum pname, GLint param )
         FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
         ctx->Pack.Alignment = param;
         break;
+      case GL_PACK_INVERT_MESA:
+         if (!ctx->Extensions.MESA_pack_invert) {
+            _mesa_error( ctx, GL_INVALID_ENUM, "glPixelstore(pname)" );
+            return;
+         }
+         if (ctx->Pack.Invert == param)
+            return;
+         FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
+         ctx->Pack.Invert = param;
+         break;
+
       case GL_UNPACK_SWAP_BYTES:
         if (param == (GLint)ctx->Unpack.SwapBytes)
            return;
@@ -223,6 +227,12 @@ _mesa_PixelStorei( GLenum pname, GLint param )
         FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
         ctx->Unpack.Alignment = param;
         break;
+      case GL_UNPACK_CLIENT_STORAGE_APPLE:
+         if (param == (GLint)ctx->Unpack.ClientStorage)
+            return;
+         FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
+         ctx->Unpack.ClientStorage = param ? GL_TRUE : GL_FALSE;
+         break;
       default:
         _mesa_error( ctx, GL_INVALID_ENUM, "glPixelStore" );
         return;
@@ -230,7 +240,7 @@ _mesa_PixelStorei( GLenum pname, GLint param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelStoref( GLenum pname, GLfloat param )
 {
    _mesa_PixelStorei( pname, (GLint) param );
@@ -244,19 +254,19 @@ _mesa_PixelStoref( GLenum pname, GLfloat param )
 
 
 
-void
-_mesa_PixelMapfv( GLenum map, GLint mapsize, const GLfloat *values )
+void GLAPIENTRY
+_mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
 {
    GLint i;
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (mapsize<0 || mapsize>MAX_PIXEL_MAP_TABLE) {
+   if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
       return;
    }
 
-   if (map>=GL_PIXEL_MAP_S_TO_S && map<=GL_PIXEL_MAP_I_TO_A) {
+   if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
       /* test that mapsize is a power of two */
       if (_mesa_bitcount((GLuint) mapsize) != 1) {
         _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
@@ -342,8 +352,8 @@ _mesa_PixelMapfv( GLenum map, GLint mapsize, const GLfloat *values )
 
 
 
-void
-_mesa_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values )
+void GLAPIENTRY
+_mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
 {
    const GLint n = MIN2(mapsize, MAX_PIXEL_MAP_TABLE);
    GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
@@ -363,8 +373,8 @@ _mesa_PixelMapuiv(GLenum map, GLint mapsize, const GLuint *values )
 
 
 
-void
-_mesa_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values )
+void GLAPIENTRY
+_mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
 {
    const GLint n = MIN2(mapsize, MAX_PIXEL_MAP_TABLE);
    GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
@@ -384,7 +394,7 @@ _mesa_PixelMapusv(GLenum map, GLint mapsize, const GLushort *values )
 
 
 
-void
+void GLAPIENTRY
 _mesa_GetPixelMapfv( GLenum map, GLfloat *values )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -432,7 +442,7 @@ _mesa_GetPixelMapfv( GLenum map, GLfloat *values )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetPixelMapuiv( GLenum map, GLuint *values )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -492,7 +502,7 @@ _mesa_GetPixelMapuiv( GLenum map, GLuint *values )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_GetPixelMapusv( GLenum map, GLushort *values )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -566,7 +576,7 @@ _mesa_GetPixelMapusv( GLenum map, GLushort *values )
  * Implements glPixelTransfer[fi] whether called immediately or from a
  * display list.
  */
-void
+void GLAPIENTRY
 _mesa_PixelTransferf( GLenum pname, GLfloat param )
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -760,14 +770,12 @@ _mesa_PixelTransferf( GLenum pname, GLfloat param )
 }
 
 
-void
+void GLAPIENTRY
 _mesa_PixelTransferi( GLenum pname, GLint param )
 {
    _mesa_PixelTransferf( pname, (GLfloat) param );
 }
 
-
-
 /**********************************************************************/
 /*****                  Pixel processing functions               ******/
 /**********************************************************************/
@@ -852,7 +860,7 @@ _mesa_transform_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4])
    const GLfloat bb = ctx->Pixel.PostColorMatrixBias[2];
    const GLfloat as = ctx->Pixel.PostColorMatrixScale[3];
    const GLfloat ab = ctx->Pixel.PostColorMatrixBias[3];
-   const GLfloat *m = ctx->ColorMatrix.m;
+   const GLfloat *m = ctx->ColorMatrixStack.Top->m;
    GLuint i;
    for (i = 0; i < n; i++) {
       const GLfloat r = rgba[i][RCOMP];
@@ -869,30 +877,29 @@ _mesa_transform_rgba(const GLcontext *ctx, GLuint n, GLfloat rgba[][4])
 
 /*
  * Apply a color table lookup to an array of colors.
+ * XXX merge with _swrast_texture_table_lookup in s_texture.c
  */
 void
 _mesa_lookup_rgba(const struct gl_color_table *table,
                   GLuint n, GLfloat rgba[][4])
 {
-   ASSERT(table->FloatTable);
    if (!table->Table || table->Size == 0)
       return;
 
    switch (table->Format) {
       case GL_INTENSITY:
          /* replace RGBA with I */
-         if (!table->FloatTable) {
+         if (table->Type != GL_FLOAT) {
             const GLint max = table->Size - 1;
             const GLfloat scale = (GLfloat) max;
             const GLchan *lut = (const GLchan *) table->Table;
             GLuint i;
             for (i = 0; i < n; i++) {
                GLint j = IROUND(rgba[i][RCOMP] * scale);
-               GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, 1)]);
+               GLfloat c = CHAN_TO_FLOAT(lut[CLAMP(j, 0, max)]);
                rgba[i][RCOMP] = rgba[i][GCOMP] =
                   rgba[i][BCOMP] = rgba[i][ACOMP] = c;
             }
-
          }
          else {
             const GLint max = table->Size - 1;
@@ -909,7 +916,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
          break;
       case GL_LUMINANCE:
          /* replace RGB with L */
-         if (!table->FloatTable) {
+         if (table->Type != GL_FLOAT) {
             const GLint max = table->Size - 1;
             const GLfloat scale = (GLfloat) max;
             const GLchan *lut = (const GLchan *) table->Table;
@@ -934,7 +941,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
          break;
       case GL_ALPHA:
          /* replace A with A */
-         if (!table->FloatTable) {
+         if (table->Type != GL_FLOAT) {
             const GLint max = table->Size - 1;
             const GLfloat scale = (GLfloat) max;
             const GLchan *lut = (const GLchan *) table->Table;
@@ -957,7 +964,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
          break;
       case GL_LUMINANCE_ALPHA:
          /* replace RGBA with LLLA */
-         if (!table->FloatTable) {
+         if (table->Type != GL_FLOAT) {
             const GLint max = table->Size - 1;
             const GLfloat scale = (GLfloat) max;
             const GLchan *lut = (const GLchan *) table->Table;
@@ -994,7 +1001,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
          break;
       case GL_RGB:
          /* replace RGB with RGB */
-         if (!table->FloatTable) {
+         if (table->Type != GL_FLOAT) {
             const GLint max = table->Size - 1;
             const GLfloat scale = (GLfloat) max;
             const GLchan *lut = (const GLchan *) table->Table;
@@ -1031,7 +1038,7 @@ _mesa_lookup_rgba(const struct gl_color_table *table,
          break;
       case GL_RGBA:
          /* replace RGBA with RGBA */
-         if (!table->FloatTable) {
+         if (table->Type != GL_FLOAT) {
             const GLint max = table->Size - 1;
             const GLfloat scale = (GLfloat) max;
             const GLchan *lut = (const GLchan *) table->Table;
@@ -1318,3 +1325,206 @@ _mesa_chan_to_float_span(const GLcontext *ctx, GLuint n,
    }
 #endif
 }
+
+/**********************************************************************/
+/*****                    State Management                        *****/
+/**********************************************************************/
+
+/*
+ * Return a bitmask of IMAGE_*_BIT flags which to indicate which
+ * pixel transfer operations are enabled.
+ */
+static void
+update_image_transfer_state(GLcontext *ctx)
+{
+   GLuint mask = 0;
+
+   if (ctx->Pixel.RedScale   != 1.0F || ctx->Pixel.RedBias   != 0.0F ||
+       ctx->Pixel.GreenScale != 1.0F || ctx->Pixel.GreenBias != 0.0F ||
+       ctx->Pixel.BlueScale  != 1.0F || ctx->Pixel.BlueBias  != 0.0F ||
+       ctx->Pixel.AlphaScale != 1.0F || ctx->Pixel.AlphaBias != 0.0F)
+      mask |= IMAGE_SCALE_BIAS_BIT;
+
+   if (ctx->Pixel.IndexShift || ctx->Pixel.IndexOffset)
+      mask |= IMAGE_SHIFT_OFFSET_BIT;
+
+   if (ctx->Pixel.MapColorFlag)
+      mask |= IMAGE_MAP_COLOR_BIT;
+
+   if (ctx->Pixel.ColorTableEnabled)
+      mask |= IMAGE_COLOR_TABLE_BIT;
+
+   if (ctx->Pixel.Convolution1DEnabled ||
+       ctx->Pixel.Convolution2DEnabled ||
+       ctx->Pixel.Separable2DEnabled) {
+      mask |= IMAGE_CONVOLUTION_BIT;
+      if (ctx->Pixel.PostConvolutionScale[0] != 1.0F ||
+          ctx->Pixel.PostConvolutionScale[1] != 1.0F ||
+          ctx->Pixel.PostConvolutionScale[2] != 1.0F ||
+          ctx->Pixel.PostConvolutionScale[3] != 1.0F ||
+          ctx->Pixel.PostConvolutionBias[0] != 0.0F ||
+          ctx->Pixel.PostConvolutionBias[1] != 0.0F ||
+          ctx->Pixel.PostConvolutionBias[2] != 0.0F ||
+          ctx->Pixel.PostConvolutionBias[3] != 0.0F) {
+         mask |= IMAGE_POST_CONVOLUTION_SCALE_BIAS;
+      }
+   }
+
+   if (ctx->Pixel.PostConvolutionColorTableEnabled)
+      mask |= IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT;
+
+   if (ctx->ColorMatrixStack.Top->type != MATRIX_IDENTITY ||
+       ctx->Pixel.PostColorMatrixScale[0] != 1.0F ||
+       ctx->Pixel.PostColorMatrixBias[0]  != 0.0F ||
+       ctx->Pixel.PostColorMatrixScale[1] != 1.0F ||
+       ctx->Pixel.PostColorMatrixBias[1]  != 0.0F ||
+       ctx->Pixel.PostColorMatrixScale[2] != 1.0F ||
+       ctx->Pixel.PostColorMatrixBias[2]  != 0.0F ||
+       ctx->Pixel.PostColorMatrixScale[3] != 1.0F ||
+       ctx->Pixel.PostColorMatrixBias[3]  != 0.0F)
+      mask |= IMAGE_COLOR_MATRIX_BIT;
+
+   if (ctx->Pixel.PostColorMatrixColorTableEnabled)
+      mask |= IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT;
+
+   if (ctx->Pixel.HistogramEnabled)
+      mask |= IMAGE_HISTOGRAM_BIT;
+
+   if (ctx->Pixel.MinMaxEnabled)
+      mask |= IMAGE_MIN_MAX_BIT;
+
+   ctx->_ImageTransferState = mask;
+}
+
+
+void _mesa_update_pixel( GLcontext *ctx, GLuint new_state )
+{
+   if (new_state & _NEW_COLOR_MATRIX)
+      _math_matrix_analyse( ctx->ColorMatrixStack.Top );
+
+   /* References ColorMatrix.type (derived above).
+    */
+   if (new_state & _IMAGE_NEW_TRANSFER_STATE)
+      update_image_transfer_state(ctx);
+}
+
+
+/**********************************************************************/
+/*****                      Initialization                        *****/
+/**********************************************************************/
+
+void _mesa_init_pixel( GLcontext * ctx )
+{
+   int i;
+
+   /* Pixel group */
+   ctx->Pixel.RedBias = 0.0;
+   ctx->Pixel.RedScale = 1.0;
+   ctx->Pixel.GreenBias = 0.0;
+   ctx->Pixel.GreenScale = 1.0;
+   ctx->Pixel.BlueBias = 0.0;
+   ctx->Pixel.BlueScale = 1.0;
+   ctx->Pixel.AlphaBias = 0.0;
+   ctx->Pixel.AlphaScale = 1.0;
+   ctx->Pixel.DepthBias = 0.0;
+   ctx->Pixel.DepthScale = 1.0;
+   ctx->Pixel.IndexOffset = 0;
+   ctx->Pixel.IndexShift = 0;
+   ctx->Pixel.ZoomX = 1.0;
+   ctx->Pixel.ZoomY = 1.0;
+   ctx->Pixel.MapColorFlag = GL_FALSE;
+   ctx->Pixel.MapStencilFlag = GL_FALSE;
+   ctx->Pixel.MapStoSsize = 1;
+   ctx->Pixel.MapItoIsize = 1;
+   ctx->Pixel.MapItoRsize = 1;
+   ctx->Pixel.MapItoGsize = 1;
+   ctx->Pixel.MapItoBsize = 1;
+   ctx->Pixel.MapItoAsize = 1;
+   ctx->Pixel.MapRtoRsize = 1;
+   ctx->Pixel.MapGtoGsize = 1;
+   ctx->Pixel.MapBtoBsize = 1;
+   ctx->Pixel.MapAtoAsize = 1;
+   ctx->Pixel.MapStoS[0] = 0;
+   ctx->Pixel.MapItoI[0] = 0;
+   ctx->Pixel.MapItoR[0] = 0.0;
+   ctx->Pixel.MapItoG[0] = 0.0;
+   ctx->Pixel.MapItoB[0] = 0.0;
+   ctx->Pixel.MapItoA[0] = 0.0;
+   ctx->Pixel.MapItoR8[0] = 0;
+   ctx->Pixel.MapItoG8[0] = 0;
+   ctx->Pixel.MapItoB8[0] = 0;
+   ctx->Pixel.MapItoA8[0] = 0;
+   ctx->Pixel.MapRtoR[0] = 0.0;
+   ctx->Pixel.MapGtoG[0] = 0.0;
+   ctx->Pixel.MapBtoB[0] = 0.0;
+   ctx->Pixel.MapAtoA[0] = 0.0;
+   ctx->Pixel.HistogramEnabled = GL_FALSE;
+   ctx->Pixel.MinMaxEnabled = GL_FALSE;
+   ctx->Pixel.PixelTextureEnabled = GL_FALSE;
+   ctx->Pixel.FragmentRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
+   ctx->Pixel.FragmentAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
+   ASSIGN_4V(ctx->Pixel.PostColorMatrixScale, 1.0, 1.0, 1.0, 1.0);
+   ASSIGN_4V(ctx->Pixel.PostColorMatrixBias, 0.0, 0.0, 0.0, 0.0);
+   ASSIGN_4V(ctx->Pixel.ColorTableScale, 1.0, 1.0, 1.0, 1.0);
+   ASSIGN_4V(ctx->Pixel.ColorTableBias, 0.0, 0.0, 0.0, 0.0);
+   ASSIGN_4V(ctx->Pixel.PCCTscale, 1.0, 1.0, 1.0, 1.0);
+   ASSIGN_4V(ctx->Pixel.PCCTbias, 0.0, 0.0, 0.0, 0.0);
+   ASSIGN_4V(ctx->Pixel.PCMCTscale, 1.0, 1.0, 1.0, 1.0);
+   ASSIGN_4V(ctx->Pixel.PCMCTbias, 0.0, 0.0, 0.0, 0.0);
+   ctx->Pixel.ColorTableEnabled = GL_FALSE;
+   ctx->Pixel.PostConvolutionColorTableEnabled = GL_FALSE;
+   ctx->Pixel.PostColorMatrixColorTableEnabled = GL_FALSE;
+   ctx->Pixel.Convolution1DEnabled = GL_FALSE;
+   ctx->Pixel.Convolution2DEnabled = GL_FALSE;
+   ctx->Pixel.Separable2DEnabled = GL_FALSE;
+   for (i = 0; i < 3; i++) {
+      ASSIGN_4V(ctx->Pixel.ConvolutionBorderColor[i], 0.0, 0.0, 0.0, 0.0);
+      ctx->Pixel.ConvolutionBorderMode[i] = GL_REDUCE;
+      ASSIGN_4V(ctx->Pixel.ConvolutionFilterScale[i], 1.0, 1.0, 1.0, 1.0);
+      ASSIGN_4V(ctx->Pixel.ConvolutionFilterBias[i], 0.0, 0.0, 0.0, 0.0);
+   }
+   for (i = 0; i < MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_WIDTH * 4; i++) {
+      ctx->Convolution1D.Filter[i] = 0.0;
+      ctx->Convolution2D.Filter[i] = 0.0;
+      ctx->Separable2D.Filter[i] = 0.0;
+   }
+   ASSIGN_4V(ctx->Pixel.PostConvolutionScale, 1.0, 1.0, 1.0, 1.0);
+   ASSIGN_4V(ctx->Pixel.PostConvolutionBias, 0.0, 0.0, 0.0, 0.0);
+   /* GL_SGI_texture_color_table */
+   ASSIGN_4V(ctx->Pixel.TextureColorTableScale, 1.0, 1.0, 1.0, 1.0);
+   ASSIGN_4V(ctx->Pixel.TextureColorTableBias, 0.0, 0.0, 0.0, 0.0);
+
+   /* Pixel transfer */
+   ctx->Pack.Alignment = 4;
+   ctx->Pack.RowLength = 0;
+   ctx->Pack.ImageHeight = 0;
+   ctx->Pack.SkipPixels = 0;
+   ctx->Pack.SkipRows = 0;
+   ctx->Pack.SkipImages = 0;
+   ctx->Pack.SwapBytes = GL_FALSE;
+   ctx->Pack.LsbFirst = GL_FALSE;
+   ctx->Pack.ClientStorage = GL_FALSE;
+   ctx->Pack.Invert = GL_FALSE;
+   ctx->Unpack.Alignment = 4;
+   ctx->Unpack.RowLength = 0;
+   ctx->Unpack.ImageHeight = 0;
+   ctx->Unpack.SkipPixels = 0;
+   ctx->Unpack.SkipRows = 0;
+   ctx->Unpack.SkipImages = 0;
+   ctx->Unpack.SwapBytes = GL_FALSE;
+   ctx->Unpack.LsbFirst = GL_FALSE;
+   ctx->Unpack.ClientStorage = GL_FALSE;
+   ctx->Unpack.Invert = GL_FALSE;
+
+   if (ctx->Visual.doubleBufferMode) {
+      ctx->Pixel.ReadBuffer = GL_BACK;
+      ctx->Pixel._ReadSrcMask = BACK_LEFT_BIT;
+   }
+   else {
+      ctx->Pixel.ReadBuffer = GL_FRONT;
+      ctx->Pixel._ReadSrcMask = FRONT_LEFT_BIT;
+   }
+
+   /* Miscellaneous */
+   ctx->_ImageTransferState = 0;
+}