More progress in DDS read support.
This commit is contained in:
parent
babb7e8df7
commit
ceef4c3ec0
@ -281,22 +281,29 @@ void BlockDXT3::decodeBlock(ColorBlock * block) const
|
||||
color.decodeBlock(block);
|
||||
|
||||
// Decode alpha.
|
||||
block->color(0x0).a = (alpha.alpha0 << 4) | alpha.alpha0;
|
||||
block->color(0x1).a = (alpha.alpha1 << 4) | alpha.alpha1;
|
||||
block->color(0x2).a = (alpha.alpha2 << 4) | alpha.alpha2;
|
||||
block->color(0x3).a = (alpha.alpha3 << 4) | alpha.alpha3;
|
||||
block->color(0x4).a = (alpha.alpha4 << 4) | alpha.alpha4;
|
||||
block->color(0x5).a = (alpha.alpha5 << 4) | alpha.alpha5;
|
||||
block->color(0x6).a = (alpha.alpha6 << 4) | alpha.alpha6;
|
||||
block->color(0x7).a = (alpha.alpha7 << 4) | alpha.alpha7;
|
||||
block->color(0x8).a = (alpha.alpha8 << 4) | alpha.alpha8;
|
||||
block->color(0x9).a = (alpha.alpha9 << 4) | alpha.alpha9;
|
||||
block->color(0xA).a = (alpha.alphaA << 4) | alpha.alphaA;
|
||||
block->color(0xB).a = (alpha.alphaB << 4) | alpha.alphaB;
|
||||
block->color(0xC).a = (alpha.alphaC << 4) | alpha.alphaC;
|
||||
block->color(0xD).a = (alpha.alphaD << 4) | alpha.alphaD;
|
||||
block->color(0xE).a = (alpha.alphaE << 4) | alpha.alphaE;
|
||||
block->color(0xF).a = (alpha.alphaF << 4) | alpha.alphaF;
|
||||
alpha.decodeBlock(block);
|
||||
}
|
||||
|
||||
void AlphaBlockDXT3::decodeBlock(ColorBlock * block) const
|
||||
{
|
||||
nvDebugCheck(block != NULL);
|
||||
|
||||
block->color(0x0).a = (alpha0 << 4) | alpha0;
|
||||
block->color(0x1).a = (alpha1 << 4) | alpha1;
|
||||
block->color(0x2).a = (alpha2 << 4) | alpha2;
|
||||
block->color(0x3).a = (alpha3 << 4) | alpha3;
|
||||
block->color(0x4).a = (alpha4 << 4) | alpha4;
|
||||
block->color(0x5).a = (alpha5 << 4) | alpha5;
|
||||
block->color(0x6).a = (alpha6 << 4) | alpha6;
|
||||
block->color(0x7).a = (alpha7 << 4) | alpha7;
|
||||
block->color(0x8).a = (alpha8 << 4) | alpha8;
|
||||
block->color(0x9).a = (alpha9 << 4) | alpha9;
|
||||
block->color(0xA).a = (alphaA << 4) | alphaA;
|
||||
block->color(0xB).a = (alphaB << 4) | alphaB;
|
||||
block->color(0xC).a = (alphaC << 4) | alphaC;
|
||||
block->color(0xD).a = (alphaD << 4) | alphaD;
|
||||
block->color(0xE).a = (alphaE << 4) | alphaE;
|
||||
block->color(0xF).a = (alphaF << 4) | alphaF;
|
||||
}
|
||||
|
||||
/// Flip DXT3 alpha block vertically.
|
||||
@ -387,21 +394,6 @@ void AlphaBlockDXT5::indices(uint8 index_array[16]) const
|
||||
index_array[0xD] = bitsD;
|
||||
index_array[0xE] = bitsE;
|
||||
index_array[0xF] = bitsF;
|
||||
|
||||
/*
|
||||
// @@ missaligned reads might be very expensive on some hardware.
|
||||
uint b = (uint &) bits[0];
|
||||
for(int i = 0; i < 8; i++) {
|
||||
index_array[i] = uint8(b & 0x07);
|
||||
b >>= 3;
|
||||
}
|
||||
|
||||
b = (uint &) bits[3];
|
||||
for(int i = 0; i < 8; i++) {
|
||||
index_array[8+i] = uint8(b & 0x07);
|
||||
b >>= 3;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
uint AlphaBlockDXT5::index(uint index) const
|
||||
@ -410,25 +402,6 @@ uint AlphaBlockDXT5::index(uint index) const
|
||||
|
||||
int offset = (3 * index + 16);
|
||||
return (this->u >> offset) & 0x7;
|
||||
/*
|
||||
if (index == 0x0) return bits0;
|
||||
else if (index == 0x1) return bits1;
|
||||
else if (index == 0x2) return bits2;
|
||||
else if (index == 0x3) return bits3;
|
||||
else if (index == 0x4) return bits4;
|
||||
else if (index == 0x5) return bits5;
|
||||
else if (index == 0x6) return bits6;
|
||||
else if (index == 0x7) return bits7;
|
||||
else if (index == 0x8) return bits8;
|
||||
else if (index == 0x9) return bits9;
|
||||
else if (index == 0xA) return bitsA;
|
||||
else if (index == 0xB) return bitsB;
|
||||
else if (index == 0xC) return bitsC;
|
||||
else if (index == 0xD) return bitsD;
|
||||
else if (index == 0xE) return bitsE;
|
||||
else if (index == 0xF) return bitsF;
|
||||
return 0;
|
||||
*/
|
||||
}
|
||||
|
||||
void AlphaBlockDXT5::setIndex(uint index, uint value)
|
||||
@ -439,26 +412,21 @@ void AlphaBlockDXT5::setIndex(uint index, uint value)
|
||||
int offset = (3 * index + 16);
|
||||
uint64 mask = uint64(0x7) << offset;
|
||||
this->u = (this->u & ~mask) | (uint64(value) << offset);
|
||||
}
|
||||
|
||||
/*
|
||||
// @@ Really bad code...
|
||||
if (index == 0x0) bits0 = value;
|
||||
else if (index == 0x1) bits1 = value;
|
||||
else if (index == 0x2) bits2 = value;
|
||||
else if (index == 0x3) bits3 = value;
|
||||
else if (index == 0x4) bits4 = value;
|
||||
else if (index == 0x5) bits5 = value;
|
||||
else if (index == 0x6) bits6 = value;
|
||||
else if (index == 0x7) bits7 = value;
|
||||
else if (index == 0x8) bits8 = value;
|
||||
else if (index == 0x9) bits9 = value;
|
||||
else if (index == 0xA) bitsA = value;
|
||||
else if (index == 0xB) bitsB = value;
|
||||
else if (index == 0xC) bitsC = value;
|
||||
else if (index == 0xD) bitsD = value;
|
||||
else if (index == 0xE) bitsE = value;
|
||||
else if (index == 0xF) bitsF = value;
|
||||
*/
|
||||
void AlphaBlockDXT5::decodeBlock(ColorBlock * block) const
|
||||
{
|
||||
nvDebugCheck(block != NULL);
|
||||
|
||||
uint8 alpha_array[8];
|
||||
evaluatePalette(alpha_array);
|
||||
|
||||
uint8 index_array[16];
|
||||
indices(index_array);
|
||||
|
||||
for(uint i = 0; i < 16; i++) {
|
||||
block->color(i).a = alpha_array[index_array[i]];
|
||||
}
|
||||
}
|
||||
|
||||
void AlphaBlockDXT5::flip4()
|
||||
@ -495,15 +463,8 @@ void BlockDXT5::decodeBlock(ColorBlock * block) const
|
||||
color.decodeBlock(block);
|
||||
|
||||
// Decode alpha.
|
||||
uint8 alpha_array[8];
|
||||
alpha.evaluatePalette(alpha_array);
|
||||
alpha.decodeBlock(block);
|
||||
|
||||
uint8 index_array[16];
|
||||
alpha.indices(index_array);
|
||||
|
||||
for(uint i = 0; i < 16; i++) {
|
||||
block->color(i).a = alpha_array[index_array[i]];
|
||||
}
|
||||
}
|
||||
|
||||
/// Flip DXT5 block vertically.
|
||||
|
@ -89,6 +89,8 @@ namespace nv
|
||||
uint16 row[4];
|
||||
};
|
||||
|
||||
void decodeBlock(ColorBlock * block) const;
|
||||
|
||||
void flip4();
|
||||
void flip2();
|
||||
};
|
||||
@ -142,6 +144,8 @@ namespace nv
|
||||
uint index(uint index) const;
|
||||
void setIndex(uint index, uint value);
|
||||
|
||||
void decodeBlock(ColorBlock * block) const;
|
||||
|
||||
void flip4();
|
||||
void flip2();
|
||||
};
|
||||
|
@ -52,7 +52,6 @@ namespace
|
||||
static const uint FOURCC_RXGB = MAKEFOURCC('R', 'X', 'G', 'B');
|
||||
static const uint FOURCC_ATI1 = MAKEFOURCC('A', 'T', 'I', '1');
|
||||
static const uint FOURCC_ATI2 = MAKEFOURCC('A', 'T', 'I', '2');
|
||||
static const uint FOURCC_BC3N = MAKEFOURCC('B', 'C', '3', 'N');
|
||||
|
||||
static const uint DDSD_CAPS = 0x00000001U;
|
||||
static const uint DDSD_PIXELFORMAT = 0x00001000U;
|
||||
@ -368,8 +367,7 @@ bool DirectDrawSurface::isSupported() const
|
||||
header.pf.fourcc != FOURCC_DXT5 &&
|
||||
header.pf.fourcc != FOURCC_RXGB &&
|
||||
header.pf.fourcc != FOURCC_ATI1 &&
|
||||
header.pf.fourcc != FOURCC_ATI2 &&
|
||||
header.pf.fourcc != FOURCC_BC3N)
|
||||
header.pf.fourcc != FOURCC_ATI2)
|
||||
{
|
||||
// Unknown fourcc code.
|
||||
return false;
|
||||
@ -480,20 +478,24 @@ void DirectDrawSurface::mipmap(Image * img, uint face, uint mipmap)
|
||||
}
|
||||
|
||||
|
||||
void DirectDrawSurface::readLinearImage(Stream * stream, Image * img)
|
||||
void DirectDrawSurface::readLinearImage(Image * img)
|
||||
{
|
||||
nvDebugCheck(stream != NULL);
|
||||
nvDebugCheck(img != NULL);
|
||||
|
||||
// @@ Read linear RGB images.
|
||||
}
|
||||
|
||||
void DirectDrawSurface::readBlockImage(Stream * stream, Image * img)
|
||||
void DirectDrawSurface::readBlockImage(Image * img)
|
||||
{
|
||||
nvDebugCheck(stream != NULL);
|
||||
nvDebugCheck(img != NULL);
|
||||
|
||||
const uint bw = (img->width() + 3) / 4;
|
||||
const uint bh = (img->height() + 3) / 4;
|
||||
const uint w = img->width();
|
||||
const uint h = img->height();
|
||||
|
||||
const uint bw = (w + 3) / 4;
|
||||
const uint bh = (h + 3) / 4;
|
||||
|
||||
for (uint by = 0; by < bh; by++)
|
||||
{
|
||||
@ -502,64 +504,96 @@ void DirectDrawSurface::readBlockImage(Stream * stream, Image * img)
|
||||
ColorBlock block;
|
||||
|
||||
// Read color block.
|
||||
readBlock(stream, &block);
|
||||
readBlock(&block);
|
||||
|
||||
// Write color block.
|
||||
|
||||
for (uint y = 0; y < min(4U, 4*bh-h); y++)
|
||||
{
|
||||
for (uint x = 0; x < min(4U, 4*bw-w); x++)
|
||||
{
|
||||
img->pixel(4*bx+x, 4*by+y) = block.color(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DirectDrawSurface::readBlock(Stream * stream, ColorBlock * rgba)
|
||||
void DirectDrawSurface::readBlock(ColorBlock * rgba)
|
||||
{
|
||||
nvDebugCheck(stream != NULL);
|
||||
nvDebugCheck(rgba != NULL);
|
||||
|
||||
if (header.pf.fourcc == FOURCC_DXT1 ||
|
||||
header.pf.fourcc == FOURCC_DXT2 ||
|
||||
header.pf.fourcc == FOURCC_DXT3 ||
|
||||
header.pf.fourcc == FOURCC_DXT4 ||
|
||||
header.pf.fourcc == FOURCC_DXT5 ||
|
||||
header.pf.fourcc == FOURCC_RXGB ||
|
||||
header.pf.fourcc != FOURCC_BC3N)
|
||||
/*if (header.pf.fourcc == FOURCC_DXT1)
|
||||
{
|
||||
// Read DXT1 block.
|
||||
BlockDXT1 block;
|
||||
|
||||
if (header.pf.fourcc == FOURCC_BC3N)
|
||||
{
|
||||
// Write G only
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write RGB.
|
||||
}
|
||||
}
|
||||
|
||||
if (header.pf.fourcc == FOURCC_ATI2)
|
||||
{
|
||||
// Read DXT5 alpha block.
|
||||
// Write R.
|
||||
}
|
||||
|
||||
if (header.pf.fourcc == FOURCC_DXT2 ||
|
||||
else if (header.pf.fourcc == FOURCC_DXT2 ||
|
||||
header.pf.fourcc == FOURCC_DXT3)
|
||||
{
|
||||
// Read DXT3 alpha block.
|
||||
BlockDXT3 block;
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
}
|
||||
|
||||
if (header.pf.fourcc == FOURCC_DXT4 ||
|
||||
else if (header.pf.fourcc == FOURCC_DXT4 ||
|
||||
header.pf.fourcc == FOURCC_DXT5 ||
|
||||
header.pf.fourcc == FOURCC_RXGB)
|
||||
{
|
||||
// Read DXT5 alpha block.
|
||||
}
|
||||
BlockDXT5 block;
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
|
||||
if (header.pf.fourcc == FOURCC_RXGB)
|
||||
{
|
||||
// swap G & A
|
||||
// Swap R & A.
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Color32 & c = rgba->color(i);
|
||||
uint tmp = c.r;
|
||||
c.r = c.a;
|
||||
c.a = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (header.pf.fourcc == FOURCC_ATI1)
|
||||
{
|
||||
AlphaBlockDXT5 block;
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Color32 & c = rgba->color(i);
|
||||
c.r = c.a;
|
||||
c.a = 255;
|
||||
}
|
||||
}
|
||||
else if (header.pf.fourcc == FOURCC_ATI2)
|
||||
{
|
||||
AlphaBlockDXT5 block;
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Color32 & c = rgba->color(i);
|
||||
c.r = c.a;
|
||||
}
|
||||
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Color32 & c = rgba->color(i);
|
||||
c.g = c.a;
|
||||
}
|
||||
}*/
|
||||
|
||||
// If normal map flag set, conver to normal.
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint DirectDrawSurface::blockSize() const
|
||||
@ -575,7 +609,6 @@ uint DirectDrawSurface::blockSize() const
|
||||
case FOURCC_DXT5:
|
||||
case FOURCC_RXGB:
|
||||
case FOURCC_ATI2:
|
||||
case FOURCC_BC3N:
|
||||
return 16;
|
||||
};
|
||||
|
||||
|
@ -112,9 +112,9 @@ namespace nv
|
||||
|
||||
uint offset(uint f, uint m);
|
||||
|
||||
void readLinearImage(Stream * stream, Image * img);
|
||||
void readBlockImage(Stream * stream, Image * img);
|
||||
void readBlock(Stream * stream, ColorBlock * rgba);
|
||||
void readLinearImage(Image * img);
|
||||
void readBlockImage(Image * img);
|
||||
void readBlock(ColorBlock * rgba);
|
||||
|
||||
|
||||
private:
|
||||
|
@ -11,7 +11,6 @@ SET(NVTT_SRCS
|
||||
FastCompressDXT.h
|
||||
FastCompressDXT.cpp
|
||||
dxtlib.cpp
|
||||
dxtlib_compat.h
|
||||
CompressionOptions.h
|
||||
CompressionOptions.cpp
|
||||
InputOptions.h
|
||||
|
Loading…
Reference in New Issue
Block a user