blob: c9f3995c2a410a13edc0b4556ba9fc2bcb37ee7c [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001// This may look like C code, but it is really -*- C++ -*-
2//
3// Copyright Bob Friesenhahn, 1999, 2000, 2003
dirk39930a02014-12-27 11:28:17 +00004// Copyright Dirk Lemstra 2014
cristy3ed852e2009-09-05 21:47:34 +00005//
dirk39930a02014-12-27 11:28:17 +00006// Test STL readImages and writeImages functions and test
7// image format when reading/writing.
cristy3ed852e2009-09-05 21:47:34 +00008//
9
cristy3ed852e2009-09-05 21:47:34 +000010#include <Magick++.h>
11#include <string>
12#include <iostream>
13#include <list>
14#include <vector>
15
16using namespace std;
17
18using namespace Magick;
19
dirk39930a02014-12-27 11:28:17 +000020int main(int,char ** argv)
cristy3ed852e2009-09-05 21:47:34 +000021{
dirk39930a02014-12-27 11:28:17 +000022 int
23 failures=0;
24
25 string
26 srcdir("");
27
cristy3ed852e2009-09-05 21:47:34 +000028
29 // Initialize ImageMagick install location for Windows
30 InitializeMagick(*argv);
31
dirk39930a02014-12-27 11:28:17 +000032 try
33 {
34 if (getenv("SRCDIR") != 0)
35 srcdir=getenv("SRCDIR");
cristy3ed852e2009-09-05 21:47:34 +000036
37 //
38 // Test readImages and writeImages
39 //
cristy3ed852e2009-09-05 21:47:34 +000040 list<Image> first;
dirk39930a02014-12-27 11:28:17 +000041 readImages(&first,srcdir + "test_image_anim.miff");
42
43 if (first.size() != 6)
cristy3ed852e2009-09-05 21:47:34 +000044 {
dirk39930a02014-12-27 11:28:17 +000045 ++failures;
46 cout << "Line: " << __LINE__
47 << " Read images failed, number of frames is "
48 << first.size()
49 << " rather than 6 as expected." << endl;
cristy3ed852e2009-09-05 21:47:34 +000050 }
dirk39930a02014-12-27 11:28:17 +000051
52 writeImages(first.begin(),first.end(),"testmagick_anim_out.miff");
53
cristy3ed852e2009-09-05 21:47:34 +000054 list<Image> second;
dirk39930a02014-12-27 11:28:17 +000055 readImages(&second,"testmagick_anim_out.miff");
56
cristy3ed852e2009-09-05 21:47:34 +000057 list<Image>::iterator firstIter = first.begin();
58 list<Image>::iterator secondIter = second.begin();
dirk39930a02014-12-27 11:28:17 +000059 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")
cristy3ed852e2009-09-05 21:47:34 +0000102 {
dirk39930a02014-12-27 11:28:17 +0000103 ++failures;
104 cout << "Line: " << __LINE__
105 << " Image magick: " << fourth.magick()
106 << " is not equal to MIFF"
107 << endl;
108 }
cristy3ed852e2009-09-05 21:47:34 +0000109
dirk39930a02014-12-27 11:28:17 +0000110 third.write("testmagick_anim_out.ico");
111 fourth.read("testmagick_anim_out.ico");
cristy3ed852e2009-09-05 21:47:34 +0000112
dirk39930a02014-12-27 11:28:17 +0000113 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 }
cristy3ed852e2009-09-05 21:47:34 +0000121
dirk39930a02014-12-27 11:28:17 +0000122 third.magick("BMP");
123 third.write("testmagick_anim_out.ico");
124 fourth.read("testmagick_anim_out.ico");
cristy3ed852e2009-09-05 21:47:34 +0000125
dirk39930a02014-12-27 11:28:17 +0000126 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;
cristy3ed852e2009-09-05 21:47:34 +0000145 }
dirk49ccbc82015-01-31 17:13:04 +0000146
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 }
cristy3ed852e2009-09-05 21:47:34 +0000159 }
dirk39930a02014-12-27 11:28:17 +0000160 catch(Exception &error_)
cristy3ed852e2009-09-05 21:47:34 +0000161 {
162 cout << "Caught exception: " << error_.what() << endl;
163 return 1;
164 }
dirk39930a02014-12-27 11:28:17 +0000165 catch(exception &error_)
cristy3ed852e2009-09-05 21:47:34 +0000166 {
167 cout << "Caught exception: " << error_.what() << endl;
168 return 1;
169 }
170
dirk39930a02014-12-27 11:28:17 +0000171 if (failures)
cristy3ed852e2009-09-05 21:47:34 +0000172 {
173 cout << failures << " failures" << endl;
174 return 1;
175 }
dirk39930a02014-12-27 11:28:17 +0000176
cristy3ed852e2009-09-05 21:47:34 +0000177 return 0;
178}
179