0

I am writing an improved Perlin noise (I don't really understand simplex noise) terrain generator for C, and I am practically finished with the alpha build. However, there is one thing holding me back: actually saving the stupid image. I recruited MagickWand to help me solve the problem of PNG creation, and it looks like a nice implementation on the whole, with tons of useful features etc., but there is very little documentation on the whole thing. No tutorials, really, just a bunch of lists of functions and some example programs. Here is my code so far, based on this:

EDIT: Cut out a bunch of irrelevant code.

#include <stdio.h>
#include <stdlib.h>
#include "mt.h"
#include "diamondsquare.h"
#include "/Library/Frameworks/libWand.framework/Versions/6.3.0/Headers/wand/MagickWand.h"

int main () {
    unsigned  long seed = 0, x = 0, y = 0, initial = 0, range = 0;
    int smooth = 0, fail = 1, index1 = 0, index2 = 0, exception = 0;
    char flagchar1 = 'n';
    // Some imperative code. Not relevant.
    image *ConstituteImage(x, y, "I", IntegerPixel, grid, &exception);
    write("image.png", image);
}

At the very least, I know that this is linked wrong (compiling returns an error inside wand.h that it can't find one of the headers). What's the proper way to go about creating an image from an array within a program using MagickWand for C?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
mszegedy
  • 185
  • 1
  • 9

2 Answers2

0

Too much code, it could be summarized with:

image *ConstituteImage(x, y, "I", IntegerPixel, grid, &exception);
write("image.png", image);

But reading the MagickWand link you provided:

MagickWriteImageFile

MagickWriteImageFile() writes an image to an open file descriptor. The format of the MagickWriteImageFile method is:

MagickBooleanType MagickWriteImageFile ( MagickWand *wand, FILE *file ); A description of each parameter follows:

wand: The magick wand. file: The file descriptor.

So it is clear you have to call:

MagickBooleanType MagickWriteImageFile ( MagickWand *wand, FILE *file );
vulkanino
  • 9,074
  • 7
  • 44
  • 71
  • Huh, strange, from [here](http://www.decuslib.com/decus/freewarev70/imagemagick/imagemagick-6_1_5/www/api/constitute.html#writeimage) it's just writeimage(). Thanks! – mszegedy Mar 07 '12 at 10:05
0

that header almost definitely tries to include other headers so you need something like:

gcc -I"/Library/Frameworks/libWand.framework/Versions/6.3.0/Headers"

or

gcc -I"/Library/Frameworks/libWand.framework/Versions/6.3.0/Headers/wand"
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • I don't know anything about Xcode but there must be a project setting for include directories. google? – Karoly Horvath Mar 07 '12 at 11:28
  • Hmm, nothing specifically about including, but instead paths for the build product. I think what I'll do is just copy the headers over into the build directory (there is no way that this can possibly go wrong). – mszegedy Mar 07 '12 at 12:11