#include <Magick++.h>
#include <cassert>
#include <vector>
#include <glob.h>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
glob_t pics;
glob("*.jpg",GLOB_MARK,NULL,&pics);
InitializeMagick(*argv);
vector<Image> im;
for(int i = 0; i < pics.gl_pathc; ++i){
try
{
Image newim(pics.gl_pathv[i]);
newim.resize("1000x480");
im.push_back(newim);
while(im.size() > 639){
ostringstream oss;
oss << "im" << i+360 << ".jpg";
Image out("640x480", "white");
out.type(TrueColorType);
out.modifyImage();
ssize_t x = 0;
for(vector<Image>::iterator it = im.begin(); it != im.end(); ++it){
assert(it->columns() >= 640);
assert(it->rows() >= 480);
assert(out.columns() >= 640);
assert(out.rows() >= 480);
assert(x < 640);
PixelPacket *in_cache = it->getPixels(x,0,1,480);
PixelPacket *out_cache = out.getPixels(x,0,1,480);
for(int p = 0; p < 480; ++p) out_cache[p] = in_cache[p];
out.syncPixels();
++x;
if(x > 639) break;
}
out.write(oss.str());
im.erase(im.begin());
}
}
catch( Exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
}
return 0;
}