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

Function EmitAlphaIndices

trinity/Tr2DxtCompressor.cpp:378–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378void EmitAlphaIndices( const uint8_t* colorBlock, const uint8_t minAlpha, const uint8_t maxAlpha, uint8_t** outBuff )
379{
380
381 CCP_ASSERT( maxAlpha >= minAlpha );
382
383 const int ALPHA_RANGE = 7;
384
385 uint8_t mid, ab1, ab2, ab3, ab4, ab5, ab6, ab7;
386 uint8_t indexes[16];
387
388 mid = ( maxAlpha - minAlpha ) / ( 2 * ALPHA_RANGE );
389
390 ab1 = minAlpha + mid;
391 ab2 = ( 6 * maxAlpha + 1 * minAlpha ) / ALPHA_RANGE + mid;
392 ab3 = ( 5 * maxAlpha + 2 * minAlpha ) / ALPHA_RANGE + mid;
393 ab4 = ( 4 * maxAlpha + 3 * minAlpha ) / ALPHA_RANGE + mid;
394 ab5 = ( 3 * maxAlpha + 4 * minAlpha ) / ALPHA_RANGE + mid;
395 ab6 = ( 2 * maxAlpha + 5 * minAlpha ) / ALPHA_RANGE + mid;
396 ab7 = ( 1 * maxAlpha + 6 * minAlpha ) / ALPHA_RANGE + mid;
397
398 for( int i = 0; i < 16; i++ )
399 {
400 uint8_t a = colorBlock[i * 4 + 3];
401 int b1 = ( a <= ab1 );
402 int b2 = ( a <= ab2 );
403 int b3 = ( a <= ab3 );
404 int b4 = ( a <= ab4 );
405 int b5 = ( a <= ab5 );
406 int b6 = ( a <= ab6 );
407 int b7 = ( a <= ab7 );
408 int index = ( b1 + b2 + b3 + b4 + b5 + b6 + b7 + 1 ) & 7;
409 indexes[i] = index ^ ( 2 > index );
410 }
411
412 EmitByte( ( indexes[0] >> 0 ) | ( indexes[1] << 3 ) | ( indexes[2] << 6 ), outBuff );
413 EmitByte( ( indexes[2] >> 2 ) | ( indexes[3] << 1 ) | ( indexes[4] << 4 ) | ( indexes[5] << 7 ), outBuff );
414 EmitByte( ( indexes[5] >> 1 ) | ( indexes[6] << 2 ) | ( indexes[7] << 5 ), outBuff );
415
416 EmitByte( ( indexes[8] >> 0 ) | ( indexes[9] << 3 ) | ( indexes[10] << 6 ), outBuff );
417 EmitByte( ( indexes[10] >> 2 ) | ( indexes[11] << 1 ) | ( indexes[12] << 4 ) | ( indexes[13] << 7 ), outBuff );
418 EmitByte( ( indexes[13] >> 1 ) | ( indexes[14] << 2 ) | ( indexes[15] << 5 ), outBuff );
419}
420
421void EmitColorIndices( const uint8_t* colorBlock, const uint8_t* minColor, const uint8_t* maxColor, uint8_t** outBuff )
422{

Callers 3

CompressYCoCgDXT5Function · 0.85
CompressImageDXT5Function · 0.85
CompressNormalMapDXT5Function · 0.85

Calls 1

EmitByteFunction · 0.85

Tested by

no test coverage detected