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 |
| 4 | // |
| 5 | // Test STL readImages and writeImages functions |
| 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 | |
| 18 | int main( int /*argc*/, char ** argv) |
| 19 | { |
| 20 | |
| 21 | // Initialize ImageMagick install location for Windows |
| 22 | InitializeMagick(*argv); |
| 23 | |
| 24 | int failures=0; |
| 25 | |
| 26 | try { |
| 27 | |
| 28 | string srcdir(""); |
| 29 | if(getenv("SRCDIR") != 0) |
| 30 | srcdir = getenv("SRCDIR"); |
| 31 | |
| 32 | // |
| 33 | // Test readImages and writeImages |
| 34 | // |
| 35 | |
| 36 | list<Image> first; |
| 37 | readImages( &first, srcdir + "test_image_anim.miff" ); |
| 38 | |
| 39 | if ( first.size() != 6 ) |
| 40 | { |
| 41 | ++failures; |
| 42 | cout << "Line: " << __LINE__ |
| 43 | << " Read images failed, number of frames is " |
| 44 | << first.size() |
| 45 | << " rather than 6 as expected." << endl; |
| 46 | } |
| 47 | |
| 48 | writeImages( first.begin(), first.end(), "testmagick_anim_out.miff" ); |
| 49 | |
| 50 | list<Image> second; |
| 51 | readImages( &second, "testmagick_anim_out.miff" ); |
| 52 | |
| 53 | list<Image>::iterator firstIter = first.begin(); |
| 54 | list<Image>::iterator secondIter = second.begin(); |
| 55 | while( firstIter != first.end() && secondIter != second.end() ) |
| 56 | { |
| 57 | |
| 58 | if ( firstIter->scene() != secondIter->scene() ) |
| 59 | { |
| 60 | ++failures; |
| 61 | cout << "Line: " << __LINE__ |
| 62 | << " Image scene: " << secondIter->scene() |
| 63 | << " is not equal to original " |
| 64 | << firstIter->scene() |
| 65 | << endl; |
| 66 | } |
| 67 | |
| 68 | if ( firstIter->rows() != secondIter->rows() ) |
| 69 | { |
| 70 | ++failures; |
| 71 | cout << "Line: " << __LINE__ |
| 72 | << " Image rows " << secondIter->rows() |
| 73 | << " are not equal to original " |
| 74 | << firstIter->rows() |
| 75 | << endl; |
| 76 | } |
| 77 | |
| 78 | if ( firstIter->columns() != secondIter->columns() ) |
| 79 | { |
| 80 | ++failures; |
| 81 | cout << "Line: " << __LINE__ |
| 82 | << " Image columns " << secondIter->columns() |
| 83 | << " are not equal to original " |
| 84 | << firstIter->rows() |
| 85 | << endl; |
| 86 | } |
| 87 | |
| 88 | firstIter++; |
| 89 | secondIter++; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | catch( Exception &error_ ) |
| 94 | { |
| 95 | cout << "Caught exception: " << error_.what() << endl; |
| 96 | return 1; |
| 97 | } |
| 98 | catch( exception &error_ ) |
| 99 | { |
| 100 | cout << "Caught exception: " << error_.what() << endl; |
| 101 | return 1; |
| 102 | } |
| 103 | |
| 104 | if ( failures ) |
| 105 | { |
| 106 | cout << failures << " failures" << endl; |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |