Created
January 14, 2014 14:47
-
-
Save kou1okada/8419424 to your computer and use it in GitHub Desktop.
A skeleton of the C++ project files which uses Magick++, Boost and Autotools.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- Autoconf -*- | |
# Process this file with autoconf to produce a configure script. | |
AC_PREREQ([2.69]) | |
AC_INIT([omr], [0.1], [kou1okada@users.noreply.github.com]) | |
AM_INIT_AUTOMAKE | |
AC_CONFIG_SRCDIR([omr.cpp]) | |
AC_CONFIG_HEADERS([config.h]) | |
# Checks for programs. | |
AC_PROG_CXX | |
# Checks for Modules. | |
PKG_CHECK_MODULES(GRAPHICSMAGICKXX, "GraphicsMagick++", [ HAVE_GRAPHICSMAGICKXX=yes ], [ ]) | |
PKG_CHECK_MODULES(IMAGEMAGICKXX, "ImageMagick++", [ HAVE_IMAGEMAGICKXX=yes ], [ ]) | |
if test -n "$HAVE_GRAPHICSMAGICKXX"; then | |
MAGICKXX_CFLAGS="$GRAPHICSMAGICKXX_CFLAGS" | |
MAGICKXX_LIBS="$GRAPHICSMAGICKXX_LIBS" | |
elif test -n "$HAVE_IMAGEMAGICKXX"; then | |
MAGICKXX_CFLAGS="$IMAGEMAGICKXX_CFLAGS" | |
MAGICKXX_LIBS="$IMAGEMAGICKXX_LIBS" | |
fi | |
AC_SUBST(MAGICKXX_CFLAGS) | |
AC_SUBST(MAGICKXX_LIBS) | |
# Checks for libraries. | |
# Checks for header files. | |
# Checks for typedefs, structures, and compiler characteristics. | |
# Checks for library functions. | |
AC_CONFIG_FILES([Makefile]) | |
AC_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AM_CXXFLAGS = -mcmodel=large | |
AM_CXXFLAGS += $(MAGICKXX_CFLAGS) | |
LDADD = $(MAGICKXX_LIBS) -lboost_filesystem-mt -lboost_program_options-mt -lboost_system-mt | |
bin_PROGRAMS = omr | |
omr_SOURCES = omr.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Magick++.h> | |
#include <iostream> | |
#include <cstdlib> | |
#include <vector> | |
#include <string> | |
#include <boost/filesystem.hpp> | |
#include <boost/program_options.hpp> | |
#include <boost/foreach.hpp> | |
using namespace std; | |
using namespace Magick; | |
namespace fs = boost::filesystem; | |
namespace po = boost::program_options; | |
void usage(char *argv[], po::options_description &opts) | |
{ | |
cout | |
<< "Usage: " << fs::path(argv[0]).filename() << " [options] src dst ..." << std::endl | |
<< opts << std::endl; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
vector<string> files; | |
po::positional_options_description p; | |
p.add("files", -1); | |
po::options_description hidden("Hidden options"); hidden.add_options() | |
("files", po::value< vector<string> >(&files), "files"); | |
po::options_description generic("Options"); generic.add_options() | |
("help,h", "describe arguments"); | |
po::options_description cmdline_options; | |
cmdline_options.add(generic).add(hidden); | |
po::options_description visible_options; | |
visible_options.add(generic); | |
po::variables_map vm; | |
po::store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); | |
po::notify(vm); | |
if (vm.count("help")) { | |
usage(argv, visible_options); | |
return EXIT_FAILURE; | |
} | |
if (files.size() <= 1) { | |
usage(argv, visible_options); | |
return EXIT_SUCCESS; | |
} | |
#if 0 | |
// Not useful | |
// If files is not set, it causes Segmentation fault. | |
std::cout << "files: " << vm.count("files") << std::endl; | |
if (vm.count("files")) BOOST_FOREACH(string fn, vm["files"].as< vector<string> >()) { | |
std::cout << fn << std::endl; | |
} | |
#endif | |
std::cout << "files: " << files.size() << std::endl; | |
BOOST_FOREACH(string fn, files) { | |
std::cout << fn << std::endl; | |
} | |
Magick::InitializeMagick(argv[0]); | |
Magick::Image image; | |
try { | |
image.read(files[0]); | |
image.write(files[1]); | |
std::cout << "read " << files[0] << " and write " << files[1] << std::endl; | |
} | |
catch(Magick::Exception &error) { | |
std::cout << "Caught exception: " << error.what() << std::endl; | |
return EXIT_FAILURE; | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment