Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22.  * OTHER DEALINGS IN THE SOFTWARE.
  23.  */
  24.  
  25.  
  26. #include "colormac.h"
  27. #include "format_unpack.h"
  28. #include "macros.h"
  29. #include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
  30. #include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"
  31.  
  32.  
  33. /** Helper struct for MESA_FORMAT_Z32_FLOAT_X24S8 */
  34. struct z32f_x24s8
  35. {
  36.    float z;
  37.    uint32_t x24s8;
  38. };
  39.  
  40.  
  41. /* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */
  42.  
  43. #define EXPAND_1_8(X)  ( (X) ? 0xff : 0x0 )
  44.  
  45. #define EXPAND_2_8(X)  ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )
  46.  
  47. #define EXPAND_3_8(X)  ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )
  48.  
  49. #define EXPAND_4_8(X)  ( ((X) << 4) | (X) )
  50.  
  51. #define EXPAND_5_8(X)  ( ((X) << 3) | ((X) >> 2) )
  52.  
  53. #define EXPAND_6_8(X)  ( ((X) << 2) | ((X) >> 4) )
  54.  
  55.  
  56. /**
  57.  * Convert an 8-bit sRGB value from non-linear space to a
  58.  * linear RGB value in [0, 1].
  59.  * Implemented with a 256-entry lookup table.
  60.  */
  61. GLfloat
  62. _mesa_nonlinear_to_linear(GLubyte cs8)
  63. {
  64.    static GLfloat table[256];
  65.    static GLboolean tableReady = GL_FALSE;
  66.    if (!tableReady) {
  67.       /* compute lookup table now */
  68.       GLuint i;
  69.       for (i = 0; i < 256; i++) {
  70.          const GLfloat cs = UBYTE_TO_FLOAT(i);
  71.          if (cs <= 0.04045) {
  72.             table[i] = cs / 12.92f;
  73.          }
  74.          else {
  75.             table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
  76.          }
  77.       }
  78.       tableReady = GL_TRUE;
  79.    }
  80.    return table[cs8];
  81. }
  82.  
  83.  
  84. /**********************************************************************/
  85. /*  Unpack, returning GLfloat colors                                  */
  86. /**********************************************************************/
  87.  
  88. typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);
  89.  
  90.  
  91. static void
  92. unpack_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
  93. {
  94.    const GLuint *s = ((const GLuint *) src);
  95.    GLuint i;
  96.    for (i = 0; i < n; i++) {
  97.       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
  98.       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
  99.       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
  100.       dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
  101.    }
  102. }
  103.  
  104. static void
  105. unpack_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
  106. {
  107.    const GLuint *s = ((const GLuint *) src);
  108.    GLuint i;
  109.    for (i = 0; i < n; i++) {
  110.       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
  111.       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
  112.       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
  113.       dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
  114.    }
  115. }
  116.  
  117. static void
  118. unpack_ARGB8888(const void *src, GLfloat dst[][4], GLuint n)
  119. {
  120.    const GLuint *s = ((const GLuint *) src);
  121.    GLuint i;
  122.    for (i = 0; i < n; i++) {
  123.       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
  124.       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
  125.       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
  126.       dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
  127.    }
  128. }
  129.  
  130. static void
  131. unpack_ARGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
  132. {
  133.    const GLuint *s = ((const GLuint *) src);
  134.    GLuint i;
  135.    for (i = 0; i < n; i++) {
  136.       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
  137.       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
  138.       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
  139.       dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
  140.    }
  141. }
  142.  
  143. static void
  144. unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
  145. {
  146.    const GLuint *s = ((const GLuint *) src);
  147.    GLuint i;
  148.    for (i = 0; i < n; i++) {
  149.       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
  150.       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
  151.       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
  152.       dst[i][ACOMP] = 1.0f;
  153.    }
  154. }
  155.  
  156. static void
  157. unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
  158. {
  159.    const GLuint *s = ((const GLuint *) src);
  160.    GLuint i;
  161.    for (i = 0; i < n; i++) {
  162.       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
  163.       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
  164.       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
  165.       dst[i][ACOMP] = 1.0f;
  166.    }
  167. }
  168.  
  169. static void
  170. unpack_XRGB8888(const void *src, GLfloat dst[][4], GLuint n)
  171. {
  172.    const GLuint *s = ((const GLuint *) src);
  173.    GLuint i;
  174.    for (i = 0; i < n; i++) {
  175.       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
  176.       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
  177.       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
  178.       dst[i][ACOMP] = 1.0f;
  179.    }
  180. }
  181.  
  182. static void
  183. unpack_XRGB8888_REV(const void *src, GLfloat dst[][4], GLuint n)
  184. {
  185.    const GLuint *s = ((const GLuint *) src);
  186.    GLuint i;
  187.    for (i = 0; i < n; i++) {
  188.       dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
  189.       dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
  190.       dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
  191.       dst[i][ACOMP] = 1.0f;
  192.    }
  193. }
  194.  
  195. static void
  196. unpack_RGB888(const void *src, GLfloat dst[][4], GLuint n)
  197. {
  198.    const GLubyte *s = (const GLubyte *) src;
  199.    GLuint i;
  200.    for (i = 0; i < n; i++) {
  201.       dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
  202.       dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
  203.       dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
  204.       dst[i][ACOMP] = 1.0F;
  205.    }
  206. }
  207.  
  208. static void
  209. unpack_BGR888(const void *src, GLfloat dst[][4], GLuint n)
  210. {
  211.    const GLubyte *s = (const GLubyte *) src;
  212.    GLuint i;
  213.    for (i = 0; i < n; i++) {
  214.       dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
  215.       dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
  216.       dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
  217.       dst[i][ACOMP] = 1.0F;
  218.    }
  219. }
  220.  
  221. static void
  222. unpack_RGB565(const void *src, GLfloat dst[][4], GLuint n)
  223. {
  224.    const GLushort *s = ((const GLushort *) src);
  225.    GLuint i;
  226.    for (i = 0; i < n; i++) {
  227.       dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
  228.       dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
  229.       dst[i][BCOMP] = ((s[i]      ) & 0x1f) * (1.0F / 31.0F);
  230.       dst[i][ACOMP] = 1.0F;
  231.    }
  232. }
  233.  
  234. static void
  235. unpack_RGB565_REV(const void *src, GLfloat dst[][4], GLuint n)
  236. {
  237.    const GLushort *s = ((const GLushort *) src);
  238.    GLuint i;
  239.    for (i = 0; i < n; i++) {
  240.       GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
  241.       dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
  242.       dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >>  9) & 0x3) );
  243.       dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >>  2) & 0x7) );
  244.       dst[i][ACOMP] = 1.0F;
  245.    }
  246. }
  247.  
  248. static void
  249. unpack_ARGB4444(const void *src, GLfloat dst[][4], GLuint n)
  250. {
  251.    const GLushort *s = ((const GLushort *) src);
  252.    GLuint i;
  253.    for (i = 0; i < n; i++) {
  254.       dst[i][RCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
  255.       dst[i][GCOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
  256.       dst[i][BCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
  257.       dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
  258.    }
  259. }
  260.  
  261. static void
  262. unpack_ARGB4444_REV(const void *src, GLfloat dst[][4], GLuint n)
  263. {
  264.    const GLushort *s = ((const GLushort *) src);
  265.    GLuint i;
  266.    for (i = 0; i < n; i++) {
  267.       dst[i][RCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
  268.       dst[i][GCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
  269.       dst[i][BCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
  270.       dst[i][ACOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
  271.    }
  272. }
  273.  
  274. static void
  275. unpack_RGBA5551(const void *src, GLfloat dst[][4], GLuint n)
  276. {
  277.    const GLushort *s = ((const GLushort *) src);
  278.    GLuint i;
  279.    for (i = 0; i < n; i++) {
  280.       dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
  281.       dst[i][GCOMP] = ((s[i] >>  6) & 0x1f) * (1.0F / 31.0F);
  282.       dst[i][BCOMP] = ((s[i] >>  1) & 0x1f) * (1.0F / 31.0F);
  283.       dst[i][ACOMP] = ((s[i]      ) & 0x01) * 1.0F;
  284.    }
  285. }
  286.  
  287. static void
  288. unpack_ARGB1555(const void *src, GLfloat dst[][4], GLuint n)
  289. {
  290.    const GLushort *s = ((const GLushort *) src);
  291.    GLuint i;
  292.    for (i = 0; i < n; i++) {
  293.       dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
  294.       dst[i][GCOMP] = ((s[i] >>  5) & 0x1f) * (1.0F / 31.0F);
  295.       dst[i][BCOMP] = ((s[i] >>  0) & 0x1f) * (1.0F / 31.0F);
  296.       dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
  297.    }
  298. }
  299.  
  300. static void
  301. unpack_ARGB1555_REV(const void *src, GLfloat dst[][4], GLuint n)
  302. {
  303.    const GLushort *s = ((const GLushort *) src);
  304.    GLuint i;
  305.    for (i = 0; i < n; i++) {
  306.       GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
  307.       dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
  308.       dst[i][GCOMP] = ((tmp >>  5) & 0x1f) * (1.0F / 31.0F);
  309.       dst[i][BCOMP] = ((tmp >>  0) & 0x1f) * (1.0F / 31.0F);
  310.       dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
  311.    }
  312. }
  313.  
  314. static void
  315. unpack_AL44(const void *src, GLfloat dst[][4], GLuint n)
  316. {
  317.    const GLubyte *s = ((const GLubyte *) src);
  318.    GLuint i;
  319.    for (i = 0; i < n; i++) {
  320.       dst[i][RCOMP] =
  321.       dst[i][GCOMP] =
  322.       dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
  323.       dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
  324.    }
  325. }
  326.  
  327. static void
  328. unpack_AL88(const void *src, GLfloat dst[][4], GLuint n)
  329. {
  330.    const GLushort *s = ((const GLushort *) src);
  331.    GLuint i;
  332.    for (i = 0; i < n; i++) {
  333.       dst[i][RCOMP] =
  334.       dst[i][GCOMP] =
  335.       dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
  336.       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
  337.    }
  338. }
  339.  
  340. static void
  341. unpack_AL88_REV(const void *src, GLfloat dst[][4], GLuint n)
  342. {
  343.    const GLushort *s = ((const GLushort *) src);
  344.    GLuint i;
  345.    for (i = 0; i < n; i++) {
  346.       dst[i][RCOMP] =
  347.       dst[i][GCOMP] =
  348.       dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
  349.       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
  350.    }
  351. }
  352.  
  353. static void
  354. unpack_AL1616(const void *src, GLfloat dst[][4], GLuint n)
  355. {
  356.    const GLuint *s = ((const GLuint *) src);
  357.    GLuint i;
  358.    for (i = 0; i < n; i++) {
  359.       dst[i][RCOMP] =
  360.       dst[i][GCOMP] =
  361.       dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
  362.       dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
  363.    }
  364. }
  365.  
  366. static void
  367. unpack_AL1616_REV(const void *src, GLfloat dst[][4], GLuint n)
  368. {
  369.    const GLuint *s = ((const GLuint *) src);
  370.    GLuint i;
  371.    for (i = 0; i < n; i++) {
  372.       dst[i][RCOMP] =
  373.       dst[i][GCOMP] =
  374.       dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
  375.       dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
  376.    }
  377. }
  378.  
  379. static void
  380. unpack_RGB332(const void *src, GLfloat dst[][4], GLuint n)
  381. {
  382.    const GLubyte *s = ((const GLubyte *) src);
  383.    GLuint i;
  384.    for (i = 0; i < n; i++) {
  385.       dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
  386.       dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
  387.       dst[i][BCOMP] = ((s[i]     ) & 0x3) * (1.0F / 3.0F);
  388.       dst[i][ACOMP] = 1.0F;
  389.    }
  390. }
  391.  
  392.  
  393. static void
  394. unpack_A8(const void *src, GLfloat dst[][4], GLuint n)
  395. {
  396.    const GLubyte *s = ((const GLubyte *) src);
  397.    GLuint i;
  398.    for (i = 0; i < n; i++) {
  399.       dst[i][RCOMP] =
  400.       dst[i][GCOMP] =
  401.       dst[i][BCOMP] = 0.0F;
  402.       dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
  403.    }
  404. }
  405.  
  406. static void
  407. unpack_A16(const void *src, GLfloat dst[][4], GLuint n)
  408. {
  409.    const GLushort *s = ((const GLushort *) src);
  410.    GLuint i;
  411.    for (i = 0; i < n; i++) {
  412.       dst[i][RCOMP] =
  413.       dst[i][GCOMP] =
  414.       dst[i][BCOMP] = 0.0F;
  415.       dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
  416.    }
  417. }
  418.  
  419. static void
  420. unpack_L8(const void *src, GLfloat dst[][4], GLuint n)
  421. {
  422.    const GLubyte *s = ((const GLubyte *) src);
  423.    GLuint i;
  424.    for (i = 0; i < n; i++) {
  425.       dst[i][RCOMP] =
  426.       dst[i][GCOMP] =
  427.       dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
  428.       dst[i][ACOMP] = 1.0F;
  429.    }
  430. }
  431.  
  432. static void
  433. unpack_L16(const void *src, GLfloat dst[][4], GLuint n)
  434. {
  435.    const GLushort *s = ((const GLushort *) src);
  436.    GLuint i;
  437.    for (i = 0; i < n; i++) {
  438.       dst[i][RCOMP] =
  439.       dst[i][GCOMP] =
  440.       dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
  441.       dst[i][ACOMP] = 1.0F;
  442.    }
  443. }
  444.  
  445. static void
  446. unpack_I8(const void *src, GLfloat dst[][4], GLuint n)
  447. {
  448.    const GLubyte *s = ((const GLubyte *) src);
  449.    GLuint i;
  450.    for (i = 0; i < n; i++) {
  451.       dst[i][RCOMP] =
  452.       dst[i][GCOMP] =
  453.       dst[i][BCOMP] =
  454.       dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
  455.    }
  456. }
  457.  
  458. static void
  459. unpack_I16(const void *src, GLfloat dst[][4], GLuint n)
  460. {
  461.    const GLushort *s = ((const GLushort *) src);
  462.    GLuint i;
  463.    for (i = 0; i < n; i++) {
  464.       dst[i][RCOMP] =
  465.       dst[i][GCOMP] =
  466.       dst[i][BCOMP] =
  467.       dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
  468.    }
  469. }
  470.  
  471. static void
  472. unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
  473. {
  474.    GLuint i;
  475.    for (i = 0; i < n; i++) {
  476.       const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
  477.       const GLushort *src1 = src0 + 1;         /* odd */
  478.       const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
  479.       const GLubyte cb = *src0 & 0xff;         /* chroma U */
  480.       const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
  481.       const GLubyte cr = *src1 & 0xff;         /* chroma V */
  482.       const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
  483.       GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
  484.       GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
  485.       GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
  486.       r *= (1.0F / 255.0F);
  487.       g *= (1.0F / 255.0F);
  488.       b *= (1.0F / 255.0F);
  489.       dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
  490.       dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
  491.       dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
  492.       dst[i][ACOMP] = 1.0F;
  493.    }
  494. }
  495.  
  496. static void
  497. unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
  498. {
  499.    GLuint i;
  500.    for (i = 0; i < n; i++) {
  501.       const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
  502.       const GLushort *src1 = src0 + 1;         /* odd */
  503.       const GLubyte y0 = *src0 & 0xff;         /* luminance */
  504.       const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
  505.       const GLubyte y1 = *src1 & 0xff;         /* luminance */
  506.       const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
  507.       const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
  508.       GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
  509.       GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
  510.       GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
  511.       r *= (1.0F / 255.0F);
  512.       g *= (1.0F / 255.0F);
  513.       b *= (1.0F / 255.0F);
  514.       dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
  515.       dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
  516.       dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
  517.       dst[i][ACOMP] = 1.0F;
  518.    }
  519. }
  520.  
  521. static void
  522. unpack_R8(const void *src, GLfloat dst[][4], GLuint n)
  523. {
  524.    const GLubyte *s = ((const GLubyte *) src);
  525.    GLuint i;
  526.    for (i = 0; i < n; i++) {
  527.       dst[i][0] = UBYTE_TO_FLOAT(s[i]);
  528.       dst[i][1] =
  529.       dst[i][2] = 0.0F;
  530.       dst[i][3] = 1.0F;
  531.    }
  532. }
  533.  
  534. static void
  535. unpack_GR88(const void *src, GLfloat dst[][4], GLuint n)
  536. {
  537.    const GLushort *s = ((const GLushort *) src);
  538.    GLuint i;
  539.    for (i = 0; i < n; i++) {
  540.       dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
  541.       dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
  542.       dst[i][BCOMP] = 0.0;
  543.       dst[i][ACOMP] = 1.0;
  544.    }
  545. }
  546.  
  547. static void
  548. unpack_RG88(const void *src, GLfloat dst[][4], GLuint n)
  549. {
  550.    const GLushort *s = ((const GLushort *) src);
  551.    GLuint i;
  552.    for (i = 0; i < n; i++) {
  553.       dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
  554.       dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
  555.       dst[i][BCOMP] = 0.0;
  556.       dst[i][ACOMP] = 1.0;
  557.    }
  558. }
  559.  
  560. static void
  561. unpack_R16(const void *src, GLfloat dst[][4], GLuint n)
  562. {
  563.    const GLushort *s = ((const GLushort *) src);
  564.    GLuint i;
  565.    for (i = 0; i < n; i++) {
  566.       dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
  567.       dst[i][GCOMP] = 0.0;
  568.       dst[i][BCOMP] = 0.0;
  569.       dst[i][ACOMP] = 1.0;
  570.    }
  571. }
  572.  
  573. static void
  574. unpack_GR1616(const void *src, GLfloat dst[][4], GLuint n)
  575. {
  576.    const GLuint *s = ((const GLuint *) src);
  577.    GLuint i;
  578.    for (i = 0; i < n; i++) {
  579.       dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
  580.       dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
  581.       dst[i][BCOMP] = 0.0;
  582.       dst[i][ACOMP] = 1.0;
  583.    }
  584. }
  585.  
  586. static void
  587. unpack_RG1616(const void *src, GLfloat dst[][4], GLuint n)
  588. {
  589.    const GLuint *s = ((const GLuint *) src);
  590.    GLuint i;
  591.    for (i = 0; i < n; i++) {
  592.       dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
  593.       dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
  594.       dst[i][BCOMP] = 0.0;
  595.       dst[i][ACOMP] = 1.0;
  596.    }
  597. }
  598.  
  599. static void
  600. unpack_ARGB2101010(const void *src, GLfloat dst[][4], GLuint n)
  601. {
  602.    const GLuint *s = ((const GLuint *) src);
  603.    GLuint i;
  604.    for (i = 0; i < n; i++) {
  605.       dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
  606.       dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
  607.       dst[i][BCOMP] = ((s[i] >>  0) & 0x3ff) * (1.0F / 1023.0F);
  608.       dst[i][ACOMP] = ((s[i] >> 30) &  0x03) * (1.0F / 3.0F);
  609.    }
  610. }
  611.  
  612.  
  613. static void
  614. unpack_ARGB2101010_UINT(const void *src, GLfloat dst[][4], GLuint n)
  615. {
  616.    const GLuint *s = (const GLuint *) src;
  617.    GLuint i;
  618.    for (i = 0; i < n; i++) {
  619.       dst[i][RCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
  620.       dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
  621.       dst[i][BCOMP] = (GLfloat)((s[i] >>  0) & 0x3ff);
  622.       dst[i][ACOMP] = (GLfloat)((s[i] >> 30) &  0x03);
  623.    }
  624. }
  625.  
  626.  
  627. static void
  628. unpack_ABGR2101010_UINT(const void *src, GLfloat dst[][4], GLuint n)
  629. {
  630.    const GLuint *s = ((const GLuint *) src);
  631.    GLuint i;
  632.    for (i = 0; i < n; i++) {
  633.       dst[i][RCOMP] = (GLfloat)((s[i] >>  0) & 0x3ff);
  634.       dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
  635.       dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
  636.       dst[i][ACOMP] = (GLfloat)((s[i] >> 30) &  0x03);
  637.    }
  638. }
  639.  
  640.  
  641. static void
  642. unpack_Z24_S8(const void *src, GLfloat dst[][4], GLuint n)
  643. {
  644.    /* only return Z, not stencil data */
  645.    const GLuint *s = ((const GLuint *) src);
  646.    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
  647.    GLuint i;
  648.    for (i = 0; i < n; i++) {
  649.       dst[i][0] =
  650.       dst[i][1] =
  651.       dst[i][2] = (GLfloat) ((s[i] >> 8) * scale);
  652.       dst[i][3] = 1.0F;
  653.       ASSERT(dst[i][0] >= 0.0F);
  654.       ASSERT(dst[i][0] <= 1.0F);
  655.    }
  656. }
  657.  
  658. static void
  659. unpack_S8_Z24(const void *src, GLfloat dst[][4], GLuint n)
  660. {
  661.    /* only return Z, not stencil data */
  662.    const GLuint *s = ((const GLuint *) src);
  663.    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
  664.    GLuint i;
  665.    for (i = 0; i < n; i++) {
  666.       dst[i][0] =
  667.       dst[i][1] =
  668.       dst[i][2] = (float) ((s[i] & 0x00ffffff) * scale);
  669.       dst[i][3] = 1.0F;
  670.       ASSERT(dst[i][0] >= 0.0F);
  671.       ASSERT(dst[i][0] <= 1.0F);
  672.    }
  673. }
  674.  
  675. static void
  676. unpack_Z16(const void *src, GLfloat dst[][4], GLuint n)
  677. {
  678.    const GLushort *s = ((const GLushort *) src);
  679.    GLuint i;
  680.    for (i = 0; i < n; i++) {
  681.       dst[i][0] =
  682.       dst[i][1] =
  683.       dst[i][2] = s[i] * (1.0F / 65535.0F);
  684.       dst[i][3] = 1.0F;
  685.    }
  686. }
  687.  
  688. static void
  689. unpack_X8_Z24(const void *src, GLfloat dst[][4], GLuint n)
  690. {
  691.    unpack_S8_Z24(src, dst, n);
  692. }
  693.  
  694. static void
  695. unpack_Z24_X8(const void *src, GLfloat dst[][4], GLuint n)
  696. {
  697.    unpack_Z24_S8(src, dst, n);
  698. }
  699.  
  700. static void
  701. unpack_Z32(const void *src, GLfloat dst[][4], GLuint n)
  702. {
  703.    const GLuint *s = ((const GLuint *) src);
  704.    GLuint i;
  705.    for (i = 0; i < n; i++) {
  706.       dst[i][0] =
  707.       dst[i][1] =
  708.       dst[i][2] = s[i] * (1.0F / 0xffffffff);
  709.       dst[i][3] = 1.0F;
  710.    }
  711. }
  712.  
  713. static void
  714. unpack_Z32_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
  715. {
  716.    const GLfloat *s = ((const GLfloat *) src);
  717.    GLuint i;
  718.    for (i = 0; i < n; i++) {
  719.       dst[i][0] =
  720.       dst[i][1] =
  721.       dst[i][2] = s[i * 2];
  722.       dst[i][3] = 1.0F;
  723.    }
  724. }
  725.  
  726. static void
  727. unpack_Z32_FLOAT_X24S8(const void *src, GLfloat dst[][4], GLuint n)
  728. {
  729.    const GLfloat *s = ((const GLfloat *) src);
  730.    GLuint i;
  731.    for (i = 0; i < n; i++) {
  732.       dst[i][0] =
  733.       dst[i][1] =
  734.       dst[i][2] = s[i];
  735.       dst[i][3] = 1.0F;
  736.    }
  737. }
  738.  
  739.  
  740. static void
  741. unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
  742. {
  743.    /* should never be used */
  744.    GLuint i;
  745.    for (i = 0; i < n; i++) {
  746.       dst[i][0] =
  747.       dst[i][1] =
  748.       dst[i][2] = 0.0F;
  749.       dst[i][3] = 1.0F;
  750.    }
  751. }
  752.  
  753.  
  754. static void
  755. unpack_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
  756. {
  757.    const GLubyte *s = (const GLubyte *) src;
  758.    GLuint i;
  759.    for (i = 0; i < n; i++) {
  760.       dst[i][RCOMP] = _mesa_nonlinear_to_linear(s[i*3+2]);
  761.       dst[i][GCOMP] = _mesa_nonlinear_to_linear(s[i*3+1]);
  762.       dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i*3+0]);
  763.       dst[i][ACOMP] = 1.0F;
  764.    }
  765. }
  766.  
  767. static void
  768. unpack_SRGBA8(const void *src, GLfloat dst[][4], GLuint n)
  769. {
  770.    const GLuint *s = ((const GLuint *) src);
  771.    GLuint i;
  772.    for (i = 0; i < n; i++) {
  773.       dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 24) );
  774.       dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
  775.       dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
  776.       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
  777.    }
  778. }
  779.  
  780. static void
  781. unpack_SARGB8(const void *src, GLfloat dst[][4], GLuint n)
  782. {
  783.    const GLuint *s = ((const GLuint *) src);
  784.    GLuint i;
  785.    for (i = 0; i < n; i++) {
  786.       dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
  787.       dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
  788.       dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
  789.       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
  790.    }
  791. }
  792.  
  793. static void
  794. unpack_SL8(const void *src, GLfloat dst[][4], GLuint n)
  795. {
  796.    const GLubyte *s = ((const GLubyte *) src);
  797.    GLuint i;
  798.    for (i = 0; i < n; i++) {
  799.       dst[i][RCOMP] =
  800.       dst[i][GCOMP] =
  801.       dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]);
  802.       dst[i][ACOMP] = 1.0F;
  803.    }
  804. }
  805.  
  806. static void
  807. unpack_SLA8(const void *src, GLfloat dst[][4], GLuint n)
  808. {
  809.    const GLushort *s = (const GLushort *) src;
  810.    GLuint i;
  811.    for (i = 0; i < n; i++) {
  812.       dst[i][RCOMP] =
  813.       dst[i][GCOMP] =
  814.       dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff);
  815.       dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
  816.    }
  817. }
  818.  
  819. static void
  820. unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
  821. {
  822. }
  823.  
  824. static void
  825. unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
  826. {
  827. }
  828.  
  829. static void
  830. unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
  831. {
  832. }
  833.  
  834. static void
  835. unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
  836. {
  837. }
  838.  
  839. static void
  840. unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
  841. {
  842. }
  843.  
  844. static void
  845. unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
  846. {
  847. }
  848.  
  849. static void
  850. unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
  851. {
  852. }
  853.  
  854. static void
  855. unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
  856. {
  857. }
  858.  
  859. static void
  860. unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
  861. {
  862. }
  863.  
  864. static void
  865. unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
  866. {
  867. }
  868.  
  869.  
  870. static void
  871. unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
  872. {
  873.    const GLfloat *s = (const GLfloat *) src;
  874.    GLuint i;
  875.    for (i = 0; i < n; i++) {
  876.       dst[i][RCOMP] = s[i*4+0];
  877.       dst[i][GCOMP] = s[i*4+1];
  878.       dst[i][BCOMP] = s[i*4+2];
  879.       dst[i][ACOMP] = s[i*4+3];
  880.    }
  881. }
  882.  
  883. static void
  884. unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
  885. {
  886.    const GLhalfARB *s = (const GLhalfARB *) src;
  887.    GLuint i;
  888.    for (i = 0; i < n; i++) {
  889.       dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
  890.       dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
  891.       dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
  892.       dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
  893.    }
  894. }
  895.  
  896. static void
  897. unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
  898. {
  899.    const GLfloat *s = (const GLfloat *) src;
  900.    GLuint i;
  901.    for (i = 0; i < n; i++) {
  902.       dst[i][RCOMP] = s[i*3+0];
  903.       dst[i][GCOMP] = s[i*3+1];
  904.       dst[i][BCOMP] = s[i*3+2];
  905.       dst[i][ACOMP] = 1.0F;
  906.    }
  907. }
  908.  
  909. static void
  910. unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
  911. {
  912.    const GLhalfARB *s = (const GLhalfARB *) src;
  913.    GLuint i;
  914.    for (i = 0; i < n; i++) {
  915.       dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
  916.       dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
  917.       dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
  918.       dst[i][ACOMP] = 1.0F;
  919.    }
  920. }
  921.  
  922. static void
  923. unpack_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
  924. {
  925.    const GLfloat *s = (const GLfloat *) src;
  926.    GLuint i;
  927.    for (i = 0; i < n; i++) {
  928.       dst[i][RCOMP] =
  929.       dst[i][GCOMP] =
  930.       dst[i][BCOMP] = 0.0F;
  931.       dst[i][ACOMP] = s[i];
  932.    }
  933. }
  934.  
  935. static void
  936. unpack_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
  937. {
  938.    const GLhalfARB *s = (const GLhalfARB *) src;
  939.    GLuint i;
  940.    for (i = 0; i < n; i++) {
  941.       dst[i][RCOMP] =
  942.       dst[i][GCOMP] =
  943.       dst[i][BCOMP] = 0.0F;
  944.       dst[i][ACOMP] = _mesa_half_to_float(s[i]);
  945.    }
  946. }
  947.  
  948. static void
  949. unpack_LUMINANCE_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
  950. {
  951.    const GLfloat *s = (const GLfloat *) src;
  952.    GLuint i;
  953.    for (i = 0; i < n; i++) {
  954.       dst[i][RCOMP] =
  955.       dst[i][GCOMP] =
  956.       dst[i][BCOMP] = s[i];
  957.       dst[i][ACOMP] = 1.0F;
  958.    }
  959. }
  960.  
  961. static void
  962. unpack_LUMINANCE_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
  963. {
  964.    const GLhalfARB *s = (const GLhalfARB *) src;
  965.    GLuint i;
  966.    for (i = 0; i < n; i++) {
  967.       dst[i][RCOMP] =
  968.       dst[i][GCOMP] =
  969.       dst[i][BCOMP] = _mesa_half_to_float(s[i]);
  970.       dst[i][ACOMP] = 1.0F;
  971.    }
  972. }
  973.  
  974. static void
  975. unpack_LUMINANCE_ALPHA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
  976. {
  977.    const GLfloat *s = (const GLfloat *) src;
  978.    GLuint i;
  979.    for (i = 0; i < n; i++) {
  980.       dst[i][RCOMP] =
  981.       dst[i][GCOMP] =
  982.       dst[i][BCOMP] = s[i*2+0];
  983.       dst[i][ACOMP] = s[i*2+1];
  984.    }
  985. }
  986.  
  987. static void
  988. unpack_LUMINANCE_ALPHA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
  989. {
  990.    const GLhalfARB *s = (const GLhalfARB *) src;
  991.    GLuint i;
  992.    for (i = 0; i < n; i++) {
  993.       dst[i][RCOMP] =
  994.       dst[i][GCOMP] =
  995.       dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
  996.       dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
  997.    }
  998. }
  999.  
  1000. static void
  1001. unpack_INTENSITY_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
  1002. {
  1003.    const GLfloat *s = (const GLfloat *) src;
  1004.    GLuint i;
  1005.    for (i = 0; i < n; i++) {
  1006.       dst[i][RCOMP] =
  1007.       dst[i][GCOMP] =
  1008.       dst[i][BCOMP] =
  1009.       dst[i][ACOMP] = s[i];
  1010.    }
  1011. }
  1012.  
  1013. static void
  1014. unpack_INTENSITY_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
  1015. {
  1016.    const GLhalfARB *s = (const GLhalfARB *) src;
  1017.    GLuint i;
  1018.    for (i = 0; i < n; i++) {
  1019.       dst[i][RCOMP] =
  1020.       dst[i][GCOMP] =
  1021.       dst[i][BCOMP] =
  1022.       dst[i][ACOMP] = _mesa_half_to_float(s[i]);
  1023.    }
  1024. }
  1025.  
  1026. static void
  1027. unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
  1028. {
  1029.    const GLfloat *s = (const GLfloat *) src;
  1030.    GLuint i;
  1031.    for (i = 0; i < n; i++) {
  1032.       dst[i][RCOMP] = s[i];
  1033.       dst[i][GCOMP] = 0.0F;
  1034.       dst[i][BCOMP] = 0.0F;
  1035.       dst[i][ACOMP] = 1.0F;
  1036.    }
  1037. }
  1038.  
  1039. static void
  1040. unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
  1041. {
  1042.    const GLhalfARB *s = (const GLhalfARB *) src;
  1043.    GLuint i;
  1044.    for (i = 0; i < n; i++) {
  1045.       dst[i][RCOMP] = _mesa_half_to_float(s[i]);
  1046.       dst[i][GCOMP] = 0.0F;
  1047.       dst[i][BCOMP] = 0.0F;
  1048.       dst[i][ACOMP] = 1.0F;
  1049.    }
  1050. }
  1051.  
  1052. static void
  1053. unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
  1054. {
  1055.    const GLfloat *s = (const GLfloat *) src;
  1056.    GLuint i;
  1057.    for (i = 0; i < n; i++) {
  1058.       dst[i][RCOMP] = s[i*2+0];
  1059.       dst[i][GCOMP] = s[i*2+1];
  1060.       dst[i][BCOMP] = 0.0F;
  1061.       dst[i][ACOMP] = 1.0F;
  1062.    }
  1063. }
  1064.  
  1065. static void
  1066. unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
  1067. {
  1068.    const GLhalfARB *s = (const GLhalfARB *) src;
  1069.    GLuint i;
  1070.    for (i = 0; i < n; i++) {
  1071.       dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
  1072.       dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
  1073.       dst[i][BCOMP] = 0.0F;
  1074.       dst[i][ACOMP] = 1.0F;
  1075.    }
  1076. }
  1077.  
  1078. static void
  1079. unpack_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
  1080. {
  1081.    const GLubyte *s = (const GLubyte *) src;
  1082.    GLuint i;
  1083.    for (i = 0; i < n; i++) {
  1084.       dst[i][RCOMP] =
  1085.       dst[i][GCOMP] =
  1086.       dst[i][BCOMP] = 0.0;
  1087.       dst[i][ACOMP] = (GLfloat) s[i];
  1088.    }
  1089. }
  1090.  
  1091. static void
  1092. unpack_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
  1093. {
  1094.    const GLushort *s = (const GLushort *) src;
  1095.    GLuint i;
  1096.    for (i = 0; i < n; i++) {
  1097.       dst[i][RCOMP] =
  1098.       dst[i][GCOMP] =
  1099.       dst[i][BCOMP] = 0.0;
  1100.       dst[i][ACOMP] = (GLfloat) s[i];
  1101.    }
  1102. }
  1103.  
  1104. static void
  1105. unpack_ALPHA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
  1106. {
  1107.    const GLuint *s = (const GLuint *) src;
  1108.    GLuint i;
  1109.    for (i = 0; i < n; i++) {
  1110.       dst[i][RCOMP] =
  1111.       dst[i][GCOMP] =
  1112.       dst[i][BCOMP] = 0.0;
  1113.       dst[i][ACOMP] = (GLfloat) s[i];
  1114.    }
  1115. }
  1116.  
  1117. static void
  1118. unpack_ALPHA_INT8(const void *src, GLfloat dst[][4], GLuint n)
  1119. {
  1120.    const GLbyte *s = (const GLbyte *) src;
  1121.    GLuint i;
  1122.    for (i = 0; i < n; i++) {
  1123.       dst[i][RCOMP] =
  1124.       dst[i][GCOMP] =
  1125.       dst[i][BCOMP] = 0.0;
  1126.       dst[i][ACOMP] = (GLfloat) s[i];
  1127.    }
  1128. }
  1129.  
  1130. static void
  1131. unpack_ALPHA_INT16(const void *src, GLfloat dst[][4], GLuint n)
  1132. {
  1133.    const GLshort *s = (const GLshort *) src;
  1134.    GLuint i;
  1135.    for (i = 0; i < n; i++) {
  1136.       dst[i][RCOMP] =
  1137.       dst[i][GCOMP] =
  1138.       dst[i][BCOMP] = 0.0;
  1139.       dst[i][ACOMP] = (GLfloat) s[i];
  1140.    }
  1141. }
  1142.  
  1143. static void
  1144. unpack_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
  1145. {
  1146.    const GLint *s = (const GLint *) src;
  1147.    GLuint i;
  1148.    for (i = 0; i < n; i++) {
  1149.       dst[i][RCOMP] =
  1150.       dst[i][GCOMP] =
  1151.       dst[i][BCOMP] = 0.0;
  1152.       dst[i][ACOMP] = (GLfloat) s[i];
  1153.    }
  1154. }
  1155.  
  1156. static void
  1157. unpack_INTENSITY_UINT8(const void *src, GLfloat dst[][4], GLuint n)
  1158. {
  1159.    const GLubyte *s = (const GLubyte *) src;
  1160.    GLuint i;
  1161.    for (i = 0; i < n; i++) {
  1162.       dst[i][RCOMP] =
  1163.       dst[i][GCOMP] =
  1164.       dst[i][BCOMP] =
  1165.       dst[i][ACOMP] = (GLfloat) s[i];
  1166.    }
  1167. }
  1168.  
  1169. static void
  1170. unpack_INTENSITY_UINT16(const void *src, GLfloat dst[][4], GLuint n)
  1171. {
  1172.    const GLushort *s = (const GLushort *) src;
  1173.    GLuint i;
  1174.    for (i = 0; i < n; i++) {
  1175.       dst[i][RCOMP] =
  1176.       dst[i][GCOMP] =
  1177.       dst[i][BCOMP] =
  1178.       dst[i][ACOMP] = (GLfloat) s[i];
  1179.    }
  1180. }
  1181.  
  1182. static void
  1183. unpack_INTENSITY_UINT32(const void *src, GLfloat dst[][4], GLuint n)
  1184. {
  1185.    const GLuint *s = (const GLuint *) src;
  1186.    GLuint i;
  1187.    for (i = 0; i < n; i++) {
  1188.       dst[i][RCOMP] =
  1189.       dst[i][GCOMP] =
  1190.       dst[i][BCOMP] =
  1191.       dst[i][ACOMP] = (GLfloat) s[i];
  1192.    }
  1193. }
  1194.  
  1195. static void
  1196. unpack_INTENSITY_INT8(const void *src, GLfloat dst[][4], GLuint n)
  1197. {
  1198.    const GLbyte *s = (const GLbyte *) src;
  1199.    GLuint i;
  1200.    for (i = 0; i < n; i++) {
  1201.       dst[i][RCOMP] =
  1202.       dst[i][GCOMP] =
  1203.       dst[i][BCOMP] =
  1204.       dst[i][ACOMP] = (GLfloat) s[i];
  1205.    }
  1206. }
  1207.  
  1208. static void
  1209. unpack_INTENSITY_INT16(const void *src, GLfloat dst[][4], GLuint n)
  1210. {
  1211.    const GLshort *s = (const GLshort *) src;
  1212.    GLuint i;
  1213.    for (i = 0; i < n; i++) {
  1214.       dst[i][RCOMP] =
  1215.       dst[i][GCOMP] =
  1216.       dst[i][BCOMP] =
  1217.       dst[i][ACOMP] = (GLfloat) s[i];
  1218.    }
  1219. }
  1220.  
  1221. static void
  1222. unpack_INTENSITY_INT32(const void *src, GLfloat dst[][4], GLuint n)
  1223. {
  1224.    const GLint *s = (const GLint *) src;
  1225.    GLuint i;
  1226.    for (i = 0; i < n; i++) {
  1227.       dst[i][RCOMP] =
  1228.       dst[i][GCOMP] =
  1229.       dst[i][BCOMP] =
  1230.       dst[i][ACOMP] = (GLfloat) s[i];
  1231.    }
  1232. }
  1233.  
  1234. static void
  1235. unpack_LUMINANCE_UINT8(const void *src, GLfloat dst[][4], GLuint n)
  1236. {
  1237.    const GLubyte *s = (const GLubyte *) src;
  1238.    GLuint i;
  1239.    for (i = 0; i < n; i++) {
  1240.       dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
  1241.       dst[i][ACOMP] = 1.0;
  1242.    }
  1243. }
  1244.  
  1245. static void
  1246. unpack_LUMINANCE_UINT16(const void *src, GLfloat dst[][4], GLuint n)
  1247. {
  1248.    const GLushort *s = (const GLushort *) src;
  1249.    GLuint i;
  1250.    for (i = 0; i < n; i++) {
  1251.       dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
  1252.       dst[i][ACOMP] = 1.0;
  1253.    }
  1254. }
  1255.  
  1256. static void
  1257. unpack_LUMINANCE_UINT32(const void *src, GLfloat dst[][4], GLuint n)
  1258. {
  1259.    const GLuint *s = (const GLuint *) src;
  1260.    GLuint i;
  1261.    for (i = 0; i < n; i++) {
  1262.       dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
  1263.       dst[i][ACOMP] = 1.0;
  1264.    }
  1265. }
  1266.  
  1267. static void
  1268. unpack_LUMINANCE_INT8(const void *src, GLfloat dst[][4], GLuint n)
  1269. {
  1270.    const GLbyte *s = (const GLbyte *) src;
  1271.    GLuint i;
  1272.    for (i = 0; i < n; i++) {
  1273.       dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
  1274.       dst[i][ACOMP] = 1.0;
  1275.    }
  1276. }
  1277.  
  1278. static void
  1279. unpack_LUMINANCE_INT16(const void *src, GLfloat dst[][4], GLuint n)
  1280. {
  1281.    const GLshort *s = (const GLshort *) src;
  1282.    GLuint i;
  1283.    for (i = 0; i < n; i++) {
  1284.       dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
  1285.       dst[i][ACOMP] = 1.0;
  1286.    }
  1287. }
  1288.  
  1289. static void
  1290. unpack_LUMINANCE_INT32(const void *src, GLfloat dst[][4], GLuint n)
  1291. {
  1292.    const GLint *s = (const GLint *) src;
  1293.    GLuint i;
  1294.    for (i = 0; i < n; i++) {
  1295.       dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
  1296.       dst[i][ACOMP] = 1.0;
  1297.    }
  1298. }
  1299.  
  1300. static void
  1301. unpack_LUMINANCE_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
  1302. {
  1303.    const GLubyte *s = (const GLubyte *) src;
  1304.    GLuint i;
  1305.    for (i = 0; i < n; i++) {
  1306.       dst[i][RCOMP] =
  1307.       dst[i][GCOMP] =
  1308.       dst[i][BCOMP] = (GLfloat) s[2*i+0];
  1309.       dst[i][ACOMP] = (GLfloat) s[2*i+1];
  1310.    }
  1311. }
  1312.  
  1313. static void
  1314. unpack_LUMINANCE_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
  1315. {
  1316.    const GLushort *s = (const GLushort *) src;
  1317.    GLuint i;
  1318.    for (i = 0; i < n; i++) {
  1319.       dst[i][RCOMP] =
  1320.       dst[i][GCOMP] =
  1321.       dst[i][BCOMP] = (GLfloat) s[2*i+0];
  1322.       dst[i][ACOMP] = (GLfloat) s[2*i+1];
  1323.    }
  1324. }
  1325.  
  1326. static void
  1327. unpack_LUMINANCE_ALPHA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
  1328. {
  1329.    const GLuint *s = (const GLuint *) src;
  1330.    GLuint i;
  1331.    for (i = 0; i < n; i++) {
  1332.       dst[i][RCOMP] =
  1333.       dst[i][GCOMP] =
  1334.       dst[i][BCOMP] = (GLfloat) s[2*i+0];
  1335.       dst[i][ACOMP] = (GLfloat) s[2*i+1];
  1336.    }
  1337. }
  1338.  
  1339. static void
  1340. unpack_LUMINANCE_ALPHA_INT8(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] =
  1346.       dst[i][GCOMP] =
  1347.       dst[i][BCOMP] = (GLfloat) s[2*i+0];
  1348.       dst[i][ACOMP] = (GLfloat) s[2*i+1];
  1349.    }
  1350. }
  1351.  
  1352. static void
  1353. unpack_LUMINANCE_ALPHA_INT16(const void *src, GLfloat dst[][4], GLuint n)
  1354. {
  1355.    const GLshort *s = (const GLshort *) src;
  1356.    GLuint i;
  1357.    for (i = 0; i < n; i++) {
  1358.       dst[i][RCOMP] =
  1359.       dst[i][GCOMP] =
  1360.       dst[i][BCOMP] = (GLfloat) s[2*i+0];
  1361.       dst[i][ACOMP] = (GLfloat) s[2*i+1];
  1362.    }
  1363. }
  1364.  
  1365. static void
  1366. unpack_LUMINANCE_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
  1367. {
  1368.    const GLint *s = (const GLint *) src;
  1369.    GLuint i;
  1370.    for (i = 0; i < n; i++) {
  1371.       dst[i][RCOMP] =
  1372.       dst[i][GCOMP] =
  1373.       dst[i][BCOMP] = (GLfloat) s[2*i+0];
  1374.       dst[i][ACOMP] = (GLfloat) s[2*i+1];
  1375.    }
  1376. }
  1377.  
  1378. static void
  1379. unpack_R_INT8(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] = (GLfloat) s[i];
  1385.       dst[i][GCOMP] = 0.0;
  1386.       dst[i][BCOMP] = 0.0;
  1387.       dst[i][ACOMP] = 1.0;
  1388.    }
  1389. }
  1390.  
  1391. static void
  1392. unpack_RG_INT8(const void *src, GLfloat dst[][4], GLuint n)
  1393. {
  1394.    const GLbyte *s = (const GLbyte *) src;
  1395.    GLuint i;
  1396.    for (i = 0; i < n; i++) {
  1397.       dst[i][RCOMP] = (GLfloat) s[i*2+0];
  1398.       dst[i][GCOMP] = (GLfloat) s[i*2+1];
  1399.       dst[i][BCOMP] = 0.0;
  1400.       dst[i][ACOMP] = 1.0;
  1401.    }
  1402. }
  1403.  
  1404. static void
  1405. unpack_RGB_INT8(const void *src, GLfloat dst[][4], GLuint n)
  1406. {
  1407.    const GLbyte *s = (const GLbyte *) src;
  1408.    GLuint i;
  1409.    for (i = 0; i < n; i++) {
  1410.       dst[i][RCOMP] = (GLfloat) s[i*3+0];
  1411.       dst[i][GCOMP] = (GLfloat) s[i*3+1];
  1412.       dst[i][BCOMP] = (GLfloat) s[i*3+2];
  1413.       dst[i][ACOMP] = 1.0;
  1414.    }
  1415. }
  1416.  
  1417. static void
  1418. unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
  1419. {
  1420.    const GLbyte *s = (const GLbyte *) src;
  1421.    GLuint i;
  1422.    for (i = 0; i < n; i++) {
  1423.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  1424.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  1425.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  1426.       dst[i][ACOMP] = (GLfloat) s[i*4+3];
  1427.    }
  1428. }
  1429.  
  1430. static void
  1431. unpack_R_INT16(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] = (GLfloat) s[i];
  1437.       dst[i][GCOMP] = 0.0;
  1438.       dst[i][BCOMP] = 0.0;
  1439.       dst[i][ACOMP] = 1.0;
  1440.    }
  1441. }
  1442.  
  1443. static void
  1444. unpack_RG_INT16(const void *src, GLfloat dst[][4], GLuint n)
  1445. {
  1446.    const GLshort *s = (const GLshort *) src;
  1447.    GLuint i;
  1448.    for (i = 0; i < n; i++) {
  1449.       dst[i][RCOMP] = (GLfloat) s[i*2+0];
  1450.       dst[i][GCOMP] = (GLfloat) s[i*2+1];
  1451.       dst[i][BCOMP] = 0.0;
  1452.       dst[i][ACOMP] = 1.0;
  1453.    }
  1454. }
  1455.  
  1456. static void
  1457. unpack_RGB_INT16(const void *src, GLfloat dst[][4], GLuint n)
  1458. {
  1459.    const GLshort *s = (const GLshort *) src;
  1460.    GLuint i;
  1461.    for (i = 0; i < n; i++) {
  1462.       dst[i][RCOMP] = (GLfloat) s[i*3+0];
  1463.       dst[i][GCOMP] = (GLfloat) s[i*3+1];
  1464.       dst[i][BCOMP] = (GLfloat) s[i*3+2];
  1465.       dst[i][ACOMP] = 1.0;
  1466.    }
  1467. }
  1468.  
  1469. static void
  1470. unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
  1471. {
  1472.    const GLshort *s = (const GLshort *) src;
  1473.    GLuint i;
  1474.    for (i = 0; i < n; i++) {
  1475.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  1476.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  1477.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  1478.       dst[i][ACOMP] = (GLfloat) s[i*4+3];
  1479.    }
  1480. }
  1481.  
  1482. static void
  1483. unpack_R_INT32(const void *src, GLfloat dst[][4], GLuint n)
  1484. {
  1485.    const GLint *s = (const GLint *) src;
  1486.    GLuint i;
  1487.    for (i = 0; i < n; i++) {
  1488.       dst[i][RCOMP] = (GLfloat) s[i];
  1489.       dst[i][GCOMP] = 0.0;
  1490.       dst[i][BCOMP] = 0.0;
  1491.       dst[i][ACOMP] = 1.0;
  1492.    }
  1493. }
  1494.  
  1495. static void
  1496. unpack_RG_INT32(const void *src, GLfloat dst[][4], GLuint n)
  1497. {
  1498.    const GLint *s = (const GLint *) src;
  1499.    GLuint i;
  1500.    for (i = 0; i < n; i++) {
  1501.       dst[i][RCOMP] = (GLfloat) s[i*2+0];
  1502.       dst[i][GCOMP] = (GLfloat) s[i*2+1];
  1503.       dst[i][BCOMP] = 0.0;
  1504.       dst[i][ACOMP] = 1.0;
  1505.    }
  1506. }
  1507.  
  1508. static void
  1509. unpack_RGB_INT32(const void *src, GLfloat dst[][4], GLuint n)
  1510. {
  1511.    const GLint *s = (const GLint *) src;
  1512.    GLuint i;
  1513.    for (i = 0; i < n; i++) {
  1514.       dst[i][RCOMP] = (GLfloat) s[i*3+0];
  1515.       dst[i][GCOMP] = (GLfloat) s[i*3+1];
  1516.       dst[i][BCOMP] = (GLfloat) s[i*3+2];
  1517.       dst[i][ACOMP] = 1.0;
  1518.    }
  1519. }
  1520.  
  1521.  
  1522. static void
  1523. unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
  1524. {
  1525.    const GLint *s = (const GLint *) src;
  1526.    GLuint i;
  1527.    for (i = 0; i < n; i++) {
  1528.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  1529.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  1530.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  1531.       dst[i][ACOMP] = (GLfloat) s[i*4+3];
  1532.    }
  1533. }
  1534.  
  1535. static void
  1536. unpack_R_UINT8(const void *src, GLfloat dst[][4], GLuint n)
  1537. {
  1538.    const GLubyte *s = (const GLubyte *) src;
  1539.    GLuint i;
  1540.    for (i = 0; i < n; i++) {
  1541.       dst[i][RCOMP] = (GLfloat) s[i];
  1542.       dst[i][GCOMP] = 0.0;
  1543.       dst[i][BCOMP] = 0.0;
  1544.       dst[i][ACOMP] = 1.0;
  1545.    }
  1546. }
  1547.  
  1548. static void
  1549. unpack_RG_UINT8(const void *src, GLfloat dst[][4], GLuint n)
  1550. {
  1551.    const GLubyte *s = (const GLubyte *) src;
  1552.    GLuint i;
  1553.    for (i = 0; i < n; i++) {
  1554.       dst[i][RCOMP] = (GLfloat) s[i*2+0];
  1555.       dst[i][GCOMP] = (GLfloat) s[i*2+1];
  1556.       dst[i][BCOMP] = 0.0;
  1557.       dst[i][ACOMP] = 1.0;
  1558.    }
  1559. }
  1560.  
  1561. static void
  1562. unpack_RGB_UINT8(const void *src, GLfloat dst[][4], GLuint n)
  1563. {
  1564.    const GLubyte *s = (const GLubyte *) src;
  1565.    GLuint i;
  1566.    for (i = 0; i < n; i++) {
  1567.       dst[i][RCOMP] = (GLfloat) s[i*3+0];
  1568.       dst[i][GCOMP] = (GLfloat) s[i*3+1];
  1569.       dst[i][BCOMP] = (GLfloat) s[i*3+2];
  1570.       dst[i][ACOMP] = 1.0;
  1571.    }
  1572. }
  1573.  
  1574. static void
  1575. unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
  1576. {
  1577.    const GLubyte *s = (const GLubyte *) src;
  1578.    GLuint i;
  1579.    for (i = 0; i < n; i++) {
  1580.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  1581.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  1582.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  1583.       dst[i][ACOMP] = (GLfloat) s[i*4+3];
  1584.    }
  1585. }
  1586.  
  1587. static void
  1588. unpack_R_UINT16(const void *src, GLfloat dst[][4], GLuint n)
  1589. {
  1590.    const GLushort *s = (const GLushort *) src;
  1591.    GLuint i;
  1592.    for (i = 0; i < n; i++) {
  1593.       dst[i][RCOMP] = (GLfloat) s[i];
  1594.       dst[i][GCOMP] = 0.0;
  1595.       dst[i][BCOMP] = 0.0;
  1596.       dst[i][ACOMP] = 1.0;
  1597.    }
  1598. }
  1599.  
  1600. static void
  1601. unpack_RG_UINT16(const void *src, GLfloat dst[][4], GLuint n)
  1602. {
  1603.    const GLushort *s = (const GLushort *) src;
  1604.    GLuint i;
  1605.    for (i = 0; i < n; i++) {
  1606.       dst[i][RCOMP] = (GLfloat) s[i*2+0];
  1607.       dst[i][GCOMP] = (GLfloat) s[i*2+1];
  1608.       dst[i][BCOMP] = 0.0;
  1609.       dst[i][ACOMP] = 1.0;
  1610.    }
  1611. }
  1612.  
  1613. static void
  1614. unpack_RGB_UINT16(const void *src, GLfloat dst[][4], GLuint n)
  1615. {
  1616.    const GLushort *s = (const GLushort *) src;
  1617.    GLuint i;
  1618.    for (i = 0; i < n; i++) {
  1619.       dst[i][RCOMP] = (GLfloat) s[i*3+0];
  1620.       dst[i][GCOMP] = (GLfloat) s[i*3+1];
  1621.       dst[i][BCOMP] = (GLfloat) s[i*3+2];
  1622.       dst[i][ACOMP] = 1.0;
  1623.    }
  1624. }
  1625.  
  1626. static void
  1627. unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
  1628. {
  1629.    const GLushort *s = (const GLushort *) src;
  1630.    GLuint i;
  1631.    for (i = 0; i < n; i++) {
  1632.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  1633.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  1634.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  1635.       dst[i][ACOMP] = (GLfloat) s[i*4+3];
  1636.    }
  1637. }
  1638.  
  1639. static void
  1640. unpack_R_UINT32(const void *src, GLfloat dst[][4], GLuint n)
  1641. {
  1642.    const GLuint *s = (const GLuint *) src;
  1643.    GLuint i;
  1644.    for (i = 0; i < n; i++) {
  1645.       dst[i][RCOMP] = (GLfloat) s[i];
  1646.       dst[i][GCOMP] = 0.0;
  1647.       dst[i][BCOMP] = 0.0;
  1648.       dst[i][ACOMP] = 1.0;
  1649.    }
  1650. }
  1651.  
  1652. static void
  1653. unpack_RG_UINT32(const void *src, GLfloat dst[][4], GLuint n)
  1654. {
  1655.    const GLuint *s = (const GLuint *) src;
  1656.    GLuint i;
  1657.    for (i = 0; i < n; i++) {
  1658.       dst[i][RCOMP] = (GLfloat) s[i*2+0];
  1659.       dst[i][GCOMP] = (GLfloat) s[i*2+1];
  1660.       dst[i][BCOMP] = 0.0;
  1661.       dst[i][ACOMP] = 1.0;
  1662.    }
  1663. }
  1664.  
  1665. static void
  1666. unpack_RGB_UINT32(const void *src, GLfloat dst[][4], GLuint n)
  1667. {
  1668.    const GLuint *s = (const GLuint *) src;
  1669.    GLuint i;
  1670.    for (i = 0; i < n; i++) {
  1671.       dst[i][RCOMP] = (GLfloat) s[i*3+0];
  1672.       dst[i][GCOMP] = (GLfloat) s[i*3+1];
  1673.       dst[i][BCOMP] = (GLfloat) s[i*3+2];
  1674.       dst[i][ACOMP] = 1.0;
  1675.    }
  1676. }
  1677.  
  1678. static void
  1679. unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
  1680. {
  1681.    const GLuint *s = (const GLuint *) src;
  1682.    GLuint i;
  1683.    for (i = 0; i < n; i++) {
  1684.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  1685.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  1686.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  1687.       dst[i][ACOMP] = (GLfloat) s[i*4+3];
  1688.    }
  1689. }
  1690.  
  1691. static void
  1692. unpack_DUDV8(const void *src, GLfloat dst[][4], GLuint n)
  1693. {
  1694.    const GLbyte *s = (const GLbyte *) src;
  1695.    GLuint i;
  1696.    for (i = 0; i < n; i++) {
  1697.       dst[i][RCOMP] = BYTE_TO_FLOAT(s[i*2+0]);
  1698.       dst[i][GCOMP] = BYTE_TO_FLOAT(s[i*2+1]);
  1699.       dst[i][BCOMP] = 0;
  1700.       dst[i][ACOMP] = 0;
  1701.    }
  1702. }
  1703.  
  1704. static void
  1705. unpack_SIGNED_R8(const void *src, GLfloat dst[][4], GLuint n)
  1706. {
  1707.    const GLbyte *s = ((const GLbyte *) src);
  1708.    GLuint i;
  1709.    for (i = 0; i < n; i++) {
  1710.       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
  1711.       dst[i][GCOMP] = 0.0F;
  1712.       dst[i][BCOMP] = 0.0F;
  1713.       dst[i][ACOMP] = 1.0F;
  1714.    }
  1715. }
  1716.  
  1717. static void
  1718. unpack_SIGNED_RG88_REV(const void *src, GLfloat dst[][4], GLuint n)
  1719. {
  1720.    const GLushort *s = ((const GLushort *) src);
  1721.    GLuint i;
  1722.    for (i = 0; i < n; i++) {
  1723.       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
  1724.       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
  1725.       dst[i][BCOMP] = 0.0F;
  1726.       dst[i][ACOMP] = 1.0F;
  1727.    }
  1728. }
  1729.  
  1730. static void
  1731. unpack_SIGNED_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
  1732. {
  1733.    const GLuint *s = ((const GLuint *) src);
  1734.    GLuint i;
  1735.    for (i = 0; i < n; i++) {
  1736.       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
  1737.       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
  1738.       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
  1739.       dst[i][ACOMP] = 1.0f;
  1740.    }
  1741. }
  1742.  
  1743. static void
  1744. unpack_SIGNED_RGBA8888(const void *src, GLfloat dst[][4], GLuint n)
  1745. {
  1746.    const GLuint *s = ((const GLuint *) src);
  1747.    GLuint i;
  1748.    for (i = 0; i < n; i++) {
  1749.       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
  1750.       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
  1751.       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
  1752.       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
  1753.    }
  1754. }
  1755.  
  1756. static void
  1757. unpack_SIGNED_RGBA8888_REV(const void *src, GLfloat dst[][4], GLuint n)
  1758. {
  1759.    const GLuint *s = ((const GLuint *) src);
  1760.    GLuint i;
  1761.    for (i = 0; i < n; i++) {
  1762.       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
  1763.       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
  1764.       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
  1765.       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
  1766.    }
  1767. }
  1768.  
  1769. static void
  1770. unpack_SIGNED_R16(const void *src, GLfloat dst[][4], GLuint n)
  1771. {
  1772.    const GLshort *s = ((const GLshort *) src);
  1773.    GLuint i;
  1774.    for (i = 0; i < n; i++) {
  1775.       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
  1776.       dst[i][GCOMP] = 0.0F;
  1777.       dst[i][BCOMP] = 0.0F;
  1778.       dst[i][ACOMP] = 1.0F;
  1779.    }
  1780. }
  1781.  
  1782. static void
  1783. unpack_SIGNED_GR1616(const void *src, GLfloat dst[][4], GLuint n)
  1784. {
  1785.    const GLuint *s = ((const GLuint *) src);
  1786.    GLuint i;
  1787.    for (i = 0; i < n; i++) {
  1788.       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
  1789.       dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
  1790.       dst[i][BCOMP] = 0.0F;
  1791.       dst[i][ACOMP] = 1.0F;
  1792.    }
  1793. }
  1794.  
  1795. static void
  1796. unpack_SIGNED_RGB_16(const void *src, GLfloat dst[][4], GLuint n)
  1797. {
  1798.    const GLshort *s = (const GLshort *) src;
  1799.    GLuint i;
  1800.    for (i = 0; i < n; i++) {
  1801.       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
  1802.       dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
  1803.       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
  1804.       dst[i][ACOMP] = 1.0F;
  1805.    }
  1806. }
  1807.  
  1808. static void
  1809. unpack_SIGNED_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
  1810. {
  1811.    const GLshort *s = (const GLshort *) src;
  1812.    GLuint i;
  1813.    for (i = 0; i < n; i++) {
  1814.       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
  1815.       dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
  1816.       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
  1817.       dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
  1818.    }
  1819. }
  1820.  
  1821. static void
  1822. unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
  1823. {
  1824.    const GLushort *s = (const GLushort *) src;
  1825.    GLuint i;
  1826.    for (i = 0; i < n; i++) {
  1827.       dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
  1828.       dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
  1829.       dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
  1830.       dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
  1831.    }
  1832. }
  1833.  
  1834. static void
  1835. unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
  1836. {
  1837.    /* XXX to do */
  1838. }
  1839.  
  1840. static void
  1841. unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
  1842. {
  1843.    /* XXX to do */
  1844. }
  1845.  
  1846. static void
  1847. unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
  1848. {
  1849.    /* XXX to do */
  1850. }
  1851.  
  1852. static void
  1853. unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
  1854. {
  1855.    /* XXX to do */
  1856. }
  1857.  
  1858. static void
  1859. unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
  1860. {
  1861.    /* XXX to do */
  1862. }
  1863.  
  1864. static void
  1865. unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
  1866. {
  1867.    /* XXX to do */
  1868. }
  1869.  
  1870. static void
  1871. unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
  1872. {
  1873.    /* XXX to do */
  1874. }
  1875.  
  1876. static void
  1877. unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
  1878. {
  1879.    /* XXX to do */
  1880. }
  1881.  
  1882. static void
  1883. unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
  1884. {
  1885.    /* XXX to do */
  1886. }
  1887.  
  1888. static void
  1889. unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n)
  1890. {
  1891.    /* XXX to do */
  1892. }
  1893.  
  1894. static void
  1895. unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
  1896. {
  1897.    /* XXX to do */
  1898. }
  1899.  
  1900. static void
  1901. unpack_ETC2_RGBA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
  1902. {
  1903.    /* XXX to do */
  1904. }
  1905.  
  1906. static void
  1907. unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
  1908. {
  1909.    /* XXX to do */
  1910. }
  1911.  
  1912. static void
  1913. unpack_ETC2_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
  1914. {
  1915.    /* XXX to do */
  1916. }
  1917.  
  1918. static void
  1919. unpack_ETC2_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
  1920. {
  1921.    /* XXX to do */
  1922. }
  1923.  
  1924. static void
  1925. unpack_ETC2_SIGNED_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
  1926. {
  1927.    /* XXX to do */
  1928. }
  1929.  
  1930. static void
  1931. unpack_ETC2_SIGNED_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
  1932. {
  1933.    /* XXX to do */
  1934. }
  1935.  
  1936. static void
  1937. unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
  1938.                                       GLuint n)
  1939. {
  1940.    /* XXX to do */
  1941. }
  1942.  
  1943. static void
  1944. unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
  1945.                                       GLuint n)
  1946. {
  1947.    /* XXX to do */
  1948. }
  1949.  
  1950. static void
  1951. unpack_SIGNED_A8(const void *src, GLfloat dst[][4], GLuint n)
  1952. {
  1953.    const GLbyte *s = ((const GLbyte *) src);
  1954.    GLuint i;
  1955.    for (i = 0; i < n; i++) {
  1956.       dst[i][RCOMP] = 0.0F;
  1957.       dst[i][GCOMP] = 0.0F;
  1958.       dst[i][BCOMP] = 0.0F;
  1959.       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
  1960.    }
  1961. }
  1962.  
  1963. static void
  1964. unpack_SIGNED_L8(const void *src, GLfloat dst[][4], GLuint n)
  1965. {
  1966.    const GLbyte *s = ((const GLbyte *) src);
  1967.    GLuint i;
  1968.    for (i = 0; i < n; i++) {
  1969.       dst[i][RCOMP] =
  1970.       dst[i][GCOMP] =
  1971.       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
  1972.       dst[i][ACOMP] = 1.0F;
  1973.    }
  1974. }
  1975.  
  1976. static void
  1977. unpack_SIGNED_AL88(const void *src, GLfloat dst[][4], GLuint n)
  1978. {
  1979.    const GLshort *s = ((const GLshort *) src);
  1980.    GLuint i;
  1981.    for (i = 0; i < n; i++) {
  1982.       dst[i][RCOMP] =
  1983.       dst[i][GCOMP] =
  1984.       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
  1985.       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
  1986.    }
  1987. }
  1988.  
  1989. static void
  1990. unpack_SIGNED_I8(const void *src, GLfloat dst[][4], GLuint n)
  1991. {
  1992.    const GLbyte *s = ((const GLbyte *) src);
  1993.    GLuint i;
  1994.    for (i = 0; i < n; i++) {
  1995.       dst[i][RCOMP] =
  1996.       dst[i][GCOMP] =
  1997.       dst[i][BCOMP] =
  1998.       dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
  1999.    }
  2000. }
  2001.  
  2002. static void
  2003. unpack_SIGNED_A16(const void *src, GLfloat dst[][4], GLuint n)
  2004. {
  2005.    const GLshort *s = ((const GLshort *) src);
  2006.    GLuint i;
  2007.    for (i = 0; i < n; i++) {
  2008.       dst[i][RCOMP] = 0.0F;
  2009.       dst[i][GCOMP] = 0.0F;
  2010.       dst[i][BCOMP] = 0.0F;
  2011.       dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
  2012.    }
  2013. }
  2014.  
  2015. static void
  2016. unpack_SIGNED_L16(const void *src, GLfloat dst[][4], GLuint n)
  2017. {
  2018.    const GLshort *s = ((const GLshort *) src);
  2019.    GLuint i;
  2020.    for (i = 0; i < n; i++) {
  2021.       dst[i][RCOMP] =
  2022.       dst[i][GCOMP] =
  2023.       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
  2024.       dst[i][ACOMP] = 1.0F;
  2025.    }
  2026. }
  2027.  
  2028. static void
  2029. unpack_SIGNED_AL1616(const void *src, GLfloat dst[][4], GLuint n)
  2030. {
  2031.    const GLshort *s = (const GLshort *) src;
  2032.    GLuint i;
  2033.    for (i = 0; i < n; i++) {
  2034.       dst[i][RCOMP] =
  2035.       dst[i][GCOMP] =
  2036.       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
  2037.       dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
  2038.    }
  2039. }
  2040.  
  2041. static void
  2042. unpack_SIGNED_I16(const void *src, GLfloat dst[][4], GLuint n)
  2043. {
  2044.    const GLshort *s = ((const GLshort *) src);
  2045.    GLuint i;
  2046.    for (i = 0; i < n; i++) {
  2047.       dst[i][RCOMP] =
  2048.       dst[i][GCOMP] =
  2049.       dst[i][BCOMP] =
  2050.       dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
  2051.    }
  2052. }
  2053.  
  2054. static void
  2055. unpack_RGB9_E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
  2056. {
  2057.    const GLuint *s = (const GLuint *) src;
  2058.    GLuint i;
  2059.    for (i = 0; i < n; i++) {
  2060.       rgb9e5_to_float3(s[i], dst[i]);
  2061.       dst[i][ACOMP] = 1.0F;
  2062.    }
  2063. }
  2064.  
  2065. static void
  2066. unpack_R11_G11_B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
  2067. {
  2068.    const GLuint *s = (const GLuint *) src;
  2069.    GLuint i;
  2070.    for (i = 0; i < n; i++) {
  2071.       r11g11b10f_to_float3(s[i], dst[i]);
  2072.       dst[i][ACOMP] = 1.0F;
  2073.    }
  2074. }
  2075.  
  2076. static void
  2077. unpack_XRGB4444_UNORM(const void *src, GLfloat dst[][4], GLuint n)
  2078. {
  2079.    const GLushort *s = ((const GLushort *) src);
  2080.    GLuint i;
  2081.    for (i = 0; i < n; i++) {
  2082.       dst[i][RCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
  2083.       dst[i][GCOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
  2084.       dst[i][BCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
  2085.       dst[i][ACOMP] = 1.0;
  2086.    }
  2087. }
  2088.  
  2089. static void
  2090. unpack_XRGB1555_UNORM(const void *src, GLfloat dst[][4], GLuint n)
  2091. {
  2092.    const GLushort *s = ((const GLushort *) src);
  2093.    GLuint i;
  2094.    for (i = 0; i < n; i++) {
  2095.       dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
  2096.       dst[i][GCOMP] = ((s[i] >>  5) & 0x1f) * (1.0F / 31.0F);
  2097.       dst[i][BCOMP] = ((s[i] >>  0) & 0x1f) * (1.0F / 31.0F);
  2098.       dst[i][ACOMP] = 1.0;
  2099.    }
  2100. }
  2101.  
  2102. static void
  2103. unpack_XBGR8888_SNORM(const void *src, GLfloat dst[][4], GLuint n)
  2104. {
  2105.    const GLuint *s = ((const GLuint *) src);
  2106.    GLuint i;
  2107.    for (i = 0; i < n; i++) {
  2108.       dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
  2109.       dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
  2110.       dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
  2111.       dst[i][ACOMP] = 1.0;
  2112.    }
  2113. }
  2114.  
  2115. static void
  2116. unpack_XBGR8888_SRGB(const void *src, GLfloat dst[][4], GLuint n)
  2117. {
  2118.    const GLuint *s = ((const GLuint *) src);
  2119.    GLuint i;
  2120.    for (i = 0; i < n; i++) {
  2121.       dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
  2122.       dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
  2123.       dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
  2124.       dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
  2125.    }
  2126. }
  2127.  
  2128. static void
  2129. unpack_XBGR8888_UINT(const void *src, GLfloat dst[][4], GLuint n)
  2130. {
  2131.    const GLbyte *s = (const GLbyte *) src;
  2132.    GLuint i;
  2133.    for (i = 0; i < n; i++) {
  2134.       dst[i][RCOMP] = s[i*4+0];
  2135.       dst[i][GCOMP] = s[i*4+1];
  2136.       dst[i][BCOMP] = s[i*4+2];
  2137.       dst[i][ACOMP] = 1.0;
  2138.    }
  2139. }
  2140.  
  2141. static void
  2142. unpack_XBGR8888_SINT(const void *src, GLfloat dst[][4], GLuint n)
  2143. {
  2144.    const GLbyte *s = (const GLbyte *) src;
  2145.    GLuint i;
  2146.    for (i = 0; i < n; i++) {
  2147.       dst[i][RCOMP] = s[i*4+0];
  2148.       dst[i][GCOMP] = s[i*4+1];
  2149.       dst[i][BCOMP] = s[i*4+2];
  2150.       dst[i][ACOMP] = 1.0;
  2151.    }
  2152. }
  2153.  
  2154. static void
  2155. unpack_XRGB2101010_UNORM(const void *src, GLfloat dst[][4], GLuint n)
  2156. {
  2157.    const GLuint *s = ((const GLuint *) src);
  2158.    GLuint i;
  2159.    for (i = 0; i < n; i++) {
  2160.       dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
  2161.       dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
  2162.       dst[i][BCOMP] = ((s[i] >>  0) & 0x3ff) * (1.0F / 1023.0F);
  2163.       dst[i][ACOMP] = 1.0;
  2164.    }
  2165. }
  2166.  
  2167. static void
  2168. unpack_XBGR16161616_UNORM(const void *src, GLfloat dst[][4], GLuint n)
  2169. {
  2170.    const GLushort *s = (const GLushort *) src;
  2171.    GLuint i;
  2172.    for (i = 0; i < n; i++) {
  2173.       dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
  2174.       dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
  2175.       dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
  2176.       dst[i][ACOMP] = 1.0;
  2177.    }
  2178. }
  2179.  
  2180. static void
  2181. unpack_XBGR16161616_SNORM(const void *src, GLfloat dst[][4], GLuint n)
  2182. {
  2183.    const GLshort *s = (const GLshort *) src;
  2184.    GLuint i;
  2185.    for (i = 0; i < n; i++) {
  2186.       dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
  2187.       dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
  2188.       dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
  2189.       dst[i][ACOMP] = 1.0;
  2190.    }
  2191. }
  2192.  
  2193. static void
  2194. unpack_XBGR16161616_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
  2195. {
  2196.    const GLshort *s = (const GLshort *) src;
  2197.    GLuint i;
  2198.    for (i = 0; i < n; i++) {
  2199.       dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
  2200.       dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
  2201.       dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
  2202.       dst[i][ACOMP] = 1.0;
  2203.    }
  2204. }
  2205.  
  2206. static void
  2207. unpack_XBGR16161616_UINT(const void *src, GLfloat dst[][4], GLuint n)
  2208. {
  2209.    const GLushort *s = (const GLushort *) src;
  2210.    GLuint i;
  2211.    for (i = 0; i < n; i++) {
  2212.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  2213.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  2214.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  2215.       dst[i][ACOMP] = 1.0;
  2216.    }
  2217. }
  2218.  
  2219. static void
  2220. unpack_XBGR16161616_SINT(const void *src, GLfloat dst[][4], GLuint n)
  2221. {
  2222.    const GLshort *s = (const GLshort *) src;
  2223.    GLuint i;
  2224.    for (i = 0; i < n; i++) {
  2225.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  2226.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  2227.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  2228.       dst[i][ACOMP] = 1.0;
  2229.    }
  2230. }
  2231.  
  2232. static void
  2233. unpack_XBGR32323232_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
  2234. {
  2235.    const GLfloat *s = (const GLfloat *) src;
  2236.    GLuint i;
  2237.    for (i = 0; i < n; i++) {
  2238.       dst[i][RCOMP] = s[i*4+0];
  2239.       dst[i][GCOMP] = s[i*4+1];
  2240.       dst[i][BCOMP] = s[i*4+2];
  2241.       dst[i][ACOMP] = 1.0;
  2242.    }
  2243. }
  2244.  
  2245. static void
  2246. unpack_XBGR32323232_UINT(const void *src, GLfloat dst[][4], GLuint n)
  2247. {
  2248.    const GLuint *s = (const GLuint *) src;
  2249.    GLuint i;
  2250.    for (i = 0; i < n; i++) {
  2251.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  2252.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  2253.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  2254.       dst[i][ACOMP] = 1.0;
  2255.    }
  2256. }
  2257.  
  2258. static void
  2259. unpack_XBGR32323232_SINT(const void *src, GLfloat dst[][4], GLuint n)
  2260. {
  2261.    const GLint *s = (const GLint *) src;
  2262.    GLuint i;
  2263.    for (i = 0; i < n; i++) {
  2264.       dst[i][RCOMP] = (GLfloat) s[i*4+0];
  2265.       dst[i][GCOMP] = (GLfloat) s[i*4+1];
  2266.       dst[i][BCOMP] = (GLfloat) s[i*4+2];
  2267.       dst[i][ACOMP] = 1.0;
  2268.    }
  2269. }
  2270.  
  2271.  
  2272. /**
  2273.  * Return the unpacker function for the given format.
  2274.  */
  2275. static unpack_rgba_func
  2276. get_unpack_rgba_function(gl_format format)
  2277. {
  2278.    static unpack_rgba_func table[MESA_FORMAT_COUNT];
  2279.    static GLboolean initialized = GL_FALSE;
  2280.  
  2281.    if (!initialized) {
  2282.       table[MESA_FORMAT_NONE] = NULL;
  2283.  
  2284.       table[MESA_FORMAT_RGBA8888] = unpack_RGBA8888;
  2285.       table[MESA_FORMAT_RGBA8888_REV] = unpack_RGBA8888_REV;
  2286.       table[MESA_FORMAT_ARGB8888] = unpack_ARGB8888;
  2287.       table[MESA_FORMAT_ARGB8888_REV] = unpack_ARGB8888_REV;
  2288.       table[MESA_FORMAT_RGBX8888] = unpack_RGBX8888;
  2289.       table[MESA_FORMAT_RGBX8888_REV] = unpack_RGBX8888_REV;
  2290.       table[MESA_FORMAT_XRGB8888] = unpack_XRGB8888;
  2291.       table[MESA_FORMAT_XRGB8888_REV] = unpack_XRGB8888_REV;
  2292.       table[MESA_FORMAT_RGB888] = unpack_RGB888;
  2293.       table[MESA_FORMAT_BGR888] = unpack_BGR888;
  2294.       table[MESA_FORMAT_RGB565] = unpack_RGB565;
  2295.       table[MESA_FORMAT_RGB565_REV] = unpack_RGB565_REV;
  2296.       table[MESA_FORMAT_ARGB4444] = unpack_ARGB4444;
  2297.       table[MESA_FORMAT_ARGB4444_REV] = unpack_ARGB4444_REV;
  2298.       table[MESA_FORMAT_RGBA5551] = unpack_RGBA5551;
  2299.       table[MESA_FORMAT_ARGB1555] = unpack_ARGB1555;
  2300.       table[MESA_FORMAT_ARGB1555_REV] = unpack_ARGB1555_REV;
  2301.       table[MESA_FORMAT_AL44] = unpack_AL44;
  2302.       table[MESA_FORMAT_AL88] = unpack_AL88;
  2303.       table[MESA_FORMAT_AL88_REV] = unpack_AL88_REV;
  2304.       table[MESA_FORMAT_AL1616] = unpack_AL1616;
  2305.       table[MESA_FORMAT_AL1616_REV] = unpack_AL1616_REV;
  2306.       table[MESA_FORMAT_RGB332] = unpack_RGB332;
  2307.       table[MESA_FORMAT_A8] = unpack_A8;
  2308.       table[MESA_FORMAT_A16] = unpack_A16;
  2309.       table[MESA_FORMAT_L8] = unpack_L8;
  2310.       table[MESA_FORMAT_L16] = unpack_L16;
  2311.       table[MESA_FORMAT_I8] = unpack_I8;
  2312.       table[MESA_FORMAT_I16] = unpack_I16;
  2313.       table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
  2314.       table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
  2315.       table[MESA_FORMAT_R8] = unpack_R8;
  2316.       table[MESA_FORMAT_GR88] = unpack_GR88;
  2317.       table[MESA_FORMAT_RG88] = unpack_RG88;
  2318.       table[MESA_FORMAT_R16] = unpack_R16;
  2319.       table[MESA_FORMAT_GR1616] = unpack_GR1616;
  2320.       table[MESA_FORMAT_RG1616] = unpack_RG1616;
  2321.       table[MESA_FORMAT_ARGB2101010] = unpack_ARGB2101010;
  2322.       table[MESA_FORMAT_ARGB2101010_UINT] = unpack_ARGB2101010_UINT;
  2323.       table[MESA_FORMAT_ABGR2101010_UINT] = unpack_ABGR2101010_UINT;
  2324.       table[MESA_FORMAT_Z24_S8] = unpack_Z24_S8;
  2325.       table[MESA_FORMAT_S8_Z24] = unpack_S8_Z24;
  2326.       table[MESA_FORMAT_Z16] = unpack_Z16;
  2327.       table[MESA_FORMAT_X8_Z24] = unpack_X8_Z24;
  2328.       table[MESA_FORMAT_Z24_X8] = unpack_Z24_X8;
  2329.       table[MESA_FORMAT_Z32] = unpack_Z32;
  2330.       table[MESA_FORMAT_S8] = unpack_S8;
  2331.       table[MESA_FORMAT_SRGB8] = unpack_SRGB8;
  2332.       table[MESA_FORMAT_SRGBA8] = unpack_SRGBA8;
  2333.       table[MESA_FORMAT_SARGB8] = unpack_SARGB8;
  2334.       table[MESA_FORMAT_SL8] = unpack_SL8;
  2335.       table[MESA_FORMAT_SLA8] = unpack_SLA8;
  2336.       table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
  2337.       table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
  2338.       table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
  2339.       table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;
  2340.  
  2341.       table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
  2342.       table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
  2343.       table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
  2344.       table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
  2345.       table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
  2346.       table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;
  2347.  
  2348.       table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
  2349.       table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
  2350.       table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
  2351.       table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
  2352.       table[MESA_FORMAT_ALPHA_FLOAT32] = unpack_ALPHA_FLOAT32;
  2353.       table[MESA_FORMAT_ALPHA_FLOAT16] = unpack_ALPHA_FLOAT16;
  2354.       table[MESA_FORMAT_LUMINANCE_FLOAT32] = unpack_LUMINANCE_FLOAT32;
  2355.       table[MESA_FORMAT_LUMINANCE_FLOAT16] = unpack_LUMINANCE_FLOAT16;
  2356.       table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = unpack_LUMINANCE_ALPHA_FLOAT32;
  2357.       table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = unpack_LUMINANCE_ALPHA_FLOAT16;
  2358.       table[MESA_FORMAT_INTENSITY_FLOAT32] = unpack_INTENSITY_FLOAT32;
  2359.       table[MESA_FORMAT_INTENSITY_FLOAT16] = unpack_INTENSITY_FLOAT16;
  2360.       table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
  2361.       table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
  2362.       table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
  2363.       table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;
  2364.  
  2365.       table[MESA_FORMAT_ALPHA_UINT8] = unpack_ALPHA_UINT8;
  2366.       table[MESA_FORMAT_ALPHA_UINT16] = unpack_ALPHA_UINT16;
  2367.       table[MESA_FORMAT_ALPHA_UINT32] = unpack_ALPHA_UINT32;
  2368.       table[MESA_FORMAT_ALPHA_INT8] = unpack_ALPHA_INT8;
  2369.       table[MESA_FORMAT_ALPHA_INT16] = unpack_ALPHA_INT16;
  2370.       table[MESA_FORMAT_ALPHA_INT32] = unpack_ALPHA_INT32;
  2371.  
  2372.       table[MESA_FORMAT_INTENSITY_UINT8] = unpack_INTENSITY_UINT8;
  2373.       table[MESA_FORMAT_INTENSITY_UINT16] = unpack_INTENSITY_UINT16;
  2374.       table[MESA_FORMAT_INTENSITY_UINT32] = unpack_INTENSITY_UINT32;
  2375.       table[MESA_FORMAT_INTENSITY_INT8] = unpack_INTENSITY_INT8;
  2376.       table[MESA_FORMAT_INTENSITY_INT16] = unpack_INTENSITY_INT16;
  2377.       table[MESA_FORMAT_INTENSITY_INT32] = unpack_INTENSITY_INT32;
  2378.  
  2379.       table[MESA_FORMAT_LUMINANCE_UINT8] = unpack_LUMINANCE_UINT8;
  2380.       table[MESA_FORMAT_LUMINANCE_UINT16] = unpack_LUMINANCE_UINT16;
  2381.       table[MESA_FORMAT_LUMINANCE_UINT32] = unpack_LUMINANCE_UINT32;
  2382.       table[MESA_FORMAT_LUMINANCE_INT8] = unpack_LUMINANCE_INT8;
  2383.       table[MESA_FORMAT_LUMINANCE_INT16] = unpack_LUMINANCE_INT16;
  2384.       table[MESA_FORMAT_LUMINANCE_INT32] = unpack_LUMINANCE_INT32;
  2385.  
  2386.       table[MESA_FORMAT_LUMINANCE_ALPHA_UINT8] = unpack_LUMINANCE_ALPHA_UINT8;
  2387.       table[MESA_FORMAT_LUMINANCE_ALPHA_UINT16] = unpack_LUMINANCE_ALPHA_UINT16;
  2388.       table[MESA_FORMAT_LUMINANCE_ALPHA_UINT32] = unpack_LUMINANCE_ALPHA_UINT32;
  2389.       table[MESA_FORMAT_LUMINANCE_ALPHA_INT8] = unpack_LUMINANCE_ALPHA_INT8;
  2390.       table[MESA_FORMAT_LUMINANCE_ALPHA_INT16] = unpack_LUMINANCE_ALPHA_INT16;
  2391.       table[MESA_FORMAT_LUMINANCE_ALPHA_INT32] = unpack_LUMINANCE_ALPHA_INT32;
  2392.  
  2393.       table[MESA_FORMAT_R_INT8] = unpack_R_INT8;
  2394.       table[MESA_FORMAT_RG_INT8] = unpack_RG_INT8;
  2395.       table[MESA_FORMAT_RGB_INT8] = unpack_RGB_INT8;
  2396.       table[MESA_FORMAT_RGBA_INT8] = unpack_RGBA_INT8;
  2397.       table[MESA_FORMAT_R_INT16] = unpack_R_INT16;
  2398.       table[MESA_FORMAT_RG_INT16] = unpack_RG_INT16;
  2399.       table[MESA_FORMAT_RGB_INT16] = unpack_RGB_INT16;
  2400.       table[MESA_FORMAT_RGBA_INT16] = unpack_RGBA_INT16;
  2401.       table[MESA_FORMAT_R_INT32] = unpack_R_INT32;
  2402.       table[MESA_FORMAT_RG_INT32] = unpack_RG_INT32;
  2403.       table[MESA_FORMAT_RGB_INT32] = unpack_RGB_INT32;
  2404.       table[MESA_FORMAT_RGBA_INT32] = unpack_RGBA_INT32;
  2405.       table[MESA_FORMAT_R_UINT8] = unpack_R_UINT8;
  2406.       table[MESA_FORMAT_RG_UINT8] = unpack_RG_UINT8;
  2407.       table[MESA_FORMAT_RGB_UINT8] = unpack_RGB_UINT8;
  2408.       table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
  2409.       table[MESA_FORMAT_R_UINT16] = unpack_R_UINT16;
  2410.       table[MESA_FORMAT_RG_UINT16] = unpack_RG_UINT16;
  2411.       table[MESA_FORMAT_RGB_UINT16] = unpack_RGB_UINT16;
  2412.       table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
  2413.       table[MESA_FORMAT_R_UINT32] = unpack_R_UINT32;
  2414.       table[MESA_FORMAT_RG_UINT32] = unpack_RG_UINT32;
  2415.       table[MESA_FORMAT_RGB_UINT32] = unpack_RGB_UINT32;
  2416.       table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;
  2417.  
  2418.       table[MESA_FORMAT_DUDV8] = unpack_DUDV8;
  2419.       table[MESA_FORMAT_SIGNED_R8] = unpack_SIGNED_R8;
  2420.       table[MESA_FORMAT_SIGNED_RG88_REV] = unpack_SIGNED_RG88_REV;
  2421.       table[MESA_FORMAT_SIGNED_RGBX8888] = unpack_SIGNED_RGBX8888;
  2422.       table[MESA_FORMAT_SIGNED_RGBA8888] = unpack_SIGNED_RGBA8888;
  2423.       table[MESA_FORMAT_SIGNED_RGBA8888_REV] = unpack_SIGNED_RGBA8888_REV;
  2424.       table[MESA_FORMAT_SIGNED_R16] = unpack_SIGNED_R16;
  2425.       table[MESA_FORMAT_SIGNED_GR1616] = unpack_SIGNED_GR1616;
  2426.       table[MESA_FORMAT_SIGNED_RGB_16] = unpack_SIGNED_RGB_16;
  2427.       table[MESA_FORMAT_SIGNED_RGBA_16] = unpack_SIGNED_RGBA_16;
  2428.       table[MESA_FORMAT_RGBA_16] = unpack_RGBA_16;
  2429.  
  2430.       table[MESA_FORMAT_RED_RGTC1] = unpack_RED_RGTC1;
  2431.       table[MESA_FORMAT_SIGNED_RED_RGTC1] = unpack_SIGNED_RED_RGTC1;
  2432.       table[MESA_FORMAT_RG_RGTC2] = unpack_RG_RGTC2;
  2433.       table[MESA_FORMAT_SIGNED_RG_RGTC2] = unpack_SIGNED_RG_RGTC2;
  2434.  
  2435.       table[MESA_FORMAT_L_LATC1] = unpack_L_LATC1;
  2436.       table[MESA_FORMAT_SIGNED_L_LATC1] = unpack_SIGNED_L_LATC1;
  2437.       table[MESA_FORMAT_LA_LATC2] = unpack_LA_LATC2;
  2438.       table[MESA_FORMAT_SIGNED_LA_LATC2] = unpack_SIGNED_LA_LATC2;
  2439.  
  2440.       table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
  2441.       table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8;
  2442.       table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8;
  2443.       table[MESA_FORMAT_ETC2_RGBA8_EAC] = unpack_ETC2_RGBA8_EAC;
  2444.       table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = unpack_ETC2_SRGB8_ALPHA8_EAC;
  2445.       table[MESA_FORMAT_ETC2_R11_EAC] = unpack_ETC2_R11_EAC;
  2446.       table[MESA_FORMAT_ETC2_RG11_EAC] = unpack_ETC2_RG11_EAC;
  2447.       table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = unpack_ETC2_SIGNED_R11_EAC;
  2448.       table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = unpack_ETC2_SIGNED_RG11_EAC;
  2449.       table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
  2450.          unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
  2451.       table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] =
  2452.          unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
  2453.       table[MESA_FORMAT_SIGNED_A8] = unpack_SIGNED_A8;
  2454.       table[MESA_FORMAT_SIGNED_L8] = unpack_SIGNED_L8;
  2455.       table[MESA_FORMAT_SIGNED_AL88] = unpack_SIGNED_AL88;
  2456.       table[MESA_FORMAT_SIGNED_I8] = unpack_SIGNED_I8;
  2457.       table[MESA_FORMAT_SIGNED_A16] = unpack_SIGNED_A16;
  2458.       table[MESA_FORMAT_SIGNED_L16] = unpack_SIGNED_L16;
  2459.       table[MESA_FORMAT_SIGNED_AL1616] = unpack_SIGNED_AL1616;
  2460.       table[MESA_FORMAT_SIGNED_I16] = unpack_SIGNED_I16;
  2461.  
  2462.       table[MESA_FORMAT_RGB9_E5_FLOAT] = unpack_RGB9_E5_FLOAT;
  2463.       table[MESA_FORMAT_R11_G11_B10_FLOAT] = unpack_R11_G11_B10_FLOAT;
  2464.  
  2465.       table[MESA_FORMAT_Z32_FLOAT] = unpack_Z32_FLOAT;
  2466.       table[MESA_FORMAT_Z32_FLOAT_X24S8] = unpack_Z32_FLOAT_X24S8;
  2467.  
  2468.       table[MESA_FORMAT_XRGB4444_UNORM] = unpack_XRGB4444_UNORM;
  2469.       table[MESA_FORMAT_XRGB1555_UNORM] = unpack_XRGB1555_UNORM;
  2470.       table[MESA_FORMAT_XBGR8888_SNORM] = unpack_XBGR8888_SNORM;
  2471.       table[MESA_FORMAT_XBGR8888_SRGB] = unpack_XBGR8888_SRGB;
  2472.       table[MESA_FORMAT_XBGR8888_UINT] = unpack_XBGR8888_UINT;
  2473.       table[MESA_FORMAT_XBGR8888_SINT] = unpack_XBGR8888_SINT;
  2474.       table[MESA_FORMAT_XRGB2101010_UNORM] = unpack_XRGB2101010_UNORM;
  2475.       table[MESA_FORMAT_XBGR16161616_UNORM] = unpack_XBGR16161616_UNORM;
  2476.       table[MESA_FORMAT_XBGR16161616_SNORM] = unpack_XBGR16161616_SNORM;
  2477.       table[MESA_FORMAT_XBGR16161616_FLOAT] = unpack_XBGR16161616_FLOAT;
  2478.       table[MESA_FORMAT_XBGR16161616_UINT] = unpack_XBGR16161616_UINT;
  2479.       table[MESA_FORMAT_XBGR16161616_SINT] = unpack_XBGR16161616_SINT;
  2480.       table[MESA_FORMAT_XBGR32323232_FLOAT] = unpack_XBGR32323232_FLOAT;
  2481.       table[MESA_FORMAT_XBGR32323232_UINT] = unpack_XBGR32323232_UINT;
  2482.       table[MESA_FORMAT_XBGR32323232_SINT] = unpack_XBGR32323232_SINT;
  2483.  
  2484.       initialized = GL_TRUE;
  2485.    }
  2486.  
  2487.    if (table[format] == NULL) {
  2488.       _mesa_problem(NULL, "unsupported unpack for format %s",
  2489.                     _mesa_get_format_name(format));
  2490.    }
  2491.  
  2492.    return table[format];
  2493. }
  2494.  
  2495.  
  2496. /**
  2497.  * Unpack rgba colors, returning as GLfloat values.
  2498.  */
  2499. void
  2500. _mesa_unpack_rgba_row(gl_format format, GLuint n,
  2501.                       const void *src, GLfloat dst[][4])
  2502. {
  2503.    unpack_rgba_func unpack = get_unpack_rgba_function(format);
  2504.    unpack(src, dst, n);
  2505. }
  2506.  
  2507.  
  2508. /**********************************************************************/
  2509. /*  Unpack, returning GLubyte colors                                  */
  2510. /**********************************************************************/
  2511.  
  2512.  
  2513. static void
  2514. unpack_ubyte_RGBA8888(const void *src, GLubyte dst[][4], GLuint n)
  2515. {
  2516.    const GLuint *s = ((const GLuint *) src);
  2517.    GLuint i;
  2518.    for (i = 0; i < n; i++) {
  2519.       dst[i][RCOMP] = (s[i] >> 24);
  2520.       dst[i][GCOMP] = (s[i] >> 16) & 0xff;
  2521.       dst[i][BCOMP] = (s[i] >>  8) & 0xff;
  2522.       dst[i][ACOMP] = (s[i]      ) & 0xff;
  2523.    }
  2524. }
  2525.  
  2526. static void
  2527. unpack_ubyte_RGBA8888_REV(const void *src, GLubyte dst[][4], GLuint n)
  2528. {
  2529.    const GLuint *s = ((const GLuint *) src);
  2530.    GLuint i;
  2531.    for (i = 0; i < n; i++) {
  2532.       dst[i][RCOMP] = (s[i]      ) & 0xff;
  2533.       dst[i][GCOMP] = (s[i] >>  8) & 0xff;
  2534.       dst[i][BCOMP] = (s[i] >> 16) & 0xff;
  2535.       dst[i][ACOMP] = (s[i] >> 24);
  2536.    }
  2537. }
  2538.  
  2539. static void
  2540. unpack_ubyte_ARGB8888(const void *src, GLubyte dst[][4], GLuint n)
  2541. {
  2542.    const GLuint *s = ((const GLuint *) src);
  2543.    GLuint i;
  2544.    for (i = 0; i < n; i++) {
  2545.       dst[i][RCOMP] = (s[i] >> 16) & 0xff;
  2546.       dst[i][GCOMP] = (s[i] >>  8) & 0xff;
  2547.       dst[i][BCOMP] = (s[i]      ) & 0xff;
  2548.       dst[i][ACOMP] = (s[i] >> 24);
  2549.    }
  2550. }
  2551.  
  2552. static void
  2553. unpack_ubyte_ARGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
  2554. {
  2555.    const GLuint *s = ((const GLuint *) src);
  2556.    GLuint i;
  2557.    for (i = 0; i < n; i++) {
  2558.       dst[i][RCOMP] = (s[i] >>  8) & 0xff;
  2559.       dst[i][GCOMP] = (s[i] >> 16) & 0xff;
  2560.       dst[i][BCOMP] = (s[i] >> 24);
  2561.       dst[i][ACOMP] = (s[i]      ) & 0xff;
  2562.    }
  2563. }
  2564.  
  2565. static void
  2566. unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
  2567. {
  2568.    const GLuint *s = ((const GLuint *) src);
  2569.    GLuint i;
  2570.    for (i = 0; i < n; i++) {
  2571.       dst[i][RCOMP] = (s[i] >> 24);
  2572.       dst[i][GCOMP] = (s[i] >> 16) & 0xff;
  2573.       dst[i][BCOMP] = (s[i] >>  8) & 0xff;
  2574.       dst[i][ACOMP] = 0xff;
  2575.    }
  2576. }
  2577.  
  2578. static void
  2579. unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
  2580. {
  2581.    const GLuint *s = ((const GLuint *) src);
  2582.    GLuint i;
  2583.    for (i = 0; i < n; i++) {
  2584.       dst[i][RCOMP] = (s[i]      ) & 0xff;
  2585.       dst[i][GCOMP] = (s[i] >>  8) & 0xff;
  2586.       dst[i][BCOMP] = (s[i] >> 16) & 0xff;
  2587.       dst[i][ACOMP] = 0xff;
  2588.    }
  2589. }
  2590.  
  2591. static void
  2592. unpack_ubyte_XRGB8888(const void *src, GLubyte dst[][4], GLuint n)
  2593. {
  2594.    const GLuint *s = ((const GLuint *) src);
  2595.    GLuint i;
  2596.    for (i = 0; i < n; i++) {
  2597.       dst[i][RCOMP] = (s[i] >> 16) & 0xff;
  2598.       dst[i][GCOMP] = (s[i] >>  8) & 0xff;
  2599.       dst[i][BCOMP] = (s[i]      ) & 0xff;
  2600.       dst[i][ACOMP] = 0xff;
  2601.    }
  2602. }
  2603.  
  2604. static void
  2605. unpack_ubyte_XRGB8888_REV(const void *src, GLubyte dst[][4], GLuint n)
  2606. {
  2607.    const GLuint *s = ((const GLuint *) src);
  2608.    GLuint i;
  2609.    for (i = 0; i < n; i++) {
  2610.       dst[i][RCOMP] = (s[i] >>  8) & 0xff;
  2611.       dst[i][GCOMP] = (s[i] >> 16) & 0xff;
  2612.       dst[i][BCOMP] = (s[i] >> 24);
  2613.       dst[i][ACOMP] = 0xff;
  2614.    }
  2615. }
  2616.  
  2617. static void
  2618. unpack_ubyte_RGB888(const void *src, GLubyte dst[][4], GLuint n)
  2619. {
  2620.    const GLubyte *s = (const GLubyte *) src;
  2621.    GLuint i;
  2622.    for (i = 0; i < n; i++) {
  2623.       dst[i][RCOMP] = s[i*3+2];
  2624.       dst[i][GCOMP] = s[i*3+1];
  2625.       dst[i][BCOMP] = s[i*3+0];
  2626.       dst[i][ACOMP] = 0xff;
  2627.    }
  2628. }
  2629.  
  2630. static void
  2631. unpack_ubyte_BGR888(const void *src, GLubyte dst[][4], GLuint n)
  2632. {
  2633.    const GLubyte *s = (const GLubyte *) src;
  2634.    GLuint i;
  2635.    for (i = 0; i < n; i++) {
  2636.       dst[i][RCOMP] = s[i*3+0];
  2637.       dst[i][GCOMP] = s[i*3+1];
  2638.       dst[i][BCOMP] = s[i*3+2];
  2639.       dst[i][ACOMP] = 0xff;
  2640.    }
  2641. }
  2642.  
  2643. static void
  2644. unpack_ubyte_RGB565(const void *src, GLubyte dst[][4], GLuint n)
  2645. {
  2646.    const GLushort *s = ((const GLushort *) src);
  2647.    GLuint i;
  2648.    for (i = 0; i < n; i++) {
  2649.       dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
  2650.       dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
  2651.       dst[i][BCOMP] = EXPAND_5_8( s[i]        & 0x1f);
  2652.       dst[i][ACOMP] = 0xff;
  2653.    }
  2654. }
  2655.  
  2656. static void
  2657. unpack_ubyte_RGB565_REV(const void *src, GLubyte dst[][4], GLuint n)
  2658. {
  2659.    const GLushort *s = ((const GLushort *) src);
  2660.    GLuint i;
  2661.    for (i = 0; i < n; i++) {
  2662.       GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
  2663.       dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
  2664.       dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
  2665.       dst[i][BCOMP] = EXPAND_5_8( t        & 0x1f);
  2666.       dst[i][ACOMP] = 0xff;
  2667.    }
  2668. }
  2669.  
  2670. static void
  2671. unpack_ubyte_ARGB4444(const void *src, GLubyte dst[][4], GLuint n)
  2672. {
  2673.    const GLushort *s = ((const GLushort *) src);
  2674.    GLuint i;
  2675.    for (i = 0; i < n; i++) {
  2676.       dst[i][RCOMP] = EXPAND_4_8((s[i] >>  8) & 0xf);
  2677.       dst[i][GCOMP] = EXPAND_4_8((s[i] >>  4) & 0xf);
  2678.       dst[i][BCOMP] = EXPAND_4_8((s[i]      ) & 0xf);
  2679.       dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
  2680.    }
  2681. }
  2682.  
  2683. static void
  2684. unpack_ubyte_ARGB4444_REV(const void *src, GLubyte dst[][4], GLuint n)
  2685. {
  2686.    const GLushort *s = ((const GLushort *) src);
  2687.    GLuint i;
  2688.    for (i = 0; i < n; i++) {
  2689.       dst[i][RCOMP] = EXPAND_4_8((s[i]      ) & 0xf);
  2690.       dst[i][GCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
  2691.       dst[i][BCOMP] = EXPAND_4_8((s[i] >>  8) & 0xf);
  2692.       dst[i][ACOMP] = EXPAND_4_8((s[i] >>  4) & 0xf);
  2693.    }
  2694. }
  2695.  
  2696. static void
  2697. unpack_ubyte_RGBA5551(const void *src, GLubyte dst[][4], GLuint n)
  2698. {
  2699.    const GLushort *s = ((const GLushort *) src);
  2700.    GLuint i;
  2701.    for (i = 0; i < n; i++) {
  2702.       dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
  2703.       dst[i][GCOMP] = EXPAND_5_8((s[i] >>  6) & 0x1f);
  2704.       dst[i][BCOMP] = EXPAND_5_8((s[i] >>  1) & 0x1f);
  2705.       dst[i][ACOMP] = EXPAND_1_8((s[i]      ) & 0x01);
  2706.    }
  2707. }
  2708.  
  2709. static void
  2710. unpack_ubyte_ARGB1555(const void *src, GLubyte dst[][4], GLuint n)
  2711. {
  2712.    const GLushort *s = ((const GLushort *) src);
  2713.    GLuint i;
  2714.    for (i = 0; i < n; i++) {
  2715.       dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
  2716.       dst[i][GCOMP] = EXPAND_5_8((s[i] >>  5) & 0x1f);
  2717.       dst[i][BCOMP] = EXPAND_5_8((s[i] >>  0) & 0x1f);
  2718.       dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
  2719.    }
  2720. }
  2721.  
  2722. static void
  2723. unpack_ubyte_ARGB1555_REV(const void *src, GLubyte dst[][4], GLuint n)
  2724. {
  2725.    const GLushort *s = ((const GLushort *) src);
  2726.    GLuint i;
  2727.    for (i = 0; i < n; i++) {
  2728.       GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
  2729.       dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
  2730.       dst[i][GCOMP] = EXPAND_5_8((tmp >>  5) & 0x1f);
  2731.       dst[i][BCOMP] = EXPAND_5_8((tmp >>  0) & 0x1f);
  2732.       dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
  2733.    }
  2734. }
  2735.  
  2736. static void
  2737. unpack_ubyte_AL44(const void *src, GLubyte dst[][4], GLuint n)
  2738. {
  2739.    const GLubyte *s = ((const GLubyte *) src);
  2740.    GLuint i;
  2741.    for (i = 0; i < n; i++) {
  2742.       dst[i][RCOMP] =
  2743.       dst[i][GCOMP] =
  2744.       dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
  2745.       dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
  2746.    }
  2747. }
  2748.  
  2749. static void
  2750. unpack_ubyte_AL88(const void *src, GLubyte dst[][4], GLuint n)
  2751. {
  2752.    const GLushort *s = ((const GLushort *) src);
  2753.    GLuint i;
  2754.    for (i = 0; i < n; i++) {
  2755.       dst[i][RCOMP] =
  2756.       dst[i][GCOMP] =
  2757.       dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
  2758.       dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
  2759.    }
  2760. }
  2761.  
  2762. static void
  2763. unpack_ubyte_AL88_REV(const void *src, GLubyte dst[][4], GLuint n)
  2764. {
  2765.    const GLushort *s = ((const GLushort *) src);
  2766.    GLuint i;
  2767.    for (i = 0; i < n; i++) {
  2768.       dst[i][RCOMP] =
  2769.       dst[i][GCOMP] =
  2770.       dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
  2771.       dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
  2772.    }
  2773. }
  2774.  
  2775. static void
  2776. unpack_ubyte_RGB332(const void *src, GLubyte dst[][4], GLuint n)
  2777. {
  2778.    const GLubyte *s = ((const GLubyte *) src);
  2779.    GLuint i;
  2780.    for (i = 0; i < n; i++) {
  2781.       dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
  2782.       dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
  2783.       dst[i][BCOMP] = EXPAND_2_8((s[i]     ) & 0x3);
  2784.       dst[i][ACOMP] = 0xff;
  2785.    }
  2786. }
  2787.  
  2788. static void
  2789. unpack_ubyte_A8(const void *src, GLubyte dst[][4], GLuint n)
  2790. {
  2791.    const GLubyte *s = ((const GLubyte *) src);
  2792.    GLuint i;
  2793.    for (i = 0; i < n; i++) {
  2794.       dst[i][RCOMP] =
  2795.       dst[i][GCOMP] =
  2796.       dst[i][BCOMP] = 0;
  2797.       dst[i][ACOMP] = s[i];
  2798.    }
  2799. }
  2800.  
  2801. static void
  2802. unpack_ubyte_L8(const void *src, GLubyte dst[][4], GLuint n)
  2803. {
  2804.    const GLubyte *s = ((const GLubyte *) src);
  2805.    GLuint i;
  2806.    for (i = 0; i < n; i++) {
  2807.       dst[i][RCOMP] =
  2808.       dst[i][GCOMP] =
  2809.       dst[i][BCOMP] = s[i];
  2810.       dst[i][ACOMP] = 0xff;
  2811.    }
  2812. }
  2813.  
  2814.  
  2815. static void
  2816. unpack_ubyte_I8(const void *src, GLubyte dst[][4], GLuint n)
  2817. {
  2818.    const GLubyte *s = ((const GLubyte *) src);
  2819.    GLuint i;
  2820.    for (i = 0; i < n; i++) {
  2821.       dst[i][RCOMP] =
  2822.       dst[i][GCOMP] =
  2823.       dst[i][BCOMP] =
  2824.       dst[i][ACOMP] = s[i];
  2825.    }
  2826. }
  2827.  
  2828. static void
  2829. unpack_ubyte_R8(const void *src, GLubyte dst[][4], GLuint n)
  2830. {
  2831.    const GLubyte *s = ((const GLubyte *) src);
  2832.    GLuint i;
  2833.    for (i = 0; i < n; i++) {
  2834.       dst[i][0] = s[i];
  2835.       dst[i][1] =
  2836.       dst[i][2] = 0;
  2837.       dst[i][3] = 0xff;
  2838.    }
  2839. }
  2840.  
  2841. static void
  2842. unpack_ubyte_GR88(const void *src, GLubyte dst[][4], GLuint n)
  2843. {
  2844.    const GLushort *s = ((const GLushort *) src);
  2845.    GLuint i;
  2846.    for (i = 0; i < n; i++) {
  2847.       dst[i][RCOMP] = s[i] & 0xff;
  2848.       dst[i][GCOMP] = s[i] >> 8;
  2849.       dst[i][BCOMP] = 0;
  2850.       dst[i][ACOMP] = 0xff;
  2851.    }
  2852. }
  2853.  
  2854. static void
  2855. unpack_ubyte_RG88(const void *src, GLubyte dst[][4], GLuint n)
  2856. {
  2857.    const GLushort *s = ((const GLushort *) src);
  2858.    GLuint i;
  2859.    for (i = 0; i < n; i++) {
  2860.       dst[i][RCOMP] = s[i] >> 8;
  2861.       dst[i][GCOMP] = s[i] & 0xff;
  2862.       dst[i][BCOMP] = 0;
  2863.       dst[i][ACOMP] = 0xff;
  2864.    }
  2865. }
  2866.  
  2867.  
  2868. /**
  2869.  * Unpack rgba colors, returning as GLubyte values.  This should usually
  2870.  * only be used for unpacking formats that use 8 bits or less per channel.
  2871.  */
  2872. void
  2873. _mesa_unpack_ubyte_rgba_row(gl_format format, GLuint n,
  2874.                             const void *src, GLubyte dst[][4])
  2875. {
  2876.    switch (format) {
  2877.    case MESA_FORMAT_RGBA8888:
  2878.       unpack_ubyte_RGBA8888(src, dst, n);
  2879.       break;
  2880.    case MESA_FORMAT_RGBA8888_REV:
  2881.       unpack_ubyte_RGBA8888_REV(src, dst, n);
  2882.       break;
  2883.    case MESA_FORMAT_ARGB8888:
  2884.       unpack_ubyte_ARGB8888(src, dst, n);
  2885.       break;
  2886.    case MESA_FORMAT_ARGB8888_REV:
  2887.       unpack_ubyte_ARGB8888_REV(src, dst, n);
  2888.       break;
  2889.    case MESA_FORMAT_RGBX8888:
  2890.       unpack_ubyte_RGBX8888(src, dst, n);
  2891.       break;
  2892.    case MESA_FORMAT_RGBX8888_REV:
  2893.       unpack_ubyte_RGBX8888_REV(src, dst, n);
  2894.       break;
  2895.    case MESA_FORMAT_XRGB8888:
  2896.       unpack_ubyte_XRGB8888(src, dst, n);
  2897.       break;
  2898.    case MESA_FORMAT_XRGB8888_REV:
  2899.       unpack_ubyte_XRGB8888_REV(src, dst, n);
  2900.       break;
  2901.    case MESA_FORMAT_RGB888:
  2902.       unpack_ubyte_RGB888(src, dst, n);
  2903.       break;
  2904.    case MESA_FORMAT_BGR888:
  2905.       unpack_ubyte_BGR888(src, dst, n);
  2906.       break;
  2907.    case MESA_FORMAT_RGB565:
  2908.       unpack_ubyte_RGB565(src, dst, n);
  2909.       break;
  2910.    case MESA_FORMAT_RGB565_REV:
  2911.       unpack_ubyte_RGB565_REV(src, dst, n);
  2912.       break;
  2913.    case MESA_FORMAT_ARGB4444:
  2914.       unpack_ubyte_ARGB4444(src, dst, n);
  2915.       break;
  2916.    case MESA_FORMAT_ARGB4444_REV:
  2917.       unpack_ubyte_ARGB4444_REV(src, dst, n);
  2918.       break;
  2919.    case MESA_FORMAT_RGBA5551:
  2920.       unpack_ubyte_RGBA5551(src, dst, n);
  2921.       break;
  2922.    case MESA_FORMAT_ARGB1555:
  2923.       unpack_ubyte_ARGB1555(src, dst, n);
  2924.       break;
  2925.    case MESA_FORMAT_ARGB1555_REV:
  2926.       unpack_ubyte_ARGB1555_REV(src, dst, n);
  2927.       break;
  2928.    case MESA_FORMAT_AL44:
  2929.       unpack_ubyte_AL44(src, dst, n);
  2930.       break;
  2931.    case MESA_FORMAT_AL88:
  2932.       unpack_ubyte_AL88(src, dst, n);
  2933.       break;
  2934.    case MESA_FORMAT_AL88_REV:
  2935.       unpack_ubyte_AL88_REV(src, dst, n);
  2936.       break;
  2937.    case MESA_FORMAT_RGB332:
  2938.       unpack_ubyte_RGB332(src, dst, n);
  2939.       break;
  2940.    case MESA_FORMAT_A8:
  2941.       unpack_ubyte_A8(src, dst, n);
  2942.       break;
  2943.    case MESA_FORMAT_L8:
  2944.       unpack_ubyte_L8(src, dst, n);
  2945.       break;
  2946.    case MESA_FORMAT_I8:
  2947.       unpack_ubyte_I8(src, dst, n);
  2948.       break;
  2949.    case MESA_FORMAT_R8:
  2950.       unpack_ubyte_R8(src, dst, n);
  2951.       break;
  2952.    case MESA_FORMAT_GR88:
  2953.       unpack_ubyte_GR88(src, dst, n);
  2954.       break;
  2955.    case MESA_FORMAT_RG88:
  2956.       unpack_ubyte_RG88(src, dst, n);
  2957.       break;
  2958.    default:
  2959.       /* get float values, convert to ubyte */
  2960.       {
  2961.          GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
  2962.          if (tmp) {
  2963.             GLuint i;
  2964.             _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
  2965.             for (i = 0; i < n; i++) {
  2966.                UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
  2967.                UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
  2968.                UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
  2969.                UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
  2970.             }
  2971.             free(tmp);
  2972.          }
  2973.       }
  2974.       break;
  2975.    }
  2976. }
  2977.  
  2978.  
  2979. /**********************************************************************/
  2980. /*  Unpack, returning GLuint colors                                   */
  2981. /**********************************************************************/
  2982.  
  2983. static void
  2984. unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
  2985. {
  2986.    memcpy(dst, src, n * 4 * sizeof(GLuint));
  2987. }
  2988.  
  2989. static void
  2990. unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
  2991. {
  2992.    unsigned int i;
  2993.  
  2994.    for (i = 0; i < n; i++) {
  2995.       dst[i][0] = src[i * 4 + 0];
  2996.       dst[i][1] = src[i * 4 + 1];
  2997.       dst[i][2] = src[i * 4 + 2];
  2998.       dst[i][3] = src[i * 4 + 3];
  2999.    }
  3000. }
  3001.  
  3002. static void
  3003. unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
  3004. {
  3005.    unsigned int i;
  3006.  
  3007.    for (i = 0; i < n; i++) {
  3008.       dst[i][0] = src[i * 4 + 0];
  3009.       dst[i][1] = src[i * 4 + 1];
  3010.       dst[i][2] = src[i * 4 + 2];
  3011.       dst[i][3] = src[i * 4 + 3];
  3012.    }
  3013. }
  3014.  
  3015. static void
  3016. unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
  3017. {
  3018.    unsigned int i;
  3019.  
  3020.    for (i = 0; i < n; i++) {
  3021.       dst[i][0] = src[i * 4 + 0];
  3022.       dst[i][1] = src[i * 4 + 1];
  3023.       dst[i][2] = src[i * 4 + 2];
  3024.       dst[i][3] = src[i * 4 + 3];
  3025.    }
  3026. }
  3027.  
  3028. static void
  3029. unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
  3030. {
  3031.    unsigned int i;
  3032.  
  3033.    for (i = 0; i < n; i++) {
  3034.       dst[i][0] = src[i * 4 + 0];
  3035.       dst[i][1] = src[i * 4 + 1];
  3036.       dst[i][2] = src[i * 4 + 2];
  3037.       dst[i][3] = src[i * 4 + 3];
  3038.    }
  3039. }
  3040.  
  3041. static void
  3042. unpack_int_rgba_ARGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
  3043. {
  3044.    unsigned int i;
  3045.  
  3046.    for (i = 0; i < n; i++) {
  3047.       dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
  3048.       dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
  3049.       dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
  3050.       dst[i][ACOMP] = (GLubyte) src[i * 4 + 3];
  3051.    }
  3052. }
  3053.  
  3054. static void
  3055. unpack_int_rgba_XRGB8888(const GLbyte *src, GLuint dst[][4], GLuint n)
  3056. {
  3057.    unsigned int i;
  3058.  
  3059.    for (i = 0; i < n; i++) {
  3060.       dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
  3061.       dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
  3062.       dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
  3063.       dst[i][ACOMP] = (GLubyte) 0xff;
  3064.    }
  3065. }
  3066.  
  3067. static void
  3068. unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
  3069. {
  3070.    unsigned int i;
  3071.  
  3072.    for (i = 0; i < n; i++) {
  3073.       dst[i][0] = src[i * 3 + 0];
  3074.       dst[i][1] = src[i * 3 + 1];
  3075.       dst[i][2] = src[i * 3 + 2];
  3076.       dst[i][3] = 1;
  3077.    }
  3078. }
  3079.  
  3080. static void
  3081. unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
  3082. {
  3083.    unsigned int i;
  3084.  
  3085.    for (i = 0; i < n; i++) {
  3086.       dst[i][0] = src[i * 3 + 0];
  3087.       dst[i][1] = src[i * 3 + 1];
  3088.       dst[i][2] = src[i * 3 + 2];
  3089.       dst[i][3] = 1;
  3090.    }
  3091. }
  3092.  
  3093. static void
  3094. unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
  3095. {
  3096.    unsigned int i;
  3097.  
  3098.    for (i = 0; i < n; i++) {
  3099.       dst[i][0] = src[i * 3 + 0];
  3100.       dst[i][1] = src[i * 3 + 1];
  3101.       dst[i][2] = src[i * 3 + 2];
  3102.       dst[i][3] = 1;
  3103.    }
  3104. }
  3105.  
  3106. static void
  3107. unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
  3108. {
  3109.    unsigned int i;
  3110.  
  3111.    for (i = 0; i < n; i++) {
  3112.       dst[i][0] = src[i * 3 + 0];
  3113.       dst[i][1] = src[i * 3 + 1];
  3114.       dst[i][2] = src[i * 3 + 2];
  3115.       dst[i][3] = 1;
  3116.    }
  3117. }
  3118.  
  3119. static void
  3120. unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
  3121. {
  3122.    unsigned int i;
  3123.  
  3124.    for (i = 0; i < n; i++) {
  3125.       dst[i][0] = src[i * 3 + 0];
  3126.       dst[i][1] = src[i * 3 + 1];
  3127.       dst[i][2] = src[i * 3 + 2];
  3128.       dst[i][3] = 1;
  3129.    }
  3130. }
  3131.  
  3132. static void
  3133. unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
  3134. {
  3135.    unsigned int i;
  3136.  
  3137.    for (i = 0; i < n; i++) {
  3138.       dst[i][0] = src[i * 2 + 0];
  3139.       dst[i][1] = src[i * 2 + 1];
  3140.       dst[i][2] = 0;
  3141.       dst[i][3] = 1;
  3142.    }
  3143. }
  3144.  
  3145. static void
  3146. unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
  3147. {
  3148.    unsigned int i;
  3149.  
  3150.    for (i = 0; i < n; i++) {
  3151.       dst[i][0] = src[i * 2 + 0];
  3152.       dst[i][1] = src[i * 2 + 1];
  3153.       dst[i][2] = 0;
  3154.       dst[i][3] = 1;
  3155.    }
  3156. }
  3157.  
  3158. static void
  3159. unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
  3160. {
  3161.    unsigned int i;
  3162.  
  3163.    for (i = 0; i < n; i++) {
  3164.       dst[i][0] = src[i * 2 + 0];
  3165.       dst[i][1] = src[i * 2 + 1];
  3166.       dst[i][2] = 0;
  3167.       dst[i][3] = 1;
  3168.    }
  3169. }
  3170.  
  3171. static void
  3172. unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
  3173. {
  3174.    unsigned int i;
  3175.  
  3176.    for (i = 0; i < n; i++) {
  3177.       dst[i][0] = src[i * 2 + 0];
  3178.       dst[i][1] = src[i * 2 + 1];
  3179.       dst[i][2] = 0;
  3180.       dst[i][3] = 1;
  3181.    }
  3182. }
  3183.  
  3184. static void
  3185. unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
  3186. {
  3187.    unsigned int i;
  3188.  
  3189.    for (i = 0; i < n; i++) {
  3190.       dst[i][0] = src[i * 2 + 0];
  3191.       dst[i][1] = src[i * 2 + 1];
  3192.       dst[i][2] = 0;
  3193.       dst[i][3] = 1;
  3194.    }
  3195. }
  3196.  
  3197. static void
  3198. unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
  3199. {
  3200.    unsigned int i;
  3201.  
  3202.    for (i = 0; i < n; i++) {
  3203.       dst[i][0] = src[i];
  3204.       dst[i][1] = 0;
  3205.       dst[i][2] = 0;
  3206.       dst[i][3] = 1;
  3207.    }
  3208. }
  3209.  
  3210. static void
  3211. unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
  3212. {
  3213.    unsigned int i;
  3214.  
  3215.    for (i = 0; i < n; i++) {
  3216.       dst[i][0] = src[i];
  3217.       dst[i][1] = 0;
  3218.       dst[i][2] = 0;
  3219.       dst[i][3] = 1;
  3220.    }
  3221. }
  3222.  
  3223. static void
  3224. unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
  3225. {
  3226.    unsigned int i;
  3227.  
  3228.    for (i = 0; i < n; i++) {
  3229.       dst[i][0] = src[i];
  3230.       dst[i][1] = 0;
  3231.       dst[i][2] = 0;
  3232.       dst[i][3] = 1;
  3233.    }
  3234. }
  3235.  
  3236. static void
  3237. unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
  3238. {
  3239.    unsigned int i;
  3240.  
  3241.    for (i = 0; i < n; i++) {
  3242.       dst[i][0] = src[i];
  3243.       dst[i][1] = 0;
  3244.       dst[i][2] = 0;
  3245.       dst[i][3] = 1;
  3246.    }
  3247. }
  3248.  
  3249. static void
  3250. unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
  3251. {
  3252.    unsigned int i;
  3253.  
  3254.    for (i = 0; i < n; i++) {
  3255.       dst[i][0] = src[i];
  3256.       dst[i][1] = 0;
  3257.       dst[i][2] = 0;
  3258.       dst[i][3] = 1;
  3259.    }
  3260. }
  3261.  
  3262. static void
  3263. unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
  3264. {
  3265.    unsigned int i;
  3266.  
  3267.    for (i = 0; i < n; i++) {
  3268.       dst[i][0] = dst[i][1] = dst[i][2] = 0;
  3269.       dst[i][3] = src[i];
  3270.    }
  3271. }
  3272.  
  3273. static void
  3274. unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
  3275. {
  3276.    unsigned int i;
  3277.  
  3278.    for (i = 0; i < n; i++) {
  3279.       dst[i][0] = dst[i][1] = dst[i][2] = 0;
  3280.       dst[i][3] = src[i];
  3281.    }
  3282. }
  3283.  
  3284. static void
  3285. unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
  3286. {
  3287.    unsigned int i;
  3288.  
  3289.    for (i = 0; i < n; i++) {
  3290.       dst[i][0] = dst[i][1] = dst[i][2] = 0;
  3291.       dst[i][3] = src[i];
  3292.    }
  3293. }
  3294.  
  3295. static void
  3296. unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
  3297. {
  3298.    unsigned int i;
  3299.  
  3300.    for (i = 0; i < n; i++) {
  3301.       dst[i][0] = dst[i][1] = dst[i][2] = 0;
  3302.       dst[i][3] = src[i];
  3303.    }
  3304. }
  3305.  
  3306. static void
  3307. unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
  3308. {
  3309.    unsigned int i;
  3310.  
  3311.    for (i = 0; i < n; i++) {
  3312.       dst[i][0] = dst[i][1] = dst[i][2] = 0;
  3313.       dst[i][3] = src[i];
  3314.    }
  3315. }
  3316.  
  3317. static void
  3318. unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
  3319. {
  3320.    unsigned int i;
  3321.  
  3322.    for (i = 0; i < n; i++) {
  3323.       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
  3324.       dst[i][3] = 1;
  3325.    }
  3326. }
  3327.  
  3328. static void
  3329. unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
  3330. {
  3331.    unsigned int i;
  3332.  
  3333.    for (i = 0; i < n; i++) {
  3334.       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
  3335.       dst[i][3] = 1;
  3336.    }
  3337. }
  3338.  
  3339. static void
  3340. unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
  3341. {
  3342.    unsigned int i;
  3343.  
  3344.    for (i = 0; i < n; i++) {
  3345.       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
  3346.       dst[i][3] = 1;
  3347.    }
  3348. }
  3349.  
  3350. static void
  3351. unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
  3352. {
  3353.    unsigned int i;
  3354.  
  3355.    for (i = 0; i < n; i++) {
  3356.       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
  3357.       dst[i][3] = 1;
  3358.    }
  3359. }
  3360.  
  3361. static void
  3362. unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
  3363. {
  3364.    unsigned int i;
  3365.  
  3366.    for (i = 0; i < n; i++) {
  3367.       dst[i][0] = dst[i][1] = dst[i][2] = src[i];
  3368.       dst[i][3] = 1;
  3369.    }
  3370. }
  3371.  
  3372.  
  3373. static void
  3374. unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
  3375. {
  3376.    unsigned int i;
  3377.  
  3378.    for (i = 0; i < n; i++) {
  3379.       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
  3380.       dst[i][3] = src[i * 2 + 1];
  3381.    }
  3382. }
  3383.  
  3384. static void
  3385. unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
  3386. {
  3387.    unsigned int i;
  3388.  
  3389.    for (i = 0; i < n; i++) {
  3390.       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
  3391.       dst[i][3] = src[i * 2 + 1];
  3392.    }
  3393. }
  3394.  
  3395. static void
  3396. unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
  3397. {
  3398.    unsigned int i;
  3399.  
  3400.    for (i = 0; i < n; i++) {
  3401.       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
  3402.       dst[i][3] = src[i * 2 + 1];
  3403.    }
  3404. }
  3405.  
  3406. static void
  3407. unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
  3408. {
  3409.    unsigned int i;
  3410.  
  3411.    for (i = 0; i < n; i++) {
  3412.       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
  3413.       dst[i][3] = src[i * 2 + 1];
  3414.    }
  3415. }
  3416.  
  3417. static void
  3418. unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
  3419. {
  3420.    unsigned int i;
  3421.  
  3422.    for (i = 0; i < n; i++) {
  3423.       dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
  3424.       dst[i][3] = src[i * 2 + 1];
  3425.    }
  3426. }
  3427.  
  3428. static void
  3429. unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
  3430. {
  3431.    unsigned int i;
  3432.  
  3433.    for (i = 0; i < n; i++) {
  3434.       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
  3435.    }
  3436. }
  3437.  
  3438. static void
  3439. unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
  3440. {
  3441.    unsigned int i;
  3442.  
  3443.    for (i = 0; i < n; i++) {
  3444.       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
  3445.    }
  3446. }
  3447.  
  3448. static void
  3449. unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
  3450. {
  3451.    unsigned int i;
  3452.  
  3453.    for (i = 0; i < n; i++) {
  3454.       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
  3455.    }
  3456. }
  3457.  
  3458. static void
  3459. unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
  3460. {
  3461.    unsigned int i;
  3462.  
  3463.    for (i = 0; i < n; i++) {
  3464.       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
  3465.    }
  3466. }
  3467.  
  3468. static void
  3469. unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
  3470. {
  3471.    unsigned int i;
  3472.  
  3473.    for (i = 0; i < n; i++) {
  3474.       dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
  3475.    }
  3476. }
  3477.  
  3478. static void
  3479. unpack_int_rgba_ARGB2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
  3480. {
  3481.    unsigned int i;
  3482.  
  3483.    for (i = 0; i < n; i++) {
  3484.       GLuint tmp = src[i];
  3485.       dst[i][0] = (tmp >> 20) & 0x3ff;
  3486.       dst[i][1] = (tmp >> 10) & 0x3ff;
  3487.       dst[i][2] = (tmp >> 0) & 0x3ff;
  3488.       dst[i][3] = (tmp >> 30) & 0x3;
  3489.    }
  3490. }
  3491.  
  3492. static void
  3493. unpack_int_rgba_ABGR2101010_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
  3494. {
  3495.    unsigned int i;
  3496.  
  3497.    for (i = 0; i < n; i++) {
  3498.       GLuint tmp = src[i];
  3499.       dst[i][0] = (tmp >> 0) & 0x3ff;
  3500.       dst[i][1] = (tmp >> 10) & 0x3ff;
  3501.       dst[i][2] = (tmp >> 20) & 0x3ff;
  3502.       dst[i][3] = (tmp >> 30) & 0x3;
  3503.    }
  3504. }
  3505.  
  3506. static void
  3507. unpack_int_rgba_ARGB2101010(const GLuint *src, GLuint dst[][4], GLuint n)
  3508. {
  3509.    unsigned int i;
  3510.  
  3511.    for (i = 0; i < n; i++) {
  3512.       GLuint tmp = src[i];
  3513.       dst[i][0] = (tmp >> 20) & 0x3ff;
  3514.       dst[i][1] = (tmp >> 10) & 0x3ff;
  3515.       dst[i][2] = (tmp >> 0) & 0x3ff;
  3516.       dst[i][3] = (tmp >> 30) & 0x3;
  3517.    }
  3518. }
  3519.  
  3520. static void
  3521. unpack_int_rgba_XBGR8888_UINT(const GLubyte *src, GLuint dst[][4], GLuint n)
  3522. {
  3523.    unsigned int i;
  3524.  
  3525.    for (i = 0; i < n; i++) {
  3526.       dst[i][0] = src[i * 4 + 0];
  3527.       dst[i][1] = src[i * 4 + 1];
  3528.       dst[i][2] = src[i * 4 + 2];
  3529.       dst[i][3] = 1;
  3530.    }
  3531. }
  3532.  
  3533. static void
  3534. unpack_int_rgba_XBGR8888_SINT(const GLbyte *src, GLuint dst[][4], GLuint n)
  3535. {
  3536.    unsigned int i;
  3537.  
  3538.    for (i = 0; i < n; i++) {
  3539.       dst[i][0] = src[i * 4 + 0];
  3540.       dst[i][1] = src[i * 4 + 1];
  3541.       dst[i][2] = src[i * 4 + 2];
  3542.       dst[i][3] = 1;
  3543.    }
  3544. }
  3545.  
  3546. static void
  3547. unpack_int_rgba_XBGR16161616_UINT(const GLushort *src, GLuint dst[][4], GLuint n)
  3548. {
  3549.    unsigned int i;
  3550.  
  3551.    for (i = 0; i < n; i++) {
  3552.       dst[i][0] = src[i * 4 + 0];
  3553.       dst[i][1] = src[i * 4 + 1];
  3554.       dst[i][2] = src[i * 4 + 2];
  3555.       dst[i][3] = 1;
  3556.    }
  3557. }
  3558.  
  3559. static void
  3560. unpack_int_rgba_XBGR16161616_SINT(const GLshort *src, GLuint dst[][4], GLuint n)
  3561. {
  3562.    unsigned int i;
  3563.  
  3564.    for (i = 0; i < n; i++) {
  3565.       dst[i][0] = src[i * 4 + 0];
  3566.       dst[i][1] = src[i * 4 + 1];
  3567.       dst[i][2] = src[i * 4 + 2];
  3568.       dst[i][3] = 1;
  3569.    }
  3570. }
  3571.  
  3572. static void
  3573. unpack_int_rgba_XBGR32323232_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
  3574. {
  3575.    unsigned int i;
  3576.  
  3577.    for (i = 0; i < n; i++) {
  3578.       dst[i][0] = src[i * 4 + 0];
  3579.       dst[i][1] = src[i * 4 + 1];
  3580.       dst[i][2] = src[i * 4 + 2];
  3581.       dst[i][3] = 1;
  3582.    }
  3583. }
  3584.  
  3585. void
  3586. _mesa_unpack_uint_rgba_row(gl_format format, GLuint n,
  3587.                            const void *src, GLuint dst[][4])
  3588. {
  3589.    switch (format) {
  3590.       /* Since there won't be any sign extension happening, there's no need to
  3591.        * make separate paths for 32-bit-to-32-bit integer unpack.
  3592.        */
  3593.    case MESA_FORMAT_RGBA_UINT32:
  3594.    case MESA_FORMAT_RGBA_INT32:
  3595.       unpack_int_rgba_RGBA_UINT32(src, dst, n);
  3596.       break;
  3597.  
  3598.    case MESA_FORMAT_RGBA_UINT16:
  3599.       unpack_int_rgba_RGBA_UINT16(src, dst, n);
  3600.       break;
  3601.    case MESA_FORMAT_RGBA_INT16:
  3602.       unpack_int_rgba_RGBA_INT16(src, dst, n);
  3603.       break;
  3604.  
  3605.    case MESA_FORMAT_RGBA_UINT8:
  3606.       unpack_int_rgba_RGBA_UINT8(src, dst, n);
  3607.       break;
  3608.    case MESA_FORMAT_RGBA_INT8:
  3609.       unpack_int_rgba_RGBA_INT8(src, dst, n);
  3610.       break;
  3611.  
  3612.    case MESA_FORMAT_ARGB8888:
  3613.       unpack_int_rgba_ARGB8888(src, dst, n);
  3614.       break;
  3615.  
  3616.    case MESA_FORMAT_XRGB8888:
  3617.       unpack_int_rgba_XRGB8888(src, dst, n);
  3618.       break;
  3619.  
  3620.    case MESA_FORMAT_RGB_UINT32:
  3621.    case MESA_FORMAT_RGB_INT32:
  3622.       unpack_int_rgba_RGB_UINT32(src, dst, n);
  3623.       break;
  3624.  
  3625.    case MESA_FORMAT_RGB_UINT16:
  3626.       unpack_int_rgba_RGB_UINT16(src, dst, n);
  3627.       break;
  3628.    case MESA_FORMAT_RGB_INT16:
  3629.       unpack_int_rgba_RGB_INT16(src, dst, n);
  3630.       break;
  3631.  
  3632.    case MESA_FORMAT_RGB_UINT8:
  3633.       unpack_int_rgba_RGB_UINT8(src, dst, n);
  3634.       break;
  3635.    case MESA_FORMAT_RGB_INT8:
  3636.       unpack_int_rgba_RGB_INT8(src, dst, n);
  3637.       break;
  3638.  
  3639.    case MESA_FORMAT_RG_UINT32:
  3640.    case MESA_FORMAT_RG_INT32:
  3641.       unpack_int_rgba_RG_UINT32(src, dst, n);
  3642.       break;
  3643.  
  3644.    case MESA_FORMAT_RG_UINT16:
  3645.       unpack_int_rgba_RG_UINT16(src, dst, n);
  3646.       break;
  3647.    case MESA_FORMAT_RG_INT16:
  3648.       unpack_int_rgba_RG_INT16(src, dst, n);
  3649.       break;
  3650.  
  3651.    case MESA_FORMAT_RG_UINT8:
  3652.       unpack_int_rgba_RG_UINT8(src, dst, n);
  3653.       break;
  3654.    case MESA_FORMAT_RG_INT8:
  3655.       unpack_int_rgba_RG_INT8(src, dst, n);
  3656.       break;
  3657.  
  3658.    case MESA_FORMAT_R_UINT32:
  3659.    case MESA_FORMAT_R_INT32:
  3660.       unpack_int_rgba_R_UINT32(src, dst, n);
  3661.       break;
  3662.  
  3663.    case MESA_FORMAT_R_UINT16:
  3664.       unpack_int_rgba_R_UINT16(src, dst, n);
  3665.       break;
  3666.    case MESA_FORMAT_R_INT16:
  3667.       unpack_int_rgba_R_INT16(src, dst, n);
  3668.       break;
  3669.  
  3670.    case MESA_FORMAT_R_UINT8:
  3671.       unpack_int_rgba_R_UINT8(src, dst, n);
  3672.       break;
  3673.    case MESA_FORMAT_R_INT8:
  3674.       unpack_int_rgba_R_INT8(src, dst, n);
  3675.       break;
  3676.  
  3677.    case MESA_FORMAT_ALPHA_UINT32:
  3678.    case MESA_FORMAT_ALPHA_INT32:
  3679.       unpack_int_rgba_ALPHA_UINT32(src, dst, n);
  3680.       break;
  3681.  
  3682.    case MESA_FORMAT_ALPHA_UINT16:
  3683.       unpack_int_rgba_ALPHA_UINT16(src, dst, n);
  3684.       break;
  3685.    case MESA_FORMAT_ALPHA_INT16:
  3686.       unpack_int_rgba_ALPHA_INT16(src, dst, n);
  3687.       break;
  3688.  
  3689.    case MESA_FORMAT_ALPHA_UINT8:
  3690.       unpack_int_rgba_ALPHA_UINT8(src, dst, n);
  3691.       break;
  3692.    case MESA_FORMAT_ALPHA_INT8:
  3693.       unpack_int_rgba_ALPHA_INT8(src, dst, n);
  3694.       break;
  3695.  
  3696.    case MESA_FORMAT_LUMINANCE_UINT32:
  3697.    case MESA_FORMAT_LUMINANCE_INT32:
  3698.       unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
  3699.       break;
  3700.    case MESA_FORMAT_LUMINANCE_UINT16:
  3701.       unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
  3702.       break;
  3703.    case MESA_FORMAT_LUMINANCE_INT16:
  3704.       unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
  3705.       break;
  3706.  
  3707.    case MESA_FORMAT_LUMINANCE_UINT8:
  3708.       unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
  3709.       break;
  3710.    case MESA_FORMAT_LUMINANCE_INT8:
  3711.       unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
  3712.       break;
  3713.  
  3714.    case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
  3715.    case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
  3716.       unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
  3717.       break;
  3718.  
  3719.    case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
  3720.       unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
  3721.       break;
  3722.    case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
  3723.       unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
  3724.       break;
  3725.  
  3726.    case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
  3727.       unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
  3728.       break;
  3729.    case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
  3730.       unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
  3731.       break;
  3732.  
  3733.    case MESA_FORMAT_INTENSITY_UINT32:
  3734.    case MESA_FORMAT_INTENSITY_INT32:
  3735.       unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
  3736.       break;
  3737.  
  3738.    case MESA_FORMAT_INTENSITY_UINT16:
  3739.       unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
  3740.       break;
  3741.    case MESA_FORMAT_INTENSITY_INT16:
  3742.       unpack_int_rgba_INTENSITY_INT16(src, dst, n);
  3743.       break;
  3744.  
  3745.    case MESA_FORMAT_INTENSITY_UINT8:
  3746.       unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
  3747.       break;
  3748.    case MESA_FORMAT_INTENSITY_INT8:
  3749.       unpack_int_rgba_INTENSITY_INT8(src, dst, n);
  3750.       break;
  3751.  
  3752.    case MESA_FORMAT_ARGB2101010_UINT:
  3753.       unpack_int_rgba_ARGB2101010_UINT(src, dst, n);
  3754.       break;
  3755.  
  3756.    case MESA_FORMAT_ABGR2101010_UINT:
  3757.       unpack_int_rgba_ABGR2101010_UINT(src, dst, n);
  3758.       break;
  3759.  
  3760.    case MESA_FORMAT_ARGB2101010:
  3761.       unpack_int_rgba_ARGB2101010(src, dst, n);
  3762.       break;
  3763.  
  3764.    case MESA_FORMAT_XBGR8888_UINT:
  3765.       unpack_int_rgba_XBGR8888_UINT(src, dst, n);
  3766.       break;
  3767.  
  3768.    case MESA_FORMAT_XBGR8888_SINT:
  3769.       unpack_int_rgba_XBGR8888_SINT(src, dst, n);
  3770.       break;
  3771.  
  3772.    case MESA_FORMAT_XBGR16161616_UINT:
  3773.       unpack_int_rgba_XBGR16161616_UINT(src, dst, n);
  3774.       break;
  3775.  
  3776.    case MESA_FORMAT_XBGR16161616_SINT:
  3777.       unpack_int_rgba_XBGR16161616_SINT(src, dst, n);
  3778.       break;
  3779.  
  3780.    case MESA_FORMAT_XBGR32323232_UINT:
  3781.    case MESA_FORMAT_XBGR32323232_SINT:
  3782.       unpack_int_rgba_XBGR32323232_UINT(src, dst, n);
  3783.       break;
  3784.  
  3785.    default:
  3786.       _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
  3787.                     _mesa_get_format_name(format));
  3788.       return;
  3789.    }
  3790. }
  3791.  
  3792. /**
  3793.  * Unpack a 2D rect of pixels returning float RGBA colors.
  3794.  * \param format  the source image format
  3795.  * \param src  start address of the source image
  3796.  * \param srcRowStride  source image row stride in bytes
  3797.  * \param dst  start address of the dest image
  3798.  * \param dstRowStride  dest image row stride in bytes
  3799.  * \param x  source image start X pos
  3800.  * \param y  source image start Y pos
  3801.  * \param width  width of rect region to convert
  3802.  * \param height  height of rect region to convert
  3803.  */
  3804. void
  3805. _mesa_unpack_rgba_block(gl_format format,
  3806.                         const void *src, GLint srcRowStride,
  3807.                         GLfloat dst[][4], GLint dstRowStride,
  3808.                         GLuint x, GLuint y, GLuint width, GLuint height)
  3809. {
  3810.    unpack_rgba_func unpack = get_unpack_rgba_function(format);
  3811.    const GLuint srcPixStride = _mesa_get_format_bytes(format);
  3812.    const GLuint dstPixStride = 4 * sizeof(GLfloat);
  3813.    const GLubyte *srcRow;
  3814.    GLubyte *dstRow;
  3815.    GLuint i;
  3816.  
  3817.    /* XXX needs to be fixed for compressed formats */
  3818.  
  3819.    srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
  3820.    dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;
  3821.  
  3822.    for (i = 0; i < height; i++) {
  3823.       unpack(srcRow, (GLfloat (*)[4]) dstRow, width);
  3824.  
  3825.       dstRow += dstRowStride;
  3826.       srcRow += srcRowStride;
  3827.    }
  3828. }
  3829.  
  3830.  
  3831.  
  3832.  
  3833. typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);
  3834.  
  3835. static void
  3836. unpack_float_z_Z24_X8(GLuint n, const void *src, GLfloat *dst)
  3837. {
  3838.    /* only return Z, not stencil data */
  3839.    const GLuint *s = ((const GLuint *) src);
  3840.    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
  3841.    GLuint i;
  3842.    for (i = 0; i < n; i++) {
  3843.       dst[i] = (GLfloat) ((s[i] >> 8) * scale);
  3844.       ASSERT(dst[i] >= 0.0F);
  3845.       ASSERT(dst[i] <= 1.0F);
  3846.    }
  3847. }
  3848.  
  3849. static void
  3850. unpack_float_z_X8_Z24(GLuint n, const void *src, GLfloat *dst)
  3851. {
  3852.    /* only return Z, not stencil data */
  3853.    const GLuint *s = ((const GLuint *) src);
  3854.    const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
  3855.    GLuint i;
  3856.    for (i = 0; i < n; i++) {
  3857.       dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
  3858.       ASSERT(dst[i] >= 0.0F);
  3859.       ASSERT(dst[i] <= 1.0F);
  3860.    }
  3861. }
  3862.  
  3863. static void
  3864. unpack_float_z_Z16(GLuint n, const void *src, GLfloat *dst)
  3865. {
  3866.    const GLushort *s = ((const GLushort *) src);
  3867.    GLuint i;
  3868.    for (i = 0; i < n; i++) {
  3869.       dst[i] = s[i] * (1.0F / 65535.0F);
  3870.    }
  3871. }
  3872.  
  3873. static void
  3874. unpack_float_z_Z32(GLuint n, const void *src, GLfloat *dst)
  3875. {
  3876.    const GLuint *s = ((const GLuint *) src);
  3877.    GLuint i;
  3878.    for (i = 0; i < n; i++) {
  3879.       dst[i] = s[i] * (1.0F / 0xffffffff);
  3880.    }
  3881. }
  3882.  
  3883. static void
  3884. unpack_float_z_Z32F(GLuint n, const void *src, GLfloat *dst)
  3885. {
  3886.    memcpy(dst, src, n * sizeof(float));
  3887. }
  3888.  
  3889. static void
  3890. unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
  3891. {
  3892.    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
  3893.    GLuint i;
  3894.    for (i = 0; i < n; i++) {
  3895.       dst[i] = s[i].z;
  3896.    }
  3897. }
  3898.  
  3899.  
  3900.  
  3901. /**
  3902.  * Unpack Z values.
  3903.  * The returned values will always be in the range [0.0, 1.0].
  3904.  */
  3905. void
  3906. _mesa_unpack_float_z_row(gl_format format, GLuint n,
  3907.                          const void *src, GLfloat *dst)
  3908. {
  3909.    unpack_float_z_func unpack;
  3910.  
  3911.    switch (format) {
  3912.    case MESA_FORMAT_Z24_S8:
  3913.    case MESA_FORMAT_Z24_X8:
  3914.       unpack = unpack_float_z_Z24_X8;
  3915.       break;
  3916.    case MESA_FORMAT_S8_Z24:
  3917.    case MESA_FORMAT_X8_Z24:
  3918.       unpack = unpack_float_z_X8_Z24;
  3919.       break;
  3920.    case MESA_FORMAT_Z16:
  3921.       unpack = unpack_float_z_Z16;
  3922.       break;
  3923.    case MESA_FORMAT_Z32:
  3924.       unpack = unpack_float_z_Z32;
  3925.       break;
  3926.    case MESA_FORMAT_Z32_FLOAT:
  3927.       unpack = unpack_float_z_Z32F;
  3928.       break;
  3929.    case MESA_FORMAT_Z32_FLOAT_X24S8:
  3930.       unpack = unpack_float_z_Z32X24S8;
  3931.       break;
  3932.    default:
  3933.       _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
  3934.                     _mesa_get_format_name(format));
  3935.       return;
  3936.    }
  3937.  
  3938.    unpack(n, src, dst);
  3939. }
  3940.  
  3941.  
  3942.  
  3943. typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);
  3944.  
  3945. static void
  3946. unpack_uint_z_Z24_X8(const void *src, GLuint *dst, GLuint n)
  3947. {
  3948.    /* only return Z, not stencil data */
  3949.    const GLuint *s = ((const GLuint *) src);
  3950.    GLuint i;
  3951.    for (i = 0; i < n; i++) {
  3952.       dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
  3953.    }
  3954. }
  3955.  
  3956. static void
  3957. unpack_uint_z_X8_Z24(const void *src, GLuint *dst, GLuint n)
  3958. {
  3959.    /* only return Z, not stencil data */
  3960.    const GLuint *s = ((const GLuint *) src);
  3961.    GLuint i;
  3962.    for (i = 0; i < n; i++) {
  3963.       dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
  3964.    }
  3965. }
  3966.  
  3967. static void
  3968. unpack_uint_z_Z16(const void *src, GLuint *dst, GLuint n)
  3969. {
  3970.    const GLushort *s = ((const GLushort *)src);
  3971.    GLuint i;
  3972.    for (i = 0; i < n; i++) {
  3973.       dst[i] = (s[i] << 16) | s[i];
  3974.    }
  3975. }
  3976.  
  3977. static void
  3978. unpack_uint_z_Z32(const void *src, GLuint *dst, GLuint n)
  3979. {
  3980.    memcpy(dst, src, n * sizeof(GLuint));
  3981. }
  3982.  
  3983. static void
  3984. unpack_uint_z_Z32_FLOAT(const void *src, GLuint *dst, GLuint n)
  3985. {
  3986.    const float *s = (const float *)src;
  3987.    GLuint i;
  3988.    for (i = 0; i < n; i++) {
  3989.       dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
  3990.    }
  3991. }
  3992.  
  3993. static void
  3994. unpack_uint_z_Z32_FLOAT_X24S8(const void *src, GLuint *dst, GLuint n)
  3995. {
  3996.    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
  3997.    GLuint i;
  3998.  
  3999.    for (i = 0; i < n; i++) {
  4000.       dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
  4001.    }
  4002. }
  4003.  
  4004.  
  4005. /**
  4006.  * Unpack Z values.
  4007.  * The returned values will always be in the range [0, 0xffffffff].
  4008.  */
  4009. void
  4010. _mesa_unpack_uint_z_row(gl_format format, GLuint n,
  4011.                         const void *src, GLuint *dst)
  4012. {
  4013.    unpack_uint_z_func unpack;
  4014.    const GLubyte *srcPtr = (GLubyte *) src;
  4015.  
  4016.    switch (format) {
  4017.    case MESA_FORMAT_Z24_S8:
  4018.    case MESA_FORMAT_Z24_X8:
  4019.       unpack = unpack_uint_z_Z24_X8;
  4020.       break;
  4021.    case MESA_FORMAT_S8_Z24:
  4022.    case MESA_FORMAT_X8_Z24:
  4023.       unpack = unpack_uint_z_X8_Z24;
  4024.       break;
  4025.    case MESA_FORMAT_Z16:
  4026.       unpack = unpack_uint_z_Z16;
  4027.       break;
  4028.    case MESA_FORMAT_Z32:
  4029.       unpack = unpack_uint_z_Z32;
  4030.       break;
  4031.    case MESA_FORMAT_Z32_FLOAT:
  4032.       unpack = unpack_uint_z_Z32_FLOAT;
  4033.       break;
  4034.    case MESA_FORMAT_Z32_FLOAT_X24S8:
  4035.       unpack = unpack_uint_z_Z32_FLOAT_X24S8;
  4036.       break;
  4037.    default:
  4038.       _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
  4039.                     _mesa_get_format_name(format));
  4040.       return;
  4041.    }
  4042.  
  4043.    unpack(srcPtr, dst, n);
  4044. }
  4045.  
  4046.  
  4047. static void
  4048. unpack_ubyte_s_S8(const void *src, GLubyte *dst, GLuint n)
  4049. {
  4050.    memcpy(dst, src, n);
  4051. }
  4052.  
  4053. static void
  4054. unpack_ubyte_s_Z24_S8(const void *src, GLubyte *dst, GLuint n)
  4055. {
  4056.    GLuint i;
  4057.    const GLuint *src32 = src;
  4058.  
  4059.    for (i = 0; i < n; i++)
  4060.       dst[i] = src32[i] & 0xff;
  4061. }
  4062.  
  4063. static void
  4064. unpack_ubyte_s_S8_Z24(const void *src, GLubyte *dst, GLuint n)
  4065. {
  4066.    GLuint i;
  4067.    const GLuint *src32 = src;
  4068.  
  4069.    for (i = 0; i < n; i++)
  4070.       dst[i] = src32[i] >> 24;
  4071. }
  4072.  
  4073. static void
  4074. unpack_ubyte_s_Z32_FLOAT_X24S8(const void *src, GLubyte *dst, GLuint n)
  4075. {
  4076.    GLuint i;
  4077.    const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
  4078.  
  4079.    for (i = 0; i < n; i++)
  4080.       dst[i] = s[i].x24s8 & 0xff;
  4081. }
  4082.  
  4083. void
  4084. _mesa_unpack_ubyte_stencil_row(gl_format format, GLuint n,
  4085.                                const void *src, GLubyte *dst)
  4086. {
  4087.    switch (format) {
  4088.    case MESA_FORMAT_S8:
  4089.       unpack_ubyte_s_S8(src, dst, n);
  4090.       break;
  4091.    case MESA_FORMAT_Z24_S8:
  4092.       unpack_ubyte_s_Z24_S8(src, dst, n);
  4093.       break;
  4094.    case MESA_FORMAT_S8_Z24:
  4095.       unpack_ubyte_s_S8_Z24(src, dst, n);
  4096.       break;
  4097.    case MESA_FORMAT_Z32_FLOAT_X24S8:
  4098.       unpack_ubyte_s_Z32_FLOAT_X24S8(src, dst, n);
  4099.       break;
  4100.    default:
  4101.       _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
  4102.                     _mesa_get_format_name(format));
  4103.       return;
  4104.    }
  4105. }
  4106.  
  4107. static void
  4108. unpack_uint_24_8_depth_stencil_S8_Z24(const GLuint *src, GLuint *dst, GLuint n)
  4109. {
  4110.    GLuint i;
  4111.  
  4112.    for (i = 0; i < n; i++) {
  4113.       GLuint val = src[i];
  4114.       dst[i] = val >> 24 | val << 8;
  4115.    }
  4116. }
  4117.  
  4118. static void
  4119. unpack_uint_24_8_depth_stencil_Z24_S8(const GLuint *src, GLuint *dst, GLuint n)
  4120. {
  4121.    memcpy(dst, src, n * 4);
  4122. }
  4123.  
  4124. void
  4125. _mesa_unpack_uint_24_8_depth_stencil_row(gl_format format, GLuint n,
  4126.                                          const void *src, GLuint *dst)
  4127. {
  4128.    switch (format) {
  4129.    case MESA_FORMAT_Z24_S8:
  4130.       unpack_uint_24_8_depth_stencil_Z24_S8(src, dst, n);
  4131.       break;
  4132.    case MESA_FORMAT_S8_Z24:
  4133.       unpack_uint_24_8_depth_stencil_S8_Z24(src, dst, n);
  4134.       break;
  4135.    default:
  4136.       _mesa_problem(NULL,
  4137.                     "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
  4138.                     _mesa_get_format_name(format));
  4139.       return;
  4140.    }
  4141. }
  4142.