// Last updated 2011/03/14 18:23

// Implement Anthony's tilt-shift example from http://www.imagemagick.org/Usage/photos/#tilt_shift
// NOTE that I use the -function version - not the linear one
// convert beijing_md.jpg -sigmoidal-contrast 15x30% \
//          \( +clone -sparse-color Barycentric '0,0 black 0,%[fx:h-1] gray80' \
//             -function polynomial 4,-4,1 \) \
//          -compose Blur -set option:compose:args 15 -composite \
//          beijing_model.jpg
#include <windows.h>
#include <wand/magick_wand.h>

void test_wand(LPTSTR lpCmdLine) {
    MagickWand *mw = NULL;
    MagickWand *cw = NULL;		// cloned wand

    // arguments for MagickSparseColorImage
    // Note that the colours are stored as separate *normalized* RGB components
    double arglist[10] = {
        0,0,
        // RGB black
        0,0,0,

        // The y coordinate is filled in later
        0,-1,
        // RGB white
        1,1,1
    };
    // arguments for MagickFunctionImage
    double funclist[3] = {
        4,-4,1
    };

    MagickWandGenesis();
    mw = NewMagickWand();
    MagickReadImage(mw,"beijing_md.jpg");
    // fill in the Y coordinate now that we can get the image dimensions
    arglist[6] = MagickGetImageHeight(mw)-1;

    MagickSigmoidalContrastImage(mw,MagickTrue,15,QuantumRange*30/100);

    cw = CloneMagickWand(mw);
    MagickSparseColorImage(cw,BlueChannel|GreenChannel|RedChannel,BarycentricColorInterpolate,10,arglist);
    // Do the polynomial function
    MagickFunctionImage(cw,PolynomialFunction,3,funclist);
    // -set option:compose:args 15
    if (MagickSetImageArtifact(cw,"compose:args","15") == MagickFalse) {
        MessageBox(NULL,"Artifact failed","",MB_OK);
        mw = DestroyMagickWand(mw);
        cw = DestroyMagickWand(cw);
        MagickWandTerminus();
        return;
    }

    MagickCompositeImage(mw,cw,BlurCompositeOp,0,0);
    MagickWriteImage(mw,"beijing_model.jpg");
    mw = DestroyMagickWand(mw);
    cw = DestroyMagickWand(cw);
    MagickWandTerminus();

}