struct rgb565
{
short r : 5;
short g : 6;
short b : 5;
bool operator>( const rgb565 & rhs )
{
return *(ushort*)this > *(ushort*)&rhs;
}
};
struct rgba8
{
unsigned char r, g, b, a;
};
struct dxt1_block
{
rgb565 color0, color1;
uint code;
};
void foo( GLenum target, int mipmap, uint w, uint h, void* buffer ){
rgba8 * pixels = new rgba8[ w * h ];
dxt1_block * blocks = (dxt1_block*)buffer;
int x_blocks = w / 4;
int y_blocks = h / 4;
for(int y = 0; y < y_blocks; ++y)
{
for(int x = 0; x < x_blocks; ++x)
{
dxt1_block & b = blocks[ y * x_blocks + x ];
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 4; ++j)
{
int p_index = (w * (y + i)) + (x + j);
uint type = b.code & 3;
rgba8 & p = pixels[p_index];
switch(type)
{
case 0:
p.r = b.color0.r;
p.g = b.color0.g;
p.b = b.color0.b;
p.a = 255;
break;
case 1:
p.r = b.color1.r;
p.g = b.color1.g;
p.b = b.color1.b;
p.a = 255;
break;
case 2:
if(b.color0 > b.color1)
{
p.r = (2 * b.color0.r + b.color1.r) / 3;
p.g = (2 * b.color0.g + b.color1.g) / 3;
p.b = (2 * b.color0.b + b.color1.b) / 3;
}
else {
p.r = (b.color0.r + b.color1.r) / 2;
p.g = (b.color0.g + b.color1.g) / 2;
p.b = (b.color0.b + b.color1.b) / 2;
}
p.a = 255;
break;
case 3:
if(b.color0 > b.color1)
{
p.r = (b.color0.r + 2 * b.color1.r) / 3;
p.g = (b.color0.g + 2 * b.color1.g) / 3;
p.b = (b.color0.b + 2 * b.color1.b) / 3;
p.a = 255;
}
else {
p.r = 0;
p.b = 0;
p.g = 0;
p.a = 0;
}
break;
}
b.code >>= 2;
}
}
}
}
glTexImage2D(target, mipmap, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
delete[] pixels;
}
it seems to be a problem with how i'm calculating where the pixels go as there is a problem if the image is 2x2 or 1x1 nothing is written to the pixels buffer.
I can't seem to find much on dxt decompression, i know there are some libraries (libsquish) the way they decompress is nothing like how the article describes it.
Thanks for any help.