13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// This may look like C code, but it is really -*- C++ -*-
23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//
33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// Copyright Bob Friesenhahn, 1999, 2000, 2002, 2003
43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//
53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// Test STL montageImages function
63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//
73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <Magick++.h>
93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <string>
103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <iostream>
113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <list>
123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <vector>
133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
143ed852eea50f9d4cd633efb8c2b054b8e33c253cristyusing namespace std;
153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
163ed852eea50f9d4cd633efb8c2b054b8e33c253cristyusing namespace Magick;
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
183ed852eea50f9d4cd633efb8c2b054b8e33c253cristyint main( int /*argc*/, char ** /*argv*/)
193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  // Initialize ImageMagick install location for Windows
223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  // InitializeMagick(*argv);
233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  InitializeMagick("");
243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int failures=0;
263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  try {
283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    string srcdir("");
303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if(getenv("SRCDIR") != 0)
313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      srcdir = getenv("SRCDIR");
323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    //
343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Test montageImages
353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    //
363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    list<Image> imageList;
383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    readImages( &imageList, srcdir + "test_image_anim.miff" );
393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    vector<Image> montage;
413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    MontageFramed montageOpts;
423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Default montage
443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageImages( &montage, imageList.begin(), imageList.end(), montageOpts );
453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
477330f7ff64955819ef91a00c8d6669b74e326bf2cristy      Geometry targetGeometry(128, 126 );
483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ( montage[0].montageGeometry() != targetGeometry )
493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ++failures;
513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          cout << "Line: " << __LINE__
523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << "  Montage geometry ("
533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << string(montage[0].montageGeometry())
543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << ") is incorrect (expected "
553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << string(targetGeometry)
563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << ")"
573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << endl;
583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
617330f7ff64955819ef91a00c8d6669b74e326bf2cristy    if ( montage[0].columns() != 768 || montage[0].rows() != 504 )
623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	++failures;
643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	cout << "Line: " << __LINE__
653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << "  Montage columns/rows ("
663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << montage[0].columns() << "x"
673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << montage[0].rows()
683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << ") incorrect. (expected 768x504)" << endl;
693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Montage with options set
723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montage.clear();
733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.borderColor( "green" );
743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.borderWidth( 1 );
753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.fileName( "Montage" );
763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.frameGeometry( "6x6+3+3" );
773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.geometry("50x50+2+2>");
783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.gravity( CenterGravity );
79ee1f0aee35021f89c4ee765057dce002175e1d4adirk    montageOpts.strokeColor( "yellow" );
803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.shadow( true );
813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.texture( "granite:" );
823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageOpts.tile("2x1");
833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    montageImages( &montage, imageList.begin(), imageList.end(), montageOpts );
843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ( montage.size() != 3 )
863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	++failures;
883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	cout << "Line: " << __LINE__
893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << "  Montage images failed, number of montage frames is "
903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << montage.size()
913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << " rather than 3 as expected." << endl;
923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
957330f7ff64955819ef91a00c8d6669b74e326bf2cristy      Geometry targetGeometry( 66, 70 );
963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ( montage[0].montageGeometry() != targetGeometry )
973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ++failures;
993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          cout << "Line: " << __LINE__
1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << "  Montage geometry ("
1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << string(montage[0].montageGeometry())
1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << ") is incorrect (expected "
1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << string(targetGeometry)
1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << ")."
1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               << endl;
1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1097330f7ff64955819ef91a00c8d6669b74e326bf2cristy    if ( montage[0].columns() != 136 || montage[0].rows() != 70 )
1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
1113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	++failures;
1123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	cout << "Line: " << __LINE__
1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << "  Montage columns/rows ("
1143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << montage[0].columns() << "x"
1153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << montage[0].rows()
1163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy	     << ") incorrect. (expected 136x70)" << endl;
1173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
1183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
1193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  catch( Exception &error_ )
1213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      cout << "Caught exception: " << error_.what() << endl;
1233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return 1;
1243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
1253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  catch( exception &error_ )
1263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      cout << "Caught exception: " << error_.what() << endl;
1283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return 1;
1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ( failures )
1323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      cout << failures << " failures" << endl;
1343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return 1;
1353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
1363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return 0;
1383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
140