15#define ASTC_WITH_HDRTEST
19 ASTC_PUBLIC
void ASTC_Decode_LDR8(
unsigned char *
in,
unsigned char *
out,
int pixstride,
int layerstride,
int bw,
int bh,
int bd);
22 ASTC_PUBLIC
void ASTC_Decode_HDR(
unsigned char *
in,
unsigned short *
out,
int pixstride,
int layerstride,
int bw,
int bh,
int bd);
24#ifdef ASTC_WITH_HDRTEST
25 ASTC_PUBLIC
int ASTC_BlocksAreHDR(
unsigned char *
in,
size_t datasize,
int bw,
int bh,
int bd);
34 #define Vector4Set(r,x,y,z,w) {(r)[0] = x; (r)[1] = y;(r)[2] = z;(r)[3]=w;}
37 #define countof(array) (sizeof(array)/sizeof(array[0]))
39#if defined(ASTC_WITH_LDR) || defined(ASTC_WITH_HDR)
40 #define ASTC_WITH_DECODE
83static unsigned char ASTC_readbits(
unsigned char *
in,
unsigned int offset,
unsigned int count)
92 return s & ((1u<<
count)-1);
94static unsigned int ASTC_readmanybits(
unsigned char *
in,
unsigned int offset,
unsigned int count)
109static unsigned char dequant_weight_1b[1<<1] = {0x00,0x40};
110static unsigned char dequant_weight_2b[1<<2] = {0x00,0x15,0x2b,0x40};
111static unsigned char dequant_weight_3b[1<<3] = {0x00,0x09,0x12,0x1b,0x25,0x2e,0x37,0x40};
112static unsigned char dequant_weight_4b[1<<4] = {0x00,0x04,0x08,0x0c,0x11,0x15,0x19,0x1d,0x23,0x27,0x2b,0x2f,0x34,0x38,0x3c,0x40};
113static unsigned char dequant_weight_5b[1<<5] = {0x00,0x02,0x04,0x06,0x08,0x0a,0x0c,0x0e,0x10,0x12,0x14,0x16,0x18,0x1a,0x1c,0x1e,0x22,0x24,0x26,0x28,0x2a,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38,0x3a,0x3c,0x3e,0x40};
114static unsigned char dequant_weight_0t[3] = {0,32,64};
115static unsigned char dequant_weight_1t[6] = {0x00,0x40,0x0c,0x34,0x19,0x27};
116static unsigned char dequant_weight_2t[12] = {0x00,0x40,0x11,0x2f,0x06,0x3a,0x17,0x29,0x0c,0x34,0x1d,0x23};
117static unsigned char dequant_weight_3t[24] = {0x00,0x40,0x08,0x38,0x10,0x30,0x18,0x28,0x02,0x3e,0x0b,0x35,0x13,0x2d,0x1b,0x25,0x05,0x3b,0x0d,0x33,0x16,0x2a,0x1e,0x22};
118static unsigned char dequant_weight_0q[5] = {0,16,32,48,64};
119static unsigned char dequant_weight_1q[10] = {0x00,0x40,0x05,0x3b,0x0b,0x35,0x11,0x2f,0x17,0x29};
120static unsigned char dequant_weight_2q[20] = {0x00,0x40,0x10,0x30,0x03,0x3d,0x13,0x2d,0x06,0x3a,0x17,0x29,0x09,0x37,0x1a,0x26,0x0d,0x33,0x1d,0x23};
128 {0,1, dequant_weight_1b},
129 {1,0, dequant_weight_0t},
130 {0,2, dequant_weight_2b},
131 {2,0, dequant_weight_0q},
132 {1,1, dequant_weight_1t},
133 {0,3, dequant_weight_3b},
136 {2,1, dequant_weight_1q},
137 {1,2, dequant_weight_2t},
138 {0,4, dequant_weight_4b},
139 {2,2, dequant_weight_2q},
140 {1,3, dequant_weight_3t},
141 {0,5, dequant_weight_5b},
143static unsigned int ASTC_DecodeSize(
unsigned int count,
unsigned int bits,
unsigned char extra)
153 unsigned char *
in =
b->in;
154 unsigned short s = ASTC_readmanybits(
in, 0, 13);
157 if ((
s&0x1ff)==0x1fc)
163 b->dualplane =
b->precision =
b->wcount[0] =
b->wcount[1] =
b->wcount[2] =
b->partitions = 0;
167 b->dualplane = (
s>>10)&1;
168 b->precision = (
s>>(9-3))&(1<<3);
169 b->precision |= (
s>>4)&1;
170 if (
b->blocksize[2] != 1)
175 b->precision|=(
s&3)<<1;
176 b->wcount[0] = ((
s>>5)&3)+2,
b->wcount[1] = ((
s>>7)&3)+2,
b->wcount[2] = ((
s>>2)&3)+2;
180 b->precision|=(
s&0xc)>>1;
181 if ((
s&0x180)!=0x180)
186 b->wcount[0] = 6,
b->wcount[1] = ((
s>>9)&3)+2,
b->wcount[2] = ((
s>>5)&3)+2;
188 b->wcount[0] = ((
s>>5)&3)+2,
b->wcount[1] = 6,
b->wcount[2] = ((
s>>9)&3)+2;
190 b->wcount[0] = ((
s>>5)&3)+2,
b->wcount[1] = ((
s>>9)&3)+2,
b->wcount[2] = 6;
192 else if ((
s&0x60)!=0x60)
195 b->wcount[0] = 6,
b->wcount[1] = 2,
b->wcount[2] = 2;
197 b->wcount[0] = 2,
b->wcount[1] = 6,
b->wcount[2] = 2;
199 b->wcount[0] = 2,
b->wcount[1] = 2,
b->wcount[2] = 6;
213 b->precision|=(
s&3)<<1;
218 b->wcount[0] = ((
s>>7)&3)+4;
219 b->wcount[1] = ((
s>>5)&3)+2;
223 b->wcount[0] = ((
s>>7)&3)+8;
224 b->wcount[1] = ((
s>>5)&3)+2;
229 b->wcount[0] = ((
s>>5)&3)+2;
230 b->wcount[1] = ((
s>>7)&3)+8;
234 b->wcount[0] = ((
s>>5)&3)+2;
235 b->wcount[1] = ((
s>>7)&1)+6;
239 b->wcount[0] = ((
s>>7)&1)+2;
240 b->wcount[1] = ((
s>>5)&3)+2;
245 b->precision|=(
s&0xc)>>1;
249 b->wcount[1] = ((
s>>5)&3)+2;
251 else if ((
s&384)==128)
253 b->wcount[0] = ((
s>>5)&3)+2;
256 else if ((
s&480)==384)
261 else if ((
s&480)==416)
266 else if ((
s&384)==256)
268 b->wcount[0] = ((
s>>5)&3)+6;
269 b->wcount[1] = ((
s>>9)&3)+6;
277 b->partitions = ((
s>>11)&3)+1;
279 if (
b->partitions > 3 &&
b->dualplane)
282 if (
b->wcount[0] >
b->blocksize[0] ||
b->wcount[1] >
b->blocksize[1] ||
b->wcount[2] >
b->blocksize[2])
285 b->wcount[3] =
b->wcount[0] *
b->wcount[1] *
b->wcount[2];
286 b->wcount[3]<<=
b->dualplane;
287 if (
b->wcount[3] > countof(
b->weights))
289 b->weight_bits = ASTC_DecodeSize(
b->wcount[3], astc_weightmode[
b->precision].bits, astc_weightmode[
b->precision].extra);
296 unsigned char *
in =
b->in;
297 int weight_bits =
b->weight_bits;
299 if (
b->partitions == 1)
302 b->part[0].mode = ASTC_readbits(
in,
b->config_bits, 4);
307 b->partindex = ASTC_readmanybits(
in,
b->config_bits, 10);
308 b->config_bits += 10;
309 sel = ASTC_readbits(
in,
b->config_bits, 6);
314 for (
i = 0;
i <
b->partitions;
i++)
315 b->part[
i].mode = sel;
320 int highbits =
b->partitions*3 - 4;
322 weight_bits += highbits;
323 sel |= ASTC_readbits(
in, 128-weight_bits, highbits)<<6;
325 for (
i = 0;
i <
b->partitions;
i++, shift++)
327 b->part[
i].mode = ((sel&3)-1)<<2;
328 b->part[
i].mode += ((sel>>shift)&1)<<2;
330 for (
i = 0;
i <
b->partitions;
i++, shift+=2)
331 b->part[
i].mode += (sel>>shift)&3;
337 b->ccs = ASTC_readbits(
in, 128-weight_bits, 2);
342 b->ep_bits = 128 - weight_bits -
b->config_bits;
347#ifdef ASTC_WITH_HDRTEST
352 size_t blocks = datasize/16;
359 ASTC_ReadBlockMode(&
b);
366 ASTC_ReadPartitions(&
b);
367 for (
i = 0;
i <
b.partitions;
i++)
369 switch(
b.part[
i].mode)
386#ifdef ASTC_WITH_DECODE
387static unsigned char ASTC_readbits2(
unsigned char *
in,
unsigned int *
offset,
unsigned int count)
395 unsigned char block[5];
439 if ((
t&0x1c) == 0x1c)
441 c = ((
t>>3)&0x1c) | (
t&3);
448 if ((
t&0x60) == 0x60)
451 block[3] |= (
t>>7)<<
bits;
455 block[4] |= (
t>>7)<<
bits;
456 block[3] |= ((
t>>5)&3)<<
bits;
462 block[1] |= ((c>>4)&1)<<
bits;
463 block[0] |= (((c>>2)&2) | ((c>>2)&~(c>>3)&1))<<
bits;
465 else if ((c&0xc)==0xc)
469 block[0] |= (c&3)<<
bits;
473 block[2] |= ((c>>4)&1)<<
bits;
474 block[1] |= ((c>>2)&3)<<
bits;
475 block[0] |= ((c&2)|(c&1&~(c>>1)))<<
bits;
509 if ((
t&6)==6 && !(
t&0x60))
511 block[2] |= (((
t&1)<<2) | (((
t>>4)&~
t&1)<<1) | ((
t>>3)&~t&1))<<
bits;
526 block[2] |= ((
t>>5)&3)<<
bits;
533 block[0] |= ((c>>3)&3)<<
bits;
537 block[1] |= ((c>>3)&3)<<
bits;
538 block[0] |= (c&7)<<
bits;
548 else while(
count --> 0)
558static unsigned char dequant_ep_1b[1<<1] = {0,255};
559static unsigned char dequant_ep_2b[1<<2] = {0x00,0x55,0xaa,0xff};
560static unsigned char dequant_ep_3b[1<<3] = {0x00,0x24,0x49,0x6d,0x92,0xb6,0xdb,0xff};
561static unsigned char dequant_ep_4b[1<<4] = {
562 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff};
563static unsigned char dequant_ep_5b[1<<5] = {
564 0x00,0x08,0x10,0x18,0x21,0x29,0x31,0x39,0x42,0x4a,0x52,0x5a,0x63,0x6b,0x73,0x7b,
565 0x84,0x8c,0x94,0x9c,0xa5,0xad,0xb5,0xbd,0xc6,0xce,0xd6,0xde,0xe7,0xef,0xf7,0xff};
566static unsigned char dequant_ep_6b[1<<6] = {
567 0x00,0x04,0x08,0x0c,0x10,0x14,0x18,0x1c,0x20,0x24,0x28,0x2c,0x30,0x34,0x38,0x3c,
568 0x41,0x45,0x49,0x4d,0x51,0x55,0x59,0x5d,0x61,0x65,0x69,0x6d,0x71,0x75,0x79,0x7d,
569 0x82,0x86,0x8a,0x8e,0x92,0x96,0x9a,0x9e,0xa2,0xa6,0xaa,0xae,0xb2,0xb6,0xba,0xbe,
570 0xc3,0xc7,0xcb,0xcf,0xd3,0xd7,0xdb,0xdf,0xe3,0xe7,0xeb,0xef,0xf3,0xf7,0xfb,0xff};
571static unsigned char dequant_ep_7b[1<<7] = {
572 0x00,0x02,0x04,0x06,0x08,0x0a,0x0c,0x0e,0x10,0x12,0x14,0x16,0x18,0x1a,0x1c,0x1e,
573 0x20,0x22,0x24,0x26,0x28,0x2a,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38,0x3a,0x3c,0x3e,
574 0x40,0x42,0x44,0x46,0x48,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c,0x5e,
575 0x60,0x62,0x64,0x66,0x68,0x6a,0x6c,0x6e,0x70,0x72,0x74,0x76,0x78,0x7a,0x7c,0x7e,
576 0x81,0x83,0x85,0x87,0x89,0x8b,0x8d,0x8f,0x91,0x93,0x95,0x97,0x99,0x9b,0x9d,0x9f,
577 0xa1,0xa3,0xa5,0xa7,0xa9,0xab,0xad,0xaf,0xb1,0xb3,0xb5,0xb7,0xb9,0xbb,0xbd,0xbf,
578 0xc1,0xc3,0xc5,0xc7,0xc9,0xcb,0xcd,0xcf,0xd1,0xd3,0xd5,0xd7,0xd9,0xdb,0xdd,0xdf,
579 0xe1,0xe3,0xe5,0xe7,0xe9,0xeb,0xed,0xef,0xf1,0xf3,0xf5,0xf7,0xf9,0xfb,0xfd,0xff};
580static unsigned char dequant_ep_8b[1<<8] = {
581 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
582 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
583 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
584 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
585 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
586 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
587 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
588 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
589 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
590 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
591 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
592 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
593 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
594 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
595 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
596 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff};
597static unsigned char dequant_ep_0t[3] = {0,128,255};
598static unsigned char dequant_ep_1t[6] = {0x00,0xff,0x33,0xcc,0x66,0x99};
599static unsigned char dequant_ep_2t[12] = {0x00,0xff,0x45,0xba,0x17,0xe8,0x5c,0xa3,0x2e,0xd1,0x74,0x8b};
600static unsigned char dequant_ep_3t[24] = {0x00,0xff,0x21,0xde,0x42,0xbd,0x63,0x9c,0x0b,0xf4,0x2c,0xd3,0x4d,0xb2,0x6e,0x91,0x16,0xe9,0x37,0xc8,0x58,0xa7,0x79,0x86};
601static unsigned char dequant_ep_4t[48] = {0x00,0xff,0x10,0xef,0x20,0xdf,0x30,0xcf,0x41,0xbe,0x51,0xae,0x61,0x9e,0x71,0x8e,0x05,0xfa,0x15,0xea,0x26,0xd9,0x36,0xc9,0x46,0xb9,0x56,0xa9,0x67,0x98,0x77,0x88,0x0b,0xf4,0x1b,0xe4,0x2b,0xd4,0x3b,0xc4,0x4c,0xb3,0x5c,0xa3,0x6c,0x93,0x7c,0x83};
602static unsigned char dequant_ep_5t[96] = {0x00,0xff,0x08,0xf7,0x10,0xef,0x18,0xe7,0x20,0xdf,0x28,0xd7,0x30,0xcf,0x38,0xc7,0x40,0xbf,0x48,0xb7,0x50,0xaf,0x58,0xa7,0x60,0x9f,0x68,0x97,0x70,0x8f,0x78,0x87,0x02,0xfd,0x0a,0xf5,0x12,0xed,0x1a,0xe5,0x23,0xdc,0x2b,0xd4,0x33,0xcc,0x3b,0xc4,0x43,0xbc,0x4b,0xb4,0x53,0xac,0x5b,0xa4,0x63,0x9c,0x6b,0x94,0x73,0x8c,0x7b,0x84,0x05,0xfa,0x0d,0xf2,0x15,0xea,0x1d,0xe2,0x25,0xda,0x2d,0xd2,0x35,0xca,0x3d,0xc2,0x46,0xb9,0x4e,0xb1,0x56,0xa9,0x5e,0xa1,0x66,0x99,0x6e,0x91,0x76,0x89,0x7e,0x81};
603static unsigned char dequant_ep_6t[192]= {0x00,0xff,0x04,0xfb,0x08,0xf7,0x0c,0xf3,0x10,0xef,0x14,0xeb,0x18,0xe7,0x1c,0xe3,0x20,0xdf,0x24,0xdb,0x28,0xd7,0x2c,0xd3,0x30,0xcf,0x34,0xcb,0x38,0xc7,0x3c,0xc3,0x40,0xbf,0x44,0xbb,0x48,0xb7,0x4c,0xb3,0x50,0xaf,0x54,0xab,0x58,0xa7,0x5c,0xa3,0x60,0x9f,0x64,0x9b,0x68,0x97,0x6c,0x93,0x70,0x8f,0x74,0x8b,0x78,0x87,0x7c,0x83,0x01,0xfe,0x05,0xfa,0x09,0xf6,0x0d,0xf2,0x11,0xee,0x15,0xea,0x19,0xe6,0x1d,0xe2,0x21,0xde,0x25,0xda,0x29,0xd6,0x2d,0xd2,0x31,0xce,0x35,0xca,0x39,0xc6,0x3d,0xc2,0x41,0xbe,0x45,0xba,0x49,0xb6,0x4d,0xb2,0x51,0xae,0x55,0xaa,0x59,0xa6,0x5d,0xa2,0x61,0x9e,0x65,0x9a,0x69,0x96,0x6d,0x92,0x71,0x8e,0x75,0x8a,0x79,0x86,0x7d,0x82,0x02,0xfd,0x06,0xf9,0x0a,0xf5,0x0e,0xf1,0x12,0xed,0x16,0xe9,0x1a,0xe5,0x1e,0xe1,0x22,0xdd,0x26,0xd9,0x2a,0xd5,0x2e,0xd1,0x32,0xcd,0x36,0xc9,0x3a,0xc5,0x3e,0xc1,0x42,0xbd,0x46,0xb9,0x4a,0xb5,0x4e,0xb1,0x52,0xad,0x56,0xa9,0x5a,0xa5,0x5e,0xa1,0x62,0x9d,0x66,0x99,0x6a,0x95,0x6e,0x91,0x72,0x8d,0x76,0x89,0x7a,0x85,0x7e,0x81};
604static unsigned char dequant_ep_0q[5] = {0,64,128,192,255};
605static unsigned char dequant_ep_1q[10] = {0x00,0xff,0x1c,0xe3,0x38,0xc7,0x54,0xab,0x71,0x8e};
606static unsigned char dequant_ep_2q[20] = {0x00,0xff,0x43,0xbc,0x0d,0xf2,0x50,0xaf,0x1b,0xe4,0x5e,0xa1,0x28,0xd7,0x6b,0x94,0x36,0xc9,0x79,0x86};
607static unsigned char dequant_ep_3q[40] = {0x00,0xff,0x20,0xdf,0x41,0xbe,0x61,0x9e,0x06,0xf9,0x27,0xd8,0x47,0xb8,0x68,0x97,0x0d,0xf2,0x2d,0xd2,0x4e,0xb1,0x6e,0x91,0x13,0xec,0x34,0xcb,0x54,0xab,0x75,0x8a,0x1a,0xe5,0x3a,0xc5,0x5b,0xa4,0x7b,0x84};
608static unsigned char dequant_ep_4q[80] = {0x00,0xff,0x10,0xef,0x20,0xdf,0x30,0xcf,0x40,0xbf,0x50,0xaf,0x60,0x9f,0x70,0x8f,0x03,0xfc,0x13,0xec,0x23,0xdc,0x33,0xcc,0x43,0xbc,0x53,0xac,0x64,0x9b,0x74,0x8b,0x06,0xf9,0x16,0xe9,0x26,0xd9,0x36,0xc9,0x47,0xb8,0x57,0xa8,0x67,0x98,0x77,0x88,0x09,0xf6,0x19,0xe6,0x2a,0xd5,0x3a,0xc5,0x4a,0xb5,0x5a,0xa5,0x6a,0x95,0x7a,0x85,0x0d,0xf2,0x1d,0xe2,0x2d,0xd2,0x3d,0xc2,0x4d,0xb2,0x5d,0xa2,0x6d,0x92,0x7d,0x82};
609static unsigned char dequant_ep_5q[160]= {0x00,0xff,0x08,0xf7,0x10,0xef,0x18,0xe7,0x20,0xdf,0x28,0xd7,0x30,0xcf,0x38,0xc7,0x40,0xbf,0x48,0xb7,0x50,0xaf,0x58,0xa7,0x60,0x9f,0x68,0x97,0x70,0x8f,0x78,0x87,0x01,0xfe,0x09,0xf6,0x11,0xee,0x19,0xe6,0x21,0xde,0x29,0xd6,0x31,0xce,0x39,0xc6,0x41,0xbe,0x49,0xb6,0x51,0xae,0x59,0xa6,0x61,0x9e,0x69,0x96,0x71,0x8e,0x79,0x86,0x03,0xfc,0x0b,0xf4,0x13,0xec,0x1b,0xe4,0x23,0xdc,0x2b,0xd4,0x33,0xcc,0x3b,0xc4,0x43,0xbc,0x4b,0xb4,0x53,0xac,0x5b,0xa4,0x63,0x9c,0x6b,0x94,0x73,0x8c,0x7b,0x84,0x04,0xfb,0x0c,0xf3,0x14,0xeb,0x1c,0xe3,0x24,0xdb,0x2c,0xd3,0x34,0xcb,0x3c,0xc3,0x44,0xbb,0x4c,0xb3,0x54,0xab,0x5c,0xa3,0x64,0x9b,0x6c,0x93,0x74,0x8b,0x7c,0x83,0x06,0xf9,0x0e,0xf1,0x16,0xe9,0x1e,0xe1,0x26,0xd9,0x2e,0xd1,0x36,0xc9,0x3e,0xc1,0x46,0xb9,0x4e,0xb1,0x56,0xa9,0x5e,0xa1,0x66,0x99,0x6e,0x91,0x76,0x89,0x7e,0x81};
615 {0,1, dequant_ep_1b},
616 {1,0, dequant_ep_0t},
617 {0,2, dequant_ep_2b},
618 {2,0, dequant_ep_0q},
619 {1,1, dequant_ep_1t},
620 {0,3, dequant_ep_3b},
621 {2,1, dequant_ep_1q},
622 {1,2, dequant_ep_2t},
623 {0,4, dequant_ep_4b},
624 {2,2, dequant_ep_2q},
625 {1,3, dequant_ep_3t},
626 {0,5, dequant_ep_5b},
627 {2,3, dequant_ep_3q},
628 {1,4, dequant_ep_4t},
629 {0,6, dequant_ep_6b},
630 {2,4, dequant_ep_4q},
631 {1,5, dequant_ep_5t},
632 {0,7, dequant_ep_7b},
633 {2,5, dequant_ep_5q},
634 {1,6, dequant_ep_6t},
635 {0,8, dequant_ep_8b},
812static void ASTC_blue_contract(
int *
out,
int r,
int g,
int b,
int a)
819static int ASTC_bit_transfer_signed(
int a,
unsigned char *
b)
829static void ASTC_clamp_unorm8(
int *c)
831 c[0] = bound(0, c[0], 255);
832 c[1] = bound(0, c[1], 255);
833 c[2] = bound(0, c[2], 255);
834 c[3] = bound(0, c[3], 255);
838static void ASTC_HDR_Mode_2(
struct astc_part *
p,
unsigned char *
v)
848 y0 = (
v[1] << 4) + 8;
849 y1 = (
v[0] << 4) - 8;
851 Vector4Set(
p->ep[0],
y0,
y0,
y0, 0x780);
852 Vector4Set(
p->ep[1],
y1,
y1,
y1, 0x780);
855static void ASTC_HDR_Mode_3(
struct astc_part *
p,
unsigned char *
v)
860 y0 = ((
v[1] & 0xE0) << 4) | ((
v[0] & 0x7F) << 2);
861 d = (
v[1] & 0x1F) << 2;
865 y0 = ((
v[1] & 0xF0) << 4) | ((
v[0] & 0x7F) << 1);
866 d = (
v[1] & 0x0F) << 1;
873 Vector4Set(
p->ep[0],
y0,
y0,
y0, 0x780);
874 Vector4Set(
p->ep[1],
y1,
y1,
y1, 0x780);
877static void ASTC_HDR_Mode_7(
struct astc_part *
p,
unsigned char *
v)
879 int modeval = ((
v[0]&0xC0)>>6) | ((
v[1]&0x80)>>5) | ((
v[2]&0x80)>>4);
882 static const int shamts[6] = { 1,1,2,3,4,5 };
886 int x0,
x1,
x2,x3,x4,x5,x6,ohm;
888 if( (modeval & 0xC ) != 0xC )
890 majcomp = modeval >> 2;
893 else if( modeval != 0xF )
895 majcomp = modeval & 3;
900 majcomp = 0;
mode = 5;
908 x0 = (
v[1] >> 6) & 1;
x1 = (
v[1] >> 5) & 1;
909 x2 = (
v[2] >> 6) & 1; x3 = (
v[2] >> 5) & 1;
910 x4 = (
v[3] >> 7) & 1; x5 = (
v[3] >> 6) & 1;
911 x6 = (
v[3] >> 5) & 1;
914 if( ohm & 0x30 )
green |=
x0 << 6;
915 if( ohm & 0x3A )
green |=
x1 << 5;
916 if( ohm & 0x30 )
blue |=
x2 << 6;
917 if( ohm & 0x3A )
blue |= x3 << 5;
918 if( ohm & 0x3D )
scale |= x6 << 5;
919 if( ohm & 0x2D )
scale |= x5 << 6;
920 if( ohm & 0x04 )
scale |= x4 << 7;
921 if( ohm & 0x3B ) red |= x4 << 6;
922 if( ohm & 0x04 ) red |= x3 << 6;
923 if( ohm & 0x10 ) red |= x5 << 7;
924 if( ohm & 0x0F ) red |=
x2 << 7;
925 if( ohm & 0x05 ) red |=
x1 << 8;
926 if( ohm & 0x0A ) red |=
x0 << 8;
927 if( ohm & 0x05 ) red |=
x0 << 9;
928 if( ohm & 0x02 ) red |= x6 << 9;
929 if( ohm & 0x01 ) red |= x3 << 10;
930 if( ohm & 0x02 ) red |= x5 << 10;
932 shamt = shamts[
mode];
950 p->ep[1][0] = bound( 0, red, 0xFFF );
951 p->ep[1][1] = bound( 0,
green, 0xFFF );
952 p->ep[1][2] = bound( 0,
blue, 0xFFF );
954 p->ep[0][0] = bound( 0, red -
scale, 0xFFF );
956 p->ep[0][2] = bound( 0,
blue -
scale, 0xFFF );
958 p->ep[1][3] =
p->ep[0][3] = 0x780;
962static void ASTC_HDR_Mode_11(
struct astc_part *
p,
unsigned char *
v)
964 static const int dbitstab[8] = {7,6,7,6,5,6,5,6};
966 int majcomp = ((
v[4] & 0x80) >> 7) | ((
v[5] & 0x80) >> 6);
967 int mode,
va,vb0,vb1,vc,vd0,vd1;
968 int x0,
x1,
x2,x3,x4,x5,ohm;
972 Vector4Set(
p->ep[0],
v[0] << 4,
v[2] << 4, (
v[4] & 0x7f) << 5, 0x780);
973 Vector4Set(
p->ep[1],
v[1] << 4,
v[3] << 4, (
v[5] & 0x7f) << 5, 0x780);
978 mode = ((
v[1]&0x80)>>7) | ((
v[2]&0x80)>>6) | ((
v[3]&0x80)>>5);
979 va =
v[0] | ((
v[1] & 0x40) << 2);
986 if (vd0 & (1<<(dbitstab[
mode]-1)))
987 vd0 |= -1 & ~((1u<<dbitstab[
mode])-1);
988 if (vd1 & (1<<(dbitstab[
mode]-1)))
989 vd1 |= -1 & ~((1u<<dbitstab[
mode])-1);
991 x0 = (
v[2] >> 6) & 1;
992 x1 = (
v[3] >> 6) & 1;
993 x2 = (
v[4] >> 6) & 1;
994 x3 = (
v[5] >> 6) & 1;
995 x4 = (
v[4] >> 5) & 1;
996 x5 = (
v[5] >> 5) & 1;
999 if( ohm & 0xA4 )
va |=
x0 << 9;
1000 if( ohm & 0x08 )
va |=
x2 << 9;
1001 if( ohm & 0x50 )
va |= x4 << 9;
1002 if( ohm & 0x50 )
va |= x5 << 10;
1003 if( ohm & 0xA0 )
va |=
x1 << 10;
1004 if( ohm & 0xC0 )
va |=
x2 << 11;
1005 if( ohm & 0x04 ) vc |=
x1 << 6;
1006 if( ohm & 0xE8 ) vc |= x3 << 6;
1007 if( ohm & 0x20 ) vc |=
x2 << 7;
1008 if( ohm & 0x5B ) vb0 |=
x0 << 6;
1009 if( ohm & 0x5B ) vb1 |=
x1 << 6;
1010 if( ohm & 0x12 ) vb0 |=
x2 << 7;
1011 if( ohm & 0x12 ) vb1 |= x3 << 7;
1014 shamt = (
mode >> 1) ^ 3;
1015 va <<= shamt; vb0 <<= shamt; vb1 <<= shamt;
1016 vc <<= shamt; vd0 <<= shamt; vd1 <<= shamt;
1018 p->ep[1][0] = bound( 0,
va, 0xFFF );
1019 p->ep[1][1] = bound( 0,
va - vb0, 0xFFF );
1020 p->ep[1][2] = bound( 0,
va - vb1, 0xFFF );
1022 p->ep[0][0] = bound( 0,
va - vc, 0xFFF );
1023 p->ep[0][1] = bound( 0,
va - vb0 - vc - vd0, 0xFFF );
1024 p->ep[0][2] = bound( 0,
va - vb1 - vc - vd1, 0xFFF );
1028 p->ep[0][3] =
p->ep[0][0];
1029 p->ep[0][0] =
p->ep[0][1];
1030 p->ep[0][1] =
p->ep[0][3];
1031 p->ep[1][3] =
p->ep[1][0];
1032 p->ep[1][0] =
p->ep[1][1];
1033 p->ep[1][1] =
p->ep[1][3];
1035 else if( majcomp == 2 )
1037 p->ep[0][3] =
p->ep[0][0];
1038 p->ep[0][0] =
p->ep[0][2];
1039 p->ep[0][2] =
p->ep[0][3];
1040 p->ep[1][3] =
p->ep[1][0];
1041 p->ep[1][0] =
p->ep[1][2];
1042 p->ep[1][2] =
p->ep[1][3];
1045 p->ep[0][3] =
p->ep[1][3] = 0x780;
1049static void ASTC_HDR_Mode_14(
struct astc_part *
p,
unsigned char *
v)
1051 ASTC_HDR_Mode_11(
p,
v);
1057static void ASTC_HDR_Mode_15(
struct astc_part *
p,
unsigned char *
v)
1059 int v6=
v[6], v7=
v[7];
1061 ASTC_HDR_Mode_11(
p,
v);
1063 mode = ((v6 >> 7) & 1) | ((v7 >> 6) & 2);
1069 p->ep[0][3] = v6 << 5;
1070 p->ep[1][3] = v7 << 5;
1074 v6 |= (v7 << (
mode+1)) & 0x780;
1075 v7 &= (0x3F >>
mode);
1082 v7 = bound(0, v7, 0xFFF);
1091 int i,
t0,
t1, t3, t5, t7;
1093 for (
i = 0;
i <
b->partitions;
i++)
1098 switch (
b->part[
i].mode & 15)
1102 ASTC_HDR_Mode_2(&
b->part[
i],
v);
1105 ASTC_HDR_Mode_3(&
b->part[
i],
v);
1108 ASTC_HDR_Mode_7(&
b->part[
i],
v);
1111 ASTC_HDR_Mode_11(&
b->part[
i],
v);
1114 ASTC_HDR_Mode_14(&
b->part[
i],
v);
1117 ASTC_HDR_Mode_15(&
b->part[
i],
v);
1121 Vector4Set(
b->part[
i].ep[0], 0xff, 0, 0xff, 0xff);
1122 Vector4Set(
b->part[
i].ep[1], 0xff, 0, 0xff, 0xff);
1126 Vector4Set(
b->part[
i].ep[0],
v[0],
v[0],
v[0], 0xff);
1127 Vector4Set(
b->part[
i].ep[1],
v[1],
v[1],
v[1], 0xff);
1130 t0 = (
v[0]>>2)|(
v[1]&0xc0);
1131 t1 =
t0+(
v[1]&0x3f);
1134 Vector4Set(
b->part[
i].ep[0],
t0,
t0,
t0, 0xff);
1135 Vector4Set(
b->part[
i].ep[1],
t1,
t1,
t1, 0xff);
1138 Vector4Set(
b->part[
i].ep[0],
v[0],
v[0],
v[0],
v[2]);
1139 Vector4Set(
b->part[
i].ep[1],
v[1],
v[1],
v[1],
v[3]);
1142 t1 = ASTC_bit_transfer_signed(
v[1],&
v[0]);
1143 t3 = ASTC_bit_transfer_signed(
v[3],&
v[2]);
1144 Vector4Set(
b->part[
i].ep[0],
v[0],
v[0],
v[0],
v[2]);
1145 Vector4Set(
b->part[
i].ep[1],
v[0]+
t1,
v[0]+
t1,
v[0]+
t1,
v[2]+t3);
1146 ASTC_clamp_unorm8(
b->part[
i].ep[0]);
1147 ASTC_clamp_unorm8(
b->part[
i].ep[1]);
1150 Vector4Set(
b->part[
i].ep[0], ((
int)
v[0]*(
int)
v[3])>>8, ((
int)
v[1]*(
int)
v[3])>>8, ((
int)
v[2]*(
int)
v[3])>>8, 0xff);
1151 Vector4Set(
b->part[
i].ep[1],
v[0],
v[1],
v[2], 0xff);
1158 Vector4Set(
b->part[
i].ep[0],
v[0],
v[2],
v[4],0xff);
1159 Vector4Set(
b->part[
i].ep[1],
v[1],
v[3],
v[5],0xff);
1163 ASTC_blue_contract(
b->part[
i].ep[0],
v[1],
v[3],
v[5], 0xff);
1164 ASTC_blue_contract(
b->part[
i].ep[1],
v[0],
v[2],
v[4], 0xff);
1168 t1 = ASTC_bit_transfer_signed(
v[1],&
v[0]);
1169 t3 = ASTC_bit_transfer_signed(
v[3],&
v[2]);
1170 t5 = ASTC_bit_transfer_signed(
v[5],&
v[4]);
1173 Vector4Set(
b->part[
i].ep[0],
v[0],
v[2],
v[4],0xff);
1174 Vector4Set(
b->part[
i].ep[1],
v[0]+
t1,
v[2]+t3,
v[4]+t5,0xff);
1178 ASTC_blue_contract(
b->part[
i].ep[0],
v[0]+
t1,
v[2]+t3,
v[4]+t5, 0xff);
1179 ASTC_blue_contract(
b->part[
i].ep[1],
v[0],
v[2],
v[4], 0xff);
1181 ASTC_clamp_unorm8(
b->part[
i].ep[0]);
1182 ASTC_clamp_unorm8(
b->part[
i].ep[1]);
1185 Vector4Set(
b->part[
i].ep[0], ((
int)
v[0]*
v[3])>>8, ((
int)
v[1]*
v[3])>>8, ((
int)
v[2]*
v[3])>>8,
v[4]);
1186 Vector4Set(
b->part[
i].ep[1],
v[0],
v[1],
v[2],
v[5]);
1189 if (
v[1]+(
int)
v[3]+
v[5]>=
v[0]+(
int)
v[2]+
v[4])
1191 Vector4Set(
b->part[
i].ep[0],
v[0],
v[2],
v[4],
v[6]);
1192 Vector4Set(
b->part[
i].ep[1],
v[1],
v[3],
v[5],
v[7]);
1196 ASTC_blue_contract(
b->part[
i].ep[0],
v[1],
v[3],
v[5],
v[7]);
1197 ASTC_blue_contract(
b->part[
i].ep[1],
v[0],
v[2],
v[4],
v[6]);
1201 t1 = ASTC_bit_transfer_signed(
v[1],&
v[0]);
1202 t3 = ASTC_bit_transfer_signed(
v[3],&
v[2]);
1203 t5 = ASTC_bit_transfer_signed(
v[5],&
v[4]);
1204 t7 = ASTC_bit_transfer_signed(
v[7],&
v[6]);
1207 Vector4Set(
b->part[
i].ep[0],
v[0],
v[2],
v[4],
v[6]);
1208 Vector4Set(
b->part[
i].ep[1],
v[0]+
t1,
v[2]+t3,
v[4]+t5,
v[6]+t7);
1212 ASTC_blue_contract(
b->part[
i].ep[0],
v[0]+
t1,
v[2]+t3,
v[4]+t5,
v[6]+t7);
1213 ASTC_blue_contract(
b->part[
i].ep[1],
v[0],
v[2],
v[4],
v[6]);
1215 ASTC_clamp_unorm8(
b->part[
i].ep[0]);
1216 ASTC_clamp_unorm8(
b->part[
i].ep[1]);
1219 v += ((
b->part[
i].mode>>2)+1)<<1;
1227 unsigned char epv[18];
1229 unsigned char gahffs[16],
t;
1233 for (
i = 0;
i <
b->partitions;
i++)
1234 epvalues += ((
b->part[
i].mode>>2)+1)<<1;
1235 if (epvalues > countof(epv))
1242 for(
i = countof(astc_epvmode)-1;
i >= 0;
i--)
1244 cembits = ASTC_DecodeSize(epvalues, astc_epvmode[
i].
bits, astc_epvmode[
i].
extra);
1248 ASTC_Decode(
b->in, epv, epvalues,
b->config_bits, astc_epvmode[
i].bits, astc_epvmode[
i].extra, astc_epvmode[
i].dequant);
1250 ASTC_DecodeEndpoints(
b, epv);
1254 for (
i = 0;
i < countof(gahffs);
i++)
1258 t = ((
t&0xcc)>>2)|((
t&0x33)<<2);
1259 t = ((
t&0xaa)>>1)|((
t&0x55)<<1);
1263 ASTC_Decode(gahffs,
b->weights,
b->wcount[3], 0, astc_weightmode[
b->precision].bits, astc_weightmode[
b->precision].extra, astc_weightmode[
b->precision].dequant);
1270static unsigned int hash52(
unsigned int p)
1272 p ^=
p >> 15;
p -=
p << 17;
p +=
p << 7;
p +=
p << 4;
1273 p ^=
p >> 5;
p += p << 16; p ^= p >> 7;
p ^=
p >> 3;
1274 p ^= p << 6; p ^= p >> 17;
1277static int ASTC_ChoosePartition(
int seed,
int x,
int y,
int z,
int partitions,
int smallblock)
1279 int sh1, sh2, sh3,
a,
b,c,d;
1281 unsigned char seed1,seed2,seed3,seed4,seed5,seed6,seed7,seed8,seed9,seed10,seed11,seed12;
1291 rnum = hash52(seed);
1293 seed2 = (rnum >> 4) & 0xF;
1294 seed3 = (rnum >> 8) & 0xF;
1295 seed4 = (rnum >> 12) & 0xF;
1296 seed5 = (rnum >> 16) & 0xF;
1297 seed6 = (rnum >> 20) & 0xF;
1298 seed7 = (rnum >> 24) & 0xF;
1299 seed8 = (rnum >> 28) & 0xF;
1300 seed9 = (rnum >> 18) & 0xF;
1301 seed10 = (rnum >> 22) & 0xF;
1302 seed11 = (rnum >> 26) & 0xF;
1303 seed12 = ((rnum >> 30) | (rnum << 2)) & 0xF;
1305 seed1 *= seed1; seed2 *= seed2;
1306 seed3 *= seed3; seed4 *= seed4;
1307 seed5 *= seed5; seed6 *= seed6;
1308 seed7 *= seed7; seed8 *= seed8;
1309 seed9 *= seed9; seed10 *= seed10;
1310 seed11 *= seed11; seed12 *= seed12;
1315 sh1 = ((seed&2) ? 4:5);
1321 sh2 = ((seed&2) ? 4:5);
1323 sh3 = (seed & 0x10) ? sh1 : sh2;
1325 seed1 >>= sh1; seed2 >>= sh2; seed3 >>= sh1; seed4 >>= sh2;
1326 seed5 >>= sh1; seed6 >>= sh2; seed7 >>= sh1; seed8 >>= sh2;
1327 seed9 >>= sh3; seed10 >>= sh3; seed11 >>= sh3; seed12 >>= sh3;
1329 a = seed1*
x + seed2*
y + seed11*
z + (rnum >> 14);
1330 b = seed3*
x + seed4*
y + seed12*
z + (rnum >> 10);
1331 c = seed5*
x + seed6*
y + seed9 *
z + (rnum >> 6);
1332 d = seed7*
x + seed8*
y + seed10*
z + (rnum >> 2);
1334 a &= 0x3F;
b &= 0x3F; c &= 0x3F; d &= 0x3F;
1341 if (
a >=
b &&
a >= c &&
a >= d)
1343 else if (
b >= c &&
b >= d)
1355ASTC_PUBLIC
void ASTC_Decode_LDR8(
unsigned char *
in,
unsigned char *
out,
int pixstride,
int layerstride,
int bw,
int bh,
int bd)
1359 int stride = pixstride*4;
1362 layerstride = layerstride*4-(
stride*bh);
1368 b.blocksize[0] = bw;
1369 b.blocksize[1] = bh;
1370 b.blocksize[2] = bd;
1371 ASTC_ReadBlockMode(&
b);
1377 for (
x = 0;
x < bw;
x++)
1388 ASTC_ReadPartitions(&
b);
1390 ASTC_ReadEndpoints(&
b);
1394 #define N b.wcount[0]
1395 #define M b.wcount[1]
1396 int s1=1<<
b.dualplane,s2=N<<
b.dualplane;
1397 int s3=((bd!=1?N*M:0)+N+1)<<
b.dualplane;
1399 int smallblock = (
b.blocksize[0]*
b.blocksize[1]*
b.blocksize[2])<31;
1400 int fs,
s, ds = (1024+
b.blocksize[0]/2)/(
b.blocksize[0]-1);
1401 int ft,
t,
dt = (1024+
b.blocksize[1]/2)/(
b.blocksize[1]-1);
1403 int fr,
r, dr = (1024+
b.blocksize[2]/2)/(
b.blocksize[2]-1);
1405 int v0,
w, w00,w01,w10,w11;
1406 struct astc_part *
p;
1409 for (
x = 0;
x <
b.partitions;
x++)
1413 Vector4Set(
b.part[
x].ep[0], 0xff, 0, 0xff, 0xff);
1414 Vector4Set(
b.part[
x].ep[1], 0xff, 0, 0xff, 0xff);
1425 r = ((dr*
z)*(
b.wcount[2]-1)+32)>>6;
1430 t = ((
dt*
y)*(
b.wcount[1]-1)+32)>>6;
1432 for (
x = 0;
x < bw;
x++)
1434 p = &
b.part[ASTC_ChoosePartition(
b.partindex,
x,
y,0,
b.partitions, smallblock)];
1435 s = ((ds*
x)*(
b.wcount[0]-1)+32)>>6;
1445 s1=1, s2=N, w00=16-fs, w01=fs-ft, w10=ft-fr, w11=fr;
1447 s1=N, s2=1, w00=16-ft, w01=ft-fs, w10=fs-fr, w11=fr;
1450 s1=1, s2=N*M, w00=16-fs, w01=fs-fr, w10=fr-ft, w11=ft;
1455 s1=N*M, s2=1, w00=16-fr, w01=fr-fs, w10=fs-ft, w11=ft;
1459 s1=N, s2=N*M, w00=16-ft, w01=ft-fr, w10=fr-fs, w11=fs;
1461 s1=N*M, s2=N, w00=16-fr, w01=fr-ft, w10=ft-fs, w11=fs;
1469 v0 = ((
s>>4)+(
t>>4)*N+(
r>>4)*N*M) <<
b.dualplane;
1477 w11 = (fs*ft+8) >> 4;
1480 w00 = 16 - fs - ft + w11;
1481 v0 = ((
s>>4)+(
t>>4)*N) <<
b.dualplane;
1483 w = ( w00*
b.weights[
v0] +
1484 w01*
b.weights[
v0+
s1] +
1485 w10*
b.weights[
v0+s2] +
1486 w11*
b.weights[
v0+s3] + 8) >> 4;
1487 out[(
x<<2)+0] = ((64-
w)*
p->ep[0][0] +
w*
p->ep[1][0])>>6;
1488 out[(
x<<2)+1] = ((64-
w)*
p->ep[0][1] +
w*
p->ep[1][1])>>6;
1489 out[(
x<<2)+2] = ((64-
w)*
p->ep[0][2] +
w*
p->ep[1][2])>>6;
1490 out[(
x<<2)+3] = ((64-
w)*
p->ep[0][3] +
w*
p->ep[1][3])>>6;
1495 w = ( w00*
b.weights[
v0] +
1496 w01*
b.weights[
v0+
s1] +
1497 w10*
b.weights[
v0+s2] +
1498 w11*
b.weights[
v0+s3] + 8) >> 4;
1499 out[(
x<<2)+
b.ccs] = ((64-
w)*
p->ep[0][
b.ccs] +
w*
p->ep[1][
b.ccs])>>6;
1510 for (
z = 0;
z < bd;
z++,
out += layerstride)
1513 for (
x = 0;
x < bw;
x++)
1515 out[(
x<<2)+0] = 0xff;
1517 out[(
x<<2)+2] = 0xff;
1518 out[(
x<<2)+3] = 0xff;
1525static unsigned short ASTC_GenHalffloat(
int hdr,
int rawval)
1530 fp16 = (rawval&0xF800) >> 1;
1535 fp16 |= (5*m - 2048)>>3;
1537 fp16 |= (4*m - 512)>>3;
1546 } u = {rawval/65535.0};
1550 e = ((u.u>>23)&0xff) - 127;
1556 m = (u.u&((1<<23)-1))>>13;
1557 return ((
e+15)<<10) | m;
1562ASTC_PUBLIC
void ASTC_Decode_HDR(
unsigned char *
in,
unsigned short *
out,
int pixstride,
int layerstride,
int bw,
int bh,
int bd)
1565 int stride = pixstride*4;
1569 layerstride = layerstride*4-(
stride*bh);
1575 b.blocksize[0] = bw;
1576 b.blocksize[1] = bh;
1577 b.blocksize[2] = bd;
1579 ASTC_ReadBlockMode(&
b);
1585 for (
x = 0;
x < bw;
x++)
1587 out[(
x<<2)+0] =
in[8] | (
in[9]<<8);
1588 out[(
x<<2)+1] =
in[10] | (
in[11]<<8);
1589 out[(
x<<2)+2] =
in[12] | (
in[13]<<8);
1590 out[(
x<<2)+3] =
in[14] | (
in[15]<<8);
1598 for (
x = 0;
x < bw;
x++)
1600 out[(
x<<2)+0] = ASTC_GenHalffloat(0,
in[8] | (
in[9]<<8));
1601 out[(
x<<2)+1] = ASTC_GenHalffloat(0,
in[10] | (
in[11]<<8));
1602 out[(
x<<2)+2] = ASTC_GenHalffloat(0,
in[12] | (
in[13]<<8));
1603 out[(
x<<2)+3] = ASTC_GenHalffloat(0,
in[14] | (
in[15]<<8));
1609 ASTC_ReadPartitions(&
b);
1611 ASTC_ReadEndpoints(&
b);
1615 #define N b.wcount[0]
1616 #define M b.wcount[1]
1617 int s1=1<<
b.dualplane,s2=N<<
b.dualplane;
1618 int s3=((bd!=1?N*M:0)+N+1)<<
b.dualplane;
1620 int smallblock = (
b.blocksize[0]*
b.blocksize[1]*
b.blocksize[2])<31;
1621 int fs,
s, ds = (1024+
b.blocksize[0]/2)/(
b.blocksize[0]-1);
1622 int ft,
t,
dt = (1024+
b.blocksize[1]/2)/(
b.blocksize[1]-1);
1624 int fr,
r, dr = (1024+
b.blocksize[2]/2)/(
b.blocksize[2]-1);
1626 int v0,
w, w00,w01,w10,w11;
1627 struct astc_part *
p;
1629 for (
x = 0;
x <
b.partitions;
x++)
1631 for (
y = 0;
y < 4;
y++)
1633 if (
b.part[
x].hdr&(1<<
y))
1635 b.part[
x].ep[0][
y] <<= 4;
1636 b.part[
x].ep[1][
y] <<= 4;
1640 b.part[
x].ep[0][
y] |=
b.part[
x].ep[0][
y] << 8;
1641 b.part[
x].ep[1][
y] |=
b.part[
x].ep[1][
y] << 8;
1647 for (
z = 0;
z < bd;
z++,
out += layerstride)
1651 r = ((dr*
z)*(
b.wcount[2]-1)+32)>>6;
1656 t = ((
dt*
y)*(
b.wcount[1]-1)+32)>>6;
1658 for (
x = 0;
x < bw;
x++)
1660 p = &
b.part[ASTC_ChoosePartition(
b.partindex,
x,
y,0,
b.partitions, smallblock)];
1661 s = ((ds*
x)*(
b.wcount[0]-1)+32)>>6;
1671 s1=1, s2=N, w00=16-fs, w01=fs-ft, w10=ft-fr, w11=fr;
1673 s1=N, s2=1, w00=16-ft, w01=ft-fs, w10=fs-fr, w11=fr;
1676 s1=1, s2=N*M, w00=16-fs, w01=fs-fr, w10=fr-ft, w11=ft;
1681 s1=N*M, s2=1, w00=16-fr, w01=fr-fs, w10=fs-ft, w11=ft;
1685 s1=N, s2=N*M, w00=16-ft, w01=ft-fr, w10=fr-fs, w11=fs;
1687 s1=N*M, s2=N, w00=16-fr, w01=fr-ft, w10=ft-fs, w11=fs;
1695 v0 = (((
s>>4))+((
t>>4)*N)+(
r>>4)*N*M) <<
b.dualplane;
1703 w11 = (fs*ft+8) >> 4;
1706 w00 = 16 - fs - ft + w11;
1708 v0 = (((
s>>4))+(
t>>4)*N) <<
b.dualplane;
1710 w = ( w00*
b.weights[
v0] +
1711 w01*
b.weights[
v0+
s1] +
1712 w10*
b.weights[
v0+s2] +
1713 w11*
b.weights[
v0+s3] + 8) >> 4;
1714 out[(
x<<2)+0] = ASTC_GenHalffloat(
p->hdr&1, ((64-
w)*
p->ep[0][0] +
w*
p->ep[1][0])>>6);
1715 out[(
x<<2)+1] = ASTC_GenHalffloat(
p->hdr&1, ((64-
w)*
p->ep[0][1] +
w*
p->ep[1][1])>>6);
1716 out[(
x<<2)+2] = ASTC_GenHalffloat(
p->hdr&1, ((64-
w)*
p->ep[0][2] +
w*
p->ep[1][2])>>6);
1717 out[(
x<<2)+3] = ASTC_GenHalffloat(
p->hdr&8, ((64-
w)*
p->ep[0][3] +
w*
p->ep[1][3])>>6);
1722 w = ( w00*
b.weights[
v0] +
1723 w01*
b.weights[
v0+
s1] +
1724 w10*
b.weights[
v0+s2] +
1725 w11*
b.weights[
v0+s3] + 8) >> 4;
1726 out[(
x<<2)+
b.ccs] = ASTC_GenHalffloat(
p->hdr&(1<<
b.ccs), ((64-
w)*
p->ep[0][
b.ccs] +
w*
p->ep[1][
b.ccs])>>6);
1737 for (
z = 0;
z < bd;
z++,
out += layerstride)
1740 for (
x = 0;
x < bw;
x++)
1742 out[(
x<<2)+0] = 0xf<<10;
1744 out[(
x<<2)+2] = 0xf<<10;
1745 out[(
x<<2)+3] = 0xf<<10;
enum @13::coninfomode_e mode
Definition: com_phys_ode.c:695
char *VARGS va(const char *format,...)
Definition: common.c:6687
s
Definition: execloop.h:53
GLclampf GLclampf blue
Definition: gl_vidcommon.c:39
GLfloat t
Definition: gl_vidcommon.c:184
GLclampf green
Definition: gl_vidcommon.c:39
static GLuint GLfloat x0
Definition: gl_vidnt.c:848
static GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition: gl_vidnt.c:848
static GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition: gl_vidnt.c:848
static CONST PIXELFORMATDESCRIPTOR *static int
Definition: gl_vidnt.c:222
static GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition: gl_vidnt.c:848
static GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition: gl_vidnt.c:848
static GLuint GLfloat GLfloat y0
Definition: gl_vidnt.c:848
static GLuint GLfloat GLfloat GLfloat x1
Definition: gl_vidnt.c:848
GLfloat GLfloat GLfloat z
Definition: glquake.h:158
GLfloat GLfloat y
Definition: glquake.h:158
GLsizei count
Definition: glquake.h:149
GLint GLenum GLboolean GLsizei stride
Definition: glquake.h:157
GLdouble GLdouble x2
Definition: glquake.h:938
GLfloat v0
Definition: glquake.h:163
GLfloat x
Definition: glquake.h:158
GLdouble GLdouble r
Definition: glquake.h:969
GLint j
Definition: glquake.h:806
GLfloat GLfloat GLfloat GLfloat w
Definition: glquake.h:158
const GLfloat * v
Definition: glsupp.h:466
astc_status_e
Definition: image_astc.h:43
@ ASTC_VOID_HDR
Definition: image_astc.h:47
@ ASTC_UNSUPPORTED
Definition: image_astc.h:51
@ ASTC_VOID_LDR
Definition: image_astc.h:46
@ ASTC_ERROR
Definition: image_astc.h:50
@ ASTC_OKAY
Definition: image_astc.h:45
@ ASTC_RESERVED
Definition: image_astc.h:52
unsigned char bits
Definition: image_astc.h:123
unsigned char extra
Definition: image_astc.h:123
unsigned char * dequant
Definition: image_astc.h:123
ASTC_PUBLIC int ASTC_BlocksAreHDR(unsigned char *in, size_t datasize, int bw, int bh, int bd)
Definition: image_astc.h:348
ASTC_PUBLIC void ASTC_Decode_HDR(unsigned char *in, unsigned short *out, int pixstride, int layerstride, int bw, int bh, int bd)
Definition: image_astc.h:1562
ASTC_PUBLIC void ASTC_Decode_LDR8(unsigned char *in, unsigned char *out, int pixstride, int layerstride, int bw, int bh, int bd)
Definition: image_astc.h:1355
int const void * p
Definition: pr_lua.c:232
int b
Definition: pr_lua.c:242
int const char * e
Definition: pr_lua.c:259
lua_Reader void * dt
Definition: pr_lua.c:218
vec3_t offset
Definition: q2m_flash.c:28
if(StringFromGUID2(guid==NULL)
Definition: snd_directx.c:1080
static spx_int16_t * in
Definition: snd_dma.c:488
static SpeexBits spx_int16_t * out
Definition: snd_dma.c:492
int i
Definition: snd_ov.c:50
Definition: image_astc.h:74
int ep[2][4]
Definition: image_astc.h:79
unsigned char hdr
Definition: image_astc.h:77
unsigned char mode
Definition: image_astc.h:75
Definition: image_astc.h:55
unsigned short partindex
Definition: image_astc.h:72
int weight_bits
Definition: image_astc.h:66
unsigned char blocksize[3]
Definition: image_astc.h:57
unsigned char precision
Definition: image_astc.h:63
unsigned char ccs
Definition: image_astc.h:61
int wcount[4]
Definition: image_astc.h:65
unsigned char * in
Definition: image_astc.h:56
int config_bits
Definition: image_astc.h:67
struct astc_block_info::astc_part part[4]
unsigned char partitions
Definition: image_astc.h:71
int ep_bits
Definition: image_astc.h:68
unsigned char weights[64]
Definition: image_astc.h:69
unsigned char dualplane
Definition: image_astc.h:60
enum astc_status_e status
Definition: image_astc.h:59
netadr_t a
Definition: sv_master.c:141