<div dir="ltr"><div>Haven't looked at it too carefully because it mostly looks like a rename. Assuming it builds and you've run piglit:<br><br></div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 15, 2014 at 10:40 PM, Dave Airlie <span dir="ltr"><<a href="mailto:airlied@gmail.com" target="_blank">airlied@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
<br>
This was being shared using a ../../ get out of gallium into<br>
mesa, and I swore when I did it I'd fix things when we got a util<br>
dir, we did, so I have.<br>
<br>
Signed-off-by: Dave Airlie <<a href="mailto:airlied@redhat.com">airlied@redhat.com</a>><br>
---<br>
src/gallium/auxiliary/util/u_format_latc.c | 72 ++---<br>
src/gallium/auxiliary/util/u_format_rgtc.c | 92 ++-----<br>
src/mesa/main/texcompress_rgtc.c | 76 ++----<br>
src/mesa/main/texcompress_rgtc_tmp.h | 418 -----------------------------<br>
src/util/Makefile.sources | 3 +-<br>
src/util/rgtc.c | 59 ++++<br>
src/util/rgtc.h | 39 +++<br>
src/util/texcompress_rgtc_tmp.h | 418 +++++++++++++++++++++++++++++<br>
8 files changed, 583 insertions(+), 594 deletions(-)<br>
delete mode 100644 src/mesa/main/texcompress_rgtc_tmp.h<br>
create mode 100644 src/util/rgtc.c<br>
create mode 100644 src/util/rgtc.h<br>
create mode 100644 src/util/texcompress_rgtc_tmp.h<br>
<br>
diff --git a/src/gallium/auxiliary/util/u_format_latc.c b/src/gallium/auxiliary/util/u_format_latc.c<br>
index caab7e8..31d72b5 100644<br>
--- a/src/gallium/auxiliary/util/u_format_latc.c<br>
+++ b/src/gallium/auxiliary/util/u_format_latc.c<br>
@@ -27,27 +27,16 @@<br>
#include "u_format.h"<br>
#include "u_format_rgtc.h"<br>
#include "u_format_latc.h"<br>
-<br>
-static void u_format_unsigned_encode_rgtc_ubyte(uint8_t *blkaddr, uint8_t srccolors[4][4],<br>
- int numxpixels, int numypixels);<br>
-<br>
-static void u_format_unsigned_fetch_texel_rgtc(unsigned srcRowStride, const uint8_t *pixdata,<br>
- unsigned i, unsigned j, uint8_t *value, unsigned comps);<br>
-<br>
-static void u_format_signed_encode_rgtc_ubyte(int8_t *blkaddr, int8_t srccolors[4][4],<br>
- int numxpixels, int numypixels);<br>
-<br>
-static void u_format_signed_fetch_texel_rgtc(unsigned srcRowStride, const int8_t *pixdata,<br>
- unsigned i, unsigned j, int8_t *value, unsigned comps);<br>
+#include "util/rgtc.h"<br>
<br>
void<br>
util_format_latc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)<br>
{<br>
/* Fix warnings here: */<br>
- (void) u_format_unsigned_encode_rgtc_ubyte;<br>
- (void) u_format_signed_encode_rgtc_ubyte;<br>
+ (void) util_format_unsigned_encode_rgtc_ubyte;<br>
+ (void) util_format_signed_encode_rgtc_ubyte;<br>
<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);<br>
dst[1] = dst[0];<br>
dst[2] = dst[0];<br>
dst[3] = 255;<br>
@@ -79,7 +68,7 @@ util_format_latc1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, c<br>
for(i = 0; i < 4; ++i) {<br>
float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;<br>
uint8_t tmp_r;<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
dst[0] =<br>
dst[1] =<br>
dst[2] = ubyte_to_float(tmp_r);<br>
@@ -103,7 +92,7 @@ util_format_latc1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigne<br>
{<br>
uint8_t tmp_r;<br>
<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
dst[0] =<br>
dst[1] =<br>
dst[2] = ubyte_to_float(tmp_r);<br>
@@ -147,7 +136,7 @@ util_format_latc1_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, c<br>
for(i = 0; i < 4; ++i) {<br>
float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;<br>
int8_t tmp_r;<br>
- u_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
+ util_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
dst[0] =<br>
dst[1] =<br>
dst[2] = byte_to_float_tex(tmp_r);<br>
@@ -165,7 +154,7 @@ util_format_latc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigne<br>
{<br>
int8_t tmp_r;<br>
<br>
- u_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 1);<br>
+ util_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 1);<br>
dst[0] =<br>
dst[1] =<br>
dst[2] = byte_to_float_tex(tmp_r);<br>
@@ -176,10 +165,10 @@ util_format_latc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigne<br>
void<br>
util_format_latc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)<br>
{<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);<br>
dst[1] = dst[0];<br>
dst[2] = dst[0];<br>
- u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 3, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 3, 2);<br>
}<br>
<br>
void<br>
@@ -213,8 +202,8 @@ util_format_latc2_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, c<br>
for(i = 0; i < 4; ++i) {<br>
float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;<br>
uint8_t tmp_r, tmp_g;<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
- u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
dst[0] =<br>
dst[1] =<br>
dst[2] = ubyte_to_float(tmp_r);<br>
@@ -232,8 +221,8 @@ util_format_latc2_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigne<br>
{<br>
uint8_t tmp_r, tmp_g;<br>
<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
- u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
dst[0] =<br>
dst[1] =<br>
dst[2] = ubyte_to_float(tmp_r);<br>
@@ -272,8 +261,8 @@ util_format_latc2_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, c<br>
for(i = 0; i < 4; ++i) {<br>
float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;<br>
int8_t tmp_r, tmp_g;<br>
- u_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
- u_format_signed_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
+ util_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
+ util_format_signed_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
dst[0] =<br>
dst[1] =<br>
dst[2] = byte_to_float_tex(tmp_r);<br>
@@ -297,36 +286,11 @@ util_format_latc2_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigne<br>
{<br>
int8_t tmp_r, tmp_g;<br>
<br>
- u_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 2);<br>
- u_format_signed_fetch_texel_rgtc(0, (int8_t *)src + 8, i, j, &tmp_g, 2);<br>
+ util_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 2);<br>
+ util_format_signed_fetch_texel_rgtc(0, (int8_t *)src + 8, i, j, &tmp_g, 2);<br>
dst[0] =<br>
dst[1] =<br>
dst[2] = byte_to_float_tex(tmp_r);<br>
dst[3] = byte_to_float_tex(tmp_g);<br>
}<br>
<br>
-<br>
-#define TAG(x) u_format_unsigned_##x<br>
-#define TYPE uint8_t<br>
-#define T_MIN 0<br>
-#define T_MAX 255<br>
-<br>
-#include "../../../mesa/main/texcompress_rgtc_tmp.h"<br>
-<br>
-#undef TYPE<br>
-#undef TAG<br>
-#undef T_MIN<br>
-#undef T_MAX<br>
-<br>
-<br>
-#define TAG(x) u_format_signed_##x<br>
-#define TYPE int8_t<br>
-#define T_MIN (int8_t)-128<br>
-#define T_MAX (int8_t)127<br>
-<br>
-#include "../../../mesa/main/texcompress_rgtc_tmp.h"<br>
-<br>
-#undef TYPE<br>
-#undef TAG<br>
-#undef T_MIN<br>
-#undef T_MAX<br>
diff --git a/src/gallium/auxiliary/util/u_format_rgtc.c b/src/gallium/auxiliary/util/u_format_rgtc.c<br>
index 758e337..1596917 100644<br>
--- a/src/gallium/auxiliary/util/u_format_rgtc.c<br>
+++ b/src/gallium/auxiliary/util/u_format_rgtc.c<br>
@@ -26,23 +26,12 @@<br>
#include "u_math.h"<br>
#include "u_format.h"<br>
#include "u_format_rgtc.h"<br>
-<br>
-static void u_format_unsigned_encode_rgtc_ubyte(uint8_t *blkaddr, uint8_t srccolors[4][4],<br>
- int numxpixels, int numypixels);<br>
-<br>
-static void u_format_unsigned_fetch_texel_rgtc(unsigned srcRowStride, const uint8_t *pixdata,<br>
- unsigned i, unsigned j, uint8_t *value, unsigned comps);<br>
-<br>
-static void u_format_signed_encode_rgtc_ubyte(int8_t *blkaddr, int8_t srccolors[4][4],<br>
- int numxpixels, int numypixels);<br>
-<br>
-static void u_format_signed_fetch_texel_rgtc(unsigned srcRowStride, const int8_t *pixdata,<br>
- unsigned i, unsigned j, int8_t *value, unsigned comps);<br>
+#include "util/rgtc.h"<br>
<br>
void<br>
util_format_rgtc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)<br>
{<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);<br>
dst[1] = 0;<br>
dst[2] = 0;<br>
dst[3] = 255;<br>
@@ -61,7 +50,7 @@ util_format_rgtc1_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride<br>
for(j = 0; j < bh; ++j) {<br>
for(i = 0; i < bw; ++i) {<br>
uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*comps;<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);<br>
dst[1] = 0;<br>
dst[2] = 0;<br>
dst[3] = 255;<br>
@@ -89,7 +78,7 @@ util_format_rgtc1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,<br>
tmp[j][i] = src_row[(y + j)*src_stride/sizeof(*src_row) + (x + i)*4];<br>
}<br>
}<br>
- u_format_unsigned_encode_rgtc_ubyte(dst, tmp, 4, 4);<br>
+ util_format_unsigned_encode_rgtc_ubyte(dst, tmp, 4, 4);<br>
dst += bytes_per_block;<br>
}<br>
dst_row += dst_stride / sizeof(*dst_row);<br>
@@ -108,7 +97,7 @@ util_format_rgtc1_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, c<br>
for(i = 0; i < 4; ++i) {<br>
float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;<br>
uint8_t tmp_r;<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
dst[0] = ubyte_to_float(tmp_r);<br>
dst[1] = 0.0;<br>
dst[2] = 0.0;<br>
@@ -136,7 +125,7 @@ util_format_rgtc1_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, c<br>
tmp[j][i] = float_to_ubyte(src_row[(y + j)*src_stride/sizeof(*src_row) + (x + i)*4]);<br>
}<br>
}<br>
- u_format_unsigned_encode_rgtc_ubyte(dst, tmp, 4, 4);<br>
+ util_format_unsigned_encode_rgtc_ubyte(dst, tmp, 4, 4);<br>
dst += bytes_per_block;<br>
}<br>
dst_row += dst_stride / sizeof(*dst_row);<br>
@@ -147,7 +136,7 @@ void<br>
util_format_rgtc1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)<br>
{<br>
uint8_t tmp_r;<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
dst[0] = ubyte_to_float(tmp_r);<br>
dst[1] = 0.0;<br>
dst[2] = 0.0;<br>
@@ -187,7 +176,7 @@ util_format_rgtc1_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, c<br>
tmp[j][i] = float_to_byte_tex(src_row[(y + j)*src_stride/sizeof(*src_row) + (x + i)*4]);<br>
}<br>
}<br>
- u_format_signed_encode_rgtc_ubyte(dst, tmp, 4, 4);<br>
+ util_format_signed_encode_rgtc_ubyte(dst, tmp, 4, 4);<br>
dst += bytes_per_block;<br>
}<br>
dst_row += dst_stride / sizeof(*dst_row);<br>
@@ -206,7 +195,7 @@ util_format_rgtc1_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, c<br>
for(i = 0; i < 4; ++i) {<br>
float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;<br>
int8_t tmp_r;<br>
- u_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
+ util_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);<br>
dst[0] = byte_to_float_tex(tmp_r);<br>
dst[1] = 0.0;<br>
dst[2] = 0.0;<br>
@@ -223,7 +212,7 @@ void<br>
util_format_rgtc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)<br>
{<br>
int8_t tmp_r;<br>
- u_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 1);<br>
+ util_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 1);<br>
dst[0] = byte_to_float_tex(tmp_r);<br>
dst[1] = 0.0;<br>
dst[2] = 0.0;<br>
@@ -234,8 +223,8 @@ util_format_rgtc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigne<br>
void<br>
util_format_rgtc2_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)<br>
{<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);<br>
- u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 2);<br>
dst[2] = 0;<br>
dst[3] = 255;<br>
}<br>
@@ -253,8 +242,8 @@ util_format_rgtc2_unorm_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride<br>
for(j = 0; j < bh; ++j) {<br>
for(i = 0; i < bw; ++i) {<br>
uint8_t *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*comps;<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);<br>
- u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 2);<br>
dst[2] = 0;<br>
dst[3] = 255;<br>
}<br>
@@ -282,8 +271,8 @@ util_format_rgtc2_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride,<br>
tmp_g[j][i] = src_row[((y + j)*src_stride/sizeof(*src_row) + (x + i)*4) + 1];<br>
}<br>
}<br>
- u_format_unsigned_encode_rgtc_ubyte(dst, tmp_r, 4, 4);<br>
- u_format_unsigned_encode_rgtc_ubyte(dst + 8, tmp_g, 4, 4);<br>
+ util_format_unsigned_encode_rgtc_ubyte(dst, tmp_r, 4, 4);<br>
+ util_format_unsigned_encode_rgtc_ubyte(dst + 8, tmp_g, 4, 4);<br>
dst += bytes_per_block;<br>
}<br>
dst_row += dst_stride / sizeof(*dst_row);<br>
@@ -307,8 +296,8 @@ util_format_rxtc2_unorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, c<br>
tmp_g[j][i] = float_to_ubyte(src_row[(y + j)*src_stride/sizeof(*src_row) + (x + i)*4 + chan2off]);<br>
}<br>
}<br>
- u_format_unsigned_encode_rgtc_ubyte(dst, tmp_r, 4, 4);<br>
- u_format_unsigned_encode_rgtc_ubyte(dst + 8, tmp_g, 4, 4);<br>
+ util_format_unsigned_encode_rgtc_ubyte(dst, tmp_r, 4, 4);<br>
+ util_format_unsigned_encode_rgtc_ubyte(dst + 8, tmp_g, 4, 4);<br>
dst += bytes_per_block;<br>
}<br>
dst_row += dst_stride / sizeof(*dst_row);<br>
@@ -333,8 +322,8 @@ util_format_rgtc2_unorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, c<br>
for(i = 0; i < 4; ++i) {<br>
float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;<br>
uint8_t tmp_r, tmp_g;<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
- u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
dst[0] = ubyte_to_float(tmp_r);<br>
dst[1] = ubyte_to_float(tmp_g);<br>
dst[2] = 0.0;<br>
@@ -351,8 +340,8 @@ void<br>
util_format_rgtc2_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)<br>
{<br>
uint8_t tmp_r, tmp_g;<br>
- u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
- u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
+ util_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
dst[0] = ubyte_to_float(tmp_r);<br>
dst[1] = ubyte_to_float(tmp_g);<br>
dst[2] = 0.0;<br>
@@ -390,8 +379,8 @@ util_format_rgtc2_snorm_unpack_rgba_float(float *dst_row, unsigned dst_stride, c<br>
for(i = 0; i < 4; ++i) {<br>
float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;<br>
int8_t tmp_r, tmp_g;<br>
- u_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
- u_format_signed_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
+ util_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);<br>
+ util_format_signed_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);<br>
dst[0] = byte_to_float_tex(tmp_r);<br>
dst[1] = byte_to_float_tex(tmp_g);<br>
dst[2] = 0.0;<br>
@@ -421,8 +410,8 @@ util_format_rxtc2_snorm_pack_rgba_float(uint8_t *dst_row, unsigned dst_stride, c<br>
tmp_g[j][i] = float_to_byte_tex(src_row[(y + j)*src_stride/sizeof(*src_row) + (x + i)*4 + chan2off]);<br>
}<br>
}<br>
- u_format_signed_encode_rgtc_ubyte(dst, tmp_r, 4, 4);<br>
- u_format_signed_encode_rgtc_ubyte(dst + 8, tmp_g, 4, 4);<br>
+ util_format_signed_encode_rgtc_ubyte(dst, tmp_r, 4, 4);<br>
+ util_format_signed_encode_rgtc_ubyte(dst + 8, tmp_g, 4, 4);<br>
dst += bytes_per_block;<br>
}<br>
dst_row += dst_stride / sizeof(*dst_row);<br>
@@ -439,36 +428,11 @@ void<br>
util_format_rgtc2_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)<br>
{<br>
int8_t tmp_r, tmp_g;<br>
- u_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 2);<br>
- u_format_signed_fetch_texel_rgtc(0, (int8_t *)src + 8, i, j, &tmp_g, 2);<br>
+ util_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 2);<br>
+ util_format_signed_fetch_texel_rgtc(0, (int8_t *)src + 8, i, j, &tmp_g, 2);<br>
dst[0] = byte_to_float_tex(tmp_r);<br>
dst[1] = byte_to_float_tex(tmp_g);<br>
dst[2] = 0.0;<br>
dst[3] = 1.0;<br>
}<br>
<br>
-<br>
-#define TAG(x) u_format_unsigned_##x<br>
-#define TYPE uint8_t<br>
-#define T_MIN 0<br>
-#define T_MAX 255<br>
-<br>
-#include "../../../mesa/main/texcompress_rgtc_tmp.h"<br>
-<br>
-#undef TYPE<br>
-#undef TAG<br>
-#undef T_MIN<br>
-#undef T_MAX<br>
-<br>
-<br>
-#define TAG(x) u_format_signed_##x<br>
-#define TYPE int8_t<br>
-#define T_MIN (int8_t)-128<br>
-#define T_MAX (int8_t)127<br>
-<br>
-#include "../../../mesa/main/texcompress_rgtc_tmp.h"<br>
-<br>
-#undef TYPE<br>
-#undef TAG<br>
-#undef T_MIN<br>
-#undef T_MAX<br>
diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c<br>
index 1012699..c8325c3 100644<br>
--- a/src/mesa/main/texcompress_rgtc.c<br>
+++ b/src/mesa/main/texcompress_rgtc.c<br>
@@ -40,23 +40,13 @@<br>
#include "macros.h"<br>
#include "mipmap.h"<br>
#include "texcompress.h"<br>
+#include "util/rgtc.h"<br>
#include "texcompress_rgtc.h"<br>
#include "texstore.h"<br>
<br>
<br>
#define RGTC_DEBUG 0<br>
<br>
-static void unsigned_encode_rgtc_ubyte(GLubyte *blkaddr, GLubyte srccolors[4][4],<br>
- GLint numxpixels, GLint numypixels);<br>
-static void signed_encode_rgtc_ubyte(GLbyte *blkaddr, GLbyte srccolors[4][4],<br>
- GLint numxpixels, GLint numypixels);<br>
-<br>
-static void unsigned_fetch_texel_rgtc(unsigned srcRowStride, const GLubyte *pixdata,<br>
- unsigned i, unsigned j, GLubyte *value, unsigned comps);<br>
-<br>
-static void signed_fetch_texel_rgtc(unsigned srcRowStride, const GLbyte *pixdata,<br>
- unsigned i, unsigned j, GLbyte *value, unsigned comps);<br>
-<br>
static void extractsrc_u( GLubyte srcpixels[4][4], const GLubyte *srcaddr,<br>
GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps)<br>
{<br>
@@ -121,7 +111,7 @@ _mesa_texstore_red_rgtc1(TEXSTORE_PARAMS)<br>
if (srcWidth > i + 3) numxpixels = 4;<br>
else numxpixels = srcWidth - i;<br>
extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1);<br>
- unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
+ util_format_unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
srcaddr += numxpixels;<br>
blkaddr += 8;<br>
}<br>
@@ -168,7 +158,7 @@ _mesa_texstore_signed_red_rgtc1(TEXSTORE_PARAMS)<br>
if (srcWidth > i + 3) numxpixels = 4;<br>
else numxpixels = srcWidth - i;<br>
extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 1);<br>
- signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
+ util_format_signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
srcaddr += numxpixels;<br>
blkaddr += 8;<br>
}<br>
@@ -216,11 +206,11 @@ _mesa_texstore_rg_rgtc2(TEXSTORE_PARAMS)<br>
if (srcWidth > i + 3) numxpixels = 4;<br>
else numxpixels = srcWidth - i;<br>
extractsrc_u(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2);<br>
- unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
+ util_format_unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
<br>
blkaddr += 8;<br>
extractsrc_u(srcpixels, (GLubyte *)srcaddr + 1, srcWidth, numxpixels, numypixels, 2);<br>
- unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
+ util_format_unsigned_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
<br>
blkaddr += 8;<br>
<br>
@@ -271,11 +261,11 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS)<br>
else numxpixels = srcWidth - i;<br>
<br>
extractsrc_s(srcpixels, srcaddr, srcWidth, numxpixels, numypixels, 2);<br>
- signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
+ util_format_signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
blkaddr += 8;<br>
<br>
extractsrc_s(srcpixels, srcaddr + 1, srcWidth, numxpixels, numypixels, 2);<br>
- signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
+ util_format_signed_encode_rgtc_ubyte(blkaddr, srcpixels, numxpixels, numypixels);<br>
blkaddr += 8;<br>
<br>
srcaddr += numxpixels * 2;<br>
@@ -289,40 +279,12 @@ _mesa_texstore_signed_rg_rgtc2(TEXSTORE_PARAMS)<br>
return GL_TRUE;<br>
}<br>
<br>
-<br>
-#define TAG(x) unsigned_##x<br>
-<br>
-#define TYPE GLubyte<br>
-#define T_MIN 0<br>
-#define T_MAX 0xff<br>
-<br>
-#include "texcompress_rgtc_tmp.h"<br>
-<br>
-#undef TAG<br>
-#undef TYPE<br>
-#undef T_MIN<br>
-#undef T_MAX<br>
-<br>
-#define TAG(x) signed_##x<br>
-#define TYPE GLbyte<br>
-#define T_MIN (GLbyte)-128<br>
-#define T_MAX (GLbyte)127<br>
-<br>
-#include "texcompress_rgtc_tmp.h"<br>
-<br>
-#undef TAG<br>
-#undef TYPE<br>
-#undef T_MIN<br>
-#undef T_MAX<br>
-<br>
-<br>
-<br>
static void<br>
fetch_red_rgtc1(const GLubyte *map,<br>
GLint rowStride, GLint i, GLint j, GLfloat *texel)<br>
{<br>
GLubyte red;<br>
- unsigned_fetch_texel_rgtc(rowStride, map, i, j, &red, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(rowStride, map, i, j, &red, 1);<br>
texel[RCOMP] = UBYTE_TO_FLOAT(red);<br>
texel[GCOMP] = 0.0;<br>
texel[BCOMP] = 0.0;<br>
@@ -334,7 +296,7 @@ fetch_l_latc1(const GLubyte *map,<br>
GLint rowStride, GLint i, GLint j, GLfloat *texel)<br>
{<br>
GLubyte red;<br>
- unsigned_fetch_texel_rgtc(rowStride, map, i, j, &red, 1);<br>
+ util_format_unsigned_fetch_texel_rgtc(rowStride, map, i, j, &red, 1);<br>
texel[RCOMP] =<br>
texel[GCOMP] =<br>
texel[BCOMP] = UBYTE_TO_FLOAT(red);<br>
@@ -346,7 +308,7 @@ fetch_signed_red_rgtc1(const GLubyte *map,<br>
GLint rowStride, GLint i, GLint j, GLfloat *texel)<br>
{<br>
GLbyte red;<br>
- signed_fetch_texel_rgtc(rowStride, (const GLbyte *) map,<br>
+ util_format_signed_fetch_texel_rgtc(rowStride, (const GLbyte *) map,<br>
i, j, &red, 1);<br>
texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);<br>
texel[GCOMP] = 0.0;<br>
@@ -359,7 +321,7 @@ fetch_signed_l_latc1(const GLubyte *map,<br>
GLint rowStride, GLint i, GLint j, GLfloat *texel)<br>
{<br>
GLbyte red;<br>
- signed_fetch_texel_rgtc(rowStride, (GLbyte *) map,<br>
+ util_format_signed_fetch_texel_rgtc(rowStride, (GLbyte *) map,<br>
i, j, &red, 1);<br>
texel[RCOMP] =<br>
texel[GCOMP] =<br>
@@ -372,10 +334,10 @@ fetch_rg_rgtc2(const GLubyte *map,<br>
GLint rowStride, GLint i, GLint j, GLfloat *texel)<br>
{<br>
GLubyte red, green;<br>
- unsigned_fetch_texel_rgtc(rowStride,<br>
+ util_format_unsigned_fetch_texel_rgtc(rowStride,<br>
map,<br>
i, j, &red, 2);<br>
- unsigned_fetch_texel_rgtc(rowStride,<br>
+ util_format_unsigned_fetch_texel_rgtc(rowStride,<br>
map + 8,<br>
i, j, &green, 2);<br>
texel[RCOMP] = UBYTE_TO_FLOAT(red);<br>
@@ -389,10 +351,10 @@ fetch_la_latc2(const GLubyte *map,<br>
GLint rowStride, GLint i, GLint j, GLfloat *texel)<br>
{<br>
GLubyte red, green;<br>
- unsigned_fetch_texel_rgtc(rowStride,<br>
+ util_format_unsigned_fetch_texel_rgtc(rowStride,<br>
map,<br>
i, j, &red, 2);<br>
- unsigned_fetch_texel_rgtc(rowStride,<br>
+ util_format_unsigned_fetch_texel_rgtc(rowStride,<br>
map + 8,<br>
i, j, &green, 2);<br>
texel[RCOMP] =<br>
@@ -407,10 +369,10 @@ fetch_signed_rg_rgtc2(const GLubyte *map,<br>
GLint rowStride, GLint i, GLint j, GLfloat *texel)<br>
{<br>
GLbyte red, green;<br>
- signed_fetch_texel_rgtc(rowStride,<br>
+ util_format_signed_fetch_texel_rgtc(rowStride,<br>
(GLbyte *) map,<br>
i, j, &red, 2);<br>
- signed_fetch_texel_rgtc(rowStride,<br>
+ util_format_signed_fetch_texel_rgtc(rowStride,<br>
(GLbyte *) map + 8,<br>
i, j, &green, 2);<br>
texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);<br>
@@ -425,10 +387,10 @@ fetch_signed_la_latc2(const GLubyte *map,<br>
GLint rowStride, GLint i, GLint j, GLfloat *texel)<br>
{<br>
GLbyte red, green;<br>
- signed_fetch_texel_rgtc(rowStride,<br>
+ util_format_signed_fetch_texel_rgtc(rowStride,<br>
(GLbyte *) map,<br>
i, j, &red, 2);<br>
- signed_fetch_texel_rgtc(rowStride,<br>
+ util_format_signed_fetch_texel_rgtc(rowStride,<br>
(GLbyte *) map + 8,<br>
i, j, &green, 2);<br>
texel[RCOMP] =<br>
diff --git a/src/mesa/main/texcompress_rgtc_tmp.h b/src/mesa/main/texcompress_rgtc_tmp.h<br>
deleted file mode 100644<br>
index 5fa9de6..0000000<br>
--- a/src/mesa/main/texcompress_rgtc_tmp.h<br>
+++ /dev/null<br>
@@ -1,418 +0,0 @@<br>
-/*<br>
- * Copyright (C) 2011 Red Hat Inc.<br>
- *<br>
- * block compression parts are:<br>
- * Copyright (C) 2004 Roland Scheidegger All Rights Reserved.<br>
- *<br>
- * Permission is hereby granted, free of charge, to any person obtaining a<br>
- * copy of this software and associated documentation files (the "Software"),<br>
- * to deal in the Software without restriction, including without limitation<br>
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
- * and/or sell copies of the Software, and to permit persons to whom the<br>
- * Software is furnished to do so, subject to the following conditions:<br>
- *<br>
- * The above copyright notice and this permission notice (including the next<br>
- * paragraph) shall be included in all copies or substantial portions of the<br>
- * Software.<br>
- *<br>
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
- * DEALINGS IN THE SOFTWARE.<br>
- *<br>
- * Author:<br>
- * Dave Airlie<br>
- */<br>
-<br>
-/* included by texcompress_rgtc to define byte/ubyte compressors */<br>
-<br>
-static void TAG(fetch_texel_rgtc)(unsigned srcRowStride, const TYPE *pixdata,<br>
- unsigned i, unsigned j, TYPE *value, unsigned comps)<br>
-{<br>
- TYPE decode;<br>
- const TYPE *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps);<br>
- const TYPE alpha0 = blksrc[0];<br>
- const TYPE alpha1 = blksrc[1];<br>
- const char bit_pos = ((j&3) * 4 + (i&3)) * 3;<br>
- const unsigned char acodelow = blksrc[2 + bit_pos / 8];<br>
- const unsigned char acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0;<br>
- const unsigned char code = (acodelow >> (bit_pos & 0x7) |<br>
- (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7;<br>
-<br>
- if (code == 0)<br>
- decode = alpha0;<br>
- else if (code == 1)<br>
- decode = alpha1;<br>
- else if (alpha0 > alpha1)<br>
- decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7);<br>
- else if (code < 6)<br>
- decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5);<br>
- else if (code == 6)<br>
- decode = T_MIN;<br>
- else<br>
- decode = T_MAX;<br>
-<br>
- *value = decode;<br>
-}<br>
-<br>
-static void TAG(write_rgtc_encoded_channel)(TYPE *blkaddr,<br>
- TYPE alphabase1,<br>
- TYPE alphabase2,<br>
- TYPE alphaenc[16])<br>
-{<br>
- *blkaddr++ = alphabase1;<br>
- *blkaddr++ = alphabase2;<br>
- *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6);<br>
- *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7);<br>
- *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5);<br>
- *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6);<br>
- *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7);<br>
- *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5);<br>
-}<br>
-<br>
-static void TAG(encode_rgtc_ubyte)(TYPE *blkaddr, TYPE srccolors[4][4],<br>
- int numxpixels, int numypixels)<br>
-{<br>
- TYPE alphabase[2], alphause[2];<br>
- short alphatest[2] = { 0 };<br>
- unsigned int alphablockerror1, alphablockerror2, alphablockerror3;<br>
- TYPE i, j, aindex, acutValues[7];<br>
- TYPE alphaenc1[16], alphaenc2[16], alphaenc3[16];<br>
- int alphaabsmin = 0, alphaabsmax = 0;<br>
- short alphadist;<br>
-<br>
- /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */<br>
- alphabase[0] = T_MAX; alphabase[1] = T_MIN;<br>
- for (j = 0; j < numypixels; j++) {<br>
- for (i = 0; i < numxpixels; i++) {<br>
- if (srccolors[j][i] == T_MIN)<br>
- alphaabsmin = 1;<br>
- else if (srccolors[j][i] == T_MAX)<br>
- alphaabsmax = 1;<br>
- else {<br>
- if (srccolors[j][i] > alphabase[1])<br>
- alphabase[1] = srccolors[j][i];<br>
- if (srccolors[j][i] < alphabase[0])<br>
- alphabase[0] = srccolors[j][i];<br>
- }<br>
- }<br>
- }<br>
-<br>
-<br>
- if (((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax))<br>
- || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax)) { /* one color, either max or min */<br>
- /* shortcut here since it is a very common case (and also avoids later problems) */<br>
- /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */<br>
-<br>
- *blkaddr++ = srccolors[0][0];<br>
- blkaddr++;<br>
- *blkaddr++ = 0;<br>
- *blkaddr++ = 0;<br>
- *blkaddr++ = 0;<br>
- *blkaddr++ = 0;<br>
- *blkaddr++ = 0;<br>
- *blkaddr++ = 0;<br>
-#if RGTC_DEBUG<br>
- fprintf(stderr, "enc0 used\n");<br>
-#endif<br>
- return;<br>
- }<br>
-<br>
- /* find best encoding for alpha0 > alpha1 */<br>
- /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */<br>
- alphablockerror1 = 0x0;<br>
- alphablockerror2 = 0xffffffff;<br>
- alphablockerror3 = 0xffffffff;<br>
- if (alphaabsmin) alphause[0] = T_MIN;<br>
- else alphause[0] = alphabase[0];<br>
- if (alphaabsmax) alphause[1] = T_MAX;<br>
- else alphause[1] = alphabase[1];<br>
- /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */<br>
- for (aindex = 0; aindex < 7; aindex++) {<br>
- /* don't forget here is always rounded down */<br>
- acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14;<br>
- }<br>
-<br>
- for (j = 0; j < numypixels; j++) {<br>
- for (i = 0; i < numxpixels; i++) {<br>
- /* maybe it's overkill to have the most complicated calculation just for the error<br>
- calculation which we only need to figure out if encoding1 or encoding2 is better... */<br>
- if (srccolors[j][i] > acutValues[0]) {<br>
- alphaenc1[4*j + i] = 0;<br>
- alphadist = srccolors[j][i] - alphause[1];<br>
- }<br>
- else if (srccolors[j][i] > acutValues[1]) {<br>
- alphaenc1[4*j + i] = 2;<br>
- alphadist = srccolors[j][i] - (alphause[1] * 6 + alphause[0] * 1) / 7;<br>
- }<br>
- else if (srccolors[j][i] > acutValues[2]) {<br>
- alphaenc1[4*j + i] = 3;<br>
- alphadist = srccolors[j][i] - (alphause[1] * 5 + alphause[0] * 2) / 7;<br>
- }<br>
- else if (srccolors[j][i] > acutValues[3]) {<br>
- alphaenc1[4*j + i] = 4;<br>
- alphadist = srccolors[j][i] - (alphause[1] * 4 + alphause[0] * 3) / 7;<br>
- }<br>
- else if (srccolors[j][i] > acutValues[4]) {<br>
- alphaenc1[4*j + i] = 5;<br>
- alphadist = srccolors[j][i] - (alphause[1] * 3 + alphause[0] * 4) / 7;<br>
- }<br>
- else if (srccolors[j][i] > acutValues[5]) {<br>
- alphaenc1[4*j + i] = 6;<br>
- alphadist = srccolors[j][i] - (alphause[1] * 2 + alphause[0] * 5) / 7;<br>
- }<br>
- else if (srccolors[j][i] > acutValues[6]) {<br>
- alphaenc1[4*j + i] = 7;<br>
- alphadist = srccolors[j][i] - (alphause[1] * 1 + alphause[0] * 6) / 7;<br>
- }<br>
- else {<br>
- alphaenc1[4*j + i] = 1;<br>
- alphadist = srccolors[j][i] - alphause[0];<br>
- }<br>
- alphablockerror1 += alphadist * alphadist;<br>
- }<br>
- }<br>
-<br>
-#if RGTC_DEBUG<br>
- for (i = 0; i < 16; i++) {<br>
- fprintf(stderr, "%d ", alphaenc1[i]);<br>
- }<br>
- fprintf(stderr, "cutVals ");<br>
- for (i = 0; i < 7; i++) {<br>
- fprintf(stderr, "%d ", acutValues[i]);<br>
- }<br>
- fprintf(stderr, "srcVals ");<br>
- for (j = 0; j < numypixels; j++) {<br>
- for (i = 0; i < numxpixels; i++) {<br>
- fprintf(stderr, "%d ", srccolors[j][i]);<br>
- }<br>
- }<br>
- fprintf(stderr, "\n");<br>
-#endif<br>
-<br>
- /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax<br>
- are false but try it anyway */<br>
- if (alphablockerror1 >= 32) {<br>
-<br>
- /* don't bother if encoding is already very good, this condition should also imply<br>
- we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */<br>
- alphablockerror2 = 0;<br>
- for (aindex = 0; aindex < 5; aindex++) {<br>
- /* don't forget here is always rounded down */<br>
- acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10;<br>
- }<br>
- for (j = 0; j < numypixels; j++) {<br>
- for (i = 0; i < numxpixels; i++) {<br>
- /* maybe it's overkill to have the most complicated calculation just for the error<br>
- calculation which we only need to figure out if encoding1 or encoding2 is better... */<br>
- if (srccolors[j][i] == T_MIN) {<br>
- alphaenc2[4*j + i] = 6;<br>
- alphadist = 0;<br>
- }<br>
- else if (srccolors[j][i] == T_MAX) {<br>
- alphaenc2[4*j + i] = 7;<br>
- alphadist = 0;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[0]) {<br>
- alphaenc2[4*j + i] = 0;<br>
- alphadist = srccolors[j][i] - alphabase[0];<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[1]) {<br>
- alphaenc2[4*j + i] = 2;<br>
- alphadist = srccolors[j][i] - (alphabase[0] * 4 + alphabase[1] * 1) / 5;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[2]) {<br>
- alphaenc2[4*j + i] = 3;<br>
- alphadist = srccolors[j][i] - (alphabase[0] * 3 + alphabase[1] * 2) / 5;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[3]) {<br>
- alphaenc2[4*j + i] = 4;<br>
- alphadist = srccolors[j][i] - (alphabase[0] * 2 + alphabase[1] * 3) / 5;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[4]) {<br>
- alphaenc2[4*j + i] = 5;<br>
- alphadist = srccolors[j][i] - (alphabase[0] * 1 + alphabase[1] * 4) / 5;<br>
- }<br>
- else {<br>
- alphaenc2[4*j + i] = 1;<br>
- alphadist = srccolors[j][i] - alphabase[1];<br>
- }<br>
- alphablockerror2 += alphadist * alphadist;<br>
- }<br>
- }<br>
-<br>
-<br>
- /* skip this if the error is already very small<br>
- this encoding is MUCH better on average than #2 though, but expensive! */<br>
- if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) {<br>
- short blockerrlin1 = 0;<br>
- short blockerrlin2 = 0;<br>
- TYPE nralphainrangelow = 0;<br>
- TYPE nralphainrangehigh = 0;<br>
- alphatest[0] = T_MAX;<br>
- alphatest[1] = T_MIN;<br>
- /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */<br>
- for (j = 0; j < numypixels; j++) {<br>
- for (i = 0; i < numxpixels; i++) {<br>
- if ((srccolors[j][i] > alphatest[1]) && (srccolors[j][i] < (T_MAX -(alphabase[1] - alphabase[0]) / 28)))<br>
- alphatest[1] = srccolors[j][i];<br>
- if ((srccolors[j][i] < alphatest[0]) && (srccolors[j][i] > (alphabase[1] - alphabase[0]) / 28))<br>
- alphatest[0] = srccolors[j][i];<br>
- }<br>
- }<br>
- /* shouldn't happen too often, don't really care about those degenerated cases */<br>
- if (alphatest[1] <= alphatest[0]) {<br>
- alphatest[0] = T_MIN+1;<br>
- alphatest[1] = T_MAX-1;<br>
- }<br>
- for (aindex = 0; aindex < 5; aindex++) {<br>
- /* don't forget here is always rounded down */<br>
- acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;<br>
- }<br>
-<br>
- /* find the "average" difference between the alpha values and the next encoded value.<br>
- This is then used to calculate new base values.<br>
- Should there be some weighting, i.e. those values closer to alphatest[x] have more weight,<br>
- since they will see more improvement, and also because the values in the middle are somewhat<br>
- likely to get no improvement at all (because the base values might move in different directions)?<br>
- OTOH it would mean the values in the middle are even less likely to get an improvement<br>
- */<br>
- for (j = 0; j < numypixels; j++) {<br>
- for (i = 0; i < numxpixels; i++) {<br>
- if (srccolors[j][i] <= alphatest[0] / 2) {<br>
- }<br>
- else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) {<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[0]) {<br>
- blockerrlin1 += (srccolors[j][i] - alphatest[0]);<br>
- nralphainrangelow += 1;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[1]) {<br>
- blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);<br>
- blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);<br>
- nralphainrangelow += 1;<br>
- nralphainrangehigh += 1;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[2]) {<br>
- blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);<br>
- blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);<br>
- nralphainrangelow += 1;<br>
- nralphainrangehigh += 1;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[3]) {<br>
- blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);<br>
- blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);<br>
- nralphainrangelow += 1;<br>
- nralphainrangehigh += 1;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[4]) {<br>
- blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);<br>
- blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);<br>
- nralphainrangelow += 1;<br>
- nralphainrangehigh += 1;<br>
- }<br>
- else {<br>
- blockerrlin2 += (srccolors[j][i] - alphatest[1]);<br>
- nralphainrangehigh += 1;<br>
- }<br>
- }<br>
- }<br>
- /* shouldn't happen often, needed to avoid div by zero */<br>
- if (nralphainrangelow == 0) nralphainrangelow = 1;<br>
- if (nralphainrangehigh == 0) nralphainrangehigh = 1;<br>
- alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow);<br>
-#if RGTC_DEBUG<br>
- fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow);<br>
- fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh);<br>
-#endif<br>
- /* again shouldn't really happen often... */<br>
- if (alphatest[0] < T_MIN) {<br>
- alphatest[0] = T_MIN;<br>
- }<br>
- alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh);<br>
- if (alphatest[1] > T_MAX) {<br>
- alphatest[1] = T_MAX;<br>
- }<br>
-<br>
- alphablockerror3 = 0;<br>
- for (aindex = 0; aindex < 5; aindex++) {<br>
- /* don't forget here is always rounded down */<br>
- acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;<br>
- }<br>
- for (j = 0; j < numypixels; j++) {<br>
- for (i = 0; i < numxpixels; i++) {<br>
- /* maybe it's overkill to have the most complicated calculation just for the error<br>
- calculation which we only need to figure out if encoding1 or encoding2 is better... */<br>
- if (srccolors[j][i] <= alphatest[0] / 2) {<br>
- alphaenc3[4*j + i] = 6;<br>
- alphadist = srccolors[j][i];<br>
- }<br>
- else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) {<br>
- alphaenc3[4*j + i] = 7;<br>
- alphadist = T_MAX - srccolors[j][i];<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[0]) {<br>
- alphaenc3[4*j + i] = 0;<br>
- alphadist = srccolors[j][i] - alphatest[0];<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[1]) {<br>
- alphaenc3[4*j + i] = 2;<br>
- alphadist = srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[2]) {<br>
- alphaenc3[4*j + i] = 3;<br>
- alphadist = srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[3]) {<br>
- alphaenc3[4*j + i] = 4;<br>
- alphadist = srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5;<br>
- }<br>
- else if (srccolors[j][i] <= acutValues[4]) {<br>
- alphaenc3[4*j + i] = 5;<br>
- alphadist = srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5;<br>
- }<br>
- else {<br>
- alphaenc3[4*j + i] = 1;<br>
- alphadist = srccolors[j][i] - alphatest[1];<br>
- }<br>
- alphablockerror3 += alphadist * alphadist;<br>
- }<br>
- }<br>
- }<br>
- }<br>
-<br>
- /* write the alpha values and encoding back. */<br>
- if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) {<br>
-#if RGTC_DEBUG<br>
- if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1);<br>
- fprintf(stderr,"w1: min %d max %d au0 %d au1 %d\n",<br>
- T_MIN, T_MAX,<br>
- alphause[1], alphause[0]);<br>
-#endif<br>
-<br>
- TAG(write_rgtc_encoded_channel)( blkaddr, alphause[1], alphause[0], alphaenc1 );<br>
- }<br>
- else if (alphablockerror2 <= alphablockerror3) {<br>
-#if RGTC_DEBUG<br>
- if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2);<br>
- fprintf(stderr,"w2: min %d max %d au0 %d au1 %d\n",<br>
- T_MIN, T_MAX,<br>
- alphabase[0], alphabase[1]);<br>
-#endif<br>
-<br>
- TAG(write_rgtc_encoded_channel)( blkaddr, alphabase[0], alphabase[1], alphaenc2 );<br>
- }<br>
- else {<br>
-#if RGTC_DEBUG<br>
- fprintf(stderr, "enc3 used, error %d\n", alphablockerror3);<br>
- fprintf(stderr,"w3: min %d max %d au0 %d au1 %d\n",<br>
- T_MIN, T_MAX,<br>
- alphatest[0], alphatest[1]);<br>
-#endif<br>
-<br>
- TAG(write_rgtc_encoded_channel)( blkaddr, (TYPE)alphatest[0], (TYPE)alphatest[1], alphaenc3 );<br>
- }<br>
-}<br>
diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources<br>
index b99aa25..c34475a 100644<br>
--- a/src/util/Makefile.sources<br>
+++ b/src/util/Makefile.sources<br>
@@ -1,6 +1,7 @@<br>
MESA_UTIL_FILES := \<br>
hash_table.c \<br>
- ralloc.c<br>
+ ralloc.c \<br>
+ rgtc.c<br>
<br>
MESA_UTIL_GENERATED_FILES = \<br>
format_srgb.c<br>
diff --git a/src/util/rgtc.c b/src/util/rgtc.c<br>
new file mode 100644<br>
index 0000000..6269924<br>
--- /dev/null<br>
+++ b/src/util/rgtc.c<br>
@@ -0,0 +1,59 @@<br>
+/*<br>
+ * Copyright (C) 2011 Red Hat Inc.<br>
+ *<br>
+ * block compression parts are:<br>
+ * Copyright (C) 2004 Roland Scheidegger All Rights Reserved.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ *<br>
+ * Author:<br>
+ * Dave Airlie<br>
+ */<br>
+<br>
+#include <inttypes.h><br>
+#include "macros.h"<br>
+<br>
+#include "rgtc.h"<br>
+<br>
+#define TAG(x) util_format_unsigned_##x<br>
+<br>
+#define TYPE unsigned char<br>
+#define T_MIN 0<br>
+#define T_MAX 0xff<br>
+<br>
+#include "texcompress_rgtc_tmp.h"<br>
+<br>
+#undef TAG<br>
+#undef TYPE<br>
+#undef T_MIN<br>
+#undef T_MAX<br>
+<br>
+#define TAG(x) util_format_signed_##x<br>
+#define TYPE signed char<br>
+#define T_MIN (signed char)-128<br>
+#define T_MAX (signed char)127<br>
+<br>
+#include "texcompress_rgtc_tmp.h"<br>
+<br>
+#undef TAG<br>
+#undef TYPE<br>
+#undef T_MIN<br>
+#undef T_MAX<br>
+<br>
diff --git a/src/util/rgtc.h b/src/util/rgtc.h<br>
new file mode 100644<br>
index 0000000..6bba9f2<br>
--- /dev/null<br>
+++ b/src/util/rgtc.h<br>
@@ -0,0 +1,39 @@<br>
+/*<br>
+ * Copyright © 2014 Red Hat<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ *<br>
+ */<br>
+<br>
+#ifndef _RGTC_H<br>
+#define _RGTC_H<br>
+<br>
+void util_format_unsigned_fetch_texel_rgtc(unsigned srcRowStride, const unsigned char *pixdata,<br>
+ unsigned i, unsigned j, unsigned char *value, unsigned comps);<br>
+<br>
+void util_format_signed_fetch_texel_rgtc(unsigned srcRowStride, const signed char *pixdata,<br>
+ unsigned i, unsigned j, signed char *value, unsigned comps);<br>
+<br>
+void util_format_unsigned_encode_rgtc_ubyte(unsigned char *blkaddr, unsigned char srccolors[4][4],<br>
+ int numxpixels, int numypixels);<br>
+<br>
+void util_format_signed_encode_rgtc_ubyte(signed char *blkaddr, signed char srccolors[4][4],<br>
+ int numxpixels, int numypixels);<br>
+#endif /* _RGTC_H */<br>
diff --git a/src/util/texcompress_rgtc_tmp.h b/src/util/texcompress_rgtc_tmp.h<br>
new file mode 100644<br>
index 0000000..6bbae5e<br>
--- /dev/null<br>
+++ b/src/util/texcompress_rgtc_tmp.h<br>
@@ -0,0 +1,418 @@<br>
+/*<br>
+ * Copyright (C) 2011 Red Hat Inc.<br>
+ *<br>
+ * block compression parts are:<br>
+ * Copyright (C) 2004 Roland Scheidegger All Rights Reserved.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ *<br>
+ * Author:<br>
+ * Dave Airlie<br>
+ */<br>
+<br>
+/* included by texcompress_rgtc to define byte/ubyte compressors */<br>
+<br>
+void TAG(fetch_texel_rgtc)(unsigned srcRowStride, const TYPE *pixdata,<br>
+ unsigned i, unsigned j, TYPE *value, unsigned comps)<br>
+{<br>
+ TYPE decode;<br>
+ const TYPE *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8 * comps);<br>
+ const TYPE alpha0 = blksrc[0];<br>
+ const TYPE alpha1 = blksrc[1];<br>
+ const char bit_pos = ((j&3) * 4 + (i&3)) * 3;<br>
+ const unsigned char acodelow = blksrc[2 + bit_pos / 8];<br>
+ const unsigned char acodehigh = (3 + bit_pos / 8) < 8 ? blksrc[3 + bit_pos / 8] : 0;<br>
+ const unsigned char code = (acodelow >> (bit_pos & 0x7) |<br>
+ (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7;<br>
+<br>
+ if (code == 0)<br>
+ decode = alpha0;<br>
+ else if (code == 1)<br>
+ decode = alpha1;<br>
+ else if (alpha0 > alpha1)<br>
+ decode = ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7);<br>
+ else if (code < 6)<br>
+ decode = ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5);<br>
+ else if (code == 6)<br>
+ decode = T_MIN;<br>
+ else<br>
+ decode = T_MAX;<br>
+<br>
+ *value = decode;<br>
+}<br>
+<br>
+static void TAG(write_rgtc_encoded_channel)(TYPE *blkaddr,<br>
+ TYPE alphabase1,<br>
+ TYPE alphabase2,<br>
+ TYPE alphaenc[16])<br>
+{<br>
+ *blkaddr++ = alphabase1;<br>
+ *blkaddr++ = alphabase2;<br>
+ *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6);<br>
+ *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7);<br>
+ *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5);<br>
+ *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6);<br>
+ *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7);<br>
+ *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5);<br>
+}<br>
+<br>
+void TAG(encode_rgtc_ubyte)(TYPE *blkaddr, TYPE srccolors[4][4],<br>
+ int numxpixels, int numypixels)<br>
+{<br>
+ TYPE alphabase[2], alphause[2];<br>
+ short alphatest[2] = { 0 };<br>
+ unsigned int alphablockerror1, alphablockerror2, alphablockerror3;<br>
+ TYPE i, j, aindex, acutValues[7];<br>
+ TYPE alphaenc1[16], alphaenc2[16], alphaenc3[16];<br>
+ int alphaabsmin = 0, alphaabsmax = 0;<br>
+ short alphadist;<br>
+<br>
+ /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */<br>
+ alphabase[0] = T_MAX; alphabase[1] = T_MIN;<br>
+ for (j = 0; j < numypixels; j++) {<br>
+ for (i = 0; i < numxpixels; i++) {<br>
+ if (srccolors[j][i] == T_MIN)<br>
+ alphaabsmin = 1;<br>
+ else if (srccolors[j][i] == T_MAX)<br>
+ alphaabsmax = 1;<br>
+ else {<br>
+ if (srccolors[j][i] > alphabase[1])<br>
+ alphabase[1] = srccolors[j][i];<br>
+ if (srccolors[j][i] < alphabase[0])<br>
+ alphabase[0] = srccolors[j][i];<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+<br>
+ if (((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax))<br>
+ || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax)) { /* one color, either max or min */<br>
+ /* shortcut here since it is a very common case (and also avoids later problems) */<br>
+ /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */<br>
+<br>
+ *blkaddr++ = srccolors[0][0];<br>
+ blkaddr++;<br>
+ *blkaddr++ = 0;<br>
+ *blkaddr++ = 0;<br>
+ *blkaddr++ = 0;<br>
+ *blkaddr++ = 0;<br>
+ *blkaddr++ = 0;<br>
+ *blkaddr++ = 0;<br>
+#if RGTC_DEBUG<br>
+ fprintf(stderr, "enc0 used\n");<br>
+#endif<br>
+ return;<br>
+ }<br>
+<br>
+ /* find best encoding for alpha0 > alpha1 */<br>
+ /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */<br>
+ alphablockerror1 = 0x0;<br>
+ alphablockerror2 = 0xffffffff;<br>
+ alphablockerror3 = 0xffffffff;<br>
+ if (alphaabsmin) alphause[0] = T_MIN;<br>
+ else alphause[0] = alphabase[0];<br>
+ if (alphaabsmax) alphause[1] = T_MAX;<br>
+ else alphause[1] = alphabase[1];<br>
+ /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */<br>
+ for (aindex = 0; aindex < 7; aindex++) {<br>
+ /* don't forget here is always rounded down */<br>
+ acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14;<br>
+ }<br>
+<br>
+ for (j = 0; j < numypixels; j++) {<br>
+ for (i = 0; i < numxpixels; i++) {<br>
+ /* maybe it's overkill to have the most complicated calculation just for the error<br>
+ calculation which we only need to figure out if encoding1 or encoding2 is better... */<br>
+ if (srccolors[j][i] > acutValues[0]) {<br>
+ alphaenc1[4*j + i] = 0;<br>
+ alphadist = srccolors[j][i] - alphause[1];<br>
+ }<br>
+ else if (srccolors[j][i] > acutValues[1]) {<br>
+ alphaenc1[4*j + i] = 2;<br>
+ alphadist = srccolors[j][i] - (alphause[1] * 6 + alphause[0] * 1) / 7;<br>
+ }<br>
+ else if (srccolors[j][i] > acutValues[2]) {<br>
+ alphaenc1[4*j + i] = 3;<br>
+ alphadist = srccolors[j][i] - (alphause[1] * 5 + alphause[0] * 2) / 7;<br>
+ }<br>
+ else if (srccolors[j][i] > acutValues[3]) {<br>
+ alphaenc1[4*j + i] = 4;<br>
+ alphadist = srccolors[j][i] - (alphause[1] * 4 + alphause[0] * 3) / 7;<br>
+ }<br>
+ else if (srccolors[j][i] > acutValues[4]) {<br>
+ alphaenc1[4*j + i] = 5;<br>
+ alphadist = srccolors[j][i] - (alphause[1] * 3 + alphause[0] * 4) / 7;<br>
+ }<br>
+ else if (srccolors[j][i] > acutValues[5]) {<br>
+ alphaenc1[4*j + i] = 6;<br>
+ alphadist = srccolors[j][i] - (alphause[1] * 2 + alphause[0] * 5) / 7;<br>
+ }<br>
+ else if (srccolors[j][i] > acutValues[6]) {<br>
+ alphaenc1[4*j + i] = 7;<br>
+ alphadist = srccolors[j][i] - (alphause[1] * 1 + alphause[0] * 6) / 7;<br>
+ }<br>
+ else {<br>
+ alphaenc1[4*j + i] = 1;<br>
+ alphadist = srccolors[j][i] - alphause[0];<br>
+ }<br>
+ alphablockerror1 += alphadist * alphadist;<br>
+ }<br>
+ }<br>
+<br>
+#if RGTC_DEBUG<br>
+ for (i = 0; i < 16; i++) {<br>
+ fprintf(stderr, "%d ", alphaenc1[i]);<br>
+ }<br>
+ fprintf(stderr, "cutVals ");<br>
+ for (i = 0; i < 7; i++) {<br>
+ fprintf(stderr, "%d ", acutValues[i]);<br>
+ }<br>
+ fprintf(stderr, "srcVals ");<br>
+ for (j = 0; j < numypixels; j++) {<br>
+ for (i = 0; i < numxpixels; i++) {<br>
+ fprintf(stderr, "%d ", srccolors[j][i]);<br>
+ }<br>
+ }<br>
+ fprintf(stderr, "\n");<br>
+#endif<br>
+<br>
+ /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax<br>
+ are false but try it anyway */<br>
+ if (alphablockerror1 >= 32) {<br>
+<br>
+ /* don't bother if encoding is already very good, this condition should also imply<br>
+ we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */<br>
+ alphablockerror2 = 0;<br>
+ for (aindex = 0; aindex < 5; aindex++) {<br>
+ /* don't forget here is always rounded down */<br>
+ acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10;<br>
+ }<br>
+ for (j = 0; j < numypixels; j++) {<br>
+ for (i = 0; i < numxpixels; i++) {<br>
+ /* maybe it's overkill to have the most complicated calculation just for the error<br>
+ calculation which we only need to figure out if encoding1 or encoding2 is better... */<br>
+ if (srccolors[j][i] == T_MIN) {<br>
+ alphaenc2[4*j + i] = 6;<br>
+ alphadist = 0;<br>
+ }<br>
+ else if (srccolors[j][i] == T_MAX) {<br>
+ alphaenc2[4*j + i] = 7;<br>
+ alphadist = 0;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[0]) {<br>
+ alphaenc2[4*j + i] = 0;<br>
+ alphadist = srccolors[j][i] - alphabase[0];<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[1]) {<br>
+ alphaenc2[4*j + i] = 2;<br>
+ alphadist = srccolors[j][i] - (alphabase[0] * 4 + alphabase[1] * 1) / 5;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[2]) {<br>
+ alphaenc2[4*j + i] = 3;<br>
+ alphadist = srccolors[j][i] - (alphabase[0] * 3 + alphabase[1] * 2) / 5;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[3]) {<br>
+ alphaenc2[4*j + i] = 4;<br>
+ alphadist = srccolors[j][i] - (alphabase[0] * 2 + alphabase[1] * 3) / 5;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[4]) {<br>
+ alphaenc2[4*j + i] = 5;<br>
+ alphadist = srccolors[j][i] - (alphabase[0] * 1 + alphabase[1] * 4) / 5;<br>
+ }<br>
+ else {<br>
+ alphaenc2[4*j + i] = 1;<br>
+ alphadist = srccolors[j][i] - alphabase[1];<br>
+ }<br>
+ alphablockerror2 += alphadist * alphadist;<br>
+ }<br>
+ }<br>
+<br>
+<br>
+ /* skip this if the error is already very small<br>
+ this encoding is MUCH better on average than #2 though, but expensive! */<br>
+ if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) {<br>
+ short blockerrlin1 = 0;<br>
+ short blockerrlin2 = 0;<br>
+ TYPE nralphainrangelow = 0;<br>
+ TYPE nralphainrangehigh = 0;<br>
+ alphatest[0] = T_MAX;<br>
+ alphatest[1] = T_MIN;<br>
+ /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */<br>
+ for (j = 0; j < numypixels; j++) {<br>
+ for (i = 0; i < numxpixels; i++) {<br>
+ if ((srccolors[j][i] > alphatest[1]) && (srccolors[j][i] < (T_MAX -(alphabase[1] - alphabase[0]) / 28)))<br>
+ alphatest[1] = srccolors[j][i];<br>
+ if ((srccolors[j][i] < alphatest[0]) && (srccolors[j][i] > (alphabase[1] - alphabase[0]) / 28))<br>
+ alphatest[0] = srccolors[j][i];<br>
+ }<br>
+ }<br>
+ /* shouldn't happen too often, don't really care about those degenerated cases */<br>
+ if (alphatest[1] <= alphatest[0]) {<br>
+ alphatest[0] = T_MIN+1;<br>
+ alphatest[1] = T_MAX-1;<br>
+ }<br>
+ for (aindex = 0; aindex < 5; aindex++) {<br>
+ /* don't forget here is always rounded down */<br>
+ acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;<br>
+ }<br>
+<br>
+ /* find the "average" difference between the alpha values and the next encoded value.<br>
+ This is then used to calculate new base values.<br>
+ Should there be some weighting, i.e. those values closer to alphatest[x] have more weight,<br>
+ since they will see more improvement, and also because the values in the middle are somewhat<br>
+ likely to get no improvement at all (because the base values might move in different directions)?<br>
+ OTOH it would mean the values in the middle are even less likely to get an improvement<br>
+ */<br>
+ for (j = 0; j < numypixels; j++) {<br>
+ for (i = 0; i < numxpixels; i++) {<br>
+ if (srccolors[j][i] <= alphatest[0] / 2) {<br>
+ }<br>
+ else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) {<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[0]) {<br>
+ blockerrlin1 += (srccolors[j][i] - alphatest[0]);<br>
+ nralphainrangelow += 1;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[1]) {<br>
+ blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);<br>
+ blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);<br>
+ nralphainrangelow += 1;<br>
+ nralphainrangehigh += 1;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[2]) {<br>
+ blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);<br>
+ blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);<br>
+ nralphainrangelow += 1;<br>
+ nralphainrangehigh += 1;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[3]) {<br>
+ blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);<br>
+ blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);<br>
+ nralphainrangelow += 1;<br>
+ nralphainrangehigh += 1;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[4]) {<br>
+ blockerrlin1 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);<br>
+ blockerrlin2 += (srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);<br>
+ nralphainrangelow += 1;<br>
+ nralphainrangehigh += 1;<br>
+ }<br>
+ else {<br>
+ blockerrlin2 += (srccolors[j][i] - alphatest[1]);<br>
+ nralphainrangehigh += 1;<br>
+ }<br>
+ }<br>
+ }<br>
+ /* shouldn't happen often, needed to avoid div by zero */<br>
+ if (nralphainrangelow == 0) nralphainrangelow = 1;<br>
+ if (nralphainrangehigh == 0) nralphainrangehigh = 1;<br>
+ alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow);<br>
+#if RGTC_DEBUG<br>
+ fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow);<br>
+ fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh);<br>
+#endif<br>
+ /* again shouldn't really happen often... */<br>
+ if (alphatest[0] < T_MIN) {<br>
+ alphatest[0] = T_MIN;<br>
+ }<br>
+ alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh);<br>
+ if (alphatest[1] > T_MAX) {<br>
+ alphatest[1] = T_MAX;<br>
+ }<br>
+<br>
+ alphablockerror3 = 0;<br>
+ for (aindex = 0; aindex < 5; aindex++) {<br>
+ /* don't forget here is always rounded down */<br>
+ acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;<br>
+ }<br>
+ for (j = 0; j < numypixels; j++) {<br>
+ for (i = 0; i < numxpixels; i++) {<br>
+ /* maybe it's overkill to have the most complicated calculation just for the error<br>
+ calculation which we only need to figure out if encoding1 or encoding2 is better... */<br>
+ if (srccolors[j][i] <= alphatest[0] / 2) {<br>
+ alphaenc3[4*j + i] = 6;<br>
+ alphadist = srccolors[j][i];<br>
+ }<br>
+ else if (srccolors[j][i] > ((T_MAX + alphatest[1]) / 2)) {<br>
+ alphaenc3[4*j + i] = 7;<br>
+ alphadist = T_MAX - srccolors[j][i];<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[0]) {<br>
+ alphaenc3[4*j + i] = 0;<br>
+ alphadist = srccolors[j][i] - alphatest[0];<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[1]) {<br>
+ alphaenc3[4*j + i] = 2;<br>
+ alphadist = srccolors[j][i] - (alphatest[0] * 4 + alphatest[1] * 1) / 5;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[2]) {<br>
+ alphaenc3[4*j + i] = 3;<br>
+ alphadist = srccolors[j][i] - (alphatest[0] * 3 + alphatest[1] * 2) / 5;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[3]) {<br>
+ alphaenc3[4*j + i] = 4;<br>
+ alphadist = srccolors[j][i] - (alphatest[0] * 2 + alphatest[1] * 3) / 5;<br>
+ }<br>
+ else if (srccolors[j][i] <= acutValues[4]) {<br>
+ alphaenc3[4*j + i] = 5;<br>
+ alphadist = srccolors[j][i] - (alphatest[0] * 1 + alphatest[1] * 4) / 5;<br>
+ }<br>
+ else {<br>
+ alphaenc3[4*j + i] = 1;<br>
+ alphadist = srccolors[j][i] - alphatest[1];<br>
+ }<br>
+ alphablockerror3 += alphadist * alphadist;<br>
+ }<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ /* write the alpha values and encoding back. */<br>
+ if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) {<br>
+#if RGTC_DEBUG<br>
+ if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1);<br>
+ fprintf(stderr,"w1: min %d max %d au0 %d au1 %d\n",<br>
+ T_MIN, T_MAX,<br>
+ alphause[1], alphause[0]);<br>
+#endif<br>
+<br>
+ TAG(write_rgtc_encoded_channel)( blkaddr, alphause[1], alphause[0], alphaenc1 );<br>
+ }<br>
+ else if (alphablockerror2 <= alphablockerror3) {<br>
+#if RGTC_DEBUG<br>
+ if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2);<br>
+ fprintf(stderr,"w2: min %d max %d au0 %d au1 %d\n",<br>
+ T_MIN, T_MAX,<br>
+ alphabase[0], alphabase[1]);<br>
+#endif<br>
+<br>
+ TAG(write_rgtc_encoded_channel)( blkaddr, alphabase[0], alphabase[1], alphaenc2 );<br>
+ }<br>
+ else {<br>
+#if RGTC_DEBUG<br>
+ fprintf(stderr, "enc3 used, error %d\n", alphablockerror3);<br>
+ fprintf(stderr,"w3: min %d max %d au0 %d au1 %d\n",<br>
+ T_MIN, T_MAX,<br>
+ alphatest[0], alphatest[1]);<br>
+#endif<br>
+<br>
+ TAG(write_rgtc_encoded_channel)( blkaddr, (TYPE)alphatest[0], (TYPE)alphatest[1], alphaenc3 );<br>
+ }<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.9.3<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>