demo.cpp
Go to the documentation of this file.
// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
//
// Copyright @ 2013 ImageMagick Studio LLC, a non-profit organization
// dedicated to making software imaging solutions freely available.
//
// Simple demo program for Magick++
//
// Concept and algorithms lifted from PerlMagick demo script written
// by John Christy.
//
// Max run-time size 60MB (as compared with 95MB for PerlMagick) under SPARC Solaris
//
#include <Magick++.h>
#include <string>
#include <iostream>
#include <list>
using namespace std;
using namespace Magick;
#if MAGICKCORE_FREETYPE_DELEGATE
#define MakeLabel(image, text) image.label( (text) )
#else
#define MakeLabel(image, text)
#endif
int main( int /*argc*/, char ** argv)
{
// Initialize ImageMagick install location for Windows
InitializeMagick(*argv);
const char *const p = getenv("MAGICK_FONT");
const string MAGICK_FONT(p ? p : "");
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" );
MakeLabel(model, "Magick++");
model.borderColor( "black" );
model.backgroundColor( "black" );
Image smile( srcdir + "smile.miff" );
MakeLabel(smile, "Smile");
smile.borderColor( "black" );
//
// Create image stack.
//
cout << "Creating thumbnails..." << endl;
// Construct initial list containing seven copies of a null image
Image null;
null.size( Geometry(70,70) );
null.read( "NULL:black" );
list<Image> images( 7, 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;
MakeLabel(example, "Add Noise");
example.addNoise( LaplacianNoise );
images.push_back( example );
cout << " add noise (blue) ..." << endl;
MakeLabel(example, "Add Noise\n(Blue Channel)");
example.addNoiseChannel( BlueChannel, PoissonNoise );
images.push_back( example );
#if MAGICKCORE_FREETYPE_DELEGATE
cout << " annotate ..." << endl;
example = model;
MakeLabel(example, "Annotate");
example.density( "72x72" );
example.fontPointsize( 18 );
example.font(MAGICK_FONT);
example.strokeColor( Color() );
example.fillColor( "gold" );
example.annotate( "Magick++", "+0+20", NorthGravity );
images.push_back( example );
#endif
cout << " blur ..." << endl;
example = model;
MakeLabel(example, "Blur");
example.blur( 0, 1.5 );
images.push_back( example );
cout << " blur red channel ..." << endl;
example = model;
MakeLabel(example, "Blur Channel\n(Red Channel)");
example.blurChannel( RedChannel, 0, 3.0 );
images.push_back( example );
cout << " border ..." << endl;
example = model;
MakeLabel(example, "Border");
example.borderColor( "gold" );
example.border( Geometry(6,6) );
images.push_back( example );
cout << " channel ..." << endl;
example = model;
MakeLabel(example, "Channel\n(Red Channel)");
example.channel( RedChannel );
images.push_back( example );
cout << " charcoal ..." << endl;
example = model;
MakeLabel(example, "Charcoal");
example.charcoal( );
images.push_back( example );
cout << " composite ..." << endl;
example = model;
MakeLabel(example, "Composite");
example.composite( smile, "+35+65", OverCompositeOp);
images.push_back( example );
cout << " contrast ..." << endl;
example = model;
MakeLabel(example, "Contrast");
example.contrast( false );
images.push_back( example );
cout << " convolve ..." << endl;
example = model;
MakeLabel(example, "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;
MakeLabel(example, "Crop");
example.crop( "80x80+25+50" );
images.push_back( example );
cout << " despeckle ..." << endl;
example = model;
MakeLabel(example, "Despeckle");
example.despeckle( );
images.push_back( example );
cout << " draw ..." << endl;
example = model;
MakeLabel(example, "Draw");
example.fillColor(Color());
example.strokeColor( "gold" );
example.strokeWidth( 2 );
example.draw( DrawableCircle( 60,90, 60,120 ) );
images.push_back( example );
cout << " edge ..." << endl;
example = model;
MakeLabel(example, "Detect Edges");
example.edge( );
images.push_back( example );
cout << " emboss ..." << endl;
example = model;
MakeLabel(example, "Emboss");
example.emboss( );
images.push_back( example );
cout << " equalize ..." << endl;
example = model;
MakeLabel(example, "Equalize");
example.equalize( );
images.push_back( example );
cout << " explode ..." << endl;
example = model;
MakeLabel(example, "Explode");
example.backgroundColor( "#000000FF" );
example.implode( -1 );
images.push_back( example );
cout << " flip ..." << endl;
example = model;
MakeLabel(example, "Flip");
example.flip( );
images.push_back( example );
cout << " flop ..." << endl;
example = model;
MakeLabel(example, "Flop");
example.flop();
images.push_back( example );
cout << " frame ..." << endl;
example = model;
MakeLabel(example, "Frame");
example.frame( );
images.push_back( example );
cout << " gamma ..." << endl;
example = model;
MakeLabel(example, "Gamma");
example.gamma( 1.6 );
images.push_back( example );
cout << " gaussian blur ..." << endl;
example = model;
MakeLabel(example, "Gaussian Blur");
example.gaussianBlur( 0.0, 1.5 );
images.push_back( example );
cout << " gaussian blur channel ..." << endl;
example = model;
MakeLabel(example, "Gaussian Blur\n(Green Channel)");
example.gaussianBlurChannel( GreenChannel, 0.0, 1.5 );
images.push_back( example );
cout << " gradient ..." << endl;
Image gradient;
gradient.size( "130x194" );
gradient.read( "gradient:#20a0ff-#ffff00" );
MakeLabel(gradient, "Gradient");
images.push_back( gradient );
cout << " grayscale ..." << endl;
example = model;
MakeLabel(example, "Grayscale");
example.quantizeColorSpace( GRAYColorspace );
example.quantize( );
images.push_back( example );
cout << " implode ..." << endl;
example = model;
MakeLabel(example, "Implode");
example.implode( 0.5 );
images.push_back( example );
cout << " level ..." << endl;
example = model;
MakeLabel(example, "Level");
example.level( 0.20*QuantumRange, 0.90*QuantumRange, 1.20 );
images.push_back( example );
cout << " level red channel ..." << endl;
example = model;
MakeLabel(example, "Level Channel\n(Red Channel)");
example.levelChannel( RedChannel, 0.20*QuantumRange, 0.90*QuantumRange, 1.20 );
images.push_back( example );
cout << " median filter ..." << endl;
example = model;
MakeLabel(example, "Median Filter");
example.medianFilter( );
images.push_back( example );
cout << " modulate ..." << endl;
example = model;
MakeLabel(example, "Modulate");
example.modulate( 110, 110, 110 );
images.push_back( example );
cout << " monochrome ..." << endl;
example = model;
MakeLabel(example, "Monochrome");
example.quantizeColorSpace( GRAYColorspace );
example.quantizeColors( 2 );
example.quantizeDither( false );
example.quantize( );
images.push_back( example );
cout << " motion blur ..." << endl;
example = model;
MakeLabel(example, "Motion Blur");
example.motionBlur( 0.0, 7.0,45 );
images.push_back( example );
cout << " negate ..." << endl;
example = model;
MakeLabel(example, "Negate");
example.negate( );
images.push_back( example );
cout << " normalize ..." << endl;
example = model;
MakeLabel(example, "Normalize");
example.normalize( );
images.push_back( example );
cout << " oil paint ..." << endl;
example = model;
MakeLabel(example, "Oil Paint");
example.oilPaint( );
images.push_back( example );
cout << " ordered dither 2x2 ..." << endl;
example = model;
MakeLabel(example, "Ordered Dither\n(2x2)");
example.randomThreshold(2,2);
images.push_back( example );
cout << " ordered dither 3x3..." << endl;
example = model;
MakeLabel(example, "Ordered Dither\n(3x3)");
example.randomThreshold(3,3);
images.push_back( example );
cout << " ordered dither 4x4..." << endl;
example = model;
MakeLabel(example, "Ordered Dither\n(4x4)");
example.randomThreshold(4,4);
images.push_back( example );
cout << " ordered dither red 4x4..." << endl;
example = model;
MakeLabel(example, "Ordered Dither\n(Red 4x4)");
example.randomThresholdChannel(RedChannel,4,4);
images.push_back( example );
cout << " plasma ..." << endl;
Image plasma;
plasma.size( "130x194" );
plasma.read( "plasma:fractal" );
MakeLabel(plasma, "Plasma");
images.push_back( plasma );
cout << " quantize ..." << endl;
example = model;
MakeLabel(example, "Quantize");
example.quantize( );
images.push_back( example );
cout << " quantum operator ..." << endl;
example = model;
MakeLabel(example, "Quantum Operator\nRed * 0.4");
example.evaluate( RedChannel,MultiplyEvaluateOperator,0.40 );
images.push_back( example );
cout << " raise ..." << endl;
example = model;
MakeLabel(example, "Raise");
example.raise( );
images.push_back( example );
cout << " reduce noise ..." << endl;
example = model;
MakeLabel(example, "Reduce Noise");
example.reduceNoise( 1.0 );
images.push_back( example );
cout << " resize ..." << endl;
example = model;
MakeLabel(example, "Resize");
example.zoom( "50%" );
images.push_back( example );
cout << " roll ..." << endl;
example = model;
MakeLabel(example, "Roll");
example.roll( "+20+10" );
images.push_back( example );
cout << " rotate ..." << endl;
example = model;
MakeLabel(example, "Rotate");
example.rotate( 45 );
example.transparent( "black" );
images.push_back( example );
cout << " scale ..." << endl;
example = model;
MakeLabel(example, "Scale");
example.scale( "60%" );
images.push_back( example );
cout << " segment ..." << endl;
example = model;
MakeLabel(example, "Segment");
example.segment( 0.5, 0.25 );
images.push_back( example );
cout << " shade ..." << endl;
example = model;
MakeLabel(example, "Shade");
example.shade( 30, 30, false );
images.push_back( example );
cout << " sharpen ..." << endl;
example = model;
MakeLabel(example, "Sharpen");
example.sharpen( 0.0, 1.0 );
images.push_back( example );
cout << " shave ..." << endl;
example = model;
MakeLabel(example, "Shave");
example.shave( Geometry( 10, 10) );
images.push_back( example );
cout << " shear ..." << endl;
example = model;
MakeLabel(example, "Shear");
example.shear( 45, 45 );
example.transparent( "black" );
images.push_back( example );
cout << " spread ..." << endl;
example = model;
MakeLabel(example, "Spread");
example.spread( 3 );
images.push_back( example );
cout << " solarize ..." << endl;
example = model;
MakeLabel(example, "Solarize");
example.solarize( );
images.push_back( example );
cout << " swirl ..." << endl;
example = model;
example.backgroundColor( "#000000FF" );
MakeLabel(example, "Swirl");
example.swirl( 90 );
images.push_back( example );
cout << " threshold ..." << endl;
example = model;
MakeLabel(example, "Threshold");
example.threshold( QuantumRange/2.0 );
images.push_back( example );
cout << " threshold random ..." << endl;
example = model;
MakeLabel(example, "Random\nThreshold");
example.randomThreshold( (0.3*QuantumRange),
(0.85*QuantumRange) );
images.push_back( example );
cout << " unsharp mask ..." << endl;
example = model;
MakeLabel(example, "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;
MakeLabel(example, "Wave");
example.alpha( 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( "7x4" );
montageOpts.backgroundColor( "#ffffff" );
montageOpts.pointSize( 18 );
montageOpts.font(MAGICK_FONT);
montageOpts.fillColor( "#600" );
montageOpts.strokeColor( Color() );
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 );
}
for_each( montage.begin(), montage.end(), depthImage(8) );
for_each( montage.begin(), montage.end(), alphaImage( false ) );
for_each( montage.begin(), montage.end(), compressTypeImage( RLECompression) );
cout << "Writing image \"demo_out.miff\" ..." << endl;
writeImages(montage.begin(),montage.end(),"demo_out_%d.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;
}
Magick::Image::gaussianBlur
void gaussianBlur(const double radius_, const double sigma_)
Definition: Image.cpp:3253
Magick::Image::swirl
void swirl(const double degrees_)
Definition: Image.cpp:4623
Magick::Color
class MagickPPExport Color
Definition: Color.h:18
Magick::Image::modulate
void modulate(const double brightness_, const double saturation_, const double hue_)
Definition: Image.cpp:3616
Magick::Image::annotate
void annotate(const std::string &text_, const Geometry &location_)
Definition: Image.cpp:1858
Magick::Image::charcoal
void charcoal(const double radius_=0.0, const double sigma_=1.0)
Definition: Image.cpp:2200
Magick::Image::blur
void blur(const double radius_=0.0, const double sigma_=1.0)
Definition: Image.cpp:2107
Magick::Image::contrast
void contrast(const bool sharpen_)
Definition: Image.cpp:2597
Magick::Image::medianFilter
void medianFilter(const double radius_=0.0)
Definition: Image.cpp:3593
Magick::Image::composite
void composite(const Image &compositeImage_, const Geometry &offset_, const CompositeOperator compose_=InCompositeOp)
Definition: Image.cpp:2535
Magick::Image::unsharpmask
void unsharpmask(const double radius_, const double sigma_, const double amount_, const double threshold_)
Definition: Image.cpp:4811
Magick::Image::negate
void negate(const bool grayscale_=false)
Definition: Image.cpp:3745
MakeLabel
#define MakeLabel(image, text)
Definition: demo.cpp:28
Magick::Image::raise
void raise(const Geometry &geometry_=raiseGeometryDefault, const bool raisedFlag_=false)
Definition: Image.cpp:4008
Magick::Image::crop
void crop(const Geometry &geometry_)
Definition: Image.cpp:2667
Magick::Image::density
void density(const Point &density_)
Definition: Image.cpp:653
Magick::Image::shade
void shade(const double azimuth_=30, const double elevation_=30, const bool colorShading_=false)
Definition: Image.cpp:4399
std
STL namespace.
Magick::Image::equalize
void equalize(void)
Definition: Image.cpp:2888
Magick::Image::zoom
void zoom(const Geometry &geometry_)
Definition: Image.cpp:4997
Magick::Image::strokeWidth
void strokeWidth(const double strokeWidth_)
Definition: Image.cpp:1507
Magick++.h
Magick::Image::blurChannel
void blurChannel(const ChannelType channel_, const double radius_=0.0, const double sigma_=1.0)
Definition: Image.cpp:2118
Magick::Image::strokeColor
void strokeColor(const Color &strokeColor_)
Definition: Image.cpp:1403
Magick::Image::oilPaint
void oilPaint(const double radius_=0.0, const double sigma=1.0)
Definition: Image.cpp:3772
Magick::Image::spread
void spread(const double amount_=3.0)
Definition: Image.cpp:4555
Magick::Image::randomThresholdChannel
void randomThresholdChannel(const ChannelType channel_, const double low_, const double high_)
Definition: Image.cpp:4027
Magick::Image::motionBlur
void motionBlur(const double radius_, const double sigma_, const double angle_)
Definition: Image.cpp:3733
Magick::Image::emboss
void emboss(const double radius_=0.0, const double sigma_=1.0)
Definition: Image.cpp:2858
Magick::Image::segment
void segment(const double clusterThreshold_=1.0, const double smoothingThreshold_=1.5)
Definition: Image.cpp:4305
Magick::Image::reduceNoise
void reduceNoise(void)
Definition: Image.cpp:4138
Magick::Image::sharpen
void sharpen(const double radius_=0.0, const double sigma_=1.0)
Definition: Image.cpp:4425
Magick::montageImages
void montageImages(Container *montageImages_, InputIterator first_, InputIterator last_, const Montage &options_)
Definition: STL.h:2484
Magick::Image::solarize
void solarize(const double factor_=50.0)
Definition: Image.cpp:4502
Magick::Montage::geometry
void geometry(const Geometry &geometry_)
Definition: Montage.cpp:83
Magick::Image::quantize
void quantize(const bool measureError_=false)
Definition: Image.cpp:3994
Magick::Image::read
void read(const Blob &blob_)
Definition: Image.cpp:4038
Magick::Image::frame
void frame(const Geometry &geometry_=frameGeometryDefault)
Definition: Image.cpp:3162
Magick::Image::flip
void flip(void)
Definition: Image.cpp:2997
Magick::Image::shave
void shave(const Geometry &geometry_)
Definition: Image.cpp:4450
Magick::Image::borderColor
void borderColor(const Color &color_)
Definition: Image.cpp:429
Magick::Image::font
void font(const std::string &font_)
Definition: Image.cpp:852
Magick::Image::fontPointsize
void fontPointsize(const double pointSize_)
Definition: Image.cpp:874
Magick::Geometry
class MagickPPExport Geometry
Definition: Geometry.h:21
Magick::strokeColorImage
Definition: STL.h:1135
Magick::depthImage
Definition: STL.h:1440
Magick::writeImages
void writeImages(InputIterator first_, InputIterator last_, const std::string &imageSpec_, bool adjoin_=true)
Definition: STL.h:2823
Magick::Image::edge
void edge(const double radius_=0.0)
Definition: Image.cpp:2847
Magick::Image::fillColor
void fillColor(const Color &fillColor_)
Definition: Image.cpp:786
Magick::Image::scale
void scale(const Geometry &geometry_)
Definition: Image.cpp:4283
Magick::Image::size
void size(const Geometry &geometry_)
Definition: Image.cpp:1379
Magick::Image::draw
void draw(const Drawable &drawable_)
Definition: Image.cpp:2798
Magick::Image::randomThreshold
void randomThreshold(const double low_, const double high_)
Definition: Image.cpp:4020
Magick::Image::evaluate
void evaluate(const ChannelType channel_, const MagickEvaluateOperator operator_, double rvalue_)
Definition: Image.cpp:2904
Magick::Geometry
Definition: Geometry.h:37
Magick::Image::implode
void implode(const double factor_)
Definition: Image.cpp:3372
Magick::Image::addNoiseChannel
void addNoiseChannel(const ChannelType channel_, const NoiseType noiseType_, const double attenuate_=1.0)
Definition: Image.cpp:1807
Magick::DrawableCircle
Definition: Drawable.h:606
Magick::Image::wave
void wave(const double amplitude_=25.0, const double wavelength_=150.0)
Definition: Image.cpp:4852
Magick::Image::gamma
double gamma(void) const
Definition: Image.cpp:947
Magick::Image::threshold
void threshold(const double threshold_)
Definition: Image.cpp:4650
Magick::Image::convolve
void convolve(const size_t order_, const double *kernel_)
Definition: Image.cpp:2625
Magick::Image::roll
void roll(const Geometry &roll_)
Definition: Image.cpp:4202
Magick::Image::gaussianBlurChannel
void gaussianBlurChannel(const ChannelType channel_, const double radius_, const double sigma_)
Definition: Image.cpp:3264
Magick::Image::transparent
void transparent(const Color &color_, const bool inverse_=false)
Definition: Image.cpp:4713
Magick::compressTypeImage
Definition: STL.h:1416
Magick::Image::alpha
void alpha(const bool alphaFlag_)
Definition: Image.cpp:307
Magick::Image::border
void border(const Geometry &geometry_=borderGeometryDefault)
Definition: Image.cpp:2132
Magick::alphaImage
Definition: STL.h:805
Magick::Image::addNoise
void addNoise(const NoiseType noiseType_, const double attenuate_=1.0)
Definition: Image.cpp:1796
Magick::Image::columns
size_t columns(void) const
Definition: Image.cpp:590
Magick::Image::quantizeColors
void quantizeColors(const size_t colors_)
Definition: Image.cpp:1260
Magick::MontageFramed
Definition: Montage.h:119
Magick
Definition: Blob.h:17
Magick::Image::flop
void flop(void)
Definition: Image.cpp:3120
Magick::Image::levelChannel
void levelChannel(const ChannelType channel_, const double blackPoint_, const double whitePoint_, const double gamma_=1.0)
Definition: Image.cpp:3436
Magick::Image::despeckle
void despeckle(void)
Definition: Image.cpp:2767
Magick::Image::channel
void channel(const ChannelType channel_)
Definition: Image.cpp:2189
Magick::InitializeMagick
MagickPPExport void InitializeMagick(const char *path_)
Definition: Functions.cpp:45
Magick::Image::normalize
void normalize(void)
Definition: Image.cpp:3764
main
int main(int, char **argv)
Definition: demo.cpp:31
Magick::Image::backgroundColor
void backgroundColor(const Color &color_)
Definition: Image.cpp:376
Magick::Image::quantizeDither
void quantizeDither(const bool ditherFlag_)
Definition: Image.cpp:1283
Magick::Image
Definition: Image.h:55
Magick::Image::level
void level(const double blackPoint_, const double whitePoint_, const double gamma_=1.0)
Definition: Image.cpp:3427
Magick::Image::quantizeColorSpace
void quantizeColorSpace(const ColorspaceType colorSpace_)
Definition: Image.cpp:1271
Magick::Image::shear
void shear(const double xShearAngle_, const double yShearAngle_)
Definition: Image.cpp:4464
Magick::Image::rotate
void rotate(const double degrees_)
Definition: Image.cpp:4225