DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testMagickReader.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include "DGtal/kernel/SpaceND.h"
35 #include "DGtal/kernel/domains/HyperRectDomain.h"
36 #include "DGtal/images/ImageSelector.h"
37 #include "DGtal/io/colormaps/HueShadeColorMap.h"
38 #include "DGtal/io/colormaps/GrayscaleColorMap.h"
39 #include "DGtal/io/colormaps/GradientColorMap.h"
40 #include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
41 
42 #include "DGtal/io/readers/MagickReader.h"
43 #include "DGtal/io/boards/Board2D.h"
44 #include "ConfigTest.h"
45 
46 
48 
49 using namespace std;
50 using namespace DGtal;
51 
53 // Functions for testing class MagickReader.
56 
60 bool testMagickReader()
61 {
62  unsigned int nbok = 0;
63  unsigned int nb = 0;
64 
65  trace.beginBlock ( "Testing MagickReader ..." );
66 
67  typedef SpaceND<2> Space2;
68  typedef HyperRectDomain<Space2> TDomain;
69  typedef TDomain::Vector Vector;
70 
71  //Default image selector = STLVector
73 
74  std::string filename = testPath + "samples/color64.png";
75 
76  trace.info()<<"Importing: "<<filename<<endl;
77 
78  MagickReader<Image> reader;
79  Image img = reader.importImage( filename );
80 
81  nbok += img.isValid() ? 1 : 0;
82  nb++;
83  trace.info() << "(" << nbok << "/" << nb << ") "
84  << "img.isValid() == true"
85  << std::endl;
86 
87  nbok += img.extent() == Image::Vector( 64, 64 ) ? 1 : 0;
88  nb++;
89  trace.info() << "(" << nbok << "/" << nb << ") "
90  << "img.extent() = " << img.extent()
91  << "( == {64,64} )"
92  << std::endl;
93 
94  Board2D board;
95  typedef HueShadeColorMap<unsigned char,2> HueTwice;
96 
97 
99 
100  Display2DFactory::drawImage<HueTwice>(board, img, (unsigned char)0, (unsigned char)255);
101  board.saveSVG("testMagick-export.svg");
102 
103  trace.endBlock();
104 
105  return nbok == nb;
106 }
107 
109 // Standard services - public :
110 
111 int main( int argc, char** argv )
112 {
113  trace.beginBlock ( "Testing class MagickReader" );
114  trace.info() << "Args:";
115  for ( int i = 0; i < argc; ++i )
116  trace.info() << " " << argv[ i ];
117  trace.info() << endl;
118 
119  bool res = testMagickReader(); // && ... other tests
120  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
121  trace.endBlock();
122  return res ? 0 : 1;
123 }
124 // //