1 // This may look like C code, but it is really -*- C++ -*-
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
5 // Test Magick::Color classes
14 using namespace Magick;
16 int main( int /*argc*/, char **argv)
19 // Initialize ImageMagick install location for Windows
20 InitializeMagick(*argv);
27 // Verify conversion from named colors as well as ColorRGB constructor
39 // Convert ratios from rgb.txt via value/255
40 struct colorStr colorMap [] =
43 { "green", 0,0.5019607843137256,0 },
53 for ( int i = 0; colorMap[i].color != NULL; i++ )
56 Color color( colorMap[i].color );
57 ColorRGB colorMatch( colorMap[i].red,
60 if ( color != colorMatch )
63 cout << "Line: " << __LINE__ << " Color(\""
64 << colorMap[i].color << "\") is "
69 // printf ("Green: %10.16f\n", color.green());
75 // Test conversion to/from X11-style color specifications
77 const char * colorStrings[] =
85 #if MAGICKCORE_QUANTUM_DEPTH == 8
86 string expectedString = "#AABBCC";
87 #elif MAGICKCORE_QUANTUM_DEPTH == 16
88 string expectedString = "#AAAABBBBCCCC";
89 #elif MAGICKCORE_QUANTUM_DEPTH == 32
90 string expectedString = "#AAAAAAAABBBBBBBBCCCCCCCC";
91 #elif MAGICKCORE_QUANTUM_DEPTH == 64
92 string expectedString = "#AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCC";
94 # error Quantum depth not supported!
97 for ( int i = 0; colorStrings[i] != NULL; ++i )
99 if ( string(Color(colorStrings[i])) != expectedString )
102 cout << "Line: " << __LINE__
103 << " Conversion from " << colorStrings[i]
105 << string(Color(colorStrings[i])) << " rather than "
114 double resolution = 1.0/QuantumRange;
115 if ( resolution < 0.0000001 )
116 resolution = 0.0000001;
117 double max_error = resolution + MagickEpsilon;
119 for( double value = 0; value < 1.0 + MagickEpsilon; value += resolution )
121 ColorGray gray(value);
122 if ( gray.shade() < value - max_error || gray.shade() > value + max_error )
125 cout << "Line: " << __LINE__
128 << " rather than nominal "
136 catch( Exception &error_ )
138 cout << "Caught exception: " << error_.what() << endl;
141 catch( exception &error_ )
143 cout << "Caught exception: " << error_.what() << endl;
149 cout << failures << " failures" << endl;