53 #define __BIG_ENDIAN__
65 return ((src & 0xFF000000) >> 24) |
66 ((src & 0x00FF0000) >> 8) |
67 ((src & 0x0000FF00) << 8) |
68 ((src & 0x000000FF) << 24);
73 return ((src & 0xFF00) >> 8) |
74 ((src & 0x00FF) << 8);
81 out.
c[ 0 ] = in.
c[ 3 ];
82 out.
c[ 1 ] = in.
c[ 2 ];
83 out.
c[ 2 ] = in.
c[ 1 ];
84 out.
c[ 3 ] = in.
c[ 0 ];
96 return ((src & 0xFF000000) >> 24) |
97 ((src & 0x00FF0000) >> 8) |
98 ((src & 0x0000FF00) << 8) |
99 ((src & 0x000000FF) << 24);
104 return ((src & 0xFF00) >> 8) |
105 ((src & 0x00FF) << 8);
194 colors[0].
b =
static_cast<unsigned char>(word & 0xFF);
196 colors[0].
b |= (colors[0].
b >> 5);
198 colors[0].
g =
static_cast<unsigned char>(word & 0xFF);
200 colors[0].
g |= (colors[0].
g >> 5);
202 colors[0].
r =
static_cast<unsigned char>(word & 0xFF);
204 colors[0].
r |= (colors[0].
r >> 5);
211 colors[1].
b =
static_cast<unsigned char>(word & 0xFF);
213 colors[1].
b |= (colors[1].
b >> 5);
215 colors[1].
g =
static_cast<unsigned char>(word & 0xFF);
217 colors[1].
g |= (colors[1].
g >> 5);
219 colors[1].
r =
static_cast<unsigned char>(word & 0xFF);
221 colors[1].
r |= (colors[1].
r >> 5);
231 word = (
static_cast<unsigned short>(colors[0].
r) * 2 +
static_cast<unsigned short>(colors[1].r)) / 3;
234 colors[2].
r =
static_cast<unsigned char>(word);
235 word = (
static_cast<unsigned short>(colors[0].
g) * 2 +
static_cast<unsigned short>(colors[1].g)) / 3;
236 colors[2].
g =
static_cast<unsigned char>(word);
237 word = (
static_cast<unsigned short>(colors[0].
b) * 2 +
static_cast<unsigned short>(colors[1].b)) / 3;
238 colors[2].
b =
static_cast<unsigned char>(word);
241 word = (
static_cast<unsigned short>(colors[0].
r) +
static_cast<unsigned short>(colors[1].r) * 2) / 3;
242 colors[3].
r =
static_cast<unsigned char>(word);
243 word = (
static_cast<unsigned short>(colors[0].
g) +
static_cast<unsigned short>(colors[1].g) * 2) / 3;
244 colors[3].
g =
static_cast<unsigned char>(word);
245 word = (
static_cast<unsigned short>(colors[0].
b) +
static_cast<unsigned short>(colors[1].b) * 2) / 3;
246 colors[3].
b =
static_cast<unsigned char>(word);
257 word = (
static_cast<unsigned short>(colors[0].
r) +
static_cast<unsigned short>(colors[1].r)) / 2;
258 colors[2].
r =
static_cast<unsigned char>(word & 0xFF);
259 word = (
static_cast<unsigned short>(colors[0].
g) +
static_cast<unsigned short>(colors[1].g)) / 2;
260 colors[2].
g =
static_cast<unsigned char>(word & 0xFF);
261 word = (
static_cast<unsigned short>(colors[0].
b) +
static_cast<unsigned short>(colors[1].b)) / 2;
262 colors[2].
b =
static_cast<unsigned char>(word & 0xFF);
280 const unsigned int masks[] = {3, 12, 3 << 4, 3 << 6};
281 const int shift[] = {0, 2, 4, 6};
284 for (
int r = 0; r < 4; r++, pixel += (width - 4))
288 for (
int n = 0; n < 4; n++)
290 unsigned int bits = block->
row[r] & masks[n];
329 unsigned int alphaZero)
339 for (
int row = 0; row < 4; row++, pixel += (width - 4))
344 for (
int pix = 0; pix < 4; pix++)
348 color.a =
static_cast<unsigned char>(word & 0x000F);
349 color.a = color.a | (color.a << 4);
351 unsigned int colorValue = (
static_cast<unsigned int>(color.a) << 24) |
352 (
static_cast<unsigned int>(color.r) << 16) |
353 (
static_cast<unsigned int>(color.g) << 8) |
354 (
static_cast<unsigned int>(color.b));
355 *pixel |= colorValue;
367 unsigned int alphaZero)
370 unsigned char bits[4][4]{};
371 unsigned short alphas[8]{};
375 alphas[0] = alphaBlock->
alpha0;
376 alphas[1] = alphaBlock->
alpha1;
379 if (alphas[0] > alphas[1])
382 alphas[2] = (6 * alphas[0] + alphas[1]) / 7;
383 alphas[3] = (5 * alphas[0] + 2 * alphas[1]) / 7;
384 alphas[4] = (4 * alphas[0] + 3 * alphas[1]) / 7;
385 alphas[5] = (3 * alphas[0] + 4 * alphas[1]) / 7;
386 alphas[6] = (2 * alphas[0] + 5 * alphas[1]) / 7;
387 alphas[7] = (alphas[0] + 6 * alphas[1]) / 7;
394 alphas[2] = (4 * alphas[0] + alphas[1]) / 5;
395 alphas[3] = (3 * alphas[0] + 2 * alphas[1]) / 5;
396 alphas[4] = (2 * alphas[0] + 3 * alphas[1]) / 5;
397 alphas[5] = (alphas[0] + 4 * alphas[1]) / 5;
405 unsigned int stuff = *((
unsigned char*)&(alphaBlock->
stuff[0]));
407 bits[0][0] =
static_cast<unsigned char>(stuff & 0x00000007);
409 bits[0][1] =
static_cast<unsigned char>(stuff & 0x00000007);
411 bits[0][2] =
static_cast<unsigned char>(stuff & 0x00000007);
413 bits[0][3] =
static_cast<unsigned char>(stuff & 0x00000007);
415 bits[1][0] =
static_cast<unsigned char>(stuff & 0x00000007);
417 bits[1][1] =
static_cast<unsigned char>(stuff & 0x00000007);
419 bits[1][2] =
static_cast<unsigned char>(stuff & 0x00000007);
421 bits[1][3] =
static_cast<unsigned char>(stuff & 0x00000007);
424 stuff = *((
unsigned char*)&(alphaBlock->
stuff[3]));
426 bits[2][0] =
static_cast<unsigned char>(stuff & 0x00000007);
428 bits[2][1] =
static_cast<unsigned char>(stuff & 0x00000007);
430 bits[2][2] =
static_cast<unsigned char>(stuff & 0x00000007);
432 bits[2][3] =
static_cast<unsigned char>(stuff & 0x00000007);
434 bits[3][0] =
static_cast<unsigned char>(stuff & 0x00000007);
436 bits[3][1] =
static_cast<unsigned char>(stuff & 0x00000007);
438 bits[3][2] =
static_cast<unsigned char>(stuff & 0x00000007);
440 bits[3][3] =
static_cast<unsigned char>(stuff & 0x00000007);
443 for (row = 0; row < 4; row++)
445 for (pix = 0; pix < 4; pix++)
447 aColors[row][pix].r = 0;
448 aColors[row][pix].g = 0;
449 aColors[row][pix].b = 0;
450 aColors[row][pix].a =
static_cast<unsigned char>(alphas[bits[row][pix]]);
455 for (row = 0; row < 4; row++, pixel += width - 4)
457 for (pix = 0; pix < 4; pix++)
464 unsigned int colorValue = (
static_cast<unsigned int>(c.
a) << 24) |
465 (
static_cast<unsigned int>(c.
r) << 16) |
466 (
static_cast<unsigned int>(c.
g) << 8) |
467 (
static_cast<unsigned int>(c.
b));
468 *pixel |= colorValue;
484 const int xBlocks = width / 4;
485 const int yBlocks = height / 4;
488 for (
int y = 0; y < yBlocks; y++)
494 for (
int x = 0; x < xBlocks; x++, block++)
498 unsigned int colorInts[4];
499 for (
int i = 0; i < 4; ++i)
501 colorInts[i] = (
static_cast<unsigned int>(colors[i].
a) << 24) |
502 (
static_cast<unsigned int>(colors[i].
r) << 16) |
503 (
static_cast<unsigned int>(colors[i].
g) << 8) |
504 (
static_cast<unsigned int>(colors[i].
b));
506 unsigned int* pixel =
reinterpret_cast<unsigned int*
>(dest + x * 16 + (y * 4) * width * 4);
524 const int xBlocks = width / 4;
525 const int yBlocks = height / 4;
532 const unsigned int alphaZero = *
reinterpret_cast<unsigned int*
>(&colors[0]);
535 for (
int y = 0; y < yBlocks; y++)
541 for (
int x = 0; x < xBlocks; x++, block++)
551 unsigned int* pixel =
reinterpret_cast<unsigned int*
>(dest + x * 16 + (y * 4) * width * 4);
571 const int xBlocks = width / 4;
572 const int yBlocks = height / 4;
579 const unsigned int alphaZero = *
reinterpret_cast<unsigned int*
>(&colors[0]);
582 for (
int y = 0; y < yBlocks; y++)
588 for (
int x = 0; x < xBlocks; x++, block++)
598 unsigned int* pixel =
reinterpret_cast<unsigned int*
>(dest + x * 16 + (y * 4) * width * 4);
650static int DDSDecompressARGB8888(
ddsBuffer_t *dds,
int width,
int height,
unsigned char *pixels )
653 unsigned char *in, *out;
661 for( y = 0; y <
height; y++ )
664 for( x = 0; x < width; x++ )
float DDSLittleFloat(float src)
short DDSLittleShort(short src)
static void DDSGetColorBlockColors(ddsColorBlock_t *block, ddsColor_t colors[4])
int DDSDecompressDXT1(unsigned char *src, int width, int height, unsigned char *dest)
Decompress a DXT1 (BC1) compressed texture into raw RGBA pixels.
short DDSBigShort(short src)
float DDSBigFloat(float src)
static void DDSDecodeAlpha3BitLinear(unsigned int *pixel, ddsAlphaBlock3BitLinear_t *alphaBlock, int width, unsigned int alphaZero)
int DDSLittleLong(int src)
int DDSDecompressDXT3(unsigned char *src, int width, int height, unsigned char *dest)
Decompress a DXT3 (BC2) compressed texture into raw RGBA pixels.
static void DDSDecodeAlphaExplicit(unsigned int *pixel, ddsAlphaBlockExplicit_t *alphaBlock, int width, unsigned int alphaZero)
static void DDSDecodeColorBlock(unsigned int *pixel, ddsColorBlock_t *block, int width, unsigned int colors[4])
int DDSDecompressDXT5(unsigned char *src, int width, int height, unsigned char *dest)
Decompress a DXT5 (BC3) compressed texture into raw RGBA pixels.
float height() noexcept
Title bar height in logical pixels (call after begin()).