DGtal  0.9.2
testColor.cpp
1 
30 #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  trace.info() << "(" << nbok << "/" << nb << ") "
121  << "red" << std::endl;
122 
123 
124 
125  trace.endBlock();
126 
127  return nbok == nb;
128 }
129 
131 // Standard services - public :
132 
133 int main( int argc, char** argv )
134 {
135  trace.beginBlock ( "Testing class Color" );
136  trace.info() << "Args:";
137  for ( int i = 0; i < argc; ++i )
138  trace.info() << " " << argv[ i ];
139  trace.info() << endl;
140 
141  bool res = testColor(); // && ... other tests
142  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
143  trace.endBlock();
144  return res ? 0 : 1;
145 }
146 // //
void beginBlock(const std::string &keyword="")
Color & setRGBi(const unsigned char aRedValue, const unsigned char aGreenValue, const unsigned char aBlueValue, const unsigned char aAlphaValue)
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66