Add squish external compressor.

Rename our squish version to nvsquish.
pull/216/head
castano 16 years ago
parent 4a85f8e48d
commit 4bbf5e96f4

@ -36,22 +36,25 @@
// squish
#include "squish/colourset.h"
//#include "squish/clusterfit.h"
#include "squish/fastclusterfit.h"
#include "squish/weightedclusterfit.h"
// s3_quant
#if defined(HAVE_S3QUANT)
#include "s3tc/s3_quant.h"
#include "extern/s3tc/s3_quant.h"
#endif
// ati tc
#if defined(HAVE_ATITC)
#include "atitc/ATI_Compress.h"
#include "extern/atitc/ATI_Compress.h"
#endif
// squish
#if defined(HAVE_SQUISH)
#include "extern/squish/squish.h"
#endif
//#include <time.h>
using namespace nv;
using namespace nvtt;
@ -205,9 +208,9 @@ void nv::SlowCompressor::compressDXT1(const CompressionOptions::Private & compre
ColorBlock rgba;
BlockDXT1 block;
//squish::WeightedClusterFit fit;
//squish::ClusterFit fit;
squish::FastClusterFit fit;
nvsquish::WeightedClusterFit fit;
//nvsquish::ClusterFit fit;
//nvsquish::FastClusterFit fit;
fit.SetMetric(compressionOptions.colorWeight.x(), compressionOptions.colorWeight.y(), compressionOptions.colorWeight.z());
for (uint y = 0; y < h; y += 4) {
@ -221,8 +224,8 @@ void nv::SlowCompressor::compressDXT1(const CompressionOptions::Private & compre
}
else
{
squish::ColourSet colours((uint8 *)rgba.colors(), 0);
fit.SetColourSet(&colours, squish::kDxt1);
nvsquish::ColourSet colours((uint8 *)rgba.colors(), 0, true);
fit.SetColourSet(&colours, nvsquish::kDxt1);
fit.Compress(&block);
}
@ -242,7 +245,7 @@ void nv::SlowCompressor::compressDXT1a(const CompressionOptions::Private & compr
ColorBlock rgba;
BlockDXT1 block;
squish::WeightedClusterFit fit;
nvsquish::WeightedClusterFit fit;
fit.SetMetric(compressionOptions.colorWeight.x(), compressionOptions.colorWeight.y(), compressionOptions.colorWeight.z());
for (uint y = 0; y < h; y += 4) {
@ -265,8 +268,8 @@ void nv::SlowCompressor::compressDXT1a(const CompressionOptions::Private & compr
}
else
{
squish::ColourSet colours((uint8 *)rgba.colors(), squish::kDxt1|squish::kWeightColourByAlpha);
fit.SetColourSet(&colours, squish::kDxt1);
nvsquish::ColourSet colours((uint8 *)rgba.colors(), nvsquish::kDxt1|nvsquish::kWeightColourByAlpha);
fit.SetColourSet(&colours, nvsquish::kDxt1);
fit.Compress(&block);
}
@ -286,8 +289,7 @@ void nv::SlowCompressor::compressDXT3(const CompressionOptions::Private & compre
ColorBlock rgba;
BlockDXT3 block;
squish::WeightedClusterFit fit;
//squish::FastClusterFit fit;
nvsquish::WeightedClusterFit fit;
fit.SetMetric(compressionOptions.colorWeight.x(), compressionOptions.colorWeight.y(), compressionOptions.colorWeight.z());
for (uint y = 0; y < h; y += 4) {
@ -305,7 +307,7 @@ void nv::SlowCompressor::compressDXT3(const CompressionOptions::Private & compre
}
else
{
squish::ColourSet colours((uint8 *)rgba.colors(), squish::kWeightColourByAlpha);
nvsquish::ColourSet colours((uint8 *)rgba.colors(), nvsquish::kWeightColourByAlpha);
fit.SetColourSet(&colours, 0);
fit.Compress(&block.color);
}
@ -325,7 +327,7 @@ void nv::SlowCompressor::compressDXT5(const CompressionOptions::Private & compre
ColorBlock rgba;
BlockDXT5 block;
squish::WeightedClusterFit fit;
nvsquish::WeightedClusterFit fit;
fit.SetMetric(compressionOptions.colorWeight.x(), compressionOptions.colorWeight.y(), compressionOptions.colorWeight.z());
for (uint y = 0; y < h; y += 4) {
@ -350,7 +352,7 @@ void nv::SlowCompressor::compressDXT5(const CompressionOptions::Private & compre
}
else
{
squish::ColourSet colours((uint8 *)rgba.colors(), squish::kWeightColourByAlpha);
nvsquish::ColourSet colours((uint8 *)rgba.colors(), nvsquish::kWeightColourByAlpha);
fit.SetColourSet(&colours, 0);
fit.Compress(&block.color);
}
@ -371,7 +373,7 @@ void nv::SlowCompressor::compressDXT5n(const CompressionOptions::Private & compr
ColorBlock rgba;
BlockDXT5 block;
squish::WeightedClusterFit fit;
nvsquish::WeightedClusterFit fit;
fit.SetMetric(0, 1, 0);
for (uint y = 0; y < h; y += 4) {
@ -400,7 +402,7 @@ void nv::SlowCompressor::compressDXT5n(const CompressionOptions::Private & compr
}
else*/
{
squish::ColourSet colours((uint8 *)rgba.colors(), squish::kWeightColourByAlpha);
nvsquish::ColourSet colours((uint8 *)rgba.colors(), nvsquish::kWeightColourByAlpha);
fit.SetColourSet(&colours, 0);
fit.Compress(&block.color);
}
@ -609,3 +611,27 @@ void nv::atiCompressDXT1(const Image * image, const OutputOptions::Private & out
}
#endif // defined(HAVE_ATITC)
#if defined(HAVE_SQUISH)
void nv::squishCompressDXT1(const Image * image, const OutputOptions::Private & outputOptions)
{
Image img(*image);
int count = img.width() * img.height();
for (int i = 0; i < count; i++)
{
Color32 c = img.pixel(i);
img.pixel(i) = Color32(c.b, c.g, c.r, c.a);
}
int size = squish::GetStorageRequirements(img.width(), img.height(), squish::kDxt1);
void * blocks = malloc(size);
squish::CompressImage((const squish::u8 *)img.pixels(), img.width(), img.height(), blocks, squish::kDxt1 | squish::kColourClusterFit);
if (outputOptions.outputHandler != NULL) {
outputOptions.outputHandler->writeData(blocks, size);
}
}
#endif // defined(HAVE_SQUISH)

@ -81,6 +81,10 @@ namespace nv
void atiCompressDXT1(const Image * image, const nvtt::OutputOptions::Private & outputOptions);
#endif
#if defined(HAVE_SQUISH)
void squishCompressDXT1(const Image * image, const nvtt::OutputOptions::Private & outputOptions);
#endif
} // nv namespace

@ -935,6 +935,15 @@ bool Compressor::Private::compressMipmap(const Mipmap & mipmap, const InputOptio
}
else
#endif
#if defined(HAVE_SQUISH)
if (compressionOptions.externalCompressor == "squish")
{
squishCompressDXT1(image, outputOptions);
}
else
#endif
if (compressionOptions.quality == Quality_Fastest)
{
fast.compressDXT1(outputOptions);

@ -28,7 +28,7 @@
#include "colourblock.h"
#include <cfloat>
namespace squish {
namespace nvsquish {
ClusterFit::ClusterFit()
{

@ -23,15 +23,15 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_CLUSTERFIT_H
#define SQUISH_CLUSTERFIT_H
#ifndef NV_SQUISH_CLUSTERFIT_H
#define NV_SQUISH_CLUSTERFIT_H
#include "squish.h"
#include "maths.h"
#include "simd.h"
#include "colourfit.h"
namespace squish {
namespace nvsquish {
class ClusterFit : public ColourFit
{

@ -25,7 +25,7 @@
#include "colourblock.h"
namespace squish {
namespace nvsquish {
static int FloatToInt( float a, int limit )
{

@ -23,13 +23,13 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURBLOCK_H
#define SQUISH_COLOURBLOCK_H
#ifndef NV_SQUISH_COLOURBLOCK_H
#define NV_SQUISH_COLOURBLOCK_H
#include "squish.h"
#include "maths.h"
namespace squish {
namespace nvsquish {
void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block );
void WriteColourBlock4( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block );

@ -26,7 +26,7 @@
#include "colourfit.h"
#include "colourset.h"
namespace squish {
namespace nvsquish {
ColourFit::ColourFit()
{

@ -23,13 +23,13 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURFIT_H
#define SQUISH_COLOURFIT_H
#ifndef NV_SQUISH_COLOURFIT_H
#define NV_SQUISH_COLOURFIT_H
#include "squish.h"
#include "maths.h"
namespace squish {
namespace nvsquish {
class ColourSet;

@ -25,7 +25,7 @@
#include "colourset.h"
namespace squish {
namespace nvsquish {
// @@ Add flags:
// - MatchTransparent

@ -23,14 +23,14 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_COLOURSET_H
#define SQUISH_COLOURSET_H
#ifndef NV_SQUISH_COLOURSET_H
#define NV_SQUISH_COLOURSET_H
#include "squish.h"
#include "maths.h"
#include "simd.h"
namespace squish {
namespace nvsquish {
/*! @brief Represents a set of block colours
*/

@ -31,7 +31,7 @@
#include "fastclusterlookup.inl"
namespace squish {
namespace nvsquish {
FastClusterFit::FastClusterFit()
{

@ -24,15 +24,15 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_FASTCLUSTERFIT_H
#define SQUISH_FASTCLUSTERFIT_H
#ifndef NV_SQUISH_FASTCLUSTERFIT_H
#define NV_SQUISH_FASTCLUSTERFIT_H
#include "squish.h"
#include "maths.h"
#include "simd.h"
#include "colourfit.h"
namespace squish {
namespace nvsquish {
class FastClusterFit : public ColourFit
{

@ -26,7 +26,7 @@
#include "maths.h"
#include <cfloat>
namespace squish {
namespace nvsquish {
Sym3x3 ComputeWeightedCovariance( int n, Vec3 const* points, float const* weights, Vec3::Arg metric )
{

@ -23,14 +23,14 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_MATHS_H
#define SQUISH_MATHS_H
#ifndef NV_SQUISH_MATHS_H
#define NV_SQUISH_MATHS_H
#include <cmath>
#include <algorithm>
#include "config.h"
namespace squish {
namespace nvsquish {
class Vec3
{

@ -23,8 +23,8 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_SIMD_H
#define SQUISH_SIMD_H
#ifndef NV_SQUISH_SIMD_H
#define NV_SQUISH_SIMD_H
#include "maths.h"

@ -23,8 +23,8 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_SIMD_SSE_H
#define SQUISH_SIMD_SSE_H
#ifndef NV_SQUISH_SIMD_SSE_H
#define NV_SQUISH_SIMD_SSE_H
#include <xmmintrin.h>
#if ( SQUISH_USE_SSE > 1 )
@ -35,7 +35,7 @@
#define SQUISH_SSE_SPLAT( a ) \
( ( a ) | ( ( a ) << 2 ) | ( ( a ) << 4 ) | ( ( a ) << 6 ) )
namespace squish {
namespace nvsquish {
#define VEC4_CONST( X ) Vec4( _mm_set1_ps( X ) )

@ -23,11 +23,11 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_H
#define SQUISH_H
#ifndef NV_SQUISH_H
#define NV_SQUISH_H
//! All squish API functions live in this namespace.
namespace squish {
namespace nvsquish {
// -----------------------------------------------------------------------------

@ -30,7 +30,7 @@
#include <cfloat>
namespace squish {
namespace nvsquish {
WeightedClusterFit::WeightedClusterFit()
{
@ -131,6 +131,7 @@ float WeightedClusterFit::GetBestError() const
void WeightedClusterFit::Compress3( void* block )
{
int const count = m_colours->GetCount();
Vec4 const one = VEC4_CONST(1.0f);
Vec4 const zero = VEC4_CONST(0.0f);
Vec4 const half(0.5f, 0.5f, 0.5f, 0.25f);
@ -148,11 +149,11 @@ void WeightedClusterFit::Compress3( void* block )
int b0 = 0, b1 = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 <= count; c0++)
{
Vec4 x1 = zero;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 <= count-c0; c1++)
{
Vec4 const x2 = m_xsum - x1 - x0;
@ -220,17 +221,17 @@ void WeightedClusterFit::Compress3( void* block )
for(; i < b0+b1; i++) {
bestindices[i] = 2;
}
for(; i < 16; i++) {
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < 16; ++i )
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices ); // Set alpha indices.
m_colours->RemapIndices( ordered, bestindices );
// save the block
@ -243,6 +244,7 @@ void WeightedClusterFit::Compress3( void* block )
void WeightedClusterFit::Compress4( void* block )
{
int const count = m_colours->GetCount();
Vec4 const one = VEC4_CONST(1.0f);
Vec4 const zero = VEC4_CONST(0.0f);
Vec4 const half = VEC4_CONST(0.5f);
@ -262,15 +264,15 @@ void WeightedClusterFit::Compress4( void* block )
int b0 = 0, b1 = 0, b2 = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 <= count; c0++)
{
Vec4 x1 = zero;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 <= count-c0; c1++)
{
Vec4 x2 = zero;
for( int c2 = 0; c2 <= 16-c0-c1; c2++)
for( int c2 = 0; c2 <= count-c0-c1; c2++)
{
Vec4 const x3 = m_xsum - x2 - x1 - x0;
@ -345,18 +347,20 @@ void WeightedClusterFit::Compress4( void* block )
for(; i < b0+b1+b2; i++) {
bestindices[i] = 3;
}
for(; i < 16; i++) {
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < 16; ++i )
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock4( beststart.GetVec3(), bestend.GetVec3(), ordered, block );
WriteColourBlock4( beststart.GetVec3(), bestend.GetVec3(), bestindices, block );
// save the error
m_besterror = besterror;
@ -367,6 +371,7 @@ void WeightedClusterFit::Compress4( void* block )
void WeightedClusterFit::Compress3( void* block )
{
int const count = m_colours->GetCount();
Vec3 const one( 1.0f );
Vec3 const zero( 0.0f );
Vec3 const half( 0.5f );
@ -384,12 +389,12 @@ void WeightedClusterFit::Compress3( void* block )
int b0 = 0, b1 = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 <= count; c0++)
{
Vec3 x1(0.0f);
float w1 = 0.0f;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 <= count-c0; c1++)
{
float w2 = m_wsum - w0 - w1;
@ -448,18 +453,20 @@ void WeightedClusterFit::Compress3( void* block )
for(; i < b0+b1; i++) {
bestindices[i] = 2;
}
for(; i < 16; i++) {
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < 16; ++i )
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock3( beststart, bestend, ordered, block );
WriteColourBlock3( beststart, bestend, bestindices, block );
// save the error
m_besterror = besterror;
@ -468,6 +475,7 @@ void WeightedClusterFit::Compress3( void* block )
void WeightedClusterFit::Compress4( void* block )
{
int const count = m_colours->GetCount();
Vec3 const one( 1.0f );
Vec3 const zero( 0.0f );
Vec3 const half( 0.5f );
@ -484,17 +492,17 @@ void WeightedClusterFit::Compress4( void* block )
int b0 = 0, b1 = 0, b2 = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
for( int c0 = 0; c0 <= count; c0++)
{
Vec3 x1(0.0f);
float w1 = 0.0f;
for( int c1 = 0; c1 <= 16-c0; c1++)
for( int c1 = 0; c1 <= count-c0; c1++)
{
Vec3 x2(0.0f);
float w2 = 0.0f;
for( int c2 = 0; c2 <= 16-c0-c1; c2++)
for( int c2 = 0; c2 <= count-c0-c1; c2++)
{
float w3 = m_wsum - w0 - w1 - w2;
@ -560,18 +568,20 @@ void WeightedClusterFit::Compress4( void* block )
for(; i < b0+b1+b2; i++) {
bestindices[i] = 3;
}
for(; i < 16; i++) {
for(; i < count; i++) {
bestindices[i] = 1;
}
}
// remap the indices
u8 ordered[16];
for( int i = 0; i < 16; ++i )
for( int i = 0; i < count; ++i )
ordered[m_order[i]] = bestindices[i];
m_colours->RemapIndices( ordered, bestindices );
// save the block
WriteColourBlock4( beststart, bestend, ordered, block );
WriteColourBlock4( beststart, bestend, bestindices, block );
// save the error
m_besterror = besterror;

@ -24,15 +24,15 @@
-------------------------------------------------------------------------- */
#ifndef SQUISH_WEIGHTEDCLUSTERFIT_H
#define SQUISH_WEIGHTEDCLUSTERFIT_H
#ifndef NV_SQUISH_WEIGHTEDCLUSTERFIT_H
#define NV_SQUISH_WEIGHTEDCLUSTERFIT_H
#include "squish.h"
#include "maths.h"
#include "simd.h"
#include "colourfit.h"
namespace squish {
namespace nvsquish {
class WeightedClusterFit : public ColourFit
{

Loading…
Cancel
Save