kDxt1GCN flag

This commit is contained in:
Jack Andersen 2015-07-19 10:47:24 -10:00
parent 21d3742aa5
commit ac84440bec
8 changed files with 201 additions and 173 deletions

View File

@ -27,6 +27,7 @@
#include "clusterfit.h"
#include "colourset.h"
#include "colourblock.h"
#include "colourblockGCN.h"
#include <cfloat>
namespace squish {
@ -237,6 +238,9 @@ void ClusterFit::Compress3( void* block )
m_colours->RemapIndices( unordered, bestindices );
// save the block
if ( ( m_flags & kDxt1GCN ) != 0 )
WriteColourBlock3GCN( beststart.GetVec3(), bestend.GetVec3(), bestindices, block );
else
WriteColourBlock3( beststart.GetVec3(), bestend.GetVec3(), bestindices, block );
// save the error
@ -382,6 +386,9 @@ void ClusterFit::Compress4( void* block )
m_colours->RemapIndices( unordered, bestindices );
// save the block
if ( ( m_flags & kDxt1GCN ) != 0 )
WriteColourBlock4GCN( beststart.GetVec3(), bestend.GetVec3(), bestindices, block );
else
WriteColourBlock4( beststart.GetVec3(), bestend.GetVec3(), bestindices, block );
// save the error

View File

@ -61,7 +61,7 @@ static void WriteColourBlock( int a, int b, u8* indices, void* block )
// get the block as bytes
u8* bytes = ( u8* )block;
// write the endpoints - GCN 16-bit words byte-swapped
// write the endpoints - GCN: 16-bit words byte-swapped
bytes[1] = ( u8 )( a & 0xff );
bytes[0] = ( u8 )( a >> 8 );
bytes[3] = ( u8 )( b & 0xff );

View File

@ -40,7 +40,7 @@ ColourFit::~ColourFit()
void ColourFit::Compress( void* block )
{
bool isDxt1 = ( ( m_flags & kDxt1 ) != 0 );
bool isDxt1 = ( ( m_flags & ( kDxt1 | kDxt1GCN ) ) != 0 );
if( isDxt1 )
{
Compress3( block );

View File

@ -32,7 +32,7 @@ ColourSet::ColourSet( u8 const* rgba, int mask, int flags )
m_transparent( false )
{
// check the compression mode for dxt1
bool isDxt1 = ( ( flags & kDxt1 ) != 0 );
bool isDxt1 = ( ( flags & ( kDxt1 | kDxt1GCN ) ) != 0 );
bool weightByAlpha = ( ( flags & kWeightColourByAlpha ) != 0 );
// create the minimal set

View File

@ -26,6 +26,7 @@
#include "rangefit.h"
#include "colourset.h"
#include "colourblock.h"
#include "colourblockGCN.h"
#include <cfloat>
namespace squish {
@ -138,6 +139,9 @@ void RangeFit::Compress3( void* block )
m_colours->RemapIndices( closest, indices );
// save the block
if ( ( m_flags & kDxt1GCN ) != 0 )
WriteColourBlock3GCN( m_start, m_end, indices, block );
else
WriteColourBlock3( m_start, m_end, indices, block );
// save the error
@ -191,6 +195,9 @@ void RangeFit::Compress4( void* block )
m_colours->RemapIndices( closest, indices );
// save the block
if ( ( m_flags & kDxt1GCN ) != 0 )
WriteColourBlock4GCN( m_start, m_end, indices, block );
else
WriteColourBlock4( m_start, m_end, indices, block );
// save the error

View File

@ -26,6 +26,7 @@
#include "singlecolourfit.h"
#include "colourset.h"
#include "colourblock.h"
#include "colourblockGCN.h"
namespace squish {
@ -92,6 +93,9 @@ void SingleColourFit::Compress3( void* block )
m_colours->RemapIndices( &m_index, indices );
// save the block
if ( ( m_flags & kDxt1GCN ) != 0 )
WriteColourBlock3GCN( m_start, m_end, indices, block );
else
WriteColourBlock3( m_start, m_end, indices, block );
// save the error
@ -120,6 +124,9 @@ void SingleColourFit::Compress4( void* block )
m_colours->RemapIndices( &m_index, indices );
// save the block
if ( ( m_flags & kDxt1GCN ) != 0 )
WriteColourBlock4GCN( m_start, m_end, indices, block );
else
WriteColourBlock4( m_start, m_end, indices, block );
// save the error

View File

@ -29,6 +29,7 @@
#include "rangefit.h"
#include "clusterfit.h"
#include "colourblock.h"
#include "colourblockGCN.h"
#include "alpha.h"
#include "singlecolourfit.h"
@ -37,12 +38,12 @@ namespace squish {
static int FixFlags( int flags )
{
// grab the flag bits
int method = flags & ( kDxt1 | kDxt3 | kDxt5 );
int method = flags & ( kDxt1 | kDxt3 | kDxt5 | kDxt1GCN );
int fit = flags & ( kColourIterativeClusterFit | kColourClusterFit | kColourRangeFit );
int extra = flags & kWeightColourByAlpha;
// set defaults
if( method != kDxt3 && method != kDxt5 )
if( method != kDxt3 && method != kDxt5 && method != kDxt1GCN )
method = kDxt1;
if( fit != kColourRangeFit && fit != kColourIterativeClusterFit )
fit = kColourClusterFit;
@ -104,6 +105,9 @@ void Decompress( u8* rgba, void const* block, int flags )
colourBlock = reinterpret_cast< u8 const* >( block ) + 8;
// decompress colour
if ( ( flags & kDxt1GCN ) != 0 )
DecompressColourGCN( rgba, colourBlock );
else
DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 );
// decompress alpha separately if necessary
@ -120,7 +124,7 @@ int GetStorageRequirements( int width, int height, int flags )
// compute the storage requirements
int blockcount = ( ( width + 3 )/4 ) * ( ( height + 3 )/4 );
int blocksize = ( ( flags & kDxt1 ) != 0 ) ? 8 : 16;
int blocksize = ( ( flags & ( kDxt1 | kDxt1GCN ) ) != 0 ) ? 8 : 16;
return blockcount*blocksize;
}
@ -131,7 +135,7 @@ void CompressImage( u8 const* rgba, int width, int height, void* blocks, int fla
// initialise the block output
u8* targetBlock = reinterpret_cast< u8* >( blocks );
int bytesPerBlock = ( ( flags & kDxt1 ) != 0 ) ? 8 : 16;
int bytesPerBlock = ( ( flags & ( kDxt1 | kDxt1GCN ) ) != 0 ) ? 8 : 16;
// loop over blocks
for( int y = 0; y < height; y += 4 )
@ -185,7 +189,7 @@ void DecompressImage( u8* rgba, int width, int height, void const* blocks, int f
// initialise the block input
u8 const* sourceBlock = reinterpret_cast< u8 const* >( blocks );
int bytesPerBlock = ( ( flags & kDxt1 ) != 0 ) ? 8 : 16;
int bytesPerBlock = ( ( flags & ( kDxt1 | kDxt1GCN ) ) != 0 ) ? 8 : 16;
// loop over blocks
for( int y = 0; y < height; y += 4 )

View File

@ -47,6 +47,9 @@ enum
//! Use DXT5 compression.
kDxt5 = ( 1 << 2 ),
//! Use DXT1 compression with GCN byte-ordering
kDxt1GCN = ( 1 << 9 ),
//! Use a very slow but very high quality colour compressor.
kColourIterativeClusterFit = ( 1 << 8 ),