DGtal  1.5.beta
testColor.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "ConfigTest.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/io/Color.h"
37 
38 using namespace std;
39 using namespace DGtal;
40 
42 // Functions for testing class Color.
44 
48 bool testColor()
49 {
50  unsigned int nbok = 0;
51  unsigned int nb = 0;
52 
53  trace.beginBlock ( "Testing Color ..." );
54 
55  Color b(0,0,0,255);
56  Color g(32,32,32,255);
57  Color gg(64,64,64,255);
58  Color w(255,255,255,255);
59 
60  trace.info() << " B+G = g "<< b+g<<std::endl;
61  nbok += ((b+g)==g) ? 1 : 0;
62  nb++;
63  trace.info() << "(" << nbok << "/" << nb << ") "
64  << "add" << std::endl;
65 
66  trace.info() << " g+g = gg "<< g*2<< " expected ="<<gg<<std::endl;
67  nbok += ((g+g)==gg) ? 1 : 0;
68  nb++;
69  trace.info() << "(" << nbok << "/" << nb << ") "
70  << "add (bis)" << std::endl;
71 
72  trace.info() << " W+W = w "<< w+w<<std::endl;
73  nbok += ((w+w)==w) ? 1 : 0;
74  nb++;
75  trace.info() << "(" << nbok << "/" << nb << ") "
76  << "max " << std::endl;
77 
78  trace.info() << " g*2 = gg "<< g*2<< " expected ="<<gg<<std::endl;
79  nbok += ((g*2)==gg) ? 1 : 0;
80  nb++;
81  trace.info() << "(" << nbok << "/" << nb << ") "
82  << "coeff" << std::endl;
83 
84  trace.info() << " 1.*red = red "<< 1.0*Color::Red<< " expected ="<<Color::Red<<std::endl;
85  nbok += ((1.0*Color::Red)==Color::Red) ? 1 : 0;
86  nb++;
87  trace.info() << "(" << nbok << "/" << nb << ") "
88  << "coeff" << std::endl;
89 
90  trace.info() << " 2*g = gg "<< 2.0*g<< " expected ="<<gg<<std::endl;
91  nbok += ((2*g)==gg) ? 1 : 0;
92  nb++;
93  trace.info() << "(" << nbok << "/" << nb << ") "
94  << "coeff" << std::endl;
95 
96  //Checking alpha channel
97  Color a(0,0,0,64);
98  Color aa(0,0,0,32);
99  Color c = a+aa;
100 #ifdef COLOR_WITH_ALPHA_ARITH
101  trace.info() << " a+aa = "<< a+aa<<std::endl;
102  nbok += (c == Color(0,0,0,96)) ? 1 : 0;
103  nb++;
104  trace.info() << "(" << nbok << "/" << nb << ") "
105  << "alpha arith (enabled)" << std::endl;
106 #else
107  trace.info() << " a+aa = "<< a+aa<<std::endl;
108  nbok += (c == Color(0,0,0,64)) ? 1 : 0;
109  nb++;
110  trace.info() << "(" << nbok << "/" << nb << ") "
111  << "alpha arith (disabled)" << std::endl;
112 #endif
113 
114  Color val;
115  val.setRGBi(0,0,0,255);
116  val += 1.0*Color::Red;
117  trace.info() << " val == Color::Red "<< val<<std::endl;
118  nbok += (val==Color::Red) ? 1 : 0;
119  nb++;
120 
121  trace.info() << "(" << nbok << "/" << nb << ") "
122  << "red" << std::endl;
123 
124  // Test Color is trivialy_copiable
125  const auto is_trivially_copyable_ = std::is_trivially_copyable<Color>::value;
126  trace.info() << "is_trivially_copyable: "<< is_trivially_copyable_ <<std::endl;
127  nbok += (is_trivially_copyable_) ? 1 : 0;
128  nb++;
129  trace.info() << "(" << nbok << "/" << nb << ") "
130  << "is_trivially_copyable" << std::endl;
131 
132  trace.endBlock();
133 
134  return nbok == nb;
135 }
136 
138 // Standard services - public :
139 
140 int main( int argc, char** argv )
141 {
142  trace.beginBlock ( "Testing class Color" );
143  trace.info() << "Args:";
144  for ( int i = 0; i < argc; ++i )
145  trace.info() << " " << argv[ i ];
146  trace.info() << endl;
147 
148  bool res = testColor(); // && ... other tests
149  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
150  trace.endBlock();
151  return res ? 0 : 1;
152 }
153 // //
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Color & setRGBi(const unsigned char aRedValue, const unsigned char aGreenValue, const unsigned char aBlueValue, const unsigned char aAlphaValue=255)
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
int main(int argc, char **argv)
Definition: testColor.cpp:140
bool testColor()
Definition: testColor.cpp:48