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 / import.c < prev    next >
C/C++ Source or Header  |  1998-04-22  |  30KB  |  796 lines

  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %                                                                             %
  4. %                                                                             %
  5. %                                                                             %
  6. %                 IIIII  M   M  PPPP    OOO   RRRR   TTTTT                    %
  7. %                   I    MM MM  P   P  O   O  R   R    T                      %
  8. %                   I    M M M  PPPP   O   O  RRRR     T                      %
  9. %                   I    M   M  P      O   O  R R      T                      %
  10. %                 IIIII  M   M  P       OOO   R  R     T                      %
  11. %                                                                             %
  12. %                                                                             %
  13. %             Import X11 image to a machine independent format.               %
  14. %                                                                             %
  15. %                                                                             %
  16. %                                                                             %
  17. %                           Software Design                                   %
  18. %                             John Cristy                                     %
  19. %                              July 1992                                      %
  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. %  Import is an X Window System window dumping utility.  Import allows X
  50. %  users to store window images in a specially formatted dump file.  This
  51. %  file can then be read by the Display utility for redisplay, printing,
  52. %  editing, formatting, archiving, image processing, etc.  The target
  53. %  window can be specified by id or name or be selected by clicking the
  54. %  mouse in the desired window.  The keyboard bell is rung once at the
  55. %  beginning of the dump and twice when the dump is completed.
  56. %
  57. %  The import program command syntax is:
  58. %
  59. %  Usage: import [options ...] [file]
  60. %
  61. %  Where options include:
  62. %    -border             include image borders in the output image
  63. %    -colors value       preferred number of colors in the image
  64. %    -colorspace type    alternate image colorspace
  65. %    -comment string     annotate image with comment
  66. %    -compress type      None, JPEG, LZW, RunlengthEncoded, or Zip
  67. %    -crop geometry      preferred size and location of the cropped image
  68. %    -delay seconds      pause before selecting target window
  69. %    -density geometry   vertical and horizontal density of the image
  70. %    -descend            obtain image by descending window hierarchy
  71. %    -display server     X server to contact
  72. %    -dispose method     GIF disposal method
  73. %    -dither             apply Floyd/Steinberg error diffusion to image
  74. %    -frame              include window manager frame
  75. %    -geometry geometry  perferred size or location of the image
  76. %    -interlace type     None, Line, Plane, or Partition
  77. %    -label name         assign a label to an image
  78. %    -monochrome         transform image to black and white
  79. %    -negate             apply color inversion to image
  80. %    -page geometry      size and location of an image canvas
  81. %    -ping               efficiently determine image width and height
  82. %    -pointsize value    pointsize of Postscript font
  83. %    -quality value      JPEG/MIFF/PNG compression level
  84. %    -rotate degrees     apply Paeth rotation to the image
  85. %    -scene value        image scene number
  86. %    -screen             select image from root window
  87. %    -silent             operate silently, i.e. don't ring any bells 
  88. %    -transparent color  make this color transparent within the image
  89. %    -treedepth value    depth of the color classification tree
  90. %    -verbose            print detailed information about the image
  91. %    -window id          select window with this id or name
  92. %
  93. %  By default, 'file' is written in the Postscript image format.  To specify
  94. %  a particular image format, precede the filename with an image format
  95. %  name and a colon (i.e. ps:image) or specify the image type as the
  96. %  filename suffix (i.e. image.ps).  Specify 'file' as '-' for standard
  97. %  input or output.
  98. %
  99. %
  100. */
  101.  
  102. /*
  103.   Include declarations.
  104. */
  105. #include "magick.h"
  106. #include "version.h"
  107.  
  108. /*
  109.   Define declarations.
  110. */
  111. #define DefaultImportName  "magick.ps"
  112.  
  113. /*
  114. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  115. %                                                                             %
  116. %                                                                             %
  117. %                                                                             %
  118. %   U s a g e                                                                 %
  119. %                                                                             %
  120. %                                                                             %
  121. %                                                                             %
  122. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  123. %
  124. %  Procedure Usage displays the program usage;
  125. %
  126. %  The format of the Usage routine is:
  127. %
  128. %      Usage(client_name)
  129. %
  130. %    o client_name: a character string representing the name of the client
  131. %      program.
  132. %
  133. %
  134. */
  135. static void Usage(const char *client_name)
  136. {
  137.   char
  138.     **p;
  139.  
  140.   static char
  141.     *options[]=
  142.     {
  143.       "-border             include image borders in the output image",
  144.       "-colors value       preferred number of colors in the image",
  145.       "-colorspace type    alternate image colorspace",
  146.       "-comment string     annotate image with comment",
  147.       "-compress type      None, JPEG, LZW, RunlengthEncoded, or Zip",
  148.       "-crop geometry      preferred size and location of the cropped image",
  149.       "-delay seconds      pause before selecting target window",
  150.       "-density geometry   vertical and horizontal density of the image",
  151.       "-descend            obtain image by descending window hierarchy",
  152.       "-display server     X server to contact",
  153.       "-dispose method     GIF disposal method",
  154.       "-dither             apply Floyd/Steinberg error diffusion to image",
  155.       "-frame              include window manager frame",
  156.       "-geometry geometry  perferred size or location of the image",
  157.       "-interlace type     None, Line, Plane, or Partition",
  158.       "-label name         assign a label to an image",
  159.       "-monochrome         transform image to black and white",
  160.       "-negate             apply color inversion to image",
  161.       "-page geometry      size and location of an image canvas",
  162.       "-ping               efficiently determine image width and height",
  163.       "-pointsize value    pointsize of Postscript font",
  164.       "-quality value      JPEG/MIFF/PNG compression level",
  165.       "-rotate degrees     apply Paeth rotation to the image",
  166.       "-scene value        image scene number",
  167.       "-treedepth value    depth of the color classification tree",
  168.       "-transparent color  make this color transparent within the image",
  169.       "-silent             operate silently, i.e. don't ring any bells ",
  170.       "-screen             select image from root window",
  171.       "-verbose            print detailed information about the image",
  172.       "-window id          select window with this id or name",
  173.       (char *) NULL
  174.     };
  175.  
  176.   (void) printf("Version: %s\n",Version);
  177.   (void) printf("Copyright: %s\n\n",Copyright);
  178.   (void) printf("Usage: %s [options ...] [file]\n",client_name);
  179.   (void) printf("\nWhere options include:\n");
  180.   for (p=options; *p != (char *) NULL; p++)
  181.     (void) printf("  %s\n",*p);
  182.   (void) printf(
  183.   "\nBy default, 'file' is written in the Postscript image format.  To\n");
  184.   (void) printf(
  185.     "specify a particular image format, precede the filename with an image\n");
  186.   (void) printf(
  187.     "format name and a colon (i.e. ps:image) or specify the image type as\n");
  188.   (void) printf(
  189.     "the filename suffix (i.e. image.ps).  Specify 'file' as '-' for\n");
  190.   (void) printf("standard input or output.\n");
  191.   Exit(0);
  192. }
  193.  
  194. /*
  195. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  196. %                                                                             %
  197. %                                                                             %
  198. %                                                                             %
  199. %    M a i n                                                                  %
  200. %                                                                             %
  201. %                                                                             %
  202. %                                                                             %
  203. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  204. %
  205. %
  206. */
  207. int main(int argc,char **argv)
  208. {
  209.   char
  210.     *client_name,
  211.     *filename,
  212.     *option,
  213.     *resource_value,
  214.     *target_window;
  215.  
  216.   Display
  217.     *display;
  218.  
  219.   Image
  220.     *image;
  221.  
  222.   ImageInfo
  223.     image_info;
  224.  
  225.   int
  226.     i,
  227.     x;
  228.  
  229.   QuantizeInfo
  230.     quantize_info;
  231.  
  232.   unsigned int
  233.     scene;
  234.  
  235.   XImportInfo
  236.     ximage_info;
  237.  
  238.   XResourceInfo
  239.     resource_info;
  240.  
  241.   XrmDatabase
  242.     resource_database;
  243.  
  244.   /*
  245.     Connect to X server.
  246.   */
  247. #if defined(WIN32)
  248.   SetErrorHandler(NTErrorHandler);
  249.   SetWarningHandler(NTWarningHandler);
  250. #endif
  251.   GetImageInfo(&image_info);
  252.   GetQuantizeInfo(&quantize_info);
  253.   ReadCommandlLine(argc,&argv);
  254.   client_name=SetClientName(*argv);
  255.   for (i=1; i < argc; i++)
  256.   {
  257.     /*
  258.       Check command line for server name.
  259.     */
  260.     option=argv[i];
  261.     if ((Extent(option) == 1) || ((*option != '-') && (*option != '+')))
  262.       continue;
  263.     if (strcmp("display",option+1) == 0)
  264.       {
  265.         /*
  266.           User specified server name.
  267.         */
  268.         i++;
  269.         if (i == argc)
  270.           MagickError(OptionError,"Missing server name on -display",option);
  271.         image_info.server_name=argv[i];
  272.         break;
  273.       }
  274.     if (strncmp("help",option+1,2) == 0)
  275.       Usage(client_name);
  276.   }
  277.   /*
  278.     Get user defaults from X resource database.
  279.   */
  280.   display=XOpenDisplay(image_info.server_name);
  281.   if (display == (Display *) NULL)
  282.     MagickError(OptionError,"Unable to connect to X server",
  283.       XDisplayName(image_info.server_name));
  284.   XSetErrorHandler(XError);
  285.   resource_database=XGetResourceDatabase(display,client_name);
  286.   GetImageInfo(&image_info);
  287.   XGetImportInfo(&ximage_info);
  288.   XGetResourceInfo(resource_database,client_name,&resource_info);
  289.   resource_value=
  290.     XGetResourceInstance(resource_database,client_name,"border","False");
  291.   ximage_info.borders=IsTrue(resource_value);
  292.   image_info.density=XGetResourceInstance(resource_database,client_name,
  293.     "density",(char *) NULL);
  294.   resource_value=
  295.     XGetResourceInstance(resource_database,client_name,"descend","True");
  296.   ximage_info.descend=IsTrue(resource_value);
  297.   resource_value=
  298.     XGetResourceInstance(resource_database,client_name,"frame","False");
  299.   ximage_info.frame=IsTrue(resource_value);
  300.   resource_value=
  301.     XGetResourceInstance(resource_database,client_name,"interlace","none");
  302.   image_info.interlace=UndefinedInterlace;
  303.   if (Latin1Compare("None",resource_value) == 0)
  304.     image_info.interlace=NoInterlace;
  305.   if (Latin1Compare("Line",resource_value) == 0)
  306.     image_info.interlace=LineInterlace;
  307.   if (Latin1Compare("Plane",resource_value) == 0)
  308.     image_info.interlace=PlaneInterlace;
  309.   if (Latin1Compare("Partition",resource_value) == 0)
  310.     image_info.interlace=PartitionInterlace;
  311.   if (image_info.interlace == UndefinedInterlace)
  312.     MagickWarning(OptionWarning,"Unrecognized interlace type",resource_value);
  313.   image_info.page=XGetResourceInstance(resource_database,client_name,
  314.     "pageGeometry",(char *) NULL);
  315.   resource_value=
  316.     XGetResourceInstance(resource_database,client_name,"quality","85");
  317.   image_info.quality=atoi(resource_value);
  318.   resource_value=
  319.     XGetResourceInstance(resource_database,client_name,"scene","0");
  320.   scene=atoi(resource_value);
  321.   resource_value=
  322.     XGetResourceInstance(resource_database,client_name,"screen","False");
  323.   ximage_info.screen=IsTrue(resource_value);
  324.   resource_value=
  325.     XGetResourceInstance(resource_database,client_name,"silent","False");
  326.   ximage_info.silent=IsTrue(resource_value);
  327.   resource_value=
  328.     XGetResourceInstance(resource_database,client_name,"verbose","False");
  329.   image_info.verbose=IsTrue(resource_value);
  330.   /*
  331.     Check command syntax.
  332.   */
  333.   filename=(char *) NULL;
  334.   target_window=(char *) NULL;
  335.   for (i=1; i < argc; i++)
  336.   {
  337.     option=argv[i];
  338.     if ((Extent(option) < 2) || ((*option != '-') && (*option != '+')))
  339.       filename=argv[i];
  340.     else
  341.       switch(*(option+1))
  342.       {
  343.         case 'b':
  344.         {
  345.           if (strcmp("border",option+1) == 0)
  346.             {
  347.               ximage_info.borders=(*option == '-');
  348.               break;
  349.             }
  350.           if (strncmp("bordercolor",option+1,7) == 0)
  351.             {
  352.               if ((i == argc) || !sscanf(argv[i],"%d",&x))
  353.                 {
  354.                   i++;
  355.                   if (i == argc)
  356.                     MagickError(OptionError,"Missing color",option);
  357.                 }
  358.               break;
  359.             }
  360.           MagickError(OptionError,"Unrecognized option",option);
  361.           break;
  362.         }
  363.         case 'c':
  364.         {
  365.           if (strncmp("colors",option+1,7) == 0)
  366.             {
  367.               quantize_info.number_colors=0;
  368.               if (*option == '-')
  369.                 {
  370.                   i++;
  371.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  372.                     MagickError(OptionError,"Missing colors",option);
  373.                   quantize_info.number_colors=atoi(argv[i]);
  374.                 }
  375.               break;
  376.             }
  377.           if (strncmp("colorspace",option+1,7) == 0)
  378.             {
  379.               quantize_info.colorspace=RGBColorspace;
  380.               if (*option == '-')
  381.                 {
  382.                   i++;
  383.                   if (i == argc)
  384.                     MagickError(OptionError,"Missing type",option);
  385.                   option=argv[i];
  386.                   quantize_info.colorspace=UndefinedColorspace;
  387.                   if (Latin1Compare("cmyk",option) == 0)
  388.                     quantize_info.colorspace=CMYKColorspace;
  389.                   if (Latin1Compare("gray",option) == 0)
  390.                     {
  391.                       quantize_info.colorspace=GRAYColorspace;
  392.                       quantize_info.number_colors=256;
  393.                       quantize_info.tree_depth=8;
  394.                     }
  395.                   if (Latin1Compare("ohta",option) == 0)
  396.                     quantize_info.colorspace=OHTAColorspace;
  397.                   if (Latin1Compare("rgb",option) == 0)
  398.                     quantize_info.colorspace=RGBColorspace;
  399.                   if (Latin1Compare("transparent",option) == 0)
  400.                     quantize_info.colorspace=TransparentColorspace;
  401.                   if (Latin1Compare("xyz",option) == 0)
  402.                     quantize_info.colorspace=XYZColorspace;
  403.                   if (Latin1Compare("ycbcr",option) == 0)
  404.                     quantize_info.colorspace=YCbCrColorspace;
  405.                   if (Latin1Compare("yiq",option) == 0)
  406.                     quantize_info.colorspace=YIQColorspace;
  407.                   if (Latin1Compare("ypbpr",option) == 0)
  408.                     quantize_info.colorspace=YPbPrColorspace;
  409.                   if (Latin1Compare("yuv",option) == 0)
  410.                     quantize_info.colorspace=YUVColorspace;
  411.                   if (quantize_info.colorspace == UndefinedColorspace)
  412.                     MagickError(OptionError,"Invalid colorspace type",option);
  413.                 }
  414.               break;
  415.             }
  416.           if (strncmp("comment",option+1,4) == 0)
  417.             {
  418.               if (*option == '-')
  419.                 {
  420.                   i++;
  421.                   if (i == argc)
  422.                     MagickError(OptionError,"Missing comment",option);
  423.                 }
  424.               break;
  425.             }
  426.           if (strncmp("compress",option+1,5) == 0)
  427.             {
  428.               image_info.compression=NoCompression;
  429.               if (*option == '-')
  430.                 {
  431.                   i++;
  432.                   if (i == argc)
  433.                     MagickError(OptionError,"Missing type",option);
  434.                   option=argv[i];
  435.                   image_info.compression=UndefinedCompression;
  436.                   if (Latin1Compare("None",option) == 0)
  437.                     image_info.compression=NoCompression;
  438.                   if (Latin1Compare("JPEG",option) == 0)
  439.                     image_info.compression=JPEGCompression;
  440.                   if (Latin1Compare("LZW",option) == 0)
  441.                     image_info.compression=LZWCompression;
  442.                   if (Latin1Compare("RunlengthEncoded",option) == 0)
  443.                     image_info.compression=RunlengthEncodedCompression;
  444.                   if (Latin1Compare("Zip",option) == 0)
  445.                     image_info.compression=ZipCompression;
  446.                   if (image_info.compression == UndefinedCompression)
  447.                     MagickError(OptionError,"Invalid compression type",option);
  448.                 }
  449.               break;
  450.             }
  451.           if (strncmp("crop",option+1,2) == 0)
  452.             {
  453.               if (*option == '-')
  454.                 {
  455.                   i++;
  456.                   if ((i == argc) || !IsGeometry(argv[i]))
  457.                     MagickError(OptionError,"Missing geometry",option);
  458.                 }
  459.               break;
  460.             }
  461.           MagickError(OptionError,"Unrecognized option",option);
  462.           break;
  463.         }
  464.         case 'd':
  465.         {
  466.           if (strncmp("delay",option+1,3) == 0)
  467.             {
  468.               image_info.delay=(char *) NULL;
  469.               if (*option == '-')
  470.                 {
  471.                   i++;
  472.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  473.                     MagickError(OptionError,"Missing delay",option);
  474.                   image_info.delay=PostscriptGeometry(argv[i]);
  475.                 }
  476.               break;
  477.             }
  478.           if (strncmp("density",option+1,3) == 0)
  479.             {
  480.               image_info.density=(char *) NULL;
  481.               if (*option == '-')
  482.                 {
  483.                   i++;
  484.                   if ((i == argc) || !IsGeometry(argv[i]))
  485.                     MagickError(OptionError,"Missing geometry",option);
  486.                   image_info.density=argv[i];
  487.                 }
  488.               break;
  489.             }
  490.           if (strncmp("descend",option+1,3) == 0)
  491.             {
  492.               ximage_info.descend=(*option == '-');
  493.               break;
  494.             }
  495.           if (strcmp("display",option+1) == 0)
  496.             {
  497.               image_info.server_name=(char *) NULL;
  498.               if (*option == '-')
  499.                 {
  500.                   i++;
  501.                   if (i == argc)
  502.                     MagickError(OptionError,"Missing server name",option);
  503.                   image_info.server_name=argv[i];
  504.                 }
  505.               break;
  506.             }
  507.           if (strncmp("dispose",option+1,5) == 0)
  508.             {
  509.               image_info.dispose=(char *) NULL;
  510.               if (*option == '-')
  511.                 {
  512.                   i++;
  513.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  514.                     MagickError(OptionError,"Missing method",option);
  515.                   image_info.dispose=PostscriptGeometry(argv[i]);
  516.                 }
  517.               break;
  518.             }
  519.           if (strncmp("dither",option+1,3) == 0)
  520.             {
  521.               quantize_info.dither=(*option == '-');
  522.               break;
  523.             }
  524.           MagickError(OptionError,"Unrecognized option",option);
  525.           break;
  526.         }
  527.         case 'f':
  528.         {
  529.           argv[i]="-ignore";  /* resolve option confict */
  530.           ximage_info.frame=(*option == '-');
  531.           break;
  532.         }
  533.         case 'g':
  534.         {
  535.           if (strncmp("geometry",option+1,2) == 0)
  536.             {
  537.               if (*option == '-')
  538.                 {
  539.                   i++;
  540.                   if ((i == argc) || !IsGeometry(argv[i]))
  541.                     MagickError(OptionError,"Missing geometry",option);
  542.                 }
  543.               break;
  544.             }
  545.           MagickError(OptionError,"Unrecognized option",option);
  546.           break;
  547.         }
  548.         case 'h':
  549.         {
  550.           if (strncmp("help",option+1,2) == 0)
  551.             {
  552.               Usage(client_name);
  553.               break;
  554.             }
  555.           MagickError(OptionError,"Unrecognized option",option);
  556.           break;
  557.         }
  558.         case 'i':
  559.         {
  560.           if (strncmp("interlace",option+1,3) == 0)
  561.             {
  562.               image_info.interlace=NoInterlace;
  563.               if (*option == '-')
  564.                 {
  565.                   i++;
  566.                   if (i == argc)
  567.                     MagickError(OptionError,"Missing type",option);
  568.                   option=argv[i];
  569.                   image_info.interlace=UndefinedInterlace;
  570.                   if (Latin1Compare("No",option) == 0)
  571.                     image_info.interlace=NoInterlace;
  572.                   if (Latin1Compare("Line",option) == 0)
  573.                     image_info.interlace=LineInterlace;
  574.                   if (Latin1Compare("Plane",option) == 0)
  575.                     image_info.interlace=PlaneInterlace;
  576.                   if (Latin1Compare("Partition",option) == 0)
  577.                     image_info.interlace=PartitionInterlace;
  578.                   if (image_info.interlace == UndefinedInterlace)
  579.                     MagickError(OptionError,"Invalid interlace type",option);
  580.                 }
  581.               break;
  582.             }
  583.           MagickError(OptionError,"Unrecognized option",option);
  584.           break;
  585.         }
  586.         case 'l':
  587.         {
  588.           if (strncmp("label",option+1,3) == 0)
  589.             {
  590.               if (*option == '-')
  591.                 {
  592.                   i++;
  593.                   if (i == argc)
  594.                     MagickError(OptionError,"Missing label name",option);
  595.                 }
  596.               break;
  597.             }
  598.           MagickError(OptionError,"Unrecognized option",option);
  599.           break;
  600.         }
  601.         case 'm':
  602.         {
  603.           if (strncmp("monochrome",option+1,2) == 0)
  604.             {
  605.               image_info.monochrome=(*option == '-');
  606.               if (image_info.monochrome)
  607.                 {
  608.                   quantize_info.number_colors=2;
  609.                   quantize_info.tree_depth=8;
  610.                   quantize_info.colorspace=GRAYColorspace;
  611.                 }
  612.               break;
  613.             }
  614.           MagickError(OptionError,"Unrecognized option",option);
  615.         }
  616.         case 'n':
  617.         {
  618.           if (strncmp("negate",option+1,2) == 0)
  619.             break;
  620.           MagickError(OptionError,"Unrecognized option",option);
  621.         }
  622.         case 'p':
  623.         {
  624.           if (strncmp("page",option+1,3) == 0)
  625.             {
  626.               image_info.page=(char *) NULL;
  627.               if (*option == '-')
  628.                 {
  629.                   i++;
  630.                   if (i == argc)
  631.                     MagickError(OptionError,"Missing page geometry",option);
  632.                   image_info.page=PostscriptGeometry(argv[i]);
  633.                 }
  634.               break;
  635.             }
  636.           if (strncmp("ping",option+1,2) == 0)
  637.             {
  638.               image_info.ping=(*option == '-');
  639.               break;
  640.             }
  641.           if (strncmp("pointsize",option+1,2) == 0)
  642.             {
  643.               image_info.pointsize=atoi(DefaultPointSize);
  644.               if (*option == '-')
  645.                 {
  646.                   i++;
  647.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  648.                     MagickError(OptionError,"Missing size",option);
  649.                   image_info.pointsize=atoi(argv[i]);
  650.                 }
  651.               break;
  652.             }
  653.           MagickError(OptionError,"Unrecognized option",option);
  654.           break;
  655.         }
  656.         case 'q':
  657.         {
  658.           if (strncmp("quality",option+1,2) == 0)
  659.             {
  660.               image_info.quality=0;
  661.               if (*option == '-')
  662.                 {
  663.                   i++;
  664.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  665.                     MagickError(OptionError,"Missing quality",option);
  666.                   image_info.quality=atoi(argv[i]);
  667.                 }
  668.               break;
  669.             }
  670.           MagickError(OptionError,"Unrecognized option",option);
  671.           break;
  672.         }
  673.         case 'r':
  674.         {
  675.           if (strncmp("rotate",option+1,3) == 0)
  676.             {
  677.               if (*option == '-')
  678.                 {
  679.                   i++;
  680.                   if ((i == argc) || !IsGeometry(argv[i]))
  681.                      MagickError(OptionError,"Missing degrees",option);
  682.                 }
  683.               break;
  684.             }
  685.           MagickError(OptionError,"Unrecognized option",option);
  686.           break;
  687.         }
  688.         case 's':
  689.         {
  690.           if (strncmp("scene",option+1,3) == 0)
  691.             {
  692.               i++;
  693.               if ((i == argc) || !sscanf(argv[i],"%d",&x))
  694.                 MagickError(OptionError,"Missing scene",option);
  695.               scene=atoi(argv[i]);
  696.               break;
  697.             }
  698.           if (strncmp("screen",option+1,3) == 0)
  699.             {
  700.               ximage_info.screen=(*option == '-');
  701.               break;
  702.             }
  703.           if (strncmp("silent",option+1,3) == 0)
  704.             {
  705.               ximage_info.silent=(*option == '-');
  706.               break;
  707.             }
  708.           MagickError(OptionError,"Unrecognized option",option);
  709.           break;
  710.         }
  711.         case 't':
  712.         {
  713.           if (strncmp("transparent",option+1,3) == 0)
  714.             {
  715.               if (*option == '-')
  716.                 {
  717.                   i++;
  718.                   if (i == argc)
  719.                     MagickError(OptionError,"Missing color",option);
  720.                 }
  721.               break;
  722.             }
  723.           if (strncmp("treedepth",option+1,3) == 0)
  724.             {
  725.               quantize_info.tree_depth=0;
  726.               if (*option == '-')
  727.                 {
  728.                   i++;
  729.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  730.                     MagickError(OptionError,"Missing depth",option);
  731.                   quantize_info.tree_depth=atoi(argv[i]);
  732.                 }
  733.               break;
  734.             }
  735.           MagickError(OptionError,"Unrecognized option",option);
  736.           break;
  737.         }
  738.         case 'w':
  739.         {
  740.           i++;
  741.           if (i == argc)
  742.             MagickError(OptionError,"Missing id, name, or 'root'",option);
  743.           target_window=argv[i];
  744.           break;
  745.         }
  746.         case 'v':
  747.         {
  748.           image_info.verbose=(*option == '-');
  749.           break;
  750.         }
  751.         case '?':
  752.         {
  753.           Usage(client_name);
  754.           break;
  755.         }
  756.         default:
  757.         {
  758.           MagickError(OptionError,"Unrecognized option",option);
  759.           break;
  760.         }
  761.       }
  762.   }
  763.   if (filename == (char *) NULL)
  764.     filename=DefaultImportName;
  765.   /*
  766.     Read image from X server.
  767.   */
  768.   if (target_window != (char *) NULL)
  769.     (void) strcpy(image_info.filename,target_window);
  770.   if (image_info.delay != (char *) NULL)
  771.     (void) sleep(atoi(image_info.delay));
  772.   image_info.colorspace=quantize_info.colorspace;
  773.   image_info.dither=quantize_info.dither;
  774.   image=ReadXImage(&image_info,&ximage_info);
  775.   if (image == (Image *) NULL)
  776.     MagickError(OptionError,"Missing an image file name",(char *) NULL);
  777.   (void) strcpy(image->magick,"X");
  778.   /*
  779.     Transmogrify image as defined by the image processing options.
  780.   */
  781.   MogrifyImage(&image_info,argc,argv,&image);
  782.   /*
  783.     Write import X image.
  784.   */
  785.   image->scene=scene;
  786.   (void) strcpy(image_info.filename,filename);
  787.   (void) strcpy(image->magick,"PS");
  788.   (void) strcpy(image->filename,filename);
  789.   (void) WriteImage(&image_info,image);
  790.   if (image_info.verbose)
  791.     DescribeImage(image,stdout,False);
  792.   DestroyImage(image);
  793.   Exit(0);
  794.   return(False);
  795. }
  796.