Powered by Pair ImageMagick logo
Image Magick
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

ImageMagick-6.1.1/Magick++/tests/color.cpp File Reference

#include <Magick++.h>
#include <string>
#include <iostream>

Include dependency graph for color.cpp:

Include dependency graph

Go to the source code of this file.

Defines

#define MagickEpsilon   1.0e-12

Functions

int main (int, char **argv)


Define Documentation

#define MagickEpsilon   1.0e-12
 


Function Documentation

int main int  ,
char **  argv
 

Definition at line 16 of file color.cpp.

References Magick::Color, InitializeMagick(), MagickEpsilon, MaxRGB, and Magick::ColorGray::shade().

00017 { 00018 00019 // Initialize ImageMagick install location for Windows 00020 InitializeMagick(*argv); 00021 00022 int failures=0; 00023 00024 try { 00025 00026 // 00027 // Verify conversion from named colors as well as ColorRGB constructor 00028 // 00029 00030 { 00031 struct colorStr 00032 { 00033 const char* color; 00034 double red; 00035 double green; 00036 double blue; 00037 }; 00038 00039 // Convert ratios from rgb.txt via value/255 00040 struct colorStr colorMap [] = 00041 { 00042 { "red", 1,0,0 }, 00043 { "green", 0,0.5019607843137256,0 }, 00044 { "blue", 0,0,1 }, 00045 { "black", 0,0,0 }, 00046 { "white", 1,1,1 }, 00047 { "cyan", 0,1,1 }, 00048 { "magenta", 1,0,1 }, 00049 { "yellow", 1,1,0 }, 00050 { NULL, 0,0,0 } 00051 }; 00052 00053 for ( int i = 0; colorMap[i].color != NULL; i++ ) 00054 { 00055 { 00056 Color color( colorMap[i].color ); 00057 ColorRGB colorMatch( colorMap[i].red, 00058 colorMap[i].green, 00059 colorMap[i].blue ); 00060 if ( color != colorMatch ) 00061 { 00062 ++failures; 00063 cout << "Line: " << __LINE__ << " Color(\"" 00064 << colorMap[i].color << "\") is " 00065 << string(color) 00066 << " rather than " 00067 << string(colorMatch) 00068 << endl; 00069 // printf ("Green: %10.16f\n", color.green()); 00070 } 00071 } 00072 } 00073 } 00074 00075 // Test conversion to/from X11-style color specifications 00076 { 00077 const char * colorStrings[] = 00078 { 00079 "#ABC", 00080 "#AABBCC", 00081 "#AAAABBBBCCCC", 00082 NULL 00083 }; 00084 00085 #if QuantumDepth == 8 00086 string expectedString = "#AABBCC"; 00087 #elif QuantumDepth == 16 00088 string expectedString = "#AAAABBBBCCCC"; 00089 #elif QuantumDepth == 32 00090 string expectedString = "#AAAAAAAABBBBBBBBCCCCCCCC"; 00091 #else 00092 # error Quantum depth not supported! 00093 #endif 00094 00095 for ( int i = 0; colorStrings[i] != NULL; ++i ) 00096 { 00097 if ( string(Color(colorStrings[i])) != expectedString ) 00098 { 00099 ++failures; 00100 cout << "Line: " << __LINE__ 00101 << " Conversion from " << colorStrings[i] 00102 << " is " 00103 << string(Color(colorStrings[i])) << " rather than " 00104 << expectedString 00105 << endl; 00106 } 00107 } 00108 } 00109 00110 // Test ColorGray 00111 { 00112 #undef MagickEpsilon 00113 #define MagickEpsilon 1.0e-12 00114 double resolution = 1.0/MaxRGB; 00115 double max_error = resolution + MagickEpsilon; 00116 00117 if ( resolution < 0.0001 ) 00118 resolution = 0.0001; 00119 00120 for( double value = 0; value < 1.0 + MagickEpsilon; value += resolution ) 00121 { 00122 ColorGray gray(value); 00123 if ( gray.shade() < value - max_error || gray.shade() > value + max_error ) 00124 { 00125 ++failures; 00126 cout << "Line: " << __LINE__ 00127 << " shade is " 00128 << gray.shade() 00129 << " rather than nominal" 00130 << value 00131 << endl; 00132 } 00133 } 00134 } 00135 00136 } 00137 catch( Exception &error_ ) 00138 { 00139 cout << "Caught exception: " << error_.what() << endl; 00140 return 1; 00141 } 00142 catch( exception &error_ ) 00143 { 00144 cout << "Caught exception: " << error_.what() << endl; 00145 return 1; 00146 } 00147 00148 if ( failures ) 00149 { 00150 cout << failures << " failures" << endl; 00151 return 1; 00152 } 00153 00154 return 0; 00155 }

Here is the call graph for this function:


Generated on Mon Oct 25 13:43:25 2004 for ImageMagick by doxygen 1.3.7
ImageMagick Copyright © 2004, ImageMagick Studio LLC