DGtal  0.9.3
Functions
testColor.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/Color.h"
Include dependency graph for testColor.cpp:

Go to the source code of this file.

Functions

bool testColor ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2014/11/16

Functions for testing class Color.

This file is part of the DGtal library.

Definition in file testColor.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 133 of file testColor.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testColor(), and DGtal::trace.

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
bool testColor()
Definition: testColor.cpp:48
double endBlock()
std::ostream & emphase()
std::ostream & info()

◆ testColor()

bool testColor ( )

Example of a test. To be completed.

Definition at line 48 of file testColor.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::Color::setRGBi(), and DGtal::trace.

Referenced by main().

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 }
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:137
double endBlock()
std::ostream & info()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66