/*
* Mesa 3-D graphics library
- * Version: 6.1
*
- * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* \file texcompress_fxt1.c
- * GL_EXT_texture_compression_fxt1 support.
+ * GL_3DFX_texture_compression_FXT1 support.
*/
#include "glheader.h"
#include "imports.h"
-#include "colormac.h"
-#include "context.h"
-#include "convolve.h"
#include "image.h"
+#include "macros.h"
+#include "mipmap.h"
#include "texcompress.h"
-#include "texformat.h"
+#include "texcompress_fxt1.h"
#include "texstore.h"
-static GLint
+static void
fxt1_encode (GLuint width, GLuint height, GLint comps,
const void *source, GLint srcRowStride,
void *dest, GLint destRowStride);
/**
- * Called during context initialization.
- */
-void
-_mesa_init_texture_fxt1( GLcontext *ctx )
-{
- (void) ctx;
-}
-
-
-/**
- * Called via TexFormat->StoreImage to store an RGB_FXT1 texture.
+ * Store user's image in rgb_fxt1 format.
*/
-static GLboolean
-texstore_rgb_fxt1(STORE_PARAMS)
+GLboolean
+_mesa_texstore_rgb_fxt1(TEXSTORE_PARAMS)
{
- const GLchan *pixels;
+ const GLubyte *pixels;
GLint srcRowStride;
GLubyte *dst;
- const GLint texWidth = dstRowStride * 8 / 16; /* a bit of a hack */
- const GLchan *tempImage = NULL;
+ const GLubyte *tempImage = NULL;
- ASSERT(dstFormat == &_mesa_texformat_rgb_fxt1);
- ASSERT(dstXoffset % 8 == 0);
- ASSERT(dstYoffset % 4 == 0);
- ASSERT(dstZoffset == 0);
- (void) dstZoffset; (void) dstImageStride;
+ assert(dstFormat == MESA_FORMAT_RGB_FXT1);
if (srcFormat != GL_RGB ||
- srcType != CHAN_TYPE ||
+ srcType != GL_UNSIGNED_BYTE ||
ctx->_ImageTransferState ||
+ ALIGN(srcPacking->RowLength, srcPacking->Alignment) != srcWidth ||
srcPacking->SwapBytes) {
- /* convert image to RGB/GLchan */
- tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- dstFormat->BaseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
+ /* convert image to RGB/GLubyte */
+ GLubyte *tempImageSlices[1];
+ int rgbRowStride = 3 * srcWidth * sizeof(GLubyte);
+ tempImage = malloc(srcWidth * srcHeight * 3 * sizeof(GLubyte));
if (!tempImage)
return GL_FALSE; /* out of memory */
- _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+ tempImageSlices[0] = (GLubyte *) tempImage;
+ _mesa_texstore(ctx, dims,
+ baseInternalFormat,
+ MESA_FORMAT_RGB_UNORM8,
+ rgbRowStride, tempImageSlices,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
pixels = tempImage;
srcRowStride = 3 * srcWidth;
srcFormat = GL_RGB;
}
else {
- pixels = (const GLchan *) srcAddr;
+ pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
+ srcFormat, srcType, 0, 0);
+
srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
- srcType) / sizeof(GLchan);
+ srcType) / sizeof(GLubyte);
}
- dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- GL_COMPRESSED_RGB_FXT1_3DFX,
- texWidth, (GLubyte *) dstAddr);
+ dst = dstSlices[0];
fxt1_encode(srcWidth, srcHeight, 3, pixels, srcRowStride,
dst, dstRowStride);
- if (tempImage)
- _mesa_free((void*) tempImage);
+ free((void*) tempImage);
return GL_TRUE;
}
/**
- * Called via TexFormat->StoreImage to store an RGBA_FXT1 texture.
+ * Store user's image in rgba_fxt1 format.
*/
-static GLboolean
-texstore_rgba_fxt1(STORE_PARAMS)
+GLboolean
+_mesa_texstore_rgba_fxt1(TEXSTORE_PARAMS)
{
- const GLchan *pixels;
+ const GLubyte *pixels;
GLint srcRowStride;
GLubyte *dst;
- GLint texWidth = dstRowStride * 8 / 16; /* a bit of a hack */
- const GLchan *tempImage = NULL;
+ const GLubyte *tempImage = NULL;
- ASSERT(dstFormat == &_mesa_texformat_rgba_fxt1);
- ASSERT(dstXoffset % 8 == 0);
- ASSERT(dstYoffset % 4 == 0);
- ASSERT(dstZoffset == 0);
- (void) dstZoffset; (void) dstImageStride;
+ assert(dstFormat == MESA_FORMAT_RGBA_FXT1);
if (srcFormat != GL_RGBA ||
- srcType != CHAN_TYPE ||
+ srcType != GL_UNSIGNED_BYTE ||
ctx->_ImageTransferState ||
srcPacking->SwapBytes) {
- /* convert image to RGBA/GLchan */
- tempImage = _mesa_make_temp_chan_image(ctx, dims,
- baseInternalFormat,
- dstFormat->BaseFormat,
- srcWidth, srcHeight, srcDepth,
- srcFormat, srcType, srcAddr,
- srcPacking);
+ /* convert image to RGBA/GLubyte */
+ GLubyte *tempImageSlices[1];
+ int rgbaRowStride = 4 * srcWidth * sizeof(GLubyte);
+ tempImage = malloc(srcWidth * srcHeight * 4 * sizeof(GLubyte));
if (!tempImage)
return GL_FALSE; /* out of memory */
- _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
+ tempImageSlices[0] = (GLubyte *) tempImage;
+ _mesa_texstore(ctx, dims,
+ baseInternalFormat,
+ _mesa_little_endian() ? MESA_FORMAT_R8G8B8A8_UNORM
+ : MESA_FORMAT_A8B8G8R8_UNORM,
+ rgbaRowStride, tempImageSlices,
+ srcWidth, srcHeight, srcDepth,
+ srcFormat, srcType, srcAddr,
+ srcPacking);
pixels = tempImage;
srcRowStride = 4 * srcWidth;
srcFormat = GL_RGBA;
}
else {
- pixels = (const GLchan *) srcAddr;
+ pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
+ srcFormat, srcType, 0, 0);
+
srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
- srcType) / sizeof(GLchan);
+ srcType) / sizeof(GLubyte);
}
- dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
- GL_COMPRESSED_RGBA_FXT1_3DFX,
- texWidth, (GLubyte *) dstAddr);
+ dst = dstSlices[0];
fxt1_encode(srcWidth, srcHeight, 4, pixels, srcRowStride,
dst, dstRowStride);
- if (tempImage)
- _mesa_free((void*) tempImage);
+ free((void*) tempImage);
return GL_TRUE;
}
-static void
-fetch_texel_2d_rgba_fxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLchan *texel )
-{
- (void) k;
- fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, texel);
-}
-
-
-static void
-fetch_texel_2d_f_rgba_fxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- /* just sample as GLchan and convert to float here */
- GLchan rgba[4];
- (void) k;
- fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
- texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
- texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
- texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
- texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
-}
-
-
-static void
-fetch_texel_2d_rgb_fxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLchan *texel )
-{
- (void) k;
- fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, texel);
- texel[ACOMP] = 255;
-}
-
-
-static void
-fetch_texel_2d_f_rgb_fxt1( const struct gl_texture_image *texImage,
- GLint i, GLint j, GLint k, GLfloat *texel )
-{
- /* just sample as GLchan and convert to float here */
- GLchan rgba[4];
- (void) k;
- fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
- texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
- texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
- texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
- texel[ACOMP] = 1.0F;
-}
-
-
-
-const struct gl_texture_format _mesa_texformat_rgb_fxt1 = {
- MESA_FORMAT_RGB_FXT1, /* MesaFormat */
- GL_RGB, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 0, /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* TexelBytes */
- texstore_rgb_fxt1, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- fetch_texel_2d_rgb_fxt1, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_rgb_fxt1, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
-};
-
-const struct gl_texture_format _mesa_texformat_rgba_fxt1 = {
- MESA_FORMAT_RGBA_FXT1, /* MesaFormat */
- GL_RGBA, /* BaseFormat */
- GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
- 4, /*approx*/ /* RedBits */
- 4, /*approx*/ /* GreenBits */
- 4, /*approx*/ /* BlueBits */
- 1, /*approx*/ /* AlphaBits */
- 0, /* LuminanceBits */
- 0, /* IntensityBits */
- 0, /* IndexBits */
- 0, /* DepthBits */
- 0, /* TexelBytes */
- texstore_rgba_fxt1, /* StoreTexImageFunc */
- NULL, /*impossible*/ /* FetchTexel1D */
- fetch_texel_2d_rgba_fxt1, /* FetchTexel2D */
- NULL, /*impossible*/ /* FetchTexel3D */
- NULL, /*impossible*/ /* FetchTexel1Df */
- fetch_texel_2d_f_rgba_fxt1, /* FetchTexel2Df */
- NULL, /*impossible*/ /* FetchTexel3Df */
-};
-
-
/***************************************************************************\
* FXT1 encoder
*
#define LL_RMS_D 10 /* fault tolerance (maximum delta) */
#define LL_RMS_E 255 /* fault tolerance (maximum error) */
#define ALPHA_TS 2 /* alpha threshold: (255 - ALPHA_TS) deemed opaque */
-#define ISTBLACK(v) (*((GLuint *)(v)) == 0)
-
+static const GLuint zero = 0;
+#define ISTBLACK(v) (memcmp(&(v), &zero, sizeof(zero)) == 0)
/*
* Define a 64-bit unsigned integer type and macros
*/
-#if defined(__GNUC__) && !defined(__cplusplus)
+#if 1
#define FX64_NATIVE 1
-typedef unsigned long long Fx64;
+typedef uint64_t Fx64;
#define FX64_MOV32(a, b) a = b
#define FX64_OR32(a, b) a |= b
#define FX64_SHL(a, c) a <<= c
-#else /* !__GNUC__ */
+#else
#define FX64_NATIVE 0
} \
} while (0)
-#endif /* !__GNUC__ */
-
+#endif
-#define F(i) 1 /* can be used to obtain an oblong metric: 0.30 / 0.59 / 0.11 */
+#define F(i) (GLfloat)1 /* can be used to obtain an oblong metric: 0.30 / 0.59 / 0.11 */
#define SAFECDOT 1 /* for paranoids */
#define MAKEIVEC(NV, NC, IV, B, V0, V1) \
for (j = 0; j < nv; j++) {
for (i = 0; i < nc; i++) {
- vec[j][i] = ((nv - 1 - j) * input[minCol][i] + j * input[maxCol][i] + (nv - 1) / 2) / (nv - 1);
+ vec[j][i] = ((nv - 1 - j) * input[minCol][i] + j * input[maxCol][i] + (nv - 1) / 2) / (GLfloat)(nv - 1);
}
}
#endif
* for each sample color
* sort to nearest vector.
*
- * replace each vector with the centroid of it's matching colors.
+ * replace each vector with the centroid of its matching colors.
*
* repeat until RMS doesn't improve.
*
#else
GLint best = fxt1_bestcol(vec, nv, input[k], nc, &err);
#endif
+ assert(best >= 0);
/* add in closest color */
for (i = 0; i < nc; i++) {
sum[best][i] += input[k][i];
GLint minColL = 0, maxColL = 0;
GLint minColR = 0, maxColR = 0;
GLint sumL = 0, sumR = 0;
-
+ GLint nn_comp;
/* Our solution here is to find the darkest and brightest colors in
* the 4x4 tile and use those as the two representative colors.
* There are probably better algorithms to use (histogram-based).
*/
- minSum = 2000; /* big enough */
- maxSum = -1; /* small enough */
- for (k = 0; k < N_TEXELS / 2; k++) {
- GLint sum = 0;
- for (i = 0; i < n_comp; i++) {
- sum += input[k][i];
- }
- if (minSum > sum) {
- minSum = sum;
- minColL = k;
- }
- if (maxSum < sum) {
- maxSum = sum;
- maxColL = k;
- }
- sumL += sum;
+ nn_comp = n_comp;
+ while ((minColL == maxColL) && nn_comp) {
+ minSum = 2000; /* big enough */
+ maxSum = -1; /* small enough */
+ for (k = 0; k < N_TEXELS / 2; k++) {
+ GLint sum = 0;
+ for (i = 0; i < nn_comp; i++) {
+ sum += input[k][i];
+ }
+ if (minSum > sum) {
+ minSum = sum;
+ minColL = k;
+ }
+ if (maxSum < sum) {
+ maxSum = sum;
+ maxColL = k;
+ }
+ sumL += sum;
+ }
+
+ nn_comp--;
}
- minSum = 2000; /* big enough */
- maxSum = -1; /* small enough */
- for (; k < N_TEXELS; k++) {
- GLint sum = 0;
- for (i = 0; i < n_comp; i++) {
- sum += input[k][i];
- }
- if (minSum > sum) {
- minSum = sum;
- minColR = k;
- }
- if (maxSum < sum) {
- maxSum = sum;
- maxColR = k;
- }
- sumR += sum;
+
+ nn_comp = n_comp;
+ while ((minColR == maxColR) && nn_comp) {
+ minSum = 2000; /* big enough */
+ maxSum = -1; /* small enough */
+ for (k = N_TEXELS / 2; k < N_TEXELS; k++) {
+ GLint sum = 0;
+ for (i = 0; i < nn_comp; i++) {
+ sum += input[k][i];
+ }
+ if (minSum > sum) {
+ minSum = sum;
+ minColR = k;
+ }
+ if (maxSum < sum) {
+ maxSum = sum;
+ maxColR = k;
+ }
+ sumR += sum;
+ }
+
+ nn_comp--;
}
/* choose the common vector (yuck!) */
}
for (j1 = 0; j1 < 2; j1++) {
for (j2 = 2; j2 < 4; j2++) {
- GLfloat e = 0.0F;
- for (i = 0; i < n_comp; i++) {
- e += (tv[j1][i] - tv[j2][i]) * (tv[j1][i] - tv[j2][i]);
- }
- if (e < err) {
- err = e;
- v1 = j1;
- v2 = j2;
- }
+ GLfloat e = 0.0F;
+ for (i = 0; i < n_comp; i++) {
+ e += (tv[j1][i] - tv[j2][i]) * (tv[j1][i] - tv[j2][i]);
+ }
+ if (e < err) {
+ err = e;
+ v1 = j1;
+ v2 = j2;
+ }
}
}
for (i = 0; i < n_comp; i++) {
/* add in texels */
for (k = N_TEXELS - 1; k >= 0; k--) {
GLint t = k * 3;
- GLuint *kk = (GLuint *)((GLuint)cc + t / 8);
+ GLuint *kk = (GLuint *)((char *)cc + t / 8);
GLint texel = n_vect + 1; /* transparent black */
if (!ISTBLACK(input[k])) {
/* left microtile */
if (maxColL == -1) {
/* all transparent black */
- cc[0] = ~0ul;
+ cc[0] = ~0u;
for (i = 0; i < n_comp; i++) {
vec[0][i] = 0;
vec[1][i] = 0;
/* right microtile */
if (maxColR == -1) {
/* all transparent black */
- cc[1] = ~0ul;
+ cc[1] = ~0u;
for (i = 0; i < n_comp; i++) {
vec[2][i] = 0;
vec[3][i] = 0;
if (trualpha) {
fxt1_quantize_ALPHA1(cc, input);
} else if (l == 0) {
- cc[0] = cc[1] = cc[2] = ~0ul;
+ cc[0] = cc[1] = cc[2] = ~0u;
cc[3] = 0;
} else if (l < N_TEXELS) {
fxt1_quantize_MIXED1(cc, input);
}
-static GLint
+
+/**
+ * Upscale an image by replication, not (typical) stretching.
+ * We use this when the image width or height is less than a
+ * certain size (4, 8) and we need to upscale an image.
+ */
+static void
+upscale_teximage2d(GLsizei inWidth, GLsizei inHeight,
+ GLsizei outWidth, GLsizei outHeight,
+ GLint comps, const GLubyte *src, GLint srcRowStride,
+ GLubyte *dest )
+{
+ GLint i, j, k;
+
+ assert(outWidth >= inWidth);
+ assert(outHeight >= inHeight);
+#if 0
+ assert(inWidth == 1 || inWidth == 2 || inHeight == 1 || inHeight == 2);
+ assert((outWidth & 3) == 0);
+ assert((outHeight & 3) == 0);
+#endif
+
+ for (i = 0; i < outHeight; i++) {
+ const GLint ii = i % inHeight;
+ for (j = 0; j < outWidth; j++) {
+ const GLint jj = j % inWidth;
+ for (k = 0; k < comps; k++) {
+ dest[(i * outWidth + j) * comps + k]
+ = src[ii * srcRowStride + jj * comps + k];
+ }
+ }
+ }
+}
+
+
+static void
fxt1_encode (GLuint width, GLuint height, GLint comps,
const void *source, GLint srcRowStride,
void *dest, GLint destRowStride)
{
GLuint x, y;
const GLubyte *data;
- GLuint *encoded = (GLuint *) dest;
- GLubyte *newSource = NULL;
+ GLuint *encoded = (GLuint *)dest;
+ void *newSource = NULL;
+
+ assert(comps == 3 || comps == 4);
/* Replicate image if width is not M8 or height is not M4 */
if ((width & 7) | (height & 3)) {
GLint newWidth = (width + 7) & ~7;
GLint newHeight = (height + 3) & ~3;
- newSource = (GLubyte *)
- _mesa_malloc(comps * newWidth * newHeight * sizeof(GLubyte *));
- _mesa_upscale_teximage2d(width, height, newWidth, newHeight,
- comps, (const GLchan *) source,
- srcRowStride, newSource);
+ newSource = malloc(comps * newWidth * newHeight * sizeof(GLubyte));
+ if (!newSource) {
+ GET_CURRENT_CONTEXT(ctx);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture compression");
+ goto cleanUp;
+ }
+ upscale_teximage2d(width, height, newWidth, newHeight,
+ comps, (const GLubyte *) source,
+ srcRowStride, (GLubyte *) newSource);
source = newSource;
width = newWidth;
height = newHeight;
encoded += destRowStride;
}
- if (newSource != NULL) {
- _mesa_free(newSource);
- }
-
- return 0;
+ cleanUp:
+ free(newSource);
}
/* lookup table for scaling 5 bit colors up to 8 bits */
-static GLubyte _rgb_scale_5[] = {
+static const GLubyte _rgb_scale_5[] = {
0, 8, 16, 25, 33, 41, 49, 58,
66, 74, 82, 90, 99, 107, 115, 123,
132, 140, 148, 156, 165, 173, 181, 189,
};
/* lookup table for scaling 6 bit colors up to 8 bits */
-static GLubyte _rgb_scale_6[] = {
+static const GLubyte _rgb_scale_6[] = {
0, 4, 8, 12, 16, 20, 24, 28,
32, 36, 40, 45, 49, 53, 57, 61,
65, 69, 73, 77, 81, 85, 89, 93,
#define UP5(c) _rgb_scale_5[(c) & 31]
#define UP6(c, b) _rgb_scale_6[(((c) & 31) << 1) | ((b) & 1)]
#define LERP(n, t, c0, c1) (((n) - (t)) * (c0) + (t) * (c1) + (n) / 2) / (n)
-#define ZERO_4UBV(v) *((GLuint *)(v)) = 0
static void
-fxt1_decode_1HI (GLubyte *code, GLint t, GLubyte *rgba)
+fxt1_decode_1HI (const GLubyte *code, GLint t, GLubyte *rgba)
{
const GLuint *cc;
t *= 3;
- cc = (GLuint *)(code + t / 8);
+ cc = (const GLuint *)(code + t / 8);
t = (cc[0] >> (t & 7)) & 7;
if (t == 7) {
- ZERO_4UBV(rgba);
+ rgba[RCOMP] = rgba[GCOMP] = rgba[BCOMP] = rgba[ACOMP] = 0;
} else {
- cc = (GLuint *)(code + 12);
+ GLubyte r, g, b;
+ cc = (const GLuint *)(code + 12);
if (t == 0) {
- rgba[BCOMP] = UP5(CC_SEL(cc, 0));
- rgba[GCOMP] = UP5(CC_SEL(cc, 5));
- rgba[RCOMP] = UP5(CC_SEL(cc, 10));
+ b = UP5(CC_SEL(cc, 0));
+ g = UP5(CC_SEL(cc, 5));
+ r = UP5(CC_SEL(cc, 10));
} else if (t == 6) {
- rgba[BCOMP] = UP5(CC_SEL(cc, 15));
- rgba[GCOMP] = UP5(CC_SEL(cc, 20));
- rgba[RCOMP] = UP5(CC_SEL(cc, 25));
+ b = UP5(CC_SEL(cc, 15));
+ g = UP5(CC_SEL(cc, 20));
+ r = UP5(CC_SEL(cc, 25));
} else {
- rgba[BCOMP] = LERP(6, t, UP5(CC_SEL(cc, 0)), UP5(CC_SEL(cc, 15)));
- rgba[GCOMP] = LERP(6, t, UP5(CC_SEL(cc, 5)), UP5(CC_SEL(cc, 20)));
- rgba[RCOMP] = LERP(6, t, UP5(CC_SEL(cc, 10)), UP5(CC_SEL(cc, 25)));
+ b = LERP(6, t, UP5(CC_SEL(cc, 0)), UP5(CC_SEL(cc, 15)));
+ g = LERP(6, t, UP5(CC_SEL(cc, 5)), UP5(CC_SEL(cc, 20)));
+ r = LERP(6, t, UP5(CC_SEL(cc, 10)), UP5(CC_SEL(cc, 25)));
}
+ rgba[RCOMP] = r;
+ rgba[GCOMP] = g;
+ rgba[BCOMP] = b;
rgba[ACOMP] = 255;
}
}
static void
-fxt1_decode_1CHROMA (GLubyte *code, GLint t, GLubyte *rgba)
+fxt1_decode_1CHROMA (const GLubyte *code, GLint t, GLubyte *rgba)
{
const GLuint *cc;
GLuint kk;
- cc = (GLuint *)code;
+ cc = (const GLuint *)code;
if (t & 16) {
cc++;
t &= 15;
t = (cc[0] >> (t * 2)) & 3;
t *= 15;
- cc = (GLuint *)(code + 8 + t / 8);
+ cc = (const GLuint *)(code + 8 + t / 8);
kk = cc[0] >> (t & 7);
rgba[BCOMP] = UP5(kk);
rgba[GCOMP] = UP5(kk >> 5);
static void
-fxt1_decode_1MIXED (GLubyte *code, GLint t, GLubyte *rgba)
+fxt1_decode_1MIXED (const GLubyte *code, GLint t, GLubyte *rgba)
{
const GLuint *cc;
GLuint col[2][3];
GLint glsb, selb;
- cc = (GLuint *)code;
+ cc = (const GLuint *)code;
if (t & 16) {
t &= 15;
t = (cc[1] >> (t * 2)) & 3;
/* col 2 */
- col[0][BCOMP] = (*(GLuint *)(code + 11)) >> 6;
+ col[0][BCOMP] = (*(const GLuint *)(code + 11)) >> 6;
col[0][GCOMP] = CC_SEL(cc, 99);
col[0][RCOMP] = CC_SEL(cc, 104);
/* col 3 */
/* alpha[0] == 1 */
if (t == 3) {
- ZERO_4UBV(rgba);
+ /* zero */
+ rgba[RCOMP] = rgba[BCOMP] = rgba[GCOMP] = rgba[ACOMP] = 0;
} else {
+ GLubyte r, g, b;
if (t == 0) {
- rgba[BCOMP] = UP5(col[0][BCOMP]);
- rgba[GCOMP] = UP5(col[0][GCOMP]);
- rgba[RCOMP] = UP5(col[0][RCOMP]);
+ b = UP5(col[0][BCOMP]);
+ g = UP5(col[0][GCOMP]);
+ r = UP5(col[0][RCOMP]);
} else if (t == 2) {
- rgba[BCOMP] = UP5(col[1][BCOMP]);
- rgba[GCOMP] = UP6(col[1][GCOMP], glsb);
- rgba[RCOMP] = UP5(col[1][RCOMP]);
+ b = UP5(col[1][BCOMP]);
+ g = UP6(col[1][GCOMP], glsb);
+ r = UP5(col[1][RCOMP]);
} else {
- rgba[BCOMP] = (UP5(col[0][BCOMP]) + UP5(col[1][BCOMP])) / 2;
- rgba[GCOMP] = (UP5(col[0][GCOMP]) + UP6(col[1][GCOMP], glsb)) / 2;
- rgba[RCOMP] = (UP5(col[0][RCOMP]) + UP5(col[1][RCOMP])) / 2;
+ b = (UP5(col[0][BCOMP]) + UP5(col[1][BCOMP])) / 2;
+ g = (UP5(col[0][GCOMP]) + UP6(col[1][GCOMP], glsb)) / 2;
+ r = (UP5(col[0][RCOMP]) + UP5(col[1][RCOMP])) / 2;
}
+ rgba[RCOMP] = r;
+ rgba[GCOMP] = g;
+ rgba[BCOMP] = b;
rgba[ACOMP] = 255;
}
} else {
/* alpha[0] == 0 */
-
+ GLubyte r, g, b;
if (t == 0) {
- rgba[BCOMP] = UP5(col[0][BCOMP]);
- rgba[GCOMP] = UP6(col[0][GCOMP], glsb ^ selb);
- rgba[RCOMP] = UP5(col[0][RCOMP]);
+ b = UP5(col[0][BCOMP]);
+ g = UP6(col[0][GCOMP], glsb ^ selb);
+ r = UP5(col[0][RCOMP]);
} else if (t == 3) {
- rgba[BCOMP] = UP5(col[1][BCOMP]);
- rgba[GCOMP] = UP6(col[1][GCOMP], glsb);
- rgba[RCOMP] = UP5(col[1][RCOMP]);
+ b = UP5(col[1][BCOMP]);
+ g = UP6(col[1][GCOMP], glsb);
+ r = UP5(col[1][RCOMP]);
} else {
- rgba[BCOMP] = LERP(3, t, UP5(col[0][BCOMP]), UP5(col[1][BCOMP]));
- rgba[GCOMP] = LERP(3, t, UP6(col[0][GCOMP], glsb ^ selb),
- UP6(col[1][GCOMP], glsb));
- rgba[RCOMP] = LERP(3, t, UP5(col[0][RCOMP]), UP5(col[1][RCOMP]));
- }
+ b = LERP(3, t, UP5(col[0][BCOMP]), UP5(col[1][BCOMP]));
+ g = LERP(3, t, UP6(col[0][GCOMP], glsb ^ selb),
+ UP6(col[1][GCOMP], glsb));
+ r = LERP(3, t, UP5(col[0][RCOMP]), UP5(col[1][RCOMP]));
+ }
+ rgba[RCOMP] = r;
+ rgba[GCOMP] = g;
+ rgba[BCOMP] = b;
rgba[ACOMP] = 255;
}
}
static void
-fxt1_decode_1ALPHA (GLubyte *code, GLint t, GLubyte *rgba)
+fxt1_decode_1ALPHA (const GLubyte *code, GLint t, GLubyte *rgba)
{
const GLuint *cc;
+ GLubyte r, g, b, a;
- cc = (GLuint *)code;
+ cc = (const GLuint *)code;
if (CC_SEL(cc, 124) & 1) {
/* lerp == 1 */
GLuint col0[4];
t &= 15;
t = (cc[1] >> (t * 2)) & 3;
/* col 2 */
- col0[BCOMP] = (*(GLuint *)(code + 11)) >> 6;
+ col0[BCOMP] = (*(const GLuint *)(code + 11)) >> 6;
col0[GCOMP] = CC_SEL(cc, 99);
col0[RCOMP] = CC_SEL(cc, 104);
col0[ACOMP] = CC_SEL(cc, 119);
}
if (t == 0) {
- rgba[BCOMP] = UP5(col0[BCOMP]);
- rgba[GCOMP] = UP5(col0[GCOMP]);
- rgba[RCOMP] = UP5(col0[RCOMP]);
- rgba[ACOMP] = UP5(col0[ACOMP]);
+ b = UP5(col0[BCOMP]);
+ g = UP5(col0[GCOMP]);
+ r = UP5(col0[RCOMP]);
+ a = UP5(col0[ACOMP]);
} else if (t == 3) {
- rgba[BCOMP] = UP5(CC_SEL(cc, 79));
- rgba[GCOMP] = UP5(CC_SEL(cc, 84));
- rgba[RCOMP] = UP5(CC_SEL(cc, 89));
- rgba[ACOMP] = UP5(CC_SEL(cc, 114));
+ b = UP5(CC_SEL(cc, 79));
+ g = UP5(CC_SEL(cc, 84));
+ r = UP5(CC_SEL(cc, 89));
+ a = UP5(CC_SEL(cc, 114));
} else {
- rgba[BCOMP] = LERP(3, t, UP5(col0[BCOMP]), UP5(CC_SEL(cc, 79)));
- rgba[GCOMP] = LERP(3, t, UP5(col0[GCOMP]), UP5(CC_SEL(cc, 84)));
- rgba[RCOMP] = LERP(3, t, UP5(col0[RCOMP]), UP5(CC_SEL(cc, 89)));
- rgba[ACOMP] = LERP(3, t, UP5(col0[ACOMP]), UP5(CC_SEL(cc, 114)));
+ b = LERP(3, t, UP5(col0[BCOMP]), UP5(CC_SEL(cc, 79)));
+ g = LERP(3, t, UP5(col0[GCOMP]), UP5(CC_SEL(cc, 84)));
+ r = LERP(3, t, UP5(col0[RCOMP]), UP5(CC_SEL(cc, 89)));
+ a = LERP(3, t, UP5(col0[ACOMP]), UP5(CC_SEL(cc, 114)));
}
} else {
/* lerp == 0 */
t = (cc[0] >> (t * 2)) & 3;
if (t == 3) {
- ZERO_4UBV(rgba);
+ /* zero */
+ r = g = b = a = 0;
} else {
GLuint kk;
- cc = (GLuint *)code;
- rgba[ACOMP] = UP5(cc[3] >> (t * 5 + 13));
+ cc = (const GLuint *)code;
+ a = UP5(cc[3] >> (t * 5 + 13));
t *= 15;
- cc = (GLuint *)(code + 8 + t / 8);
+ cc = (const GLuint *)(code + 8 + t / 8);
kk = cc[0] >> (t & 7);
- rgba[BCOMP] = UP5(kk);
- rgba[GCOMP] = UP5(kk >> 5);
- rgba[RCOMP] = UP5(kk >> 10);
+ b = UP5(kk);
+ g = UP5(kk >> 5);
+ r = UP5(kk >> 10);
}
}
+ rgba[RCOMP] = r;
+ rgba[GCOMP] = g;
+ rgba[BCOMP] = b;
+ rgba[ACOMP] = a;
}
fxt1_decode_1 (const void *texture, GLint stride, /* in pixels */
GLint i, GLint j, GLubyte *rgba)
{
- static void (*decode_1[]) (GLubyte *, GLint, GLubyte *) = {
+ static void (*decode_1[]) (const GLubyte *, GLint, GLubyte *) = {
fxt1_decode_1HI, /* cc-high = "00?" */
fxt1_decode_1HI, /* cc-high = "00?" */
fxt1_decode_1CHROMA, /* cc-chroma = "010" */
fxt1_decode_1MIXED /* mixed = "1??" */
};
- GLubyte *code = (GLubyte *)texture +
+ const GLubyte *code = (const GLubyte *)texture +
((j / 4) * (stride / 8) + (i / 8)) * 16;
- GLint mode = CC_SEL((GLuint *)code, 125);
+ GLint mode = CC_SEL(code, 125);
GLint t = i & 7;
if (t & 4) {
decode_1[mode](code, t, rgba);
}
+
+
+
+
+static void
+fetch_rgb_fxt1(const GLubyte *map,
+ GLint rowStride, GLint i, GLint j, GLfloat *texel)
+{
+ GLubyte rgba[4];
+ fxt1_decode_1(map, rowStride, i, j, rgba);
+ texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
+ texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
+ texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
+ texel[ACOMP] = 1.0F;
+}
+
+
+static void
+fetch_rgba_fxt1(const GLubyte *map,
+ GLint rowStride, GLint i, GLint j, GLfloat *texel)
+{
+ GLubyte rgba[4];
+ fxt1_decode_1(map, rowStride, i, j, rgba);
+ texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
+ texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
+ texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
+ texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
+}
+
+
+compressed_fetch_func
+_mesa_get_fxt_fetch_func(mesa_format format)
+{
+ switch (format) {
+ case MESA_FORMAT_RGB_FXT1:
+ return fetch_rgb_fxt1;
+ case MESA_FORMAT_RGBA_FXT1:
+ return fetch_rgba_fxt1;
+ default:
+ return NULL;
+ }
+}