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

Function DecompressImage

Engine/lib/squish/squish.cpp:211–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209}
210
211void DecompressImage( u8* rgba, int width, int height, void const* blocks, int flags )
212{
213 // fix any bad flags
214 flags = FixFlags( flags );
215
216 // initialise the block input
217 u8 const* sourceBlock = reinterpret_cast< u8 const* >( blocks );
218 int bytesPerBlock = ( ( flags & ( kDxt1 | kBc4 ) ) != 0 ) ? 8 : 16;
219
220 // loop over blocks
221 for( int y = 0; y < height; y += 4 )
222 {
223 for( int x = 0; x < width; x += 4 )
224 {
225 // decompress the block
226 u8 targetRgba[4*16];
227 Decompress( targetRgba, sourceBlock, flags );
228
229 // write the decompressed pixels to the correct image locations
230 u8 const* sourcePixel = targetRgba;
231 for( int py = 0; py < 4; ++py )
232 {
233 for( int px = 0; px < 4; ++px )
234 {
235 // get the target location
236 int sx = x + px;
237 int sy = y + py;
238 if( sx < width && sy < height )
239 {
240 u8* targetPixel = rgba + 4*( width*sy + sx );
241
242 // copy the rgba value
243 for( int i = 0; i < 4; ++i )
244 *targetPixel++ = *sourcePixel++;
245 }
246 else
247 {
248 // skip this pixel as its outside the image
249 sourcePixel += 4;
250 }
251 }
252 }
253
254 // advance
255 sourceBlock += bytesPerBlock;
256 }
257 }
258}
259
260} // namespace squish

Callers 1

decompressFunction · 0.85

Calls 2

FixFlagsFunction · 0.85
DecompressFunction · 0.85

Tested by

no test coverage detected