Add create minimal set option.
This commit is contained in:
parent
0959798ff6
commit
ad6597b75e
@ -28,12 +28,11 @@
|
|||||||
namespace squish {
|
namespace squish {
|
||||||
|
|
||||||
// @@ Add flags:
|
// @@ Add flags:
|
||||||
// - FindColorMatch
|
// - MatchTransparent
|
||||||
// - DXT1a
|
|
||||||
// - WeightColorByAlpha
|
// - WeightColorByAlpha
|
||||||
|
|
||||||
|
|
||||||
ColourSet::ColourSet( u8 const* rgba, int flags )
|
ColourSet::ColourSet( u8 const* rgba, int flags, bool createMinimalSet/*=false*/ )
|
||||||
: m_count( 0 ),
|
: m_count( 0 ),
|
||||||
m_transparent( false )
|
m_transparent( false )
|
||||||
{
|
{
|
||||||
@ -49,70 +48,74 @@ ColourSet::ColourSet( u8 const* rgba, int flags )
|
|||||||
{
|
{
|
||||||
m_remap[i] = -1;
|
m_remap[i] = -1;
|
||||||
m_transparent = true;
|
m_transparent = true;
|
||||||
// continue;
|
if (createMinimalSet) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
if (createMinimalSet)
|
||||||
// normalise coordinates to [0,1]
|
|
||||||
float x = ( float )rgba[4*i + 2] / 255.0f;
|
|
||||||
float y = ( float )rgba[4*i + 1] / 255.0f;
|
|
||||||
float z = ( float )rgba[4*i + 0] / 255.0f;
|
|
||||||
|
|
||||||
// ensure there is always non-zero weight even for zero alpha
|
|
||||||
float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;
|
|
||||||
|
|
||||||
// add the point
|
|
||||||
m_points[m_count] = Vec3( x, y, z );
|
|
||||||
m_weights[m_count] = ( weightByAlpha ? w : 1.0f );
|
|
||||||
m_remap[i] = m_count;
|
|
||||||
|
|
||||||
// advance
|
|
||||||
++m_count;
|
|
||||||
#else
|
|
||||||
// loop over previous points for a match
|
|
||||||
for( int j = 0;; ++j )
|
|
||||||
{
|
{
|
||||||
// allocate a new point
|
// loop over previous points for a match
|
||||||
if( j == i )
|
for( int j = 0;; ++j )
|
||||||
{
|
{
|
||||||
// normalise coordinates to [0,1]
|
// allocate a new point
|
||||||
float x = ( float )rgba[4*i + 2] / 255.0f;
|
if( j == i )
|
||||||
float y = ( float )rgba[4*i + 1] / 255.0f;
|
{
|
||||||
float z = ( float )rgba[4*i + 0] / 255.0f;
|
// normalise coordinates to [0,1]
|
||||||
|
float x = ( float )rgba[4*i + 2] / 255.0f;
|
||||||
// ensure there is always non-zero weight even for zero alpha
|
float y = ( float )rgba[4*i + 1] / 255.0f;
|
||||||
float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;
|
float z = ( float )rgba[4*i + 0] / 255.0f;
|
||||||
|
|
||||||
|
// ensure there is always non-zero weight even for zero alpha
|
||||||
|
float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;
|
||||||
|
|
||||||
// add the point
|
// add the point
|
||||||
m_points[m_count] = Vec3( x, y, z );
|
m_points[m_count] = Vec3( x, y, z );
|
||||||
m_weights[m_count] = ( weightByAlpha ? w : 1.0f );
|
m_weights[m_count] = ( weightByAlpha ? w : 1.0f );
|
||||||
m_remap[i] = m_count;
|
m_remap[i] = m_count;
|
||||||
|
|
||||||
// advance
|
// advance
|
||||||
++m_count;
|
++m_count;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for a match
|
// check for a match
|
||||||
bool match = ( rgba[4*i] == rgba[4*j] )
|
bool match = ( rgba[4*i] == rgba[4*j] )
|
||||||
&& ( rgba[4*i + 1] == rgba[4*j + 1] )
|
&& ( rgba[4*i + 1] == rgba[4*j + 1] )
|
||||||
&& ( rgba[4*i + 2] == rgba[4*j + 2] )
|
&& ( rgba[4*i + 2] == rgba[4*j + 2] )
|
||||||
&& ( rgba[4*j + 3] != 0 || !isDxt1 );
|
&& ( rgba[4*j + 3] != 0 || !isDxt1 ); // @@ I think this check is not necessary.
|
||||||
if( match )
|
|
||||||
{
|
|
||||||
// get the index of the match
|
|
||||||
int index = m_remap[j];
|
|
||||||
|
|
||||||
// ensure there is always non-zero weight even for zero alpha
|
|
||||||
float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;
|
|
||||||
|
|
||||||
// map to this point and increase the weight
|
if( match )
|
||||||
m_weights[index] += ( weightByAlpha ? w : 1.0f );
|
{
|
||||||
m_remap[i] = index;
|
// get the index of the match
|
||||||
break;
|
int index = m_remap[j];
|
||||||
|
|
||||||
|
// ensure there is always non-zero weight even for zero alpha
|
||||||
|
float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;
|
||||||
|
|
||||||
|
// map to this point and increase the weight
|
||||||
|
m_weights[index] += ( weightByAlpha ? w : 1.0f );
|
||||||
|
m_remap[i] = index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
else
|
||||||
|
{
|
||||||
|
// normalise coordinates to [0,1]
|
||||||
|
float x = ( float )rgba[4*i + 2] / 255.0f;
|
||||||
|
float y = ( float )rgba[4*i + 1] / 255.0f;
|
||||||
|
float z = ( float )rgba[4*i + 0] / 255.0f;
|
||||||
|
|
||||||
|
// ensure there is always non-zero weight even for zero alpha
|
||||||
|
float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;
|
||||||
|
|
||||||
|
// add the point
|
||||||
|
m_points[m_count] = Vec3( x, y, z );
|
||||||
|
m_weights[m_count] = ( weightByAlpha ? w : 1.0f );
|
||||||
|
m_remap[i] = m_count;
|
||||||
|
|
||||||
|
// advance
|
||||||
|
++m_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SQUISH_USE_SIMD
|
#if SQUISH_USE_SIMD
|
||||||
|
@ -37,7 +37,7 @@ namespace squish {
|
|||||||
class ColourSet
|
class ColourSet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ColourSet( u8 const* rgba, int flags );
|
ColourSet( u8 const* rgba, int flags, bool createMinimalSet = false );
|
||||||
|
|
||||||
int GetCount() const { return m_count; }
|
int GetCount() const { return m_count; }
|
||||||
Vec3 const* GetPoints() const { return m_points; }
|
Vec3 const* GetPoints() const { return m_points; }
|
||||||
|
Loading…
Reference in New Issue
Block a user