Add wxImage Change{Saturation,Brightness,HSV,Lightness}()

Add more functions for manipulating wxImage colours.

Show using them in the same and add new unit tests for them.

This is a squashed commit of branch 'tomay3000/image-lightness'.

Closes https://github.com/wxWidgets/wxWidgets/pull/2310
This commit is contained in:
Tomay
2021-05-01 14:03:04 +02:00
committed by Vadim Zeitlin
parent 3217a4e8a2
commit 0e39566b3a
20 changed files with 626 additions and 133 deletions

View File

@@ -2200,6 +2200,55 @@ TEST_CASE("wxImage::XPM", "[image][xpm]")
CHECK( wxIcon(dummy_xpm).IsOk() );
}
TEST_CASE("wxImage::ChangeColours", "[image]")
{
wxImage original;
REQUIRE(original.LoadFile("image/toucan.png", wxBITMAP_TYPE_PNG));
wxImage test;
wxImage expected;
test = original;
test.RotateHue(0.538);
REQUIRE(expected.LoadFile("image/toucan_hue_0.538.png", wxBITMAP_TYPE_PNG));
CHECK_THAT(test, RGBSameAs(expected));
test = original;
test.ChangeSaturation(-0.41);
REQUIRE(expected.LoadFile("image/toucan_sat_-0.41.png", wxBITMAP_TYPE_PNG));
CHECK_THAT(test, RGBSameAs(expected));
test = original;
test.ChangeBrightness(-0.259);
REQUIRE(expected.LoadFile("image/toucan_bright_-0.259.png", wxBITMAP_TYPE_PNG));
CHECK_THAT(test, RGBSameAs(expected));
test = original;
test.ChangeHSV(0.538, -0.41, -0.259);
REQUIRE(expected.LoadFile("image/toucan_hsv_0.538_-0.41_-0.259.png", wxBITMAP_TYPE_PNG));
CHECK_THAT(test, RGBSameAs(expected));
test = original;
test = test.ChangeLightness(46);
REQUIRE(expected.LoadFile("image/toucan_light_46.png", wxBITMAP_TYPE_PNG));
CHECK_THAT(test, RGBSameAs(expected));
test = original;
test = test.ConvertToDisabled(240);
REQUIRE(expected.LoadFile("image/toucan_dis_240.png", wxBITMAP_TYPE_PNG));
CHECK_THAT(test, RGBSameAs(expected));
test = original;
test = test.ConvertToGreyscale();
REQUIRE(expected.LoadFile("image/toucan_grey.png", wxBITMAP_TYPE_PNG));
CHECK_THAT(test, RGBSameAs(expected));
test = original;
test = test.ConvertToMono(255, 255, 255);
REQUIRE(expected.LoadFile("image/toucan_mono_255_255_255.png", wxBITMAP_TYPE_PNG));
CHECK_THAT(test, RGBSameAs(expected));
}
/*
TODO: add lots of more tests to wxImage functions
*/