home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / ImageMagick-4.0.6.tar.gz / ImageMagick-4.0.6.tar / ImageMagick-4.0.6 / combine.c < prev    next >
C/C++ Source or Header  |  1998-04-22  |  32KB  |  880 lines

  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %                                                                             %
  4. %                                                                             %
  5. %                                                                             %
  6. %                CCCC   OOO   M   M  BBBB   IIIII  N   N  EEEEE               %
  7. %               C      O   O  MM MM  B   B    I    NN  N  E                   %
  8. %               C      O   O  M M M  BBBB     I    N N N  EEE                 %
  9. %               C      O   O  M   M  B   B    I    N  NN  E                   %
  10. %                CCCC   OOO   M   N  BBBB   IIIII  N   N  EEEEE               %
  11. %                                                                             %
  12. %                                                                             %
  13. %                        Digitally combine two images.                        %
  14. %                                                                             %
  15. %                                                                             %
  16. %                                                                             %
  17. %                              Software Design                                %
  18. %                                John Cristy                                  %
  19. %                               January 1993                                  %
  20. %                                                                             %
  21. %                                                                             %
  22. %  Copyright 1998 E. I. du Pont de Nemours and Company                        %
  23. %                                                                             %
  24. %  Permission is hereby granted, free of charge, to any person obtaining a    %
  25. %  copy of this software and associated documentation files ("ImageMagick"),  %
  26. %  to deal in ImageMagick without restriction, including without limitation   %
  27. %  the rights to use, copy, modify, merge, publish, distribute, sublicense,   %
  28. %  and/or sell copies of ImageMagick, and to permit persons to whom the       %
  29. %  ImageMagick is furnished to do so, subject to the following conditions:    %
  30. %                                                                             %
  31. %  The above copyright notice and this permission notice shall be included in %
  32. %  all copies or substantial portions of ImageMagick.                         %
  33. %                                                                             %
  34. %  The software is provided "as is", without warranty of any kind, express or %
  35. %  implied, including but not limited to the warranties of merchantability,   %
  36. %  fitness for a particular purpose and noninfringement.  In no event shall   %
  37. %  E. I. du Pont de Nemours and Company be liable for any claim, damages or   %
  38. %  other liability, whether in an action of contract, tort or otherwise,      %
  39. %  arising from, out of or in connection with ImageMagick or the use or other %
  40. %  dealings in ImageMagick.                                                   %
  41. %                                                                             %
  42. %  Except as contained in this notice, the name of the E. I. du Pont de       %
  43. %  Nemours and Company shall not be used in advertising or otherwise to       %
  44. %  promote the sale, use or other dealings in ImageMagick without prior       %
  45. %  written authorization from the E. I. du Pont de Nemours and Company.       %
  46. %                                                                             %
  47. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  48. %
  49. %  The combine program syntax is:
  50. %
  51. %  Usage: combine [options ...] image composite [mask] combined
  52. %
  53. %  Where options include:
  54. %    -blend value        blend the two images a given percent
  55. %    -colors value       preferred number of colors in the image
  56. %    -compose operator   composite operator
  57. %    -colorspace type    alternate image colorspace
  58. %    -comment string     annotate image with comment
  59. %    -compress type      None, JPEG, LZW, RunlengthEncoded, or Zip
  60. %    -density geometry   vertical and horizontal density of the image
  61. %    -displace geometry  shift image pixels as defined by a displacement map
  62. %    -display server     obtain image or font from this X server
  63. %    -dispose method     GIF disposal method
  64. %    -dither             apply Floyd/Steinberg error diffusion to image
  65. %    -font name          X11 font for displaying text
  66. %    -geometry geometry  perferred size or location of the image
  67. %    -gravity direction  which direction to gravitate towards
  68. %    -interlace type     None, Line, Plane, or Partition
  69. %    -label name         assign a label to an image
  70. %    -matte              store matte channel if the image has one
  71. %    -monochrome         transform image to black and white
  72. %    -negate             apply color inversion to image
  73. %    -page geometry      size and location of an image canvas
  74. %    -quality value      JPEG/MIFF/PNG compression level
  75. %    -scene value        image scene number
  76. %    -size geometry      width and height of image
  77. %    -stereo             combine two image to create a stereo anaglyph
  78. %    -tile               repeat composite operation across image
  79. %    -treedepth value    depth of the color classification tree
  80. %    -verbose            print detailed information about the image
  81. %
  82. %
  83. */
  84.  
  85. /*
  86.   Include declarations.
  87. */
  88. #include "magick.h"
  89. #include "version.h"
  90.  
  91. /*
  92. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  93. %                                                                             %
  94. %                                                                             %
  95. %                                                                             %
  96. %   U s a g e                                                                 %
  97. %                                                                             %
  98. %                                                                             %
  99. %                                                                             %
  100. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  101. %
  102. %  Procedure Usage displays the program usage;
  103. %
  104. %  The format of the Usage routine is:
  105. %
  106. %      Usage(client_name)
  107. %
  108. %    o client_name: a character string representing the name of the client
  109. %      program.
  110. %
  111. %
  112. */
  113. static void Usage(const char *client_name)
  114. {
  115.   char
  116.     **p;
  117.  
  118.   static char
  119.     *options[]=
  120.     {
  121.       "-blend value        blend the two images a given percent",
  122.       "-colors value       preferred number of colors in the image",
  123.       "-colorspace type    alternate image colorspace",
  124.       "-comment string     annotate image with comment",
  125.       "-compose operator   composite operator",
  126.       "-compress type      None, JPEG, LZW, RunlengthEncoded, or Zip",
  127.       "-density geometry   vertical and horizontal density of the image",
  128.       "-displace geometry  shift image pixels as defined by a displacement map",
  129.       "-display server     obtain image or font from this X server",
  130.       "-dispose method     GIF disposal method",
  131.       "-dither             apply Floyd/Steinberg error diffusion to image",
  132.       "-font name          X11 font for displaying text",
  133.       "-geometry geometry  perferred size or location of the image",
  134.       "-gravity direction  which direction to gravitate towards",
  135.       "-interlace type     None, Line, Plane, or Partition",
  136.       "-label name         assign a label to an image",
  137.       "-matte              store matte channel if the image has one",
  138.       "-monochrome         transform image to black and white",
  139.       "-negate              apply color inversion to image",
  140.       "-page geometry      size and location of an image canvas",
  141.       "-quality value      JPEG/MIFF/PNG compression level",
  142.       "-scene value        image scene number",
  143.       "-size geometry      width and height of image",
  144.       "-stereo             combine two image to create a stereo anaglyph",
  145.       "-tile               repeat composite operation across image",
  146.       "-treedepth value    depth of the color classification tree",
  147.       "-verbose            print detailed information about the image",
  148.       (char *) NULL
  149.     };
  150.  
  151.   (void) printf("Version: %s\n",Version);
  152.   (void) printf("Copyright: %s\n\n",Copyright);
  153.   (void) printf("Usage: %s [options ...] image composite [mask] combined\n",
  154.     client_name);
  155.   (void) printf("\nWhere options include:\n");
  156.   for (p=options; *p != (char *) NULL; p++)
  157.     (void) printf("  %s\n",*p);
  158.   Exit(0);
  159. }
  160.  
  161. /*
  162. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  163. %                                                                             %
  164. %                                                                             %
  165. %                                                                             %
  166. %  M a i n                                                                    %
  167. %                                                                             %
  168. %                                                                             %
  169. %                                                                             %
  170. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  171. %
  172. %
  173. */
  174. int main(int argc,char **argv)
  175. {
  176. #define NotInitialized  (unsigned int) (~0)
  177.  
  178.   char
  179.     *client_name,
  180.     *displacement_geometry,
  181.     *filename,
  182.     *geometry,
  183.     *option,
  184.     *write_filename;
  185.  
  186.   CompositeOperator
  187.     compose;
  188.  
  189.   double
  190.     blend;
  191.  
  192.   Image
  193.     *combined_image,
  194.     *composite_image,
  195.     *image,
  196.     *mask_image;
  197.  
  198.   ImageInfo
  199.     image_info;
  200.  
  201.   int
  202.     gravity,
  203.     x,
  204.     y;
  205.  
  206.   register int
  207.     i;
  208.  
  209.   unsigned int
  210.     stereo,
  211.     tile;
  212.  
  213.   /*
  214.     Initialize program variables.
  215.   */
  216.   ReadCommandlLine(argc,&argv);
  217.   client_name=SetClientName(*argv);
  218.   if (argc < 4)
  219.     Usage(client_name);
  220.   /*
  221.     Read image and convert to MIFF format.
  222.   */
  223.   blend=0.0;
  224.   compose=ReplaceCompositeOp;
  225.   composite_image=(Image *) NULL;
  226.   displacement_geometry=(char *) NULL;
  227.   geometry=(char *) NULL;
  228.   gravity=NorthWestGravity;
  229.   GetImageInfo(&image_info);
  230.   image=(Image *) NULL;
  231.   mask_image=(Image *) NULL;
  232.   stereo=False;
  233.   tile=False;
  234.   write_filename=argv[argc-1];
  235.   /*
  236.     Check command syntax.
  237.   */
  238.   filename=(char *) NULL;
  239.   for (i=1; i < (argc-1); i++)
  240.   {
  241.     option=argv[i];
  242.     if ((Extent(option) < 2) || ((*option != '-') && (*option != '+')))
  243.       {
  244.         /*
  245.           Read input images.
  246.         */
  247.         filename=argv[i];
  248.         (void) strcpy(image_info.filename,filename);
  249.         if (image == (Image *) NULL)
  250.           {
  251.             image=ReadImage(&image_info);
  252.             if (image == (Image *) NULL)
  253.               MagickError(OptionError,"Missing an image file name",
  254.                 (char *) NULL);
  255.             continue;
  256.           }
  257.         if (mask_image != (Image *) NULL)
  258.           MagickError(OptionError,"input images already specified",filename);
  259.         if (composite_image == (Image *) NULL)
  260.           {
  261.             composite_image=ReadImage(&image_info);
  262.             if (composite_image == (Image *) NULL)
  263.               MagickError(OptionError,"Missing an image file name",
  264.                 (char *) NULL);
  265.             continue;
  266.           }
  267.         mask_image=ReadImage(&image_info);
  268.         if (mask_image == (Image *) NULL)
  269.           MagickError(OptionError,"Missing an image file name",(char *) NULL);
  270.       }
  271.     else
  272.       switch(*(option+1))
  273.       {
  274.         case 'b':
  275.         {
  276.           if (strncmp("blend",option+1,3) == 0)
  277.             {
  278.               blend=0.0;
  279.               if (*option == '-')
  280.                 {
  281.                   i++;
  282.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  283.                     MagickError(OptionError,"Missing value",option);
  284.                   blend=atof(argv[i]);
  285.                   compose=BlendCompositeOp;
  286.                 }
  287.               break;
  288.             }
  289.           MagickError(OptionError,"Unrecognized option",option);
  290.           break;
  291.         }
  292.         case 'c':
  293.         {
  294.           if (strncmp("colors",option+1,7) == 0)
  295.             {
  296.               if (*option == '-')
  297.                 {
  298.                   i++;
  299.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  300.                     MagickError(OptionError,"Missing colors",option);
  301.                 }
  302.               break;
  303.             }
  304.           if (strncmp("colorspace",option+1,7) == 0)
  305.             {
  306.               image_info.colorspace=RGBColorspace;
  307.               if (*option == '-')
  308.                 {
  309.                   i++;
  310.                   if (i == argc)
  311.                     MagickError(OptionError,"Missing type",option);
  312.                   option=argv[i];
  313.                   image_info.colorspace=UndefinedColorspace;
  314.                   if (Latin1Compare("cmyk",option) == 0)
  315.                     image_info.colorspace=CMYKColorspace;
  316.                   if (Latin1Compare("gray",option) == 0)
  317.                     image_info.colorspace=GRAYColorspace;
  318.                   if (Latin1Compare("ohta",option) == 0)
  319.                     image_info.colorspace=OHTAColorspace;
  320.                   if (Latin1Compare("rgb",option) == 0)
  321.                     image_info.colorspace=RGBColorspace;
  322.                   if (Latin1Compare("transparent",option) == 0)
  323.                     image_info.colorspace=TransparentColorspace;
  324.                   if (Latin1Compare("xyz",option) == 0)
  325.                     image_info.colorspace=XYZColorspace;
  326.                   if (Latin1Compare("ycbcr",option) == 0)
  327.                     image_info.colorspace=YCbCrColorspace;
  328.                   if (Latin1Compare("yiq",option) == 0)
  329.                     image_info.colorspace=YIQColorspace;
  330.                   if (Latin1Compare("ypbpr",option) == 0)
  331.                     image_info.colorspace=YPbPrColorspace;
  332.                   if (Latin1Compare("yuv",option) == 0)
  333.                     image_info.colorspace=YUVColorspace;
  334.                   if (image_info.colorspace == UndefinedColorspace)
  335.                     MagickError(OptionError,"Invalid colorspace type",option);
  336.                 }
  337.               break;
  338.             }
  339.           if (strncmp("comment",option+1,4) == 0)
  340.             {
  341.               if (*option == '-')
  342.                 {
  343.                   i++;
  344.                   if (i == argc)
  345.                     MagickError(OptionError,"Missing comment",option);
  346.                 }
  347.               break;
  348.             }
  349.           if (strncmp("compose",option+1,5) == 0)
  350.             {
  351.               compose=ReplaceCompositeOp;
  352.               if (*option == '-')
  353.                 {
  354.                   i++;
  355.                   if (i == argc)
  356.                     MagickError(OptionError,"Missing type",option);
  357.                   option=argv[i];
  358.                   compose=UndefinedCompositeOp;
  359.                   if (Latin1Compare("Over",option) == 0)
  360.                     compose=OverCompositeOp;
  361.                   if (Latin1Compare("In",option) == 0)
  362.                     compose=InCompositeOp;
  363.                   if (Latin1Compare("Out",option) == 0)
  364.                     compose=OutCompositeOp;
  365.                   if (Latin1Compare("Atop",option) == 0)
  366.                     compose=AtopCompositeOp;
  367.                   if (Latin1Compare("Xor",option) == 0)
  368.                     compose=XorCompositeOp;
  369.                   if (Latin1Compare("Plus",option) == 0)
  370.                     compose=PlusCompositeOp;
  371.                   if (Latin1Compare("Minus",option) == 0)
  372.                     compose=MinusCompositeOp;
  373.                   if (Latin1Compare("Add",option) == 0)
  374.                     compose=AddCompositeOp;
  375.                   if (Latin1Compare("Subtract",option) == 0)
  376.                     compose=SubtractCompositeOp;
  377.                   if (Latin1Compare("Difference",option) == 0)
  378.                     compose=DifferenceCompositeOp;
  379.                   if (Latin1Compare("Bumpmap",option) == 0)
  380.                     compose=BumpmapCompositeOp;
  381.                   if (Latin1Compare("Replace",option) == 0)
  382.                     compose=ReplaceCompositeOp;
  383.                   if (Latin1Compare("ReplaceRed",option) == 0)
  384.                     compose=ReplaceRedCompositeOp;
  385.                   if (Latin1Compare("ReplaceGreen",option) == 0)
  386.                     compose=ReplaceGreenCompositeOp;
  387.                   if (Latin1Compare("ReplaceBlue",option) == 0)
  388.                     compose=ReplaceBlueCompositeOp;
  389.                   if (Latin1Compare("ReplaceMatte",option) == 0)
  390.                     compose=ReplaceMatteCompositeOp;
  391.                   if (compose == UndefinedCompositeOp)
  392.                     MagickError(OptionError,"Invalid compose type",option);
  393.                 }
  394.               break;
  395.             }
  396.           if (strncmp("compress",option+1,5) == 0)
  397.             {
  398.               image_info.compression=NoCompression;
  399.               if (*option == '-')
  400.                 {
  401.                   i++;
  402.                   if (i == argc)
  403.                     MagickError(OptionError,"Missing type",option);
  404.                   option=argv[i];
  405.                   image_info.compression=UndefinedCompression;
  406.                   if (Latin1Compare("None",option) == 0)
  407.                     image_info.compression=NoCompression;
  408.                   if (Latin1Compare("JPEG",option) == 0)
  409.                     image_info.compression=JPEGCompression;
  410.                   if (Latin1Compare("LZW",option) == 0)
  411.                     image_info.compression=LZWCompression;
  412.                   if (Latin1Compare("RunlengthEncoded",option) == 0)
  413.                     image_info.compression=RunlengthEncodedCompression;
  414.                   if (Latin1Compare("Zip",option) == 0)
  415.                     image_info.compression=ZipCompression;
  416.                   if (image_info.compression == UndefinedCompression)
  417.                     MagickError(OptionError,"Invalid compression type",option);
  418.                 }
  419.               break;
  420.             }
  421.           MagickError(OptionError,"Unrecognized option",option);
  422.           break;
  423.         }
  424.         case 'd':
  425.         {
  426.           if (strncmp("density",option+1,3) == 0)
  427.             {
  428.               image_info.density=(char *) NULL;
  429.               if (*option == '-')
  430.                 {
  431.                   i++;
  432.                   if ((i == argc) || !IsGeometry(argv[i]))
  433.                     MagickError(OptionError,"Missing geometry",option);
  434.                   image_info.density=argv[i];
  435.                 }
  436.               break;
  437.             }
  438.           if (strcmp("displace",option+1) == 0)
  439.             {
  440.               displacement_geometry=(char *) NULL;
  441.               if (*option == '-')
  442.                 {
  443.                   i++;
  444.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  445.                     MagickError(OptionError,"Missing geometry",option);
  446.                   displacement_geometry=argv[i];
  447.                   compose=DisplaceCompositeOp;
  448.                 }
  449.               break;
  450.             }
  451.           if (strcmp("display",option+1) == 0)
  452.             {
  453.               image_info.server_name=(char *) NULL;
  454.               if (*option == '-')
  455.                 {
  456.                   i++;
  457.                   if (i == argc)
  458.                     MagickError(OptionError,"Missing server name",option);
  459.                   image_info.server_name=argv[i];
  460.                 }
  461.               break;
  462.             }
  463.           if (strncmp("dispose",option+1,5) == 0)
  464.             {
  465.               image_info.dispose=(char *) NULL;
  466.               if (*option == '-')
  467.                 {
  468.                   i++;
  469.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  470.                     MagickError(OptionError,"Missing method",option);
  471.                   image_info.dispose=PostscriptGeometry(argv[i]);
  472.                 }
  473.               break;
  474.             }
  475.           if (strncmp("dither",option+1,3) == 0)
  476.             {
  477.               image_info.dither=(*option == '-');
  478.               break;
  479.             }
  480.           MagickError(OptionError,"Unrecognized option",option);
  481.           break;
  482.         }
  483.         case 'f':
  484.         {
  485.           image_info.font=(char *) NULL;
  486.           if (*option == '-')
  487.             {
  488.               i++;
  489.               if (i == argc)
  490.                 MagickError(OptionError,"Missing font name",option);
  491.               image_info.font=argv[i];
  492.             }
  493.           break;
  494.         }
  495.         case 'g':
  496.         {
  497.           if (strncmp("geometry",option+1,2) == 0)
  498.             {
  499.               geometry=(char *) NULL;
  500.               if (*option == '-')
  501.                 {
  502.                   i++;
  503.                   if ((i == argc) || !IsGeometry(argv[i]))
  504.                     MagickError(OptionError,"Missing geometry",option);
  505.                   geometry=argv[i];
  506.                 }
  507.               break;
  508.             }
  509.           if (strncmp("gravity",option+1,2) == 0)
  510.             {
  511.               gravity=NorthWestGravity;
  512.               if (*option == '-')
  513.                 {
  514.                   i++;
  515.                   if (i == argc)
  516.                     MagickError(OptionError,"Missing type",option);
  517.                   option=argv[i];
  518.                   gravity=(-1);
  519.                   if (Latin1Compare("Forget",option) == 0)
  520.                     gravity=ForgetGravity;
  521.                   if (Latin1Compare("NorthWest",option) == 0)
  522.                     gravity=NorthWestGravity;
  523.                   if (Latin1Compare("North",option) == 0)
  524.                     gravity=NorthGravity;
  525.                   if (Latin1Compare("NorthEast",option) == 0)
  526.                     gravity=NorthEastGravity;
  527.                   if (Latin1Compare("West",option) == 0)
  528.                     gravity=WestGravity;
  529.                   if (Latin1Compare("Center",option) == 0)
  530.                     gravity=CenterGravity;
  531.                   if (Latin1Compare("East",option) == 0)
  532.                     gravity=EastGravity;
  533.                   if (Latin1Compare("SouthWest",option) == 0)
  534.                     gravity=SouthWestGravity;
  535.                   if (Latin1Compare("South",option) == 0)
  536.                     gravity=SouthGravity;
  537.                   if (Latin1Compare("SouthEast",option) == 0)
  538.                     gravity=SouthEastGravity;
  539.                   if (Latin1Compare("Static",option) == 0)
  540.                     gravity=StaticGravity;
  541.                   if (gravity == (-1))
  542.                     MagickError(OptionError,"Invalid gravity type",option);
  543.                 }
  544.               break;
  545.             }
  546.           MagickError(OptionError,"Unrecognized option",option);
  547.           break;
  548.         }
  549.         case 'h':
  550.         {
  551.           if (strncmp("help",option+1,2) == 0)
  552.             {
  553.               Usage(client_name);
  554.               break;
  555.             }
  556.           MagickError(OptionError,"Unrecognized option",option);
  557.           break;
  558.         }
  559.         case 'i':
  560.         {
  561.           if (strncmp("interlace",option+1,3) == 0)
  562.             {
  563.               image_info.interlace=NoInterlace;
  564.               if (*option == '-')
  565.                 {
  566.                   i++;
  567.                   if (i == argc)
  568.                     MagickError(OptionError,"Missing type",option);
  569.                   option=argv[i];
  570.                   image_info.interlace=UndefinedInterlace;
  571.                   if (Latin1Compare("None",option) == 0)
  572.                     image_info.interlace=NoInterlace;
  573.                   if (Latin1Compare("Line",option) == 0)
  574.                     image_info.interlace=LineInterlace;
  575.                   if (Latin1Compare("Plane",option) == 0)
  576.                     image_info.interlace=PlaneInterlace;
  577.                   if (Latin1Compare("Partition",option) == 0)
  578.                     image_info.interlace=PartitionInterlace;
  579.                   if (image_info.interlace == UndefinedInterlace)
  580.                     MagickError(OptionError,"Invalid interlace type",option);
  581.                 }
  582.               break;
  583.             }
  584.           MagickError(OptionError,"Unrecognized option",option);
  585.           break;
  586.         }
  587.         case 'l':
  588.         {
  589.           if (strncmp("label",option+1,3) == 0)
  590.             {
  591.               if (*option == '-')
  592.                 {
  593.                   i++;
  594.                   if (i == argc)
  595.                     MagickError(OptionError,"Missing label name",option);
  596.                 }
  597.               break;
  598.             }
  599.           MagickError(OptionError,"Unrecognized option",option);
  600.           break;
  601.         }
  602.         case 'm':
  603.         {
  604.           if (strncmp("matte",option+1,5) == 0)
  605.             break;
  606.           if (strncmp("monochrome",option+1,2) == 0)
  607.             break;
  608.           MagickError(OptionError,"Unrecognized option",option);
  609.           break;
  610.         }
  611.         case 'n':
  612.         {
  613.           if (strncmp("negate",option+1,3) == 0)
  614.             break;
  615.           MagickError(OptionError,"Unrecognized option",option);
  616.           break;
  617.         }
  618.         case 'p':
  619.         {
  620.           if (strncmp("page",option+1,3) == 0)
  621.             {
  622.               image_info.page=(char *) NULL;
  623.               if (*option == '-')
  624.                 {
  625.                   i++;
  626.                   if (i == argc)
  627.                     MagickError(OptionError,"Missing page geometry",option);
  628.                   image_info.page=PostscriptGeometry(argv[i]);
  629.                 }
  630.               break;
  631.             }
  632.           MagickError(OptionError,"Unrecognized option",option);
  633.           break;
  634.         }
  635.         case 'q':
  636.         {
  637.           if (strncmp("quality",option+1,2) == 0)
  638.             {
  639.               image_info.quality=atoi(DefaultImageQuality);
  640.               if (*option == '-')
  641.                 {
  642.                   i++;
  643.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  644.                     MagickError(OptionError,"Missing quality",option);
  645.                   image_info.quality=atoi(argv[i]);
  646.                 }
  647.               break;
  648.             }
  649.           MagickError(OptionError,"Unrecognized option",option);
  650.           break;
  651.         }
  652.         case 's':
  653.         {
  654.           if (strncmp("scene",option+1,2) == 0)
  655.             {
  656.               if (*option == '-')
  657.                 {
  658.                   i++;
  659.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  660.                     MagickError(OptionError,"Missing scene number",option);
  661.                 }
  662.               break;
  663.             }
  664.           if (strncmp("size",option+1,2) == 0)
  665.             {
  666.               image_info.size=(char *) NULL;
  667.               if (*option == '-')
  668.                 {
  669.                   i++;
  670.                   if ((i == argc) || !IsGeometry(argv[i]))
  671.                     MagickError(OptionError,"Missing geometry",option);
  672.                   image_info.size=argv[i];
  673.                 }
  674.               break;
  675.             }
  676.           if (strncmp("stereo",option+1,2) == 0)
  677.             {
  678.               stereo=(*option == '-');
  679.               break;
  680.             }
  681.           MagickError(OptionError,"Unrecognized option",option);
  682.           break;
  683.         }
  684.         case 't':
  685.         {
  686.           if (strncmp("tile",option+1,2) == 0)
  687.             {
  688.               tile=(*option == '-');
  689.               break;
  690.             }
  691.           MagickError(OptionError,"Unrecognized option",option);
  692.           if (strncmp("treedepth",option+1,3) == 0)
  693.             {
  694.               if (*option == '-')
  695.                 {
  696.                   i++;
  697.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  698.                     MagickError(OptionError,"Missing depth",option);
  699.                 }
  700.               break;
  701.             }
  702.           MagickError(OptionError,"Unrecognized option",option);
  703.           break;
  704.         }
  705.         case 'v':
  706.         {
  707.           if (strncmp("verbose",option+1,2) == 0)
  708.             {
  709.               image_info.verbose=(*option == '-');
  710.               break;
  711.             }
  712.           MagickError(OptionError,"Unrecognized option",option);
  713.           break;
  714.         }
  715.         case '?':
  716.         {
  717.           Usage(client_name);
  718.           break;
  719.         }
  720.         default:
  721.         {
  722.           MagickError(OptionError,"Unrecognized option",option);
  723.           break;
  724.         }
  725.       }
  726.   }
  727.   if ((image == (Image *) NULL) || (composite_image == (Image *) NULL))
  728.     Usage(client_name);
  729.   if (mask_image != (Image *) NULL)
  730.     {
  731.       CompositeImage(composite_image,ReplaceMatteCompositeOp,mask_image,0,0);
  732.       DestroyImage(mask_image);
  733.     }
  734.   if (compose == BlendCompositeOp)
  735.     {
  736.       register RunlengthPacket
  737.         *p;
  738.  
  739.       unsigned short
  740.         index;
  741.  
  742.       /*
  743.         Create mattes for blending.
  744.       */
  745.       index=(unsigned short)
  746.         (DownScale(MaxRGB)-(((int) DownScale(MaxRGB)*blend)/100));
  747.       image->class=DirectClass;
  748.       image->matte=True;
  749.       p=image->pixels;
  750.       for (i=0; i < image->packets; i++)
  751.       {
  752.         p->index=index;
  753.         p++;
  754.       }
  755.       index=(unsigned short) (DownScale(MaxRGB)-index);
  756.       composite_image->class=DirectClass;
  757.       composite_image->matte=True;
  758.       p=composite_image->pixels;
  759.       for (i=0; i < composite_image->packets; i++)
  760.       {
  761.         p->index=index;
  762.         p++;
  763.       }
  764.     }
  765.   if (compose == DisplaceCompositeOp)
  766.     composite_image->geometry=displacement_geometry;
  767.   /*
  768.     Combine image.
  769.   */
  770.   if (stereo)
  771.     combined_image=StereoImage(image,composite_image);
  772.   else
  773.     if (tile)
  774.       {
  775.         /*
  776.           Tile the composite image.
  777.         */
  778.         for (y=0; y < image->rows; y+=composite_image->rows)
  779.           for (x=0; x < image->columns; x+=composite_image->columns)
  780.             CompositeImage(image,compose,composite_image,x,y);
  781.         combined_image=image;
  782.       }
  783.     else
  784.       {
  785.         unsigned int
  786.           size;
  787.  
  788.         /*
  789.           Digitally composite image.
  790.         */
  791.         size=0;
  792.         x=0;
  793.         y=0;
  794.         if (geometry != (char *) NULL)
  795.           (void) ParseImageGeometry(geometry,&x,&y,&size,&size);
  796.         switch (gravity)
  797.         {
  798.           case NorthWestGravity:
  799.             break;
  800.           case NorthGravity:
  801.           {
  802.             x+=(image->columns-composite_image->columns) >> 1;
  803.             break;
  804.           }
  805.           case NorthEastGravity:
  806.           {
  807.             x+=image->columns-composite_image->columns;
  808.             break;
  809.           }
  810.           case WestGravity:
  811.           {
  812.             y+=(image->rows-composite_image->rows) >> 1;
  813.             break;
  814.           }
  815.           case ForgetGravity:
  816.           {
  817.             char
  818.               geometry[MaxTextExtent];
  819.  
  820.             /*
  821.               Stretch composite to the same size as the image.
  822.             */
  823.             (void) sprintf(geometry,"%ux%u+0+0",image->columns,image->rows);
  824.             TransformImage(&composite_image,(char *) NULL,geometry);
  825.             break;
  826.           }
  827.           case StaticGravity:
  828.           case CenterGravity:
  829.           default:
  830.           {
  831.             x+=(image->columns-composite_image->columns) >> 1;
  832.             y+=(image->rows-composite_image->rows) >> 1;
  833.             break;
  834.           }
  835.           case EastGravity:
  836.           {
  837.             x+=image->columns-composite_image->columns;
  838.             y+=(image->rows-composite_image->rows) >> 1;
  839.             break;
  840.           }
  841.           case SouthWestGravity:
  842.           {
  843.             y+=image->rows-composite_image->rows;
  844.             break;
  845.           }
  846.           case SouthGravity:
  847.           {
  848.             x+=(image->columns-composite_image->columns) >> 1;
  849.             y+=image->rows-composite_image->rows;
  850.             break;
  851.           }
  852.           case SouthEastGravity:
  853.           {
  854.             x+=image->columns-composite_image->columns;
  855.             y+=image->rows-composite_image->rows;
  856.             break;
  857.           }
  858.         }
  859.         CompositeImage(image,compose,composite_image,x,y);
  860.         combined_image=image;
  861.       }
  862.   if (combined_image == (Image *) NULL)
  863.     MagickError(OptionError,"Missing an image file name",(char *) NULL);
  864.   /*
  865.     Transmogrify image as defined by the image processing options.
  866.   */
  867.   CommentImage(combined_image,composite_image->comments);
  868.   MogrifyImage(&image_info,argc,argv,&combined_image);
  869.   /*
  870.     Write image.
  871.   */
  872.   (void) strcpy(combined_image->filename,write_filename);
  873.   (void) WriteImage(&image_info,combined_image);
  874.   if (image_info.verbose)
  875.     DescribeImage(combined_image,stdout,False);
  876.   DestroyImage(combined_image);
  877.   Exit(0);
  878.   return(False);
  879. }
  880.