Magick++  7.1.2-29
Convert, Edit, Or Compose Bitmap Images
flip.cpp
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2003
4 //
5 // Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
6 // dedicated to making software imaging solutions freely available.
7 //
8 // Demonstration of unary function-object based operations
9 //
10 // Reads the multi-frame file "smile_anim.miff" and writes a
11 // flipped and morphed version to "flip_out.miff".
12 //
13 
14 #include <Magick++.h>
15 #include <cstdlib>
16 #include <string>
17 #include <iostream>
18 #include <list>
19 #include <algorithm>
20 
21 using namespace std;
22 
23 using namespace Magick;
24 
25 int main( int /*argc*/, char ** argv)
26 {
27 
28  // Initialize ImageMagick install location for Windows
29  MagickPlusPlusGenesis genesis(*argv);
30 
31 
32  try {
33 
34  string srcdir("");
35  if(getenv("SRCDIR") != 0)
36  srcdir = getenv("SRCDIR");
37 
38  // Read images into STL list
39  list<Image> imageList;
40  readImages( &imageList, srcdir + "smile_anim.miff" );
41 
42  // cout << "Total scenes: " << imageList.size() << endl;
43 
44  // Flip images
45  for_each( imageList.begin(), imageList.end(), flipImage() );
46 
47  // Create a morphed version, adding three frames between each
48  // existing frame.
49  list<Image> morphed;
50  morphImages( &morphed, imageList.begin(), imageList.end(), 3 );
51 
52  // Write out images
53  cout << "Writing image \"flip_out.miff\" ..." << endl;
54  writeImages( morphed.begin(), morphed.end(), "flip_out.miff" );
55 
56  }
57  catch( exception &error_ )
58  {
59  cout << "Caught exception: " << error_.what() << endl;
60  return 1;
61  }
62 
63  return 0;
64 }