Home | History | Annotate | Download | only in main
      1 /*
      2  * Mesa 3-D graphics library
      3  *
      4  * Copyright (c) 2011 VMware, Inc.
      5  *
      6  * Permission is hereby granted, free of charge, to any person obtaining a
      7  * copy of this software and associated documentation files (the "Software"),
      8  * to deal in the Software without restriction, including without limitation
      9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the
     11  * Software is furnished to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included
     14  * in all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     20  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     22  */
     23 
     24 
     25 #include "colormac.h"
     26 #include "format_unpack.h"
     27 #include "macros.h"
     28 #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
     29 #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
     30 
     31 
     32 /** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */
     33 struct z32f_x24s8
     34 {
     35    float z;
     36    uint32_t x24s8;
     37 };
     38 
     39 
     40 /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
     41 
     42 #define EXPAND_1_8(X)  ( (X) ? 0xff : 0x0 )
     43 
     44 #define EXPAND_2_8(X)  ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
     45 
     46 #define EXPAND_3_8(X)  ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
     47 
     48 #define EXPAND_4_8(X)  ( ((X) << 4) | (X) )
     49 
     50 #define EXPAND_5_8(X)  ( ((X) << 3) | ((X) >> 2) )
     51 
     52 #define EXPAND_6_8(X)  ( ((X) << 2) | ((X) >> 4) )
     53 
     54 
     55 /**
     56  * Convert an 8-bit sRGB value from non-linear space to a
     57  * linear RGB value in [0, 1].
     58  * Implemented with a 256-entry lookup table.
     59  */
     60 static inline GLfloat
     61 nonlinear_to_linear(GLubyte cs8)
     62 {
     63    static GLfloat table[256];
     64    static GLboolean tableReady = GL_FALSE;
     65    if (!tableReady) {
     66       /* compute lookup table now */
     67       GLuint i;
     68       for (i = 0; i < 256; i++) {
     69          const GLfloat cs = UBYTE_TO_FLOAT(i);
     70          if (cs <= 0.04045) {
     71             table[i] = cs / 12.92f;
     72          }
     73          else {
     74             table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
     75          }
     76       }
     77       tableReady = GL_TRUE;
     78    }
     79    return table[cs8];
     80 }
     81 
     82 
     83 /**********************************************************************/
     84 /*  Unpack, returning GLfloat colors                                  */
     85 /**********************************************************************/
     86 
     87 typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
     88 
     89 
     90 static void
     91 unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
     92 {
     93    const GLuint *s = ((const GLuint *) src);
     94    GLuint i;
     95    for (i = 0; i < n; i++) {
     96       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
     97       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
     98       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
     99       dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
    100    }
    101 }
    102 
    103 static void
    104 unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
    105 {
    106    const GLuint *s = ((const GLuint *) src);
    107    GLuint i;
    108    for (i = 0; i < n; i++) {
    109       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
    110       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
    111       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
    112       dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
    113    }
    114 }
    115 
    116 static void
    117 unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
    118 {
    119    const GLuint *s = ((const GLuint *) src);
    120    GLuint i;
    121    for (i = 0; i < n; i++) {
    122       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
    123       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
    124       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
    125       dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
    126    }
    127 }
    128 
    129 static void
    130 unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
    131 {
    132    const GLuint *s = ((const GLuint *) src);
    133    GLuint i;
    134    for (i = 0; i < n; i++) {
    135       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
    136       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
    137       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
    138       dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
    139    }
    140 }
    141 
    142 static void
    143 unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
    144 {
    145    const GLuint *s = ((const GLuint *) src);
    146    GLuint i;
    147    for (i = 0; i < n; i++) {
    148       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
    149       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
    150       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
    151       dst[i][ACOMP] = 1.0f;
    152    }
    153 }
    154 
    155 static void
    156 unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
    157 {
    158    const GLuint *s = ((const GLuint *) src);
    159    GLuint i;
    160    for (i = 0; i < n; i++) {
    161       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
    162       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
    163       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
    164       dst[i][ACOMP] = 1.0f;
    165    }
    166 }
    167 
    168 static void
    169 unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
    170 {
    171    const GLuint *s = ((const GLuint *) src);
    172    GLuint i;
    173    for (i = 0; i < n; i++) {
    174       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
    175       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
    176       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
    177       dst[i][ACOMP] = 1.0f;
    178    }
    179 }
    180 
    181 static void
    182 unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
    183 {
    184    const GLuint *s = ((const GLuint *) src);
    185    GLuint i;
    186    for (i = 0; i < n; i++) {
    187       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
    188       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
    189       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
    190       dst[i][ACOMP] = 1.0f;
    191    }
    192 }
    193 
    194 static void
    195 unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
    196 {
    197    const GLubyte *s = (const GLubyte *) src;
    198    GLuint i;
    199    for (i = 0; i < n; i++) {
    200       dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
    201       dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
    202       dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
    203       dst[i][ACOMP] = 1.0F;
    204    }
    205 }
    206 
    207 static void
    208 unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
    209 {
    210    const GLubyte *s = (const GLubyte *) src;
    211    GLuint i;
    212    for (i = 0; i < n; i++) {
    213       dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
    214       dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
    215       dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
    216       dst[i][ACOMP] = 1.0F;
    217    }
    218 }
    219 
    220 static void
    221 unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
    222 {
    223    const GLushort *s = ((const GLushort *) src);
    224    GLuint i;
    225    for (i = 0; i < n; i++) {
    226       dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
    227       dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
    228       dst[i][BCOMP] = ((s[i]      ) & 0x1f) * (1.0F / 31.0F);
    229       dst[i][ACOMP] = 1.0F;
    230    }
    231 }
    232 
    233 static void
    234 unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
    235 {
    236    const GLushort *s = ((const GLushort *) src);
    237    GLuint i;
    238    for (i = 0; i < n; i++) {
    239       GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
    240       dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
    241       dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >>  9) & 0x3) );
    242       dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >>  2) & 0x7) );
    243       dst[i][ACOMP] = 1.0F;
    244    }
    245 }
    246 
    247 static void
    248 unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
    249 {
    250    const GLushort *s = ((const GLushort *) src);
    251    GLuint i;
    252    for (i = 0; i < n; i++) {
    253       dst[i][RCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
    254       dst[i][GCOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
    255       dst[i][BCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
    256       dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
    257    }
    258 }
    259 
    260 static void
    261 unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
    262 {
    263    const GLushort *s = ((const GLushort *) src);
    264    GLuint i;
    265    for (i = 0; i < n; i++) {
    266       dst[i][RCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
    267       dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
    268       dst[i][BCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
    269       dst[i][ACOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
    270    }
    271 }
    272 
    273 static void
    274 unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
    275 {
    276    const GLushort *s = ((const GLushort *) src);
    277    GLuint i;
    278    for (i = 0; i < n; i++) {
    279       dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
    280       dst[i][GCOMP] = ((s[i] >>  6) & 0x1f) * (1.0F / 31.0F);
    281       dst[i][BCOMP] = ((s[i] >>  1) & 0x1f) * (1.0F / 31.0F);
    282       dst[i][ACOMP] = ((s[i]      ) & 0x01) * 1.0F;
    283    }
    284 }
    285 
    286 static void
    287 unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
    288 {
    289    const GLushort *s = ((const GLushort *) src);
    290    GLuint i;
    291    for (i = 0; i < n; i++) {
    292       dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
    293       dst[i][GCOMP] = ((s[i] >>  5) & 0x1f) * (1.0F / 31.0F);
    294       dst[i][BCOMP] = ((s[i] >>  0) & 0x1f) * (1.0F / 31.0F);
    295       dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
    296    }
    297 }
    298 
    299 static void
    300 unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
    301 {
    302    const GLushort *s = ((const GLushort *) src);
    303    GLuint i;
    304    for (i = 0; i < n; i++) {
    305       GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
    306       dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
    307       dst[i][GCOMP] = ((tmp >>  5) & 0x1f) * (1.0F / 31.0F);
    308       dst[i][BCOMP] = ((tmp >>  0) & 0x1f) * (1.0F / 31.0F);
    309       dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
    310    }
    311 }
    312 
    313 static void
    314 unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
    315 {
    316    const GLubyte *s = ((const GLubyte *) src);
    317    GLuint i;
    318    for (i = 0; i < n; i++) {
    319       dst[i][RCOMP] =
    320       dst[i][GCOMP] =
    321       dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
    322       dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
    323    }
    324 }
    325 
    326 static void
    327 unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
    328 {
    329    const GLushort *s = ((const GLushort *) src);
    330    GLuint i;
    331    for (i = 0; i < n; i++) {
    332       dst[i][RCOMP] =
    333       dst[i][GCOMP] =
    334       dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
    335       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
    336    }
    337 }
    338 
    339 static void
    340 unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
    341 {
    342    const GLushort *s = ((const GLushort *) src);
    343    GLuint i;
    344    for (i = 0; i < n; i++) {
    345       dst[i][RCOMP] =
    346       dst[i][GCOMP] =
    347       dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
    348       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
    349    }
    350 }
    351 
    352 static void
    353 unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
    354 {
    355    const GLuint *s = ((const GLuint *) src);
    356    GLuint i;
    357    for (i = 0; i < n; i++) {
    358       dst[i][RCOMP] =
    359       dst[i][GCOMP] =
    360       dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
    361       dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
    362    }
    363 }
    364 
    365 static void
    366 unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
    367 {
    368    const GLuint *s = ((const GLuint *) src);
    369    GLuint i;
    370    for (i = 0; i < n; i++) {
    371       dst[i][RCOMP] =
    372       dst[i][GCOMP] =
    373       dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
    374       dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
    375    }
    376 }
    377 
    378 static void
    379 unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
    380 {
    381    const GLubyte *s = ((const GLubyte *) src);
    382    GLuint i;
    383    for (i = 0; i < n; i++) {
    384       dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
    385       dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
    386       dst[i][BCOMP] = ((s[i]     ) & 0x3) * (1.0F / 3.0F);
    387       dst[i][ACOMP] = 1.0F;
    388    }
    389 }
    390 
    391 
    392 static void
    393 unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
    394 {
    395    const GLubyte *s = ((const GLubyte *) src);
    396    GLuint i;
    397    for (i = 0; i < n; i++) {
    398       dst[i][RCOMP] =
    399       dst[i][GCOMP] =
    400       dst[i][BCOMP] = 0.0F;
    401       dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
    402    }
    403 }
    404 
    405 static void
    406 unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
    407 {
    408    const GLushort *s = ((const GLushort *) src);
    409    GLuint i;
    410    for (i = 0; i < n; i++) {
    411       dst[i][RCOMP] =
    412       dst[i][GCOMP] =
    413       dst[i][BCOMP] = 0.0F;
    414       dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
    415    }
    416 }
    417 
    418 static void
    419 unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
    420 {
    421    const GLubyte *s = ((const GLubyte *) src);
    422    GLuint i;
    423    for (i = 0; i < n; i++) {
    424       dst[i][RCOMP] =
    425       dst[i][GCOMP] =
    426       dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
    427       dst[i][ACOMP] = 1.0F;
    428    }
    429 }
    430 
    431 static void
    432 unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
    433 {
    434    const GLushort *s = ((const GLushort *) src);
    435    GLuint i;
    436    for (i = 0; i < n; i++) {
    437       dst[i][RCOMP] =
    438       dst[i][GCOMP] =
    439       dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
    440       dst[i][ACOMP] = 1.0F;
    441    }
    442 }
    443 
    444 static void
    445 unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
    446 {
    447    const GLubyte *s = ((const GLubyte *) src);
    448    GLuint i;
    449    for (i = 0; i < n; i++) {
    450       dst[i][RCOMP] =
    451       dst[i][GCOMP] =
    452       dst[i][BCOMP] =
    453       dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
    454    }
    455 }
    456 
    457 static void
    458 unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
    459 {
    460    const GLushort *s = ((const GLushort *) src);
    461    GLuint i;
    462    for (i = 0; i < n; i++) {
    463       dst[i][RCOMP] =
    464       dst[i][GCOMP] =
    465       dst[i][BCOMP] =
    466       dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
    467    }
    468 }
    469 
    470 static void
    471 unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
    472 {
    473    GLuint i;
    474    for (i = 0; i < n; i++) {
    475       const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
    476       const GLushort *src1 = src0 + 1;         /* odd */
    477       const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
    478       const GLubyte cb = *src0 & 0xff;         /* chroma U */
    479       const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
    480       const GLubyte cr = *src1 & 0xff;         /* chroma V */
    481       const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
    482       GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
    483       GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
    484       GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
    485       r *= (1.0F / 255.0F);
    486       g *= (1.0F / 255.0F);
    487       b *= (1.0F / 255.0F);
    488       dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
    489       dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
    490       dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
    491       dst[i][ACOMP] = 1.0F;
    492    }
    493 }
    494 
    495 static void
    496 unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
    497 {
    498    GLuint i;
    499    for (i = 0; i < n; i++) {
    500       const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
    501       const GLushort *src1 = src0 + 1;         /* odd */
    502       const GLubyte y0 = *src0 & 0xff;         /* luminance */
    503       const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
    504       const GLubyte y1 = *src1 & 0xff;         /* luminance */
    505       const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
    506       const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
    507       GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
    508       GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
    509       GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
    510       r *= (1.0F / 255.0F);
    511       g *= (1.0F / 255.0F);
    512       b *= (1.0F / 255.0F);
    513       dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
    514       dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
    515       dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
    516       dst[i][ACOMP] = 1.0F;
    517    }
    518 }
    519 
    520 static void
    521 unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
    522 {
    523    const GLubyte *s = ((const GLubyte *) src);
    524    GLuint i;
    525    for (i = 0; i < n; i++) {
    526       dst[i][0] = UBYTE_TO_FLOAT(s[i]);
    527       dst[i][1] =
    528       dst[i][2] = 0.0F;
    529       dst[i][3] = 1.0F;
    530    }
    531 }
    532 
    533 static void
    534 unpack_GR88(const void *src, GLfloat dst[][4], GLuint n)
    535 {
    536    const GLushort *s = ((const GLushort *) src);
    537    GLuint i;
    538    for (i = 0; i < n; i++) {
    539       dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
    540       dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
    541       dst[i][BCOMP] = 0.0;
    542       dst[i][ACOMP] = 1.0;
    543    }
    544 }
    545 
    546 static void
    547 unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
    548 {
    549    const GLushort *s = ((const GLushort *) src);
    550    GLuint i;
    551    for (i = 0; i < n; i++) {
    552       dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
    553       dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
    554       dst[i][BCOMP] = 0.0;
    555       dst[i][ACOMP] = 1.0;
    556    }
    557 }
    558 
    559 static void
    560 unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
    561 {
    562    const GLushort *s = ((const GLushort *) src);
    563    GLuint i;
    564    for (i = 0; i < n; i++) {
    565       dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
    566       dst[i][GCOMP] = 0.0;
    567       dst[i][BCOMP] = 0.0;
    568       dst[i][ACOMP] = 1.0;
    569    }
    570 }
    571 
    572 static void
    573 unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
    574 {
    575    const GLuint *s = ((const GLuint *) src);
    576    GLuint i;
    577    for (i = 0; i < n; i++) {
    578       dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
    579       dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
    580       dst[i][BCOMP] = 0.0;
    581       dst[i][ACOMP] = 1.0;
    582    }
    583 }
    584 
    585 static void
    586 unpack_RG1616_REV(const void *src, GLfloat dst[][4], GLuint n)
    587 {
    588    const GLuint *s = ((const GLuint *) src);
    589    GLuint i;
    590    for (i = 0; i < n; i++) {
    591       dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
    592       dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
    593       dst[i][BCOMP] = 0.0;
    594       dst[i][ACOMP] = 1.0;
    595    }
    596 }
    597 
    598 static void
    599 unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
    600 {
    601    const GLuint *s = ((const GLuint *) src);
    602    GLuint i;
    603    for (i = 0; i < n; i++) {
    604       dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
    605       dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
    606       dst[i][BCOMP] = ((s[i] >>  0) & 0x3ff) * (1.0F / 1023.0F);
    607       dst[i][ACOMP] = ((s[i] >> 30) &  0x03) * (1.0F / 3.0F);
    608    }
    609 }
    610 
    611 
    612 static void
    613 unpack_ABGR2101010_UINT(const void *src, GLfloat dst[][4], GLuint n)
    614 {
    615    const GLuint *s = ((const GLuint *) src);
    616    GLuint i;
    617    for (i = 0; i < n; i++) {
    618       dst[i][RCOMP] = (GLfloat)((s[i] >>  0) & 0x3ff);
    619       dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
    620       dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
    621       dst[i][ACOMP] = (GLfloat)((s[i] >> 30) &  0x03);
    622    }
    623 }
    624 
    625 
    626 static void
    627 unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
    628 {
    629    /* only return Z, not stencil data */
    630    const GLuint *s = ((const GLuint *) src);
    631    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
    632    GLuint i;
    633    for (i = 0; i < n; i++) {
    634       dst[i][0] =
    635       dst[i][1] =
    636       dst[i][2] = (s[i] >> 8) * scale;
    637       dst[i][3] = 1.0F;
    638       ASSERT(dst[i][0] >= 0.0F);
    639       ASSERT(dst[i][0] <= 1.0F);
    640    }
    641 }
    642 
    643 static void
    644 unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
    645 {
    646    /* only return Z, not stencil data */
    647    const GLuint *s = ((const GLuint *) src);
    648    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
    649    GLuint i;
    650    for (i = 0; i < n; i++) {
    651       dst[i][0] =
    652       dst[i][1] =
    653       dst[i][2] = (s[i] & 0x00ffffff) * scale;
    654       dst[i][3] = 1.0F;
    655       ASSERT(dst[i][0] >= 0.0F);
    656       ASSERT(dst[i][0] <= 1.0F);
    657    }
    658 }
    659 
    660 static void
    661 unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
    662 {
    663    const GLushort *s = ((const GLushort *) src);
    664    GLuint i;
    665    for (i = 0; i < n; i++) {
    666       dst[i][0] =
    667       dst[i][1] =
    668       dst[i][2] = s[i] * (1.0F / 65535.0F);
    669       dst[i][3] = 1.0F;
    670    }
    671 }
    672 
    673 static void
    674 unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
    675 {
    676    unpack_S8_Z24(src, dst, n);
    677 }
    678 
    679 static void
    680 unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
    681 {
    682    unpack_Z24_S8(src, dst, n);
    683 }
    684 
    685 static void
    686 unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
    687 {
    688    const GLuint *s = ((const GLuint *) src);
    689    GLuint i;
    690    for (i = 0; i < n; i++) {
    691       dst[i][0] =
    692       dst[i][1] =
    693       dst[i][2] = s[i] * (1.0F / 0xffffffff);
    694       dst[i][3] = 1.0F;
    695    }
    696 }
    697 
    698 static void
    699 unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
    700 {
    701    const GLfloat *s = ((const GLfloat *) src);
    702    GLuint i;
    703    for (i = 0; i < n; i++) {
    704       dst[i][0] =
    705       dst[i][1] =
    706       dst[i][2] = s[i * 2];
    707       dst[i][3] = 1.0F;
    708    }
    709 }
    710 
    711 static void
    712 unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
    713 {
    714    const GLfloat *s = ((const GLfloat *) src);
    715    GLuint i;
    716    for (i = 0; i < n; i++) {
    717       dst[i][0] =
    718       dst[i][1] =
    719       dst[i][2] = s[i];
    720       dst[i][3] = 1.0F;
    721    }
    722 }
    723 
    724 
    725 static void
    726 unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
    727 {
    728    /* should never be used */
    729    GLuint i;
    730    for (i = 0; i < n; i++) {
    731       dst[i][0] =
    732       dst[i][1] =
    733       dst[i][2] = 0.0F;
    734       dst[i][3] = 1.0F;
    735    }
    736 }
    737 
    738 
    739 static void
    740 unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
    741 {
    742    const GLubyte *s = (const GLubyte *) src;
    743    GLuint i;
    744    for (i = 0; i < n; i++) {
    745       dst[i][RCOMP] = nonlinear_to_linear(s[i*3+2]);
    746       dst[i][GCOMP] = nonlinear_to_linear(s[i*3+1]);
    747       dst[i][BCOMP] = nonlinear_to_linear(s[i*3+0]);
    748       dst[i][ACOMP] = 1.0F;
    749    }
    750 }
    751 
    752 static void
    753 unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
    754 {
    755    const GLuint *s = ((const GLuint *) src);
    756    GLuint i;
    757    for (i = 0; i < n; i++) {
    758       dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 24) );
    759       dst[i][GCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
    760       dst[i][BCOMP] = nonlinear_to_linear( (s[i] >>  8) & 0xff );
    761       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
    762    }
    763 }
    764 
    765 static void
    766 unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
    767 {
    768    const GLuint *s = ((const GLuint *) src);
    769    GLuint i;
    770    for (i = 0; i < n; i++) {
    771       dst[i][RCOMP] = nonlinear_to_linear( (s[i] >> 16) & 0xff );
    772       dst[i][GCOMP] = nonlinear_to_linear( (s[i] >>  8) & 0xff );
    773       dst[i][BCOMP] = nonlinear_to_linear( (s[i]      ) & 0xff );
    774       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
    775    }
    776 }
    777 
    778 static void
    779 unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
    780 {
    781    const GLubyte *s = ((const GLubyte *) src);
    782    GLuint i;
    783    for (i = 0; i < n; i++) {
    784       dst[i][RCOMP] =
    785       dst[i][GCOMP] =
    786       dst[i][BCOMP] = nonlinear_to_linear(s[i]);
    787       dst[i][ACOMP] = 1.0F;
    788    }
    789 }
    790 
    791 static void
    792 unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
    793 {
    794    const GLushort *s = (const GLushort *) src;
    795    GLuint i;
    796    for (i = 0; i < n; i++) {
    797       dst[i][RCOMP] =
    798       dst[i][GCOMP] =
    799       dst[i][BCOMP] = nonlinear_to_linear(s[i] & 0xff);
    800       dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
    801    }
    802 }
    803 
    804 static void
    805 unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
    806 {
    807 }
    808 
    809 static void
    810 unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
    811 {
    812 }
    813 
    814 static void
    815 unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
    816 {
    817 }
    818 
    819 static void
    820 unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
    821 {
    822 }
    823 
    824 static void
    825 unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
    826 {
    827 }
    828 
    829 static void
    830 unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
    831 {
    832 }
    833 
    834 static void
    835 unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
    836 {
    837 }
    838 
    839 static void
    840 unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
    841 {
    842 }
    843 
    844 static void
    845 unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
    846 {
    847 }
    848 
    849 static void
    850 unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
    851 {
    852 }
    853 
    854 
    855 static void
    856 unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
    857 {
    858    const GLfloat *s = (const GLfloat *) src;
    859    GLuint i;
    860    for (i = 0; i < n; i++) {
    861       dst[i][RCOMP] = s[i*4+0];
    862       dst[i][GCOMP] = s[i*4+1];
    863       dst[i][BCOMP] = s[i*4+2];
    864       dst[i][ACOMP] = s[i*4+3];
    865    }
    866 }
    867 
    868 static void
    869 unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
    870 {
    871    const GLhalfARB *s = (const GLhalfARB *) src;
    872    GLuint i;
    873    for (i = 0; i < n; i++) {
    874       dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
    875       dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
    876       dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
    877       dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
    878    }
    879 }
    880 
    881 static void
    882 unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
    883 {
    884    const GLfloat *s = (const GLfloat *) src;
    885    GLuint i;
    886    for (i = 0; i < n; i++) {
    887       dst[i][RCOMP] = s[i*3+0];
    888       dst[i][GCOMP] = s[i*3+1];
    889       dst[i][BCOMP] = s[i*3+2];
    890       dst[i][ACOMP] = 1.0F;
    891    }
    892 }
    893 
    894 static void
    895 unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
    896 {
    897    const GLhalfARB *s = (const GLhalfARB *) src;
    898    GLuint i;
    899    for (i = 0; i < n; i++) {
    900       dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
    901       dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
    902       dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
    903       dst[i][ACOMP] = 1.0F;
    904    }
    905 }
    906 
    907 static void
    908 unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
    909 {
    910    const GLfloat *s = (const GLfloat *) src;
    911    GLuint i;
    912    for (i = 0; i < n; i++) {
    913       dst[i][RCOMP] =
    914       dst[i][GCOMP] =
    915       dst[i][BCOMP] = 0.0F;
    916       dst[i][ACOMP] = s[i];
    917    }
    918 }
    919 
    920 static void
    921 unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
    922 {
    923    const GLhalfARB *s = (const GLhalfARB *) src;
    924    GLuint i;
    925    for (i = 0; i < n; i++) {
    926       dst[i][RCOMP] =
    927       dst[i][GCOMP] =
    928       dst[i][BCOMP] = 0.0F;
    929       dst[i][ACOMP] = _mesa_half_to_float(s[i]);
    930    }
    931 }
    932 
    933 static void
    934 unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
    935 {
    936    const GLfloat *s = (const GLfloat *) src;
    937    GLuint i;
    938    for (i = 0; i < n; i++) {
    939       dst[i][RCOMP] =
    940       dst[i][GCOMP] =
    941       dst[i][BCOMP] = s[i];
    942       dst[i][ACOMP] = 1.0F;
    943    }
    944 }
    945 
    946 static void
    947 unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
    948 {
    949    const GLhalfARB *s = (const GLhalfARB *) src;
    950    GLuint i;
    951    for (i = 0; i < n; i++) {
    952       dst[i][RCOMP] =
    953       dst[i][GCOMP] =
    954       dst[i][BCOMP] = _mesa_half_to_float(s[i]);
    955       dst[i][ACOMP] = 1.0F;
    956    }
    957 }
    958 
    959 static void
    960 unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
    961 {
    962    const GLfloat *s = (const GLfloat *) src;
    963    GLuint i;
    964    for (i = 0; i < n; i++) {
    965       dst[i][RCOMP] =
    966       dst[i][GCOMP] =
    967       dst[i][BCOMP] = s[i*2+0];
    968       dst[i][ACOMP] = s[i*2+1];
    969    }
    970 }
    971 
    972 static void
    973 unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
    974 {
    975    const GLhalfARB *s = (const GLhalfARB *) src;
    976    GLuint i;
    977    for (i = 0; i < n; i++) {
    978       dst[i][RCOMP] =
    979       dst[i][GCOMP] =
    980       dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
    981       dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
    982    }
    983 }
    984 
    985 static void
    986 unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
    987 {
    988    const GLfloat *s = (const GLfloat *) src;
    989    GLuint i;
    990    for (i = 0; i < n; i++) {
    991       dst[i][RCOMP] =
    992       dst[i][GCOMP] =
    993       dst[i][BCOMP] =
    994       dst[i][ACOMP] = s[i];
    995    }
    996 }
    997 
    998 static void
    999 unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
   1000 {
   1001    const GLhalfARB *s = (const GLhalfARB *) src;
   1002    GLuint i;
   1003    for (i = 0; i < n; i++) {
   1004       dst[i][RCOMP] =
   1005       dst[i][GCOMP] =
   1006       dst[i][BCOMP] =
   1007       dst[i][ACOMP] = _mesa_half_to_float(s[i]);
   1008    }
   1009 }
   1010 
   1011 static void
   1012 unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
   1013 {
   1014    const GLfloat *s = (const GLfloat *) src;
   1015    GLuint i;
   1016    for (i = 0; i < n; i++) {
   1017       dst[i][RCOMP] = s[i];
   1018       dst[i][GCOMP] = 0.0F;
   1019       dst[i][BCOMP] = 0.0F;
   1020       dst[i][ACOMP] = 1.0F;
   1021    }
   1022 }
   1023 
   1024 static void
   1025 unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
   1026 {
   1027    const GLhalfARB *s = (const GLhalfARB *) src;
   1028    GLuint i;
   1029    for (i = 0; i < n; i++) {
   1030       dst[i][RCOMP] = _mesa_half_to_float(s[i]);
   1031       dst[i][GCOMP] = 0.0F;
   1032       dst[i][BCOMP] = 0.0F;
   1033       dst[i][ACOMP] = 1.0F;
   1034    }
   1035 }
   1036 
   1037 static void
   1038 unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
   1039 {
   1040    const GLfloat *s = (const GLfloat *) src;
   1041    GLuint i;
   1042    for (i = 0; i < n; i++) {
   1043       dst[i][RCOMP] = s[i*2+0];
   1044       dst[i][GCOMP] = s[i*2+1];
   1045       dst[i][BCOMP] = 0.0F;
   1046       dst[i][ACOMP] = 1.0F;
   1047    }
   1048 }
   1049 
   1050 static void
   1051 unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
   1052 {
   1053    const GLhalfARB *s = (const GLhalfARB *) src;
   1054    GLuint i;
   1055    for (i = 0; i < n; i++) {
   1056       dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
   1057       dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
   1058       dst[i][BCOMP] = 0.0F;
   1059       dst[i][ACOMP] = 1.0F;
   1060    }
   1061 }
   1062 
   1063 
   1064 static void
   1065 unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
   1066 {
   1067    const GLbyte *s = (const GLbyte *) src;
   1068    GLuint i;
   1069    for (i = 0; i < n; i++) {
   1070       dst[i][RCOMP] = (GLfloat) s[i*4+0];
   1071       dst[i][GCOMP] = (GLfloat) s[i*4+1];
   1072       dst[i][BCOMP] = (GLfloat) s[i*4+2];
   1073       dst[i][ACOMP] = (GLfloat) s[i*4+3];
   1074    }
   1075 }
   1076 
   1077 static void
   1078 unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
   1079 {
   1080    const GLshort *s = (const GLshort *) src;
   1081    GLuint i;
   1082    for (i = 0; i < n; i++) {
   1083       dst[i][RCOMP] = (GLfloat) s[i*4+0];
   1084       dst[i][GCOMP] = (GLfloat) s[i*4+1];
   1085       dst[i][BCOMP] = (GLfloat) s[i*4+2];
   1086       dst[i][ACOMP] = (GLfloat) s[i*4+3];
   1087    }
   1088 }
   1089 
   1090 static void
   1091 unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
   1092 {
   1093    const GLint *s = (const GLint *) src;
   1094    GLuint i;
   1095    for (i = 0; i < n; i++) {
   1096       dst[i][RCOMP] = (GLfloat) s[i*4+0];
   1097       dst[i][GCOMP] = (GLfloat) s[i*4+1];
   1098       dst[i][BCOMP] = (GLfloat) s[i*4+2];
   1099       dst[i][ACOMP] = (GLfloat) s[i*4+3];
   1100    }
   1101 }
   1102 
   1103 static void
   1104 unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
   1105 {
   1106    const GLubyte *s = (const GLubyte *) src;
   1107    GLuint i;
   1108    for (i = 0; i < n; i++) {
   1109       dst[i][RCOMP] = (GLfloat) s[i*4+0];
   1110       dst[i][GCOMP] = (GLfloat) s[i*4+1];
   1111       dst[i][BCOMP] = (GLfloat) s[i*4+2];
   1112       dst[i][ACOMP] = (GLfloat) s[i*4+3];
   1113    }
   1114 }
   1115 
   1116 static void
   1117 unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
   1118 {
   1119    const GLushort *s = (const GLushort *) src;
   1120    GLuint i;
   1121    for (i = 0; i < n; i++) {
   1122       dst[i][RCOMP] = (GLfloat) s[i*4+0];
   1123       dst[i][GCOMP] = (GLfloat) s[i*4+1];
   1124       dst[i][BCOMP] = (GLfloat) s[i*4+2];
   1125       dst[i][ACOMP] = (GLfloat) s[i*4+3];
   1126    }
   1127 }
   1128 
   1129 static void
   1130 unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
   1131 {
   1132    const GLuint *s = (const GLuint *) src;
   1133    GLuint i;
   1134    for (i = 0; i < n; i++) {
   1135       dst[i][RCOMP] = (GLfloat) s[i*4+0];
   1136       dst[i][GCOMP] = (GLfloat) s[i*4+1];
   1137       dst[i][BCOMP] = (GLfloat) s[i*4+2];
   1138       dst[i][ACOMP] = (GLfloat) s[i*4+3];
   1139    }
   1140 }
   1141 
   1142 static void
   1143 unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
   1144 {
   1145    const GLbyte *s = (const GLbyte *) src;
   1146    GLuint i;
   1147    for (i = 0; i < n; i++) {
   1148       dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
   1149       dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
   1150       dst[i][BCOMP] = 0;
   1151       dst[i][ACOMP] = 0;
   1152    }
   1153 }
   1154 
   1155 static void
   1156 unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
   1157 {
   1158    const GLbyte *s = ((const GLbyte *) src);
   1159    GLuint i;
   1160    for (i = 0; i < n; i++) {
   1161       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
   1162       dst[i][GCOMP] = 0.0F;
   1163       dst[i][BCOMP] = 0.0F;
   1164       dst[i][ACOMP] = 1.0F;
   1165    }
   1166 }
   1167 
   1168 static void
   1169 unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
   1170 {
   1171    const GLushort *s = ((const GLushort *) src);
   1172    GLuint i;
   1173    for (i = 0; i < n; i++) {
   1174       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
   1175       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
   1176       dst[i][BCOMP] = 0.0F;
   1177       dst[i][ACOMP] = 1.0F;
   1178    }
   1179 }
   1180 
   1181 static void
   1182 unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
   1183 {
   1184    const GLuint *s = ((const GLuint *) src);
   1185    GLuint i;
   1186    for (i = 0; i < n; i++) {
   1187       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
   1188       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
   1189       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
   1190       dst[i][ACOMP] = 1.0f;
   1191    }
   1192 }
   1193 
   1194 static void
   1195 unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
   1196 {
   1197    const GLuint *s = ((const GLuint *) src);
   1198    GLuint i;
   1199    for (i = 0; i < n; i++) {
   1200       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
   1201       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
   1202       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
   1203       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
   1204    }
   1205 }
   1206 
   1207 static void
   1208 unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
   1209 {
   1210    const GLuint *s = ((const GLuint *) src);
   1211    GLuint i;
   1212    for (i = 0; i < n; i++) {
   1213       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
   1214       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
   1215       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
   1216       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
   1217    }
   1218 }
   1219 
   1220 static void
   1221 unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
   1222 {
   1223    const GLshort *s = ((const GLshort *) src);
   1224    GLuint i;
   1225    for (i = 0; i < n; i++) {
   1226       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
   1227       dst[i][GCOMP] = 0.0F;
   1228       dst[i][BCOMP] = 0.0F;
   1229       dst[i][ACOMP] = 1.0F;
   1230    }
   1231 }
   1232 
   1233 static void
   1234 unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
   1235 {
   1236    const GLuint *s = ((const GLuint *) src);
   1237    GLuint i;
   1238    for (i = 0; i < n; i++) {
   1239       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
   1240       dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
   1241       dst[i][BCOMP] = 0.0F;
   1242       dst[i][ACOMP] = 1.0F;
   1243    }
   1244 }
   1245 
   1246 static void
   1247 unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
   1248 {
   1249    const GLshort *s = (const GLshort *) src;
   1250    GLuint i;
   1251    for (i = 0; i < n; i++) {
   1252       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
   1253       dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
   1254       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
   1255       dst[i][ACOMP] = 1.0F;
   1256    }
   1257 }
   1258 
   1259 static void
   1260 unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
   1261 {
   1262    const GLshort *s = (const GLshort *) src;
   1263    GLuint i;
   1264    for (i = 0; i < n; i++) {
   1265       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
   1266       dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
   1267       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
   1268       dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
   1269    }
   1270 }
   1271 
   1272 static void
   1273 unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
   1274 {
   1275    const GLushort *s = (const GLushort *) src;
   1276    GLuint i;
   1277    for (i = 0; i < n; i++) {
   1278       dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
   1279       dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
   1280       dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
   1281       dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
   1282    }
   1283 }
   1284 
   1285 static void
   1286 unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
   1287 {
   1288    /* XXX to do */
   1289 }
   1290 
   1291 static void
   1292 unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
   1293 {
   1294    /* XXX to do */
   1295 }
   1296 
   1297 static void
   1298 unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
   1299 {
   1300    /* XXX to do */
   1301 }
   1302 
   1303 static void
   1304 unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
   1305 {
   1306    /* XXX to do */
   1307 }
   1308 
   1309 static void
   1310 unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
   1311 {
   1312    /* XXX to do */
   1313 }
   1314 
   1315 static void
   1316 unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
   1317 {
   1318    /* XXX to do */
   1319 }
   1320 
   1321 static void
   1322 unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
   1323 {
   1324    /* XXX to do */
   1325 }
   1326 
   1327 static void
   1328 unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
   1329 {
   1330    /* XXX to do */
   1331 }
   1332 
   1333 static void
   1334 unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
   1335 {
   1336    /* XXX to do */
   1337 }
   1338 
   1339 static void
   1340 unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
   1341 {
   1342    const GLbyte *s = ((const GLbyte *) src);
   1343    GLuint i;
   1344    for (i = 0; i < n; i++) {
   1345       dst[i][RCOMP] = 0.0F;
   1346       dst[i][GCOMP] = 0.0F;
   1347       dst[i][BCOMP] = 0.0F;
   1348       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
   1349    }
   1350 }
   1351 
   1352 static void
   1353 unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
   1354 {
   1355    const GLbyte *s = ((const GLbyte *) src);
   1356    GLuint i;
   1357    for (i = 0; i < n; i++) {
   1358       dst[i][RCOMP] =
   1359       dst[i][GCOMP] =
   1360       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
   1361       dst[i][ACOMP] = 1.0F;
   1362    }
   1363 }
   1364 
   1365 static void
   1366 unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
   1367 {
   1368    const GLshort *s = ((const GLshort *) src);
   1369    GLuint i;
   1370    for (i = 0; i < n; i++) {
   1371       dst[i][RCOMP] =
   1372       dst[i][GCOMP] =
   1373       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
   1374       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
   1375    }
   1376 }
   1377 
   1378 static void
   1379 unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
   1380 {
   1381    const GLbyte *s = ((const GLbyte *) src);
   1382    GLuint i;
   1383    for (i = 0; i < n; i++) {
   1384       dst[i][RCOMP] =
   1385       dst[i][GCOMP] =
   1386       dst[i][BCOMP] =
   1387       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
   1388    }
   1389 }
   1390 
   1391 static void
   1392 unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
   1393 {
   1394    const GLshort *s = ((const GLshort *) src);
   1395    GLuint i;
   1396    for (i = 0; i < n; i++) {
   1397       dst[i][RCOMP] = 0.0F;
   1398       dst[i][GCOMP] = 0.0F;
   1399       dst[i][BCOMP] = 0.0F;
   1400       dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
   1401    }
   1402 }
   1403 
   1404 static void
   1405 unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
   1406 {
   1407    const GLshort *s = ((const GLshort *) src);
   1408    GLuint i;
   1409    for (i = 0; i < n; i++) {
   1410       dst[i][RCOMP] =
   1411       dst[i][GCOMP] =
   1412       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
   1413       dst[i][ACOMP] = 1.0F;
   1414    }
   1415 }
   1416 
   1417 static void
   1418 unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
   1419 {
   1420    const GLshort *s = (const GLshort *) src;
   1421    GLuint i;
   1422    for (i = 0; i < n; i++) {
   1423       dst[i][RCOMP] =
   1424       dst[i][GCOMP] =
   1425       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
   1426       dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
   1427    }
   1428 }
   1429 
   1430 static void
   1431 unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
   1432 {
   1433    const GLshort *s = ((const GLshort *) src);
   1434    GLuint i;
   1435    for (i = 0; i < n; i++) {
   1436       dst[i][RCOMP] =
   1437       dst[i][GCOMP] =
   1438       dst[i][BCOMP] =
   1439       dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
   1440    }
   1441 }
   1442 
   1443 static void
   1444 unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
   1445 {
   1446    const GLuint *s = (const GLuint *) src;
   1447    GLuint i;
   1448    for (i = 0; i < n; i++) {
   1449       rgb9e5_to_float3(s[i], dst[i]);
   1450       dst[i][ACOMP] = 1.0F;
   1451    }
   1452 }
   1453 
   1454 static void
   1455 unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
   1456 {
   1457    const GLuint *s = (const GLuint *) src;
   1458    GLuint i;
   1459    for (i = 0; i < n; i++) {
   1460       r11g11b10f_to_float3(s[i], dst[i]);
   1461       dst[i][ACOMP] = 1.0F;
   1462    }
   1463 }
   1464 
   1465 
   1466 /**
   1467  * Return the unpacker function for the given format.
   1468  */
   1469 static unpack_rgba_func
   1470 get_unpack_rgba_function(gl_format format)
   1471 {
   1472    static unpack_rgba_func table[MESA_FORMAT_COUNT];
   1473    static GLboolean initialized = GL_FALSE;
   1474 
   1475    if (!initialized) {
   1476       table[MESA_FORMAT_NONE] = NULL;
   1477 
   1478       table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
   1479       table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
   1480       table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
   1481       table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
   1482       table[MESA_FORMAT_RGBX8888] = unpack_RGBX8888;
   1483       table[MESA_FORMAT_RGBX8888_REV] = unpack_RGBX8888_REV;
   1484       table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
   1485       table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
   1486       table[MESA_FORMAT_RGB888] = unpack_RGB888;
   1487       table[MESA_FORMAT_BGR888] = unpack_BGR888;
   1488       table[MESA_FORMAT_RGB565] = unpack_RGB565;
   1489       table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
   1490       table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
   1491       table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
   1492       table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
   1493       table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
   1494       table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
   1495       table[MESA_FORMAT_AL44] = unpack_AL44;
   1496       table[MESA_FORMAT_AL88] = unpack_AL88;
   1497       table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
   1498       table[MESA_FORMAT_AL1616] = unpack_AL1616;
   1499       table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
   1500       table[MESA_FORMAT_RGB332] = unpack_RGB332;
   1501       table[MESA_FORMAT_A8] = unpack_A8;
   1502       table[MESA_FORMAT_A16] = unpack_A16;
   1503       table[MESA_FORMAT_L8] = unpack_L8;
   1504       table[MESA_FORMAT_L16] = unpack_L16;
   1505       table[MESA_FORMAT_I8] = unpack_I8;
   1506       table[MESA_FORMAT_I16] = unpack_I16;
   1507       table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
   1508       table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
   1509       table[MESA_FORMAT_R8] = unpack_R8;
   1510       table[MESA_FORMAT_GR88] = unpack_GR88;
   1511       table[MESA_FORMAT_RG88] = unpack_RG88;
   1512       table[MESA_FORMAT_R16] = unpack_R16;
   1513       table[MESA_FORMAT_RG1616] = unpack_RG1616;
   1514       table[MESA_FORMAT_RG1616_REV] = unpack_RG1616_REV;
   1515       table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
   1516       table[MESA_FORMAT_ABGR2101010_UINT] = unpack_ABGR2101010_UINT;
   1517       table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
   1518       table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
   1519       table[MESA_FORMAT_Z16] = unpack_Z16;
   1520       table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
   1521       table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
   1522       table[MESA_FORMAT_Z32] = unpack_Z32;
   1523       table[MESA_FORMAT_S8] = unpack_S8;
   1524       table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
   1525       table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
   1526       table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
   1527       table[MESA_FORMAT_SL8] = unpack_SL8;
   1528       table[MESA_FORMAT_SLA8] = unpack_SLA8;
   1529       table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
   1530       table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
   1531       table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
   1532       table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
   1533 
   1534       table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
   1535       table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
   1536       table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
   1537       table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
   1538       table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
   1539       table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
   1540 
   1541       table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
   1542       table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
   1543       table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
   1544       table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
   1545       table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
   1546       table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
   1547       table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
   1548       table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
   1549       table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
   1550       table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
   1551       table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
   1552       table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
   1553       table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
   1554       table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
   1555       table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
   1556       table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
   1557 
   1558       table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
   1559       table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
   1560       table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
   1561       table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
   1562       table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
   1563       table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
   1564 
   1565       table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
   1566       table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
   1567       table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
   1568       table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
   1569       table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
   1570       table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
   1571       table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
   1572       table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
   1573       table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
   1574       table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
   1575       table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
   1576 
   1577       table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
   1578       table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
   1579       table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
   1580       table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
   1581 
   1582       table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
   1583       table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
   1584       table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
   1585       table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
   1586 
   1587       table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
   1588 
   1589       table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
   1590       table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
   1591       table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
   1592       table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
   1593       table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
   1594       table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
   1595       table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
   1596       table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
   1597 
   1598       table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
   1599       table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
   1600 
   1601       table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
   1602       table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
   1603 
   1604       initialized = GL_TRUE;
   1605    }
   1606 
   1607    if (table[format] == NULL) {
   1608       _mesa_problem(NULL, "unsupported unpack for format %s",
   1609                     _mesa_get_format_name(format));
   1610    }
   1611 
   1612    return table[format];
   1613 }
   1614 
   1615 
   1616 /**
   1617  * Unpack rgba colors, returning as GLfloat values.
   1618  */
   1619 void
   1620 _mesa_unpack_rgba_row(gl_format format, GLuint n,
   1621                       const void *src, GLfloat dst[][4])
   1622 {
   1623    unpack_rgba_func unpack = get_unpack_rgba_function(format);
   1624    unpack(src, dst, n);
   1625 }
   1626 
   1627 
   1628 /**********************************************************************/
   1629 /*  Unpack, returning GLubyte colors                                  */
   1630 /**********************************************************************/
   1631 
   1632 
   1633 static void
   1634 unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
   1635 {
   1636    const GLuint *s = ((const GLuint *) src);
   1637    GLuint i;
   1638    for (i = 0; i < n; i++) {
   1639       dst[i][RCOMP] = (s[i] >> 24);
   1640       dst[i][GCOMP] = (s[i] >> 16) & 0xff;
   1641       dst[i][BCOMP] = (s[i] >>  8) & 0xff;
   1642       dst[i][ACOMP] = (s[i]      ) & 0xff;
   1643    }
   1644 }
   1645 
   1646 static void
   1647 unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
   1648 {
   1649    const GLuint *s = ((const GLuint *) src);
   1650    GLuint i;
   1651    for (i = 0; i < n; i++) {
   1652       dst[i][RCOMP] = (s[i]      ) & 0xff;
   1653       dst[i][GCOMP] = (s[i] >>  8) & 0xff;
   1654       dst[i][BCOMP] = (s[i] >> 16) & 0xff;
   1655       dst[i][ACOMP] = (s[i] >> 24);
   1656    }
   1657 }
   1658 
   1659 static void
   1660 unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
   1661 {
   1662    const GLuint *s = ((const GLuint *) src);
   1663    GLuint i;
   1664    for (i = 0; i < n; i++) {
   1665       dst[i][RCOMP] = (s[i] >> 16) & 0xff;
   1666       dst[i][GCOMP] = (s[i] >>  8) & 0xff;
   1667       dst[i][BCOMP] = (s[i]      ) & 0xff;
   1668       dst[i][ACOMP] = (s[i] >> 24);
   1669    }
   1670 }
   1671 
   1672 static void
   1673 unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
   1674 {
   1675    const GLuint *s = ((const GLuint *) src);
   1676    GLuint i;
   1677    for (i = 0; i < n; i++) {
   1678       dst[i][RCOMP] = (s[i] >>  8) & 0xff;
   1679       dst[i][GCOMP] = (s[i] >> 16) & 0xff;
   1680       dst[i][BCOMP] = (s[i] >> 24);
   1681       dst[i][ACOMP] = (s[i]      ) & 0xff;
   1682    }
   1683 }
   1684 
   1685 static void
   1686 unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
   1687 {
   1688    const GLuint *s = ((const GLuint *) src);
   1689    GLuint i;
   1690    for (i = 0; i < n; i++) {
   1691       dst[i][RCOMP] = (s[i] >> 24);
   1692       dst[i][GCOMP] = (s[i] >> 16) & 0xff;
   1693       dst[i][BCOMP] = (s[i] >>  8) & 0xff;
   1694       dst[i][ACOMP] = 0xff;
   1695    }
   1696 }
   1697 
   1698 static void
   1699 unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
   1700 {
   1701    const GLuint *s = ((const GLuint *) src);
   1702    GLuint i;
   1703    for (i = 0; i < n; i++) {
   1704       dst[i][RCOMP] = (s[i]      ) & 0xff;
   1705       dst[i][GCOMP] = (s[i] >>  8) & 0xff;
   1706       dst[i][BCOMP] = (s[i] >> 16) & 0xff;
   1707       dst[i][ACOMP] = 0xff;
   1708    }
   1709 }
   1710 
   1711 static void
   1712 unpack_ubyte_XRGB8888(const void *src, GLubyte dst[][4], GLuint n)
   1713 {
   1714    const GLuint *s = ((const GLuint *) src);
   1715    GLuint i;
   1716    for (i = 0; i < n; i++) {
   1717       dst[i][RCOMP] = (s[i] >> 16) & 0xff;
   1718       dst[i][GCOMP] = (s[i] >>  8) & 0xff;
   1719       dst[i][BCOMP] = (s[i]      ) & 0xff;
   1720       dst[i][ACOMP] = 0xff;
   1721    }
   1722 }
   1723 
   1724 static void
   1725 unpack_ubyte_XRGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
   1726 {
   1727    const GLuint *s = ((const GLuint *) src);
   1728    GLuint i;
   1729    for (i = 0; i < n; i++) {
   1730       dst[i][RCOMP] = (s[i] >>  8) & 0xff;
   1731       dst[i][GCOMP] = (s[i] >> 16) & 0xff;
   1732       dst[i][BCOMP] = (s[i] >> 24);
   1733       dst[i][ACOMP] = 0xff;
   1734    }
   1735 }
   1736 
   1737 static void
   1738 unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
   1739 {
   1740    const GLubyte *s = (const GLubyte *) src;
   1741    GLuint i;
   1742    for (i = 0; i < n; i++) {
   1743       dst[i][RCOMP] = s[i*3+2];
   1744       dst[i][GCOMP] = s[i*3+1];
   1745       dst[i][BCOMP] = s[i*3+0];
   1746       dst[i][ACOMP] = 0xff;
   1747    }
   1748 }
   1749 
   1750 static void
   1751 unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
   1752 {
   1753    const GLubyte *s = (const GLubyte *) src;
   1754    GLuint i;
   1755    for (i = 0; i < n; i++) {
   1756       dst[i][RCOMP] = s[i*3+0];
   1757       dst[i][GCOMP] = s[i*3+1];
   1758       dst[i][BCOMP] = s[i*3+2];
   1759       dst[i][ACOMP] = 0xff;
   1760    }
   1761 }
   1762 
   1763 static void
   1764 unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
   1765 {
   1766    const GLushort *s = ((const GLushort *) src);
   1767    GLuint i;
   1768    for (i = 0; i < n; i++) {
   1769       dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
   1770       dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
   1771       dst[i][BCOMP] = EXPAND_5_8( s[i]        & 0x1f);
   1772       dst[i][ACOMP] = 0xff;
   1773    }
   1774 }
   1775 
   1776 static void
   1777 unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
   1778 {
   1779    const GLushort *s = ((const GLushort *) src);
   1780    GLuint i;
   1781    for (i = 0; i < n; i++) {
   1782       GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
   1783       dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
   1784       dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
   1785       dst[i][BCOMP] = EXPAND_5_8( t        & 0x1f);
   1786       dst[i][ACOMP] = 0xff;
   1787    }
   1788 }
   1789 
   1790 static void
   1791 unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
   1792 {
   1793    const GLushort *s = ((const GLushort *) src);
   1794    GLuint i;
   1795    for (i = 0; i < n; i++) {
   1796       dst[i][RCOMP] = EXPAND_4_8((s[i] >>  8) & 0xf);
   1797       dst[i][GCOMP] = EXPAND_4_8((s[i] >>  4) & 0xf);
   1798       dst[i][BCOMP] = EXPAND_4_8((s[i]      ) & 0xf);
   1799       dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
   1800    }
   1801 }
   1802 
   1803 static void
   1804 unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
   1805 {
   1806    const GLushort *s = ((const GLushort *) src);
   1807    GLuint i;
   1808    for (i = 0; i < n; i++) {
   1809       dst[i][RCOMP] = EXPAND_4_8((s[i]      ) & 0xf);
   1810       dst[i][GCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
   1811       dst[i][BCOMP] = EXPAND_4_8((s[i] >>  8) & 0xf);
   1812       dst[i][ACOMP] = EXPAND_4_8((s[i] >>  4) & 0xf);
   1813    }
   1814 }
   1815 
   1816 static void
   1817 unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
   1818 {
   1819    const GLushort *s = ((const GLushort *) src);
   1820    GLuint i;
   1821    for (i = 0; i < n; i++) {
   1822       dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
   1823       dst[i][GCOMP] = EXPAND_5_8((s[i] >>  6) & 0x1f);
   1824       dst[i][BCOMP] = EXPAND_5_8((s[i] >>  1) & 0x1f);
   1825       dst[i][ACOMP] = EXPAND_1_8((s[i]      ) & 0x01);
   1826    }
   1827 }
   1828 
   1829 static void
   1830 unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
   1831 {
   1832    const GLushort *s = ((const GLushort *) src);
   1833    GLuint i;
   1834    for (i = 0; i < n; i++) {
   1835       dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
   1836       dst[i][GCOMP] = EXPAND_5_8((s[i] >>  5) & 0x1f);
   1837       dst[i][BCOMP] = EXPAND_5_8((s[i] >>  0) & 0x1f);
   1838       dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
   1839    }
   1840 }
   1841 
   1842 static void
   1843 unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
   1844 {
   1845    const GLushort *s = ((const GLushort *) src);
   1846    GLuint i;
   1847    for (i = 0; i < n; i++) {
   1848       GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
   1849       dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
   1850       dst[i][GCOMP] = EXPAND_5_8((tmp >>  5) & 0x1f);
   1851       dst[i][BCOMP] = EXPAND_5_8((tmp >>  0) & 0x1f);
   1852       dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
   1853    }
   1854 }
   1855 
   1856 static void
   1857 unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
   1858 {
   1859    const GLubyte *s = ((const GLubyte *) src);
   1860    GLuint i;
   1861    for (i = 0; i < n; i++) {
   1862       dst[i][RCOMP] =
   1863       dst[i][GCOMP] =
   1864       dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
   1865       dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
   1866    }
   1867 }
   1868 
   1869 static void
   1870 unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
   1871 {
   1872    const GLushort *s = ((const GLushort *) src);
   1873    GLuint i;
   1874    for (i = 0; i < n; i++) {
   1875       dst[i][RCOMP] =
   1876       dst[i][GCOMP] =
   1877       dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
   1878       dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
   1879    }
   1880 }
   1881 
   1882 static void
   1883 unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
   1884 {
   1885    const GLushort *s = ((const GLushort *) src);
   1886    GLuint i;
   1887    for (i = 0; i < n; i++) {
   1888       dst[i][RCOMP] =
   1889       dst[i][GCOMP] =
   1890       dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
   1891       dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
   1892    }
   1893 }
   1894 
   1895 static void
   1896 unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
   1897 {
   1898    const GLubyte *s = ((const GLubyte *) src);
   1899    GLuint i;
   1900    for (i = 0; i < n; i++) {
   1901       dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
   1902       dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
   1903       dst[i][BCOMP] = EXPAND_2_8((s[i]     ) & 0x3);
   1904       dst[i][ACOMP] = 0xff;
   1905    }
   1906 }
   1907 
   1908 static void
   1909 unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
   1910 {
   1911    const GLubyte *s = ((const GLubyte *) src);
   1912    GLuint i;
   1913    for (i = 0; i < n; i++) {
   1914       dst[i][RCOMP] =
   1915       dst[i][GCOMP] =
   1916       dst[i][BCOMP] = 0;
   1917       dst[i][ACOMP] = s[i];
   1918    }
   1919 }
   1920 
   1921 static void
   1922 unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
   1923 {
   1924    const GLubyte *s = ((const GLubyte *) src);
   1925    GLuint i;
   1926    for (i = 0; i < n; i++) {
   1927       dst[i][RCOMP] =
   1928       dst[i][GCOMP] =
   1929       dst[i][BCOMP] = s[i];
   1930       dst[i][ACOMP] = 0xff;
   1931    }
   1932 }
   1933 
   1934 
   1935 static void
   1936 unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
   1937 {
   1938    const GLubyte *s = ((const GLubyte *) src);
   1939    GLuint i;
   1940    for (i = 0; i < n; i++) {
   1941       dst[i][RCOMP] =
   1942       dst[i][GCOMP] =
   1943       dst[i][BCOMP] =
   1944       dst[i][ACOMP] = s[i];
   1945    }
   1946 }
   1947 
   1948 static void
   1949 unpack_ubyte_R8(const void *src, GLubyte dst[][4], GLuint n)
   1950 {
   1951    const GLubyte *s = ((const GLubyte *) src);
   1952    GLuint i;
   1953    for (i = 0; i < n; i++) {
   1954       dst[i][0] = s[i];
   1955       dst[i][1] =
   1956       dst[i][2] = 0;
   1957       dst[i][3] = 0xff;
   1958    }
   1959 }
   1960 
   1961 static void
   1962 unpack_ubyte_GR88(const void *src, GLubyte dst[][4], GLuint n)
   1963 {
   1964    const GLushort *s = ((const GLushort *) src);
   1965    GLuint i;
   1966    for (i = 0; i < n; i++) {
   1967       dst[i][RCOMP] = s[i] & 0xff;
   1968       dst[i][GCOMP] = s[i] >> 8;
   1969       dst[i][BCOMP] = 0;
   1970       dst[i][ACOMP] = 0xff;
   1971    }
   1972 }
   1973 
   1974 static void
   1975 unpack_ubyte_RG88(const void *src, GLubyte dst[][4], GLuint n)
   1976 {
   1977    const GLushort *s = ((const GLushort *) src);
   1978    GLuint i;
   1979    for (i = 0; i < n; i++) {
   1980       dst[i][RCOMP] = s[i] >> 8;
   1981       dst[i][GCOMP] = s[i] & 0xff;
   1982       dst[i][BCOMP] = 0;
   1983       dst[i][ACOMP] = 0xff;
   1984    }
   1985 }
   1986 
   1987 
   1988 /**
   1989  * Unpack rgba colors, returning as GLubyte values.  This should usually
   1990  * only be used for unpacking formats that use 8 bits or less per channel.
   1991  */
   1992 void
   1993 _mesa_unpack_ubyte_rgba_row(gl_format format, GLuint n,
   1994                             const void *src, GLubyte dst[][4])
   1995 {
   1996    switch (format) {
   1997    case MESA_FORMAT_RGBA8888:
   1998       unpack_ubyte_RGBA8888(src, dst, n);
   1999       break;
   2000    case MESA_FORMAT_RGBA8888_REV:
   2001       unpack_ubyte_RGBA8888_REV(src, dst, n);
   2002       break;
   2003    case MESA_FORMAT_ARGB8888:
   2004       unpack_ubyte_ARGB8888(src, dst, n);
   2005       break;
   2006    case MESA_FORMAT_ARGB8888_REV:
   2007       unpack_ubyte_ARGB8888_REV(src, dst, n);
   2008       break;
   2009    case MESA_FORMAT_RGBX8888:
   2010       unpack_ubyte_RGBX8888(src, dst, n);
   2011       break;
   2012    case MESA_FORMAT_RGBX8888_REV:
   2013       unpack_ubyte_RGBX8888_REV(src, dst, n);
   2014       break;
   2015    case MESA_FORMAT_XRGB8888:
   2016       unpack_ubyte_XRGB8888(src, dst, n);
   2017       break;
   2018    case MESA_FORMAT_XRGB8888_REV:
   2019       unpack_ubyte_XRGB8888_REV(src, dst, n);
   2020       break;
   2021    case MESA_FORMAT_RGB888:
   2022       unpack_ubyte_RGB888(src, dst, n);
   2023       break;
   2024    case MESA_FORMAT_BGR888:
   2025       unpack_ubyte_BGR888(src, dst, n);
   2026       break;
   2027    case MESA_FORMAT_RGB565:
   2028       unpack_ubyte_RGB565(src, dst, n);
   2029       break;
   2030    case MESA_FORMAT_RGB565_REV:
   2031       unpack_ubyte_RGB565_REV(src, dst, n);
   2032       break;
   2033    case MESA_FORMAT_ARGB4444:
   2034       unpack_ubyte_ARGB4444(src, dst, n);
   2035       break;
   2036    case MESA_FORMAT_ARGB4444_REV:
   2037       unpack_ubyte_ARGB4444_REV(src, dst, n);
   2038       break;
   2039    case MESA_FORMAT_RGBA5551:
   2040       unpack_ubyte_RGBA5551(src, dst, n);
   2041       break;
   2042    case MESA_FORMAT_ARGB1555:
   2043       unpack_ubyte_ARGB1555(src, dst, n);
   2044       break;
   2045    case MESA_FORMAT_ARGB1555_REV:
   2046       unpack_ubyte_ARGB1555_REV(src, dst, n);
   2047       break;
   2048    case MESA_FORMAT_AL44:
   2049       unpack_ubyte_AL44(src, dst, n);
   2050       break;
   2051    case MESA_FORMAT_AL88:
   2052       unpack_ubyte_AL88(src, dst, n);
   2053       break;
   2054    case MESA_FORMAT_AL88_REV:
   2055       unpack_ubyte_AL88_REV(src, dst, n);
   2056       break;
   2057    case MESA_FORMAT_RGB332:
   2058       unpack_ubyte_RGB332(src, dst, n);
   2059       break;
   2060    case MESA_FORMAT_A8:
   2061       unpack_ubyte_A8(src, dst, n);
   2062       break;
   2063    case MESA_FORMAT_L8:
   2064       unpack_ubyte_L8(src, dst, n);
   2065       break;
   2066    case MESA_FORMAT_I8:
   2067       unpack_ubyte_I8(src, dst, n);
   2068       break;
   2069    case MESA_FORMAT_R8:
   2070       unpack_ubyte_R8(src, dst, n);
   2071       break;
   2072    case MESA_FORMAT_GR88:
   2073       unpack_ubyte_GR88(src, dst, n);
   2074       break;
   2075    case MESA_FORMAT_RG88:
   2076       unpack_ubyte_RG88(src, dst, n);
   2077       break;
   2078    default:
   2079       /* get float values, convert to ubyte */
   2080       {
   2081          GLfloat *tmp = (GLfloat *) malloc(n * 4 * sizeof(GLfloat));
   2082          if (tmp) {
   2083             GLuint i;
   2084             _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
   2085             for (i = 0; i < n; i++) {
   2086                UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
   2087                UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
   2088                UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
   2089                UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
   2090             }
   2091             free(tmp);
   2092          }
   2093       }
   2094       break;
   2095    }
   2096 }
   2097 
   2098 
   2099 /**********************************************************************/
   2100 /*  Unpack, returning GLuint colors                                   */
   2101 /**********************************************************************/
   2102 
   2103 static void
   2104 unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
   2105 {
   2106    memcpy(dst, src, n * 4 * sizeof(GLuint));
   2107 }
   2108 
   2109 static void
   2110 unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
   2111 {
   2112    unsigned int i;
   2113 
   2114    for (i = 0; i < n; i++) {
   2115       dst[i][0] = src[i * 4 + 0];
   2116       dst[i][1] = src[i * 4 + 1];
   2117       dst[i][2] = src[i * 4 + 2];
   2118       dst[i][3] = src[i * 4 + 3];
   2119    }
   2120 }
   2121 
   2122 static void
   2123 unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
   2124 {
   2125    unsigned int i;
   2126 
   2127    for (i = 0; i < n; i++) {
   2128       dst[i][0] = src[i * 4 + 0];
   2129       dst[i][1] = src[i * 4 + 1];
   2130       dst[i][2] = src[i * 4 + 2];
   2131       dst[i][3] = src[i * 4 + 3];
   2132    }
   2133 }
   2134 
   2135 static void
   2136 unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
   2137 {
   2138    unsigned int i;
   2139 
   2140    for (i = 0; i < n; i++) {
   2141       dst[i][0] = src[i * 4 + 0];
   2142       dst[i][1] = src[i * 4 + 1];
   2143       dst[i][2] = src[i * 4 + 2];
   2144       dst[i][3] = src[i * 4 + 3];
   2145    }
   2146 }
   2147 
   2148 static void
   2149 unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
   2150 {
   2151    unsigned int i;
   2152 
   2153    for (i = 0; i < n; i++) {
   2154       dst[i][0] = src[i * 4 + 0];
   2155       dst[i][1] = src[i * 4 + 1];
   2156       dst[i][2] = src[i * 4 + 2];
   2157       dst[i][3] = src[i * 4 + 3];
   2158    }
   2159 }
   2160 
   2161 static void
   2162 unpack_int_rgba_ARGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
   2163 {
   2164    unsigned int i;
   2165 
   2166    for (i = 0; i < n; i++) {
   2167       dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
   2168       dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
   2169       dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
   2170       dst[i][ACOMP] = (GLubyte) src[i * 4 + 3];
   2171    }
   2172 }
   2173 
   2174 static void
   2175 unpack_int_rgba_XRGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
   2176 {
   2177    unsigned int i;
   2178 
   2179    for (i = 0; i < n; i++) {
   2180       dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
   2181       dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
   2182       dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
   2183       dst[i][ACOMP] = (GLubyte) 0xff;
   2184    }
   2185 }
   2186 
   2187 static void
   2188 unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
   2189 {
   2190    unsigned int i;
   2191 
   2192    for (i = 0; i < n; i++) {
   2193       dst[i][0] = src[i * 3 + 0];
   2194       dst[i][1] = src[i * 3 + 1];
   2195       dst[i][2] = src[i * 3 + 2];
   2196       dst[i][3] = 1;
   2197    }
   2198 }
   2199 
   2200 static void
   2201 unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
   2202 {
   2203    unsigned int i;
   2204 
   2205    for (i = 0; i < n; i++) {
   2206       dst[i][0] = src[i * 3 + 0];
   2207       dst[i][1] = src[i * 3 + 1];
   2208       dst[i][2] = src[i * 3 + 2];
   2209       dst[i][3] = 1;
   2210    }
   2211 }
   2212 
   2213 static void
   2214 unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
   2215 {
   2216    unsigned int i;
   2217 
   2218    for (i = 0; i < n; i++) {
   2219       dst[i][0] = src[i * 3 + 0];
   2220       dst[i][1] = src[i * 3 + 1];
   2221       dst[i][2] = src[i * 3 + 2];
   2222       dst[i][3] = 1;
   2223    }
   2224 }
   2225 
   2226 static void
   2227 unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
   2228 {
   2229    unsigned int i;
   2230 
   2231    for (i = 0; i < n; i++) {
   2232       dst[i][0] = src[i * 3 + 0];
   2233       dst[i][1] = src[i * 3 + 1];
   2234       dst[i][2] = src[i * 3 + 2];
   2235       dst[i][3] = 1;
   2236    }
   2237 }
   2238 
   2239 static void
   2240 unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
   2241 {
   2242    unsigned int i;
   2243 
   2244    for (i = 0; i < n; i++) {
   2245       dst[i][0] = src[i * 3 + 0];
   2246       dst[i][1] = src[i * 3 + 1];
   2247       dst[i][2] = src[i * 3 + 2];
   2248       dst[i][3] = 1;
   2249    }
   2250 }
   2251 
   2252 static void
   2253 unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
   2254 {
   2255    unsigned int i;
   2256 
   2257    for (i = 0; i < n; i++) {
   2258       dst[i][0] = src[i * 2 + 0];
   2259       dst[i][1] = src[i * 2 + 1];
   2260       dst[i][2] = 0;
   2261       dst[i][3] = 1;
   2262    }
   2263 }
   2264 
   2265 static void
   2266 unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
   2267 {
   2268    unsigned int i;
   2269 
   2270    for (i = 0; i < n; i++) {
   2271       dst[i][0] = src[i * 2 + 0];
   2272       dst[i][1] = src[i * 2 + 1];
   2273       dst[i][2] = 0;
   2274       dst[i][3] = 1;
   2275    }
   2276 }
   2277 
   2278 static void
   2279 unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
   2280 {
   2281    unsigned int i;
   2282 
   2283    for (i = 0; i < n; i++) {
   2284       dst[i][0] = src[i * 2 + 0];
   2285       dst[i][1] = src[i * 2 + 1];
   2286       dst[i][2] = 0;
   2287       dst[i][3] = 1;
   2288    }
   2289 }
   2290 
   2291 static void
   2292 unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
   2293 {
   2294    unsigned int i;
   2295 
   2296    for (i = 0; i < n; i++) {
   2297       dst[i][0] = src[i * 2 + 0];
   2298       dst[i][1] = src[i * 2 + 1];
   2299       dst[i][2] = 0;
   2300       dst[i][3] = 1;
   2301    }
   2302 }
   2303 
   2304 static void
   2305 unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
   2306 {
   2307    unsigned int i;
   2308 
   2309    for (i = 0; i < n; i++) {
   2310       dst[i][0] = src[i * 2 + 0];
   2311       dst[i][1] = src[i * 2 + 1];
   2312       dst[i][2] = 0;
   2313       dst[i][3] = 1;
   2314    }
   2315 }
   2316 
   2317 static void
   2318 unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
   2319 {
   2320    unsigned int i;
   2321 
   2322    for (i = 0; i < n; i++) {
   2323       dst[i][0] = src[i];
   2324       dst[i][1] = 0;
   2325       dst[i][2] = 0;
   2326       dst[i][3] = 1;
   2327    }
   2328 }
   2329 
   2330 static void
   2331 unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
   2332 {
   2333    unsigned int i;
   2334 
   2335    for (i = 0; i < n; i++) {
   2336       dst[i][0] = src[i];
   2337       dst[i][1] = 0;
   2338       dst[i][2] = 0;
   2339       dst[i][3] = 1;
   2340    }
   2341 }
   2342 
   2343 static void
   2344 unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
   2345 {
   2346    unsigned int i;
   2347 
   2348    for (i = 0; i < n; i++) {
   2349       dst[i][0] = src[i];
   2350       dst[i][1] = 0;
   2351       dst[i][2] = 0;
   2352       dst[i][3] = 1;
   2353    }
   2354 }
   2355 
   2356 static void
   2357 unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
   2358 {
   2359    unsigned int i;
   2360 
   2361    for (i = 0; i < n; i++) {
   2362       dst[i][0] = src[i];
   2363       dst[i][1] = 0;
   2364       dst[i][2] = 0;
   2365       dst[i][3] = 1;
   2366    }
   2367 }
   2368 
   2369 static void
   2370 unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
   2371 {
   2372    unsigned int i;
   2373 
   2374    for (i = 0; i < n; i++) {
   2375       dst[i][0] = src[i];
   2376       dst[i][1] = 0;
   2377       dst[i][2] = 0;
   2378       dst[i][3] = 1;
   2379    }
   2380 }
   2381 
   2382 static void
   2383 unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
   2384 {
   2385    unsigned int i;
   2386 
   2387    for (i = 0; i < n; i++) {
   2388       dst[i][0] = dst[i][1] = dst[i][2] = 0;
   2389       dst[i][3] = src[i];
   2390    }
   2391 }
   2392 
   2393 static void
   2394 unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
   2395 {
   2396    unsigned int i;
   2397 
   2398    for (i = 0; i < n; i++) {
   2399       dst[i][0] = dst[i][1] = dst[i][2] = 0;
   2400       dst[i][3] = src[i];
   2401    }
   2402 }
   2403 
   2404 static void
   2405 unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
   2406 {
   2407    unsigned int i;
   2408 
   2409    for (i = 0; i < n; i++) {
   2410       dst[i][0] = dst[i][1] = dst[i][2] = 0;
   2411       dst[i][3] = src[i];
   2412    }
   2413 }
   2414 
   2415 static void
   2416 unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
   2417 {
   2418    unsigned int i;
   2419 
   2420    for (i = 0; i < n; i++) {
   2421       dst[i][0] = dst[i][1] = dst[i][2] = 0;
   2422       dst[i][3] = src[i];
   2423    }
   2424 }
   2425 
   2426 static void
   2427 unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
   2428 {
   2429    unsigned int i;
   2430 
   2431    for (i = 0; i < n; i++) {
   2432       dst[i][0] = dst[i][1] = dst[i][2] = 0;
   2433       dst[i][3] = src[i];
   2434    }
   2435 }
   2436 
   2437 static void
   2438 unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
   2439 {
   2440    unsigned int i;
   2441 
   2442    for (i = 0; i < n; i++) {
   2443       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
   2444       dst[i][3] = 1;
   2445    }
   2446 }
   2447 
   2448 static void
   2449 unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
   2450 {
   2451    unsigned int i;
   2452 
   2453    for (i = 0; i < n; i++) {
   2454       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
   2455       dst[i][3] = 1;
   2456    }
   2457 }
   2458 
   2459 static void
   2460 unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
   2461 {
   2462    unsigned int i;
   2463 
   2464    for (i = 0; i < n; i++) {
   2465       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
   2466       dst[i][3] = 1;
   2467    }
   2468 }
   2469 
   2470 static void
   2471 unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
   2472 {
   2473    unsigned int i;
   2474 
   2475    for (i = 0; i < n; i++) {
   2476       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
   2477       dst[i][3] = 1;
   2478    }
   2479 }
   2480 
   2481 static void
   2482 unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
   2483 {
   2484    unsigned int i;
   2485 
   2486    for (i = 0; i < n; i++) {
   2487       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
   2488       dst[i][3] = 1;
   2489    }
   2490 }
   2491 
   2492 
   2493 static void
   2494 unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
   2495 {
   2496    unsigned int i;
   2497 
   2498    for (i = 0; i < n; i++) {
   2499       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
   2500       dst[i][3] = src[i * 2 + 1];
   2501    }
   2502 }
   2503 
   2504 static void
   2505 unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
   2506 {
   2507    unsigned int i;
   2508 
   2509    for (i = 0; i < n; i++) {
   2510       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
   2511       dst[i][3] = src[i * 2 + 1];
   2512    }
   2513 }
   2514 
   2515 static void
   2516 unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
   2517 {
   2518    unsigned int i;
   2519 
   2520    for (i = 0; i < n; i++) {
   2521       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
   2522       dst[i][3] = src[i * 2 + 1];
   2523    }
   2524 }
   2525 
   2526 static void
   2527 unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
   2528 {
   2529    unsigned int i;
   2530 
   2531    for (i = 0; i < n; i++) {
   2532       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
   2533       dst[i][3] = src[i * 2 + 1];
   2534    }
   2535 }
   2536 
   2537 static void
   2538 unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
   2539 {
   2540    unsigned int i;
   2541 
   2542    for (i = 0; i < n; i++) {
   2543       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
   2544       dst[i][3] = src[i * 2 + 1];
   2545    }
   2546 }
   2547 
   2548 static void
   2549 unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
   2550 {
   2551    unsigned int i;
   2552 
   2553    for (i = 0; i < n; i++) {
   2554       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   2555    }
   2556 }
   2557 
   2558 static void
   2559 unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
   2560 {
   2561    unsigned int i;
   2562 
   2563    for (i = 0; i < n; i++) {
   2564       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   2565    }
   2566 }
   2567 
   2568 static void
   2569 unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
   2570 {
   2571    unsigned int i;
   2572 
   2573    for (i = 0; i < n; i++) {
   2574       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   2575    }
   2576 }
   2577 
   2578 static void
   2579 unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
   2580 {
   2581    unsigned int i;
   2582 
   2583    for (i = 0; i < n; i++) {
   2584       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   2585    }
   2586 }
   2587 
   2588 static void
   2589 unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
   2590 {
   2591    unsigned int i;
   2592 
   2593    for (i = 0; i < n; i++) {
   2594       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   2595    }
   2596 }
   2597 
   2598 static void
   2599 unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
   2600 {
   2601    unsigned int i;
   2602 
   2603    for (i = 0; i < n; i++) {
   2604       GLuint tmp = src[i];
   2605       dst[i][0] = (tmp >> 20) & 0x3ff;
   2606       dst[i][1] = (tmp >> 10) & 0x3ff;
   2607       dst[i][2] = (tmp >> 0) & 0x3ff;
   2608       dst[i][3] = (tmp >> 30) & 0x3;
   2609    }
   2610 }
   2611 
   2612 static void
   2613 unpack_int_rgba_ABGR2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
   2614 {
   2615    unsigned int i;
   2616 
   2617    for (i = 0; i < n; i++) {
   2618       GLuint tmp = src[i];
   2619       dst[i][0] = (tmp >> 0) & 0x3ff;
   2620       dst[i][1] = (tmp >> 10) & 0x3ff;
   2621       dst[i][2] = (tmp >> 20) & 0x3ff;
   2622       dst[i][3] = (tmp >> 30) & 0x3;
   2623    }
   2624 }
   2625 
   2626 static void
   2627 unpack_int_rgba_ARGB2101010(const GLuint *src, GLuint dst[][4], GLuint n)
   2628 {
   2629    unsigned int i;
   2630 
   2631    for (i = 0; i < n; i++) {
   2632       GLuint tmp = src[i];
   2633       dst[i][0] = (tmp >> 20) & 0x3ff;
   2634       dst[i][1] = (tmp >> 10) & 0x3ff;
   2635       dst[i][2] = (tmp >> 0) & 0x3ff;
   2636       dst[i][3] = (tmp >> 30) & 0x3;
   2637    }
   2638 }
   2639 
   2640 void
   2641 _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
   2642                            const void *src, GLuint dst[][4])
   2643 {
   2644    switch (format) {
   2645       /* Since there won't be any sign extension happening, there's no need to
   2646        * make separate paths for 32-bit-to-32-bit integer unpack.
   2647        */
   2648    case MESA_FORMAT_RGBA_UINT32:
   2649    case MESA_FORMAT_RGBA_INT32:
   2650       unpack_int_rgba_RGBA_UINT32(src, dst, n);
   2651       break;
   2652 
   2653    case MESA_FORMAT_RGBA_UINT16:
   2654       unpack_int_rgba_RGBA_UINT16(src, dst, n);
   2655       break;
   2656    case MESA_FORMAT_RGBA_INT16:
   2657       unpack_int_rgba_RGBA_INT16(src, dst, n);
   2658       break;
   2659 
   2660    case MESA_FORMAT_RGBA_UINT8:
   2661       unpack_int_rgba_RGBA_UINT8(src, dst, n);
   2662       break;
   2663    case MESA_FORMAT_RGBA_INT8:
   2664       unpack_int_rgba_RGBA_INT8(src, dst, n);
   2665       break;
   2666 
   2667    case MESA_FORMAT_ARGB8888:
   2668       unpack_int_rgba_ARGB8888(src, dst, n);
   2669       break;
   2670 
   2671    case MESA_FORMAT_XRGB8888:
   2672       unpack_int_rgba_XRGB8888(src, dst, n);
   2673       break;
   2674 
   2675    case MESA_FORMAT_RGB_UINT32:
   2676    case MESA_FORMAT_RGB_INT32:
   2677       unpack_int_rgba_RGB_UINT32(src, dst, n);
   2678       break;
   2679 
   2680    case MESA_FORMAT_RGB_UINT16:
   2681       unpack_int_rgba_RGB_UINT16(src, dst, n);
   2682       break;
   2683    case MESA_FORMAT_RGB_INT16:
   2684       unpack_int_rgba_RGB_INT16(src, dst, n);
   2685       break;
   2686 
   2687    case MESA_FORMAT_RGB_UINT8:
   2688       unpack_int_rgba_RGB_UINT8(src, dst, n);
   2689       break;
   2690    case MESA_FORMAT_RGB_INT8:
   2691       unpack_int_rgba_RGB_INT8(src, dst, n);
   2692       break;
   2693 
   2694    case MESA_FORMAT_RG_UINT32:
   2695    case MESA_FORMAT_RG_INT32:
   2696       unpack_int_rgba_RG_UINT32(src, dst, n);
   2697       break;
   2698 
   2699    case MESA_FORMAT_RG_UINT16:
   2700       unpack_int_rgba_RG_UINT16(src, dst, n);
   2701       break;
   2702    case MESA_FORMAT_RG_INT16:
   2703       unpack_int_rgba_RG_INT16(src, dst, n);
   2704       break;
   2705 
   2706    case MESA_FORMAT_RG_UINT8:
   2707       unpack_int_rgba_RG_UINT8(src, dst, n);
   2708       break;
   2709    case MESA_FORMAT_RG_INT8:
   2710       unpack_int_rgba_RG_INT8(src, dst, n);
   2711       break;
   2712 
   2713    case MESA_FORMAT_R_UINT32:
   2714    case MESA_FORMAT_R_INT32:
   2715       unpack_int_rgba_R_UINT32(src, dst, n);
   2716       break;
   2717 
   2718    case MESA_FORMAT_R_UINT16:
   2719       unpack_int_rgba_R_UINT16(src, dst, n);
   2720       break;
   2721    case MESA_FORMAT_R_INT16:
   2722       unpack_int_rgba_R_INT16(src, dst, n);
   2723       break;
   2724 
   2725    case MESA_FORMAT_R_UINT8:
   2726       unpack_int_rgba_R_UINT8(src, dst, n);
   2727       break;
   2728    case MESA_FORMAT_R_INT8:
   2729       unpack_int_rgba_R_INT8(src, dst, n);
   2730       break;
   2731 
   2732    case MESA_FORMAT_ALPHA_UINT32:
   2733    case MESA_FORMAT_ALPHA_INT32:
   2734       unpack_int_rgba_ALPHA_UINT32(src, dst, n);
   2735       break;
   2736 
   2737    case MESA_FORMAT_ALPHA_UINT16:
   2738       unpack_int_rgba_ALPHA_UINT16(src, dst, n);
   2739       break;
   2740    case MESA_FORMAT_ALPHA_INT16:
   2741       unpack_int_rgba_ALPHA_INT16(src, dst, n);
   2742       break;
   2743 
   2744    case MESA_FORMAT_ALPHA_UINT8:
   2745       unpack_int_rgba_ALPHA_UINT8(src, dst, n);
   2746       break;
   2747    case MESA_FORMAT_ALPHA_INT8:
   2748       unpack_int_rgba_ALPHA_INT8(src, dst, n);
   2749       break;
   2750 
   2751    case MESA_FORMAT_LUMINANCE_UINT32:
   2752    case MESA_FORMAT_LUMINANCE_INT32:
   2753       unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
   2754       break;
   2755    case MESA_FORMAT_LUMINANCE_UINT16:
   2756       unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
   2757       break;
   2758    case MESA_FORMAT_LUMINANCE_INT16:
   2759       unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
   2760       break;
   2761 
   2762    case MESA_FORMAT_LUMINANCE_UINT8:
   2763       unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
   2764       break;
   2765    case MESA_FORMAT_LUMINANCE_INT8:
   2766       unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
   2767       break;
   2768 
   2769    case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
   2770    case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
   2771       unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
   2772       break;
   2773 
   2774    case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
   2775       unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
   2776       break;
   2777    case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
   2778       unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
   2779       break;
   2780 
   2781    case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
   2782       unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
   2783       break;
   2784    case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
   2785       unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
   2786       break;
   2787 
   2788    case MESA_FORMAT_INTENSITY_UINT32:
   2789    case MESA_FORMAT_INTENSITY_INT32:
   2790       unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
   2791       break;
   2792 
   2793    case MESA_FORMAT_INTENSITY_UINT16:
   2794       unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
   2795       break;
   2796    case MESA_FORMAT_INTENSITY_INT16:
   2797       unpack_int_rgba_INTENSITY_INT16(src, dst, n);
   2798       break;
   2799 
   2800    case MESA_FORMAT_INTENSITY_UINT8:
   2801       unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
   2802       break;
   2803    case MESA_FORMAT_INTENSITY_INT8:
   2804       unpack_int_rgba_INTENSITY_INT8(src, dst, n);
   2805       break;
   2806 
   2807    case MESA_FORMAT_ARGB2101010_UINT:
   2808       unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
   2809       break;
   2810 
   2811    case MESA_FORMAT_ABGR2101010_UINT:
   2812       unpack_int_rgba_ABGR2101010_UINT(src, dst, n);
   2813       break;
   2814 
   2815    case MESA_FORMAT_ARGB2101010:
   2816       unpack_int_rgba_ARGB2101010(src, dst, n);
   2817       break;
   2818 
   2819    default:
   2820       _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
   2821                     _mesa_get_format_name(format));
   2822       return;
   2823    }
   2824 }
   2825 
   2826 /**
   2827  * Unpack a 2D rect of pixels returning float RGBA colors.
   2828  * \param format  the source image format
   2829  * \param src  start address of the source image
   2830  * \param srcRowStride  source image row stride in bytes
   2831  * \param dst  start address of the dest image
   2832  * \param dstRowStride  dest image row stride in bytes
   2833  * \param x  source image start X pos
   2834  * \param y  source image start Y pos
   2835  * \param width  width of rect region to convert
   2836  * \param height  height of rect region to convert
   2837  */
   2838 void
   2839 _mesa_unpack_rgba_block(gl_format format,
   2840                         const void *src, GLint srcRowStride,
   2841                         GLfloat dst[][4], GLint dstRowStride,
   2842                         GLuint x, GLuint y, GLuint width, GLuint height)
   2843 {
   2844    unpack_rgba_func unpack = get_unpack_rgba_function(format);
   2845    const GLuint srcPixStride = _mesa_get_format_bytes(format);
   2846    const GLuint dstPixStride = 4 * sizeof(GLfloat);
   2847    const GLubyte *srcRow;
   2848    GLubyte *dstRow;
   2849    GLuint i;
   2850 
   2851    /* XXX needs to be fixed for compressed formats */
   2852 
   2853    srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
   2854    dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
   2855 
   2856    for (i = 0; i < height; i++) {
   2857       unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
   2858 
   2859       dstRow += dstRowStride;
   2860       srcRow += srcRowStride;
   2861    }
   2862 }
   2863 
   2864 
   2865 
   2866 
   2867 typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
   2868 
   2869 static void
   2870 unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
   2871 {
   2872    /* only return Z, not stencil data */
   2873    const GLuint *s = ((const GLuint *) src);
   2874    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
   2875    GLuint i;
   2876    for (i = 0; i < n; i++) {
   2877       dst[i] = (s[i] >> 8) * scale;
   2878       ASSERT(dst[i] >= 0.0F);
   2879       ASSERT(dst[i] <= 1.0F);
   2880    }
   2881 }
   2882 
   2883 static void
   2884 unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
   2885 {
   2886    /* only return Z, not stencil data */
   2887    const GLuint *s = ((const GLuint *) src);
   2888    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
   2889    GLuint i;
   2890    for (i = 0; i < n; i++) {
   2891       dst[i] = (s[i] & 0x00ffffff) * scale;
   2892       ASSERT(dst[i] >= 0.0F);
   2893       ASSERT(dst[i] <= 1.0F);
   2894    }
   2895 }
   2896 
   2897 static void
   2898 unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
   2899 {
   2900    const GLushort *s = ((const GLushort *) src);
   2901    GLuint i;
   2902    for (i = 0; i < n; i++) {
   2903       dst[i] = s[i] * (1.0F / 65535.0F);
   2904    }
   2905 }
   2906 
   2907 static void
   2908 unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
   2909 {
   2910    const GLuint *s = ((const GLuint *) src);
   2911    GLuint i;
   2912    for (i = 0; i < n; i++) {
   2913       dst[i] = s[i] * (1.0F / 0xffffffff);
   2914    }
   2915 }
   2916 
   2917 static void
   2918 unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
   2919 {
   2920    memcpy(dst, src, n * sizeof(float));
   2921 }
   2922 
   2923 static void
   2924 unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
   2925 {
   2926    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
   2927    GLuint i;
   2928    for (i = 0; i < n; i++) {
   2929       dst[i] = s[i].z;
   2930    }
   2931 }
   2932 
   2933 
   2934 
   2935 /**
   2936  * Unpack Z values.
   2937  * The returned values will always be in the range [0.0, 1.0].
   2938  */
   2939 void
   2940 _mesa_unpack_float_z_row(gl_format format, GLuint n,
   2941                          const void *src, GLfloat *dst)
   2942 {
   2943    unpack_float_z_func unpack;
   2944 
   2945    switch (format) {
   2946    case MESA_FORMAT_Z24_S8:
   2947    case MESA_FORMAT_Z24_X8:
   2948       unpack = unpack_float_z_Z24_X8;
   2949       break;
   2950    case MESA_FORMAT_S8_Z24:
   2951    case MESA_FORMAT_X8_Z24:
   2952       unpack = unpack_float_z_X8_Z24;
   2953       break;
   2954    case MESA_FORMAT_Z16:
   2955       unpack = unpack_float_z_Z16;
   2956       break;
   2957    case MESA_FORMAT_Z32:
   2958       unpack = unpack_float_z_Z32;
   2959       break;
   2960    case MESA_FORMAT_Z32_FLOAT:
   2961       unpack = unpack_float_z_Z32F;
   2962       break;
   2963    case MESA_FORMAT_Z32_FLOAT_X24S8:
   2964       unpack = unpack_float_z_Z32X24S8;
   2965       break;
   2966    default:
   2967       _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
   2968                     _mesa_get_format_name(format));
   2969       return;
   2970    }
   2971 
   2972    unpack(n, src, dst);
   2973 }
   2974 
   2975 
   2976 
   2977 typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
   2978 
   2979 static void
   2980 unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
   2981 {
   2982    /* only return Z, not stencil data */
   2983    const GLuint *s = ((const GLuint *) src);
   2984    GLuint i;
   2985    for (i = 0; i < n; i++) {
   2986       dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
   2987    }
   2988 }
   2989 
   2990 static void
   2991 unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
   2992 {
   2993    /* only return Z, not stencil data */
   2994    const GLuint *s = ((const GLuint *) src);
   2995    GLuint i;
   2996    for (i = 0; i < n; i++) {
   2997       dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
   2998    }
   2999 }
   3000 
   3001 static void
   3002 unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
   3003 {
   3004    const GLushort *s = ((const GLushort *)src);
   3005    GLuint i;
   3006    for (i = 0; i < n; i++) {
   3007       dst[i] = (s[i] << 16) | s[i];
   3008    }
   3009 }
   3010 
   3011 static void
   3012 unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
   3013 {
   3014    memcpy(dst, src, n * sizeof(GLuint));
   3015 }
   3016 
   3017 static void
   3018 unpack_uint_z_Z32_FLOAT(const void *src, GLuint *dst, GLuint n)
   3019 {
   3020    const float *s = (const float *)src;
   3021    GLuint i;
   3022    for (i = 0; i < n; i++) {
   3023       dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
   3024    }
   3025 }
   3026 
   3027 static void
   3028 unpack_uint_z_Z32_FLOAT_X24S8(const void *src, GLuint *dst, GLuint n)
   3029 {
   3030    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
   3031    GLuint i;
   3032 
   3033    for (i = 0; i < n; i++) {
   3034       dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
   3035    }
   3036 }
   3037 
   3038 
   3039 /**
   3040  * Unpack Z values.
   3041  * The returned values will always be in the range [0, 0xffffffff].
   3042  */
   3043 void
   3044 _mesa_unpack_uint_z_row(gl_format format, GLuint n,
   3045                         const void *src, GLuint *dst)
   3046 {
   3047    unpack_uint_z_func unpack;
   3048    const GLubyte *srcPtr = (GLubyte *) src;
   3049 
   3050    switch (format) {
   3051    case MESA_FORMAT_Z24_S8:
   3052    case MESA_FORMAT_Z24_X8:
   3053       unpack = unpack_uint_z_Z24_X8;
   3054       break;
   3055    case MESA_FORMAT_S8_Z24:
   3056    case MESA_FORMAT_X8_Z24:
   3057       unpack = unpack_uint_z_X8_Z24;
   3058       break;
   3059    case MESA_FORMAT_Z16:
   3060       unpack = unpack_uint_z_Z16;
   3061       break;
   3062    case MESA_FORMAT_Z32:
   3063       unpack = unpack_uint_z_Z32;
   3064       break;
   3065    case MESA_FORMAT_Z32_FLOAT:
   3066       unpack = unpack_uint_z_Z32_FLOAT;
   3067       break;
   3068    case MESA_FORMAT_Z32_FLOAT_X24S8:
   3069       unpack = unpack_uint_z_Z32_FLOAT_X24S8;
   3070       break;
   3071    default:
   3072       _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
   3073                     _mesa_get_format_name(format));
   3074       return;
   3075    }
   3076 
   3077    unpack(srcPtr, dst, n);
   3078 }
   3079 
   3080 
   3081 static void
   3082 unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
   3083 {
   3084    memcpy(dst, src, n);
   3085 }
   3086 
   3087 static void
   3088 unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
   3089 {
   3090    GLuint i;
   3091    const GLuint *src32 = src;
   3092 
   3093    for (i = 0; i < n; i++)
   3094       dst[i] = src32[i] & 0xff;
   3095 }
   3096 
   3097 static void
   3098 unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
   3099 {
   3100    GLuint i;
   3101    const GLuint *src32 = src;
   3102 
   3103    for (i = 0; i < n; i++)
   3104       dst[i] = src32[i] >> 24;
   3105 }
   3106 
   3107 static void
   3108 unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
   3109 {
   3110    GLuint i;
   3111    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
   3112 
   3113    for (i = 0; i < n; i++)
   3114       dst[i] = s[i].x24s8 & 0xff;
   3115 }
   3116 
   3117 void
   3118 _mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
   3119 			       const void *src, GLubyte *dst)
   3120 {
   3121    switch (format) {
   3122    case MESA_FORMAT_S8:
   3123       unpack_ubyte_s_S8(src, dst, n);
   3124       break;
   3125    case MESA_FORMAT_Z24_S8:
   3126       unpack_ubyte_s_Z24_S8(src, dst, n);
   3127       break;
   3128    case MESA_FORMAT_S8_Z24:
   3129       unpack_ubyte_s_S8_Z24(src, dst, n);
   3130       break;
   3131    case MESA_FORMAT_Z32_FLOAT_X24S8:
   3132       unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
   3133       break;
   3134    default:
   3135       _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
   3136                     _mesa_get_format_name(format));
   3137       return;
   3138    }
   3139 }
   3140 
   3141 static void
   3142 unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
   3143 {
   3144    GLuint i;
   3145 
   3146    for (i = 0; i < n; i++) {
   3147       GLuint val = src[i];
   3148       dst[i] = val >> 24 | val << 8;
   3149    }
   3150 }
   3151 
   3152 static void
   3153 unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
   3154 {
   3155    memcpy(dst, src, n * 4);
   3156 }
   3157 
   3158 void
   3159 _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
   3160 					 const void *src, GLuint *dst)
   3161 {
   3162    switch (format) {
   3163    case MESA_FORMAT_Z24_S8:
   3164       unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
   3165       break;
   3166    case MESA_FORMAT_S8_Z24:
   3167       unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
   3168       break;
   3169    default:
   3170       _mesa_problem(NULL,
   3171                     "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
   3172                     _mesa_get_format_name(format));
   3173       return;
   3174    }
   3175 }
   3176