[Mesa-dev] [PATCH 1/5] mesa: Fold texcompress_etc1_tmp.h into texcompress_etc.c

Chad Versace chad.versace at linux.intel.com
Mon Jul 9 10:46:56 PDT 2012


The header defined the functions in with C-style macro templates. Since
there was only one user of the header, the templates were unnecessary.
This patch redefines the functions as vanilla, non-templated functions.

This patch also removes the header and folds its contents into
texcompress_etc.c.  The header defined many inline helper functions for
texcompress_etc.c, but, since no other file included it, it never made
sense to keep the header separate from the .c file.

Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
---
 src/mesa/main/texcompress_etc.c     | 119 +++++++++++++++++++++++++++++--
 src/mesa/main/texcompress_etc_tmp.h | 136 ------------------------------------
 2 files changed, 112 insertions(+), 143 deletions(-)
 delete mode 100644 src/mesa/main/texcompress_etc_tmp.h

diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_etc.c
index 5b331a9..a5482f4 100644
--- a/src/mesa/main/texcompress_etc.c
+++ b/src/mesa/main/texcompress_etc.c
@@ -26,6 +26,7 @@
  * GL_OES_compressed_ETC1_RGB8_texture support.
  */
 
+#include <stdint.h>
 
 #include "mfeatures.h"
 #include "texcompress.h"
@@ -34,6 +35,117 @@
 #include "macros.h"
 #include "swrast/s_context.h"
 
+struct etc1_block {
+   uint32_t pixel_indices;
+   int flipped;
+   const int *modifier_tables[2];
+   uint8_t base_colors[2][3];
+};
+
+static uint8_t
+etc1_base_color_diff_hi(uint8_t in)
+{
+   return (in & 0xf8) | (in >> 5);
+}
+
+static uint8_t
+etc1_base_color_diff_lo(uint8_t in)
+{
+   static const int lookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
+
+   in = (in >> 3) + lookup[in & 0x7];
+
+   return (in << 3) | (in >> 2);
+}
+
+static uint8_t
+etc1_base_color_ind_hi(uint8_t in)
+{
+   return (in & 0xf0) | ((in & 0xf0) >> 4);
+}
+
+static uint8_t
+etc1_base_color_ind_lo(uint8_t in)
+{
+   return ((in & 0xf) << 4) | (in & 0xf);
+}
+
+static uint8_t
+etc1_clamp(uint8_t base, int modifier)
+{
+   int tmp = (int) base + modifier;
+
+   /* CLAMP(tmp, 0, 255) */
+   return (uint8_t) ((tmp < 0) ? 0 : ((tmp > 255) ? 255 : tmp));
+}
+
+static const int etc1_modifier_tables[8][4] = {
+   {  2,   8,  -2,   -8},
+   {  5,  17,  -5,  -17},
+   {  9,  29,  -9,  -29},
+   { 13,  42, -13,  -42},
+   { 18,  60, -18,  -60},
+   { 24,  80, -24,  -80},
+   { 33, 106, -33, -106},
+   { 47, 183, -47, -183}
+};
+
+static void
+etc1_parse_block(struct etc1_block *block, const uint8_t *src)
+{
+   if (src[3] & 0x2) {
+      /* differential mode */
+      block->base_colors[0][0] = (int) etc1_base_color_diff_hi(src[0]);
+      block->base_colors[1][0] = (int) etc1_base_color_diff_lo(src[0]);
+      block->base_colors[0][1] = (int) etc1_base_color_diff_hi(src[1]);
+      block->base_colors[1][1] = (int) etc1_base_color_diff_lo(src[1]);
+      block->base_colors[0][2] = (int) etc1_base_color_diff_hi(src[2]);
+      block->base_colors[1][2] = (int) etc1_base_color_diff_lo(src[2]);
+   }
+   else {
+      /* individual mode */
+      block->base_colors[0][0] = (int) etc1_base_color_ind_hi(src[0]);
+      block->base_colors[1][0] = (int) etc1_base_color_ind_lo(src[0]);
+      block->base_colors[0][1] = (int) etc1_base_color_ind_hi(src[1]);
+      block->base_colors[1][1] = (int) etc1_base_color_ind_lo(src[1]);
+      block->base_colors[0][2] = (int) etc1_base_color_ind_hi(src[2]);
+      block->base_colors[1][2] = (int) etc1_base_color_ind_lo(src[2]);
+   }
+
+   /* pick modifier tables */
+   block->modifier_tables[0] = etc1_modifier_tables[(src[3] >> 5) & 0x7];
+   block->modifier_tables[1] = etc1_modifier_tables[(src[3] >> 2) & 0x7];
+
+   block->flipped = (src[3] & 0x1);
+
+   block->pixel_indices =
+      (src[4] << 24) | (src[5] << 16) | (src[6] << 8) | src[7];
+}
+
+static void
+etc1_fetch_texel(const struct etc1_block *block,
+                 int x, int y,
+                 uint8_t *dst)
+{
+   const uint8_t *base_color;
+   int modifier, bit, idx, blk;
+
+   /* get pixel index */
+   bit = y + x * 4;
+   idx = ((block->pixel_indices >> (15 + bit)) & 0x2) |
+         ((block->pixel_indices >>      (bit)) & 0x1);
+
+   /* get subblock */
+   blk = (block->flipped) ? (y >= 2) : (x >= 2);
+
+   base_color = block->base_colors[blk];
+   modifier = block->modifier_tables[blk][idx];
+
+   dst[0] = etc1_clamp(base_color[0], modifier);
+   dst[1] = etc1_clamp(base_color[1], modifier);
+   dst[2] = etc1_clamp(base_color[2], modifier);
+}
+
 GLboolean
 _mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS)
 {
@@ -43,13 +155,6 @@ _mesa_texstore_etc1_rgb8(TEXSTORE_PARAMS)
    return GL_FALSE;
 }
 
-/* define etc1_parse_block and etc. */
-#define UINT8_TYPE GLubyte
-#define TAG(x) x
-#include "texcompress_etc_tmp.h"
-#undef TAG
-#undef UINT8_TYPE
-
 void
 _mesa_fetch_texel_2d_f_etc1_rgb8(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
diff --git a/src/mesa/main/texcompress_etc_tmp.h b/src/mesa/main/texcompress_etc_tmp.h
deleted file mode 100644
index 5c8c6de..0000000
--- a/src/mesa/main/texcompress_etc_tmp.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2011 LunarG, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of 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
- * 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.
- */
-
-/*
- * Included by texcompress_etc1 and gallium to define ETC1 decoding routines.
- */
-
-struct TAG(etc1_block) {
-   uint32_t pixel_indices;
-   int flipped;
-   const int *modifier_tables[2];
-   UINT8_TYPE base_colors[2][3];
-};
-
-static UINT8_TYPE
-TAG(etc1_base_color_diff_hi)(UINT8_TYPE in)
-{
-   return (in & 0xf8) | (in >> 5);
-}
-
-static UINT8_TYPE
-TAG(etc1_base_color_diff_lo)(UINT8_TYPE in)
-{
-   static const int lookup[8] = { 0, 1, 2, 3, -4, -3, -2, -1 };
-
-   in = (in >> 3) + lookup[in & 0x7];
-
-   return (in << 3) | (in >> 2);
-}
-
-static UINT8_TYPE
-TAG(etc1_base_color_ind_hi)(UINT8_TYPE in)
-{
-   return (in & 0xf0) | ((in & 0xf0) >> 4);
-}
-
-static UINT8_TYPE
-TAG(etc1_base_color_ind_lo)(UINT8_TYPE in)
-{
-   return ((in & 0xf) << 4) | (in & 0xf);
-}
-
-static UINT8_TYPE
-TAG(etc1_clamp)(UINT8_TYPE base, int modifier)
-{
-   int tmp = (int) base + modifier;
-
-   /* CLAMP(tmp, 0, 255) */
-   return (UINT8_TYPE) ((tmp < 0) ? 0 : ((tmp > 255) ? 255 : tmp));
-}
-
-static const int TAG(etc1_modifier_tables)[8][4] = {
-   {  2,   8,  -2,   -8},
-   {  5,  17,  -5,  -17},
-   {  9,  29,  -9,  -29},
-   { 13,  42, -13,  -42},
-   { 18,  60, -18,  -60},
-   { 24,  80, -24,  -80},
-   { 33, 106, -33, -106},
-   { 47, 183, -47, -183}
-};
-
-static void
-TAG(etc1_parse_block)(struct TAG(etc1_block) *block, const UINT8_TYPE *src)
-{
-   if (src[3] & 0x2) {
-      /* differential mode */
-      block->base_colors[0][0] = (int) TAG(etc1_base_color_diff_hi)(src[0]);
-      block->base_colors[1][0] = (int) TAG(etc1_base_color_diff_lo)(src[0]);
-      block->base_colors[0][1] = (int) TAG(etc1_base_color_diff_hi)(src[1]);
-      block->base_colors[1][1] = (int) TAG(etc1_base_color_diff_lo)(src[1]);
-      block->base_colors[0][2] = (int) TAG(etc1_base_color_diff_hi)(src[2]);
-      block->base_colors[1][2] = (int) TAG(etc1_base_color_diff_lo)(src[2]);
-   }
-   else {
-      /* individual mode */
-      block->base_colors[0][0] = (int) TAG(etc1_base_color_ind_hi)(src[0]);
-      block->base_colors[1][0] = (int) TAG(etc1_base_color_ind_lo)(src[0]);
-      block->base_colors[0][1] = (int) TAG(etc1_base_color_ind_hi)(src[1]);
-      block->base_colors[1][1] = (int) TAG(etc1_base_color_ind_lo)(src[1]);
-      block->base_colors[0][2] = (int) TAG(etc1_base_color_ind_hi)(src[2]);
-      block->base_colors[1][2] = (int) TAG(etc1_base_color_ind_lo)(src[2]);
-   }
-
-   /* pick modifier tables */
-   block->modifier_tables[0] = TAG(etc1_modifier_tables)[(src[3] >> 5) & 0x7];
-   block->modifier_tables[1] = TAG(etc1_modifier_tables)[(src[3] >> 2) & 0x7];
-
-   block->flipped = (src[3] & 0x1);
-
-   block->pixel_indices =
-      (src[4] << 24) | (src[5] << 16) | (src[6] << 8) | src[7];
-}
-
-static void
-TAG(etc1_fetch_texel)(const struct TAG(etc1_block) *block,
-      int x, int y, UINT8_TYPE *dst)
-{
-   const UINT8_TYPE *base_color;
-   int modifier, bit, idx, blk;
-
-   /* get pixel index */
-   bit = y + x * 4;
-   idx = ((block->pixel_indices >> (15 + bit)) & 0x2) |
-         ((block->pixel_indices >>      (bit)) & 0x1);
-
-   /* get subblock */
-   blk = (block->flipped) ? (y >= 2) : (x >= 2);
-
-   base_color = block->base_colors[blk];
-   modifier = block->modifier_tables[blk][idx];
-
-   dst[0] = TAG(etc1_clamp)(base_color[0], modifier);
-   dst[1] = TAG(etc1_clamp)(base_color[1], modifier);
-   dst[2] = TAG(etc1_clamp)(base_color[2], modifier);
-}
-- 
1.7.11.1



More information about the mesa-dev mailing list