mesa: Remove unnecessary header.
[mesa.git] / src / mesa / main / texcompress_fxt1.c
index fc151605c9e32319e9a05eba6f1dbeb206536969..04acf05e528397af35b5013e9f7cda9f9db393ce 100644 (file)
 #include "image.h"
 #include "mipmap.h"
 #include "texcompress.h"
-#include "texformat.h"
+#include "texcompress_fxt1.h"
 #include "texstore.h"
 
 
+#if FEATURE_texture_fxt1
+
+
 static void
 fxt1_encode (GLuint width, GLuint height, GLint comps,
              const void *source, GLint srcRowStride,
@@ -52,20 +55,10 @@ fxt1_decode_1 (const void *texture, GLint stride,
 
 
 /**
- * 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(TEXSTORE_PARAMS)
+GLboolean
+_mesa_texstore_rgb_fxt1(TEXSTORE_PARAMS)
 {
    const GLchan *pixels;
    GLint srcRowStride;
@@ -73,7 +66,7 @@ texstore_rgb_fxt1(TEXSTORE_PARAMS)
    const GLint texWidth = dstRowStride * 8 / 16; /* a bit of a hack */
    const GLchan *tempImage = NULL;
 
-   ASSERT(dstFormat == &_mesa_texformat_rgb_fxt1);
+   ASSERT(dstFormat == MESA_FORMAT_RGB_FXT1);
    ASSERT(dstXoffset % 8 == 0);
    ASSERT(dstYoffset % 4 == 0);
    ASSERT(dstZoffset     == 0);
@@ -87,7 +80,7 @@ texstore_rgb_fxt1(TEXSTORE_PARAMS)
       /* convert image to RGB/GLchan */
       tempImage = _mesa_make_temp_chan_image(ctx, dims,
                                              baseInternalFormat,
-                                             dstFormat->BaseFormat,
+                                             _mesa_get_format_base_format(dstFormat),
                                              srcWidth, srcHeight, srcDepth,
                                              srcFormat, srcType, srcAddr,
                                              srcPacking);
@@ -105,24 +98,24 @@ texstore_rgb_fxt1(TEXSTORE_PARAMS)
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
-                                        dstFormat->MesaFormat,
+                                        dstFormat,
                                         texWidth, (GLubyte *) dstAddr);
 
    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(TEXSTORE_PARAMS)
+GLboolean
+_mesa_texstore_rgba_fxt1(TEXSTORE_PARAMS)
 {
    const GLchan *pixels;
    GLint srcRowStride;
@@ -130,7 +123,7 @@ texstore_rgba_fxt1(TEXSTORE_PARAMS)
    GLint texWidth = dstRowStride * 8 / 16; /* a bit of a hack */
    const GLchan *tempImage = NULL;
 
-   ASSERT(dstFormat == &_mesa_texformat_rgba_fxt1);
+   ASSERT(dstFormat == MESA_FORMAT_RGBA_FXT1);
    ASSERT(dstXoffset % 8 == 0);
    ASSERT(dstYoffset % 4 == 0);
    ASSERT(dstZoffset     == 0);
@@ -144,7 +137,7 @@ texstore_rgba_fxt1(TEXSTORE_PARAMS)
       /* convert image to RGBA/GLchan */
       tempImage = _mesa_make_temp_chan_image(ctx, dims,
                                              baseInternalFormat,
-                                             dstFormat->BaseFormat,
+                                             _mesa_get_format_base_format(dstFormat),
                                              srcWidth, srcHeight, srcDepth,
                                              srcFormat, srcType, srcAddr,
                                              srcPacking);
@@ -162,31 +155,22 @@ texstore_rgba_fxt1(TEXSTORE_PARAMS)
    }
 
    dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
-                                        dstFormat->MesaFormat,
+                                        dstFormat,
                                         texWidth, (GLubyte *) dstAddr);
 
    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 )
+void
+_mesa_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];
@@ -199,19 +183,9 @@ fetch_texel_2d_f_rgba_fxt1( const struct gl_texture_image *texImage,
 }
 
 
-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 )
+void
+_mesa_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];
@@ -225,55 +199,6 @@ fetch_texel_2d_f_rgb_fxt1( const struct gl_texture_image *texImage,
 
 
 
-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,                                  /* StencilBits */
-   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 */
-   NULL                                        /* StoreTexel */
-};
-
-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,                                  /* StencilBits */
-   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 */
-   NULL                                        /* StoreTexel */
-};
-
-
 /***************************************************************************\
  * FXT1 encoder
  *
@@ -481,7 +406,7 @@ fxt1_choose (GLfloat vec[][MAX_COMP], GLint nv,
    } hist[N_TEXELS];
    GLint lenh = 0;
 
-   _mesa_memset(hist, 0, sizeof(hist));
+   memset(hist, 0, sizeof(hist));
 
    for (k = 0; k < n; k++) {
       GLint l;
@@ -551,7 +476,7 @@ fxt1_lloyd (GLfloat vec[][MAX_COMP], GLint nv,
     *     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.
     *
@@ -603,6 +528,7 @@ fxt1_lloyd (GLfloat vec[][MAX_COMP], GLint nv,
 #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];
@@ -1286,7 +1212,7 @@ fxt1_quantize (GLuint *cc, const GLubyte *lines[], GLint comps)
 
    if (comps == 3) {
       /* make the whole block opaque */
-      _mesa_memset(input, -1, sizeof(input));
+      memset(input, -1, sizeof(input));
    }
 
    /* 8 texels each line */
@@ -1380,7 +1306,7 @@ fxt1_encode (GLuint width, GLuint height, GLint comps,
    if ((width & 7) | (height & 3)) {
       GLint newWidth = (width + 7) & ~7;
       GLint newHeight = (height + 3) & ~3;
-      newSource = _mesa_malloc(comps * newWidth * newHeight * sizeof(GLchan));
+      newSource = malloc(comps * newWidth * newHeight * sizeof(GLchan));
       if (!newSource) {
          GET_CURRENT_CONTEXT(ctx);
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "texture compression");
@@ -1399,7 +1325,7 @@ fxt1_encode (GLuint width, GLuint height, GLint comps,
    if (CHAN_TYPE != GL_UNSIGNED_BYTE) {
       const GLuint n = width * height * comps;
       const GLchan *src = (const GLchan *) source;
-      GLubyte *dest = (GLubyte *) _mesa_malloc(n * sizeof(GLubyte));
+      GLubyte *dest = (GLubyte *) malloc(n * sizeof(GLubyte));
       GLuint i;
       if (!dest) {
          GET_CURRENT_CONTEXT(ctx);
@@ -1410,7 +1336,7 @@ fxt1_encode (GLuint width, GLuint height, GLint comps,
          dest[i] = CHAN_TO_UBYTE(src[i]);
       }
       if (newSource != NULL) {
-         _mesa_free(newSource);
+         free(newSource);
       }
       newSource = dest;  /* we'll free this buffer before returning */
       source = dest;  /* the new, GLubyte incoming image */
@@ -1436,7 +1362,7 @@ fxt1_encode (GLuint width, GLuint height, GLint comps,
 
  cleanUp:
    if (newSource != NULL) {
-      _mesa_free(newSource);
+      free(newSource);
    }
 }
 
@@ -1722,3 +1648,6 @@ fxt1_decode_1 (const void *texture, GLint stride, /* in pixels */
 
    decode_1[mode](code, t, rgba);
 }
+
+
+#endif /* FEATURE_texture_fxt1 */