• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2002, 2003
4 //
5 // Test STL montageImages function
6 //
7 
8 #include <Magick++.h>
9 #include <string>
10 #include <iostream>
11 #include <list>
12 #include <vector>
13 
14 using namespace std;
15 
16 using namespace Magick;
17 
main(int,char **)18 int main( int /*argc*/, char ** /*argv*/)
19 {
20 
21   // Initialize ImageMagick install location for Windows
22   // InitializeMagick(*argv);
23   InitializeMagick("");
24 
25   int failures=0;
26 
27   try {
28 
29     string srcdir("");
30     if(getenv("SRCDIR") != 0)
31       srcdir = getenv("SRCDIR");
32 
33     //
34     // Test montageImages
35     //
36 
37     list<Image> imageList;
38     readImages( &imageList, srcdir + "test_image_anim.miff" );
39 
40     vector<Image> montage;
41     MontageFramed montageOpts;
42 
43     // Default montage
44     montageImages( &montage, imageList.begin(), imageList.end(), montageOpts );
45 
46     {
47       Geometry targetGeometry(128, 126 );
48       if ( montage[0].montageGeometry() != targetGeometry )
49         {
50           ++failures;
51           cout << "Line: " << __LINE__
52                << "  Montage geometry ("
53                << string(montage[0].montageGeometry())
54                << ") is incorrect (expected "
55                << string(targetGeometry)
56                << ")"
57                << endl;
58         }
59     }
60 
61     if ( montage[0].columns() != 768 || montage[0].rows() != 504 )
62       {
63 	++failures;
64 	cout << "Line: " << __LINE__
65 	     << "  Montage columns/rows ("
66 	     << montage[0].columns() << "x"
67 	     << montage[0].rows()
68 	     << ") incorrect. (expected 768x504)" << endl;
69       }
70 
71     // Montage with options set
72     montage.clear();
73     montageOpts.borderColor( "green" );
74     montageOpts.borderWidth( 1 );
75     montageOpts.fileName( "Montage" );
76     montageOpts.frameGeometry( "6x6+3+3" );
77     montageOpts.geometry("50x50+2+2>");
78     montageOpts.gravity( CenterGravity );
79     montageOpts.strokeColor( "yellow" );
80     montageOpts.shadow( true );
81     montageOpts.texture( "granite:" );
82     montageOpts.tile("2x1");
83     montageImages( &montage, imageList.begin(), imageList.end(), montageOpts );
84 
85     if ( montage.size() != 3 )
86       {
87 	++failures;
88 	cout << "Line: " << __LINE__
89 	     << "  Montage images failed, number of montage frames is "
90 	     << montage.size()
91 	     << " rather than 3 as expected." << endl;
92       }
93 
94     {
95       Geometry targetGeometry( 66, 70 );
96       if ( montage[0].montageGeometry() != targetGeometry )
97         {
98           ++failures;
99           cout << "Line: " << __LINE__
100                << "  Montage geometry ("
101                << string(montage[0].montageGeometry())
102                << ") is incorrect (expected "
103                << string(targetGeometry)
104                << ")."
105                << endl;
106         }
107     }
108 
109     if ( montage[0].columns() != 136 || montage[0].rows() != 70 )
110       {
111 	++failures;
112 	cout << "Line: " << __LINE__
113 	     << "  Montage columns/rows ("
114 	     << montage[0].columns() << "x"
115 	     << montage[0].rows()
116 	     << ") incorrect. (expected 136x70)" << endl;
117       }
118   }
119 
120   catch( Exception &error_ )
121     {
122       cout << "Caught exception: " << error_.what() << endl;
123       return 1;
124     }
125   catch( exception &error_ )
126     {
127       cout << "Caught exception: " << error_.what() << endl;
128       return 1;
129     }
130 
131   if ( failures )
132     {
133       cout << failures << " failures" << endl;
134       return 1;
135     }
136 
137   return 0;
138 }
139 
140