+ GLint i, GLint j, GLint k, GLchan *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ const struct gl_color_table *palette;
+ GLubyte texelUB[4];
+ GLuint index;
+ GET_CURRENT_CONTEXT(ctx);
+
+ if (ctx->Texture.SharedPalette) {
+ palette = &ctx->Texture.Palette;
+ }
+ else {
+ palette = &texImage->TexObject->Palette;
+ }
+ if (palette->Size == 0)
+ return; /* undefined results */
+
+ /* Mask the index against size of palette to avoid going out of bounds */
+ index = (*src) & (palette->Size - 1);
+
+ {
+ const GLubyte *table = palette->TableUB;
+ switch (palette->_BaseFormat) {
+ case GL_ALPHA:
+ texelUB[RCOMP] =
+ texelUB[GCOMP] =
+ texelUB[BCOMP] = 0;
+ texelUB[ACOMP] = table[index];
+ break;;
+ case GL_LUMINANCE:
+ texelUB[RCOMP] =
+ texelUB[GCOMP] =
+ texelUB[BCOMP] = table[index];
+ texelUB[ACOMP] = 255;
+ break;
+ case GL_INTENSITY:
+ texelUB[RCOMP] =
+ texelUB[GCOMP] =
+ texelUB[BCOMP] =
+ texelUB[ACOMP] = table[index];
+ break;;
+ case GL_LUMINANCE_ALPHA:
+ texelUB[RCOMP] =
+ texelUB[GCOMP] =
+ texelUB[BCOMP] = table[index * 2 + 0];
+ texelUB[ACOMP] = table[index * 2 + 1];
+ break;;
+ case GL_RGB:
+ texelUB[RCOMP] = table[index * 3 + 0];
+ texelUB[GCOMP] = table[index * 3 + 1];
+ texelUB[BCOMP] = table[index * 3 + 2];
+ texelUB[ACOMP] = 255;
+ break;;
+ case GL_RGBA:
+ texelUB[RCOMP] = table[index * 4 + 0];
+ texelUB[GCOMP] = table[index * 4 + 1];
+ texelUB[BCOMP] = table[index * 4 + 2];
+ texelUB[ACOMP] = table[index * 4 + 3];
+ break;;
+ default:
+ _mesa_problem(ctx, "Bad palette format in fetch_texel_ci8");
+ return;
+ }
+#if CHAN_TYPE == GL_UNSIGNED_BYTE
+ COPY_4UBV(texel, texelUB);
+#elif CHAN_TYPE == GL_UNSIGNED_SHORT
+ texel[0] = UBYTE_TO_USHORT(texelUB[0]);
+ texel[1] = UBYTE_TO_USHORT(texelUB[1]);
+ texel[2] = UBYTE_TO_USHORT(texelUB[2]);
+ texel[3] = UBYTE_TO_USHORT(texelUB[3]);
+#else
+ texel[0] = UBYTE_TO_FLOAT(texelUB[0]);
+ texel[1] = UBYTE_TO_FLOAT(texelUB[1]);
+ texel[2] = UBYTE_TO_FLOAT(texelUB[2]);
+ texel[3] = UBYTE_TO_FLOAT(texelUB[3]);
+#endif
+ }
+}
+
+#if DIM == 3
+static void store_texel_ci8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *index = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ *dst = *index;
+}
+#endif
+
+
+#if FEATURE_EXT_texture_sRGB
+
+/* Fetch texel from 1D, 2D or 3D srgb8 texture, return 4 GLfloats */
+static void FETCH(srgb8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+ texel[RCOMP] = nonlinear_to_linear(src[0]);
+ texel[GCOMP] = nonlinear_to_linear(src[1]);
+ texel[BCOMP] = nonlinear_to_linear(src[2]);
+ texel[ACOMP] = CHAN_MAX;
+}
+
+#if DIM == 3
+static void store_texel_srgb8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 3);
+ dst[0] = rgba[RCOMP]; /* no conversion */
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D srgba8 texture, return 4 GLfloats */
+static void FETCH(srgba8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
+ texel[RCOMP] = nonlinear_to_linear(src[0]);
+ texel[GCOMP] = nonlinear_to_linear(src[1]);
+ texel[BCOMP] = nonlinear_to_linear(src[2]);
+ texel[ACOMP] = UBYTE_TO_FLOAT(src[3]); /* linear! */
+}
+
+#if DIM == 3
+static void store_texel_srgba8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 4);
+ dst[0] = rgba[RCOMP];
+ dst[1] = rgba[GCOMP];
+ dst[2] = rgba[BCOMP];
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D sl8 texture, return 4 GLfloats */
+static void FETCH(sl8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = nonlinear_to_linear(src[0]);
+ texel[ACOMP] = CHAN_MAX;
+}
+
+#if DIM == 3
+static void store_texel_sl8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)
+{
+ const GLubyte *rgba = (const GLubyte *) texel;
+ GLubyte *dst = TEXEL_ADDR(GLubyte, texImage, i, j, k, 1);
+ dst[0] = rgba[RCOMP];
+}
+#endif
+
+/* Fetch texel from 1D, 2D or 3D sla8 texture, return 4 GLfloats */
+static void FETCH(sla8)(const struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, GLfloat *texel )
+{
+ const GLubyte *src = TEXEL_ADDR(GLubyte, texImage, i, j, k, 2);
+ texel[RCOMP] =
+ texel[GCOMP] =
+ texel[BCOMP] = nonlinear_to_linear(src[0]);
+ texel[ACOMP] = UBYTE_TO_FLOAT(src[1]); /* linear */
+}
+
+#if DIM == 3
+static void store_texel_sla8(struct gl_texture_image *texImage,
+ GLint i, GLint j, GLint k, const void *texel)