diff --git a/src/engine/image_tool.cpp b/src/engine/image_tool.cpp index 2b0949b2ec6..671657a8109 100644 --- a/src/engine/image_tool.cpp +++ b/src/engine/image_tool.cpp @@ -357,6 +357,7 @@ namespace fheroes2 memcpy( imageData + posX, data, pixelCount ); memset( imageTransform + posX, static_cast( 0 ), pixelCount ); + data += pixelCount; posX += pixelCount; } @@ -371,9 +372,10 @@ namespace fheroes2 ++data; const uint8_t transformValue = *data; - const uint8_t transformType = static_cast( ( ( transformValue & 0x3C ) << 6 ) / 256 + 2 ); // 1 is for skipping + const uint8_t transformType = static_cast( ( ( 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 ); @@ -390,6 +392,7 @@ namespace fheroes2 memset( imageData + posX, *data, pixelCount ); memset( imageTransform + posX, static_cast( 0 ), pixelCount ); + posX += pixelCount; ++data; @@ -400,6 +403,7 @@ namespace fheroes2 memset( imageData + posX, *data, pixelCount ); memset( imageTransform + posX, static_cast( 0 ), pixelCount ); + posX += pixelCount; ++data;