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("Add 3 sets of images after setting 'last' on empty wand\n");
     34   printf("Result shoud be: 012 345 678\n");
     35 
     36   MagickWandGenesis();
     37 
     38   wand = NewMagickWand();
     39   input = NewMagickWand();
     40 
     41   MagickSetLastIterator(wand);
     42 
     43   status = MagickReadImage(input, "font_0.gif" )
     44         && MagickReadImage(input, "font_1.gif" )
     45         && MagickReadImage(input, "font_2.gif" );
     46   if (status == MagickFalse)
     47     ThrowWandException(input);
     48 
     49   status = MagickAddImage(wand, input);
     50   if (status == MagickFalse)
     51     ThrowWandException(wand);
     52 
     53   ClearMagickWand(input);
     54   status = MagickReadImage(input, "font_3.gif" )
     55         && MagickReadImage(input, "font_4.gif" )
     56         && MagickReadImage(input, "font_5.gif" );
     57   if (status == MagickFalse)
     58     ThrowWandException(input);
     59 
     60   status = MagickAddImage(wand, input);
     61   if (status == MagickFalse)
     62     ThrowWandException(wand);
     63 
     64   ClearMagickWand(input);
     65   status = MagickReadImage(input, "font_6.gif" )
     66         && MagickReadImage(input, "font_7.gif" )
     67         && MagickReadImage(input, "font_8.gif" );
     68   if (status == MagickFalse)
     69     ThrowWandException(input);
     70 
     71   status = MagickAddImage(wand, input);
     72   if (status == MagickFalse)
     73     ThrowWandException(wand);
     74   input=DestroyMagickWand(input);
     75 
     76   /* append all images together to create the output wand */
     77   MagickResetIterator(wand); /* append all images */
     78   output = MagickAppendImages(wand,MagickFalse);
     79   wand = DestroyMagickWand(wand);  /* finished - could swap here */
     80 
     81   /* Final output */
     82   status = MagickWriteImage(output,"show:");
     83   if (status == MagickFalse)
     84     ThrowWandException(output);
     85 
     86   output = DestroyMagickWand(output);
     87 
     88   MagickWandTerminus();
     89 }
     90 
     91