1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2003
4 // Copyright Dirk Lemstra 2014
5 //
6 // Test STL readImages and writeImages functions and test
7 // image format when reading/writing.
8 //
9
10 #include <Magick++.h>
11 #include <string>
12 #include <iostream>
13 #include <list>
14 #include <vector>
15
16 using namespace std;
17
18 using namespace Magick;
19
main(int,char ** argv)20 int main(int,char ** argv)
21 {
22 int
23 failures=0;
24
25 string
26 srcdir("");
27
28
29 // Initialize ImageMagick install location for Windows
30 InitializeMagick(*argv);
31
32 try
33 {
34 if (getenv("SRCDIR") != 0)
35 srcdir=getenv("SRCDIR");
36
37 //
38 // Test readImages and writeImages
39 //
40 list<Image> first;
41 readImages(&first,srcdir + "test_image_anim.miff");
42
43 if (first.size() != 6)
44 {
45 ++failures;
46 cout << "Line: " << __LINE__
47 << " Read images failed, number of frames is "
48 << first.size()
49 << " rather than 6 as expected." << endl;
50 }
51
52 writeImages(first.begin(),first.end(),"testmagick_anim_out.miff");
53
54 list<Image> second;
55 readImages(&second,"testmagick_anim_out.miff");
56
57 list<Image>::iterator firstIter = first.begin();
58 list<Image>::iterator secondIter = second.begin();
59 while (firstIter != first.end() && secondIter != second.end())
60 {
61 if (firstIter->scene() != secondIter->scene())
62 {
63 ++failures;
64 cout << "Line: " << __LINE__
65 << " Image scene: " << secondIter->scene()
66 << " is not equal to original "
67 << firstIter->scene()
68 << endl;
69 }
70
71 if (firstIter->rows() != secondIter->rows())
72 {
73 ++failures;
74 cout << "Line: " << __LINE__
75 << " Image rows " << secondIter->rows()
76 << " are not equal to original "
77 << firstIter->rows()
78 << endl;
79 }
80
81 if (firstIter->columns() != secondIter->columns())
82 {
83 ++failures;
84 cout << "Line: " << __LINE__
85 << " Image columns " << secondIter->columns()
86 << " are not equal to original "
87 << firstIter->rows()
88 << endl;
89 }
90
91 firstIter++;
92 secondIter++;
93 }
94
95 Image third(*first.begin());
96 third.write("testmagick_anim_out");
97
98 Image fourth;
99 fourth.read("testmagick_anim_out");
100
101 if (fourth.magick() != "MIFF")
102 {
103 ++failures;
104 cout << "Line: " << __LINE__
105 << " Image magick: " << fourth.magick()
106 << " is not equal to MIFF"
107 << endl;
108 }
109
110 third.write("testmagick_anim_out.ico");
111 fourth.read("testmagick_anim_out.ico");
112
113 if (fourth.magick() != "ICO")
114 {
115 ++failures;
116 cout << "Line: " << __LINE__
117 << " Image magick: " << fourth.magick()
118 << " is not equal to ICO"
119 << endl;
120 }
121
122 third.magick("BMP");
123 third.write("testmagick_anim_out.ico");
124 fourth.read("testmagick_anim_out.ico");
125
126 if (fourth.magick() != "BMP")
127 {
128 ++failures;
129 cout << "Line: " << __LINE__
130 << " Image magick: " << fourth.magick()
131 << " is not equal to BMP"
132 << endl;
133 }
134
135 third.write("PDB:testmagick_anim_out.ico");
136 fourth.read("testmagick_anim_out.ico");
137
138 if (fourth.magick() != "PDB")
139 {
140 ++failures;
141 cout << "Line: " << __LINE__
142 << " Image magick: " << fourth.magick()
143 << " is not equal to PDB"
144 << endl;
145 }
146
147 third.magick("");
148 third.write("testmagick_anim_out.ico");
149 fourth.read("testmagick_anim_out.ico");
150
151 if (fourth.magick() != "ICO")
152 {
153 ++failures;
154 cout << "Line: " << __LINE__
155 << " Image magick: " << fourth.magick()
156 << " is not equal to ICO"
157 << endl;
158 }
159 }
160 catch(Exception &error_)
161 {
162 cout << "Caught exception: " << error_.what() << endl;
163 return 1;
164 }
165 catch(exception &error_)
166 {
167 cout << "Caught exception: " << error_.what() << endl;
168 return 1;
169 }
170
171 if (failures)
172 {
173 cout << failures << " failures" << endl;
174 return 1;
175 }
176
177 return 0;
178 }
179
180