1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Mesa 3-D graphics library
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Version:  6.5.3
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright (c) 2008 VMware, Inc.
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"),
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions:
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice shall be included
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * in all copies or substantial portions of the Software.
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \file texcompress_s3tc.c
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * GL_EXT_texture_compression_s3tc support.
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef USE_EXTERNAL_DXTN_LIB
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define USE_EXTERNAL_DXTN_LIB 1
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glheader.h"
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "imports.h"
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "colormac.h"
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "dlopen.h"
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "image.h"
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "macros.h"
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "mfeatures.h"
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "mtypes.h"
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "texcompress.h"
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "texcompress_s3tc.h"
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "texstore.h"
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "swrast/s_context.h"
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if FEATURE_texture_s3tc
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(_WIN32) || defined(WIN32)
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define DXTN_LIBNAME "dxtn.dll"
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define RTLD_LAZY 0
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define RTLD_GLOBAL 0
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(__DJGPP__)
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define DXTN_LIBNAME "dxtn.dxe"
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define DXTN_LIBNAME "libtxc_dxtn.so"
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if FEATURE_EXT_texture_sRGB
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Convert an 8-bit sRGB value from non-linear space to a
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * linear RGB value in [0, 1].
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Implemented with a 256-entry lookup table.
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic inline GLfloat
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgnonlinear_to_linear(GLubyte cs8)
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   static GLfloat table[256];
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   static GLboolean tableReady = GL_FALSE;
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!tableReady) {
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* compute lookup table now */
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GLuint i;
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      for (i = 0; i < 256; i++) {
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         const GLfloat cs = UBYTE_TO_FLOAT(i);
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         if (cs <= 0.04045) {
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            table[i] = cs / 12.92f;
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         }
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         else {
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         }
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      tableReady = GL_TRUE;
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return table[cs8];
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* FEATURE_EXT_texture_sRGB */
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut );
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL;
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdxtFetchTexelFuncExt fetch_ext_rgba_dxt1 = NULL;
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdxtFetchTexelFuncExt fetch_ext_rgba_dxt3 = NULL;
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgdxtFetchTexelFuncExt fetch_ext_rgba_dxt5 = NULL;
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width,
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      GLint height, const GLubyte *srcPixData,
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      GLenum destformat, GLubyte *dest,
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                      GLint dstRowStride);
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic dxtCompressTexFuncExt ext_tx_compress_dxtn = NULL;
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void *dxtlibhandle = NULL;
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_init_texture_s3tc( struct gl_context *ctx )
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* called during context initialization */
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ctx->Mesa_DXTn = GL_FALSE;
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if USE_EXTERNAL_DXTN_LIB
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dxtlibhandle) {
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      dxtlibhandle = _mesa_dlopen(DXTN_LIBNAME, 0);
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (!dxtlibhandle) {
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	 _mesa_warning(ctx, "couldn't open " DXTN_LIBNAME ", software DXTn "
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	    "compression/decompression unavailable");
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      else {
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         /* the fetch functions are not per context! Might be problematic... */
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         fetch_ext_rgb_dxt1 = (dxtFetchTexelFuncExt)
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgb_dxt1");
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         fetch_ext_rgba_dxt1 = (dxtFetchTexelFuncExt)
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt1");
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         fetch_ext_rgba_dxt3 = (dxtFetchTexelFuncExt)
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt3");
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         fetch_ext_rgba_dxt5 = (dxtFetchTexelFuncExt)
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt5");
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         ext_tx_compress_dxtn = (dxtCompressTexFuncExt)
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            _mesa_dlsym(dxtlibhandle, "tx_compress_dxtn");
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         if (!fetch_ext_rgb_dxt1 ||
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org             !fetch_ext_rgba_dxt1 ||
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org             !fetch_ext_rgba_dxt3 ||
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org             !fetch_ext_rgba_dxt5 ||
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org             !ext_tx_compress_dxtn) {
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	    _mesa_warning(ctx, "couldn't reference all symbols in "
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	       DXTN_LIBNAME ", software DXTn compression/decompression "
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	       "unavailable");
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            fetch_ext_rgb_dxt1 = NULL;
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            fetch_ext_rgba_dxt1 = NULL;
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            fetch_ext_rgba_dxt3 = NULL;
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            fetch_ext_rgba_dxt5 = NULL;
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            ext_tx_compress_dxtn = NULL;
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            _mesa_dlclose(dxtlibhandle);
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            dxtlibhandle = NULL;
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         }
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (dxtlibhandle) {
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      ctx->Mesa_DXTn = GL_TRUE;
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   (void) ctx;
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Store user's image in rgb_dxt1 format.
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGLboolean
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const GLubyte *pixels;
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte *dst;
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const GLubyte *tempImage = NULL;
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ASSERT(dstFormat == MESA_FORMAT_RGB_DXT1 ||
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          dstFormat == MESA_FORMAT_SRGB_DXT1);
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (srcFormat != GL_RGB ||
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcType != GL_UNSIGNED_BYTE ||
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       ctx->_ImageTransferState ||
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcPacking->RowLength != srcWidth ||
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcPacking->SwapBytes) {
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* convert image to RGB/GLubyte */
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             baseInternalFormat,
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             _mesa_get_format_base_format(dstFormat),
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcWidth, srcHeight, srcDepth,
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcFormat, srcType, srcAddr,
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcPacking);
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (!tempImage)
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return GL_FALSE; /* out of memory */
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pixels = tempImage;
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      srcFormat = GL_RGB;
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                     srcFormat, srcType, 0, 0);
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dst = dstSlices[0];
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ext_tx_compress_dxtn) {
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      (*ext_tx_compress_dxtn)(3, srcWidth, srcHeight, pixels,
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              dst, dstRowStride);
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_warning(ctx, "external dxt library not available: texstore_rgb_dxt1");
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (tempImage)
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      free((void *) tempImage);
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return GL_TRUE;
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Store user's image in rgba_dxt1 format.
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGLboolean
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const GLubyte *pixels;
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte *dst;
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const GLubyte *tempImage = NULL;
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT1 ||
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          dstFormat == MESA_FORMAT_SRGBA_DXT1);
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (srcFormat != GL_RGBA ||
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcType != GL_UNSIGNED_BYTE ||
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       ctx->_ImageTransferState ||
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcPacking->RowLength != srcWidth ||
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcPacking->SwapBytes) {
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* convert image to RGBA/GLubyte */
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             baseInternalFormat,
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             _mesa_get_format_base_format(dstFormat),
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcWidth, srcHeight, srcDepth,
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcFormat, srcType, srcAddr,
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcPacking);
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (!tempImage)
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return GL_FALSE; /* out of memory */
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pixels = tempImage;
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      srcFormat = GL_RGBA;
242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                     srcFormat, srcType, 0, 0);
246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dst = dstSlices[0];
249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ext_tx_compress_dxtn) {
251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              dst, dstRowStride);
254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt1");
257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (tempImage)
260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      free((void*) tempImage);
261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return GL_TRUE;
263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Store user's image in rgba_dxt3 format.
268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGLboolean
270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const GLubyte *pixels;
273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte *dst;
274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const GLubyte *tempImage = NULL;
275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT3 ||
277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          dstFormat == MESA_FORMAT_SRGBA_DXT3);
278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (srcFormat != GL_RGBA ||
280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcType != GL_UNSIGNED_BYTE ||
281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       ctx->_ImageTransferState ||
282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcPacking->RowLength != srcWidth ||
283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcPacking->SwapBytes) {
284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* convert image to RGBA/GLubyte */
285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             baseInternalFormat,
287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             _mesa_get_format_base_format(dstFormat),
288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcWidth, srcHeight, srcDepth,
289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcFormat, srcType, srcAddr,
290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcPacking);
291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (!tempImage)
292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return GL_FALSE; /* out of memory */
293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pixels = tempImage;
294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                     srcFormat, srcType, 0, 0);
298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dst = dstSlices[0];
301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ext_tx_compress_dxtn) {
303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              dst, dstRowStride);
306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt3");
309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (tempImage)
312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      free((void *) tempImage);
313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return GL_TRUE;
315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Store user's image in rgba_dxt5 format.
320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgGLboolean
322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const GLubyte *pixels;
325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte *dst;
326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const GLubyte *tempImage = NULL;
327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ASSERT(dstFormat == MESA_FORMAT_RGBA_DXT5 ||
329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          dstFormat == MESA_FORMAT_SRGBA_DXT5);
330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (srcFormat != GL_RGBA ||
332f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcType != GL_UNSIGNED_BYTE ||
333f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       ctx->_ImageTransferState ||
334f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcPacking->RowLength != srcWidth ||
335f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       srcPacking->SwapBytes) {
336f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* convert image to RGBA/GLubyte */
337f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
338f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             baseInternalFormat,
339f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                   	     _mesa_get_format_base_format(dstFormat),
340f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcWidth, srcHeight, srcDepth,
341f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcFormat, srcType, srcAddr,
342f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             srcPacking);
343f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (!tempImage)
344f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return GL_FALSE; /* out of memory */
345f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pixels = tempImage;
346f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
347f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
348f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
349f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                     srcFormat, srcType, 0, 0);
350f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
351f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
352f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   dst = dstSlices[0];
353f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
354f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (ext_tx_compress_dxtn) {
355f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
356f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
357f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                              dst, dstRowStride);
358f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
359f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
360f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt5");
361f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
362f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
363f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (tempImage)
364f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      free((void *) tempImage);
365f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
366f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return GL_TRUE;
367f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
368f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
369f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
370f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
371f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgfetch_texel_2d_rgb_dxt1(const struct swrast_texture_image *texImage,
372f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        GLint i, GLint j, GLint k, GLubyte *texel)
373f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
374f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   (void) k;
375f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (fetch_ext_rgb_dxt1) {
376f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GLint sliceOffset = k ? texImage->ImageOffsets[k] / 2 : 0;
377f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      fetch_ext_rgb_dxt1(texImage->RowStride,
378f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         texImage->Map + sliceOffset, i, j, texel);
379f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
380f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else
381f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1");
382f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
383f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
384f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
385f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
386f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_fetch_texel_rgb_dxt1(const struct swrast_texture_image *texImage,
387f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           GLint i, GLint j, GLint k, GLfloat *texel)
388f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
389f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* just sample as GLubyte and convert to float here */
390f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte rgba[4];
391f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba);
392f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
393f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
394f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
395f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
396f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
397f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
398f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
399f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
400f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgfetch_texel_2d_rgba_dxt1(const struct swrast_texture_image *texImage,
401f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         GLint i, GLint j, GLint k, GLubyte *texel)
402f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
403f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   (void) k;
404f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (fetch_ext_rgba_dxt1) {
405f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GLint sliceOffset = k ? texImage->ImageOffsets[k] / 2 : 0;
406f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      fetch_ext_rgba_dxt1(texImage->RowStride,
407f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                          texImage->Map + sliceOffset, i, j, texel);
408f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
409f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else
410f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n");
411f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
412f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
413f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
414f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
415f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_fetch_texel_rgba_dxt1(const struct swrast_texture_image *texImage,
416f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            GLint i, GLint j, GLint k, GLfloat *texel)
417f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
418f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* just sample as GLubyte and convert to float here */
419f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte rgba[4];
420f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba);
421f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
422f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
423f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
424f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
425f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
426f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
427f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
428f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
429f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgfetch_texel_2d_rgba_dxt3(const struct swrast_texture_image *texImage,
430f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         GLint i, GLint j, GLint k, GLubyte *texel)
431f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
432f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   (void) k;
433f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (fetch_ext_rgba_dxt3) {
434f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GLint sliceOffset = k ? texImage->ImageOffsets[k] : 0;
435f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      fetch_ext_rgba_dxt3(texImage->RowStride,
436f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                          texImage->Map + sliceOffset, i, j, texel);
437f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
438f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else
439f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt3\n");
440f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
441f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
442f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
443f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
444f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_fetch_texel_rgba_dxt3(const struct swrast_texture_image *texImage,
445f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            GLint i, GLint j, GLint k, GLfloat *texel)
446f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
447f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* just sample as GLubyte and convert to float here */
448f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte rgba[4];
449f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba);
450f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
451f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
452f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
453f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
454f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
455f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
456f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
457f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
458f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgfetch_texel_2d_rgba_dxt5(const struct swrast_texture_image *texImage,
459f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                         GLint i, GLint j, GLint k, GLubyte *texel)
460f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
461f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   (void) k;
462f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (fetch_ext_rgba_dxt5) {
463f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GLint sliceOffset = k ? texImage->ImageOffsets[k] : 0;
464f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      fetch_ext_rgba_dxt5(texImage->RowStride,
465f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                          texImage->Map + sliceOffset, i, j, texel);
466f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
467f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else
468f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt5\n");
469f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
470f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
471f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
472f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
473f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_fetch_texel_rgba_dxt5(const struct swrast_texture_image *texImage,
474f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            GLint i, GLint j, GLint k, GLfloat *texel)
475f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
476f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* just sample as GLubyte and convert to float here */
477f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte rgba[4];
478f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba);
479f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
480f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
481f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
482f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
483f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
484f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
485f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if FEATURE_EXT_texture_sRGB
486f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
487f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_fetch_texel_srgb_dxt1(const struct swrast_texture_image *texImage,
488f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            GLint i, GLint j, GLint k, GLfloat *texel)
489f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
490f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* just sample as GLubyte and convert to float here */
491f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte rgba[4];
492f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba);
493f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
494f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
495f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
496f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
497f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
498f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
499f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
500f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_fetch_texel_srgba_dxt1(const struct swrast_texture_image *texImage,
501f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                             GLint i, GLint j, GLint k, GLfloat *texel)
502f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
503f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* just sample as GLubyte and convert to float here */
504f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte rgba[4];
505f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba);
506f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
507f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
508f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
509f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
510f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
511f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
512f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
513f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_fetch_texel_srgba_dxt3(const struct swrast_texture_image *texImage,
514f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                             GLint i, GLint j, GLint k, GLfloat *texel)
515f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
516f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* just sample as GLubyte and convert to float here */
517f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte rgba[4];
518f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba);
519f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
520f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
521f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
522f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
523f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
524f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
525f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
526f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org_mesa_fetch_texel_srgba_dxt5(const struct swrast_texture_image *texImage,
527f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                             GLint i, GLint j, GLint k, GLfloat *texel)
528f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
529f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* just sample as GLubyte and convert to float here */
530f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte rgba[4];
531f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba);
532f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
533f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
534f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
535f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   texel[ACOMP] = UBYTE_TO_FLOAT(rgba[ACOMP]);
536f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
537f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* FEATURE_EXT_texture_sRGB */
538f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
539f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
540f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* FEATURE_texture_s3tc */
541