#include <stdlib.h>
#include "gldrv/sdds.h"
Go to the source code of this file.
|
#define | GETL16(buf) ( ( (unsigned short) (buf)[0] )|( (unsigned short) (buf)[1]<<8 ) ) |
|
#define | GETL64(buf) |
|
|
void | decode_color_block (unsigned char *dst, unsigned char *src, int w, int h, int rowbytes, TEXTUREFORMAT format) |
|
void | decode_dxt3_alpha (unsigned char *dst, unsigned char *src, int w, int h, int rowbytes) |
|
void | decode_dxt5_alpha (unsigned char *dst, unsigned char *src, int w, int h, int bpp, int rowbytes) |
|
void | ddsDecompress (unsigned char *&buffer, unsigned char *&data, TEXTUREFORMAT internformat, int height, int width) |
|
#define GETL16 |
( |
|
buf) | |
( ( (unsigned short) (buf)[0] )|( (unsigned short) (buf)[1]<<8 ) ) |
Value:( ( (
unsigned int) (buf)[0] ) \
|( (unsigned long long) (buf)[1] \
<<8 ) \
|( (unsigned long long) (buf)[2] \
<<16 ) \
|( (unsigned long long) (buf)[3] \
<<24 ) \
|( (unsigned long long) (buf)[4] \
<<32 ) \
|( (unsigned long long) (buf)[5] \
<<40 )|( (unsigned long long) (buf)[6]<<48 )|( (unsigned long long) (buf)[7]<<56 ) )
Definition at line 8 of file sdds.cpp.
Referenced by decode_dxt5_alpha().
void ddsDecompress |
( |
unsigned char *& |
buffer, |
|
|
unsigned char *& |
data, |
|
|
TEXTUREFORMAT |
internformat, |
|
|
int |
height, |
|
|
int |
width |
|
) |
| |
Definition at line 111 of file sdds.cpp.
References buffer, decode_color_block(), decode_dxt3_alpha(), decode_dxt5_alpha(), DXT3, DXT5, height, width, x, and y.
Referenced by GFXTransferTexture(), and LoadTex().
113 unsigned char *pos_out = NULL, *pos_in = NULL;
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) {
void decode_color_block |
( |
unsigned char * |
dst, |
|
|
unsigned char * |
src, |
|
|
int |
w, |
|
|
int |
h, |
|
|
int |
rowbytes, |
|
|
TEXTUREFORMAT |
format |
|
) |
| |
Definition at line 24 of file sdds.cpp.
References colors, d, DXT1, DXT1RGBA, DXT5, GETL16, i, x, and y.
Referenced by ddsDecompress().
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;
void decode_dxt3_alpha |
( |
unsigned char * |
dst, |
|
|
unsigned char * |
src, |
|
|
int |
w, |
|
|
int |
h, |
|
|
int |
rowbytes |
|
) |
| |
void decode_dxt5_alpha |
( |
unsigned char * |
dst, |
|
|
unsigned char * |
src, |
|
|
int |
w, |
|
|
int |
h, |
|
|
int |
bpp, |
|
|
int |
rowbytes |
|
) |
| |
Definition at line 84 of file sdds.cpp.
References a1, bits, d, GETL64, int, x, and y.
Referenced by ddsDecompress().
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) );