cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | // This may look like C code, but it is really -*- C++ -*- |
| 2 | // |
| 3 | // Copyright Bob Friesenhahn, 1999, 2000, 2003 |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 4 | // Copyright Dirk Lemstra 2014 |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5 | // |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 6 | // Test STL readImages and writeImages functions and test |
| 7 | // image format when reading/writing. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 8 | // |
| 9 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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 | |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 20 | int main(int,char ** argv) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | { |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 22 | int |
| 23 | failures=0; |
| 24 | |
| 25 | string |
| 26 | srcdir(""); |
| 27 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 28 | |
| 29 | // Initialize ImageMagick install location for Windows |
| 30 | InitializeMagick(*argv); |
| 31 | |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 32 | try |
| 33 | { |
| 34 | if (getenv("SRCDIR") != 0) |
| 35 | srcdir=getenv("SRCDIR"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 36 | |
| 37 | // |
| 38 | // Test readImages and writeImages |
| 39 | // |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 40 | list<Image> first; |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 41 | readImages(&first,srcdir + "test_image_anim.miff"); |
| 42 | |
| 43 | if (first.size() != 6) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 44 | { |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 45 | ++failures; |
| 46 | cout << "Line: " << __LINE__ |
| 47 | << " Read images failed, number of frames is " |
| 48 | << first.size() |
| 49 | << " rather than 6 as expected." << endl; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 50 | } |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 51 | |
| 52 | writeImages(first.begin(),first.end(),"testmagick_anim_out.miff"); |
| 53 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 54 | list<Image> second; |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 55 | readImages(&second,"testmagick_anim_out.miff"); |
| 56 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 57 | list<Image>::iterator firstIter = first.begin(); |
| 58 | list<Image>::iterator secondIter = second.begin(); |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 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") |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 102 | { |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 103 | ++failures; |
| 104 | cout << "Line: " << __LINE__ |
| 105 | << " Image magick: " << fourth.magick() |
| 106 | << " is not equal to MIFF" |
| 107 | << endl; |
| 108 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 109 | |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 110 | third.write("testmagick_anim_out.ico"); |
| 111 | fourth.read("testmagick_anim_out.ico"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 112 | |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 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 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 121 | |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 122 | third.magick("BMP"); |
| 123 | third.write("testmagick_anim_out.ico"); |
| 124 | fourth.read("testmagick_anim_out.ico"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 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; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 145 | } |
dirk | 49ccbc8 | 2015-01-31 17:13:04 +0000 | [diff] [blame] | 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 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | } |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 160 | catch(Exception &error_) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | { |
| 162 | cout << "Caught exception: " << error_.what() << endl; |
| 163 | return 1; |
| 164 | } |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 165 | catch(exception &error_) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 166 | { |
| 167 | cout << "Caught exception: " << error_.what() << endl; |
| 168 | return 1; |
| 169 | } |
| 170 | |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 171 | if (failures) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 172 | { |
| 173 | cout << failures << " failures" << endl; |
| 174 | return 1; |
| 175 | } |
dirk | 39930a0 | 2014-12-27 11:28:17 +0000 | [diff] [blame] | 176 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |