Ejemplo n.º 1
0
int main( int /*argc*/, char ** argv)
{

  // Initialize ImageMagick install location for Windows
  InitializeMagick(*argv);
  
  try {
    
    string srcdir("");
    if(getenv("SRCDIR") != 0)
      srcdir = getenv("SRCDIR");
    
    list<Image> montage;

    {
      //
      // Read model & smile image.
      //
      cout << "Read images ..." << endl;

      Image model( srcdir + "model.miff" );
      model.label( "Magick++" );
      model.borderColor( "black" );
      model.backgroundColor( "black" );
    
      Image smile( srcdir + "smile.miff" );
      smile.label( "Smile" );
      smile.borderColor( "black" );
    
      //
      // Create image stack.
      //
      cout << "Creating thumbnails..." << endl;
    
      // Construct initial list containing five copies of a null image
      Image null;
      null.size( Geometry(70,70) );
      null.read( "NULL:black" );
      list<Image> images( 5, null );
    
      Image example = model;
    
      // Each of the following follow the pattern
      //  1. obtain reference to (own copy of) image
      //  2. apply label to image
      //  3. apply operation to image
      //  4. append image to container

      cout << "  add noise ..." << endl;
      example.label( "Add Noise" );
      example.addNoise( LaplacianNoise );
      images.push_back( example );

      cout << "  annotate ..." << endl;
      example = model;
      example.label( "Annotate" );
      example.density( "72x72" );
      example.fontPointsize( 18 );
      example.strokeColor( Color() );
      example.fillColor( "goldenrod" );
      example.annotate( "Magick++", "+0+20", NorthGravity );
      images.push_back( example );

      cout << "  blur ..." << endl;
      example = model;
      example.label( "Blur" );
      example.blur( 0, 1.5 );
      images.push_back( example );

      cout << "  border ..." << endl;
      example = model;
      example.label( "Border" );
      example.borderColor( "goldenrod" );
      example.border( Geometry(6,6) );
      images.push_back( example );

      cout << "  channel ..." << endl;
      example = model;
      example.label( "Channel" );
      example.channel( RedChannel );
      images.push_back( example );

      cout << "  charcoal ..." << endl;
      example = model;
      example.label( "Charcoal" );
      example.charcoal( );
      images.push_back( example );

      cout << "  composite ..." << endl;
      example = model;
      example.label( "Composite" );
      example.composite( smile, "+35+65", OverCompositeOp);
      images.push_back( example );

      cout << "  contrast ..." << endl;
      example = model;
      example.label( "Contrast" );
      example.contrast( false );
      images.push_back( example );

      cout << "  convolve ..." << endl;
      example = model;
      example.label( "Convolve" );
      {
        // 3x3 matrix
        const double kernel[] = { 1, 1, 1, 1, 4, 1, 1, 1, 1 };
        example.convolve( 3, kernel );
      }
      images.push_back( example );

      cout << "  crop ..." << endl;
      example = model;
      example.label( "Crop" );
      example.crop( "80x80+25+50" );
      images.push_back( example );

      cout << "  despeckle ..." << endl;
      example = model;
      example.label( "Despeckle" );
      example.despeckle( );
      images.push_back( example );

      cout << "  draw ..." << endl;
      example = model;
      example.label( "Draw" );
      example.fillColor(Color());
      example.strokeColor( "goldenrod" );
      example.strokeWidth( 2 );
      example.draw( DrawableCircle( 60,90, 60,120 ) );
      images.push_back( example );

      cout << "  edge ..." << endl;
      example = model;
      example.label( "Detect Edges" );
      example.edge( );
      images.push_back( example );

      cout << "  emboss ..." << endl;
      example = model;
      example.label( "Emboss" );
      example.emboss( );
      images.push_back( example );

      cout << "  equalize ..." << endl;
      example = model;
      example.label( "Equalize" );
      example.equalize( );
      images.push_back( example );
    
      cout << "  explode ..." << endl;
      example = model;
      example.label( "Explode" );
      example.backgroundColor( "#000000FF" );
      example.implode( -1 );
      images.push_back( example );

      cout << "  flip ..." << endl;
      example = model;
      example.label( "Flip" );
      example.flip( );
      images.push_back( example );

      cout << "  flop ..." << endl;
      example = model;
      example.label( "Flop" );
      example.flop();
      images.push_back( example );

      cout << "  frame ..." << endl;
      example = model;
      example.label( "Frame" );
      example.frame( );
      images.push_back( example );

      cout << "  gamma ..." << endl;
      example = model;
      example.label( "Gamma" );
      example.gamma( 1.6 );
      images.push_back( example );

      cout << "  gaussian blur ..." << endl;
      example = model;
      example.label( "Gaussian Blur" );
      example.gaussianBlur( 0.0, 1.5 );
      images.push_back( example );
    
      cout << "  gradient ..." << endl;
      Image gradient;
      gradient.size( "130x194" );
      gradient.read( "gradient:#20a0ff-#ffff00" );
      gradient.label( "Gradient" );
      images.push_back( gradient );
    
      cout << "  grayscale ..." << endl;
      example = model;
      example.label( "Grayscale" );
      example.quantizeColorSpace( GRAYColorspace );
      example.quantize( );
      images.push_back( example );
    
      cout << "  implode ..." << endl;
      example = model;
      example.label( "Implode" );
      example.implode( 0.5 );
      images.push_back( example );

      cout << "  level ..." << endl;
      example = model;
      example.label( "Level" );
      example.level( 0.20*QuantumRange, 0.90*QuantumRange, 1.20 );
      images.push_back( example );

      cout << "  level red channel ..." << endl;
      example = model;
      example.label( "Level Red" );
      example.levelChannel( RedChannel, 0.20*QuantumRange, 0.90*QuantumRange, 1.20 );
      images.push_back( example );

      cout << "  median filter ..." << endl;
      example = model;
      example.label( "Median Filter" );
      example.medianFilter( );
      images.push_back( example );

      cout << "  modulate ..." << endl;
      example = model;
      example.label( "Modulate" );
      example.modulate( 110, 110, 110 );
      images.push_back( example );

      cout << "  monochrome ..." << endl;
      example = model;
      example.label( "Monochrome" );
      example.quantizeColorSpace( GRAYColorspace );
      example.quantizeColors( 2 );
      example.quantizeDither( false );
      example.quantize( );
      images.push_back( example );
    
      cout << "  negate ..." << endl;
      example = model;
      example.label( "Negate" );
      example.negate( );
      images.push_back( example );
    
      cout << "  normalize ..." << endl;
      example = model;
      example.label( "Normalize" );
      example.normalize( );
      images.push_back( example );
    
      cout << "  oil paint ..." << endl;
      example = model;
      example.label( "Oil Paint" );
      example.oilPaint( );
      images.push_back( example );
    
      cout << "  plasma ..." << endl;
      Image plasma;
      plasma.size( "130x194" );
      plasma.read( "plasma:fractal" );
      plasma.label( "Plasma" );
      images.push_back( plasma );
    
      cout << "  quantize ..." << endl;
      example = model;
      example.label( "Quantize" );
      example.quantize( );
      images.push_back( example );
    
      cout << "  raise ..." << endl;
      example = model;
      example.label( "Raise" );
      example.raise( );
      images.push_back( example );
    
      cout << "  reduce noise ..." << endl;
      example = model;
      example.label( "Reduce Noise" );
      example.reduceNoise( );
      images.push_back( example );
    
      cout << "  resize ..." << endl;
      example = model;
      example.label( "Resize" );
      example.zoom( "50%" );
      images.push_back( example );
    
      cout << "  roll ..." << endl;
      example = model;
      example.label( "Roll" );
      example.roll( "+20+10" );
      images.push_back( example );
    
      cout << "  rotate ..." << endl;
      example = model;
      example.label( "Rotate" );
      example.rotate( 45 );
      example.transparent( "black" );
      images.push_back( example );

      cout << "  scale ..." << endl;
      example = model;
      example.label( "Scale" );
      example.scale( "60%" );
      images.push_back( example );
    
      cout << "  segment ..." << endl;
      example = model;
      example.label( "Segment" );
      example.segment( );
      images.push_back( example );
    
      cout << "  shade ..." << endl;
      example = model;
      example.label( "Shade" );
      example.shade( 30, 30, false );
      images.push_back( example );
    
      cout << "  sharpen ..." << endl;
      example = model;
      example.label("Sharpen");
      example.sharpen( 0.0, 1.0 );
      images.push_back( example );
    
      cout << "  shave ..." << endl;
      example = model;
      example.label("Shave");
      example.shave( Geometry( 10, 10) );
      images.push_back( example );
    
      cout << "  shear ..." << endl;
      example = model;
      example.label( "Shear" );
      example.shear( 45, 45 );
      example.transparent( "black" );
      images.push_back( example );
    
      cout << "  spread ..." << endl;
      example = model;
      example.label( "Spread" );
      example.spread( );
      images.push_back( example );
    
      cout << "  solarize ..." << endl;
      example = model;
      example.label( "Solarize" );
      example.solarize( );
      images.push_back( example );
    
      cout << "  swirl ..." << endl;
      example = model;
      example.backgroundColor( "#000000FF" );
      example.label( "Swirl" );
      example.swirl( 90 );
      images.push_back( example );
    
      cout << "  unsharp mask ..." << endl;
      example = model;
      example.label( "Unsharp Mask" );
      //           radius_, sigma_, amount_, threshold_
      example.unsharpmask( 0.0, 1.0, 1.0, 0.05);
      images.push_back( example );
    
      cout << "  wave ..." << endl;
      example = model;
      example.label( "Wave" );
      example.matte( true );
      example.backgroundColor( "#000000FF" );
      example.wave( 25, 150 );
      images.push_back( example );
    
      //
      // Create image montage.
      //
      cout <<  "Montage images..." << endl;

      for_each( images.begin(), images.end(), strokeColorImage( Color("#600") ) );

      MontageFramed montageOpts;
      montageOpts.geometry( "130x194+10+5>" );
      montageOpts.gravity( CenterGravity );
      montageOpts.borderColor( "green" );
      montageOpts.borderWidth( 1 );
      montageOpts.tile( "5x12" );
      montageOpts.compose( OverCompositeOp );
      montageOpts.backgroundColor( "#ffffff" );
      montageOpts.pointSize( 18 );
      montageOpts.fillColor( "#600" );
      montageOpts.strokeColor( Color() );
      montageOpts.compose(OverCompositeOp);
      montageOpts.fileName( "Magick++ Demo" );
      montageImages( &montage, images.begin(), images.end(), montageOpts );
    }

    Image& montage_image = montage.front();
    {
      // Create logo image
      cout << "Adding logo image ..." << endl;
      Image logo( "logo:" );
      logo.zoom( "45%" );

      // Composite logo into montage image
      Geometry placement(0,0,(montage_image.columns()/2)-(logo.columns()/2),0);
      montage_image.composite( logo, placement, OverCompositeOp );
    }

    cout << "Writing image \"demo_out.miff\" ..." << endl;
    montage_image.matte( false );
    montage_image.compressType( RLECompression );
    montage_image.write( "demo_out.miff" );

    // Uncomment following lines to display image to screen
    //    cout <<  "Display image..." << endl;
    //    montage_image.display();

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

  return 0;
}
Ejemplo n.º 2
0
int main(int argc,char **argv)
{
  int sockfd;

  ErlConnect erlc;
  int fd;
  int identification_number = 1;
  int creation=1;
  char *cookie="cookie"; /* An example */
  string errcom;

  try {
    erl_init(NULL, 0);

    if (erl_connect_init(identification_number, cookie, creation) == -1)
      erl_err_quit("erl_connect_init");

    //fprintf(stderr, "connected\n");
    if ((sockfd = my_listen(PORT)) <= 0)
      erl_err_quit("error: my_listen");

    // fprintf(stderr, "listening\n");

    if ( erl_publish(PORT) == -1)
      erl_err_quit("error: publish");

    // fprintf(stderr, "published\n");

    if ((fd = erl_accept(sockfd, &erlc)) == ERL_ERROR)
      erl_err_quit("erl_accept");

    fprintf(stderr, "accepting on fd %i\n", fd);
    int image_index = 0;

    ETERM *ok = erl_mk_atom("ok");
    bool exit = false;

    while(!exit) {
      unsigned char buf[BUFSIZE];
      ErlMessage emsg;
      int rec = erl_receive_msg(fd, buf, BUFSIZE, &emsg);
      if (rec == ERL_MSG)
	//cout << "get message" << endl;
	;
      else if (rec == ERL_TICK) {
	//cout << "tick received" << endl;
	continue;
      }
      else if (rec == ERL_ERROR)
	//cout << "msg error " << errno << endl;
	;
      

      ETERM *pid = erl_element(1, emsg.msg);
      ETERM *msg = erl_element(2, emsg.msg);
      if (ERL_IS_TUPLE(msg)) {
	string command((const char*)ERL_ATOM_PTR(erl_element(1, msg)));
	errcom = command;
	if (command == "read") {
	  string file((const char*) erl_iolist_to_string(erl_element(2, msg)));
	  Image image;
	  image.read(file);
	  image_map[image_index] = image;
	  ETERM *reply = erl_mk_int(image_index++);
	  erl_send(fd, pid, reply);
	}
	else if (command == "write") {
	  Image& image = get_image(2, msg);
	  string file((const char*) erl_iolist_to_string(erl_element(3, msg)));
	  cout << "writing " << file << endl;
	  image.write(file);
	  erl_send(fd, pid, ok);
	}
	else if (command == "montageImages") {
	  vector<Image> imageList = getImageVector(2, msg);
	  //string tile((const char*) erl_iolist_to_string(erl_element(3, msg)));
	  MontageFramed montageOpts = get_montage_opts(3, msg);
	  string file((const char*) erl_iolist_to_string(erl_element(4, msg)));
	  montageOpts.fileName(file);
	  vector<Image> montage;
	  montageImages( &montage, imageList.begin(), imageList.end(), montageOpts );
	  writeImages(montage.begin(), montage.end(), file);
	  erl_send(fd, pid, ok);
	}
	else if (command == "clone") {
	  Image& image = get_image(2, msg);
	  Image clone(image);
	  image_map[image_index] = clone;
	  ETERM *reply = erl_mk_int(image_index++);
	  erl_send(fd, pid, reply);
	  
	}
	else if (command == "delete") {
	  del_image(2, msg);
	  erl_send(fd, pid, ok);
	}
	else if (command == "clear") {
	  clear_images();
	  erl_send(fd, pid, ok);
	}
	else if (command == "attribute") {
	  Image& image = get_image(2, msg);
	  string attribute(erl_iolist_to_string(erl_element(3, msg)));
	  string attrib(image.attribute(attribute));
	  ETERM *reply = erl_mk_estring(attrib.c_str(), attrib.size());
	  erl_send(fd, pid, reply);
	}

#include "im_commands.h"
	if (command == "quit") {
	  exit = true;
	  erl_send(fd, pid, ok); 
	}
	else {

	}
      }
    }
  }
  catch( Exception &error_ ) {
    cout << "Caught exception in command " << errcom << ": " << error_.what() << endl;
      return 1;
  }
  return 0;
}
Ejemplo n.º 3
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.º 4
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;
}