MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / CompressMasked

Function CompressMasked

Engine/lib/squish/squish.cpp:59–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59void CompressMasked( u8 const* rgba, int mask, void* block, int flags, float* metric )
60{
61 // fix any bad flags
62 flags = FixFlags( flags );
63
64 if ( ( flags & ( kBc4 | kBc5 ) ) != 0 )
65 {
66 u8 alpha[16*4];
67 for( int i = 0; i < 16; ++i )
68 {
69 alpha[i*4 + 3] = rgba[i*4 + 0]; // copy R to A
70 }
71
72 u8* rBlock = reinterpret_cast< u8* >( block );
73 CompressAlphaDxt5( alpha, mask, rBlock );
74
75 if ( ( flags & ( kBc5 ) ) != 0 )
76 {
77 for( int i = 0; i < 16; ++i )
78 {
79 alpha[i*4 + 3] = rgba[i*4 + 1]; // copy G to A
80 }
81
82 u8* gBlock = reinterpret_cast< u8* >( block ) + 8;
83 CompressAlphaDxt5( alpha, mask, gBlock );
84 }
85
86 return;
87 }
88
89 // get the block locations
90 void* colourBlock = block;
91 void* alphaBlock = block;
92 if( ( flags & ( kDxt3 | kDxt5 ) ) != 0 )
93 colourBlock = reinterpret_cast< u8* >( block ) + 8;
94
95 // create the minimal point set
96 ColourSet colours( rgba, mask, flags );
97
98 // check the compression type and compress colour
99 if( colours.GetCount() == 1 )
100 {
101 // always do a single colour fit
102 SingleColourFit fit( &colours, flags );
103 fit.Compress( colourBlock );
104 }
105 else if( ( flags & kColourRangeFit ) != 0 || colours.GetCount() == 0 )
106 {
107 // do a range fit
108 RangeFit fit( &colours, flags, metric );
109 fit.Compress( colourBlock );
110 }
111 else
112 {
113 // default to a cluster fit (could be iterative or not)
114 ClusterFit fit( &colours, flags, metric );
115 fit.Compress( colourBlock );
116 }

Callers 2

CompressFunction · 0.85
CompressImageFunction · 0.85

Calls 5

FixFlagsFunction · 0.85
CompressAlphaDxt5Function · 0.85
CompressAlphaDxt3Function · 0.85
CompressMethod · 0.80
GetCountMethod · 0.45

Tested by

no test coverage detected