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

Function CompressNormalMapDXT5NoAlpha

trinity/Tr2DxtCompressor.cpp:757–793  ·  view source on GitHub ↗

below works fine, but doesn't support a material id in the alpha channel

Source from the content-addressed store, hash-verified

755
756// below works fine, but doesn't support a material id in the alpha channel
757void CompressNormalMapDXT5NoAlpha( const uint8_t* inBuf, uint8_t* outBuf, int width, int height, ptrdiff_t& outputBytes, volatile const bool& cancel )
758{
759 uint8_t block[64];
760 uint8_t normalMin[4];
761 uint8_t normalMax[4];
762
763 uint8_t** outData = &outBuf;
764
765 for( int j = 0; j < height; j += 4, inBuf += width * 4 * 4 )
766 {
767 if( cancel )
768 {
769 return;
770 }
771 for( int i = 0; i < width; i += 4 )
772 {
773
774 ExtractBlock( inBuf + i * 4, width, block );
775
776 GetMinMaxNormalsBBox( block, normalMin, normalMax );
777 InsetNormalsBBoxDXT5( normalMin, normalMax );
778
779 // Write out Nx into alpha channel.
780 // Note: all code in this file assumes TRIFMT_A8R8G8B8, so red is at [2]
781 EmitByte( normalMax[0], outData );
782 EmitByte( normalMin[0], outData );
783 EmitAlphaIndicesForNormals( block, 2, normalMin[0], normalMax[0], outData );
784
785 // Write out Ny into green channel.
786 EmitWord( NormalYTo565( normalMax[1] ), outData );
787 EmitWord( NormalYTo565( normalMin[1] ), outData );
788 EmitGreenIndices( block, 1, normalMin[1], normalMax[1], outData );
789 }
790 }
791
792 outputBytes = *outData - outBuf;
793}
794
795void CompressNormalMap3Dc( const uint8_t* inBuf, uint8_t* outBuf, int width, int height, ptrdiff_t& outputBytes, volatile const bool& cancel )
796{

Callers

nothing calls this directly

Calls 8

ExtractBlockFunction · 0.85
GetMinMaxNormalsBBoxFunction · 0.85
InsetNormalsBBoxDXT5Function · 0.85
EmitByteFunction · 0.85
EmitWordFunction · 0.85
NormalYTo565Function · 0.85
EmitGreenIndicesFunction · 0.85

Tested by

no test coverage detected