Implemented Crop method, and added tests
This commit is contained in:
@@ -30,6 +30,7 @@ add_executable(Test
|
||||
SwapChannels.cpp
|
||||
Rotate.cpp
|
||||
ConvertColormode.cpp
|
||||
Crop.cpp
|
||||
)
|
||||
|
||||
# Move test images to build dir
|
||||
|
100
Test/Crop.cpp
Normal file
100
Test/Crop.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include <Bmp.h>
|
||||
#include <stdexcept>
|
||||
#include "Catch2.h"
|
||||
|
||||
using namespace Leonetienne::BmpPP;
|
||||
using namespace Eule;
|
||||
|
||||
// Tests that cropping produces the correct result
|
||||
TEST_CASE(__FILE__"/HappyPath", "[Cropping]")
|
||||
{
|
||||
SECTION("RGB") {
|
||||
// Read an image
|
||||
BMP bmp("base_hachi.bmp");
|
||||
|
||||
// Crop it
|
||||
bmp = bmp.Crop(
|
||||
Vector2i(95, 83),
|
||||
Vector2i(149, 239)
|
||||
);
|
||||
|
||||
// Read reference image
|
||||
const BMP reference("base_hachi_cropped.bmp");
|
||||
|
||||
// Assert that they are equal
|
||||
REQUIRE(bmp == reference);
|
||||
}
|
||||
|
||||
SECTION("RGBA") {
|
||||
// Read an image
|
||||
BMP bmp("basea_hachi.bmp");
|
||||
|
||||
// Crop it
|
||||
bmp = bmp.Crop(
|
||||
Vector2i(95, 83),
|
||||
Vector2i(149, 239)
|
||||
);
|
||||
|
||||
// Read reference image
|
||||
const BMP reference("basea_hachi_cropped.bmp");
|
||||
|
||||
// Assert that they are equal
|
||||
REQUIRE(bmp == reference);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Tests that cropping with extreme points works (like, 0,0, widht, height)
|
||||
TEST_CASE(__FILE__"/ExtremePoints", "[Cropping]")
|
||||
{
|
||||
SECTION("Crop includes {0,0}") {
|
||||
// Read an image
|
||||
BMP bmp("base_hachi.bmp");
|
||||
|
||||
// Crop it
|
||||
bmp = bmp.Crop(
|
||||
Vector2i(0, 0),
|
||||
Vector2i(252, 337)
|
||||
);
|
||||
|
||||
// Read reference image
|
||||
const BMP reference("base_hachi_cropped_extreme_topleft.bmp");
|
||||
|
||||
// Assert that they are equal
|
||||
REQUIRE(bmp == reference);
|
||||
}
|
||||
|
||||
SECTION("Crop includes {width, height}") {
|
||||
// Read an image
|
||||
BMP bmp("base_hachi.bmp");
|
||||
|
||||
// Crop it
|
||||
bmp = bmp.Crop(
|
||||
Vector2i(96, 54),
|
||||
bmp.GetDimensions() - Vector2i(96, 54) // As far-right as we can get
|
||||
);
|
||||
|
||||
// Read reference image
|
||||
const BMP reference("base_hachi_cropped_extreme_bottomright.bmp");
|
||||
|
||||
// Assert that they are equal
|
||||
REQUIRE(bmp == reference);
|
||||
}
|
||||
|
||||
SECTION("Crop includes {0, 0, width, height}") {
|
||||
// Read an image
|
||||
BMP bmp("base_hachi.bmp");
|
||||
|
||||
// Crop it (without taking away anything, lol)
|
||||
BMP cropped = bmp.Crop(
|
||||
Vector2i(0, 0),
|
||||
bmp.GetDimensions() // As far-right as we can get
|
||||
);
|
||||
|
||||
// Assert that the cropped image remains the same (as we cropped from 0,0 to width,height)
|
||||
REQUIRE(bmp == cropped);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
BIN
Test/TestAssets/base_hachi.bmp
Normal file
BIN
Test/TestAssets/base_hachi.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 624 KiB |
BIN
Test/TestAssets/base_hachi_cropped.bmp
Normal file
BIN
Test/TestAssets/base_hachi_cropped.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 105 KiB |
BIN
Test/TestAssets/base_hachi_cropped_extreme_bottomright.bmp
Normal file
BIN
Test/TestAssets/base_hachi_cropped_extreme_bottomright.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 430 KiB |
BIN
Test/TestAssets/base_hachi_cropped_extreme_topleft.bmp
Normal file
BIN
Test/TestAssets/base_hachi_cropped_extreme_topleft.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 249 KiB |
BIN
Test/TestAssets/basea_hachi.bmp
Normal file
BIN
Test/TestAssets/basea_hachi.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 830 KiB |
BIN
Test/TestAssets/basea_hachi_cropped.bmp
Normal file
BIN
Test/TestAssets/basea_hachi_cropped.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 139 KiB |
Reference in New Issue
Block a user