Commit 249836e5 by Rémi Verschelde

squish: Update to upstream 1.14

Sources are untouched, tarball from https://sourceforge.net/projects/libsquish
parent 8311a78d
...@@ -160,9 +160,8 @@ Files extracted from upstream source: ...@@ -160,9 +160,8 @@ Files extracted from upstream source:
## squish ## squish
- Upstream: https://code.google.com/archive/p/libsquish - Upstream: https://sourceforge.net/projects/libsquish
and patches from https://github.com/Cavewhere/squish - Version: 1.14
- Version: 1.11
- License: MIT - License: MIT
Files extracted from upstream source: Files extracted from upstream source:
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_ALPHA_H #ifndef SQUISH_ALPHA_H
#define SQUISH_ALPHA_H #define SQUISH_ALPHA_H
#include <squish.h> #include "squish.h"
namespace squish { namespace squish {
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Copyright (c) 2007 Ignacio Castano icastano@nvidia.com Copyright (c) 2007 Ignacio Castano icastano@nvidia.com
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_CLUSTERFIT_H #ifndef SQUISH_CLUSTERFIT_H
#define SQUISH_CLUSTERFIT_H #define SQUISH_CLUSTERFIT_H
#include <squish.h> #include "squish.h"
#include "maths.h" #include "maths.h"
#include "simd.h" #include "simd.h"
#include "colourfit.h" #include "colourfit.h"
...@@ -37,23 +37,23 @@ namespace squish { ...@@ -37,23 +37,23 @@ namespace squish {
class ClusterFit : public ColourFit class ClusterFit : public ColourFit
{ {
public: public:
ClusterFit( ColourSet const* colours, int flags ); ClusterFit( ColourSet const* colours, int flags, float* metric );
private: private:
bool ConstructOrdering( Vec3 const& axis, int iteration ); bool ConstructOrdering( Vec3 const& axis, int iteration );
virtual void Compress3( void* block ); virtual void Compress3( void* block );
virtual void Compress4( void* block ); virtual void Compress4( void* block );
enum { kMaxIterations = 8 }; enum { kMaxIterations = 8 };
int m_iterationCount; int m_iterationCount;
Vec3 m_principle; Vec3 m_principle;
u8 m_order[16*kMaxIterations]; u8 m_order[16*kMaxIterations];
Vec4 m_points_weights[16]; Vec4 m_points_weights[16];
Vec4 m_xsum_wsum; Vec4 m_xsum_wsum;
Vec4 m_metric; Vec4 m_metric;
Vec4 m_besterror; Vec4 m_besterror;
}; };
} // namespace squish } // namespace squish
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURBLOCK_H #ifndef SQUISH_COLOURBLOCK_H
#define SQUISH_COLOURBLOCK_H #define SQUISH_COLOURBLOCK_H
#include <squish.h> #include "squish.h"
#include "maths.h" #include "maths.h"
namespace squish { namespace squish {
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#include "colourfit.h" #include "colourfit.h"
#include "colourset.h" #include "colourset.h"
namespace squish { namespace squish {
ColourFit::ColourFit( ColourSet const* colours, int flags ) ColourFit::ColourFit( ColourSet const* colours, int flags )
: m_colours( colours ), : m_colours( colours ),
m_flags( flags ) m_flags( flags )
{
}
ColourFit::~ColourFit()
{ {
} }
void ColourFit::Compress( void* block ) void ColourFit::Compress( void* block )
{ {
bool isDxt1 = ( ( m_flags & kDxt1 ) != 0 ); bool isDxt1 = ( ( m_flags & kDxt1 ) != 0 );
if( isDxt1 ) if( isDxt1 )
{ {
Compress3( block ); Compress3( block );
if( !m_colours->IsTransparent() ) if( !m_colours->IsTransparent() )
Compress4( block ); Compress4( block );
} }
else else
Compress4( block ); Compress4( block );
} }
} // namespace squish } // namespace squish
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURFIT_H #ifndef SQUISH_COLOURFIT_H
#define SQUISH_COLOURFIT_H #define SQUISH_COLOURFIT_H
#include <squish.h> #include "squish.h"
#include "maths.h" #include "maths.h"
#include <climits>
namespace squish { namespace squish {
class ColourSet; class ColourSet;
...@@ -36,16 +38,17 @@ class ColourSet; ...@@ -36,16 +38,17 @@ class ColourSet;
class ColourFit class ColourFit
{ {
public: public:
ColourFit( ColourSet const* colours, int flags ); ColourFit( ColourSet const* colours, int flags );
virtual ~ColourFit();
void Compress( void* block ); void Compress( void* block );
protected: protected:
virtual void Compress3( void* block ) = 0; virtual void Compress3( void* block ) = 0;
virtual void Compress4( void* block ) = 0; virtual void Compress4( void* block ) = 0;
ColourSet const* m_colours; ColourSet const* m_colours;
int m_flags; int m_flags;
}; };
} // namespace squish } // namespace squish
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#include "colourset.h" #include "colourset.h"
namespace squish { namespace squish {
ColourSet::ColourSet( u8 const* rgba, int mask, int flags ) ColourSet::ColourSet( u8 const* rgba, int mask, int flags )
: m_count( 0 ), : m_count( 0 ),
m_transparent( false ) m_transparent( false )
{ {
// check the compression mode for dxt1 // check the compression mode for dxt1
bool isDxt1 = ( ( flags & kDxt1 ) != 0 ); bool isDxt1 = ( ( flags & kDxt1 ) != 0 );
bool weightByAlpha = ( ( flags & kWeightColourByAlpha ) != 0 ); bool weightByAlpha = ( ( flags & kWeightColourByAlpha ) != 0 );
// create the minimal set // create the minimal set
for( int i = 0; i < 16; ++i ) for( int i = 0; i < 16; ++i )
{ {
// check this pixel is enabled // check this pixel is enabled
int bit = 1 << i; int bit = 1 << i;
if( ( mask & bit ) == 0 ) if( ( mask & bit ) == 0 )
{ {
m_remap[i] = -1; m_remap[i] = -1;
continue; continue;
} }
// check for transparent pixels when using dxt1 // check for transparent pixels when using dxt1
if( isDxt1 && rgba[4*i + 3] < 128 ) if( isDxt1 && rgba[4*i + 3] < 128 )
{ {
m_remap[i] = -1; m_remap[i] = -1;
m_transparent = true; m_transparent = true;
continue; continue;
} }
// loop over previous points for a match // loop over previous points for a match
for( int j = 0;; ++j ) for( int j = 0;; ++j )
{ {
// allocate a new point // allocate a new point
if( j == i ) if( j == i )
{ {
// normalise coordinates to [0,1] // normalise coordinates to [0,1]
float x = ( float )rgba[4*i] / 255.0f; float x = ( float )rgba[4*i] / 255.0f;
float y = ( float )rgba[4*i + 1] / 255.0f; float y = ( float )rgba[4*i + 1] / 255.0f;
float z = ( float )rgba[4*i + 2] / 255.0f; float z = ( float )rgba[4*i + 2] / 255.0f;
// ensure there is always non-zero weight even for zero alpha // ensure there is always non-zero weight even for zero alpha
float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f; 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
int oldbit = 1 << j; int oldbit = 1 << j;
bool match = ( ( mask & oldbit ) != 0 ) bool match = ( ( mask & oldbit ) != 0 )
&& ( rgba[4*i] == rgba[4*j] ) && ( 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] >= 128 || !isDxt1 ); && ( rgba[4*j + 3] >= 128 || !isDxt1 );
if( match ) if( match )
{ {
// get the index of the match // get the index of the match
int index = m_remap[j]; int index = m_remap[j];
// ensure there is always non-zero weight even for zero alpha // ensure there is always non-zero weight even for zero alpha
float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f; float w = ( float )( rgba[4*i + 3] + 1 ) / 256.0f;
// map to this point and increase the weight // map to this point and increase the weight
m_weights[index] += ( weightByAlpha ? w : 1.0f ); m_weights[index] += ( weightByAlpha ? w : 1.0f );
m_remap[i] = index; m_remap[i] = index;
break; break;
} }
} }
} }
// square root the weights // square root the weights
for( int i = 0; i < m_count; ++i ) for( int i = 0; i < m_count; ++i )
m_weights[i] = std::sqrt( m_weights[i] ); m_weights[i] = std::sqrt( m_weights[i] );
} }
void ColourSet::RemapIndices( u8 const* source, u8* target ) const void ColourSet::RemapIndices( u8 const* source, u8* target ) const
{ {
for( int i = 0; i < 16; ++i ) for( int i = 0; i < 16; ++i )
{ {
int j = m_remap[i]; int j = m_remap[i];
if( j == -1 ) if( j == -1 )
target[i] = 3; target[i] = 3;
else else
target[i] = source[j]; target[i] = source[j];
} }
} }
} // namespace squish } // namespace squish
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURSET_H #ifndef SQUISH_COLOURSET_H
#define SQUISH_COLOURSET_H #define SQUISH_COLOURSET_H
#include <squish.h> #include "squish.h"
#include "maths.h" #include "maths.h"
namespace squish { namespace squish {
...@@ -36,21 +36,21 @@ namespace squish { ...@@ -36,21 +36,21 @@ namespace squish {
class ColourSet class ColourSet
{ {
public: public:
ColourSet( u8 const* rgba, int mask, int flags ); ColourSet( u8 const* rgba, int mask, int flags );
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; }
float const* GetWeights() const { return m_weights; } float const* GetWeights() const { return m_weights; }
bool IsTransparent() const { return m_transparent; } bool IsTransparent() const { return m_transparent; }
void RemapIndices( u8 const* source, u8* target ) const; void RemapIndices( u8 const* source, u8* target ) const;
private: private:
int m_count; int m_count;
Vec3 m_points[16]; Vec3 m_points[16];
float m_weights[16]; float m_weights[16];
int m_remap[16]; int m_remap[16];
bool m_transparent; bool m_transparent;
}; };
} // namespace sqish } // namespace sqish
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_CONFIG_H #ifndef SQUISH_CONFIG_H
#define SQUISH_CONFIG_H #define SQUISH_CONFIG_H
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#define SQUISH_USE_SSE 0 #define SQUISH_USE_SSE 0
#endif #endif
// Internally et SQUISH_USE_SIMD when either Altivec or SSE is available. // Internally set SQUISH_USE_SIMD when either Altivec or SSE is available.
#if SQUISH_USE_ALTIVEC && SQUISH_USE_SSE #if SQUISH_USE_ALTIVEC && SQUISH_USE_SSE
#error "Cannot enable both Altivec and SSE!" #error "Cannot enable both Altivec and SSE!"
#endif #endif
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_MATHS_H #ifndef SQUISH_MATHS_H
#define SQUISH_MATHS_H #define SQUISH_MATHS_H
...@@ -35,194 +35,194 @@ namespace squish { ...@@ -35,194 +35,194 @@ namespace squish {
class Vec3 class Vec3
{ {
public: public:
typedef Vec3 const& Arg; typedef Vec3 const& Arg;
Vec3() Vec3()
{ {
} }
explicit Vec3( float s ) explicit Vec3( float s )
{ {
m_x = s; m_x = s;
m_y = s; m_y = s;
m_z = s; m_z = s;
} }
Vec3( float x, float y, float z ) Vec3( float x, float y, float z )
{ {
m_x = x; m_x = x;
m_y = y; m_y = y;
m_z = z; m_z = z;
} }
float X() const { return m_x; } float X() const { return m_x; }
float Y() const { return m_y; } float Y() const { return m_y; }
float Z() const { return m_z; } float Z() const { return m_z; }
Vec3 operator-() const Vec3 operator-() const
{ {
return Vec3( -m_x, -m_y, -m_z ); return Vec3( -m_x, -m_y, -m_z );
} }
Vec3& operator+=( Arg v ) Vec3& operator+=( Arg v )
{ {
m_x += v.m_x; m_x += v.m_x;
m_y += v.m_y; m_y += v.m_y;
m_z += v.m_z; m_z += v.m_z;
return *this; return *this;
} }
Vec3& operator-=( Arg v ) Vec3& operator-=( Arg v )
{ {
m_x -= v.m_x; m_x -= v.m_x;
m_y -= v.m_y; m_y -= v.m_y;
m_z -= v.m_z; m_z -= v.m_z;
return *this; return *this;
} }
Vec3& operator*=( Arg v ) Vec3& operator*=( Arg v )
{ {
m_x *= v.m_x; m_x *= v.m_x;
m_y *= v.m_y; m_y *= v.m_y;
m_z *= v.m_z; m_z *= v.m_z;
return *this; return *this;
} }
Vec3& operator*=( float s ) Vec3& operator*=( float s )
{ {
m_x *= s; m_x *= s;
m_y *= s; m_y *= s;
m_z *= s; m_z *= s;
return *this; return *this;
} }
Vec3& operator/=( Arg v ) Vec3& operator/=( Arg v )
{ {
m_x /= v.m_x; m_x /= v.m_x;
m_y /= v.m_y; m_y /= v.m_y;
m_z /= v.m_z; m_z /= v.m_z;
return *this; return *this;
} }
Vec3& operator/=( float s ) Vec3& operator/=( float s )
{ {
float t = 1.0f/s; float t = 1.0f/s;
m_x *= t; m_x *= t;
m_y *= t; m_y *= t;
m_z *= t; m_z *= t;
return *this; return *this;
} }
friend Vec3 operator+( Arg left, Arg right ) friend Vec3 operator+( Arg left, Arg right )
{ {
Vec3 copy( left ); Vec3 copy( left );
return copy += right; return copy += right;
} }
friend Vec3 operator-( Arg left, Arg right ) friend Vec3 operator-( Arg left, Arg right )
{ {
Vec3 copy( left ); Vec3 copy( left );
return copy -= right; return copy -= right;
} }
friend Vec3 operator*( Arg left, Arg right ) friend Vec3 operator*( Arg left, Arg right )
{ {
Vec3 copy( left ); Vec3 copy( left );
return copy *= right; return copy *= right;
} }
friend Vec3 operator*( Arg left, float right ) friend Vec3 operator*( Arg left, float right )
{ {
Vec3 copy( left ); Vec3 copy( left );
return copy *= right; return copy *= right;
} }
friend Vec3 operator*( float left, Arg right ) friend Vec3 operator*( float left, Arg right )
{ {
Vec3 copy( right ); Vec3 copy( right );
return copy *= left; return copy *= left;
} }
friend Vec3 operator/( Arg left, Arg right ) friend Vec3 operator/( Arg left, Arg right )
{ {
Vec3 copy( left ); Vec3 copy( left );
return copy /= right; return copy /= right;
} }
friend Vec3 operator/( Arg left, float right ) friend Vec3 operator/( Arg left, float right )
{ {
Vec3 copy( left ); Vec3 copy( left );
return copy /= right; return copy /= right;
} }
friend float Dot( Arg left, Arg right ) friend float Dot( Arg left, Arg right )
{ {
return left.m_x*right.m_x + left.m_y*right.m_y + left.m_z*right.m_z; return left.m_x*right.m_x + left.m_y*right.m_y + left.m_z*right.m_z;
} }
friend Vec3 Min( Arg left, Arg right ) friend Vec3 Min( Arg left, Arg right )
{ {
return Vec3( return Vec3(
std::min( left.m_x, right.m_x ), std::min( left.m_x, right.m_x ),
std::min( left.m_y, right.m_y ), std::min( left.m_y, right.m_y ),
std::min( left.m_z, right.m_z ) std::min( left.m_z, right.m_z )
); );
} }
friend Vec3 Max( Arg left, Arg right ) friend Vec3 Max( Arg left, Arg right )
{ {
return Vec3( return Vec3(
std::max( left.m_x, right.m_x ), std::max( left.m_x, right.m_x ),
std::max( left.m_y, right.m_y ), std::max( left.m_y, right.m_y ),
std::max( left.m_z, right.m_z ) std::max( left.m_z, right.m_z )
); );
} }
friend Vec3 Truncate( Arg v ) friend Vec3 Truncate( Arg v )
{ {
return Vec3( return Vec3(
v.m_x > 0.0f ? std::floor( v.m_x ) : std::ceil( v.m_x ), v.m_x > 0.0f ? std::floor( v.m_x ) : std::ceil( v.m_x ),
v.m_y > 0.0f ? std::floor( v.m_y ) : std::ceil( v.m_y ), v.m_y > 0.0f ? std::floor( v.m_y ) : std::ceil( v.m_y ),
v.m_z > 0.0f ? std::floor( v.m_z ) : std::ceil( v.m_z ) v.m_z > 0.0f ? std::floor( v.m_z ) : std::ceil( v.m_z )
); );
} }
private: private:
float m_x; float m_x;
float m_y; float m_y;
float m_z; float m_z;
}; };
inline float LengthSquared( Vec3::Arg v ) inline float LengthSquared( Vec3::Arg v )
{ {
return Dot( v, v ); return Dot( v, v );
} }
class Sym3x3 class Sym3x3
{ {
public: public:
Sym3x3() Sym3x3()
{ {
} }
Sym3x3( float s ) Sym3x3( float s )
{ {
for( int i = 0; i < 6; ++i ) for( int i = 0; i < 6; ++i )
m_x[i] = s; m_x[i] = s;
} }
float operator[]( int index ) const float operator[]( int index ) const
{ {
return m_x[index]; return m_x[index];
} }
float& operator[]( int index ) float& operator[]( int index )
{ {
return m_x[index]; return m_x[index];
} }
private: private:
float m_x[6]; float m_x[6];
}; };
Sym3x3 ComputeWeightedCovariance( int n, Vec3 const* points, float const* weights ); Sym3x3 ComputeWeightedCovariance( int n, Vec3 const* points, float const* weights );
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_RANGEFIT_H #ifndef SQUISH_RANGEFIT_H
#define SQUISH_RANGEFIT_H #define SQUISH_RANGEFIT_H
#include <squish.h> #include "squish.h"
#include "colourfit.h" #include "colourfit.h"
#include "maths.h" #include "maths.h"
...@@ -37,16 +37,16 @@ class ColourSet; ...@@ -37,16 +37,16 @@ class ColourSet;
class RangeFit : public ColourFit class RangeFit : public ColourFit
{ {
public: public:
RangeFit( ColourSet const* colours, int flags ); RangeFit( ColourSet const* colours, int flags, float* metric );
private: private:
virtual void Compress3( void* block ); virtual void Compress3( void* block );
virtual void Compress4( void* block ); virtual void Compress4( void* block );
Vec3 m_metric; Vec3 m_metric;
Vec3 m_start; Vec3 m_start;
Vec3 m_end; Vec3 m_end;
float m_besterror; float m_besterror;
}; };
} // squish } // squish
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_SIMD_H #ifndef SQUISH_SIMD_H
#define SQUISH_SIMD_H #define SQUISH_SIMD_H
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_SIMD_FLOAT_H #ifndef SQUISH_SIMD_FLOAT_H
#define SQUISH_SIMD_FLOAT_H #define SQUISH_SIMD_FLOAT_H
...@@ -35,146 +35,146 @@ namespace squish { ...@@ -35,146 +35,146 @@ namespace squish {
class Vec4 class Vec4
{ {
public: public:
typedef Vec4 const& Arg; typedef Vec4 const& Arg;
Vec4() {} Vec4() {}
explicit Vec4( float s ) explicit Vec4( float s )
: m_x( s ), : m_x( s ),
m_y( s ), m_y( s ),
m_z( s ), m_z( s ),
m_w( s ) m_w( s )
{ {
} }
Vec4( float x, float y, float z, float w ) Vec4( float x, float y, float z, float w )
: m_x( x ), : m_x( x ),
m_y( y ), m_y( y ),
m_z( z ), m_z( z ),
m_w( w ) m_w( w )
{ {
} }
Vec3 GetVec3() const Vec3 GetVec3() const
{ {
return Vec3( m_x, m_y, m_z ); return Vec3( m_x, m_y, m_z );
} }
Vec4 SplatX() const { return Vec4( m_x ); } Vec4 SplatX() const { return Vec4( m_x ); }
Vec4 SplatY() const { return Vec4( m_y ); } Vec4 SplatY() const { return Vec4( m_y ); }
Vec4 SplatZ() const { return Vec4( m_z ); } Vec4 SplatZ() const { return Vec4( m_z ); }
Vec4 SplatW() const { return Vec4( m_w ); } Vec4 SplatW() const { return Vec4( m_w ); }
Vec4& operator+=( Arg v ) Vec4& operator+=( Arg v )
{ {
m_x += v.m_x; m_x += v.m_x;
m_y += v.m_y; m_y += v.m_y;
m_z += v.m_z; m_z += v.m_z;
m_w += v.m_w; m_w += v.m_w;
return *this; return *this;
} }
Vec4& operator-=( Arg v ) Vec4& operator-=( Arg v )
{ {
m_x -= v.m_x; m_x -= v.m_x;
m_y -= v.m_y; m_y -= v.m_y;
m_z -= v.m_z; m_z -= v.m_z;
m_w -= v.m_w; m_w -= v.m_w;
return *this; return *this;
} }
Vec4& operator*=( Arg v ) Vec4& operator*=( Arg v )
{ {
m_x *= v.m_x; m_x *= v.m_x;
m_y *= v.m_y; m_y *= v.m_y;
m_z *= v.m_z; m_z *= v.m_z;
m_w *= v.m_w; m_w *= v.m_w;
return *this; return *this;
} }
friend Vec4 operator+( Vec4::Arg left, Vec4::Arg right ) friend Vec4 operator+( Vec4::Arg left, Vec4::Arg right )
{ {
Vec4 copy( left ); Vec4 copy( left );
return copy += right; return copy += right;
} }
friend Vec4 operator-( Vec4::Arg left, Vec4::Arg right ) friend Vec4 operator-( Vec4::Arg left, Vec4::Arg right )
{ {
Vec4 copy( left ); Vec4 copy( left );
return copy -= right; return copy -= right;
} }
friend Vec4 operator*( Vec4::Arg left, Vec4::Arg right ) friend Vec4 operator*( Vec4::Arg left, Vec4::Arg right )
{ {
Vec4 copy( left ); Vec4 copy( left );
return copy *= right; return copy *= right;
} }
//! Returns a*b + c //! Returns a*b + c
friend Vec4 MultiplyAdd( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c ) friend Vec4 MultiplyAdd( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c )
{ {
return a*b + c; return a*b + c;
} }
//! Returns -( a*b - c ) //! Returns -( a*b - c )
friend Vec4 NegativeMultiplySubtract( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c ) friend Vec4 NegativeMultiplySubtract( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c )
{ {
return c - a*b; return c - a*b;
} }
friend Vec4 Reciprocal( Vec4::Arg v ) friend Vec4 Reciprocal( Vec4::Arg v )
{ {
return Vec4( return Vec4(
1.0f/v.m_x, 1.0f/v.m_x,
1.0f/v.m_y, 1.0f/v.m_y,
1.0f/v.m_z, 1.0f/v.m_z,
1.0f/v.m_w 1.0f/v.m_w
); );
} }
friend Vec4 Min( Vec4::Arg left, Vec4::Arg right ) friend Vec4 Min( Vec4::Arg left, Vec4::Arg right )
{ {
return Vec4( return Vec4(
std::min( left.m_x, right.m_x ), std::min( left.m_x, right.m_x ),
std::min( left.m_y, right.m_y ), std::min( left.m_y, right.m_y ),
std::min( left.m_z, right.m_z ), std::min( left.m_z, right.m_z ),
std::min( left.m_w, right.m_w ) std::min( left.m_w, right.m_w )
); );
} }
friend Vec4 Max( Vec4::Arg left, Vec4::Arg right ) friend Vec4 Max( Vec4::Arg left, Vec4::Arg right )
{ {
return Vec4( return Vec4(
std::max( left.m_x, right.m_x ), std::max( left.m_x, right.m_x ),
std::max( left.m_y, right.m_y ), std::max( left.m_y, right.m_y ),
std::max( left.m_z, right.m_z ), std::max( left.m_z, right.m_z ),
std::max( left.m_w, right.m_w ) std::max( left.m_w, right.m_w )
); );
} }
friend Vec4 Truncate( Vec4::Arg v ) friend Vec4 Truncate( Vec4::Arg v )
{ {
return Vec4( return Vec4(
v.m_x > 0.0f ? std::floor( v.m_x ) : std::ceil( v.m_x ), v.m_x > 0.0f ? std::floor( v.m_x ) : std::ceil( v.m_x ),
v.m_y > 0.0f ? std::floor( v.m_y ) : std::ceil( v.m_y ), v.m_y > 0.0f ? std::floor( v.m_y ) : std::ceil( v.m_y ),
v.m_z > 0.0f ? std::floor( v.m_z ) : std::ceil( v.m_z ), v.m_z > 0.0f ? std::floor( v.m_z ) : std::ceil( v.m_z ),
v.m_w > 0.0f ? std::floor( v.m_w ) : std::ceil( v.m_w ) v.m_w > 0.0f ? std::floor( v.m_w ) : std::ceil( v.m_w )
); );
} }
friend bool CompareAnyLessThan( Vec4::Arg left, Vec4::Arg right ) friend bool CompareAnyLessThan( Vec4::Arg left, Vec4::Arg right )
{ {
return left.m_x < right.m_x return left.m_x < right.m_x
|| left.m_y < right.m_y || left.m_y < right.m_y
|| left.m_z < right.m_z || left.m_z < right.m_z
|| left.m_w < right.m_w; || left.m_w < right.m_w;
} }
private: private:
float m_x; float m_x;
float m_y; float m_y;
float m_z; float m_z;
float m_w; float m_w;
}; };
} // namespace squish } // namespace squish
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_SIMD_VE_H #ifndef SQUISH_SIMD_VE_H
#define SQUISH_SIMD_VE_H #define SQUISH_SIMD_VE_H
...@@ -31,134 +31,134 @@ ...@@ -31,134 +31,134 @@
namespace squish { namespace squish {
#define VEC4_CONST( X ) Vec4( ( vector float )( X ) ) #define VEC4_CONST( X ) Vec4( ( vector float ){ X } )
class Vec4 class Vec4
{ {
public: public:
typedef Vec4 Arg; typedef Vec4 Arg;
Vec4() {} Vec4() {}
explicit Vec4( vector float v ) : m_v( v ) {} explicit Vec4( vector float v ) : m_v( v ) {}
Vec4( Vec4 const& arg ) : m_v( arg.m_v ) {} Vec4( Vec4 const& arg ) : m_v( arg.m_v ) {}
Vec4& operator=( Vec4 const& arg ) Vec4& operator=( Vec4 const& arg )
{ {
m_v = arg.m_v; m_v = arg.m_v;
return *this; return *this;
} }
explicit Vec4( float s ) explicit Vec4( float s )
{ {
union { vector float v; float c[4]; } u; union { vector float v; float c[4]; } u;
u.c[0] = s; u.c[0] = s;
u.c[1] = s; u.c[1] = s;
u.c[2] = s; u.c[2] = s;
u.c[3] = s; u.c[3] = s;
m_v = u.v; m_v = u.v;
} }
Vec4( float x, float y, float z, float w ) Vec4( float x, float y, float z, float w )
{ {
union { vector float v; float c[4]; } u; union { vector float v; float c[4]; } u;
u.c[0] = x; u.c[0] = x;
u.c[1] = y; u.c[1] = y;
u.c[2] = z; u.c[2] = z;
u.c[3] = w; u.c[3] = w;
m_v = u.v; m_v = u.v;
} }
Vec3 GetVec3() const Vec3 GetVec3() const
{ {
union { vector float v; float c[4]; } u; union { vector float v; float c[4]; } u;
u.v = m_v; u.v = m_v;
return Vec3( u.c[0], u.c[1], u.c[2] ); return Vec3( u.c[0], u.c[1], u.c[2] );
} }
Vec4 SplatX() const { return Vec4( vec_splat( m_v, 0 ) ); } Vec4 SplatX() const { return Vec4( vec_splat( m_v, 0 ) ); }
Vec4 SplatY() const { return Vec4( vec_splat( m_v, 1 ) ); } Vec4 SplatY() const { return Vec4( vec_splat( m_v, 1 ) ); }
Vec4 SplatZ() const { return Vec4( vec_splat( m_v, 2 ) ); } Vec4 SplatZ() const { return Vec4( vec_splat( m_v, 2 ) ); }
Vec4 SplatW() const { return Vec4( vec_splat( m_v, 3 ) ); } Vec4 SplatW() const { return Vec4( vec_splat( m_v, 3 ) ); }
Vec4& operator+=( Arg v ) Vec4& operator+=( Arg v )
{ {
m_v = vec_add( m_v, v.m_v ); m_v = vec_add( m_v, v.m_v );
return *this; return *this;
} }
Vec4& operator-=( Arg v ) Vec4& operator-=( Arg v )
{ {
m_v = vec_sub( m_v, v.m_v ); m_v = vec_sub( m_v, v.m_v );
return *this; return *this;
} }
Vec4& operator*=( Arg v ) Vec4& operator*=( Arg v )
{ {
m_v = vec_madd( m_v, v.m_v, ( vector float )( -0.0f ) ); m_v = vec_madd( m_v, v.m_v, ( vector float ){ -0.0f } );
return *this; return *this;
} }
friend Vec4 operator+( Vec4::Arg left, Vec4::Arg right ) friend Vec4 operator+( Vec4::Arg left, Vec4::Arg right )
{ {
return Vec4( vec_add( left.m_v, right.m_v ) ); return Vec4( vec_add( left.m_v, right.m_v ) );
} }
friend Vec4 operator-( Vec4::Arg left, Vec4::Arg right ) friend Vec4 operator-( Vec4::Arg left, Vec4::Arg right )
{ {
return Vec4( vec_sub( left.m_v, right.m_v ) ); return Vec4( vec_sub( left.m_v, right.m_v ) );
} }
friend Vec4 operator*( Vec4::Arg left, Vec4::Arg right ) friend Vec4 operator*( Vec4::Arg left, Vec4::Arg right )
{ {
return Vec4( vec_madd( left.m_v, right.m_v, ( vector float )( -0.0f ) ) ); return Vec4( vec_madd( left.m_v, right.m_v, ( vector float ){ -0.0f } ) );
} }
//! Returns a*b + c //! Returns a*b + c
friend Vec4 MultiplyAdd( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c ) friend Vec4 MultiplyAdd( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c )
{ {
return Vec4( vec_madd( a.m_v, b.m_v, c.m_v ) ); return Vec4( vec_madd( a.m_v, b.m_v, c.m_v ) );
} }
//! Returns -( a*b - c ) //! Returns -( a*b - c )
friend Vec4 NegativeMultiplySubtract( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c ) friend Vec4 NegativeMultiplySubtract( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c )
{ {
return Vec4( vec_nmsub( a.m_v, b.m_v, c.m_v ) ); return Vec4( vec_nmsub( a.m_v, b.m_v, c.m_v ) );
} }
friend Vec4 Reciprocal( Vec4::Arg v ) friend Vec4 Reciprocal( Vec4::Arg v )
{ {
// get the reciprocal estimate // get the reciprocal estimate
vector float estimate = vec_re( v.m_v ); vector float estimate = vec_re( v.m_v );
// one round of Newton-Rhaphson refinement // one round of Newton-Rhaphson refinement
vector float diff = vec_nmsub( estimate, v.m_v, ( vector float )( 1.0f ) ); vector float diff = vec_nmsub( estimate, v.m_v, ( vector float ){ 1.0f } );
return Vec4( vec_madd( diff, estimate, estimate ) ); return Vec4( vec_madd( diff, estimate, estimate ) );
} }
friend Vec4 Min( Vec4::Arg left, Vec4::Arg right ) friend Vec4 Min( Vec4::Arg left, Vec4::Arg right )
{ {
return Vec4( vec_min( left.m_v, right.m_v ) ); return Vec4( vec_min( left.m_v, right.m_v ) );
} }
friend Vec4 Max( Vec4::Arg left, Vec4::Arg right ) friend Vec4 Max( Vec4::Arg left, Vec4::Arg right )
{ {
return Vec4( vec_max( left.m_v, right.m_v ) ); return Vec4( vec_max( left.m_v, right.m_v ) );
} }
friend Vec4 Truncate( Vec4::Arg v ) friend Vec4 Truncate( Vec4::Arg v )
{ {
return Vec4( vec_trunc( v.m_v ) ); return Vec4( vec_trunc( v.m_v ) );
} }
friend bool CompareAnyLessThan( Vec4::Arg left, Vec4::Arg right ) friend bool CompareAnyLessThan( Vec4::Arg left, Vec4::Arg right )
{ {
return vec_any_lt( left.m_v, right.m_v ) != 0; return vec_any_lt( left.m_v, right.m_v ) != 0;
} }
private: private:
vector float m_v; vector float m_v;
}; };
} // namespace squish } // namespace squish
......
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#include "singlecolourfit.h" #include "singlecolourfit.h"
#include "colourset.h" #include "colourset.h"
#include "colourblock.h" #include "colourblock.h"
#include <climits>
namespace squish { namespace squish {
struct SourceBlock struct SourceBlock
{ {
u8 start; u8 start;
u8 end; u8 end;
u8 error; u8 error;
}; };
struct SingleColourLookup struct SingleColourLookup
{ {
SourceBlock sources[2]; SourceBlock sources[2];
}; };
#include "singlecolourlookup.inl" #include "singlecolourlookup.inl"
static int FloatToInt( float a, int limit ) static int FloatToInt( float a, int limit )
{ {
// use ANSI round-to-zero behaviour to get round-to-nearest // use ANSI round-to-zero behaviour to get round-to-nearest
int i = ( int )( a + 0.5f ); int i = ( int )( a + 0.5f );
// clamp to the limit // clamp to the limit
if( i < 0 ) if( i < 0 )
i = 0; i = 0;
else if( i > limit ) else if( i > limit )
i = limit; i = limit;
// done // done
return i; return i;
} }
SingleColourFit::SingleColourFit( ColourSet const* colours, int flags ) SingleColourFit::SingleColourFit( ColourSet const* colours, int flags )
: ColourFit( colours, flags ) : ColourFit( colours, flags )
{ {
// grab the single colour // grab the single colour
Vec3 const* values = m_colours->GetPoints(); Vec3 const* values = m_colours->GetPoints();
m_colour[0] = ( u8 )FloatToInt( 255.0f*values->X(), 255 ); m_colour[0] = ( u8 )FloatToInt( 255.0f*values->X(), 255 );
m_colour[1] = ( u8 )FloatToInt( 255.0f*values->Y(), 255 ); m_colour[1] = ( u8 )FloatToInt( 255.0f*values->Y(), 255 );
m_colour[2] = ( u8 )FloatToInt( 255.0f*values->Z(), 255 ); m_colour[2] = ( u8 )FloatToInt( 255.0f*values->Z(), 255 );
// initialise the best error // initialise the best error
m_besterror = INT_MAX; m_besterror = INT_MAX;
} }
void SingleColourFit::Compress3( void* block ) void SingleColourFit::Compress3( void* block )
{ {
// build the table of lookups // build the table of lookups
SingleColourLookup const* const lookups[] = SingleColourLookup const* const lookups[] =
{ {
lookup_5_3, lookup_5_3,
lookup_6_3, lookup_6_3,
lookup_5_3 lookup_5_3
}; };
// find the best end-points and index // find the best end-points and index
ComputeEndPoints( lookups ); ComputeEndPoints( lookups );
// build the block if we win // build the block if we win
if( m_error < m_besterror ) if( m_error < m_besterror )
{ {
// remap the indices // remap the indices
u8 indices[16]; u8 indices[16];
m_colours->RemapIndices( &m_index, indices ); m_colours->RemapIndices( &m_index, indices );
// save the block // save the block
WriteColourBlock3( m_start, m_end, indices, block ); WriteColourBlock3( m_start, m_end, indices, block );
// save the error // save the error
m_besterror = m_error; m_besterror = m_error;
} }
} }
void SingleColourFit::Compress4( void* block ) void SingleColourFit::Compress4( void* block )
{ {
// build the table of lookups // build the table of lookups
SingleColourLookup const* const lookups[] = SingleColourLookup const* const lookups[] =
{ {
lookup_5_4, lookup_5_4,
lookup_6_4, lookup_6_4,
lookup_5_4 lookup_5_4
}; };
// find the best end-points and index // find the best end-points and index
ComputeEndPoints( lookups ); ComputeEndPoints( lookups );
// build the block if we win // build the block if we win
if( m_error < m_besterror ) if( m_error < m_besterror )
{ {
// remap the indices // remap the indices
u8 indices[16]; u8 indices[16];
m_colours->RemapIndices( &m_index, indices ); m_colours->RemapIndices( &m_index, indices );
// save the block // save the block
WriteColourBlock4( m_start, m_end, indices, block ); WriteColourBlock4( m_start, m_end, indices, block );
// save the error // save the error
m_besterror = m_error; m_besterror = m_error;
} }
} }
void SingleColourFit::ComputeEndPoints( SingleColourLookup const* const* lookups ) void SingleColourFit::ComputeEndPoints( SingleColourLookup const* const* lookups )
{ {
// check each index combination (endpoint or intermediate) // check each index combination (endpoint or intermediate)
m_error = INT_MAX; m_error = INT_MAX;
for( int index = 0; index < 2; ++index ) for( int index = 0; index < 2; ++index )
{ {
// check the error for this codebook index // check the error for this codebook index
SourceBlock const* sources[3]; SourceBlock const* sources[3];
int error = 0; int error = 0;
for( int channel = 0; channel < 3; ++channel ) for( int channel = 0; channel < 3; ++channel )
{ {
// grab the lookup table and index for this channel // grab the lookup table and index for this channel
SingleColourLookup const* lookup = lookups[channel]; SingleColourLookup const* lookup = lookups[channel];
int target = m_colour[channel]; int target = m_colour[channel];
// store a pointer to the source for this channel // store a pointer to the source for this channel
sources[channel] = lookup[target].sources + index; sources[channel] = lookup[target].sources + index;
// accumulate the error // accumulate the error
int diff = sources[channel]->error; int diff = sources[channel]->error;
error += diff*diff; error += diff*diff;
} }
// keep it if the error is lower // keep it if the error is lower
if( error < m_error ) if( error < m_error )
{ {
m_start = Vec3( m_start = Vec3(
( float )sources[0]->start/31.0f, ( float )sources[0]->start/31.0f,
( float )sources[1]->start/63.0f, ( float )sources[1]->start/63.0f,
( float )sources[2]->start/31.0f ( float )sources[2]->start/31.0f
); );
m_end = Vec3( m_end = Vec3(
( float )sources[0]->end/31.0f, ( float )sources[0]->end/31.0f,
( float )sources[1]->end/63.0f, ( float )sources[1]->end/63.0f,
( float )sources[2]->end/31.0f ( float )sources[2]->end/31.0f
); );
m_index = ( u8 )( 2*index ); m_index = ( u8 )( 2*index );
m_error = error; m_error = error;
} }
} }
} }
} // namespace squish } // namespace squish
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
Copyright (c) 2006 Simon Brown si@sjbrown.co.uk Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to permit persons to whom the Software is furnished to do so, subject to
the following conditions: the following conditions:
The above copyright notice and this permission notice shall be included The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software. in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
#ifndef SQUISH_SINGLECOLOURFIT_H #ifndef SQUISH_SINGLECOLOURFIT_H
#define SQUISH_SINGLECOLOURFIT_H #define SQUISH_SINGLECOLOURFIT_H
#include <squish.h> #include "squish.h"
#include "colourfit.h" #include "colourfit.h"
namespace squish { namespace squish {
...@@ -37,20 +37,20 @@ struct SingleColourLookup; ...@@ -37,20 +37,20 @@ struct SingleColourLookup;
class SingleColourFit : public ColourFit class SingleColourFit : public ColourFit
{ {
public: public:
SingleColourFit( ColourSet const* colours, int flags ); SingleColourFit( ColourSet const* colours, int flags );
private: private:
virtual void Compress3( void* block ); virtual void Compress3( void* block );
virtual void Compress4( void* block ); virtual void Compress4( void* block );
void ComputeEndPoints( SingleColourLookup const* const* lookups ); void ComputeEndPoints( SingleColourLookup const* const* lookups );
u8 m_colour[3]; u8 m_colour[3];
Vec3 m_start; Vec3 m_start;
Vec3 m_end; Vec3 m_end;
u8 m_index; u8 m_index;
int m_error; int m_error;
int m_besterror; int m_besterror;
}; };
} // namespace squish } // namespace squish
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment