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