Merge 41b5945172
into a131e4c6b0
This commit is contained in:
commit
8d140dceef
|
@ -5,6 +5,15 @@ ENABLE_TESTING()
|
||||||
SET(NV_CMAKE_DIR "${NV_SOURCE_DIR}/cmake")
|
SET(NV_CMAKE_DIR "${NV_SOURCE_DIR}/cmake")
|
||||||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${NV_CMAKE_DIR}")
|
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${NV_CMAKE_DIR}")
|
||||||
|
|
||||||
|
OPTION(SQUISH_FULL_LIBRARY "Makes the whole squish library compiled, instead of just what's needed in NVTT. Please be aware that this build path is not officially maintained." OFF)
|
||||||
|
MARK_AS_ADVANCED(SQUISH_FULL_LIBRARY)
|
||||||
|
OPTION(INSTALL_SQUISH "Install the (internal) squish library alongside NVTT binaries." OFF)
|
||||||
|
MARK_AS_ADVANCED(INSTALL_SQUISH)
|
||||||
|
OPTION(INSTALL_BC6H "Install the (internal) BC6H library alongside NVTT binaries." OFF)
|
||||||
|
MARK_AS_ADVANCED(INSTALL_BC6H)
|
||||||
|
OPTION(INSTALL_BC7 "Install the (internal) BC7 library alongside NVTT binaries." OFF)
|
||||||
|
MARK_AS_ADVANCED(INSTALL_BC7)
|
||||||
|
|
||||||
# GCC check (needs -std:c++11 flag)
|
# GCC check (needs -std:c++11 flag)
|
||||||
#if(CMAKE_COMPILER_IS_GNUCC)
|
#if(CMAKE_COMPILER_IS_GNUCC)
|
||||||
# ADD_DEFINITIONS("-std=c++11")
|
# ADD_DEFINITIONS("-std=c++11")
|
||||||
|
|
|
@ -21,3 +21,10 @@ IF(NOT WIN32)
|
||||||
SET_TARGET_PROPERTIES(bc6h PROPERTIES COMPILE_FLAGS -fPIC)
|
SET_TARGET_PROPERTIES(bc6h PROPERTIES COMPILE_FLAGS -fPIC)
|
||||||
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
ENDIF(NOT WIN32)
|
ENDIF(NOT WIN32)
|
||||||
|
|
||||||
|
IF(INSTALL_BC6H)
|
||||||
|
INSTALL(TARGETS bc6h
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib/static)
|
||||||
|
ENDIF(INSTALL_BC6H)
|
||||||
|
|
|
@ -31,3 +31,10 @@ IF(NOT WIN32)
|
||||||
SET_TARGET_PROPERTIES(bc7 PROPERTIES COMPILE_FLAGS -fPIC)
|
SET_TARGET_PROPERTIES(bc7 PROPERTIES COMPILE_FLAGS -fPIC)
|
||||||
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
ENDIF(NOT WIN32)
|
ENDIF(NOT WIN32)
|
||||||
|
|
||||||
|
IF(INSTALL_BC7)
|
||||||
|
INSTALL(TARGETS bc7
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib/static)
|
||||||
|
ENDIF(INSTALL_BC7)
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "nvcore/StrLib.h"
|
#include "nvcore/StrLib.h"
|
||||||
#include "nvcore/StdStream.h"
|
#include "nvcore/StdStream.h"
|
||||||
#include "nvcore/TextWriter.h"
|
#include "nvcore/TextWriter.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
// Extern
|
// Extern
|
||||||
#if defined(NV_HAVE_FREEIMAGE)
|
#if defined(NV_HAVE_FREEIMAGE)
|
||||||
|
|
|
@ -20,6 +20,23 @@ SET(SQUISH_SRCS
|
||||||
simd_sse.h
|
simd_sse.h
|
||||||
simd_ve.h)
|
simd_ve.h)
|
||||||
|
|
||||||
|
# Additionnal squish source files which are not included in NVTT by default
|
||||||
|
IF(SQUISH_FULL_LIBRARY)
|
||||||
|
SET(SQUISH_SRCS ${SQUISH_SRCS}
|
||||||
|
alpha.h
|
||||||
|
alpha.cpp
|
||||||
|
clusterfit.h
|
||||||
|
clusterfit.cpp
|
||||||
|
rangefit.h
|
||||||
|
rangefit.cpp
|
||||||
|
singlechannelfit.h
|
||||||
|
singlechannelfit.cpp
|
||||||
|
singlecolourfit.h
|
||||||
|
singlecolourfit.cpp
|
||||||
|
squish.cpp
|
||||||
|
)
|
||||||
|
ENDIF(SQUISH_FULL_LIBRARY)
|
||||||
|
|
||||||
ADD_LIBRARY(squish STATIC ${SQUISH_SRCS})
|
ADD_LIBRARY(squish STATIC ${SQUISH_SRCS})
|
||||||
|
|
||||||
IF(NOT WIN32)
|
IF(NOT WIN32)
|
||||||
|
@ -33,3 +50,9 @@ IF(NOT WIN32)
|
||||||
ENDIF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
|
ENDIF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX)
|
||||||
ENDIF(NOT WIN32)
|
ENDIF(NOT WIN32)
|
||||||
|
|
||||||
|
IF(INSTALL_SQUISH)
|
||||||
|
INSTALL(TARGETS squish
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib/static)
|
||||||
|
ENDIF(INSTALL_SQUISH)
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "alpha.h"
|
#include "alpha.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
static int FloatToInt( float a, int limit )
|
static int FloatToInt( float a, int limit )
|
||||||
{
|
{
|
||||||
|
@ -323,4 +323,4 @@ void DecompressAlphaDxt5( u8* rgba, void const* block )
|
||||||
rgba[4*i + 3] = codes[indices[i]];
|
rgba[4*i + 3] = codes[indices[i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "squish.h"
|
#include "squish.h"
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
void CompressAlphaDxt3( u8 const* rgba, void* block );
|
void CompressAlphaDxt3( u8 const* rgba, void* block );
|
||||||
void CompressAlphaDxt5( u8 const* rgba, void* block );
|
void CompressAlphaDxt5( u8 const* rgba, void* block );
|
||||||
|
@ -36,6 +36,6 @@ void CompressAlphaDxt5( u8 const* rgba, void* block );
|
||||||
void DecompressAlphaDxt3( u8* rgba, void const* block );
|
void DecompressAlphaDxt3( u8* rgba, void const* block );
|
||||||
void DecompressAlphaDxt5( u8* rgba, void const* block );
|
void DecompressAlphaDxt5( u8* rgba, void const* block );
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
||||||
#endif // ndef SQUISH_ALPHA_H
|
#endif // ndef SQUISH_ALPHA_H
|
||||||
|
|
|
@ -78,6 +78,6 @@ private:
|
||||||
int m_order[16];
|
int m_order[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
||||||
#endif // ndef SQUISH_CLUSTERFIT_H
|
#endif // ndef SQUISH_CLUSTERFIT_H
|
||||||
|
|
|
@ -53,7 +53,7 @@ static int FloatTo565( Vec3::Arg colour )
|
||||||
return ( r << 11 ) | ( g << 5 ) | b;
|
return ( r << 11 ) | ( g << 5 ) | b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void WriteColourBlock( int a, int b, u8* indices, void* block )
|
void WriteColourBlock( int a, int b, u8* indices, void* block )
|
||||||
{
|
{
|
||||||
// get the block as bytes
|
// get the block as bytes
|
||||||
u8* bytes = ( u8* )block;
|
u8* bytes = ( u8* )block;
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
namespace nvsquish {
|
namespace nvsquish {
|
||||||
|
|
||||||
|
void WriteColourBlock(int a, int b, u8* indices, void* block);
|
||||||
void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block );
|
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 );
|
void WriteColourBlock4( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block );
|
||||||
//void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, uint indices, void* block );
|
//void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, uint indices, void* block );
|
||||||
|
|
|
@ -28,11 +28,12 @@
|
||||||
#include "colourblock.h"
|
#include "colourblock.h"
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
RangeFit::RangeFit( ColourSet const* colours, int flags )
|
RangeFit::RangeFit( ColourSet const* colours, int flags )
|
||||||
: ColourFit( colours, flags )
|
|
||||||
{
|
{
|
||||||
|
SetColourSet(colours, flags);
|
||||||
|
|
||||||
// initialise the metric
|
// initialise the metric
|
||||||
bool perceptual = ( ( m_flags & kColourMetricPerceptual ) != 0 );
|
bool perceptual = ( ( m_flags & kColourMetricPerceptual ) != 0 );
|
||||||
if( perceptual )
|
if( perceptual )
|
||||||
|
@ -49,7 +50,7 @@ RangeFit::RangeFit( ColourSet const* colours, int flags )
|
||||||
float const* weights = m_colours->GetWeights();
|
float const* weights = m_colours->GetWeights();
|
||||||
|
|
||||||
// get the covariance matrix
|
// get the covariance matrix
|
||||||
Sym3x3 covariance = ComputeWeightedCovariance( count, values, weights );
|
Sym3x3 covariance = ComputeWeightedCovariance( count, values, weights, Vec3(1,1,1) );
|
||||||
|
|
||||||
// compute the principle component
|
// compute the principle component
|
||||||
Vec3 principle = ComputePrincipleComponent( covariance );
|
Vec3 principle = ComputePrincipleComponent( covariance );
|
||||||
|
@ -199,4 +200,4 @@ void RangeFit::Compress4( void* block )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "colourfit.h"
|
#include "colourfit.h"
|
||||||
#include "maths.h"
|
#include "maths.h"
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
class ColourSet;
|
class ColourSet;
|
||||||
|
|
||||||
|
@ -49,6 +49,6 @@ private:
|
||||||
float m_besterror;
|
float m_besterror;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // squish
|
} // namespace nvsquish
|
||||||
|
|
||||||
#endif // ndef SQUISH_RANGEFIT_H
|
#endif // ndef SQUISH_RANGEFIT_H
|
||||||
|
|
|
@ -29,11 +29,12 @@
|
||||||
#include "colourblock.h"
|
#include "colourblock.h"
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
SingleChannelFit::SingleChannelFit( ColourSet const* colours, int const flags )
|
SingleChannelFit::SingleChannelFit( ColourSet const* colours, int const flags )
|
||||||
: ColourFit( colours, flags )
|
|
||||||
{
|
{
|
||||||
|
SetColourSet(colours, flags);
|
||||||
|
|
||||||
// cache some values
|
// cache some values
|
||||||
int const count = m_colours->GetCount();
|
int const count = m_colours->GetCount();
|
||||||
Vec3 const* values = m_colours->GetPoints();
|
Vec3 const* values = m_colours->GetPoints();
|
||||||
|
@ -42,7 +43,7 @@ SingleChannelFit::SingleChannelFit( ColourSet const* colours, int const flags )
|
||||||
m_g_min = 63;
|
m_g_min = 63;
|
||||||
m_g_max = 0;
|
m_g_max = 0;
|
||||||
|
|
||||||
for(uint i = 0; i < count; i++) {
|
for(int i = 0; i < count; i++) {
|
||||||
|
|
||||||
int grey = int(values[i].Y() * 255.0f); // @@ rounding?
|
int grey = int(values[i].Y() * 255.0f); // @@ rounding?
|
||||||
grey = std::min(grey, 255); // clamp to [0, 1)
|
grey = std::min(grey, 255); // clamp to [0, 1)
|
||||||
|
@ -141,4 +142,4 @@ void SingleChannelFit::Compress4( void* block )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include "maths.h"
|
#include "maths.h"
|
||||||
#include "colourfit.h"
|
#include "colourfit.h"
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
class SingleChannelFit : public ColourFit
|
class SingleChannelFit : public ColourFit
|
||||||
{
|
{
|
||||||
|
@ -48,6 +48,6 @@ private:
|
||||||
int m_g_max;
|
int m_g_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
||||||
#endif // ndef SQUISH_SINGLECHANNELFIT_H
|
#endif // ndef SQUISH_SINGLECHANNELFIT_H
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "colourset.h"
|
#include "colourset.h"
|
||||||
#include "colourblock.h"
|
#include "colourblock.h"
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
struct SourceBlock
|
struct SourceBlock
|
||||||
{
|
{
|
||||||
|
@ -59,8 +59,9 @@ static int FloatToInt( float a, int limit )
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleColourFit::SingleColourFit( ColourSet const* colours, int flags )
|
SingleColourFit::SingleColourFit( ColourSet const* colours, int flags )
|
||||||
: ColourFit( colours, flags )
|
|
||||||
{
|
{
|
||||||
|
SetColourSet(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 );
|
||||||
|
@ -169,4 +170,4 @@ void SingleColourFit::ComputeEndPoints( int count, SingleColourLookup const* con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include <squish.h>
|
#include <squish.h>
|
||||||
#include "colourfit.h"
|
#include "colourfit.h"
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
class ColourSet;
|
class ColourSet;
|
||||||
struct SingleColourLookup;
|
struct SingleColourLookup;
|
||||||
|
@ -53,6 +53,6 @@ private:
|
||||||
int m_besterror;
|
int m_besterror;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
||||||
#endif // ndef SQUISH_SINGLECOLOURFIT_H
|
#endif // ndef SQUISH_SINGLECOLOURFIT_H
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "alpha.h"
|
#include "alpha.h"
|
||||||
#include "singlecolourfit.h"
|
#include "singlecolourfit.h"
|
||||||
|
|
||||||
namespace squish {
|
namespace nvsquish {
|
||||||
|
|
||||||
static int FixFlags( int flags )
|
static int FixFlags( int flags )
|
||||||
{
|
{
|
||||||
|
@ -85,7 +85,8 @@ void Compress( u8 const* rgba, void* block, int flags )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// default to a cluster fit
|
// default to a cluster fit
|
||||||
ClusterFit fit( &colours, flags );
|
ClusterFit fit;
|
||||||
|
fit.SetColourSet(&colours, flags);
|
||||||
fit.Compress( colourBlock );
|
fit.Compress( colourBlock );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,4 +223,4 @@ void DecompressImage( u8* rgba, int width, int height, void const* blocks, int f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace squish
|
} // namespace nvsquish
|
||||||
|
|
Loading…
Reference in New Issue
Block a user