Add support for D3D9 and D3D10 decoders. Fixes issue 157.
This commit is contained in:
parent
94dce3b623
commit
0a290a64cc
@ -35,7 +35,7 @@ using namespace nv;
|
|||||||
BlockDXT1
|
BlockDXT1
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const
|
uint BlockDXT1::evaluatePalette(Color32 color_array[4], bool d3d9/*= false*/) const
|
||||||
{
|
{
|
||||||
// Does bit expansion before interpolation.
|
// Does bit expansion before interpolation.
|
||||||
color_array[0].b = (col0.b << 3) | (col0.b >> 2);
|
color_array[0].b = (col0.b << 3) | (col0.b >> 2);
|
||||||
@ -62,15 +62,18 @@ uint BlockDXT1::evaluatePalette(Color32 color_array[4]) const
|
|||||||
// color_array[1].u = c.u;
|
// color_array[1].u = c.u;
|
||||||
|
|
||||||
if( col0.u > col1.u ) {
|
if( col0.u > col1.u ) {
|
||||||
|
int bias = 0;
|
||||||
|
if (d3d9) bias = 1;
|
||||||
|
|
||||||
// Four-color block: derive the other two colors.
|
// Four-color block: derive the other two colors.
|
||||||
color_array[2].r = (2 * color_array[0].r + color_array[1].r) / 3;
|
color_array[2].r = (2 * color_array[0].r + color_array[1].r + bias) / 3;
|
||||||
color_array[2].g = (2 * color_array[0].g + color_array[1].g) / 3;
|
color_array[2].g = (2 * color_array[0].g + color_array[1].g + bias) / 3;
|
||||||
color_array[2].b = (2 * color_array[0].b + color_array[1].b) / 3;
|
color_array[2].b = (2 * color_array[0].b + color_array[1].b + bias) / 3;
|
||||||
color_array[2].a = 0xFF;
|
color_array[2].a = 0xFF;
|
||||||
|
|
||||||
color_array[3].r = (2 * color_array[1].r + color_array[0].r) / 3;
|
color_array[3].r = (2 * color_array[1].r + color_array[0].r + bias) / 3;
|
||||||
color_array[3].g = (2 * color_array[1].g + color_array[0].g) / 3;
|
color_array[3].g = (2 * color_array[1].g + color_array[0].g + bias) / 3;
|
||||||
color_array[3].b = (2 * color_array[1].b + color_array[0].b) / 3;
|
color_array[3].b = (2 * color_array[1].b + color_array[0].b + bias) / 3;
|
||||||
color_array[3].a = 0xFF;
|
color_array[3].a = 0xFF;
|
||||||
|
|
||||||
return 4;
|
return 4;
|
||||||
@ -140,7 +143,7 @@ uint BlockDXT1::evaluatePaletteNV5x(Color32 color_array[4]) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate palette assuming 3 color block.
|
// Evaluate palette assuming 3 color block.
|
||||||
void BlockDXT1::evaluatePalette3(Color32 color_array[4]) const
|
void BlockDXT1::evaluatePalette3(Color32 color_array[4], bool d3d9) const
|
||||||
{
|
{
|
||||||
color_array[0].b = (col0.b << 3) | (col0.b >> 2);
|
color_array[0].b = (col0.b << 3) | (col0.b >> 2);
|
||||||
color_array[0].g = (col0.g << 2) | (col0.g >> 4);
|
color_array[0].g = (col0.g << 2) | (col0.g >> 4);
|
||||||
@ -166,7 +169,7 @@ void BlockDXT1::evaluatePalette3(Color32 color_array[4]) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate palette assuming 4 color block.
|
// Evaluate palette assuming 4 color block.
|
||||||
void BlockDXT1::evaluatePalette4(Color32 color_array[4]) const
|
void BlockDXT1::evaluatePalette4(Color32 color_array[4], bool d3d9) const
|
||||||
{
|
{
|
||||||
color_array[0].b = (col0.b << 3) | (col0.b >> 2);
|
color_array[0].b = (col0.b << 3) | (col0.b >> 2);
|
||||||
color_array[0].g = (col0.g << 2) | (col0.g >> 4);
|
color_array[0].g = (col0.g << 2) | (col0.g >> 4);
|
||||||
@ -178,26 +181,29 @@ void BlockDXT1::evaluatePalette4(Color32 color_array[4]) const
|
|||||||
color_array[1].b = (col1.b << 3) | (col1.b >> 2);
|
color_array[1].b = (col1.b << 3) | (col1.b >> 2);
|
||||||
color_array[1].a = 0xFF;
|
color_array[1].a = 0xFF;
|
||||||
|
|
||||||
|
int bias = 0;
|
||||||
|
if (d3d9) bias = 1;
|
||||||
|
|
||||||
// Four-color block: derive the other two colors.
|
// Four-color block: derive the other two colors.
|
||||||
color_array[2].r = (2 * color_array[0].r + color_array[1].r) / 3;
|
color_array[2].r = (2 * color_array[0].r + color_array[1].r + bias) / 3;
|
||||||
color_array[2].g = (2 * color_array[0].g + color_array[1].g) / 3;
|
color_array[2].g = (2 * color_array[0].g + color_array[1].g + bias) / 3;
|
||||||
color_array[2].b = (2 * color_array[0].b + color_array[1].b) / 3;
|
color_array[2].b = (2 * color_array[0].b + color_array[1].b + bias) / 3;
|
||||||
color_array[2].a = 0xFF;
|
color_array[2].a = 0xFF;
|
||||||
|
|
||||||
color_array[3].r = (2 * color_array[1].r + color_array[0].r) / 3;
|
color_array[3].r = (2 * color_array[1].r + color_array[0].r + bias) / 3;
|
||||||
color_array[3].g = (2 * color_array[1].g + color_array[0].g) / 3;
|
color_array[3].g = (2 * color_array[1].g + color_array[0].g + bias) / 3;
|
||||||
color_array[3].b = (2 * color_array[1].b + color_array[0].b) / 3;
|
color_array[3].b = (2 * color_array[1].b + color_array[0].b + bias) / 3;
|
||||||
color_array[3].a = 0xFF;
|
color_array[3].a = 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BlockDXT1::decodeBlock(ColorBlock * block) const
|
void BlockDXT1::decodeBlock(ColorBlock * block, bool d3d9/*= false*/) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(block != NULL);
|
nvDebugCheck(block != NULL);
|
||||||
|
|
||||||
// Decode color block.
|
// Decode color block.
|
||||||
Color32 color_array[4];
|
Color32 color_array[4];
|
||||||
evaluatePalette(color_array);
|
evaluatePalette(color_array, d3d9);
|
||||||
|
|
||||||
// Write color block.
|
// Write color block.
|
||||||
for( uint j = 0; j < 4; j++ ) {
|
for( uint j = 0; j < 4; j++ ) {
|
||||||
@ -252,15 +258,15 @@ inline void BlockDXT1::flip2()
|
|||||||
BlockDXT3
|
BlockDXT3
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void BlockDXT3::decodeBlock(ColorBlock * block) const
|
void BlockDXT3::decodeBlock(ColorBlock * block, bool d3d9/*= false*/) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(block != NULL);
|
nvDebugCheck(block != NULL);
|
||||||
|
|
||||||
// Decode color.
|
// Decode color.
|
||||||
color.decodeBlock(block);
|
color.decodeBlock(block, d3d9);
|
||||||
|
|
||||||
// Decode alpha.
|
// Decode alpha.
|
||||||
alpha.decodeBlock(block);
|
alpha.decodeBlock(block, d3d9);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockDXT3::decodeBlockNV5x(ColorBlock * block) const
|
void BlockDXT3::decodeBlockNV5x(ColorBlock * block) const
|
||||||
@ -271,7 +277,7 @@ void BlockDXT3::decodeBlockNV5x(ColorBlock * block) const
|
|||||||
alpha.decodeBlock(block);
|
alpha.decodeBlock(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlphaBlockDXT3::decodeBlock(ColorBlock * block) const
|
void AlphaBlockDXT3::decodeBlock(ColorBlock * block, bool d3d9/*= false*/) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(block != NULL);
|
nvDebugCheck(block != NULL);
|
||||||
|
|
||||||
@ -325,40 +331,46 @@ void BlockDXT3::flip2()
|
|||||||
BlockDXT5
|
BlockDXT5
|
||||||
----------------------------------------------------------------------------*/
|
----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void AlphaBlockDXT5::evaluatePalette(uint8 alpha[8]) const
|
void AlphaBlockDXT5::evaluatePalette(uint8 alpha[8], bool d3d9) const
|
||||||
{
|
{
|
||||||
if (alpha0 > alpha1) {
|
if (alpha0 > alpha1) {
|
||||||
evaluatePalette8(alpha);
|
evaluatePalette8(alpha, d3d9);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
evaluatePalette6(alpha);
|
evaluatePalette6(alpha, d3d9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlphaBlockDXT5::evaluatePalette8(uint8 alpha[8]) const
|
void AlphaBlockDXT5::evaluatePalette8(uint8 alpha[8], bool d3d9) const
|
||||||
{
|
{
|
||||||
|
int bias = 0;
|
||||||
|
if (d3d9) bias = 3;
|
||||||
|
|
||||||
// 8-alpha block: derive the other six alphas.
|
// 8-alpha block: derive the other six alphas.
|
||||||
// Bit code 000 = alpha0, 001 = alpha1, others are interpolated.
|
// Bit code 000 = alpha0, 001 = alpha1, others are interpolated.
|
||||||
alpha[0] = alpha0;
|
alpha[0] = alpha0;
|
||||||
alpha[1] = alpha1;
|
alpha[1] = alpha1;
|
||||||
alpha[2] = (6 * alpha[0] + 1 * alpha[1]) / 7; // bit code 010
|
alpha[2] = (6 * alpha[0] + 1 * alpha[1] + bias) / 7; // bit code 010
|
||||||
alpha[3] = (5 * alpha[0] + 2 * alpha[1]) / 7; // bit code 011
|
alpha[3] = (5 * alpha[0] + 2 * alpha[1] + bias) / 7; // bit code 011
|
||||||
alpha[4] = (4 * alpha[0] + 3 * alpha[1]) / 7; // bit code 100
|
alpha[4] = (4 * alpha[0] + 3 * alpha[1] + bias) / 7; // bit code 100
|
||||||
alpha[5] = (3 * alpha[0] + 4 * alpha[1]) / 7; // bit code 101
|
alpha[5] = (3 * alpha[0] + 4 * alpha[1] + bias) / 7; // bit code 101
|
||||||
alpha[6] = (2 * alpha[0] + 5 * alpha[1]) / 7; // bit code 110
|
alpha[6] = (2 * alpha[0] + 5 * alpha[1] + bias) / 7; // bit code 110
|
||||||
alpha[7] = (1 * alpha[0] + 6 * alpha[1]) / 7; // bit code 111
|
alpha[7] = (1 * alpha[0] + 6 * alpha[1] + bias) / 7; // bit code 111
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlphaBlockDXT5::evaluatePalette6(uint8 alpha[8]) const
|
void AlphaBlockDXT5::evaluatePalette6(uint8 alpha[8], bool d3d9) const
|
||||||
{
|
{
|
||||||
|
int bias = 0;
|
||||||
|
if (d3d9) bias = 2;
|
||||||
|
|
||||||
// 6-alpha block.
|
// 6-alpha block.
|
||||||
// Bit code 000 = alpha0, 001 = alpha1, others are interpolated.
|
// Bit code 000 = alpha0, 001 = alpha1, others are interpolated.
|
||||||
alpha[0] = alpha0;
|
alpha[0] = alpha0;
|
||||||
alpha[1] = alpha1;
|
alpha[1] = alpha1;
|
||||||
alpha[2] = (4 * alpha[0] + 1 * alpha[1]) / 5; // Bit code 010
|
alpha[2] = (4 * alpha[0] + 1 * alpha[1] + bias) / 5; // Bit code 010
|
||||||
alpha[3] = (3 * alpha[0] + 2 * alpha[1]) / 5; // Bit code 011
|
alpha[3] = (3 * alpha[0] + 2 * alpha[1] + bias) / 5; // Bit code 011
|
||||||
alpha[4] = (2 * alpha[0] + 3 * alpha[1]) / 5; // Bit code 100
|
alpha[4] = (2 * alpha[0] + 3 * alpha[1] + bias) / 5; // Bit code 100
|
||||||
alpha[5] = (1 * alpha[0] + 4 * alpha[1]) / 5; // Bit code 101
|
alpha[5] = (1 * alpha[0] + 4 * alpha[1] + bias) / 5; // Bit code 101
|
||||||
alpha[6] = 0x00; // Bit code 110
|
alpha[6] = 0x00; // Bit code 110
|
||||||
alpha[7] = 0xFF; // Bit code 111
|
alpha[7] = 0xFF; // Bit code 111
|
||||||
}
|
}
|
||||||
@ -401,12 +413,12 @@ void AlphaBlockDXT5::setIndex(uint index, uint value)
|
|||||||
this->u = (this->u & ~mask) | (uint64(value) << offset);
|
this->u = (this->u & ~mask) | (uint64(value) << offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlphaBlockDXT5::decodeBlock(ColorBlock * block) const
|
void AlphaBlockDXT5::decodeBlock(ColorBlock * block, bool d3d9/*= false*/) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(block != NULL);
|
nvDebugCheck(block != NULL);
|
||||||
|
|
||||||
uint8 alpha_array[8];
|
uint8 alpha_array[8];
|
||||||
evaluatePalette(alpha_array);
|
evaluatePalette(alpha_array, d3d9);
|
||||||
|
|
||||||
uint8 index_array[16];
|
uint8 index_array[16];
|
||||||
indices(index_array);
|
indices(index_array);
|
||||||
@ -442,15 +454,15 @@ void AlphaBlockDXT5::flip2()
|
|||||||
*b = tmp;
|
*b = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockDXT5::decodeBlock(ColorBlock * block) const
|
void BlockDXT5::decodeBlock(ColorBlock * block, bool d3d9/*= false*/) const
|
||||||
{
|
{
|
||||||
nvDebugCheck(block != NULL);
|
nvDebugCheck(block != NULL);
|
||||||
|
|
||||||
// Decode color.
|
// Decode color.
|
||||||
color.decodeBlock(block);
|
color.decodeBlock(block, d3d9);
|
||||||
|
|
||||||
// Decode alpha.
|
// Decode alpha.
|
||||||
alpha.decodeBlock(block);
|
alpha.decodeBlock(block, d3d9);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockDXT5::decodeBlockNV5x(ColorBlock * block) const
|
void BlockDXT5::decodeBlockNV5x(ColorBlock * block) const
|
||||||
@ -480,10 +492,10 @@ void BlockDXT5::flip2()
|
|||||||
|
|
||||||
|
|
||||||
/// Decode ATI1 block.
|
/// Decode ATI1 block.
|
||||||
void BlockATI1::decodeBlock(ColorBlock * block) const
|
void BlockATI1::decodeBlock(ColorBlock * block, bool d3d9/*= false*/) const
|
||||||
{
|
{
|
||||||
uint8 alpha_array[8];
|
uint8 alpha_array[8];
|
||||||
alpha.evaluatePalette(alpha_array);
|
alpha.evaluatePalette(alpha_array, d3d9);
|
||||||
|
|
||||||
uint8 index_array[16];
|
uint8 index_array[16];
|
||||||
alpha.indices(index_array);
|
alpha.indices(index_array);
|
||||||
@ -509,12 +521,12 @@ void BlockATI1::flip2()
|
|||||||
|
|
||||||
|
|
||||||
/// Decode ATI2 block.
|
/// Decode ATI2 block.
|
||||||
void BlockATI2::decodeBlock(ColorBlock * block) const
|
void BlockATI2::decodeBlock(ColorBlock * block, bool d3d9/*= false*/) const
|
||||||
{
|
{
|
||||||
uint8 alpha_array[8];
|
uint8 alpha_array[8];
|
||||||
uint8 index_array[16];
|
uint8 index_array[16];
|
||||||
|
|
||||||
x.evaluatePalette(alpha_array);
|
x.evaluatePalette(alpha_array, d3d9);
|
||||||
x.indices(index_array);
|
x.indices(index_array);
|
||||||
|
|
||||||
for(uint i = 0; i < 16; i++) {
|
for(uint i = 0; i < 16; i++) {
|
||||||
@ -522,7 +534,7 @@ void BlockATI2::decodeBlock(ColorBlock * block) const
|
|||||||
c.r = alpha_array[index_array[i]];
|
c.r = alpha_array[index_array[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
y.evaluatePalette(alpha_array);
|
y.evaluatePalette(alpha_array, d3d9);
|
||||||
y.indices(index_array);
|
y.indices(index_array);
|
||||||
|
|
||||||
for(uint i = 0; i < 16; i++) {
|
for(uint i = 0; i < 16; i++) {
|
||||||
|
@ -47,13 +47,13 @@ namespace nv
|
|||||||
|
|
||||||
bool isFourColorMode() const;
|
bool isFourColorMode() const;
|
||||||
|
|
||||||
uint evaluatePalette(Color32 color_array[4]) const;
|
uint evaluatePalette(Color32 color_array[4], bool d3d9) const;
|
||||||
uint evaluatePaletteNV5x(Color32 color_array[4]) const;
|
uint evaluatePaletteNV5x(Color32 color_array[4]) const;
|
||||||
|
|
||||||
void evaluatePalette3(Color32 color_array[4]) const;
|
void evaluatePalette3(Color32 color_array[4], bool d3d9) const;
|
||||||
void evaluatePalette4(Color32 color_array[4]) const;
|
void evaluatePalette4(Color32 color_array[4], bool d3d9) const;
|
||||||
|
|
||||||
void decodeBlock(ColorBlock * block) const;
|
void decodeBlock(ColorBlock * block, bool d3d9 = false) const;
|
||||||
void decodeBlockNV5x(ColorBlock * block) const;
|
void decodeBlockNV5x(ColorBlock * block) const;
|
||||||
|
|
||||||
void setIndices(int * idx);
|
void setIndices(int * idx);
|
||||||
@ -94,7 +94,7 @@ namespace nv
|
|||||||
uint16 row[4];
|
uint16 row[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
void decodeBlock(ColorBlock * block) const;
|
void decodeBlock(ColorBlock * block, bool d3d9 = false) const;
|
||||||
|
|
||||||
void flip4();
|
void flip4();
|
||||||
void flip2();
|
void flip2();
|
||||||
@ -107,7 +107,7 @@ namespace nv
|
|||||||
AlphaBlockDXT3 alpha;
|
AlphaBlockDXT3 alpha;
|
||||||
BlockDXT1 color;
|
BlockDXT1 color;
|
||||||
|
|
||||||
void decodeBlock(ColorBlock * block) const;
|
void decodeBlock(ColorBlock * block, bool d3d9 = false) const;
|
||||||
void decodeBlockNV5x(ColorBlock * block) const;
|
void decodeBlockNV5x(ColorBlock * block) const;
|
||||||
|
|
||||||
void flip4();
|
void flip4();
|
||||||
@ -142,15 +142,15 @@ namespace nv
|
|||||||
uint64 u;
|
uint64 u;
|
||||||
};
|
};
|
||||||
|
|
||||||
void evaluatePalette(uint8 alpha[8]) const;
|
void evaluatePalette(uint8 alpha[8], bool d3d9) const;
|
||||||
void evaluatePalette8(uint8 alpha[8]) const;
|
void evaluatePalette8(uint8 alpha[8], bool d3d9) const;
|
||||||
void evaluatePalette6(uint8 alpha[8]) const;
|
void evaluatePalette6(uint8 alpha[8], bool d3d9) const;
|
||||||
void indices(uint8 index_array[16]) const;
|
void indices(uint8 index_array[16]) const;
|
||||||
|
|
||||||
uint index(uint index) const;
|
uint index(uint index) const;
|
||||||
void setIndex(uint index, uint value);
|
void setIndex(uint index, uint value);
|
||||||
|
|
||||||
void decodeBlock(ColorBlock * block) const;
|
void decodeBlock(ColorBlock * block, bool d3d9 = false) const;
|
||||||
|
|
||||||
void flip4();
|
void flip4();
|
||||||
void flip2();
|
void flip2();
|
||||||
@ -163,7 +163,7 @@ namespace nv
|
|||||||
AlphaBlockDXT5 alpha;
|
AlphaBlockDXT5 alpha;
|
||||||
BlockDXT1 color;
|
BlockDXT1 color;
|
||||||
|
|
||||||
void decodeBlock(ColorBlock * block) const;
|
void decodeBlock(ColorBlock * block, bool d3d9 = false) const;
|
||||||
void decodeBlockNV5x(ColorBlock * block) const;
|
void decodeBlockNV5x(ColorBlock * block) const;
|
||||||
|
|
||||||
void flip4();
|
void flip4();
|
||||||
@ -175,7 +175,7 @@ namespace nv
|
|||||||
{
|
{
|
||||||
AlphaBlockDXT5 alpha;
|
AlphaBlockDXT5 alpha;
|
||||||
|
|
||||||
void decodeBlock(ColorBlock * block) const;
|
void decodeBlock(ColorBlock * block, bool d3d9 = false) const;
|
||||||
|
|
||||||
void flip4();
|
void flip4();
|
||||||
void flip2();
|
void flip2();
|
||||||
@ -187,7 +187,7 @@ namespace nv
|
|||||||
AlphaBlockDXT5 x;
|
AlphaBlockDXT5 x;
|
||||||
AlphaBlockDXT5 y;
|
AlphaBlockDXT5 y;
|
||||||
|
|
||||||
void decodeBlock(ColorBlock * block) const;
|
void decodeBlock(ColorBlock * block, bool d3d9 = false) const;
|
||||||
|
|
||||||
void flip4();
|
void flip4();
|
||||||
void flip2();
|
void flip2();
|
||||||
|
@ -331,7 +331,7 @@ bool ClusterFit::compress4( Vector3 * start, Vector3 * end )
|
|||||||
|
|
||||||
bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
|
bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
|
||||||
{
|
{
|
||||||
int const count = m_count;
|
const uint count = m_count;
|
||||||
const Vector3 one( 1.0f );
|
const Vector3 one( 1.0f );
|
||||||
const Vector3 zero( 0.0f );
|
const Vector3 zero( 0.0f );
|
||||||
const Vector3 half( 0.5f );
|
const Vector3 half( 0.5f );
|
||||||
@ -418,7 +418,7 @@ bool ClusterFit::compress3(Vector3 * start, Vector3 * end)
|
|||||||
|
|
||||||
bool ClusterFit::compress4(Vector3 * start, Vector3 * end)
|
bool ClusterFit::compress4(Vector3 * start, Vector3 * end)
|
||||||
{
|
{
|
||||||
int const count = m_count;
|
const uint count = m_count;
|
||||||
Vector3 const one( 1.0f );
|
Vector3 const one( 1.0f );
|
||||||
Vector3 const zero( 0.0f );
|
Vector3 const zero( 0.0f );
|
||||||
Vector3 const half( 0.5f );
|
Vector3 const half( 0.5f );
|
||||||
|
@ -188,7 +188,7 @@ namespace
|
|||||||
static uint computeAlphaError(const ColorBlock & rgba, const AlphaBlockDXT5 * block, int bestError = INT_MAX)
|
static uint computeAlphaError(const ColorBlock & rgba, const AlphaBlockDXT5 * block, int bestError = INT_MAX)
|
||||||
{
|
{
|
||||||
uint8 alphas[8];
|
uint8 alphas[8];
|
||||||
block->evaluatePalette(alphas);
|
block->evaluatePalette(alphas, false); // @@ Use target decoder.
|
||||||
|
|
||||||
int totalError = 0;
|
int totalError = 0;
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ namespace
|
|||||||
static void computeAlphaIndices(const ColorBlock & rgba, AlphaBlockDXT5 * block)
|
static void computeAlphaIndices(const ColorBlock & rgba, AlphaBlockDXT5 * block)
|
||||||
{
|
{
|
||||||
uint8 alphas[8];
|
uint8 alphas[8];
|
||||||
block->evaluatePalette(alphas);
|
block->evaluatePalette(alphas, false); // @@ Use target decoder.
|
||||||
|
|
||||||
for (uint i = 0; i < 16; i++)
|
for (uint i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
@ -375,7 +375,7 @@ void OptimalCompress::compressDXT1G(const ColorBlock & rgba, BlockDXT1 * block)
|
|||||||
|
|
||||||
|
|
||||||
Color32 palette[4];
|
Color32 palette[4];
|
||||||
block->evaluatePalette(palette);
|
block->evaluatePalette(palette, false); // @@ Use target decoder.
|
||||||
block->indices = computeGreenIndices(rgba, palette);
|
block->indices = computeGreenIndices(rgba, palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,7 +381,7 @@ namespace
|
|||||||
static uint computeAlphaIndices(const ColorBlock & rgba, AlphaBlockDXT5 * block)
|
static uint computeAlphaIndices(const ColorBlock & rgba, AlphaBlockDXT5 * block)
|
||||||
{
|
{
|
||||||
uint8 alphas[8];
|
uint8 alphas[8];
|
||||||
block->evaluatePalette(alphas);
|
block->evaluatePalette(alphas, false); // @@ Use target decoder.
|
||||||
|
|
||||||
uint totalError = 0;
|
uint totalError = 0;
|
||||||
|
|
||||||
|
@ -553,8 +553,11 @@ bool TexImage::setImage2D(Format format, Decoder decoder, int w, int h, const vo
|
|||||||
{
|
{
|
||||||
const BlockDXT1 * block = (const BlockDXT1 *)ptr;
|
const BlockDXT1 * block = (const BlockDXT1 *)ptr;
|
||||||
|
|
||||||
if (decoder == Decoder_Reference) {
|
if (decoder == Decoder_D3D10) {
|
||||||
block->decodeBlock(&colors);
|
block->decodeBlock(&colors, false);
|
||||||
|
}
|
||||||
|
else if (decoder == Decoder_D3D9) {
|
||||||
|
block->decodeBlock(&colors, false);
|
||||||
}
|
}
|
||||||
else if (decoder == Decoder_NV5x) {
|
else if (decoder == Decoder_NV5x) {
|
||||||
block->decodeBlockNV5x(&colors);
|
block->decodeBlockNV5x(&colors);
|
||||||
@ -564,8 +567,11 @@ bool TexImage::setImage2D(Format format, Decoder decoder, int w, int h, const vo
|
|||||||
{
|
{
|
||||||
const BlockDXT3 * block = (const BlockDXT3 *)ptr;
|
const BlockDXT3 * block = (const BlockDXT3 *)ptr;
|
||||||
|
|
||||||
if (decoder == Decoder_Reference) {
|
if (decoder == Decoder_D3D10) {
|
||||||
block->decodeBlock(&colors);
|
block->decodeBlock(&colors, false);
|
||||||
|
}
|
||||||
|
else if (decoder == Decoder_D3D9) {
|
||||||
|
block->decodeBlock(&colors, false);
|
||||||
}
|
}
|
||||||
else if (decoder == Decoder_NV5x) {
|
else if (decoder == Decoder_NV5x) {
|
||||||
block->decodeBlockNV5x(&colors);
|
block->decodeBlockNV5x(&colors);
|
||||||
@ -575,8 +581,11 @@ bool TexImage::setImage2D(Format format, Decoder decoder, int w, int h, const vo
|
|||||||
{
|
{
|
||||||
const BlockDXT5 * block = (const BlockDXT5 *)ptr;
|
const BlockDXT5 * block = (const BlockDXT5 *)ptr;
|
||||||
|
|
||||||
if (decoder == Decoder_Reference) {
|
if (decoder == Decoder_D3D10) {
|
||||||
block->decodeBlock(&colors);
|
block->decodeBlock(&colors, false);
|
||||||
|
}
|
||||||
|
else if (decoder == Decoder_D3D9) {
|
||||||
|
block->decodeBlock(&colors, false);
|
||||||
}
|
}
|
||||||
else if (decoder == Decoder_NV5x) {
|
else if (decoder == Decoder_NV5x) {
|
||||||
block->decodeBlockNV5x(&colors);
|
block->decodeBlockNV5x(&colors);
|
||||||
@ -585,12 +594,12 @@ bool TexImage::setImage2D(Format format, Decoder decoder, int w, int h, const vo
|
|||||||
else if (format == nvtt::Format_BC4)
|
else if (format == nvtt::Format_BC4)
|
||||||
{
|
{
|
||||||
const BlockATI1 * block = (const BlockATI1 *)ptr;
|
const BlockATI1 * block = (const BlockATI1 *)ptr;
|
||||||
block->decodeBlock(&colors);
|
block->decodeBlock(&colors, decoder == Decoder_D3D9);
|
||||||
}
|
}
|
||||||
else if (format == nvtt::Format_BC5)
|
else if (format == nvtt::Format_BC5)
|
||||||
{
|
{
|
||||||
const BlockATI2 * block = (const BlockATI2 *)ptr;
|
const BlockATI2 * block = (const BlockATI2 *)ptr;
|
||||||
block->decodeBlock(&colors);
|
block->decodeBlock(&colors, decoder == Decoder_D3D9);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int yy = 0; yy < 4; yy++)
|
for (int yy = 0; yy < 4; yy++)
|
||||||
@ -1466,11 +1475,11 @@ void TexImage::quantize(int channel, int bits, bool exactEndPoints, bool dither)
|
|||||||
float scale, offset;
|
float scale, offset;
|
||||||
|
|
||||||
if (exactEndPoints) {
|
if (exactEndPoints) {
|
||||||
scale = (1 << bits) - 1;
|
scale = float((1 << bits) - 1);
|
||||||
offset = 0.0f;
|
offset = 0.0f;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
scale = (1 << bits);
|
scale = float(1 << bits);
|
||||||
offset = 0.5f;
|
offset = 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +380,8 @@ namespace nvtt
|
|||||||
/// DXT decoder.
|
/// DXT decoder.
|
||||||
enum Decoder
|
enum Decoder
|
||||||
{
|
{
|
||||||
Decoder_Reference,
|
Decoder_D3D10,
|
||||||
|
Decoder_D3D9,
|
||||||
Decoder_NV5x,
|
Decoder_NV5x,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ static const char * s_modeNames[] = {
|
|||||||
"BC3-Normal", // Mode_BC3_Normal,
|
"BC3-Normal", // Mode_BC3_Normal,
|
||||||
"BC5-Normal", // Mode_BC5_Normal,
|
"BC5-Normal", // Mode_BC5_Normal,
|
||||||
};
|
};
|
||||||
nvStaticCheck(ARRAY_SIZE(s_modeNames) == Mode_Count);
|
nvStaticCheck(NV_ARRAY_SIZE(s_modeNames) == Mode_Count);
|
||||||
|
|
||||||
struct Test {
|
struct Test {
|
||||||
const char * name;
|
const char * name;
|
||||||
@ -251,7 +251,6 @@ struct MyOutputHandler : public nvtt::OutputHandler
|
|||||||
{
|
{
|
||||||
nvtt::TexImage img;
|
nvtt::TexImage img;
|
||||||
img.setImage2D(format, decoder, m_width, m_height, m_data);
|
img.setImage2D(format, decoder, m_width, m_height, m_data);
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +279,7 @@ int main(int argc, char *argv[])
|
|||||||
bool fast = false;
|
bool fast = false;
|
||||||
bool nocuda = false;
|
bool nocuda = false;
|
||||||
bool showHelp = false;
|
bool showHelp = false;
|
||||||
nvtt::Decoder decoder = nvtt::Decoder_Reference;
|
nvtt::Decoder decoder = nvtt::Decoder_D3D10;
|
||||||
Path basePath = "";
|
Path basePath = "";
|
||||||
const char * outPath = "output";
|
const char * outPath = "output";
|
||||||
const char * regressPath = NULL;
|
const char * regressPath = NULL;
|
||||||
@ -378,7 +377,8 @@ int main(int argc, char *argv[])
|
|||||||
printf(" %i: \t%s.\n", i, s_imageTests[i].name);
|
printf(" %i: \t%s.\n", i, s_imageTests[i].name);
|
||||||
}
|
}
|
||||||
printf(" -dec x \tDecompressor.\n");
|
printf(" -dec x \tDecompressor.\n");
|
||||||
printf(" 0: \tReference.\n");
|
printf(" 0: \tReference (D3D10).\n");
|
||||||
|
printf(" 1: \tReference (D3D9).\n");
|
||||||
printf(" 1: \tNVIDIA.\n");
|
printf(" 1: \tNVIDIA.\n");
|
||||||
|
|
||||||
printf("Compression options:\n");
|
printf("Compression options:\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user