Home | History | Annotate | Download | only in tests
      1 #include <stdio.h>
      2 #include <MagickWand/MagickWand.h>
      3 
      4 /* Simplify the exception handling
      5  * technically we should abort the program if
      6  *      severity >= ErrorException
      7  */
      8 void ThrowWandException(MagickWand *wand)
      9 { char
     10   *description;
     11 
     12   ExceptionType
     13   severity;
     14 
     15   description=MagickGetException(wand,&severity);
     16   (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description);
     17   description=(char *) MagickRelinquishMemory(description);
     18 }
     19 
     20 /* useful function especially after appending two wands together */
     21 #define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; }
     22 
     23 int main(int argc, char *argv[])
     24 {
     25   MagickWand
     26     *wand,
     27     *input,
     28     *output;
     29 
     30   MagickBooleanType
     31     status;
     32 
     33   printf("Read 4 images, then set index 1 and read more individual images\n");
     34   printf("Result shoud be: 01 654 23\n");
     35 
     36   MagickWandGenesis();
     37 
     38   wand = NewMagickWand();
     39   input = NewMagickWand();
     40 
     41   status = MagickReadImage(input, "font_0.gif" )
     42         && MagickReadImage(input, "font_1.gif" )
     43         && MagickReadImage(input, "font_2.gif" )
     44         && MagickReadImage(input, "font_3.gif" );
     45   if (status == MagickFalse)
     46     ThrowWandException(input);
     47 
     48   status = MagickAddImage(wand, input);
     49   if (status == MagickFalse)
     50     ThrowWandException(wand);
     51   input=DestroyMagickWand(input);  /* finished */
     52 
     53   MagickSetIteratorIndex(wand, 1);
     54 
     55   status = MagickReadImage(wand, "font_4.gif" );
     56   if (status == MagickFalse)
     57     ThrowWandException(wand);
     58 
     59   status = MagickReadImage(wand, "font_5.gif" );
     60   if (status == MagickFalse)
     61     ThrowWandException(wand);
     62 
     63   status = MagickReadImage(wand, "font_6.gif" );
     64   if (status == MagickFalse)
     65     ThrowWandException(wand);
     66 
     67   /* append all images together to create the output wand */
     68   MagickResetIterator(wand); /* append all images */
     69   output = MagickAppendImages(wand,MagickFalse);
     70   wand = DestroyMagickWand(wand);  /* finished - could swap here */
     71 
     72   /* Final output */
     73   status = MagickWriteImage(output,"show:");
     74   if (status == MagickFalse)
     75     ThrowWandException(output);
     76 
     77   output = DestroyMagickWand(output);
     78 
     79   MagickWandTerminus();
     80 }
     81 
     82