summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/texcompress_rgtc_tmp.h
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2011-03-02 14:16:39 +1000
committerDave Airlie <[email protected]>2011-03-02 14:16:39 +1000
commit531c336fa39d8e823d05728cb7ddb3cc8a44d199 (patch)
tree20583cfddb585305555d9399ba096a0cbe93b70e /src/mesa/main/texcompress_rgtc_tmp.h
parentfb6ecca0a556dcca1f77bfb84a835e2b9c2e2e6a (diff)
rgtc: move the texel fetch into common unsigned/signed code.
This function can be done in the include file also. Signed-off-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src/mesa/main/texcompress_rgtc_tmp.h')
-rw-r--r--src/mesa/main/texcompress_rgtc_tmp.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/mesa/main/texcompress_rgtc_tmp.h b/src/mesa/main/texcompress_rgtc_tmp.h
index 9377a6bd3be..404f7fe3fd2 100644
--- a/src/mesa/main/texcompress_rgtc_tmp.h
+++ b/src/mesa/main/texcompress_rgtc_tmp.h
@@ -29,6 +29,35 @@
/* included by texcompress_rgtc to define byte/ubyte compressors */
+static void TAG(fetch_texel_rgtc)(unsigned srcRowStride, const TYPE *pixdata,
+ unsigned i, unsigned j, TYPE *value, unsigned comps)
+{
+ TYPE decode;
+ const TYPE *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps);
+ const TYPE alpha0 = blksrc[0];
+ const TYPE alpha1 = blksrc[1];
+ const char bit_pos = ((j&3) * 4 + (i&3)) * 3;
+ const TYPE acodelow = blksrc[2 + bit_pos / 8];
+ const TYPE acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0;
+ const TYPE code = (acodelow >> (bit_pos & 0x7) |
+ (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7;
+
+ if (code == 0)
+ decode = alpha0;
+ else if (code == 1)
+ decode = alpha1;
+ else if (alpha0 > alpha1)
+ decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7);
+ else if (code < 6)
+ decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5);
+ else if (code == 6)
+ decode = T_MIN;
+ else
+ decode = T_MAX;
+
+ *value = decode;
+}
+
static void TAG(write_rgtc_encoded_channel)(TYPE *blkaddr,
TYPE alphabase1,
TYPE alphabase2,