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

Don't interact with the transform layer if the image is a single layer #8149

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions src/engine/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "image.h"

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <cstdlib>
Expand Down Expand Up @@ -503,7 +502,10 @@ namespace fheroes2
if ( !empty() ) {
const size_t totalSize = static_cast<size_t>( _width ) * _height;
memset( image(), value, totalSize );
memset( transform(), static_cast<uint8_t>( 0 ), totalSize );

if ( !_singleLayer ) {
ihhub marked this conversation as resolved.
Show resolved Hide resolved
memset( transform(), static_cast<uint8_t>( 0 ), totalSize );
}
}
}

Expand Down Expand Up @@ -532,8 +534,11 @@ namespace fheroes2
if ( !empty() ) {
const size_t totalSize = static_cast<size_t>( _width ) * _height;
memset( image(), static_cast<uint8_t>( 0 ), totalSize );
// Set the transform layer to skip all data.
memset( transform(), static_cast<uint8_t>( 1 ), totalSize );

if ( !_singleLayer ) {
// Set the transform layer to skip all data.
memset( transform(), static_cast<uint8_t>( 1 ), totalSize );
}
}
}

Expand All @@ -545,18 +550,18 @@ namespace fheroes2
return;
}

const size_t size = static_cast<size_t>( image._width ) * image._height * 2;
const size_t imageSize = static_cast<size_t>( image._width ) * image._height;

_singleLayer = image._singleLayer;

if ( image._width != _width || image._height != _height ) {
_data.reset( new uint8_t[size] );
_data.reset( new uint8_t[imageSize * 2] );

_width = image._width;
_height = image._height;
}

memcpy( _data.get(), image._data.get(), size );
memcpy( _data.get(), image._data.get(), _singleLayer ? imageSize : imageSize * 2 );
}

Sprite::Sprite( const int32_t width_, const int32_t height_, const int32_t x_ /* = 0 */, const int32_t y_ /* = 0 */ )
Expand Down
7 changes: 7 additions & 0 deletions src/engine/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
***************************************************************************/
#pragma once

#include <cassert>
#include <cstdint>
#include <memory>
#include <utility>
Expand Down Expand Up @@ -63,11 +64,17 @@ namespace fheroes2

uint8_t * transform()
{
// Why do you want to get transform layer from the single-layer image?
assert( !_singleLayer );

return _data.get() + width() * height();
}

const uint8_t * transform() const
{
// Why do you want to get transform layer from the single-layer image?
assert( !_singleLayer );

return _data.get() + width() * height();
}

Expand Down