|
@@ -1,5 +1,5 @@
|
|
|
-#define HL_NAME(n) fmt_##n
|
|
|
-#include <hl.h>
|
|
|
+#define HL_NAME(n) fmt_##n
|
|
|
+#include <hl.h>
|
|
|
|
|
|
static const int BIT5[] = { 0, 8, 16, 25, 33, 41, 49, 58, 66, 74, 82, 90, 99, 107, 115, 123, 132, 140, 148, 156, 165, 173, 181, 189, 197, 206, 214, 222, 230, 239, 247, 255 };
|
|
|
static const int BIT6[] = { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125, 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, 194, 198, 202, 206, 210, 215, 219, 223, 227, 231, 235, 239, 243, 247, 251, 255 };
|
|
@@ -46,8 +46,8 @@ static int dxtAlpha(int a0, int a1, int t) {
|
|
|
case 7: return 255;
|
|
|
}
|
|
|
return 0;
|
|
|
-}
|
|
|
-
|
|
|
+}
|
|
|
+
|
|
|
static int dxtColor(int c0, int c1, int a, int t) {
|
|
|
switch (t) {
|
|
|
case 0: return DXT_COLOR1(c0, a);
|
|
@@ -56,114 +56,114 @@ static int dxtColor(int c0, int c1, int a, int t) {
|
|
|
case 3: return (c0 > c1) ? DXT_COLOR3(c1, c0, a) : 0;
|
|
|
}
|
|
|
return 0;
|
|
|
-}
|
|
|
-
|
|
|
-HL_PRIM bool HL_NAME(dxt_decode)( vbyte *data, int *out, int width, int height, int format ) {
|
|
|
- int x,y,k;
|
|
|
- int index = 0;
|
|
|
- int write = 0;
|
|
|
- int alpha[16];
|
|
|
- switch( format ) {
|
|
|
- case 1:
|
|
|
- for(y=0;y<height>>2;y++) {
|
|
|
- for(x=0;x<width>>2;x++) {
|
|
|
- int c0 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
- int c1 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
- for(k=0;k<4;k++) {
|
|
|
- unsigned char c = data[index++];
|
|
|
- int t0 = c & 0x03;
|
|
|
- int t1 = (c & 0x0C) >> 2;
|
|
|
- int t2 = (c & 0x30) >> 4;
|
|
|
- int t3 = (c & 0xC0) >> 6;
|
|
|
- int w = write + k * width;
|
|
|
- out[w++] = dxtColor(c0, c1, 0xFF, t0);
|
|
|
- out[w++] = dxtColor(c0, c1, 0xFF, t1);
|
|
|
- out[w++] = dxtColor(c0, c1, 0xFF, t2);
|
|
|
- out[w++] = dxtColor(c0, c1, 0xFF, t3);
|
|
|
- }
|
|
|
- write += 4;
|
|
|
- }
|
|
|
- write += 3 * width;
|
|
|
- }
|
|
|
- return true;
|
|
|
- case 2:
|
|
|
- for(y=0;y<height>>2;y++) {
|
|
|
- for(x=0;x<width>>2;x++) {
|
|
|
- int ap = 0;
|
|
|
- for(k=0;k<4;k++) {
|
|
|
- int a0 = data[index++];
|
|
|
- int a1 = data[index++];
|
|
|
- alpha[ap++] = 17 * ((a0 & 0xF0) >> 4);
|
|
|
- alpha[ap++] = 17 * (a0 & 0x0F);
|
|
|
- alpha[ap++] = 17 * ((a1 & 0xF0) >> 4);
|
|
|
- alpha[ap++] = 17 * (a1 & 0x0F);
|
|
|
- }
|
|
|
- ap = 0;
|
|
|
- int c0 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
- int c1 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
- for (int k = 0; k<4; k++) {
|
|
|
- int c = data[index++];
|
|
|
- int t0 = c & 0x03;
|
|
|
- int t1 = (c & 0x0C) >> 2;
|
|
|
- int t2 = (c & 0x30) >> 4;
|
|
|
- int t3 = (c & 0xC0) >> 6;
|
|
|
- int w = write + k * width;
|
|
|
- out[w++] = dxtColor(c0, c1, alpha[ap++], t0);
|
|
|
- out[w++] = dxtColor(c0, c1, alpha[ap++], t1);
|
|
|
- out[w++] = dxtColor(c0, c1, alpha[ap++], t2);
|
|
|
- out[w++] = dxtColor(c0, c1, alpha[ap++], t3);
|
|
|
- }
|
|
|
- write += 4;
|
|
|
- }
|
|
|
- write += 3 * width;
|
|
|
- }
|
|
|
- return true;
|
|
|
- case 3:
|
|
|
- for(y=0;y<height>>2;y++) {
|
|
|
- for(x=0;x<width>>2;x++) {
|
|
|
- int a0 = data[index++];
|
|
|
- int a1 = data[index++];
|
|
|
- int b0 = data[index] | (data[index + 1] << 8) | (data[index + 2] << 16); index += 3;
|
|
|
- int b1 = data[index] | (data[index + 1] << 8) | (data[index + 2] << 16); index += 3;
|
|
|
- alpha[0] = b0 & 0x07;
|
|
|
- alpha[1] = (b0 >> 3) & 0x07;
|
|
|
- alpha[2] = (b0 >> 6) & 0x07;
|
|
|
- alpha[3] = (b0 >> 9) & 0x07;
|
|
|
- alpha[4] = (b0 >> 12) & 0x07;
|
|
|
- alpha[5] = (b0 >> 15) & 0x07;
|
|
|
- alpha[6] = (b0 >> 18) & 0x07;
|
|
|
- alpha[7] = (b0 >> 21) & 0x07;
|
|
|
- alpha[8] = b1 & 0x07;
|
|
|
- alpha[9] = (b1 >> 3) & 0x07;
|
|
|
- alpha[10] = (b1 >> 6) & 0x07;
|
|
|
- alpha[11] = (b1 >> 9) & 0x07;
|
|
|
- alpha[12] = (b1 >> 12) & 0x07;
|
|
|
- alpha[13] = (b1 >> 15) & 0x07;
|
|
|
- alpha[14] = (b1 >> 18) & 0x07;
|
|
|
- alpha[15] = (b1 >> 21) & 0x07;
|
|
|
- int c0 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
- int c1 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
- int ap = 0;
|
|
|
- for (int k = 0; k<4; k++) {
|
|
|
- int c = data[index++];
|
|
|
- int t0 = c & 0x03;
|
|
|
- int t1 = (c & 0x0C) >> 2;
|
|
|
- int t2 = (c & 0x30) >> 4;
|
|
|
- int t3 = (c & 0xC0) >> 6;
|
|
|
- int w = write + k * width;
|
|
|
- out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t0);
|
|
|
- out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t1);
|
|
|
- out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t2);
|
|
|
- out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t3);
|
|
|
- }
|
|
|
- write += 4;
|
|
|
- }
|
|
|
- write += 3 * width;
|
|
|
- }
|
|
|
- return true;
|
|
|
- default:
|
|
|
- return false;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-DEFINE_PRIM(_BOOL, dxt_decode, _BYTES _BYTES _I32 _I32 _I32);
|
|
|
+}
|
|
|
+
|
|
|
+HL_PRIM bool HL_NAME(dxt_decode)( vbyte *data, int *out, int width, int height, int format ) {
|
|
|
+ int x,y,k;
|
|
|
+ int index = 0;
|
|
|
+ int write = 0;
|
|
|
+ int alpha[16];
|
|
|
+ switch( format ) {
|
|
|
+ case 1:
|
|
|
+ for(y=0;y<height>>2;y++) {
|
|
|
+ for(x=0;x<width>>2;x++) {
|
|
|
+ int c0 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
+ int c1 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
+ for(k=0;k<4;k++) {
|
|
|
+ unsigned char c = data[index++];
|
|
|
+ int t0 = c & 0x03;
|
|
|
+ int t1 = (c & 0x0C) >> 2;
|
|
|
+ int t2 = (c & 0x30) >> 4;
|
|
|
+ int t3 = (c & 0xC0) >> 6;
|
|
|
+ int w = write + k * width;
|
|
|
+ out[w++] = dxtColor(c0, c1, 0xFF, t0);
|
|
|
+ out[w++] = dxtColor(c0, c1, 0xFF, t1);
|
|
|
+ out[w++] = dxtColor(c0, c1, 0xFF, t2);
|
|
|
+ out[w++] = dxtColor(c0, c1, 0xFF, t3);
|
|
|
+ }
|
|
|
+ write += 4;
|
|
|
+ }
|
|
|
+ write += 3 * width;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ case 2:
|
|
|
+ for(y=0;y<height>>2;y++) {
|
|
|
+ for(x=0;x<width>>2;x++) {
|
|
|
+ int ap = 0;
|
|
|
+ for(k=0;k<4;k++) {
|
|
|
+ int a0 = data[index++];
|
|
|
+ int a1 = data[index++];
|
|
|
+ alpha[ap++] = 17 * ((a0 & 0xF0) >> 4);
|
|
|
+ alpha[ap++] = 17 * (a0 & 0x0F);
|
|
|
+ alpha[ap++] = 17 * ((a1 & 0xF0) >> 4);
|
|
|
+ alpha[ap++] = 17 * (a1 & 0x0F);
|
|
|
+ }
|
|
|
+ ap = 0;
|
|
|
+ int c0 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
+ int c1 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
+ for (int k = 0; k<4; k++) {
|
|
|
+ int c = data[index++];
|
|
|
+ int t0 = c & 0x03;
|
|
|
+ int t1 = (c & 0x0C) >> 2;
|
|
|
+ int t2 = (c & 0x30) >> 4;
|
|
|
+ int t3 = (c & 0xC0) >> 6;
|
|
|
+ int w = write + k * width;
|
|
|
+ out[w++] = dxtColor(c0, c1, alpha[ap++], t0);
|
|
|
+ out[w++] = dxtColor(c0, c1, alpha[ap++], t1);
|
|
|
+ out[w++] = dxtColor(c0, c1, alpha[ap++], t2);
|
|
|
+ out[w++] = dxtColor(c0, c1, alpha[ap++], t3);
|
|
|
+ }
|
|
|
+ write += 4;
|
|
|
+ }
|
|
|
+ write += 3 * width;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ case 3:
|
|
|
+ for(y=0;y<height>>2;y++) {
|
|
|
+ for(x=0;x<width>>2;x++) {
|
|
|
+ int a0 = data[index++];
|
|
|
+ int a1 = data[index++];
|
|
|
+ int b0 = data[index] | (data[index + 1] << 8) | (data[index + 2] << 16); index += 3;
|
|
|
+ int b1 = data[index] | (data[index + 1] << 8) | (data[index + 2] << 16); index += 3;
|
|
|
+ alpha[0] = b0 & 0x07;
|
|
|
+ alpha[1] = (b0 >> 3) & 0x07;
|
|
|
+ alpha[2] = (b0 >> 6) & 0x07;
|
|
|
+ alpha[3] = (b0 >> 9) & 0x07;
|
|
|
+ alpha[4] = (b0 >> 12) & 0x07;
|
|
|
+ alpha[5] = (b0 >> 15) & 0x07;
|
|
|
+ alpha[6] = (b0 >> 18) & 0x07;
|
|
|
+ alpha[7] = (b0 >> 21) & 0x07;
|
|
|
+ alpha[8] = b1 & 0x07;
|
|
|
+ alpha[9] = (b1 >> 3) & 0x07;
|
|
|
+ alpha[10] = (b1 >> 6) & 0x07;
|
|
|
+ alpha[11] = (b1 >> 9) & 0x07;
|
|
|
+ alpha[12] = (b1 >> 12) & 0x07;
|
|
|
+ alpha[13] = (b1 >> 15) & 0x07;
|
|
|
+ alpha[14] = (b1 >> 18) & 0x07;
|
|
|
+ alpha[15] = (b1 >> 21) & 0x07;
|
|
|
+ int c0 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
+ int c1 = data[index] | (data[index + 1] << 8); index += 2;
|
|
|
+ int ap = 0;
|
|
|
+ for (int k = 0; k<4; k++) {
|
|
|
+ int c = data[index++];
|
|
|
+ int t0 = c & 0x03;
|
|
|
+ int t1 = (c & 0x0C) >> 2;
|
|
|
+ int t2 = (c & 0x30) >> 4;
|
|
|
+ int t3 = (c & 0xC0) >> 6;
|
|
|
+ int w = write + k * width;
|
|
|
+ out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t0);
|
|
|
+ out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t1);
|
|
|
+ out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t2);
|
|
|
+ out[w++] = dxtColor(c0, c1, dxtAlpha(a0, a1, alpha[ap++]), t3);
|
|
|
+ }
|
|
|
+ write += 4;
|
|
|
+ }
|
|
|
+ write += 3 * width;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+DEFINE_PRIM(_BOOL, dxt_decode, _BYTES _BYTES _I32 _I32 _I32);
|