Skip to content

Commit

Permalink
Optimize alpha channel average encoding.
Browse files Browse the repository at this point in the history
Results are slighlty different in some cases, but I think the new ones
look better.
  • Loading branch information
wolfpld committed Aug 10, 2013
1 parent 414401a commit b89c862
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions ProcessAlpha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,18 @@ static void EncodeAverages( uint64& d, const uint* a, size_t idx )
d |= ( idx << 24 );
size_t base = idx << 1;

uint v;
if( ( idx & 0x2 ) == 0 )
{
for( int i=0; i<3; i++ )
{
d |= uint64( a[base+0] >> 4 ) << ( i*8 );
d |= uint64( a[base+1] >> 4 ) << ( i*8 + 4 );
}
v = ( a[base+0] >> 4 ) | ( a[base+1] & 0xF0 );
}
else
{
for( int i=0; i<3; i++ )
{
d |= uint64( a[base+1] & 0xF8 ) << ( i*8 );
int32 c = ( ( a[base+0] & 0xF8 ) - ( a[base+1] & 0xF8 ) ) >> 3;
c &= ~0xFFFFFFF8;
d |= ((uint64)c) << ( i*8 );
}
v = a[base+1] & 0xF8;
int32 c = ( ( a[base+0] & 0xF8 ) - ( a[base+1] & 0xF8 ) ) >> 3;
v |= c & ~0xFFFFFFF8;
}
d |= v | ( v << 8 ) | ( v << 16 );
}

uint64 ProcessAlpha( const uint8* src )
Expand Down

0 comments on commit b89c862

Please sign in to comment.