glapi / teximage: implement EGLImageTargetTexStorageEXT
[mesa.git] / src / mesa / main / pack.c
index e0c2226cdf9f0caaf3c7e7efd5d6cf362385f6ae..64ad115f8b5a25d6c9427e4279d81695aae2dff0 100644 (file)
@@ -42,8 +42,8 @@
 #endif
 
 
+#include "errors.h"
 #include "glheader.h"
-#include "colormac.h"
 #include "enums.h"
 #include "image.h"
 #include "imports.h"
@@ -155,7 +155,7 @@ _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,
    if (!source)
       return;
 
-   width_in_bytes = CEILING( width, 8 );
+   width_in_bytes = DIV_ROUND_UP( width, 8 );
    src = source;
    for (row = 0; row < height; row++) {
       GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, dest,
@@ -232,409 +232,6 @@ _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,
 }
 
 
-/**
- * For small integer types, return the min and max possible values.
- * Used for clamping floats to unscaled integer types.
- * \return GL_TRUE if type is handled, GL_FALSE otherwise.
- */
-static GLboolean
-get_type_min_max(GLenum type, GLfloat *min, GLfloat *max)
-{
-   switch (type) {
-   case GL_BYTE:
-      *min = -128.0;
-      *max = 127.0;
-      return GL_TRUE;
-   case GL_UNSIGNED_BYTE:
-      *min = 0.0;
-      *max = 255.0;
-      return GL_TRUE;
-   case GL_SHORT:
-      *min = -32768.0;
-      *max = 32767.0;
-      return GL_TRUE;
-   case GL_UNSIGNED_SHORT:
-      *min = 0.0;
-      *max = 65535.0;
-      return GL_TRUE;
-   default:
-      return GL_FALSE;
-   }
-}
-
-/* Customization of float packing.
- */
-#define SRC_TYPE GLfloat
-
-#define DST_TYPE GLuint
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_UINT(x)
-#define SRC_CONVERT(x) (GLuint) x
-#define FN_NAME pack_uint_from_float_rgba
-#include "pack_tmp.h"
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLint
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_INT(x)
-#define SRC_CONVERT(x) (GLint) x
-#define FN_NAME pack_int_from_float_rgba
-#include "pack_tmp.h"
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLshort
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_SHORT_TEX(x)
-#define SRC_CONVERT(x) (GLshort) x
-#define FN_NAME pack_short_from_float_rgba
-#include "pack_tmp.h"
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLubyte
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_UBYTE(x)
-#define SRC_CONVERT(x) (GLubyte) x
-#define FN_NAME pack_ubyte_from_float_rgba
-#include "pack_tmp.h"
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLbyte
-#define FLOAT_SRC_CONVERT(x) FLOAT_TO_BYTE_TEX(x)
-#define SRC_CONVERT(x) (GLbyte) x
-#define FN_NAME pack_byte_from_float_rgba
-#include "pack_tmp.h"
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLfloat
-#define FLOAT_SRC_CONVERT(x) x
-#define SRC_CONVERT(x) x
-#define FN_NAME pack_float_from_float_rgba
-#include "pack_tmp.h"
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#define DST_TYPE GLhalfARB
-#define FLOAT_SRC_CONVERT(x) _mesa_float_to_half(x)
-#define FN_NAME pack_half_float_from_float_rgba
-#include "pack_tmp.h"
-#undef DST_TYPE
-#undef SRC_CONVERT
-#undef FLOAT_SRC_CONVERT
-#undef FN_NAME
-
-#undef SRC_TYPE
-
-/**
- * Used to pack an array [][4] of RGBA float colors as specified
- * by the dstFormat, dstType and dstPacking.  Used by glReadPixels.
- * Historically, the RGBA values were in [0,1] and rescaled to fit
- * into GLubytes, etc.  But with new integer formats, the RGBA values
- * may have any value and we don't always rescale when converting to
- * integers.
- *
- * Note: the rgba values will be modified by this function when any pixel
- * transfer ops are enabled.
- */
-void
-_mesa_pack_rgba_span_float(struct gl_context *ctx, GLuint n, GLfloat rgba[][4],
-                           GLenum dstFormat, GLenum dstType,
-                           GLvoid *dstAddr,
-                           const struct gl_pixelstore_attrib *dstPacking,
-                           GLbitfield transferOps)
-{
-   GLfloat *luminance;
-   const GLint comps = _mesa_components_in_format(dstFormat);
-   const GLboolean intDstFormat = _mesa_is_enum_format_integer(dstFormat);
-   GLuint i;
-   uint32_t dstMesaFormat;
-
-   if (dstFormat == GL_LUMINANCE ||
-       dstFormat == GL_LUMINANCE_ALPHA ||
-       dstFormat == GL_LUMINANCE_INTEGER_EXT ||
-       dstFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT) {
-      luminance = malloc(n * sizeof(GLfloat));
-      if (!luminance) {
-         _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
-         return;
-      }
-   }
-   else {
-      luminance = NULL;
-   }
-
-   /* EXT_texture_integer specifies no transfer ops on integer
-    * types in the resolved issues section. Just set them to 0
-    * for integer surfaces.
-    */
-   if (intDstFormat)
-      transferOps = 0;
-
-   if (transferOps) {
-      _mesa_apply_rgba_transfer_ops(ctx, transferOps, n, rgba);
-   }
-
-   /*
-    * Component clamping (besides clamping to [0,1] in
-    * _mesa_apply_rgba_transfer_ops()).
-    */
-   if (intDstFormat) {
-      /* clamping to dest type's min/max values */
-      GLfloat min, max;
-      if (get_type_min_max(dstType, &min, &max)) {
-         for (i = 0; i < n; i++) {
-            rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], min, max);
-            rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], min, max);
-            rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], min, max);
-            rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], min, max);
-         }
-      }
-   }
-   else if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) {
-      /* compute luminance values */
-      if (transferOps & IMAGE_CLAMP_BIT) {
-         for (i = 0; i < n; i++) {
-            GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
-            luminance[i] = CLAMP(sum, 0.0F, 1.0F);
-         }
-      }
-      else {
-         for (i = 0; i < n; i++) {
-            luminance[i] = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
-         }
-      }
-   }
-
-   /*
-    * Pack/store the pixels.  Ugh!  Lots of cases!!!
-    */
-   switch (dstType) {
-      case GL_UNSIGNED_BYTE:
-         pack_ubyte_from_float_rgba(ctx, dstAddr, dstFormat, rgba, luminance, n);
-         break;
-      case GL_BYTE:
-         pack_byte_from_float_rgba(ctx, dstAddr, dstFormat, rgba, luminance, n);
-         break;
-      case GL_UNSIGNED_SHORT:
-         {
-            GLushort *dst = (GLushort *) dstAddr;
-            switch (dstFormat) {
-               case GL_RED:
-                  for (i=0;i<n;i++)
-                     CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][RCOMP]);
-                  break;
-               case GL_GREEN:
-                  for (i=0;i<n;i++)
-                     CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][GCOMP]);
-                  break;
-               case GL_BLUE:
-                  for (i=0;i<n;i++)
-                     CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][BCOMP]);
-                  break;
-               case GL_ALPHA:
-                  for (i=0;i<n;i++)
-                     CLAMPED_FLOAT_TO_USHORT(dst[i], rgba[i][ACOMP]);
-                  break;
-               case GL_LUMINANCE:
-                  for (i=0;i<n;i++)
-                     UNCLAMPED_FLOAT_TO_USHORT(dst[i], luminance[i]);
-                  break;
-               case GL_LUMINANCE_ALPHA:
-                  for (i=0;i<n;i++) {
-                     UNCLAMPED_FLOAT_TO_USHORT(dst[i*2+0], luminance[i]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][ACOMP]);
-                  }
-                  break;
-               case GL_RG:
-                  for (i=0;i<n;i++) {
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*2+0], rgba[i][RCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*2+1], rgba[i][GCOMP]);
-                  }
-                  break;
-               case GL_RGB:
-                  for (i=0;i<n;i++) {
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][RCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][BCOMP]);
-                  }
-                  break;
-               case GL_RGBA:
-                  for (i=0;i<n;i++) {
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][RCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][BCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
-                  }
-                  break;
-               case GL_BGR:
-                  for (i=0;i<n;i++) {
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+0], rgba[i][BCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+1], rgba[i][GCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*3+2], rgba[i][RCOMP]);
-                  }
-                  break;
-               case GL_BGRA:
-                  for (i=0;i<n;i++) {
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][BCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][GCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][RCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][ACOMP]);
-                  }
-                  break;
-               case GL_ABGR_EXT:
-                  for (i=0;i<n;i++) {
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+0], rgba[i][ACOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+1], rgba[i][BCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+2], rgba[i][GCOMP]);
-                     CLAMPED_FLOAT_TO_USHORT(dst[i*4+3], rgba[i][RCOMP]);
-                  }
-                  break;
-               case GL_RED_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i] = (GLushort) rgba[i][RCOMP];
-                  }
-                  break;
-               case GL_GREEN_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i] = (GLushort) rgba[i][GCOMP];
-                  }
-                  break;
-               case GL_BLUE_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i] = (GLushort) rgba[i][BCOMP];
-                  }
-                  break;
-               case GL_ALPHA_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i] = (GLushort) rgba[i][ACOMP];
-                  }
-                  break;
-               case GL_RG_INTEGER:
-                  for (i=0;i<n;i++) {
-                     dst[i*2+0] = (GLushort) rgba[i][RCOMP];
-                     dst[i*2+1] = (GLushort) rgba[i][GCOMP];
-                  }
-                  break;
-               case GL_RGB_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i*3+0] = (GLushort) rgba[i][RCOMP];
-                     dst[i*3+1] = (GLushort) rgba[i][GCOMP];
-                     dst[i*3+2] = (GLushort) rgba[i][BCOMP];
-                  }
-                  break;
-               case GL_RGBA_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i*4+0] = (GLushort) rgba[i][RCOMP];
-                     dst[i*4+1] = (GLushort) rgba[i][GCOMP];
-                     dst[i*4+2] = (GLushort) rgba[i][BCOMP];
-                     dst[i*4+3] = (GLushort) rgba[i][ACOMP];
-                  }
-                  break;
-               case GL_BGR_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i*3+0] = (GLushort) rgba[i][BCOMP];
-                     dst[i*3+1] = (GLushort) rgba[i][GCOMP];
-                     dst[i*3+2] = (GLushort) rgba[i][RCOMP];
-                  }
-                  break;
-               case GL_BGRA_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i*4+0] = (GLushort) rgba[i][BCOMP];
-                     dst[i*4+1] = (GLushort) rgba[i][GCOMP];
-                     dst[i*4+2] = (GLushort) rgba[i][RCOMP];
-                     dst[i*4+3] = (GLushort) rgba[i][ACOMP];
-                  }
-                  break;
-               case GL_LUMINANCE_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i*2+0] = (GLushort) (rgba[i][RCOMP] +
-                                              rgba[i][GCOMP] +
-                                              rgba[i][BCOMP]);
-                     dst[i*2+1] = (GLushort) rgba[i][ACOMP];
-                  }
-                  break;
-               case GL_LUMINANCE_ALPHA_INTEGER_EXT:
-                  for (i=0;i<n;i++) {
-                     dst[i] = (GLushort) (rgba[i][RCOMP] +
-                                          rgba[i][GCOMP] +
-                                          rgba[i][BCOMP]);
-                  }
-                  break;
-               default:
-                  _mesa_problem(ctx, "bad format in _mesa_pack_rgba_span\n");
-            }
-         }
-         break;
-      case GL_SHORT:
-         pack_short_from_float_rgba(ctx, dstAddr, dstFormat, rgba, luminance, n);
-         break;
-      case GL_UNSIGNED_INT:
-         pack_uint_from_float_rgba(ctx, dstAddr, dstFormat, rgba, luminance, n);
-         break;
-      case GL_INT:
-         pack_int_from_float_rgba(ctx, dstAddr, dstFormat, rgba, luminance, n);
-         break;
-      case GL_FLOAT:
-         /* No conversion necessary. */
-         pack_float_from_float_rgba(ctx, dstAddr, dstFormat, rgba, luminance, n);
-         break;
-      case GL_HALF_FLOAT_ARB:
-         pack_half_float_from_float_rgba(ctx, dstAddr, dstFormat, rgba, luminance, n);
-         break;
-      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:
-      case GL_UNSIGNED_INT_5_9_9_9_REV:
-      case GL_UNSIGNED_INT_10F_11F_11F_REV:
-         dstMesaFormat = _mesa_format_from_format_and_type(dstFormat, dstType);
-         if (!(dstMesaFormat & MESA_ARRAY_FORMAT_BIT)) {
-            _mesa_pack_float_rgba_row(dstMesaFormat, n, (void *)rgba[0], (void *)dstAddr);
-            break;
-         } else {
-            /* Fall through */
-         }
-      default:
-         _mesa_problem(ctx, "bad type in _mesa_pack_rgba_span_float");
-         free(luminance);
-         return;
-   }
-
-   if (dstPacking->SwapBytes) {
-      GLint swapSize = _mesa_sizeof_packed_type(dstType);
-      if (swapSize == 2) {
-         _mesa_swap2((GLushort *) dstAddr, n * comps);
-      }
-      else if (swapSize == 4) {
-         _mesa_swap4((GLuint *) dstAddr, n * comps);
-      }
-   }
-
-   free(luminance);
-}
-
-
-
 #define SWAP2BYTE(VALUE)                       \
    {                                           \
       GLubyte *bytes = (GLubyte *) &(VALUE);   \
@@ -660,9 +257,9 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
                      GLenum srcFormat, GLenum srcType, const GLvoid *src,
                      const struct gl_pixelstore_attrib *unpack )
 {
-   ASSERT(srcFormat == GL_COLOR_INDEX || srcFormat == GL_STENCIL_INDEX);
+   assert(srcFormat == GL_COLOR_INDEX || srcFormat == GL_STENCIL_INDEX);
 
-   ASSERT(srcType == GL_BITMAP ||
+   assert(srcType == GL_BITMAP ||
           srcType == GL_UNSIGNED_BYTE ||
           srcType == GL_BYTE ||
           srcType == GL_UNSIGNED_SHORT ||
@@ -671,6 +268,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
           srcType == GL_INT ||
           srcType == GL_UNSIGNED_INT_24_8_EXT ||
           srcType == GL_HALF_FLOAT_ARB ||
+          srcType == GL_HALF_FLOAT_OES ||
           srcType == GL_FLOAT ||
           srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
 
@@ -810,6 +408,7 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
          }
          break;
       case GL_HALF_FLOAT_ARB:
+      case GL_HALF_FLOAT_OES:
          {
             GLuint i;
             const GLhalfARB *s = (const GLhalfARB *) src;
@@ -862,243 +461,8 @@ extract_uint_indexes(GLuint n, GLuint indexes[],
          break;
 
       default:
-         _mesa_problem(NULL, "bad srcType in extract_uint_indexes");
-         return;
-   }
-}
-
-
-static inline GLuint
-clamp_float_to_uint(GLfloat f)
-{
-   return f < 0.0F ? 0 : F_TO_I(f);
-}
-
-
-static inline GLuint
-clamp_half_to_uint(GLhalfARB h)
-{
-   GLfloat f = _mesa_half_to_float(h);
-   return f < 0.0F ? 0 : F_TO_I(f);
-}
-
-
-/*
- * Unpack a row of color index data from a client buffer according to
- * the pixel unpacking parameters.
- * This is (or will be) used by glDrawPixels, glTexImage[123]D, etc.
- *
- * Args:  ctx - the context
- *        n - number of pixels
- *        dstType - destination data type
- *        dest - destination array
- *        srcType - source pixel type
- *        source - source data pointer
- *        srcPacking - pixel unpacking parameters
- *        transferOps - the pixel transfer operations to apply
- */
-void
-_mesa_unpack_index_span( struct gl_context *ctx, GLuint n,
-                         GLenum dstType, GLvoid *dest,
-                         GLenum srcType, const GLvoid *source,
-                         const struct gl_pixelstore_attrib *srcPacking,
-                         GLbitfield transferOps )
-{
-   ASSERT(srcType == GL_BITMAP ||
-          srcType == GL_UNSIGNED_BYTE ||
-          srcType == GL_BYTE ||
-          srcType == GL_UNSIGNED_SHORT ||
-          srcType == GL_SHORT ||
-          srcType == GL_UNSIGNED_INT ||
-          srcType == GL_INT ||
-          srcType == GL_HALF_FLOAT_ARB ||
-          srcType == GL_FLOAT);
-
-   ASSERT(dstType == GL_UNSIGNED_BYTE ||
-          dstType == GL_UNSIGNED_SHORT ||
-          dstType == GL_UNSIGNED_INT);
-
-
-   transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
-
-   /*
-    * Try simple cases first
-    */
-   if (transferOps == 0 && srcType == GL_UNSIGNED_BYTE
-       && dstType == GL_UNSIGNED_BYTE) {
-      memcpy(dest, source, n * sizeof(GLubyte));
-   }
-   else if (transferOps == 0 && srcType == GL_UNSIGNED_INT
-            && dstType == GL_UNSIGNED_INT && !srcPacking->SwapBytes) {
-      memcpy(dest, source, n * sizeof(GLuint));
-   }
-   else {
-      /*
-       * general solution
-       */
-      GLuint *indexes = malloc(n * sizeof(GLuint));
-
-      if (!indexes) {
-         _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel unpacking");
-         return;
-      }
-
-      extract_uint_indexes(n, indexes, GL_COLOR_INDEX, srcType, source,
-                           srcPacking);
-
-      if (transferOps)
-         _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
-
-      /* convert to dest type */
-      switch (dstType) {
-         case GL_UNSIGNED_BYTE:
-            {
-               GLubyte *dst = (GLubyte *) dest;
-               GLuint i;
-               for (i = 0; i < n; i++) {
-                  dst[i] = (GLubyte) (indexes[i] & 0xff);
-               }
-            }
-            break;
-         case GL_UNSIGNED_SHORT:
-            {
-               GLuint *dst = (GLuint *) dest;
-               GLuint i;
-               for (i = 0; i < n; i++) {
-                  dst[i] = (GLushort) (indexes[i] & 0xffff);
-               }
-            }
-            break;
-         case GL_UNSIGNED_INT:
-            memcpy(dest, indexes, n * sizeof(GLuint));
-            break;
-         default:
-            _mesa_problem(ctx, "bad dstType in _mesa_unpack_index_span");
-      }
-
-      free(indexes);
-   }
-}
-
-
-void
-_mesa_pack_index_span( struct gl_context *ctx, GLuint n,
-                       GLenum dstType, GLvoid *dest, const GLuint *source,
-                       const struct gl_pixelstore_attrib *dstPacking,
-                       GLbitfield transferOps )
-{
-   GLuint *indexes = malloc(n * sizeof(GLuint));
-
-   if (!indexes) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "pixel packing");
-      return;
-   }
-
-   transferOps &= (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT);
-
-   if (transferOps & (IMAGE_MAP_COLOR_BIT | IMAGE_SHIFT_OFFSET_BIT)) {
-      /* make a copy of input */
-      memcpy(indexes, source, n * sizeof(GLuint));
-      _mesa_apply_ci_transfer_ops(ctx, transferOps, n, indexes);
-      source = indexes;
-   }
-
-   switch (dstType) {
-   case GL_UNSIGNED_BYTE:
-      {
-         GLubyte *dst = (GLubyte *) dest;
-         GLuint i;
-         for (i = 0; i < n; i++) {
-            *dst++ = (GLubyte) source[i];
-         }
-      }
-      break;
-   case GL_BYTE:
-      {
-         GLbyte *dst = (GLbyte *) dest;
-         GLuint i;
-         for (i = 0; i < n; i++) {
-            dst[i] = (GLbyte) source[i];
-         }
-      }
-      break;
-   case GL_UNSIGNED_SHORT:
-      {
-         GLushort *dst = (GLushort *) dest;
-         GLuint i;
-         for (i = 0; i < n; i++) {
-            dst[i] = (GLushort) source[i];
-         }
-         if (dstPacking->SwapBytes) {
-            _mesa_swap2( (GLushort *) dst, n );
-         }
-      }
-      break;
-   case GL_SHORT:
-      {
-         GLshort *dst = (GLshort *) dest;
-         GLuint i;
-         for (i = 0; i < n; i++) {
-            dst[i] = (GLshort) source[i];
-         }
-         if (dstPacking->SwapBytes) {
-            _mesa_swap2( (GLushort *) dst, n );
-         }
-      }
-      break;
-   case GL_UNSIGNED_INT:
-      {
-         GLuint *dst = (GLuint *) dest;
-         GLuint i;
-         for (i = 0; i < n; i++) {
-            dst[i] = (GLuint) source[i];
-         }
-         if (dstPacking->SwapBytes) {
-            _mesa_swap4( (GLuint *) dst, n );
-         }
-      }
-      break;
-   case GL_INT:
-      {
-         GLint *dst = (GLint *) dest;
-         GLuint i;
-         for (i = 0; i < n; i++) {
-            dst[i] = (GLint) source[i];
-         }
-         if (dstPacking->SwapBytes) {
-            _mesa_swap4( (GLuint *) dst, n );
-         }
-      }
-      break;
-   case GL_FLOAT:
-      {
-         GLfloat *dst = (GLfloat *) dest;
-         GLuint i;
-         for (i = 0; i < n; i++) {
-            dst[i] = (GLfloat) source[i];
-         }
-         if (dstPacking->SwapBytes) {
-            _mesa_swap4( (GLuint *) dst, n );
-         }
-      }
-      break;
-   case GL_HALF_FLOAT_ARB:
-      {
-         GLhalfARB *dst = (GLhalfARB *) dest;
-         GLuint i;
-         for (i = 0; i < n; i++) {
-            dst[i] = _mesa_float_to_half((GLfloat) source[i]);
-         }
-         if (dstPacking->SwapBytes) {
-            _mesa_swap2( (GLushort *) dst, n );
-         }
-      }
-      break;
-   default:
-      _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
+         unreachable("bad srcType in extract_uint_indexes");
    }
-
-   free(indexes);
 }
 
 
@@ -1123,7 +487,7 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
                            const struct gl_pixelstore_attrib *srcPacking,
                            GLbitfield transferOps )
 {
-   ASSERT(srcType == GL_BITMAP ||
+   assert(srcType == GL_BITMAP ||
           srcType == GL_UNSIGNED_BYTE ||
           srcType == GL_BYTE ||
           srcType == GL_UNSIGNED_SHORT ||
@@ -1132,10 +496,11 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
           srcType == GL_INT ||
           srcType == GL_UNSIGNED_INT_24_8_EXT ||
           srcType == GL_HALF_FLOAT_ARB ||
+          srcType == GL_HALF_FLOAT_OES ||
           srcType == GL_FLOAT ||
           srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
 
-   ASSERT(dstType == GL_UNSIGNED_BYTE ||
+   assert(dstType == GL_UNSIGNED_BYTE ||
           dstType == GL_UNSIGNED_SHORT ||
           dstType == GL_UNSIGNED_INT ||
           dstType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
@@ -1220,7 +585,7 @@ _mesa_unpack_stencil_span( struct gl_context *ctx, GLuint n,
             }
             break;
          default:
-            _mesa_problem(ctx, "bad dstType in _mesa_unpack_stencil_span");
+            unreachable("bad dstType in _mesa_unpack_stencil_span");
       }
 
       free(indexes);
@@ -1322,6 +687,7 @@ _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
       }
       break;
    case GL_HALF_FLOAT_ARB:
+   case GL_HALF_FLOAT_OES:
       {
          GLhalfARB *dst = (GLhalfARB *) dest;
          GLuint i;
@@ -1366,7 +732,7 @@ _mesa_pack_stencil_span( struct gl_context *ctx, GLuint n,
       }
       break;
    default:
-      _mesa_problem(ctx, "bad type in _mesa_pack_index_span");
+      unreachable("bad type in _mesa_pack_index_span");
    }
 
    free(stencil);
@@ -1414,7 +780,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
     * back to an int type can introduce errors that will show up as
     * artifacts in things like depth peeling which uses glCopyTexImage.
     */
-   if (ctx->Pixel.DepthScale == 1.0 && ctx->Pixel.DepthBias == 0.0) {
+   if (ctx->Pixel.DepthScale == 1.0F && ctx->Pixel.DepthBias == 0.0F) {
       if (srcType == GL_UNSIGNED_INT && dstType == GL_UNSIGNED_SHORT) {
          const GLuint *src = (const GLuint *) source;
          GLushort *dst = (GLushort *) dest;
@@ -1492,8 +858,8 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
       case GL_UNSIGNED_INT_24_8_EXT: /* GL_EXT_packed_depth_stencil */
          if (dstType == GL_UNSIGNED_INT_24_8_EXT &&
              depthMax == 0xffffff &&
-             ctx->Pixel.DepthScale == 1.0 &&
-             ctx->Pixel.DepthBias == 0.0) {
+             ctx->Pixel.DepthScale == 1.0F &&
+             ctx->Pixel.DepthBias == 0.0F) {
             const GLuint *src = (const GLuint *) source;
             GLuint *zValues = (GLuint *) dest;
             GLuint i;
@@ -1539,6 +905,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
          needClamp = GL_TRUE;
          break;
       case GL_HALF_FLOAT_ARB:
+      case GL_HALF_FLOAT_OES:
          {
             GLuint i;
             const GLhalfARB *src = (const GLhalfARB *) source;
@@ -1562,7 +929,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
    {
       const GLfloat scale = ctx->Pixel.DepthScale;
       const GLfloat bias = ctx->Pixel.DepthBias;
-      if (scale != 1.0 || bias != 0.0) {
+      if (scale != 1.0F || bias != 0.0F) {
          GLuint i;
          for (i = 0; i < n; i++) {
             depthValues[i] = depthValues[i] * scale + bias;
@@ -1575,7 +942,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
    if (needClamp) {
       GLuint i;
       for (i = 0; i < n; i++) {
-         depthValues[i] = (GLfloat)CLAMP(depthValues[i], 0.0, 1.0);
+         depthValues[i] = CLAMP(depthValues[i], 0.0F, 1.0F);
       }
    }
 
@@ -1605,7 +972,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
    else if (dstType == GL_UNSIGNED_SHORT) {
       GLushort *zValues = (GLushort *) dest;
       GLuint i;
-      ASSERT(depthMax <= 0xffff);
+      assert(depthMax <= 0xffff);
       for (i = 0; i < n; i++) {
          zValues[i] = (GLushort) (depthValues[i] * (GLfloat) depthMax);
       }
@@ -1621,7 +988,7 @@ _mesa_unpack_depth_span( struct gl_context *ctx, GLuint n,
       }
    }
    else {
-      ASSERT(0);
+      assert(0);
    }
 
    free(depthTemp);
@@ -1642,7 +1009,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
       return;
    }
 
-   if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
+   if (ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F) {
       memcpy(depthCopy, depthSpan, n * sizeof(GLfloat));
       _mesa_scale_and_bias_depth(ctx, n, depthCopy);
       depthSpan = depthCopy;
@@ -1691,6 +1058,21 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
          }
       }
       break;
+   case GL_UNSIGNED_INT_24_8:
+      {
+         const GLdouble scale = (GLdouble) 0xffffff;
+         GLuint *dst = (GLuint *) dest;
+         GLuint i;
+         for (i = 0; i < n; i++) {
+            GLuint z = (GLuint) (depthSpan[i] * scale);
+            assert(z <= 0xffffff);
+            dst[i] = (z << 8);
+         }
+         if (dstPacking->SwapBytes) {
+            _mesa_swap4( (GLuint *) dst, n );
+         }
+         break;
+      }
    case GL_UNSIGNED_INT:
       {
          GLuint *dst = (GLuint *) dest;
@@ -1728,6 +1110,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
       }
       break;
    case GL_HALF_FLOAT_ARB:
+   case GL_HALF_FLOAT_OES:
       {
          GLhalfARB *dst = (GLhalfARB *) dest;
          GLuint i;
@@ -1740,7 +1123,7 @@ _mesa_pack_depth_span( struct gl_context *ctx, GLuint n, GLvoid *dest,
       }
       break;
    default:
-      _mesa_problem(ctx, "bad type in _mesa_pack_depth_span");
+      unreachable("bad type in _mesa_pack_depth_span()");
    }
 
    free(depthCopy);
@@ -1769,7 +1152,7 @@ _mesa_pack_depth_stencil_span(struct gl_context *ctx,GLuint n,
       return;
    }
 
-   if (ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0) {
+   if (ctx->Pixel.DepthScale != 1.0F || ctx->Pixel.DepthBias != 0.0F) {
       memcpy(depthCopy, depthVals, n * sizeof(GLfloat));
       _mesa_scale_and_bias_depth(ctx, n, depthCopy);
       depthVals = depthCopy;
@@ -1947,132 +1330,6 @@ _mesa_unpack_image( GLuint dimensions,
    }
 }
 
-
-
-/**
- * If we unpack colors from a luminance surface, we'll get pixel colors
- * such as (l, l, l, a).
- * When we call _mesa_pack_rgba_span_float(format=GL_LUMINANCE), that
- * function will compute L=R+G+B before packing.  The net effect is we'll
- * accidentally store luminance values = 3*l.
- * This function compensates for that by converting (aka rebasing) (l,l,l,a)
- * to be (l,0,0,a).
- * It's a similar story for other formats such as LUMINANCE_ALPHA, ALPHA
- * and INTENSITY.
- *
- * Finally, we also need to do this when the actual surface format does
- * not match the logical surface format.  For example, suppose the user
- * requests a GL_LUMINANCE texture but the driver stores it as RGBA.
- * Again, we'll get pixel values like (l,l,l,a).
- */
-void
-_mesa_rebase_rgba_float(GLuint n, GLfloat rgba[][4], GLenum baseFormat)
-{
-   GLuint i;
-
-   switch (baseFormat) {
-   case GL_ALPHA:
-      for (i = 0; i < n; i++) {
-         rgba[i][RCOMP] = 0.0F;
-         rgba[i][GCOMP] = 0.0F;
-         rgba[i][BCOMP] = 0.0F;
-      }
-      break;
-   case GL_INTENSITY:
-      /* fall-through */
-   case GL_LUMINANCE:
-      for (i = 0; i < n; i++) {
-         rgba[i][GCOMP] = 0.0F;
-         rgba[i][BCOMP] = 0.0F;
-         rgba[i][ACOMP] = 1.0F;
-      }
-      break;
-   case GL_LUMINANCE_ALPHA:
-      for (i = 0; i < n; i++) {
-         rgba[i][GCOMP] = 0.0F;
-         rgba[i][BCOMP] = 0.0F;
-      }
-      break;
-   case GL_RGB:
-      for (i = 0; i < n; i++) {
-         rgba[i][ACOMP] = 1.0F;
-      }
-      break;
-   case GL_RG:
-      for (i = 0; i < n; i++) {
-         rgba[i][BCOMP] = 0.0F;
-         rgba[i][ACOMP] = 1.0F;
-      }
-      break;
-   case GL_RED:
-      for (i = 0; i < n; i++) {
-         rgba[i][GCOMP] = 0.0F;
-         rgba[i][BCOMP] = 0.0F;
-         rgba[i][ACOMP] = 1.0F;
-      }
-      break;
-
-   default:
-      /* no-op */
-      ;
-   }
-}
-
-
-/**
- * As above, but GLuint components.
- */
-void
-_mesa_rebase_rgba_uint(GLuint n, GLuint rgba[][4], GLenum baseFormat)
-{
-   GLuint i;
-
-   switch (baseFormat) {
-   case GL_ALPHA:
-      for (i = 0; i < n; i++) {
-         rgba[i][RCOMP] = 0;
-         rgba[i][GCOMP] = 0;
-         rgba[i][BCOMP] = 0;
-      }
-      break;
-   case GL_INTENSITY:
-      /* fall-through */
-   case GL_LUMINANCE:
-      for (i = 0; i < n; i++) {
-         rgba[i][GCOMP] = 0;
-         rgba[i][BCOMP] = 0;
-         rgba[i][ACOMP] = 1;
-      }
-      break;
-   case GL_LUMINANCE_ALPHA:
-      for (i = 0; i < n; i++) {
-         rgba[i][GCOMP] = 0;
-         rgba[i][BCOMP] = 0;
-      }
-      break;
-   case GL_RGB:
-      for (i = 0; i < n; i++) {
-         rgba[i][ACOMP] = 1;
-      }
-      break;
-   case GL_RG:
-      for (i = 0; i < n; i++) {
-         rgba[i][BCOMP] = 0;
-         rgba[i][ACOMP] = 1;
-      }
-      break;
-   case GL_RED:
-      for (i = 0; i < n; i++) {
-         rgba[i][GCOMP] = 0;
-         rgba[i][BCOMP] = 0;
-         rgba[i][ACOMP] = 1;
-      }
-   default:
-      /* no-op */
-      ;
-   }
-}
-
 void
 _mesa_pack_luminance_from_rgba_float(GLuint n, GLfloat rgba[][4],
                                      GLvoid *dstAddr, GLenum dst_format,
@@ -2186,15 +1443,15 @@ _mesa_pack_luminance_from_rgba_integer(GLuint n,
                                        GLenum dst_format,
                                        GLenum dst_type)
 {
-   assert(dst_format == GL_LUMINANCE_INTEGER_EXT ||
-          dst_format == GL_LUMINANCE_ALPHA_INTEGER_EXT);
-
    int i;
    int64_t lum64;
    int32_t lum32, alpha;
    bool dst_is_signed;
    int dst_bits;
 
+   assert(dst_format == GL_LUMINANCE_INTEGER_EXT ||
+          dst_format == GL_LUMINANCE_ALPHA_INTEGER_EXT);
+
    /* We first compute luminance values as a 64-bit addition of the
     * 32-bit R,G,B components, then we clamp the result to the dst type size.
     *
@@ -2229,20 +1486,20 @@ _mesa_pack_luminance_from_rgba_integer(GLuint n,
          case GL_UNSIGNED_BYTE: {
             GLbyte *dst = (GLbyte *) dstAddr;
             dst[i] = lum32;
+            break;
          }
-         break;
          case GL_SHORT:
          case GL_UNSIGNED_SHORT: {
             GLshort *dst = (GLshort *) dstAddr;
             dst[i] = lum32;
+            break;
          }
-         break;
          case GL_INT:
          case GL_UNSIGNED_INT: {
             GLint *dst = (GLint *) dstAddr;
             dst[i] = lum32;
+            break;
          }
-         break;
          }
       }
       return;
@@ -2267,21 +1524,22 @@ _mesa_pack_luminance_from_rgba_integer(GLuint n,
             GLbyte *dst = (GLbyte *) dstAddr;
             dst[2*i] = lum32;
             dst[2*i+1] = alpha;
+            break;
          }
          case GL_SHORT:
          case GL_UNSIGNED_SHORT: {
             GLshort *dst = (GLshort *) dstAddr;
             dst[i] = lum32;
             dst[2*i+1] = alpha;
+            break;
          }
-         break;
          case GL_INT:
          case GL_UNSIGNED_INT: {
             GLint *dst = (GLint *) dstAddr;
             dst[i] = lum32;
             dst[2*i+1] = alpha;
+            break;
          }
-         break;
          }
       }
       return;