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

Minor ICN decode speed-up #7395

Merged
merged 2 commits into from
Jul 8, 2023
Merged
Changes from 1 commit
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
25 changes: 20 additions & 5 deletions src/engine/image_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,15 @@ namespace fheroes2
break;
}

memcpy( imageData + posX, data, pixelCount );
memset( imageTransform + posX, static_cast<uint8_t>( 0 ), pixelCount );
if ( pixelCount > 1 ) {
memcpy( imageData + posX, data, pixelCount );
memset( imageTransform + posX, static_cast<uint8_t>( 0 ), pixelCount );
}
else {
*( imageData + posX ) = *data;
*( imageTransform + posX ) = static_cast<uint8_t>( 0 );
}
ihhub marked this conversation as resolved.
Show resolved Hide resolved

data += pixelCount;
posX += pixelCount;
}
Expand All @@ -371,12 +378,18 @@ namespace fheroes2
++data;

const uint8_t transformValue = *data;
const uint8_t transformType = static_cast<uint8_t>( ( ( transformValue & 0x3C ) << 6 ) / 256 + 2 ); // 1 is for skipping
const uint8_t transformType = static_cast<uint8_t>( ( ( transformValue & 0x3C ) >> 2 ) + 2 ); // 1 is for skipping

const uint32_t pixelCount = *data % 4 ? *data % 4 : *( ++data );
const uint32_t countValue = transformValue & 0x03;
const uint32_t pixelCount = ( countValue != 0 ) ? countValue : *( ++data );

if ( ( transformValue & 0x40 ) && ( transformType <= 15 ) ) {
memset( imageTransform + posX, transformType, pixelCount );
if ( pixelCount > 1 ) {
memset( imageTransform + posX, transformType, pixelCount );
}
else {
*( imageTransform + posX ) = transformType;
}
ihhub marked this conversation as resolved.
Show resolved Hide resolved
}

posX += pixelCount;
Expand All @@ -390,6 +403,7 @@ namespace fheroes2

memset( imageData + posX, *data, pixelCount );
memset( imageTransform + posX, static_cast<uint8_t>( 0 ), pixelCount );

posX += pixelCount;

++data;
Expand All @@ -400,6 +414,7 @@ namespace fheroes2

memset( imageData + posX, *data, pixelCount );
memset( imageTransform + posX, static_cast<uint8_t>( 0 ), pixelCount );

posX += pixelCount;

++data;
Expand Down