Add create minimal set option.

This commit is contained in:
castano
2008-01-26 05:32:23 +00:00
parent 0959798ff6
commit ad6597b75e
2 changed files with 63 additions and 60 deletions

View File

@ -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,26 +48,11 @@ 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 // loop over previous points for a match
for( int j = 0;; ++j ) for( int j = 0;; ++j )
{ {
@ -97,7 +81,8 @@ ColourSet::ColourSet( u8 const* rgba, int flags )
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 ) if( match )
{ {
// get the index of the match // get the index of the match
@ -112,7 +97,25 @@ ColourSet::ColourSet( u8 const* rgba, int flags )
break; 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

View File

@ -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; }