33 return ((color & 0x1F) << 11) | ((color & 0x7E0) << 13) | ((color & 0xF800) << 16) | 0xFF;
37 byte r[3], g[3], b[3], a[3];
40 r[2] = (
byte)((1.0f - weight) * (double)r[0] + weight * (
double)r[1]);
41 g[0] = (color_0 >> 16) & 0xFF;
42 g[1] = (color_1 >> 16) & 0xFF;
43 g[2] = (
byte)((1.0f - weight) * (double)g[0] + weight * (
double)g[1]);
44 b[0] = (color_0 >> 8) & 0xFF;
45 b[1] = (color_1 >> 8) & 0xFF;
46 b[2] = (
byte)((1.0f - weight) * (double)b[0] + weight * (
double)b[1]);
47 a[0] = color_0 & 0xFF;
48 a[1] = color_1 & 0xFF;
49 a[2] = (
byte)((1.0f - weight) * (double)a[0] + weight * (
double)a[1]);
50 return r[2] << 24 | g[2] << 16 | b[2] << 8 | a[2];
59 #define READ_DXT1_TEXEL(x) \ 60 x.color_0 = src.readUint16LE(); \ 61 x.color_1 = src.readUint16LE(); \ 62 x.pixels = src.readUint32BE() 65 for (
int32 ty = height; ty > 0; ty -= 4) {
66 for (
uint32 tx = 0; tx < width; tx += 4) {
75 blended[2] =
interpolate32(0.333333f, blended[0], blended[1]);
76 blended[3] =
interpolate32(0.666666f, blended[0], blended[1]);
83 uint32 blockWidth = MIN<uint32>(width, 4);
84 uint32 blockHeight = MIN<uint32>(height, 4);
86 for (
byte y = 0; y < blockHeight; ++y) {
87 for (
byte x = 0; x < blockWidth; ++x) {
88 const uint32 destX = tx + x;
89 const uint32 destY = height - 1 - (ty - blockHeight + y);
91 const uint32 pixel = blended[cpx & 3];
95 if ((destX < width) && (destY < height))
96 WRITE_BE_UINT32(dest + destY * pitch + destX * 4, pixel);
107 #define READ_DXT3_TEXEL(x) \ 108 x.alpha[0] = src.readUint16LE(); \ 109 x.alpha[1] = src.readUint16LE(); \ 110 x.alpha[2] = src.readUint16LE(); \ 111 x.alpha[3] = src.readUint16LE(); \ 115 for (
int32 ty = height; ty > 0; ty -= 4) {
116 for (
uint32 tx = 0; tx < width; tx += 4) {
123 blended[2] =
interpolate32(0.333333f, blended[0], blended[1]);
124 blended[3] =
interpolate32(0.666666f, blended[0], blended[1]);
127 uint32 blockWidth = MIN<uint32>(width, 4);
128 uint32 blockHeight = MIN<uint32>(height, 4);
130 for (
byte y = 0; y < blockHeight; ++y) {
131 for (
byte x = 0; x < blockWidth; ++x) {
132 const uint32 destX = tx + x;
133 const uint32 destY = height - 1 - (ty - blockHeight + y);
135 const uint32 alpha = (tex.
alpha[y] >> (x * 4)) & 0xF;
136 const uint32 pixel = blended[cpx & 3] | alpha << 4;
140 if ((destX < width) && (destY < height))
141 WRITE_BE_UINT32(dest + destY * pitch + destX * 4, pixel);
159 #define READ_DXT5_TEXEL(x) \ 160 x.alpha_0 = src.readByte(); \ 161 x.alpha_1 = src.readByte(); \ 162 x.alphabl = readUint48LE(src); \ 166 for (
int32 ty = height; ty > 0; ty -= 4) {
167 for (
uint32 tx = 0; tx < width; tx += 4) {
177 alphab[2] = (
byte)((6.0f * (
double)alphab[0] + 1.0f * (
double)alphab[1] + 3.0f) / 7.0f);
178 alphab[3] = (
byte)((5.0f * (
double)alphab[0] + 2.0f * (double)alphab[1] + 3.0f) / 7.0f);
179 alphab[4] = (
byte)((4.0f * (
double)alphab[0] + 3.0f * (double)alphab[1] + 3.0f) / 7.0f);
180 alphab[5] = (
byte)((3.0f * (
double)alphab[0] + 4.0f * (double)alphab[1] + 3.0f) / 7.0f);
181 alphab[6] = (
byte)((2.0f * (
double)alphab[0] + 5.0f * (double)alphab[1] + 3.0f) / 7.0f);
182 alphab[7] = (
byte)((1.0f * (
double)alphab[0] + 6.0f * (double)alphab[1] + 3.0f) / 7.0f);
184 alphab[2] = (
byte)((4.0f * (
double)alphab[0] + 1.0f * (double)alphab[1] + 2.0f) / 5.0f);
185 alphab[3] = (
byte)((3.0f * (
double)alphab[0] + 2.0f * (double)alphab[1] + 2.0f) / 5.0f);
186 alphab[4] = (
byte)((2.0f * (
double)alphab[0] + 3.0f * (double)alphab[1] + 2.0f) / 5.0f);
187 alphab[5] = (
byte)((1.0f * (
double)alphab[0] + 4.0f * (double)alphab[1] + 2.0f) / 5.0f);
194 blended[2] =
interpolate32(0.333333f, blended[0], blended[1]);
195 blended[3] =
interpolate32(0.666666f, blended[0], blended[1]);
198 uint32 blockWidth = MIN<uint32>(width, 4);
199 uint32 blockHeight = MIN<uint32>(height, 4);
201 for (
byte y = 0; y < blockHeight; ++y) {
202 for (
byte x = 0; x < blockWidth; ++x) {
203 const uint32 destX = tx + x;
204 const uint32 destY = height - 1 - (ty - blockHeight + y);
206 const uint32 alpha = alphab[(tex.
alphabl >> (3 * (4 * (3 - y) + x))) & 7];
207 const uint32 pixel = blended[cpx & 3] | alpha;
211 if ((destX < width) && (destY < height))
212 WRITE_BE_UINT32(dest + destY * pitch + destX * 4, pixel);
uint16 readUint16LE()
Read an unsigned 16-bit word stored in little endian (LSB first) order from the stream and return it...
static uint32 interpolate32(double weight, uint32 color_0, uint32 color_1)
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
#define READ_DXT3_TEXEL(x)
void decompressDXT3(byte *dest, Common::SeekableReadStream &src, uint32 width, uint32 height, uint32 pitch)
Utility templates and functions.
void decompressDXT1(byte *dest, Common::SeekableReadStream &src, uint32 width, uint32 height, uint32 pitch)
void decompressDXT5(byte *dest, Common::SeekableReadStream &src, uint32 width, uint32 height, uint32 pitch)
static uint32 convert565To8888(uint16 color)
Basic reading stream interfaces.
static uint64 readUint48LE(Common::SeekableReadStream &src)
Manual S3TC DXTn decompression methods.
Interface for a seekable & readable data stream.
#define READ_DXT1_TEXEL(x)
#define READ_DXT5_TEXEL(x)