MCPcopy Create free account
hub / github.com/carbonengine/trinity / DecompressBC2

Function DecompressBC2

trinity/UI/Tr2MouseCursor.cpp:180–219  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Helper function to decompress BC2 format image into B8G8R8A8 format. Used by mouse cursors, which are small and are cached, so the function doesn't have to be super- optimal. Also flips image vertically for DX11 and GL since DX and WINAPI use different origin. Arguments: dest - Destination buffer so

Source from the content-addressed store, hash-verified

178// pitch - Destination image pitch
179// --------------------------------------------------------------------------------------
180static void DecompressBC2( char* dest, const char* source, unsigned width, unsigned height, unsigned pitch )
181{
182 for( unsigned j = 0; j < height; j += 4 )
183 {
184 for( unsigned i = 0; i < width; i += 4 )
185 {
186 unsigned color0 = *reinterpret_cast<const unsigned short*>( source + 8 );
187 unsigned color1 = *reinterpret_cast<const unsigned short*>( source + 8 + 2 );
188 unsigned bits = *reinterpret_cast<const unsigned*>( source + 8 + 4 );
189 for( unsigned y = 0; y < 4; ++y )
190 {
191 for( unsigned x = 0; x < 4; ++x )
192 {
193 unsigned destY = j + y;
194 destY = height - 1 - destY;
195
196 uint32_t* destPixel = reinterpret_cast<uint32_t*>( dest + destY * pitch + ( x + i ) * sizeof( uint32_t ) );
197 unsigned alphaValue = ( *( reinterpret_cast<const unsigned short*>( source ) + y ) >> x * 4 ) & 15;
198 alphaValue = alphaValue * 255 / 15;
199 switch( ( bits >> 2 * ( 4 * y + x ) ) & 3 )
200 {
201 case 0:
202 *destPixel = ConvertBGR565A8ToBGRA8( color0, alphaValue );
203 break;
204 case 1:
205 *destPixel = ConvertBGR565A8ToBGRA8( color1, alphaValue );
206 break;
207 case 2:
208 *destPixel = ConvertBGR565A8ToBGRA8( ( 2 * color0 + color1 ) / 3, alphaValue );
209 break;
210 case 3:
211 *destPixel = ConvertBGR565A8ToBGRA8( ( color0 + 2 * color1 ) / 3, alphaValue );
212 break;
213 }
214 }
215 }
216 source += 16;
217 }
218 }
219}
220
221std::unique_ptr<char[]> GetUncompressedBitmap( const Tr2HostBitmap* bitmap )
222{

Callers 2

GetUncompressedBitmapFunction · 0.85
CreateMethod · 0.85

Calls 1

ConvertBGR565A8ToBGRA8Function · 0.70

Tested by

no test coverage detected