Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12220: Add Decompress Bc5 to Squish #13025

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions thirdparty/squish/colourblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,87 @@ void DecompressColour( u8* rgba, void const* block, bool isDxt1 )
}
}

void DecompressColourBc5( u8* rgba, void const* block)
{
// get the block bytes
u8 const* bytes = reinterpret_cast< u8 const* >( block );

// unpack the endpoints
u8 codes[16];
int red_0 = bytes[0];
int red_1 = bytes[1];

codes[0] = red_0;
codes[1] = red_1;
codes[6] = 0.0f;
codes[7] = 1.0f;
// generate the midpoints
if(red_0 > red_1)
{
for( int i = 2; i < 8; ++i )
{
codes[i] = ((8-i)*red_0 + (i-1)*red_1)/7;
}
}
else
{
for( int i = 2; i < 6; ++i )
{
codes[i] = ((6-i)*red_0 + (i-1)*red_1)/5;
}
}

int green_0 = bytes[8];
int green_1 = bytes[9];

codes[0 + 8] = green_0;
codes[1 + 8] = green_1;
codes[6 + 8] = 0.0f;
codes[7 + 8] = 1.0f;
// generate the midpoints
if(green_0 > green_1)
{
for( int i = 2; i < 8; ++i )
{
codes[i + 8] = ((8-i)*green_0 + (i-1)*green_1)/7;
}
}
else
{
for( int i = 2; i < 6; ++i )
{
codes[i + 8] = ((6-i)*green_0 + (i-1)*green_1)/5;
}
}

u8 indices[32];
for( int i = 0; i < 4; ++i )
{
u8 packed = bytes[2 + i];
u8* red_ind = indices + 4*i;

red_ind[0] = packed & 0x3;
red_ind[1] = ( packed >> 2 ) & 0x3;
red_ind[2] = ( packed >> 4 ) & 0x3;
red_ind[3] = ( packed >> 6 ) & 0x3;

packed = bytes[8 + i];
u8* green_ind = indices + 4*i + 16;
green_ind[0] = packed & 0x3;
green_ind[1] = ( packed >> 2 ) & 0x3;
green_ind[2] = ( packed >> 4 ) & 0x3;
green_ind[3] = ( packed >> 6 ) & 0x3;
}

// store out the colours
for( int i = 0; i < 16; ++i )
{
rgba[4*i] = codes[indices[i]];
rgba[4*i +1] = codes[indices[i + 16] + 8];
rgba[4*i +2] = 0;
rgba[4*i +3] = 255;
}
}


} // namespace squish
1 change: 1 addition & 0 deletions thirdparty/squish/colourblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void WriteColourBlock3( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void*
void WriteColourBlock4( Vec3::Arg start, Vec3::Arg end, u8 const* indices, void* block );

void DecompressColour( u8* rgba, void const* block, bool isDxt1 );
void DecompressColourBc5( u8* rgba, void const* block );

} // namespace squish

Expand Down
5 changes: 4 additions & 1 deletion thirdparty/squish/squish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ void Decompress( u8* rgba, void const* block, int flags )
colourBlock = reinterpret_cast< u8 const* >( block ) + 8;

// decompress colour
DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 );
if(( flags & ( kBc5 ) ) != 0)
DecompressColourBc5( rgba, colourBlock);
else
DecompressColour( rgba, colourBlock, ( flags & kDxt1 ) != 0 );

// decompress alpha separately if necessary
if( ( flags & kDxt3 ) != 0 )
Expand Down