Skip to content

Commit

Permalink
Disable transform layer for images where it is not needed (to speed-u…
Browse files Browse the repository at this point in the history
…p image processing) (#7449)
  • Loading branch information
Districh-ru authored Jul 23, 2023
1 parent 0bbb429 commit 7f31600
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 87 deletions.
1 change: 1 addition & 0 deletions src/engine/h2d_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ namespace fheroes2
const size_t size = static_cast<size_t>( width * height );
image.resize( width, height );
memcpy( image.image(), data.data() + 4 + 4 + 4 + 4, size );
// TODO: Store in h2d images the 'isSingleLayer' state to disable and skip transform layer for such images.
memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );

image.setPosition( x, y );
Expand Down
15 changes: 15 additions & 0 deletions src/engine/image_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ namespace fheroes2

const uint8_t * dataEnd = data + sizeData;

// The need for a transform layer can only be determined during ICN decoding.
bool noTransformLayer = true;

while ( true ) {
if ( 0 == *data ) { // 0x00 - end of row
imageData += width;
Expand All @@ -347,6 +350,8 @@ namespace fheroes2
++data;
}
else if ( 0x80 > *data ) { // 0x01-0x7F - repeat a pixel N times
noTransformLayer = noTransformLayer && ( static_cast<int32_t>( posX ) >= width );

const uint8_t pixelCount = *data;
++data;

Expand All @@ -362,13 +367,19 @@ namespace fheroes2
posX += pixelCount;
}
else if ( 0x80 == *data ) { // 0x80 - end of image
noTransformLayer = noTransformLayer && ( static_cast<int32_t>( posX ) >= width );

break;
}
else if ( 0xC0 > *data ) { // 0xBF - empty (transparent) pixels
noTransformLayer = false;

posX += *data - 0x80;
++data;
}
else if ( 0xC0 == *data ) { // 0xC0 - transform layer
noTransformLayer = false;

++data;

const uint8_t transformValue = *data;
Expand Down Expand Up @@ -414,6 +425,10 @@ namespace fheroes2
}
}

if ( noTransformLayer ) {
sprite._disableTransformLayer();
}

return sprite;
}

Expand Down
Loading

0 comments on commit 7f31600

Please sign in to comment.