head	3.18;
access;
symbols
	merge-1:3.14
	autoconf:3.14.0.4
	experimental-1:3.14.0.2
	mesa-3-1-with-kw3:3.13
	mesa-3-1-prior-to-kw3:3.12;
locks; strict;
comment	@ * @;


3.18
date	99.08.01.11.31.30;	author brianp;	state Exp;
branches;
next	3.17;

3.17
date	99.07.21.20.48.26;	author miklos;	state Exp;
branches;
next	3.16;

3.16
date	99.07.13.16.54.29;	author miklos;	state Exp;
branches;
next	3.15;

3.15
date	99.06.13.15.36.15;	author brianp;	state Exp;
branches;
next	3.14;

3.14
date	99.03.28.20.56.15;	author brianp;	state Exp;
branches;
next	3.13;

3.13
date	99.02.25.14.12.31;	author keithw;	state Exp;
branches;
next	3.12;

3.12
date	99.02.24.22.48.07;	author jens;	state Exp;
branches;
next	3.11;

3.11
date	99.02.14.03.46.34;	author brianp;	state Exp;
branches;
next	3.10;

3.10
date	99.01.22.04.30.44;	author brianp;	state Exp;
branches;
next	3.9;

3.9
date	98.10.03.13.22.40;	author brianp;	state Exp;
branches;
next	3.8;

3.8
date	98.08.04.02.47.49;	author brianp;	state Exp;
branches;
next	3.7;

3.7
date	98.07.18.03.34.24;	author brianp;	state Exp;
branches;
next	3.6;

3.6
date	98.07.17.03.24.16;	author brianp;	state Exp;
branches;
next	3.5;

3.5
date	98.03.27.04.17.52;	author brianp;	state Exp;
branches;
next	3.4;

3.4
date	98.03.15.18.50.25;	author brianp;	state Exp;
branches;
next	3.3;

3.3
date	98.02.08.20.22.14;	author brianp;	state Exp;
branches;
next	3.2;

3.2
date	98.02.01.22.29.09;	author brianp;	state Exp;
branches;
next	3.1;

3.1
date	98.02.01.20.47.42;	author brianp;	state Exp;
branches;
next	3.0;

3.0
date	98.01.31.21.02.29;	author brianp;	state Exp;
branches;
next	;


desc
@glReadPixels()
@


3.18
log
@lots of clean-up, now use gl_pack_rgba_span()
@
text
@/* $Id: readpix.c,v 3.17 1999/07/21 20:48:26 miklos Exp $ */

/*
 * Mesa 3-D graphics library
 * Version:  3.1
 * 
 * Copyright (C) 1999  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"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */





#ifdef PC_HEADER
#include "all.h"
#else
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "context.h"
#include "depth.h"
#include "feedback.h"
#include "macros.h"
#include "image.h"
#include "pixel.h"
#include "readpix.h"
#include "span.h"
#include "stencil.h"
#include "types.h"
#ifdef XFree86Server
#include "GL/xf86glx.h"
#endif
#endif




/*
 * Read a block of color index pixels.
 */
static void read_index_pixels( GLcontext *ctx,
                               GLint x, GLint y,
			       GLsizei width, GLsizei height,
			       GLenum type, GLvoid *pixels,
                               const struct gl_pixelstore_attrib *packing )
{
   GLint i, j;

   /* error checking */
   if (ctx->Visual->RGBAflag) {
      gl_error( ctx, GL_INVALID_OPERATION, "glReadPixels" );
      return;
   }

   (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );


   /* process image row by row */
   for (j=0;j<height;j++,y++) {
      GLuint index[MAX_WIDTH];
      GLvoid *dest;

      (*ctx->Driver.ReadCI32Span)( ctx, width, x, y, index );

      if (ctx->Pixel.IndexShift!=0 || ctx->Pixel.IndexOffset!=0) {
         gl_shift_and_offset_ci( ctx, width, index);
      }

      if (ctx->Pixel.MapColorFlag) {
         gl_map_ci(ctx, width, index);
      }

      dest = gl_pixel_addr_in_image(packing, pixels,
                         width, height, GL_COLOR_INDEX, type, 0, j, 0);

      switch (type) {
	 case GL_UNSIGNED_BYTE:
	    {
               GLubyte *dst = (GLubyte *) dest;
	       for (i=0;i<width;i++) {
		  *dst++ = (GLubyte) index[i];
	       }
	    }
	    break;
	 case GL_BYTE:
	    {
               GLbyte *dst = (GLbyte *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLbyte) index[i];
	       }
	    }
	    break;
	 case GL_UNSIGNED_SHORT:
	    {
               GLushort *dst = (GLushort *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLushort) index[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap2( (GLushort *) dst, width );
	       }
	    }
	    break;
	 case GL_SHORT:
	    {
               GLshort *dst = (GLshort *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLshort) index[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap2( (GLushort *) dst, width );
	       }
	    }
	    break;
	 case GL_UNSIGNED_INT:
	    {
               GLuint *dst = (GLuint *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLuint) index[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap4( (GLuint *) dst, width );
	       }
	    }
	    break;
	 case GL_INT:
	    {
               GLint *dst = (GLint *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLint) index[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap4( (GLuint *) dst, width );
	       }
	    }
	    break;
	 case GL_FLOAT:
	    {
               GLfloat *dst = (GLfloat *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLfloat) index[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap4( (GLuint *) dst, width );
	       }
	    }
	    break;
         default:
            gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
            j = height + 1; /* exit loop */
      }
   }

   (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
}



static void read_depth_pixels( GLcontext *ctx,
                               GLint x, GLint y,
			       GLsizei width, GLsizei height,
			       GLenum type, GLvoid *pixels,
                               const struct gl_pixelstore_attrib *packing )
{
   GLint i, j;
   GLboolean bias_or_scale;

   /* Error checking */
   if (ctx->Visual->DepthBits <= 0) {
      /* No depth buffer */
      gl_error( ctx, GL_INVALID_OPERATION, "glReadPixels" );
      return;
   }

   bias_or_scale = ctx->Pixel.DepthBias!=0.0 || ctx->Pixel.DepthScale!=1.0;

   if (type==GL_UNSIGNED_SHORT && sizeof(GLdepth)==sizeof(GLushort)
       && !bias_or_scale && !packing->SwapBytes) {
      /* Special case: directly read 16-bit unsigned depth values. */
      for (j=0;j<height;j++,y++) {
         GLushort *dst = (GLushort*) gl_pixel_addr_in_image( packing, pixels,
                         width, height, GL_DEPTH_COMPONENT, type, 0, j, 0 );
         (*ctx->Driver.ReadDepthSpanInt)( ctx, width, x, y, (GLdepth*) dst);
      }
   }
   else if (type==GL_UNSIGNED_INT && sizeof(GLdepth)==sizeof(GLuint)
            && !bias_or_scale && !packing->SwapBytes) {
      /* Special case: directly read 32-bit unsigned depth values. */
      /* Compute shift value to scale depth values up to 32-bit uints. */
      GLuint shift = 0;
      GLuint max = MAX_DEPTH;
      while ((max&0x80000000)==0) {
         max = max << 1;
         shift++;
      }
      for (j=0;j<height;j++,y++) {
         GLuint *dst = (GLuint *) gl_pixel_addr_in_image( packing, pixels,
                         width, height, GL_DEPTH_COMPONENT, type, 0, j, 0 );
         (*ctx->Driver.ReadDepthSpanInt)( ctx, width, x, y, (GLdepth*) dst);
         for (i=0;i<width;i++) {
            dst[i] = dst[i] << shift;
         }
      }
   }
   else {
      /* General case (slow) */
      for (j=0;j<height;j++,y++) {
         GLfloat depth[MAX_WIDTH];
         GLvoid *dest;

         (*ctx->Driver.ReadDepthSpanFloat)( ctx, width, x, y, depth );

         if (bias_or_scale) {
            for (i=0;i<width;i++) {
               GLfloat d;
               d = depth[i] * ctx->Pixel.DepthScale + ctx->Pixel.DepthBias;
               depth[i] = CLAMP( d, 0.0F, 1.0F );
            }
         }

         dest = gl_pixel_addr_in_image(packing, pixels,
                         width, height, GL_DEPTH_COMPONENT, type, 0, j, 0);

         switch (type) {
            case GL_UNSIGNED_BYTE:
               {
                  GLubyte *dst = (GLubyte *) dest;
                  for (i=0;i<width;i++) {
                     dst[i] = FLOAT_TO_UBYTE( depth[i] );
                  }
               }
               break;
            case GL_BYTE:
               {
                  GLbyte *dst = (GLbyte *) dest;
                  for (i=0;i<width;i++) {
                     dst[i] = FLOAT_TO_BYTE( depth[i] );
                  }
               }
               break;
            case GL_UNSIGNED_SHORT:
               {
                  GLushort *dst = (GLushort *) dest;
                  for (i=0;i<width;i++) {
                     dst[i] = FLOAT_TO_USHORT( depth[i] );
                  }
                  if (packing->SwapBytes) {
                     gl_swap2( (GLushort *) dst, width );
                  }
               }
               break;
            case GL_SHORT:
               {
                  GLshort *dst = (GLshort *) dest;
                  for (i=0;i<width;i++) {
                     dst[i] = FLOAT_TO_SHORT( depth[i] );
                  }
                  if (packing->SwapBytes) {
                     gl_swap2( (GLushort *) dst, width );
                  }
               }
               break;
            case GL_UNSIGNED_INT:
               {
                  GLuint *dst = (GLuint *) dest;
                  for (i=0;i<width;i++) {
                     dst[i] = FLOAT_TO_UINT( depth[i] );
                  }
                  if (packing->SwapBytes) {
                     gl_swap4( (GLuint *) dst, width );
                  }
               }
               break;
            case GL_INT:
               {
                  GLint *dst = (GLint *) dest;
                  for (i=0;i<width;i++) {
                     dst[i] = FLOAT_TO_INT( depth[i] );
                  }
                  if (packing->SwapBytes) {
                     gl_swap4( (GLuint *) dst, width );
                  }
               }
               break;
            case GL_FLOAT:
               {
                  GLfloat *dst = (GLfloat *) dest;
                  for (i=0;i<width;i++) {
                     dst[i] = depth[i];
                  }
                  if (packing->SwapBytes) {
                     gl_swap4( (GLuint *) dst, width );
                  }
               }
               break;
            default:
               gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
         }
      }
   }
}




static void read_stencil_pixels( GLcontext *ctx,
                                 GLint x, GLint y,
				 GLsizei width, GLsizei height,
				 GLenum type, GLvoid *pixels,
                                 const struct gl_pixelstore_attrib *packing )
{
   GLboolean shift_or_offset;
   GLint i, j;

   if (ctx->Visual->StencilBits<=0) {
      /* No stencil buffer */
      gl_error( ctx, GL_INVALID_OPERATION, "glReadPixels" );
      return;
   }

   shift_or_offset = ctx->Pixel.IndexShift!=0 || ctx->Pixel.IndexOffset!=0;

   /* process image row by row */
   for (j=0;j<height;j++,y++) {
      GLvoid *dest;
      GLstencil stencil[MAX_WIDTH];

      gl_read_stencil_span( ctx, width, x, y, stencil );

      if (shift_or_offset) {
         gl_shift_and_offset_stencil( ctx, width, stencil );
      }

      if (ctx->Pixel.MapStencilFlag) {
         gl_map_stencil( ctx, width, stencil );
      }

      dest = gl_pixel_addr_in_image( packing, pixels,
                          width, height, GL_STENCIL_INDEX, type, 0, j, 0 );

      switch (type) {
	 case GL_UNSIGNED_BYTE:
            if (sizeof(GLstencil) == 8) {
               MEMCPY( dest, stencil, width );
            }
            else {
               GLubyte *dst = (GLubyte *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLubyte) stencil[i];
	       }
            }
	    break;
	 case GL_BYTE:
            if (sizeof(GLstencil) == 8) {
               MEMCPY( dest, stencil, width );
            }
            else {
               GLbyte *dst = (GLbyte *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLbyte) stencil[i];
	       }
            }
	    break;
	 case GL_UNSIGNED_SHORT:
	    {
               GLushort *dst = (GLushort *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLushort) stencil[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap2( (GLushort *) dst, width );
	       }
	    }
	    break;
	 case GL_SHORT:
	    {
               GLshort *dst = (GLshort *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLshort) stencil[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap2( (GLushort *) dst, width );
	       }
	    }
	    break;
	 case GL_UNSIGNED_INT:
	    {
               GLuint *dst = (GLuint *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLuint) stencil[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap4( (GLuint *) dst, width );
	       }
	    }
	    break;
	 case GL_INT:
	    {
               GLint *dst = (GLint *) dest;
	       for (i=0;i<width;i++) {
		  *dst++ = (GLint) stencil[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap4( (GLuint *) dst, width );
	       }
	    }
	    break;
	 case GL_FLOAT:
	    {
               GLfloat *dst = (GLfloat *) dest;
	       for (i=0;i<width;i++) {
		  dst[i] = (GLfloat) stencil[i];
	       }
	       if (packing->SwapBytes) {
		  gl_swap4( (GLuint *) dst, width );
	       }
	    }
	    break;
         default:
            gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
      }
   }
}



/*
 * Optimized glReadPixels for particular pixel formats:
 *   GL_UNSIGNED_BYTE, GL_RGBA
 * when pixel scaling, biasing and mapping are disabled.
 */
static GLboolean
read_fast_rgba_pixels( GLcontext *ctx,
                       GLint x, GLint y,
                       GLsizei width, GLsizei height,
                       GLenum format, GLenum type,
                       GLvoid *pixels,
                       const struct gl_pixelstore_attrib *packing )
{
   /* can't do scale, bias or mapping */
   if (ctx->Pixel.ScaleOrBiasRGBA || ctx->Pixel.MapColorFlag)
       return GL_FALSE;

   /* can't do fancy pixel packing */
   if (packing->Alignment != 1 || packing->SwapBytes || packing->LsbFirst)
      return GL_FALSE;

   {
      GLint srcX = x;
      GLint srcY = y;
      GLint readWidth = width;           /* actual width read */
      GLint readHeight = height;         /* actual height read */
      GLint skipPixels = packing->SkipPixels;
      GLint skipRows = packing->SkipRows;
      GLint rowLength;

      if (packing->RowLength > 0)
         rowLength = packing->RowLength;
      else
         rowLength = width;

      /* horizontal clipping */
      if (srcX < ctx->Buffer->Xmin) {
         skipPixels += (ctx->Buffer->Xmin - srcX);
         readWidth  -= (ctx->Buffer->Xmin - srcX);
         srcX = ctx->Buffer->Xmin;
      }
      if (srcX + readWidth > ctx->Buffer->Xmax)
         readWidth -= (srcX + readWidth - ctx->Buffer->Xmax - 1);
      if (readWidth <= 0)
         return GL_TRUE;

      /* vertical clipping */
      if (srcY < ctx->Buffer->Ymin) {
         skipRows   += (ctx->Buffer->Ymin - srcY);
         readHeight -= (ctx->Buffer->Ymin - srcY);
         srcY = ctx->Buffer->Ymin;
      }
      if (srcY + readHeight > ctx->Buffer->Ymax)
         readHeight -= (srcY + readHeight - ctx->Buffer->Ymax - 1);
      if (readHeight <= 0)
         return GL_TRUE;

      /*
       * Ready to read!
       * The window region at (destX, destY) of size (drawWidth, drawHeight)
       * will be read back.
       * We'll write pixel data to buffer pointed to by "pixels" but we'll
       * skip "skipRows" rows and skip "skipPixels" pixels/row.
       */
      if (format==GL_RGBA && type==GL_UNSIGNED_BYTE) {
         GLubyte *dest = (GLubyte *) pixels
                         + (skipRows * rowLength + skipPixels) * 4;
         GLint row;
         for (row=0; row<readHeight; row++) {
            (*ctx->Driver.ReadRGBASpan)(ctx, readWidth, srcX, srcY,
                                        (void *) dest);
            dest += rowLength * 4;
            srcY++;
         }
         return GL_TRUE;
      }
      else {
         /* can't do this format/type combination */
         return GL_FALSE;
      }
   }
}



/*
 * Read R, G, B, A, RGB, L, or LA pixels.
 */
static void read_rgba_pixels( GLcontext *ctx,
                              GLint x, GLint y,
                              GLsizei width, GLsizei height,
                              GLenum format, GLenum type, GLvoid *pixels,
                              const struct gl_pixelstore_attrib *packing )
{

   (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );

   /* Try optimized path first */
   if (read_fast_rgba_pixels( ctx, x, y, width, height,
                              format, type, pixels, packing )) {

      (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
      return; /* done! */
   }


   /* do error checking on pixel type, format was already checked by caller */
   switch (type) {
      case GL_UNSIGNED_BYTE:
      case GL_BYTE:
      case GL_UNSIGNED_SHORT:
      case GL_SHORT:
      case GL_UNSIGNED_INT:
      case GL_INT:
      case GL_FLOAT:
      case GL_UNSIGNED_BYTE_3_3_2:
      case GL_UNSIGNED_BYTE_2_3_3_REV:
      case GL_UNSIGNED_SHORT_5_6_5:
      case GL_UNSIGNED_SHORT_5_6_5_REV:
      case GL_UNSIGNED_SHORT_4_4_4_4:
      case GL_UNSIGNED_SHORT_4_4_4_4_REV:
      case GL_UNSIGNED_SHORT_5_5_5_1:
      case GL_UNSIGNED_SHORT_1_5_5_5_REV:
      case GL_UNSIGNED_INT_8_8_8_8:
      case GL_UNSIGNED_INT_8_8_8_8_REV:
      case GL_UNSIGNED_INT_10_10_10_2:
      case GL_UNSIGNED_INT_2_10_10_10_REV:
         /* valid pixel type */
         break;
      default:
         gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
         return;
   }

   if (ctx->Visual->RGBAflag) {
      GLint j;
      for (j=0;j<height;j++,y++) {
         GLubyte rgba[MAX_WIDTH][4];
         GLvoid *dest;

         gl_read_rgba_span( ctx, width, x, y, rgba );

         dest = gl_pixel_addr_in_image( packing, pixels, width, height,
                                        format, type, 0, j, 0);

         gl_pack_rgba_span( ctx, width, (const GLubyte (*)[4]) rgba,
                            format, type, dest, packing, GL_TRUE );
      }
   }
   else {
      GLint j;
      for (j=0;j<height;j++,y++) {
         GLubyte rgba[MAX_WIDTH][4];
	 GLuint index[MAX_WIDTH];
         GLvoid *dest;

	 (*ctx->Driver.ReadCI32Span)( ctx, width, x, y, index );

	 if (ctx->Pixel.IndexShift!=0 || ctx->Pixel.IndexOffset!=0) {
            gl_map_ci( ctx, width, index );
	 }

         gl_map_ci_to_rgba(ctx, width, index, rgba );

         dest = gl_pixel_addr_in_image( packing, pixels, width, height,
                                        format, type, 0, j, 0);

         gl_pack_rgba_span( ctx, width, (const GLubyte (*)[4]) rgba,
                            format, type, dest, packing, GL_TRUE );
      }
   }

   (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
}



void gl_ReadPixels( GLcontext *ctx,
                    GLint x, GLint y, GLsizei width, GLsizei height,
		    GLenum format, GLenum type, GLvoid *pixels )
{
   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glReadPixels");

   if (!pixels) {
      gl_error( ctx, GL_INVALID_VALUE, "glReadPixels(pixels)" );
      return;
   }

   switch (format) {
      case GL_COLOR_INDEX:
         read_index_pixels( ctx, x, y, width, height, type, pixels, &ctx->Pack );
	 break;
      case GL_STENCIL_INDEX:
	 read_stencil_pixels( ctx, x, y, width, height, type, pixels, &ctx->Pack );
         break;
      case GL_DEPTH_COMPONENT:
	 read_depth_pixels( ctx, x, y, width, height, type, pixels, &ctx->Pack );
	 break;
      case GL_RED:
      case GL_GREEN:
      case GL_BLUE:
      case GL_ALPHA:
      case GL_RGB:
      case GL_LUMINANCE:
      case GL_LUMINANCE_ALPHA:
      case GL_RGBA:
      case GL_BGR:
      case GL_BGRA:
      case GL_ABGR_EXT:
         read_rgba_pixels( ctx, x, y, width, height, format, type, pixels, &ctx->Pack );
	 break;
      default:
	 gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(format)" );
   }
}
@


3.17
log
@Added more DEFARRAY.
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.16 1999/07/13 16:54:29 miklos Exp $ */
d61 2
a62 1
			       GLenum type, GLvoid *pixels )
d72 3
d90 1
a90 1
      dest = gl_pixel_addr_in_image(&ctx->Pack, pixels,
d116 1
a116 1
	       if (ctx->Pack.SwapBytes) {
d127 1
a127 1
	       if (ctx->Pack.SwapBytes) {
d138 1
a138 1
	       if (ctx->Pack.SwapBytes) {
d149 1
a149 1
	       if (ctx->Pack.SwapBytes) {
d160 1
a160 1
	       if (ctx->Pack.SwapBytes) {
d167 1
d170 2
d179 2
a180 1
			       GLenum type, GLvoid *pixels )
d195 1
a195 1
       && !bias_or_scale && !ctx->Pack.SwapBytes) {
d198 2
a199 2
         GLushort *dst = (GLushort*) gl_pixel_addr_in_image(&ctx->Pack, pixels,
                         width, height, GL_DEPTH_COMPONENT, type, 0, j, 0);
d204 1
a204 1
            && !bias_or_scale && !ctx->Pack.SwapBytes) {
d214 2
a215 2
         GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack, pixels,
                         width, height, GL_DEPTH_COMPONENT, type, 0, j, 0);
d238 1
a238 1
         dest = gl_pixel_addr_in_image(&ctx->Pack, pixels,
d264 1
a264 1
                  if (ctx->Pack.SwapBytes) {
d275 1
a275 1
                  if (ctx->Pack.SwapBytes) {
d286 1
a286 1
                  if (ctx->Pack.SwapBytes) {
d297 1
a297 1
                  if (ctx->Pack.SwapBytes) {
d308 1
a308 1
                  if (ctx->Pack.SwapBytes) {
d326 2
a327 1
				 GLenum type, GLvoid *pixels )
d355 2
a356 2
      dest = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                          width, height, GL_STENCIL_INDEX, type, 0, j, 0);
d387 1
a387 1
	       if (ctx->Pack.SwapBytes) {
d398 1
a398 1
	       if (ctx->Pack.SwapBytes) {
d409 1
a409 1
	       if (ctx->Pack.SwapBytes) {
d420 1
a420 1
	       if (ctx->Pack.SwapBytes) {
d431 1
a431 1
	       if (ctx->Pack.SwapBytes) {
d449 7
a455 5
static GLboolean read_fast_rgba_pixels( GLcontext *ctx,
                                        GLint x, GLint y,
                                        GLsizei width, GLsizei height,
                                        GLenum format, GLenum type,
                                        GLvoid *pixels )
d462 1
a462 1
   if (ctx->Pack.Alignment != 1 || ctx->Pack.SwapBytes || ctx->Pack.LsbFirst)
d470 2
a471 2
      GLint skipPixels = ctx->Pack.SkipPixels;
      GLint skipRows = ctx->Pack.SkipRows;
d474 2
a475 2
      if (ctx->Pack.RowLength > 0)
         rowLength = ctx->Pack.RowLength;
d535 2
a536 1
                              GLenum format, GLenum type, GLvoid *pixels )
d538 12
a549 9
   GLint i, j, comps_per_pixel;
   GLfloat red[MAX_WIDTH];
   GLfloat green[MAX_WIDTH];
   DEFARRAY(GLfloat,blue,MAX_WIDTH);
   DEFARRAY(GLfloat,alpha,MAX_WIDTH);
   DEFARRAY(GLfloat,luminance,MAX_WIDTH);
   CHECKARRAY(blue,goto cleanup);
   CHECKARRAY(alpha,goto cleanup);
   CHECKARRAY(luminance,goto cleanup);
d575 1
a575 1
         goto cleanup;
d578 5
a582 1
   comps_per_pixel = gl_components_in_format( format );
d584 1
a584 2
   /* process image row by row */
   for (j=0;j<height;j++,y++) {
d586 2
a587 18
      /*
       * Read the pixels from frame buffer
       */
      if (ctx->Visual->RGBAflag) {
         GLubyte rgba[MAX_WIDTH][4];
	 GLfloat rscale = (1.0F / 255.0F);
	 GLfloat gscale = (1.0F / 255.0F);
	 GLfloat bscale = (1.0F / 255.0F);
	 GLfloat ascale = (1.0F / 255.0F);

	 /* read colors and convert to floats */
         gl_read_rgba_span(ctx, width, x, y, rgba );
	 for (i=0;i<width;i++) {
	    red[i]   = rgba[i][RCOMP] * rscale;
	    green[i] = rgba[i][GCOMP] * gscale;
	    blue[i]  = rgba[i][BCOMP] * bscale;
	    alpha[i] = rgba[i][ACOMP] * ascale;
	 }
d589 2
a590 6
	 if (ctx->Pixel.ScaleOrBiasRGBA) {
	    gl_scale_and_bias_color( ctx, width, red, green, blue, alpha );
	 }
	 if (ctx->Pixel.MapColorFlag) {
	    gl_map_color( ctx, width, red, green, blue, alpha );
	 }
d592 5
a596 2
      else {
	 /* convert CI values to RGBA */
d598 2
d606 1
a606 13
         gl_map_ci_to_color(ctx, width, index, red, green, blue, alpha);
      }

      if (format==GL_LUMINANCE || format==GL_LUMINANCE_ALPHA) {
         for (i=0;i<width;i++) {
            GLfloat sum = red[i] + green[i] + blue[i];
            luminance[i] = CLAMP( sum, 0.0F, 1.0F );
         }
      }

      /*
       * Pack/transfer/store the pixels
       */
d608 2
a609 4
      /* XXX
       * XXX rewrite this to use the new gl_pack_rgba_span function!!!
       * XXX
       */
d611 2
a612 754
      switch (type) {
         case GL_UNSIGNED_BYTE:
            {
               GLubyte *dst = (GLubyte *) gl_pixel_addr_in_image(&ctx->Pack,
                              pixels, width, height, format, type, 0, j, 0);
               switch (format) {
                  case GL_RED:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UBYTE(red[i]);
                     break;
                  case GL_GREEN:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UBYTE(green[i]);
                     break;
                  case GL_BLUE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UBYTE(blue[i]);
                     break;
                  case GL_ALPHA:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UBYTE(alpha[i]);
                     break;
                  case GL_LUMINANCE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UBYTE(luminance[i]);
                     break;
                  case GL_LUMINANCE_ALPHA:
                     for (i=0;i<width;i++) {
                        dst[i*2+0] = FLOAT_TO_UBYTE(luminance[i]);
                        dst[i*2+1] = FLOAT_TO_UBYTE(alpha[i]);
                     }
                     break;
                  case GL_RGB:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_UBYTE(red[i]);
                        dst[i*3+1] = FLOAT_TO_UBYTE(green[i]);
                        dst[i*3+2] = FLOAT_TO_UBYTE(blue[i]);
                     }
                     break;
                  case GL_RGBA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_UBYTE(red[i]);
                        dst[i*4+1] = FLOAT_TO_UBYTE(green[i]);
                        dst[i*4+2] = FLOAT_TO_UBYTE(blue[i]);
                        dst[i*4+3] = FLOAT_TO_UBYTE(alpha[i]);
                     }
                     break;
                  case GL_BGR:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_UBYTE(blue[i]);
                        dst[i*3+1] = FLOAT_TO_UBYTE(green[i]);
                        dst[i*3+2] = FLOAT_TO_UBYTE(red[i]);
                     }
                     break;
                  case GL_BGRA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_UBYTE(blue[i]);
                        dst[i*4+1] = FLOAT_TO_UBYTE(green[i]);
                        dst[i*4+2] = FLOAT_TO_UBYTE(red[i]);
                        dst[i*4+3] = FLOAT_TO_UBYTE(alpha[i]);
                     }
                     break;
                  case GL_ABGR_EXT:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_UBYTE(alpha[i]);
                        dst[i*4+1] = FLOAT_TO_UBYTE(blue[i]);
                        dst[i*4+2] = FLOAT_TO_UBYTE(green[i]);
                        dst[i*4+3] = FLOAT_TO_UBYTE(red[i]);
                     }
                     break;
                  default:
                     gl_problem(ctx, "bad format in glReadPixels\n");
               }
	    }
	    break;
	 case GL_BYTE:
            {
               GLbyte *dst = (GLbyte *) gl_pixel_addr_in_image(&ctx->Pack,
                             pixels, width, height, format, type, 0, j, 0);
               switch (format) {
                  case GL_RED:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_BYTE(red[i]);
                     break;
                  case GL_GREEN:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_BYTE(green[i]);
                     break;
                  case GL_BLUE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_BYTE(blue[i]);
                     break;
                  case GL_ALPHA:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_BYTE(alpha[i]);
                     break;
                  case GL_LUMINANCE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_BYTE(luminance[i]);
                     break;
                  case GL_LUMINANCE_ALPHA:
                     for (i=0;i<width;i++) {
                        dst[i*2+0] = FLOAT_TO_BYTE(luminance[i]);
                        dst[i*2+1] = FLOAT_TO_BYTE(alpha[i]);
                     }
                     break;
                  case GL_RGB:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_BYTE(red[i]);
                        dst[i*3+1] = FLOAT_TO_BYTE(green[i]);
                        dst[i*3+2] = FLOAT_TO_BYTE(blue[i]);
                     }
                     break;
                  case GL_RGBA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_BYTE(red[i]);
                        dst[i*4+1] = FLOAT_TO_BYTE(green[i]);
                        dst[i*4+2] = FLOAT_TO_BYTE(blue[i]);
                        dst[i*4+3] = FLOAT_TO_BYTE(alpha[i]);
                     }
                     break;
                  case GL_BGR:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_BYTE(blue[i]);
                        dst[i*3+1] = FLOAT_TO_BYTE(green[i]);
                        dst[i*3+2] = FLOAT_TO_BYTE(red[i]);
                     }
                     break;
                  case GL_BGRA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_BYTE(blue[i]);
                        dst[i*4+1] = FLOAT_TO_BYTE(green[i]);
                        dst[i*4+2] = FLOAT_TO_BYTE(red[i]);
                        dst[i*4+3] = FLOAT_TO_BYTE(alpha[i]);
                     }
                  case GL_ABGR_EXT:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_BYTE(alpha[i]);
                        dst[i*4+1] = FLOAT_TO_BYTE(blue[i]);
                        dst[i*4+2] = FLOAT_TO_BYTE(green[i]);
                        dst[i*4+3] = FLOAT_TO_BYTE(red[i]);
                     }
                     break;
                  default:
                     gl_problem(ctx, "bad format in glReadPixels\n");
               }
            }
	    break;
	 case GL_UNSIGNED_SHORT:
            {
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               switch (format) {
                  case GL_RED:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_USHORT(red[i]);
                     break;
                  case GL_GREEN:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_USHORT(green[i]);
                     break;
                  case GL_BLUE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_USHORT(blue[i]);
                     break;
                  case GL_ALPHA:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_USHORT(alpha[i]);
                     break;
                  case GL_LUMINANCE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_USHORT(luminance[i]);
                     break;
                  case GL_LUMINANCE_ALPHA:
                     for (i=0;i<width;i++) {
                        dst[i*2+0] = FLOAT_TO_USHORT(luminance[i]);
                        dst[i*2+1] = FLOAT_TO_USHORT(alpha[i]);
                     }
                     break;
                  case GL_RGB:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_USHORT(red[i]);
                        dst[i*3+1] = FLOAT_TO_USHORT(green[i]);
                        dst[i*3+2] = FLOAT_TO_USHORT(blue[i]);
                     }
                     break;
                  case GL_RGBA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_USHORT(red[i]);
                        dst[i*4+1] = FLOAT_TO_USHORT(green[i]);
                        dst[i*4+2] = FLOAT_TO_USHORT(blue[i]);
                        dst[i*4+3] = FLOAT_TO_USHORT(alpha[i]);
                     }
                     break;
                  case GL_BGR:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_USHORT(blue[i]);
                        dst[i*3+1] = FLOAT_TO_USHORT(green[i]);
                        dst[i*3+2] = FLOAT_TO_USHORT(red[i]);
                     }
                     break;
                  case GL_BGRA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_USHORT(blue[i]);
                        dst[i*4+1] = FLOAT_TO_USHORT(green[i]);
                        dst[i*4+2] = FLOAT_TO_USHORT(red[i]);
                        dst[i*4+3] = FLOAT_TO_USHORT(alpha[i]);
                     }
                     break;
                  case GL_ABGR_EXT:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_USHORT(alpha[i]);
                        dst[i*4+1] = FLOAT_TO_USHORT(blue[i]);
                        dst[i*4+2] = FLOAT_TO_USHORT(green[i]);
                        dst[i*4+3] = FLOAT_TO_USHORT(red[i]);
                     }
                     break;
                  default:
                     gl_problem(ctx, "bad format in glReadPixels\n");
               }
               if (ctx->Pack.SwapBytes) {
                  gl_swap2( (GLushort *) dst, width * comps_per_pixel );
               }
            }
	    break;
	 case GL_SHORT:
            {
               GLshort *dst = (GLshort *) gl_pixel_addr_in_image(&ctx->Pack,
                              pixels, width, height, format, type, 0, j, 0);
               switch (format) {
                  case GL_RED:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_SHORT(red[i]);
                     break;
                  case GL_GREEN:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_SHORT(green[i]);
                     break;
                  case GL_BLUE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_SHORT(blue[i]);
                     break;
                  case GL_ALPHA:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_SHORT(alpha[i]);
                     break;
                  case GL_LUMINANCE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_SHORT(luminance[i]);
                     break;
                  case GL_LUMINANCE_ALPHA:
                     for (i=0;i<width;i++) {
                        dst[i*2+0] = FLOAT_TO_SHORT(luminance[i]);
                        dst[i*2+1] = FLOAT_TO_SHORT(alpha[i]);
                     }
                     break;
                  case GL_RGB:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_SHORT(red[i]);
                        dst[i*3+1] = FLOAT_TO_SHORT(green[i]);
                        dst[i*3+2] = FLOAT_TO_SHORT(blue[i]);
                     }
                     break;
                  case GL_RGBA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_SHORT(red[i]);
                        dst[i*4+1] = FLOAT_TO_SHORT(green[i]);
                        dst[i*4+2] = FLOAT_TO_SHORT(blue[i]);
                        dst[i*4+3] = FLOAT_TO_SHORT(alpha[i]);
                     }
                     break;
                  case GL_BGR:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_SHORT(blue[i]);
                        dst[i*3+1] = FLOAT_TO_SHORT(green[i]);
                        dst[i*3+2] = FLOAT_TO_SHORT(red[i]);
                     }
                     break;
                  case GL_BGRA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_SHORT(blue[i]);
                        dst[i*4+1] = FLOAT_TO_SHORT(green[i]);
                        dst[i*4+2] = FLOAT_TO_SHORT(red[i]);
                        dst[i*4+3] = FLOAT_TO_SHORT(alpha[i]);
                     }
                  case GL_ABGR_EXT:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_SHORT(alpha[i]);
                        dst[i*4+1] = FLOAT_TO_SHORT(blue[i]);
                        dst[i*4+2] = FLOAT_TO_SHORT(green[i]);
                        dst[i*4+3] = FLOAT_TO_SHORT(red[i]);
                     }
                     break;
                  default:
                     gl_problem(ctx, "bad format in glReadPixels\n");
               }
               if (ctx->Pack.SwapBytes) {
                  gl_swap2( (GLushort *) dst, width * comps_per_pixel );
               }
            }
	    break;
	 case GL_UNSIGNED_INT:
            {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                             pixels, width, height, format, type, 0, j, 0);
               switch (format) {
                  case GL_RED:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UINT(red[i]);
                     break;
                  case GL_GREEN:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UINT(green[i]);
                     break;
                  case GL_BLUE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UINT(blue[i]);
                     break;
                  case GL_ALPHA:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UINT(alpha[i]);
                     break;
                  case GL_LUMINANCE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_UINT(luminance[i]);
                     break;
                  case GL_LUMINANCE_ALPHA:
                     for (i=0;i<width;i++) {
                        dst[i*2+0] = FLOAT_TO_UINT(luminance[i]);
                        dst[i*2+1] = FLOAT_TO_UINT(alpha[i]);
                     }
                     break;
                  case GL_RGB:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_UINT(red[i]);
                        dst[i*3+1] = FLOAT_TO_UINT(green[i]);
                        dst[i*3+2] = FLOAT_TO_UINT(blue[i]);
                     }
                     break;
                  case GL_RGBA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_UINT(red[i]);
                        dst[i*4+1] = FLOAT_TO_UINT(green[i]);
                        dst[i*4+2] = FLOAT_TO_UINT(blue[i]);
                        dst[i*4+3] = FLOAT_TO_UINT(alpha[i]);
                     }
                     break;
                  case GL_BGR:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_UINT(blue[i]);
                        dst[i*3+1] = FLOAT_TO_UINT(green[i]);
                        dst[i*3+2] = FLOAT_TO_UINT(red[i]);
                     }
                     break;
                  case GL_BGRA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_UINT(blue[i]);
                        dst[i*4+1] = FLOAT_TO_UINT(green[i]);
                        dst[i*4+2] = FLOAT_TO_UINT(red[i]);
                        dst[i*4+3] = FLOAT_TO_UINT(alpha[i]);
                     }
                     break;
                  case GL_ABGR_EXT:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_UINT(alpha[i]);
                        dst[i*4+1] = FLOAT_TO_UINT(blue[i]);
                        dst[i*4+2] = FLOAT_TO_UINT(green[i]);
                        dst[i*4+3] = FLOAT_TO_UINT(red[i]);
                     }
                     break;
                  default:
                     gl_problem(ctx, "bad format in glReadPixels\n");
               }
               if (ctx->Pack.SwapBytes) {
                  gl_swap4( (GLuint *) dst, width * comps_per_pixel );
               }
            }
	    break;
	 case GL_INT:
	    {
               GLint *dst = (GLint *) gl_pixel_addr_in_image(&ctx->Pack,
                            pixels, width, height, format, type, 0, j, 0);
               switch (format) {
                  case GL_RED:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_INT(red[i]);
                     break;
                  case GL_GREEN:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_INT(green[i]);
                     break;
                  case GL_BLUE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_INT(blue[i]);
                     break;
                  case GL_ALPHA:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_INT(alpha[i]);
                     break;
                  case GL_LUMINANCE:
                     for (i=0;i<width;i++)
                        dst[i] = FLOAT_TO_INT(luminance[i]);
                     break;
                  case GL_LUMINANCE_ALPHA:
                     for (i=0;i<width;i++) {
                        dst[i*2+0] = FLOAT_TO_INT(luminance[i]);
                        dst[i*2+1] = FLOAT_TO_INT(alpha[i]);
                     }
                     break;
                  case GL_RGB:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_INT(red[i]);
                        dst[i*3+1] = FLOAT_TO_INT(green[i]);
                        dst[i*3+2] = FLOAT_TO_INT(blue[i]);
                     }
                     break;
                  case GL_RGBA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_INT(red[i]);
                        dst[i*4+1] = FLOAT_TO_INT(green[i]);
                        dst[i*4+2] = FLOAT_TO_INT(blue[i]);
                        dst[i*4+3] = FLOAT_TO_INT(alpha[i]);
                     }
                     break;
                  case GL_BGR:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = FLOAT_TO_INT(blue[i]);
                        dst[i*3+1] = FLOAT_TO_INT(green[i]);
                        dst[i*3+2] = FLOAT_TO_INT(red[i]);
                     }
                     break;
                  case GL_BGRA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_INT(blue[i]);
                        dst[i*4+1] = FLOAT_TO_INT(green[i]);
                        dst[i*4+2] = FLOAT_TO_INT(red[i]);
                        dst[i*4+3] = FLOAT_TO_INT(alpha[i]);
                     }
                     break;
                  case GL_ABGR_EXT:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = FLOAT_TO_INT(alpha[i]);
                        dst[i*4+1] = FLOAT_TO_INT(blue[i]);
                        dst[i*4+2] = FLOAT_TO_INT(green[i]);
                        dst[i*4+3] = FLOAT_TO_INT(red[i]);
                     }
                     break;
                  default:
                     gl_problem(ctx, "bad format in glReadPixels\n");
               }
	       if (ctx->Pack.SwapBytes) {
		  gl_swap4( (GLuint *) dst, width * comps_per_pixel );
	       }
	    }
	    break;
	 case GL_FLOAT:
	    {
               GLfloat *dst = (GLfloat *) gl_pixel_addr_in_image(&ctx->Pack,
                              pixels, width, height, format, type, 0, j, 0);
               switch (format) {
                  case GL_RED:
                     for (i=0;i<width;i++)
                        dst[i] = red[i];
                     break;
                  case GL_GREEN:
                     for (i=0;i<width;i++)
                        dst[i] = green[i];
                     break;
                  case GL_BLUE:
                     for (i=0;i<width;i++)
                        dst[i] = blue[i];
                     break;
                  case GL_ALPHA:
                     for (i=0;i<width;i++)
                        dst[i] = alpha[i];
                     break;
                  case GL_LUMINANCE:
                     for (i=0;i<width;i++)
                        dst[i] = luminance[i];
                     break;
                  case GL_LUMINANCE_ALPHA:
                     for (i=0;i<width;i++) {
                        dst[i*2+0] = luminance[i];
                        dst[i*2+1] = alpha[i];
                     }
                     break;
                  case GL_RGB:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = red[i];
                        dst[i*3+1] = green[i];
                        dst[i*3+2] = blue[i];
                     }
                     break;
                  case GL_RGBA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = red[i];
                        dst[i*4+1] = green[i];
                        dst[i*4+2] = blue[i];
                        dst[i*4+3] = alpha[i];
                     }
                     break;
                  case GL_BGR:
                     for (i=0;i<width;i++) {
                        dst[i*3+0] = blue[i];
                        dst[i*3+1] = green[i];
                        dst[i*3+2] = red[i];
                     }
                     break;
                  case GL_BGRA:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = blue[i];
                        dst[i*4+1] = green[i];
                        dst[i*4+2] = red[i];
                        dst[i*4+3] = alpha[i];
                     }
                     break;
                  case GL_ABGR_EXT:
                     for (i=0;i<width;i++) {
                        dst[i*4+0] = alpha[i];
                        dst[i*4+1] = blue[i];
                        dst[i*4+2] = green[i];
                        dst[i*4+3] = red[i];
                     }
                     break;
                  default:
                     gl_problem(ctx, "bad format in glReadPixels\n");
               }
	       if (ctx->Pack.SwapBytes) {
		  gl_swap4( (GLuint *) dst, width * comps_per_pixel );
	       }
	    }
	    break;
         case GL_UNSIGNED_BYTE_3_3_2:
            if (format == GL_RGB) {
               GLubyte *dst = (GLubyte *) gl_pixel_addr_in_image(&ctx->Pack,
                              pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLint) (red[i]   * 7.0F)) << 5)
                         | (((GLint) (green[i] * 7.0F)) << 2)
                         | (((GLint) (blue[i]  * 3.0F))     );
               }
            }
            break;
         case GL_UNSIGNED_BYTE_2_3_3_REV:
            if (format == GL_RGB) {
               GLubyte *dst = (GLubyte *) gl_pixel_addr_in_image(&ctx->Pack,
                              pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLint) (red[i]   * 7.0F))     )
                         | (((GLint) (green[i] * 7.0F)) << 3)
                         | (((GLint) (blue[i]  * 3.0F)) << 5);
               }
            }
            break;
         case GL_UNSIGNED_SHORT_5_6_5:
            if (format == GL_RGB) {
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLint) (red[i]   * 31.0F)) << 11)
                         | (((GLint) (green[i] * 63.0F)) <<  5)
                         | (((GLint) (blue[i]  * 31.0F))      );
               }
            }
            break;
         case GL_UNSIGNED_SHORT_5_6_5_REV:
            if (format == GL_RGB) {
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLint) (red[i]   * 31.0F))      )
                         | (((GLint) (green[i] * 63.0F)) <<  5)
                         | (((GLint) (blue[i]  * 31.0F)) << 11);
               }
            }
            break;
         case GL_UNSIGNED_SHORT_4_4_4_4:
            if (format == GL_RGB) {
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLint) (red[i]   * 15.0F)) << 12)
                         | (((GLint) (green[i] * 15.0F)) <<  8)
                         | (((GLint) (blue[i]  * 15.0F)) <<  4)
                         | (((GLint) (alpha[i] * 15.0F))      );
               }
            }
            break;
         case GL_UNSIGNED_SHORT_4_4_4_4_REV:
            if (format == GL_RGB) {
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLint) (red[i]   * 15.0F))      )
                         | (((GLint) (green[i] * 15.0F)) <<  4)
                         | (((GLint) (blue[i]  * 15.0F)) <<  8)
                         | (((GLint) (alpha[i] * 15.0F)) << 12);
               }
            }
            break;
         case GL_UNSIGNED_SHORT_5_5_5_1:
            if (format == GL_RGB) {
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLint) (red[i]   * 31.0F)) << 11)
                         | (((GLint) (green[i] * 31.0F)) <<  6)
                         | (((GLint) (blue[i]  * 31.0F)) <<  1)
                         | (((GLint) (alpha[i] *  1.0F))      );
               }
            }
            break;
         case GL_UNSIGNED_SHORT_1_5_5_5_REV:
            if (format == GL_RGB) {
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLint) (red[i]   * 31.0F))      )
                         | (((GLint) (green[i] * 31.0F)) <<  5)
                         | (((GLint) (blue[i]  * 31.0F)) << 10)
                         | (((GLint) (alpha[i] *  1.0F)) << 15);
               }
            }
            break;
         case GL_UNSIGNED_INT_8_8_8_8:
            if (format == GL_RGBA) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                             pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (red[i]   * 255.0F)) << 24)
                         | (((GLuint) (green[i] * 255.0F)) << 16)
                         | (((GLuint) (blue[i]  * 255.0F)) <<  8)
                         | (((GLuint) (alpha[i] * 255.0F))      );
               }
            }
            else if (format == GL_BGRA) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (blue[i]  * 255.0F)) << 24)
                         | (((GLuint) (green[i] * 255.0F)) << 16)
                         | (((GLuint) (red[i]   * 255.0F)) <<  8)
                         | (((GLuint) (alpha[i] * 255.0F))      );
               }
            }
            else if (format == GL_ABGR_EXT) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (alpha[i] * 255.0F)) << 24)
                         | (((GLuint) (blue[i]  * 255.0F)) << 16)
                         | (((GLuint) (green[i] * 255.0F)) <<  8)
                         | (((GLuint) (red[i]   * 255.0F))      );
               }
            }
            break;
         case GL_UNSIGNED_INT_8_8_8_8_REV:
            if (format == GL_RGBA) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                             pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (red[i]   * 255.0F))      )
                         | (((GLuint) (green[i] * 255.0F)) <<  8)
                         | (((GLuint) (blue[i]  * 255.0F)) << 16)
                         | (((GLuint) (alpha[i] * 255.0F)) << 24);
               }
            }
            else if (format == GL_BGRA) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (blue[i]  * 255.0F))      )
                         | (((GLuint) (green[i] * 255.0F)) <<  8)
                         | (((GLuint) (red[i]   * 255.0F)) << 16)
                         | (((GLuint) (alpha[i] * 255.0F)) << 24);
               }
            }
            else if (format == GL_ABGR_EXT) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (alpha[i] * 255.0F))      )
                         | (((GLuint) (blue[i]  * 255.0F)) <<  8)
                         | (((GLuint) (green[i] * 255.0F)) << 16)
                         | (((GLuint) (red[i]   * 255.0F)) << 24);
               }
            }
            break;
         case GL_UNSIGNED_INT_10_10_10_2:
            if (format == GL_RGBA) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                             pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (red[i]   * 1023.0F)) << 22)
                         | (((GLuint) (green[i] * 1023.0F)) << 12)
                         | (((GLuint) (blue[i]  * 1023.0F)) <<  2)
                         | (((GLuint) (alpha[i] *    3.0F))      );
               }
            }
            else if (format == GL_BGRA) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (blue[i]  * 1023.0F)) << 22)
                         | (((GLuint) (green[i] * 1023.0F)) << 12)
                         | (((GLuint) (red[i]   * 1023.0F)) <<  2)
                         | (((GLuint) (alpha[i] *    3.0F))      );
               }
            }
            else if (format == GL_ABGR_EXT) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (alpha[i] * 1023.0F)) << 22)
                         | (((GLuint) (blue[i]  * 1023.0F)) << 12)
                         | (((GLuint) (green[i] * 1023.0F)) <<  2)
                         | (((GLuint) (red[i]   *    3.0F))      );
               }
            }
            break;
         case GL_UNSIGNED_INT_2_10_10_10_REV:
            if (format == GL_RGBA) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                             pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (red[i]   * 1023.0F))      )
                         | (((GLuint) (green[i] * 1023.0F)) << 10)
                         | (((GLuint) (blue[i]  * 1023.0F)) << 20)
                         | (((GLuint) (alpha[i] *    3.0F)) << 30);
               }
            }
            else if (format == GL_BGRA) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (blue[i]  * 1023.0F))      )
                         | (((GLuint) (green[i] * 1023.0F)) << 10)
                         | (((GLuint) (red[i]   * 1023.0F)) << 20)
                         | (((GLuint) (alpha[i] *    3.0F)) << 30);
               }
            }
            else if (format == GL_ABGR_EXT) {
               GLuint *dst = (GLuint *) gl_pixel_addr_in_image(&ctx->Pack,
                               pixels, width, height, format, type, 0, j, 0);
               for (i=0;i<width;i++) {
                  dst[i] = (((GLuint) (alpha[i] * 1023.0F))      )
                         | (((GLuint) (blue[i]  * 1023.0F)) << 10)
                         | (((GLuint) (green[i] * 1023.0F)) << 20)
                         | (((GLuint) (red[i]   *    3.0F)) << 30);
               }
            }
            break;
         default:
            gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
d615 2
a616 4
cleanup:
   UNDEFARRAY( blue );
   UNDEFARRAY( alpha );
   UNDEFARRAY( luminance );
a631 2
   (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.DriverReadBuffer );

d634 1
a634 1
         read_index_pixels( ctx, x, y, width, height, type, pixels );
d637 1
a637 1
	 read_stencil_pixels( ctx, x, y, width, height, type, pixels );
d640 1
a640 1
	 read_depth_pixels( ctx, x, y, width, height, type, pixels );
d653 1
a653 3
         if (!read_fast_rgba_pixels( ctx, x, y, width, height,
                                     format, type, pixels))
            read_rgba_pixels( ctx, x, y, width, height, format, type, pixels );
a657 2

   (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DriverDrawBuffer );
@


3.16
log
@Better DEFARRAY handling.
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.15 1999/06/13 15:36:15 brianp Exp $ */
d529 1
a529 1
   GLfloat blue[MAX_WIDTH];
d532 1
d1379 1
@


3.15
log
@fixed bugs in GL_UNSIGNED_INT_* packed format code
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.14 1999/03/28 20:56:15 brianp Exp $ */
d527 7
a533 6
   DEFARRAY(GLfloat, red, MAX_WIDTH);
   DEFARRAY(GLfloat, green, MAX_WIDTH);
   DEFARRAY(GLfloat, blue, MAX_WIDTH);
   DEFARRAY(GLfloat, alpha, MAX_WIDTH);
   DEFARRAY(GLfloat, luminance, MAX_WIDTH);

d559 1
a559 1
         return;
d1377 1
a1377 3
   UNDEFARRAY( red );
   UNDEFARRAY( green );
   UNDEFARRAY( blue );
@


3.14
log
@better handling of multi draw buffers, software alpha buffers
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.13 1999/02/25 14:12:31 keithw Exp $ */
d1249 4
a1252 4
                  dst[i] = (((GLint) (red[i]   * 255.0F)) << 24)
                         | (((GLint) (green[i] * 255.0F)) << 16)
                         | (((GLint) (blue[i]  * 255.0F)) <<  8)
                         | (((GLint) (alpha[i] * 255.0F))      );
d1256 1
a1256 1
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
d1259 4
a1262 4
                  dst[i] = (((GLint) (blue[i]  * 255.0F)) << 24)
                         | (((GLint) (green[i] * 255.0F)) << 16)
                         | (((GLint) (red[i]   * 255.0F)) <<  8)
                         | (((GLint) (alpha[i] * 255.0F))      );
d1266 1
a1266 1
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
d1269 4
a1272 4
                  dst[i] = (((GLint) (alpha[i] * 255.0F)) << 24)
                         | (((GLint) (blue[i]  * 255.0F)) << 16)
                         | (((GLint) (green[i] * 255.0F)) <<  8)
                         | (((GLint) (red[i]   * 255.0F))      );
d1281 4
a1284 4
                  dst[i] = (((GLint) (red[i]   * 255.0F))      )
                         | (((GLint) (green[i] * 255.0F)) <<  8)
                         | (((GLint) (blue[i]  * 255.0F)) << 16)
                         | (((GLint) (alpha[i] * 255.0F)) << 24);
d1288 1
a1288 1
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
d1291 4
a1294 4
                  dst[i] = (((GLint) (blue[i]  * 255.0F))      )
                         | (((GLint) (green[i] * 255.0F)) <<  8)
                         | (((GLint) (red[i]   * 255.0F)) << 16)
                         | (((GLint) (alpha[i] * 255.0F)) << 24);
d1298 1
a1298 1
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
d1301 4
a1304 4
                  dst[i] = (((GLint) (alpha[i] * 255.0F))      )
                         | (((GLint) (blue[i]  * 255.0F)) <<  8)
                         | (((GLint) (green[i] * 255.0F)) << 16)
                         | (((GLint) (red[i]   * 255.0F)) << 24);
d1313 4
a1316 4
                  dst[i] = (((GLint) (red[i]   * 1023.0F)) << 22)
                         | (((GLint) (green[i] * 1023.0F)) << 12)
                         | (((GLint) (blue[i]  * 1023.0F)) <<  2)
                         | (((GLint) (alpha[i] *    3.0F))      );
d1320 1
a1320 1
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
d1323 4
a1326 4
                  dst[i] = (((GLint) (blue[i]  * 1023.0F)) << 22)
                         | (((GLint) (green[i] * 1023.0F)) << 12)
                         | (((GLint) (red[i]   * 1023.0F)) <<  2)
                         | (((GLint) (alpha[i] *    3.0F))      );
d1330 1
a1330 1
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
d1333 4
a1336 4
                  dst[i] = (((GLint) (alpha[i] * 1023.0F)) << 22)
                         | (((GLint) (blue[i]  * 1023.0F)) << 12)
                         | (((GLint) (green[i] * 1023.0F)) <<  2)
                         | (((GLint) (red[i]   *    3.0F))      );
d1345 4
a1348 4
                  dst[i] = (((GLint) (red[i]   * 1023.0F))      )
                         | (((GLint) (green[i] * 1023.0F)) << 10)
                         | (((GLint) (blue[i]  * 1023.0F)) << 20)
                         | (((GLint) (alpha[i] *    3.0F)) << 30);
d1352 1
a1352 1
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
d1355 4
a1358 4
                  dst[i] = (((GLint) (blue[i]  * 1023.0F))      )
                         | (((GLint) (green[i] * 1023.0F)) << 10)
                         | (((GLint) (red[i]   * 1023.0F)) << 20)
                         | (((GLint) (alpha[i] *    3.0F)) << 30);
d1362 1
a1362 1
               GLushort *dst = (GLushort *) gl_pixel_addr_in_image(&ctx->Pack,
d1365 4
a1368 4
                  dst[i] = (((GLint) (alpha[i] * 1023.0F))      )
                         | (((GLint) (blue[i]  * 1023.0F)) << 10)
                         | (((GLint) (green[i] * 1023.0F)) << 20)
                         | (((GLint) (red[i]   *    3.0F)) << 30);
@


3.13
log
@Merged in kw3 patch
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.12 1999/02/24 22:48:07 jens Exp $ */
d1396 1
a1396 1
   (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.ReadBuffer );
d1427 1
a1427 1
   (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DrawBuffer );
@


3.12
log
@Added header file to get XMesa to compile standalone and inside XFree86
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.11 1999/02/14 03:46:34 brianp Exp $ */
d28 1
a28 39
/*
 * $Log: readpix.c,v $
 * Revision 3.11  1999/02/14 03:46:34  brianp
 * new copyright
 *
 * Revision 3.10  1999/01/22 04:30:44  brianp
 * fixed bugs related to packed pixel formats
 *
 * Revision 3.9  1998/10/03 13:22:40  brianp
 * stencil-related clean ups
 *
 * Revision 3.8  1998/08/04 02:47:49  brianp
 * clipping in read_fast_rgba_pixels() off by one (Randy Frank)
 *
 * Revision 3.7  1998/07/18 03:34:24  brianp
 * GL_ALPHA format was missing
 *
 * Revision 3.6  1998/07/17 03:24:16  brianp
 * added Pixel.ScaleOrBiasRGBA field
 *
 * Revision 3.5  1998/03/27 04:17:52  brianp
 * fixed G++ warnings
 *
 * Revision 3.4  1998/03/15 18:50:25  brianp
 * added GL_EXT_abgr extension
 *
 * Revision 3.3  1998/02/08 20:22:14  brianp
 * LOTS of clean-up and rewriting
 *
 * Revision 3.2  1998/02/01 22:29:09  brianp
 * added support for packed pixel formats
 *
 * Revision 3.1  1998/02/01 20:47:42  brianp
 * added GL_BGR and GL_BGRA pixel formats
 *
 * Revision 3.0  1998/01/31 21:02:29  brianp
 * initial rev
 *
 */
d1389 1
a1389 4
   if (INSIDE_BEGIN_END(ctx)) {
      gl_error( ctx, GL_INVALID_OPERATION, "glReadPixels" );
      return;
   }
@


3.11
log
@new copyright
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.10 1999/01/22 04:30:44 brianp Exp brianp $ */
d30 3
d85 3
@


3.10
log
@fixed bugs related to packed pixel formats
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.9 1998/10/03 13:22:40 brianp Exp brianp $ */
d6 19
a24 15
 * Copyright (C) 1995-1999  Brian Paul
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d30 3
@


3.9
log
@stencil-related clean ups
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.8 1998/08/04 02:47:49 brianp Exp brianp $ */
d6 1
a6 1
 * Copyright (C) 1995-1998  Brian Paul
d26 3
d551 1
a551 1
   GLint i, j, n, s;
d558 26
a583 10
   /* number of components */
   n = gl_components_in_format(format);
   if (n <= 0) {
      gl_error(ctx, GL_INVALID_ENUM, "glReadPixels(format)");
      UNDEFARRAY( red );
      UNDEFARRAY( green );
      UNDEFARRAY( blue );
      UNDEFARRAY( alpha );
      UNDEFARRAY( luminance );
      return;
d586 1
a586 11
   /* Size of each component */
   s = gl_sizeof_type( type );
   if (s <= 0) {
      gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
      UNDEFARRAY( red );
      UNDEFARRAY( green );
      UNDEFARRAY( blue );
      UNDEFARRAY( alpha );
      UNDEFARRAY( luminance );
      return;
   }
d866 1
a866 1
                  gl_swap2( (GLushort *) dst, width*n );
d942 1
a942 1
                  gl_swap2( (GLushort *) dst, width*n );
d1019 1
a1019 1
                  gl_swap4( (GLuint *) dst, width*n );
d1096 1
a1096 1
		  gl_swap4( (GLuint *) dst, width*n );
d1173 1
a1173 1
		  gl_swap4( (GLuint *) dst, width*n );
@


3.8
log
@clipping in read_fast_rgba_pixels() off by one (Randy Frank)
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.7 1998/07/18 03:34:24 brianp Exp brianp $ */
d5 1
a5 1
 * Version:  3.0
d26 3
d356 1
a356 1
      GLubyte stencil[MAX_WIDTH];
d373 9
a381 1
            MEMCPY( dest, stencil, width );
d384 9
a392 1
            MEMCPY( dest, stencil, width );
@


3.7
log
@GL_ALPHA format was missing
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.6 1998/07/17 03:24:16 brianp Exp brianp $ */
d26 3
d478 1
a478 1
         readWidth -= (srcX + readWidth - ctx->Buffer->Xmax);
d489 1
a489 1
         readHeight -= (srcY + readHeight - ctx->Buffer->Ymax);
@


3.6
log
@added Pixel.ScaleOrBiasRGBA field
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.5 1998/03/27 04:17:52 brianp Exp brianp $ */
d26 3
d632 4
d706 4
d779 4
d856 4
d932 4
d1009 4
d1085 4
@


3.5
log
@fixed G++ warnings
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.4 1998/03/15 18:50:25 brianp Exp brianp $ */
d26 3
a432 17
 * Test if scaling or biasing of colors is needed.
 */
static GLboolean scale_or_bias_rgba( GLcontext *ctx )
{
   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) {
      return GL_TRUE;
   }
   else {
      return GL_FALSE;
   }
}


/*
d444 1
a444 1
   if (scale_or_bias_rgba(ctx) || ctx->Pixel.MapColorFlag)
a523 1
   GLboolean scale_or_bias;
a529 2
   scale_or_bias = scale_or_bias_rgba( ctx );

d576 1
a576 1
	 if (scale_or_bias) {
d604 5
@


3.4
log
@added GL_EXT_abgr extension
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.3 1998/02/08 20:22:14 brianp Exp brianp $ */
d26 3
d200 1
a200 1
         GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
d216 1
a216 1
         GLuint *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
d626 2
a627 2
               GLubyte *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                 width, height, format, type, 0, j, 0);
d696 2
a697 2
               GLbyte *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d765 2
a766 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d838 2
a839 2
               GLshort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d910 2
a911 2
               GLuint *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d983 2
a984 2
               GLint *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1056 2
a1057 2
               GLfloat *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1129 2
a1130 2
               GLubyte *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1140 2
a1141 2
               GLubyte *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1151 2
a1152 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1162 2
a1163 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1173 2
a1174 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1185 2
a1186 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1197 2
a1198 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1209 2
a1210 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1221 2
a1222 2
               GLuint *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1231 2
a1232 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1241 2
a1242 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1253 2
a1254 2
               GLuint *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1263 2
a1264 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1273 2
a1274 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1285 2
a1286 2
               GLuint *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1295 2
a1296 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1305 2
a1306 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1317 2
a1318 2
               GLuint *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1327 2
a1328 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
d1337 2
a1338 2
               GLushort *dst = gl_pixel_addr_in_image(&ctx->Pack, pixels,
                                width, height, format, type, 0, j, 0);
@


3.3
log
@LOTS of clean-up and rewriting
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.2 1998/02/01 22:29:09 brianp Exp brianp $ */
d26 3
d678 8
d747 7
d817 8
d889 7
d962 8
d1035 8
d1108 8
d1237 10
d1269 10
d1301 10
d1333 10
d1393 1
@


3.2
log
@added support for packed pixel formats
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.1 1998/02/01 20:47:42 brianp Exp brianp $ */
d26 3
d49 1
a67 1
   GLuint a, s, k, l, start;
a74 26
   /* Size of each component */
   s = gl_sizeof_type( type );
   if (s<=0) {
      gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
      return;
   }

   /* Compute packing parameters */
   a = ctx->Pack.Alignment;
   if (ctx->Pack.RowLength>0) {
      l = ctx->Pack.RowLength;
   }
   else {
      l = width;
   }
   /* k = offset between rows in components */
   if (s>=a) {
      k = l;
   }
   else {
      k = a/s * CEILING( s*l, a );
   }

   /* offset to first component returned */
   start = ctx->Pack.SkipRows * k + ctx->Pack.SkipPixels;

d78 2
d83 1
a83 15
	 GLuint s;
	 if (ctx->Pixel.IndexShift<0) {
	    /* right shift */
	    s = -ctx->Pixel.IndexShift;
	    for (i=0;i<width;i++) {
	       index[i] = (index[i] >> s) + ctx->Pixel.IndexOffset;
	    }
	 }
	 else {
	    /* left shift */
	    s = ctx->Pixel.IndexShift;
	    for (i=0;i<width;i++) {
	       index[i] = (index[i] << s) + ctx->Pixel.IndexOffset;
	    }
	 }
d87 1
a87 3
	 for (i=0;i<width;i++) {
	    index[i] = ctx->Pixel.MapItoI[ index[i] ];
	 }
d90 3
d96 1
a96 1
	       GLubyte *dst = (GLubyte *) pixels + start + j * k;
d104 1
a104 1
	       GLbyte *dst = (GLbyte *) pixels + start + j * k;
d106 1
a106 1
		  *dst++ = (GLbyte) index[i];
d112 1
a112 1
	       GLushort *dst = (GLushort *) pixels + start + j * k;
d114 1
a114 1
		  *dst++ = (GLushort) index[i];
d117 1
a117 1
		  gl_swap2( (GLushort *) pixels + start + j * k, width );
d123 1
a123 1
	       GLshort *dst = (GLshort *) pixels + start + j * k;
d125 1
a125 1
		  *dst++ = (GLshort) index[i];
d128 1
a128 1
		  gl_swap2( (GLushort *) pixels + start + j * k, width );
d134 1
a134 1
	       GLuint *dst = (GLuint *) pixels + start + j * k;
d136 1
a136 1
		  *dst++ = (GLuint) index[i];
d139 1
a139 1
		  gl_swap4( (GLuint *) pixels + start + j * k, width );
d145 1
a145 1
	       GLint *dst = (GLint *) pixels + start + j * k;
d147 1
a147 1
		  *dst++ = (GLint) index[i];
d150 1
a150 1
		  gl_swap4( (GLuint *) pixels + start + j * k, width );
d156 1
a156 1
	       GLfloat *dst = (GLfloat *) pixels + start + j * k;
d158 1
a158 1
		  *dst++ = (GLfloat) index[i];
d161 1
a161 1
		  gl_swap4( (GLuint *) pixels + start + j * k, width );
a178 1
   GLuint a, s, k, l, start;
d182 1
a182 1
   if (ctx->Visual->DepthBits<=0) {
a189 26
   /* Size of each component */
   s = gl_sizeof_type( type );
   if (s<=0) {
      gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
      return;
   }

   /* Compute packing parameters */
   a = ctx->Pack.Alignment;
   if (ctx->Pack.RowLength>0) {
      l = ctx->Pack.RowLength;
   }
   else {
      l = width;
   }
   /* k = offset between rows in components */
   if (s>=a) {
      k = l;
   }
   else {
      k = a/s * CEILING( s*l, a );
   }

   /* offset to first component returned */
   start = ctx->Pack.SkipRows * k + ctx->Pack.SkipPixels;

d194 2
a195 1
         GLushort *dst = (GLushort *) pixels + start + j * k;
d210 2
a211 1
         GLuint *dst = (GLuint *) pixels + start + j * k;
d222 1
d230 1
a230 1
               depth[i] = CLAMP( d, 0.0, 1.0 );
d234 3
d240 1
a240 1
                  GLubyte *dst = (GLubyte *) pixels + start + j * k;
d242 1
a242 1
                     *dst++ = FLOAT_TO_UBYTE( depth[i] );
d248 1
a248 1
                  GLbyte *dst = (GLbyte *) pixels + start + j * k;
d250 1
a250 1
                     *dst++ = FLOAT_TO_BYTE( depth[i] );
d256 1
a256 1
                  GLushort *dst = (GLushort *) pixels + start + j * k;
d258 1
a258 1
                     *dst++ = FLOAT_TO_USHORT( depth[i] );
d261 1
a261 1
                     gl_swap2( (GLushort *) pixels + start + j * k, width );
d267 1
a267 1
                  GLshort *dst = (GLshort *) pixels + start + j * k;
d269 1
a269 1
                     *dst++ = FLOAT_TO_SHORT( depth[i] );
d272 1
a272 1
                     gl_swap2( (GLushort *) pixels + start + j * k, width );
d278 1
a278 1
                  GLuint *dst = (GLuint *) pixels + start + j * k;
d280 1
a280 1
                     *dst++ = FLOAT_TO_UINT( depth[i] );
d283 1
a283 1
                     gl_swap4( (GLuint *) pixels + start + j * k, width );
d289 1
a289 1
                  GLint *dst = (GLint *) pixels + start + j * k;
d291 1
a291 1
                     *dst++ = FLOAT_TO_INT( depth[i] );
d294 1
a294 1
                     gl_swap4( (GLuint *) pixels + start + j * k, width );
d300 1
a300 1
                  GLfloat *dst = (GLfloat *) pixels + start + j * k;
d302 1
a302 1
                     *dst++ = depth[i];
d305 1
a305 1
                     gl_swap4( (GLuint *) pixels + start + j * k, width );
d324 1
a325 2
   GLuint a, s, k, l, start;
   GLboolean shift_or_offset;
a334 26
   /* Size of each component */
   s = gl_sizeof_type( type );
   if (s<=0) {
      gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(type)" );
      return;
   }

   /* Compute packing parameters */
   a = ctx->Pack.Alignment;
   if (ctx->Pack.RowLength>0) {
      l = ctx->Pack.RowLength;
   }
   else {
      l = width;
   }
   /* k = offset between rows in components */
   if (s>=a) {
      k = l;
   }
   else {
      k = a/s * CEILING( s*l, a );
   }

   /* offset to first component returned */
   start = ctx->Pack.SkipRows * k + ctx->Pack.SkipPixels;

d337 1
d343 1
a343 15
	 GLuint s;
	 if (ctx->Pixel.IndexShift<0) {
	    /* right shift */
	    s = -ctx->Pixel.IndexShift;
	    for (i=0;i<width;i++) {
	       stencil[i] = (stencil[i] >> s) + ctx->Pixel.IndexOffset;
	    }
	 }
	 else {
	    /* left shift */
	    s = ctx->Pixel.IndexShift;
	    for (i=0;i<width;i++) {
	       stencil[i] = (stencil[i] << s) + ctx->Pixel.IndexOffset;
	    }
	 }
d347 1
a347 3
	 for (i=0;i<width;i++) {
	    stencil[i] = ctx->Pixel.MapStoS[ stencil[i] ];
	 }
d350 3
d355 1
a355 4
	    {
	       GLubyte *dst = (GLubyte *) pixels + start + j * k;
	       MEMCPY( dst, stencil, width );
	    }
d358 1
a358 4
	    {
	       GLbyte *dst = (GLbyte  *) pixels + start + j * k;
	       MEMCPY( dst, stencil, width );
	    }
d362 1
a362 1
	       GLushort *dst = (GLushort *) pixels + start + j * k;
d364 1
a364 1
		  *dst++ = (GLushort) stencil[i];
d367 1
a367 1
		  gl_swap2( (GLushort *) pixels + start +j * k, width );
d373 1
a373 1
	       GLshort *dst = (GLshort *) pixels + start + j * k;
d375 1
a375 1
		  *dst++ = (GLshort) stencil[i];
d378 1
a378 1
		  gl_swap2( (GLushort *) pixels + start +j * k, width );
d384 1
a384 1
	       GLuint *dst = (GLuint *) pixels + start + j * k;
d386 1
a386 1
		  *dst++ = (GLuint) stencil[i];
d389 1
a389 1
		  gl_swap4( (GLuint *) pixels + start +j * k, width );
d395 1
a395 1
	       GLint *dst = (GLint *) pixels + start + j * k;
d400 1
a400 1
		  gl_swap4( (GLuint *) pixels + start +j * k, width );
d406 1
a406 1
	       GLfloat *dst = (GLfloat *) pixels + start + j * k;
d408 1
a408 1
		  *dst++ = (GLfloat) stencil[i];
d411 1
a411 1
		  gl_swap4( (GLuint *) pixels + start +j * k, width );
a439 1

d441 3
a443 1
 * Apply scale and bias factors to an array of RGBA pixels.
d445 5
a449 4
static void scale_and_bias_rgba( GLcontext *ctx,
                                 GLint n,
				 GLfloat red[], GLfloat green[],
				 GLfloat blue[], GLfloat alpha[] )
d451 3
a453 2
   register GLint i;
   register GLfloat r, g, b, a;
d455 3
a457 11
   for (i=0;i<n;i++) {
      r = red[i]   * ctx->Pixel.RedScale   + ctx->Pixel.RedBias;
      g = green[i] * ctx->Pixel.GreenScale + ctx->Pixel.GreenBias;
      b = blue[i]  * ctx->Pixel.BlueScale  + ctx->Pixel.BlueBias;
      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 );
   }
}
d459 35
d495 23
a517 20

/*
 * Apply pixel mapping to an array of RGBA pixels.
 */
static void map_rgba( GLcontext *ctx,
                      GLint n,
		      GLfloat red[], GLfloat green[],
		      GLfloat blue[], GLfloat alpha[] )
{
   GLfloat rscale = ctx->Pixel.MapRtoRsize-1;
   GLfloat gscale = ctx->Pixel.MapGtoGsize-1;
   GLfloat bscale = ctx->Pixel.MapBtoBsize-1;
   GLfloat ascale = ctx->Pixel.MapAtoAsize-1;
   GLint i;

   for (i=0;i<n;i++) {
      red[i]   = ctx->Pixel.MapRtoR[ (GLint) (red[i]   * rscale) ];
      green[i] = ctx->Pixel.MapGtoG[ (GLint) (green[i] * gscale) ];
      blue[i]  = ctx->Pixel.MapBtoB[ (GLint) (blue[i]  * bscale) ];
      alpha[i] = ctx->Pixel.MapAtoA[ (GLint) (alpha[i] * ascale) ];
a522 1

d526 4
a529 4
static void read_color_pixels( GLcontext *ctx,
                               GLint x, GLint y,
			       GLsizei width, GLsizei height,
			       GLenum format, GLenum type, GLvoid *pixels )
d588 1
a588 1
	    scale_and_bias_rgba( ctx, width, red, green, blue, alpha );
d591 1
a591 1
	    map_rgba( ctx, width, red, green, blue, alpha );
d600 1
a600 15
	    GLuint s;
	    if (ctx->Pixel.IndexShift<0) {
	       /* right shift */
	       s = -ctx->Pixel.IndexShift;
	       for (i=0;i<width;i++) {
		  index[i] = (index[i] >> s) + ctx->Pixel.IndexOffset;
	       }
	    }
	    else {
	       /* left shift */
	       s = ctx->Pixel.IndexShift;
	       for (i=0;i<width;i++) {
		  index[i] = (index[i] << s) + ctx->Pixel.IndexOffset;
	       }
	    }
d603 1
a603 6
	 for (i=0;i<width;i++) {
	    red[i]   = ctx->Pixel.MapItoR[ index[i] ];
	    green[i] = ctx->Pixel.MapItoG[ index[i] ];
	    blue[i]  = ctx->Pixel.MapItoB[ index[i] ];
	    alpha[i] = ctx->Pixel.MapItoA[ index[i] ];
	 }
d1269 5
d1296 3
a1298 1
	 read_color_pixels( ctx, x, y, width, height, format, type, pixels );
@


3.1
log
@added GL_BGR and GL_BGRA pixel formats
@
text
@d1 1
a1 1
/* $Id: readpix.c,v 3.0 1998/01/31 21:02:29 brianp Exp brianp $ */
d26 3
d599 1
a599 1
   GLint i, j, n, a, s, l, k;
a605 1
   GLuint start;
a632 19
   /* Compute packing parameters */
   a = ctx->Pack.Alignment;
   if (ctx->Pack.RowLength>0) {
      l = ctx->Pack.RowLength;
   }
   else {
      l = width;
   }
   /* k = offset between rows in components */
   if (s>=a) {
      k = n * l;
   }
   else {
      k = a/s * CEILING( s*n*l, a );
   }

   /* offset to first component returned */
   start = ctx->Pack.SkipRows * k + ctx->Pack.SkipPixels * n;

d705 1
a705 1
	 case GL_UNSIGNED_BYTE:
d707 2
a708 1
	       GLubyte *dst = (GLubyte *) pixels + start + j * k;
d769 2
a770 1
	       GLbyte *dst = (GLbyte *) pixels + start + j * k;
d831 2
a832 1
	       GLushort *dst = (GLushort *) pixels + start + j * k;
d890 1
a890 1
                  gl_swap2( (GLushort *) pixels + start + j * k, width*n );
d896 2
a897 1
	       GLshort *dst = (GLshort *) pixels + start + j * k;
d955 1
a955 1
                  gl_swap2( (GLushort *) pixels + start + j * k, width*n );
d961 2
a962 1
	       GLuint *dst = (GLuint *) pixels + start + j * k;
d1020 1
a1020 1
                  gl_swap4( (GLuint *) pixels + start + j * k, width*n );
d1026 2
a1027 1
	       GLint *dst = (GLint *) pixels + start + j * k;
d1085 1
a1085 1
		  gl_swap4( (GLuint *) pixels + start + j * k, width*n );
d1091 2
a1092 1
	       GLfloat *dst = (GLfloat *) pixels + start + j * k;
d1150 1
a1150 1
		  gl_swap4( (GLuint *) pixels + start + j * k, width*n );
d1154 180
@


3.0
log
@initial rev
@
text
@d1 1
a1 1
/* $Id$ */
d25 4
a28 1
 * $Log$
a602 1
   GLboolean r_flag, g_flag, b_flag, a_flag, l_flag;
d607 10
a616 19
   /* Determine how many / which components to return */
   r_flag = g_flag = b_flag = a_flag = l_flag = GL_FALSE;
   switch (format) {
      case GL_RED:				r_flag = GL_TRUE;  n = 1;  break;
      case GL_GREEN:				g_flag = GL_TRUE;  n = 1;  break;
      case GL_BLUE:				b_flag = GL_TRUE;  n = 1;  break;
      case GL_ALPHA:				a_flag = GL_TRUE;  n = 1;  break;
      case GL_LUMINANCE:			l_flag = GL_TRUE;  n = 1;  break;
      case GL_LUMINANCE_ALPHA:	       l_flag = a_flag = GL_TRUE;  n = 2;  break;
      case GL_RGB:	      r_flag = g_flag = b_flag = GL_TRUE;  n = 3;  break;
      case GL_RGBA:  r_flag = g_flag = b_flag = a_flag = GL_TRUE;  n = 4;  break;
      default:
	 gl_error( ctx, GL_INVALID_ENUM, "glReadPixels(format)" );
         UNDEFARRAY( red );
         UNDEFARRAY( green );
         UNDEFARRAY( blue );
         UNDEFARRAY( alpha );
         UNDEFARRAY( luminance );
         return;
d621 1
a621 1
   if (s<=0) {
d710 1
a710 1
      if (l_flag) {
d723 1
a723 1
	    {
d725 56
a780 7
	       for (i=0;i<width;i++) {
		  if (r_flag)  *dst++ = FLOAT_TO_UBYTE( red[i] );
		  if (g_flag)  *dst++ = FLOAT_TO_UBYTE( green[i] );
		  if (b_flag)  *dst++ = FLOAT_TO_UBYTE( blue[i] );
		  if (l_flag)  *dst++ = FLOAT_TO_UBYTE( luminance[i] );
		  if (a_flag)  *dst++ = FLOAT_TO_UBYTE( alpha[i] );
	       }
d784 1
a784 1
	    {
d786 57
a842 8
	       for (i=0;i<width;i++) {
		  if (r_flag)  *dst++ = FLOAT_TO_BYTE( red[i] );
		  if (g_flag)  *dst++ = FLOAT_TO_BYTE( green[i] );
		  if (b_flag)  *dst++ = FLOAT_TO_BYTE( blue[i] );
		  if (l_flag)  *dst++ = FLOAT_TO_BYTE( luminance[i] );
		  if (a_flag)  *dst++ = FLOAT_TO_BYTE( alpha[i] );
	       }
	    }
d845 1
a845 1
	    {
d847 60
a906 11
	       for (i=0;i<width;i++) {
		  if (r_flag)  *dst++ = FLOAT_TO_USHORT( red[i] );
		  if (g_flag)  *dst++ = FLOAT_TO_USHORT( green[i] );
		  if (b_flag)  *dst++ = FLOAT_TO_USHORT( blue[i] );
		  if (l_flag)  *dst++ = FLOAT_TO_USHORT( luminance[i] );
		  if (a_flag)  *dst++ = FLOAT_TO_USHORT( alpha[i] );
	       }
	    }
	    if (ctx->Pack.SwapBytes) {
	       gl_swap2( (GLushort *) pixels + start + j * k, width*n );
	    }
d909 1
a909 1
	    {
d911 60
a970 11
	       for (i=0;i<width;i++) {
		  if (r_flag)  *dst++ = FLOAT_TO_SHORT( red[i] );
		  if (g_flag)  *dst++ = FLOAT_TO_SHORT( green[i] );
		  if (b_flag)  *dst++ = FLOAT_TO_SHORT( blue[i] );
		  if (l_flag)  *dst++ = FLOAT_TO_SHORT( luminance[i] );
		  if (a_flag)  *dst++ = FLOAT_TO_SHORT( alpha[i] );
	       }
	       if (ctx->Pack.SwapBytes) {
		  gl_swap2( (GLushort *) pixels + start + j * k, width*n );
	       }
	    }
d973 1
a973 1
	    {
d975 60
a1034 11
	       for (i=0;i<width;i++) {
		  if (r_flag)  *dst++ = FLOAT_TO_UINT( red[i] );
		  if (g_flag)  *dst++ = FLOAT_TO_UINT( green[i] );
		  if (b_flag)  *dst++ = FLOAT_TO_UINT( blue[i] );
		  if (l_flag)  *dst++ = FLOAT_TO_UINT( luminance[i] );
		  if (a_flag)  *dst++ = FLOAT_TO_UINT( alpha[i] );
	       }
	       if (ctx->Pack.SwapBytes) {
		  gl_swap4( (GLuint *) pixels + start + j * k, width*n );
	       }
	    }
d1039 56
a1094 7
	       for (i=0;i<width;i++) {
		  if (r_flag)  *dst++ = FLOAT_TO_INT( red[i] );
		  if (g_flag)  *dst++ = FLOAT_TO_INT( green[i] );
		  if (b_flag)  *dst++ = FLOAT_TO_INT( blue[i] );
		  if (l_flag)  *dst++ = FLOAT_TO_INT( luminance[i] );
		  if (a_flag)  *dst++ = FLOAT_TO_INT( alpha[i] );
	       }
d1103 56
a1158 7
	       for (i=0;i<width;i++) {
		  if (r_flag)  *dst++ = red[i];
		  if (g_flag)  *dst++ = green[i];
		  if (b_flag)  *dst++ = blue[i];
		  if (l_flag)  *dst++ = luminance[i];
		  if (a_flag)  *dst++ = alpha[i];
	       }
d1206 2
@
