23
23
#include < qgscliptominmaxenhancement.h>
24
24
#include < qgscontrastenhancement.h>
25
25
#include < qgslinearminmaxenhancement.h>
26
+ #include < qgslinearminmaxenhancementwithclip.h>
26
27
27
28
/* * \ingroup UnitTests
28
29
* This is a unit test for the ContrastEnhancements contrast enhancement classes.
@@ -36,7 +37,8 @@ class TestContrastEnhancements: public QObject
36
37
void init () {};// will be called before each testfunction is executed.
37
38
void cleanup () {};// will be called after every testfunction.
38
39
39
- void minMaxEnhancementTest ();
40
+ void clipMinMaxEnhancementTest ();
41
+ void linearMinMaxEnhancementWithClipTest ();
40
42
void linearMinMaxEnhancementTest ();
41
43
private:
42
44
QString mReport ;
@@ -63,20 +65,42 @@ void TestContrastEnhancements::cleanupTestCase()
63
65
}
64
66
65
67
66
- void TestContrastEnhancements::minMaxEnhancementTest ()
68
+ void TestContrastEnhancements::clipMinMaxEnhancementTest ()
67
69
{
70
+ // Clips 0 < x < 10, 240 < X < 256
71
+ // Stretch no stretch is applied
68
72
QgsClipToMinMaxEnhancement myEnhancement (QgsContrastEnhancement::QGS_Byte, 10.0 , 240.0 );
73
+ // Original pixel value 0.0 Should be out of range thus clipped
69
74
QVERIFY (!myEnhancement.isValueInDisplayableRange (0.0 ));
70
- QVERIFY (10.0 == myEnhancement.enhanceValue (0.0 )) ;
71
- QVERIFY (250.0 == myEnhancement.enhanceValue (240.0 )) ;
75
+ // Original pixel value of 10.0 should be scaled to 10.0
76
+ QVERIFY (10.0 == myEnhancement.enhanceValue (10.0 )) ;
77
+ // Original pixel value of 240 should be scaled to 240
78
+ QVERIFY (240.0 == myEnhancement.enhanceValue (240.0 )) ;
72
79
}
80
+
81
+ void TestContrastEnhancements::linearMinMaxEnhancementWithClipTest ()
82
+ {
83
+ // First clips 0 < x < 10, 240 < X < 256
84
+ // Then stretch 10 = 0, 240 = 255 linearly distribute values 10 -> 240 between 0 -> 255
85
+ QgsLinearMinMaxEnhancementWithClip myEnhancement (QgsContrastEnhancement::QGS_Byte, 10.0 , 240.0 );
86
+ // Original pixel value 0.0 Should be out of range thus clipped
87
+ QVERIFY (!myEnhancement.isValueInDisplayableRange (0.0 ));
88
+ // Original pixel value of 10.0 should be scaled to 0.0
89
+ QVERIFY (0.0 == myEnhancement.enhanceValue (10.0 )) ;
90
+ // Original pixel value of 240 should be scaled to 255
91
+ QVERIFY (255.0 == myEnhancement.enhanceValue (240.0 )) ;
92
+ }
93
+
73
94
void TestContrastEnhancements::linearMinMaxEnhancementTest ()
74
95
{
96
+ // Stretch 10 = 0, 240 = 255 linearly distribute values 10 -> 240 between 0 -> 255
75
97
QgsLinearMinMaxEnhancement myEnhancement (QgsContrastEnhancement::QGS_Byte, 10.0 , 240.0 );
76
98
// 0 should be scaled to 10 and not clipped
77
99
QVERIFY (myEnhancement.isValueInDisplayableRange (0.0 ));
78
- QVERIFY (10.0 == myEnhancement.enhanceValue (0.0 )) ;
79
- QVERIFY (250.0 == myEnhancement.enhanceValue (240.0 )) ;
100
+ // Original pixel value of 10.0 should be scaled to 0.0
101
+ QVERIFY (0.0 == myEnhancement.enhanceValue (10.0 )) ;
102
+ // Original pixel value of 240 should be scaled to 255
103
+ QVERIFY (255.0 == myEnhancement.enhanceValue (240.0 )) ;
80
104
}
81
105
QTEST_MAIN ( TestContrastEnhancements )
82
106
#include " moc_testcontrastenhancements.cxx"
0 commit comments