1
1
/* **************************************************************************
2
2
* fheroes2: https://github.com/ihhub/fheroes2 *
3
- * Copyright (C) 2020 - 2024 *
3
+ * Copyright (C) 2020 - 2025 *
4
4
* *
5
5
* This program is free software; you can redistribute it and/or modify *
6
6
* it under the terms of the GNU General Public License as published by *
@@ -1291,8 +1291,29 @@ namespace fheroes2
1291
1291
1292
1292
void Copy ( const Image & in, Image & out )
1293
1293
{
1294
- out.resize ( in.width (), in.height () );
1295
- Copy ( in, 0 , 0 , out, 0 , 0 , in.width (), in.height () );
1294
+ if ( !out.singleLayer () && !in.singleLayer () ) {
1295
+ // Both images have transform layer. Copy using the assignment operator.
1296
+ out = in;
1297
+ return ;
1298
+ }
1299
+
1300
+ const int32_t width = in.width ();
1301
+ const int32_t height = in.height ();
1302
+
1303
+ out.resize ( width, height );
1304
+
1305
+ // We do a full copy of an image.
1306
+ const size_t size = static_cast <size_t >( width ) * height;
1307
+ if ( out.singleLayer () ) {
1308
+ // Copy only image layer. Input image can be single- or double-layer.
1309
+ memcpy ( out.image (), in.image (), size );
1310
+ }
1311
+ else {
1312
+ assert ( in.singleLayer () );
1313
+ // Copy image layer and set transform to non-transparent mode.
1314
+ memcpy ( out.image (), in.image (), size );
1315
+ memset ( out.transform (), static_cast <uint8_t >( 0 ), size );
1316
+ }
1296
1317
}
1297
1318
1298
1319
void Copy ( const Image & in, int32_t inX, int32_t inY, Image & out, const Rect & outRoi )
@@ -1309,6 +1330,12 @@ namespace fheroes2
1309
1330
const int32_t widthIn = in.width ();
1310
1331
const int32_t widthOut = out.width ();
1311
1332
1333
+ if ( inX == 0 && inY == 0 && outX == 0 && outY == 0 && width == widthIn && width == widthOut && height == in.height () && height == out.height () ) {
1334
+ // Both images have identical width and height and a full copy is requested.
1335
+ Copy ( in, out );
1336
+ return ;
1337
+ }
1338
+
1312
1339
const int32_t offsetInY = inY * widthIn + inX;
1313
1340
const uint8_t * imageInY = in.image () + offsetInY;
1314
1341
0 commit comments