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