Ejemplo n.º 1
0
MontageFramed get_montage_opts(int param_num, ETERM* msg) {
  MontageFramed rval;

  // defaults
  rval.borderColor( "green" );
  rval.borderWidth( 1 );
  rval.compose( OverCompositeOp );
  rval.fileName( "Montage" );
  //rval.frameGeometry( "6x6+3+3" );
  //rval.geometry("50x50+2+2>");
  rval.gravity( CenterGravity );
  rval.penColor( "yellow" );
  rval.shadow( true );
  rval.texture( "granite:" );
  rval.tile("8x6");

  ETERM *list = erl_element(param_num, msg);
  if (!ERL_IS_LIST(list)) {
    cout << "list is not a list" << endl;
  }
  for (ETERM *hd = erl_hd(list); hd != NULL; hd = erl_hd(list)) {
    string opt((const char*) ERL_ATOM_PTR(erl_element(1, hd)));
    ETERM *param = erl_element(2, hd);
    if (opt == "bordercolor") {
      string color((const char*) erl_iolist_to_string(param));
      rval.borderColor(color);
    }
    else if (opt == "borderWidth") {
      rval.borderWidth(ERL_INT_VALUE(param) );
    }
    else if (opt == "compose") {
      string comp_op((const char*) erl_iolist_to_string(param));
      rval.compose( get_composite(comp_op));
    }
    else if (opt == "fillColor") {
      string color((const char*) erl_iolist_to_string(param));
      rval.fillColor(color);
    }
    else if (opt == "font") {
      string font((const char*) erl_iolist_to_string(param));
      rval.font( font );
    }
    else if (opt == "frameGeometry") {
      string geometry((const char*) erl_iolist_to_string(param));
      rval.frameGeometry( geometry );
    }
    else if (opt == "geometry") {
      string geometry((const char*) erl_iolist_to_string(param));
      rval.geometry( geometry );
    }
    else if (opt == "gravity") {
      string gravity_op((const char*) erl_iolist_to_string(param));
      rval.gravity( get_gravity_type(opt) );
    }
    else if (opt == "penColor") {
      string color((const char*) erl_iolist_to_string(param));
      rval.penColor( color );
    }
    else if (opt == "pointSize") {
      rval.pointSize(ERL_INT_VALUE(param) );
    }
    else if (opt == "shadow") {
      rval.shadow(ERL_INT_VALUE(param) );
    }
    else if (opt == "texture") {
      string texture((const char*) erl_iolist_to_string(param));
      rval.texture( texture );
    }
    else if (opt == "tile") {
      string tile((const char*) erl_iolist_to_string(param));
      rval.tile(tile);
    }
    list = erl_tl(list);
  }
  return rval;
}
Ejemplo n.º 2
0
int main( int /*argc*/, char **argv)
{

  // Initialize ImageMagick install location for Windows
  // InitializeMagick(*argv);
  InitializeMagick("");
  
  int failures=0;

  try {

    string srcdir("");
    if(getenv("SRCDIR") != 0)
      srcdir = getenv("SRCDIR");

    //
    // Test montageImages
    //

    list<Image> imageList;
    readImages( &imageList, srcdir + "test_image_anim.miff" );

    vector<Image> montage;
    MontageFramed montageOpts;

    // Default montage
    montageImages( &montage, imageList.begin(), imageList.end(), montageOpts );

    {
      Geometry targetGeometry(128, 126 );
      if ( montage[0].montageGeometry() != targetGeometry )
        {
          ++failures;
          cout << "Line: " << __LINE__ 
               << "  Montage geometry ("
               << string(montage[0].montageGeometry())
               << ") is incorrect (expected "
               << string(targetGeometry)
               << ")"
               << endl;
        }
    }

    if ( montage[0].columns() != 768 || montage[0].rows() != 504 )
      {
	++failures;
	cout << "Line: " << __LINE__ 
	     << "  Montage columns/rows ("
	     << montage[0].columns() << "x"
	     << montage[0].rows()
	     << ") incorrect. (expected 768x504)" << endl;
      }

    // Montage with options set
    montage.clear();
    montageOpts.borderColor( "green" );
    montageOpts.borderWidth( 1 );
    montageOpts.compose( OverCompositeOp );
    montageOpts.fileName( "Montage" );
    montageOpts.frameGeometry( "6x6+3+3" );
    montageOpts.geometry("50x50+2+2>");
    montageOpts.gravity( CenterGravity );
    montageOpts.penColor( "yellow" );
    montageOpts.shadow( true );
    montageOpts.texture( "granite:" );
    montageOpts.tile("2x1");
    montageImages( &montage, imageList.begin(), imageList.end(), montageOpts );

    if ( montage.size() != 3 )
      {
	++failures;
	cout << "Line: " << __LINE__ 
	     << "  Montage images failed, number of montage frames is "
	     << montage.size()
	     << " rather than 3 as expected." << endl;
      }

    {
      Geometry targetGeometry( 66, 70 );
      if ( montage[0].montageGeometry() != targetGeometry )
        {
          ++failures;
          cout << "Line: " << __LINE__ 
               << "  Montage geometry ("
               << string(montage[0].montageGeometry())
               << ") is incorrect (expected "
               << string(targetGeometry)
               << ")."
               << endl;
        }
    }

    if ( montage[0].columns() != 136 || montage[0].rows() != 70 )
      {
	++failures;
	cout << "Line: " << __LINE__ 
	     << "  Montage columns/rows ("
	     << montage[0].columns() << "x"
	     << montage[0].rows()
	     << ") incorrect. (expected 136x70)" << endl;
      }
  }

  catch( Exception &error_ )
    {
      cout << "Caught exception: " << error_.what() << endl;
      return 1;
    }
  catch( exception &error_ )
    {
      cout << "Caught exception: " << error_.what() << endl;
      return 1;
    }

  if ( failures )
    {
      cout << failures << " failures" << endl;
      return 1;
    }
  
  return 0;
}