// Last updated 2008/11/04 11:20
// The program makes two tiles, one using the plasma: pseudo file and one using noise
// See: https://imagemagick.org.cn/Usage/canvas/#plasma_seeded
// and: https://imagemagick.org.cn/Usage/canvas/#random
// convert -size 100x100 plasma:red-yellow ( +clone -flop ) +append \
// ( +clone -flip ) -append -resize 50% tile_plasma.png
// and
// convert -size 100x100 xc: +noise Random -virtual-pixel tile \
// -blur 0x10 -normalize ( +clone -flop ) +append \
// ( +clone -flip ) -append -resize 50% tile_random.png
/*
Basically this flops and flips the image and joins the four results together
and then resizes the result by 50% so that it's the same size as the original.
E.g. if the original image is "/", it creates the flop image "\" and then appends
them side by side to give "/\". Then it takes this image and flips it which produces
"\/" and then appends these one on top of the other to produce
/\
\/
and finally, since this image is now twice the size of the original, it is resized to 50%.
*/
#include <windows.h>
#include <wand/magick_wand.h>
// make-tile creates a tileable image from an input image.
// ( +clone -flop ) +append ( +clone -flip ) -append -resize 50%
void make_tile(MagickWand *mw,char *outfile)
{
MagickWand *mwc = NULL, *mwf = NULL;
int w,h;
mwc = CloneMagickWand(mw);
MagickFlopImage(mwc);
MagickAddImage(mw,mwc);
if(mwc)mwc = DestroyMagickWand(mwc);
mwc = MagickAppendImages(mw,MagickFalse);
mwf = CloneMagickWand(mwc);
MagickFlipImage(mwf);
MagickAddImage(mwc,mwf);
if(mwf)mwf = DestroyMagickWand(mwf);
mwf = MagickAppendImages(mwc,MagickTrue);
w = MagickGetImageWidth(mwf);
h = MagickGetImageHeight(mwf);
// 1 = Don't blur or sharpen image
MagickResizeImage(mwf,w/2,h/2,LanczosFilter,1);
MagickWriteImage(mwf,outfile);
if(mwf)mwf = DestroyMagickWand(mwf);
if(mwc)mwc = DestroyMagickWand(mwc);
}
void test_wand(void)
{
MagickWand *mw = NULL;
MagickWandGenesis();
mw = NewMagickWand();
MagickSetSize(mw,100,100);
MagickReadImage(mw,"plasma:red-yellow");
make_tile(mw,"tile_plasma.png");
if(mw)mw = DestroyMagickWand(mw);
mw = NewMagickWand();
MagickSetSize(mw,100,100);
MagickReadImage(mw,"xc:");
MagickAddNoiseImage(mw,RandomNoise);
MagickSetImageVirtualPixelMethod(mw,TileVirtualPixelMethod);
MagickBlurImage(mw,0,10);
MagickNormalizeImage(mw);
make_tile(mw,"tile_random.png");
if(mw)mw = DestroyMagickWand(mw);
MagickWandTerminus();
}