| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | #include <Magick++.h> |
|---|
| 9 | #include <string> |
|---|
| 10 | #include <iostream> |
|---|
| 11 | |
|---|
| 12 | using namespace std; |
|---|
| 13 | |
|---|
| 14 | using namespace Magick; |
|---|
| 15 | |
|---|
| 16 | int main( int , char **argv) |
|---|
| 17 | { |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | InitializeMagick(*argv); |
|---|
| 21 | |
|---|
| 22 | int failures=0; |
|---|
| 23 | |
|---|
| 24 | try { |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | { |
|---|
| 31 | struct colorStr |
|---|
| 32 | { |
|---|
| 33 | const char* color; |
|---|
| 34 | double red; |
|---|
| 35 | double green; |
|---|
| 36 | double blue; |
|---|
| 37 | }; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | struct colorStr colorMap [] = |
|---|
| 41 | { |
|---|
| 42 | { "red", 1,0,0 }, |
|---|
| 43 | { "green", 0,0.5019607843137256,0 }, |
|---|
| 44 | { "blue", 0,0,1 }, |
|---|
| 45 | { "black", 0,0,0 }, |
|---|
| 46 | { "white", 1,1,1 }, |
|---|
| 47 | { "cyan", 0,1,1 }, |
|---|
| 48 | { "magenta", 1,0,1 }, |
|---|
| 49 | { "yellow", 1,1,0 }, |
|---|
| 50 | { NULL, 0,0,0 } |
|---|
| 51 | }; |
|---|
| 52 | |
|---|
| 53 | for ( int i = 0; colorMap[i].color != NULL; i++ ) |
|---|
| 54 | { |
|---|
| 55 | { |
|---|
| 56 | Color color( colorMap[i].color ); |
|---|
| 57 | ColorRGB colorMatch( colorMap[i].red, |
|---|
| 58 | colorMap[i].green, |
|---|
| 59 | colorMap[i].blue ); |
|---|
| 60 | if ( color != colorMatch ) |
|---|
| 61 | { |
|---|
| 62 | ++failures; |
|---|
| 63 | cout << "Line: " << __LINE__ << " Color(\"" |
|---|
| 64 | << colorMap[i].color << "\") is " |
|---|
| 65 | << string(color) |
|---|
| 66 | << " rather than " |
|---|
| 67 | << string(colorMatch) |
|---|
| 68 | << endl; |
|---|
| 69 | |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | { |
|---|
| 77 | const char * colorStrings[] = |
|---|
| 78 | { |
|---|
| 79 | "#ABC", |
|---|
| 80 | "#AABBCC", |
|---|
| 81 | "#AAAABBBBCCCC", |
|---|
| 82 | NULL |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 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"; |
|---|
| 93 | #else |
|---|
| 94 | # error Quantum depth not supported! |
|---|
| 95 | #endif |
|---|
| 96 | |
|---|
| 97 | for ( int i = 0; colorStrings[i] != NULL; ++i ) |
|---|
| 98 | { |
|---|
| 99 | if ( string(Color(colorStrings[i])) != expectedString ) |
|---|
| 100 | { |
|---|
| 101 | ++failures; |
|---|
| 102 | cout << "Line: " << __LINE__ |
|---|
| 103 | << " Conversion from " << colorStrings[i] |
|---|
| 104 | << " is " |
|---|
| 105 | << string(Color(colorStrings[i])) << " rather than " |
|---|
| 106 | << expectedString |
|---|
| 107 | << endl; |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | { |
|---|
| 114 | #undef MagickEpsilon |
|---|
| 115 | #define MagickEpsilon 1.0e-12 |
|---|
| 116 | double resolution = 1.0/QuantumRange; |
|---|
| 117 | double max_error = resolution + MagickEpsilon; |
|---|
| 118 | |
|---|
| 119 | if ( resolution < 0.0001 ) |
|---|
| 120 | resolution = 0.0001; |
|---|
| 121 | |
|---|
| 122 | for( double value = 0; value < 1.0 + MagickEpsilon; value += resolution ) |
|---|
| 123 | { |
|---|
| 124 | ColorGray gray(value); |
|---|
| 125 | if ( gray.shade() < value - max_error || gray.shade() > value + max_error ) |
|---|
| 126 | { |
|---|
| 127 | ++failures; |
|---|
| 128 | cout << "Line: " << __LINE__ |
|---|
| 129 | << " shade is " |
|---|
| 130 | << gray.shade() |
|---|
| 131 | << " rather than nominal" |
|---|
| 132 | << value |
|---|
| 133 | << endl; |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | } |
|---|
| 139 | catch( Exception &error_ ) |
|---|
| 140 | { |
|---|
| 141 | cout << "Caught exception: " << error_.what() << endl; |
|---|
| 142 | return 1; |
|---|
| 143 | } |
|---|
| 144 | catch( exception &error_ ) |
|---|
| 145 | { |
|---|
| 146 | cout << "Caught exception: " << error_.what() << endl; |
|---|
| 147 | return 1; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | if ( failures ) |
|---|
| 151 | { |
|---|
| 152 | cout << failures << " failures" << endl; |
|---|
| 153 | return 1; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | return 0; |
|---|
| 157 | } |
|---|