- Fix build.
- Add D3DFMTs. - Add BlockATI#.
This commit is contained in:
parent
3422f2e300
commit
2c1b75d8f3
@ -484,24 +484,72 @@ void BlockDXT5::flip2()
|
||||
}
|
||||
|
||||
|
||||
/// Decode 3DC block.
|
||||
void Block3DC::decodeBlock(ColorBlock * block) const
|
||||
/// Decode ATI1 block.
|
||||
void BlockATI1::decodeBlock(ColorBlock * block) const
|
||||
{
|
||||
// @@ TBD
|
||||
uint8 alpha_array[8];
|
||||
alpha.evaluatePalette(alpha_array);
|
||||
|
||||
uint8 index_array[16];
|
||||
alpha.indices(index_array);
|
||||
|
||||
for(uint i = 0; i < 16; i++) {
|
||||
Color32 & c = block->color(i);
|
||||
c.b = c.g = c.r = alpha_array[index_array[i]];
|
||||
c.a = 255;
|
||||
}
|
||||
}
|
||||
|
||||
/// Flip 3DC block vertically.
|
||||
void Block3DC::flip4()
|
||||
/// Flip ATI1 block vertically.
|
||||
void BlockATI1::flip4()
|
||||
{
|
||||
alpha.flip4();
|
||||
}
|
||||
|
||||
/// Flip half ATI1 block vertically.
|
||||
void BlockATI1::flip2()
|
||||
{
|
||||
alpha.flip2();
|
||||
}
|
||||
|
||||
|
||||
/// Decode ATI2 block.
|
||||
void BlockATI2::decodeBlock(ColorBlock * block) const
|
||||
{
|
||||
uint8 alpha_array[8];
|
||||
uint8 index_array[16];
|
||||
|
||||
x.evaluatePalette(alpha_array);
|
||||
x.indices(index_array);
|
||||
|
||||
for(uint i = 0; i < 16; i++) {
|
||||
Color32 & c = block->color(i);
|
||||
c.r = alpha_array[index_array[i]];
|
||||
}
|
||||
|
||||
y.evaluatePalette(alpha_array);
|
||||
y.indices(index_array);
|
||||
|
||||
for(uint i = 0; i < 16; i++) {
|
||||
Color32 & c = block->color(i);
|
||||
c.g = alpha_array[index_array[i]];
|
||||
c.b = 0;
|
||||
c.a = 255;
|
||||
}
|
||||
}
|
||||
|
||||
/// Flip ATI2 block vertically.
|
||||
void BlockATI2::flip4()
|
||||
{
|
||||
y.flip4();
|
||||
x.flip4();
|
||||
y.flip4();
|
||||
}
|
||||
|
||||
/// Flip half 3DC block vertically.
|
||||
void Block3DC::flip2()
|
||||
/// Flip half ATI2 block vertically.
|
||||
void BlockATI2::flip2()
|
||||
{
|
||||
y.flip2();
|
||||
x.flip2();
|
||||
y.flip2();
|
||||
}
|
||||
|
||||
|
||||
@ -534,14 +582,13 @@ Stream & nv::operator<<(Stream & stream, BlockDXT5 & block)
|
||||
return stream << block.alpha << block.color;
|
||||
}
|
||||
|
||||
Stream & nv::operator<<(Stream & stream, Block3DC & block)
|
||||
Stream & nv::operator<<(Stream & stream, BlockATI1 & block)
|
||||
{
|
||||
return stream << block.alpha;
|
||||
}
|
||||
|
||||
Stream & nv::operator<<(Stream & stream, BlockATI2 & block)
|
||||
{
|
||||
return stream << block.x << block.y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -33,6 +33,7 @@ namespace nv
|
||||
struct ColorBlock;
|
||||
class Stream;
|
||||
|
||||
|
||||
/// DXT1 block.
|
||||
struct BlockDXT1
|
||||
{
|
||||
@ -164,12 +165,22 @@ namespace nv
|
||||
void flip2();
|
||||
};
|
||||
|
||||
|
||||
/// 3DC block.
|
||||
struct Block3DC
|
||||
/// ATI1 block.
|
||||
struct BlockATI1
|
||||
{
|
||||
AlphaBlockDXT5 alpha;
|
||||
|
||||
void decodeBlock(ColorBlock * block) const;
|
||||
|
||||
void flip4();
|
||||
void flip2();
|
||||
};
|
||||
|
||||
/// ATI2 block.
|
||||
struct BlockATI2
|
||||
{
|
||||
AlphaBlockDXT5 y;
|
||||
AlphaBlockDXT5 x;
|
||||
AlphaBlockDXT5 y;
|
||||
|
||||
void decodeBlock(ColorBlock * block) const;
|
||||
|
||||
@ -183,7 +194,8 @@ namespace nv
|
||||
NVIMAGE_API Stream & operator<<(Stream & stream, BlockDXT3 & block);
|
||||
NVIMAGE_API Stream & operator<<(Stream & stream, AlphaBlockDXT5 & block);
|
||||
NVIMAGE_API Stream & operator<<(Stream & stream, BlockDXT5 & block);
|
||||
NVIMAGE_API Stream & operator<<(Stream & stream, Block3DC & block);
|
||||
NVIMAGE_API Stream & operator<<(Stream & stream, BlockATI1 & block);
|
||||
NVIMAGE_API Stream & operator<<(Stream & stream, BlockATI2 & block);
|
||||
|
||||
} // nv namespace
|
||||
|
||||
|
@ -53,13 +53,41 @@ namespace
|
||||
static const uint FOURCC_ATI1 = MAKEFOURCC('A', 'T', 'I', '1');
|
||||
static const uint FOURCC_ATI2 = MAKEFOURCC('A', 'T', 'I', '2');
|
||||
|
||||
static const uint D3DFMT_A16B16G16R16;
|
||||
static const uint D3DFMT_R16F;
|
||||
static const uint D3DFMT_G16R16F;
|
||||
static const uint D3DFMT_A16B16G16R16F;
|
||||
static const uint D3DFMT_R32F;
|
||||
static const uint D3DFMT_G32R32F;
|
||||
static const uint D3DFMT_A32B32G32R32F;
|
||||
// RGB formats.
|
||||
static const uint D3DFMT_R8G8B8 = 20;
|
||||
static const uint D3DFMT_A8R8G8B8 = 21;
|
||||
static const uint D3DFMT_X8R8G8B8 = 22;
|
||||
static const uint D3DFMT_R5G6B5 = 23;
|
||||
static const uint D3DFMT_X1R5G5B5 = 24;
|
||||
static const uint D3DFMT_A1R5G5B5 = 25;
|
||||
static const uint D3DFMT_A4R4G4B4 = 26;
|
||||
static const uint D3DFMT_R3G3B2 = 27;
|
||||
static const uint D3DFMT_A8 = 28;
|
||||
static const uint D3DFMT_A8R3G3B2 = 29;
|
||||
static const uint D3DFMT_X4R4G4B4 = 30;
|
||||
static const uint D3DFMT_A2B10G10R10 = 31;
|
||||
static const uint D3DFMT_A8B8G8R8 = 32;
|
||||
static const uint D3DFMT_X8B8G8R8 = 33;
|
||||
static const uint D3DFMT_G16R16 = 34;
|
||||
static const uint D3DFMT_A2R10G10B10 = 35;
|
||||
static const uint D3DFMT_A16B16G16R16 = 36;
|
||||
|
||||
// Palette formats.
|
||||
static const uint D3DFMT_A8P8 = 40;
|
||||
static const uint D3DFMT_P8 = 41;
|
||||
|
||||
// Luminance formats.
|
||||
static const uint D3DFMT_L8 = 50;
|
||||
static const uint D3DFMT_A8L8 = 51;
|
||||
static const uint D3DFMT_A4L4 = 52;
|
||||
|
||||
// Floating point formats
|
||||
static const uint D3DFMT_R16F = 111;
|
||||
static const uint D3DFMT_G16R16F = 112;
|
||||
static const uint D3DFMT_A16B16G16R16F = 113;
|
||||
static const uint D3DFMT_R32F = 114;
|
||||
static const uint D3DFMT_G32R32F = 115;
|
||||
static const uint D3DFMT_A32B32G32R32F = 116;
|
||||
|
||||
static const uint DDSD_CAPS = 0x00000001U;
|
||||
static const uint DDSD_PIXELFORMAT = 0x00001000U;
|
||||
@ -541,6 +569,17 @@ void DirectDrawSurface::readBlockImage(Image * img)
|
||||
}
|
||||
}
|
||||
|
||||
static Color32 buildNormal(uint8 x, uint8 y)
|
||||
{
|
||||
float nx = 2 * (x / 255) - 1;
|
||||
float ny = 2 * (x / 255) - 1;
|
||||
float nz = sqrtf(1 - nx*nx - ny*ny);
|
||||
uint8 z = clamp(int(255 * (nz + 1) / 2), 0, 255);
|
||||
|
||||
return Color32(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
void DirectDrawSurface::readBlock(ColorBlock * rgba)
|
||||
{
|
||||
nvDebugCheck(stream != NULL);
|
||||
@ -581,43 +620,37 @@ void DirectDrawSurface::readBlock(ColorBlock * rgba)
|
||||
}
|
||||
else if (header.pf.fourcc == FOURCC_ATI1)
|
||||
{
|
||||
AlphaBlockDXT5 block;
|
||||
BlockATI1 block;
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Color32 & c = rgba->color(i);
|
||||
c.r = c.g = c.b = c.a;
|
||||
c.a = 255;
|
||||
}
|
||||
}
|
||||
else if (header.pf.fourcc == FOURCC_ATI2)
|
||||
{
|
||||
AlphaBlockDXT5 block;
|
||||
BlockATI2 block;
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
}
|
||||
|
||||
// If normal flag set, convert to normal.
|
||||
if (header.pf.flags & DDPF_NORMAL)
|
||||
{
|
||||
if (header.pf.fourcc == FOURCC_ATI2)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Color32 & c = rgba->color(i);
|
||||
c.r = c.a;
|
||||
c = buildNormal(c.r, c.g);
|
||||
}
|
||||
|
||||
*stream << block;
|
||||
block.decodeBlock(rgba);
|
||||
|
||||
}
|
||||
else if (header.pf.fourcc == FOURCC_DXT5)
|
||||
{
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Color32 & c = rgba->color(i);
|
||||
c.g = c.a;
|
||||
c.b = 0;
|
||||
c.a = 255;
|
||||
c = buildNormal(c.g, c.a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @@ If normal map flag set, convert to normal.
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,6 +103,7 @@ namespace nv
|
||||
bool isTextureCube() const;
|
||||
|
||||
void mipmap(Image * img, uint f, uint m);
|
||||
// void mipmap(FloatImage * img, uint f, uint m);
|
||||
|
||||
void printInfo() const;
|
||||
|
||||
|
@ -368,7 +368,7 @@ void nv::compressBC5(const Image * image, const nvtt::OutputOptions & outputOpti
|
||||
ColorBlock xcolor;
|
||||
ColorBlock ycolor;
|
||||
|
||||
Block3DC block;
|
||||
BlockATI2 block;
|
||||
|
||||
for (uint y = 0; y < h; y += 4) {
|
||||
for (uint x = 0; x < w; x += 4) {
|
||||
|
Loading…
Reference in New Issue
Block a user