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

Function DecompressColour

Engine/lib/squish/colourblock.cpp:160–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160void DecompressColour( u8* rgba, void const* block, bool isDxt1 )
161{
162 // get the block bytes
163 u8 const* bytes = reinterpret_cast< u8 const* >( block );
164
165 // unpack the endpoints
166 u8 codes[16];
167 int a = Unpack565( bytes, codes );
168 int b = Unpack565( bytes + 2, codes + 4 );
169
170 // generate the midpoints
171 for( int i = 0; i < 3; ++i )
172 {
173 int c = codes[i];
174 int d = codes[4 + i];
175
176 if( isDxt1 && a <= b )
177 {
178 codes[8 + i] = ( u8 )( ( c + d )/2 );
179 codes[12 + i] = 0;
180 }
181 else
182 {
183 codes[8 + i] = ( u8 )( ( 2*c + d )/3 );
184 codes[12 + i] = ( u8 )( ( c + 2*d )/3 );
185 }
186 }
187
188 // fill in alpha for the intermediate values
189 codes[8 + 3] = 255;
190 codes[12 + 3] = ( isDxt1 && a <= b ) ? 0 : 255;
191
192 // unpack the indices
193 u8 indices[16];
194 for( int i = 0; i < 4; ++i )
195 {
196 u8* ind = indices + 4*i;
197 u8 packed = bytes[4 + i];
198
199 ind[0] = packed & 0x3;
200 ind[1] = ( packed >> 2 ) & 0x3;
201 ind[2] = ( packed >> 4 ) & 0x3;
202 ind[3] = ( packed >> 6 ) & 0x3;
203 }
204
205 // store out the colours
206 for( int i = 0; i < 16; ++i )
207 {
208 u8 offset = 4*indices[i];
209 for( int j = 0; j < 4; ++j )
210 rgba[4*i + j] = codes[offset + j];
211 }
212}
213
214} // namespace squish

Callers 1

DecompressFunction · 0.85

Calls 1

Unpack565Function · 0.85

Tested by

no test coverage detected