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 'first' on empty wand\n");
     34   printf("Result shoud be: 678 345 012\n");
     35 
     36   MagickWandGenesis();
     37 
     38   wand = NewMagickWand();
     39   input = NewMagickWand();
     40 
     41   MagickSetFirstIterator(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 
     72   status = MagickAddImage(wand, input);
     73   if (status == MagickFalse)
     74     ThrowWandException(wand);
     75   input=DestroyMagickWand(input);  /* finished */
     76 
     77   /* append all images together to create the output wand */
     78   MagickResetIterator(wand); /* append all images */
     79   output = MagickAppendImages(wand,MagickFalse);
     80   wand = DestroyMagickWand(wand);  /* finished - could swap here */
     81 
     82   /* Final output */
     83   status = MagickWriteImage(output,"show:");
     84   if (status == MagickFalse)
     85     ThrowWandException(output);
     86 
     87   output = DestroyMagickWand(output);
     88 
     89   MagickWandTerminus();
     90 }
     91 
     92