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