Skip to content

Commit

Permalink
Minor ICN decode speed-up (#7395)
Browse files Browse the repository at this point in the history
  • Loading branch information
Districh-ru authored Jul 8, 2023
1 parent a4fb51e commit 8096359
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/engine/image_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ namespace fheroes2

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

data += pixelCount;
posX += pixelCount;
}
Expand All @@ -371,9 +372,10 @@ 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 );
Expand All @@ -390,6 +392,7 @@ namespace fheroes2

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

posX += pixelCount;

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

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

posX += pixelCount;

++data;
Expand Down

0 comments on commit 8096359

Please sign in to comment.