5 #define GETL16( buf ) ( ( (unsigned short) (buf)[0] )|( (unsigned short) (buf)[1]<<8 ) )
8 #define GETL64( buf ) \
9 ( ( (unsigned int) (buf)[0] ) \
10 |( (unsigned long long) (buf)[1] \
12 |( (unsigned long long) (buf)[2] \
14 |( (unsigned long long) (buf)[3] \
16 |( (unsigned long long) (buf)[4] \
18 |( (unsigned long long) (buf)[5] \
19 <<40 )|( (unsigned long long) (buf)[6]<<48 )|( (unsigned long long) (buf)[7]<<56 ) )
27 unsigned int indexes, idx;
29 unsigned char colors[4][3];
30 unsigned short c0, c1;
33 colors[0][0] = ( (c0>>11)&0x1f )<<3;
34 colors[0][1] = ( (c0>>5)&0x3f )<<2;
35 colors[0][2] = ( (c0)&0x1f )<<3;
36 colors[1][0] = ( (c1>>11)&0x1f )<<3;
37 colors[1][1] = ( (c1>>5)&0x3f )<<2;
38 colors[1][2] = ( (c1)&0x1f )<<3;
39 if ( (c0 > c1) || (format ==
DXT5) ) {
40 for (i = 0; i < 3; ++i) {
41 colors[2][i] = (2*colors[0][i]+colors[1][i]+1)/3;
42 colors[3][i] = (2*colors[1][i]+colors[0][i]+1)/3;
45 for (i = 0; i < 3; ++i) {
46 colors[2][i] = (colors[0][i]+colors[1][i]+1)>>1;
51 for (y = 0; y < h; ++
y) {
54 for (x = 0; x < w; ++
x) {
56 d[0] = colors[idx][0];
57 d[1] = colors[idx][1];
58 d[2] = colors[idx][2];
60 d[3] = ( (c0 <= c1) && idx == 3 ) ? 0 : 255;
67 void decode_dxt3_alpha(
unsigned char *dst,
unsigned char *src,
int w,
int h,
int rowbytes )
72 for (y = 0; y < h; ++
y) {
74 bits =
GETL16( &src[2*y] );
75 bits =
GETL16( &src[2*y] );
76 for (x = 0; x < w; ++
x) {
77 d[0] = (bits&0x0f)*17;
84 void decode_dxt5_alpha(
unsigned char *dst,
unsigned char *src,
int w,
int h,
int bpp,
int rowbytes )
87 unsigned char *
d, a0 = src[0],
a1 = src[1];
89 for (y = 0; y < h; ++
y) {
91 for (x = 0; x < w; ++
x) {
92 code = ( (
unsigned int) bits )&0x07;
98 d[0] = ( (8-code)*a0+(code-1)*
a1 )/7;
100 d[0] = (code == 6) ? 0 : 255;
102 d[0] = ( (6-code)*a0+(code-1)*
a1 )/5;
107 bits >>= ( 3*(4-w) );
113 unsigned char *pos_out = NULL, *pos_in = NULL;
117 sx = (width < 4) ? width : 4;
118 sy = (height < 4) ? width : 4;
119 data = (
unsigned char*) malloc( height*width*bpp );
123 for (
int x = 0;
x <
width;
x += 4) {
124 pos_out = data+(
y*width+
x)*bpp;
125 if (internformat ==
DXT3) {
128 }
else if (internformat ==
DXT5) {