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 / display.c < prev    next >
Text File  |  1998-04-22  |  52KB  |  1,411 lines

  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %                                                                             %
  4. %                                                                             %
  5. %                                                                             %
  6. %             DDDD   IIIII  SSSSS  PPPP   L       AAA   Y   Y                 %
  7. %             D   D    I    SS     P   P  L      A   A   Y Y                  %
  8. %             D   D    I     SSS   PPPP   L      AAAAA    Y                   %
  9. %             D   D    I       SS  P      L      A   A    Y                   %
  10. %             DDDD   IIIII  SSSSS  P      LLLLL  A   A    Y                   %
  11. %                                                                             %
  12. %                                                                             %
  13. %                     Interactively Display an Image.                         %
  14. %                                                                             %
  15. %                                                                             %
  16. %                           Software Design                                   %
  17. %                             John Cristy                                     %
  18. %                              July 1992                                      %
  19. %                                                                             %
  20. %                                                                             %
  21. %  Copyright 1998 E. I. du Pont de Nemours and Company                        %
  22. %                                                                             %
  23. %  Permission is hereby granted, free of charge, to any person obtaining a    %
  24. %  copy of this software and associated documentation files ("ImageMagick"),  %
  25. %  to deal in ImageMagick without restriction, including without limitation   %
  26. %  the rights to use, copy, modify, merge, publish, distribute, sublicense,   %
  27. %  and/or sell copies of ImageMagick, and to permit persons to whom the       %
  28. %  ImageMagick is furnished to do so, subject to the following conditions:    %
  29. %                                                                             %
  30. %  The above copyright notice and this permission notice shall be included in %
  31. %  all copies or substantial portions of ImageMagick.                         %
  32. %                                                                             %
  33. %  The software is provided "as is", without warranty of any kind, express or %
  34. %  implied, including but not limited to the warranties of merchantability,   %
  35. %  fitness for a particular purpose and noninfringement.  In no event shall   %
  36. %  E. I. du Pont de Nemours and Company be liable for any claim, damages or   %
  37. %  other liability, whether in an action of contract, tort or otherwise,      %
  38. %  arising from, out of or in connection with ImageMagick or the use or other %
  39. %  dealings in ImageMagick.                                                   %
  40. %                                                                             %
  41. %  Except as contained in this notice, the name of the E. I. du Pont de       %
  42. %  Nemours and Company shall not be used in advertising or otherwise to       %
  43. %  promote the sale, use or other dealings in ImageMagick without prior       %
  44. %  written authorization from the E. I. du Pont de Nemours and Company.       %
  45. %                                                                             %
  46. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47. %
  48. %  Display is a machine architecture independent image processing
  49. %  and display program.  It can display any image in the MIFF format on
  50. %  any workstation display running X.  Display first determines the
  51. %  hardware capabilities of the workstation.  If the number of unique
  52. %  colors in the image is less than or equal to the number the workstation
  53. %  can support, the image is displayed in an X window.  Otherwise the
  54. %  number of colors in the image is first reduced to match the color
  55. %  resolution of the workstation before it is displayed.
  56. %
  57. %  This means that a continuous-tone 24 bits-per-pixel image can display on a
  58. %  8 bit pseudo-color device or monochrome device.  In most instances the
  59. %  reduced color image closely resembles the original.  Alternatively, a
  60. %  monochrome or pseudo-color image can display on a continuous-tone 24
  61. %  bits-per-pixel device.
  62. %
  63. %  The Display program command syntax is:
  64. %
  65. %  Usage: display [options ...] file [ [options ...] file ...]
  66. %
  67. %  Where options include:
  68. %    -backdrop          display image centered on a backdrop
  69. %    -border geometry   surround image with a border of color
  70. %    -colormap type     Shared or Private
  71. %    -colors value      preferred number of colors in the image
  72. %    -colorspace type   alternate image colorspace
  73. %    -comment string    annotate image with comment",
  74. %    -compress type     None, JPEG, LZW, RunlengthEncoded, or Zip
  75. %    -contrast          enhance or reduce the image contrast
  76. %    -crop geometry     preferred size and location of the cropped image
  77. %    -delay value       display the next image after pausing
  78. %    -density geometry  vertical and horizontal density of the image
  79. %    -despeckle         reduce the speckles within an image
  80. %    -display server    display image to this X server
  81. %    -dispose method    GIF disposal method
  82. %    -dither            apply Floyd/Steinberg error diffusion to image
  83. %    -edge factor       apply a filter to detect edges in the image
  84. %    -enhance           apply a digital filter to enhance a noisy image
  85. %    -flip              flip image in the vertical direction
  86. %    -flop              flop image in the horizontal direction
  87. %    -frame geometry    surround image with an ornamental border
  88. %    -gamma value       level of gamma correction
  89. %    -geometry geometry preferred size and location of the Image window
  90. %    -immutable         displayed image cannot be modified
  91. %    -interlace type    None, Line, Plane, or Partition
  92. %    -label name        assign a label to an image
  93. %    -map type          display image using this Standard Colormap
  94. %    -matte             store matte channel if the image has one
  95. %    -monochrome        transform image to black and white
  96. %    -negate            apply color inversion to image
  97. %    -page geometry     size and location of an image canvas
  98. %    -quality value     JPEG/MIFF/PNG compression level
  99. %    -raise value       lighten/darken image edges to create a 3-D effect
  100. %    -remote command    execute a command in an remote display process
  101. %    -roll geometry     roll an image vertically or horizontally
  102. %    -rotate degrees    apply Paeth rotation to the image
  103. %    -sample geometry   scale image with pixel sampling
  104. %    -scene value       image scene number
  105. %    -segment value     segment an image
  106. %    -sharpen factor    apply a filter to sharpen the image
  107. %    -size geometry     width and height of image
  108. %    -texture filename  name of texture to tile onto the image background
  109. %    -treedepth value   depth of the color classification tree
  110. %    -update seconds    detect when image file is modified and redisplay
  111. %    -verbose           print detailed information about the image
  112. %    -visual type       display image using this visual type
  113. %    -window id         display image to background of this window
  114. %    -window_group id   exit program when this window id is destroyed
  115. %    -write filename    write image to a file
  116. %
  117. %  In addition to those listed above, you can specify these standard X
  118. %  resources as command line options:  -background, -bordercolor,
  119. %  -borderwidth, -font, -foreground, -iconGeometry, -iconic, -mattecolor,
  120. %  -name, -shared_memory, -usePixmap, or -title.
  121. %
  122. %  By default, the image format of `file' is determined by its magic
  123. %  number.  To specify a particular image format, precede the filename
  124. %  with an image format name and a colon (i.e. ps:image) or specify the
  125. %  image type as the filename suffix (i.e. image.ps).  Specify 'file' as
  126. %  '-' for standard input or output.
  127. %
  128. %  Buttons:
  129. %    1    press to map or unmap the Command widget
  130. %    2    press and drag to magnify a region of an image
  131. %    3    press to load an image from a visual image directory
  132. %
  133. %
  134. */
  135.  
  136. /*
  137.   Include declarations.
  138. */
  139. #include "magick.h"
  140. #include "version.h"
  141.  
  142. /*
  143. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  144. %                                                                             %
  145. %                                                                             %
  146. %                                                                             %
  147. %   U s a g e                                                                 %
  148. %                                                                             %
  149. %                                                                             %
  150. %                                                                             %
  151. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  152. %
  153. %  Function Usage displays the program command syntax.
  154. %
  155. %  The format of the Usage routine is:
  156. %
  157. %      Usage(client_name)
  158. %
  159. %  A description of each parameter follows:
  160. %
  161. %    o client_name: a character string representing the name of the client
  162. %      program.
  163. %
  164. */
  165. static void Usage(const char *client_name)
  166. {
  167.   char
  168.     **p;
  169.  
  170.   static char
  171.     *buttons[]=
  172.     {
  173.       "1    press to map or unmap the Command widget",
  174.       "2    press and drag to magnify a region of an image",
  175.       "3    press to load an image from a visual image directory",
  176.       (char *) NULL
  177.     },
  178.     *options[]=
  179.     {
  180.       "-backdrop          display image centered on a backdrop",
  181.       "-border geometry   surround image with a border of color",
  182.       "-colormap type     Shared or Private",
  183.       "-colors value      preferred number of colors in the image",
  184.       "-colorspace type   alternate image colorspace",
  185.       "-comment string    annotate image with comment",
  186.       "-compress type     None, JPEG, LZW, RunlengthEncoded, or Zip",
  187.       "-contrast          enhance or reduce the image contrast",
  188.       "-crop geometry     preferred size and location of the cropped image",
  189.       "-delay value       display the next image after pausing",
  190.       "-density geometry  vertical and horizontal density of the image",
  191.       "-despeckle         reduce the speckles within an image",
  192.       "-display server    display image to this X server",
  193.       "-dispose method    GIF disposal method",
  194.       "-dither            apply Floyd/Steinberg error diffusion to image",
  195.       "-edge factor       apply a filter to detect edges in the image",
  196.       "-enhance           apply a digital filter to enhance a noisy image",
  197.       "-flip              flip image in the vertical direction",
  198.       "-flop              flop image in the horizontal direction",
  199.       "-frame geometry    surround image with an ornamental border",
  200.       "-gamma value       level of gamma correction",
  201.       "-geometry geometry preferred size and location of the Image window",
  202.       "-immutable         displayed image cannot be modified",
  203.       "-interlace type    None, Line, Plane, or Partition",
  204.       "-label name        assign a label to an image",
  205.       "-map type          display image using this Standard Colormap",
  206.       "-matte             store matte channel if the image has one",
  207.       "-monochrome        transform image to black and white",
  208.       "-negate            apply color inversion to image",
  209.       "-page geometry     size and location of an image canvas",
  210.       "-quality value     JPEG/MIFF/PNG compression level",
  211.       "-raise value       lighten/darken image edges to create a 3-D effect",
  212.       "-remote command    execute a command in an remote display process",
  213.       "-roll geometry     roll an image vertically or horizontally",
  214.       "-rotate degrees    apply Paeth rotation to the image",
  215.       "-scene value       image scene number",
  216.       "-segment value     segment an image",
  217.       "-sample geometry   scale image with pixel sampling",
  218.       "-sharpen factor    apply a filter to sharpen the image",
  219.       "-size geometry     width and height of image",
  220.       "-texture filename  name of texture to tile onto the image background",
  221.       "-treedepth value   depth of the color classification tree",
  222.       "-update seconds    detect when image file is modified and redisplay",
  223.       "-verbose           print detailed information about the image",
  224.       "-visual type       display image using this visual type",
  225.       "-window id         display image to background of this window",
  226.       "-window_group id   exit program when this window id is destroyed",
  227.       "-write filename    write image to a file",
  228.       (char *) NULL
  229.     };
  230.  
  231.   (void) printf("Version: %s\n",Version);
  232.   (void) printf("Copyright: %s\n\n",Copyright);
  233.   (void) printf(
  234.     "Usage: %s [-options ...] file [ [-options ...] file ...]\n",client_name);
  235.   (void) printf("\nWhere options include: \n");
  236.   for (p=options; *p != (char *) NULL; p++)
  237.     (void) printf("  %s\n",*p);
  238.   (void) printf(
  239.     "\nIn addition to those listed above, you can specify these standard X\n");
  240.   (void) printf(
  241.     "resources as command line options:  -background, -bordercolor,\n");
  242.   (void) printf(
  243.     "-borderwidth, -font, -foreground, -iconGeometry, -iconic, -mattecolor,\n");
  244.   (void) printf("-name, -shared_memory, -usePixmap, or -title.\n");
  245.   (void) printf(
  246.     "\nBy default, the image format of `file' is determined by its magic\n");
  247.   (void) printf(
  248.     "number.  To specify a particular image format, precede the filename\n");
  249.   (void) printf(
  250.     "with an image format name and a colon (i.e. ps:image) or specify the\n");
  251.   (void) printf(
  252.     "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
  253.   (void) printf("'-' for standard input or output.\n");
  254.   (void) printf("\nButtons: \n");
  255.   for (p=buttons; *p != (char *) NULL; p++)
  256.     (void) printf("  %s\n",*p);
  257.   Exit(0);
  258. }
  259.  
  260. /*
  261. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  262. %                                                                             %
  263. %                                                                             %
  264. %                                                                             %
  265. %    M a i n                                                                  %
  266. %                                                                             %
  267. %                                                                             %
  268. %                                                                             %
  269. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  270. %
  271. %
  272. */
  273.  
  274. #if defined(WIN32)
  275. int WINAPI WinMain(HINSTANCE instance,HINSTANCE last,LPSTR command,int state)
  276. {
  277.   char
  278.     **argv;
  279.  
  280.   int
  281.     argc,
  282.     main(int,char **);
  283.  
  284.   argv=StringToArgv(command,&argc);
  285.   return(main(argc,argv));
  286. }
  287. #endif
  288.  
  289. int main(int argc,char **argv)
  290. {
  291.   char
  292.     *client_name,
  293.     *option,
  294.     *resource_value,
  295.     *server_name;
  296.  
  297.   Display
  298.     *display;
  299.  
  300.   Image
  301.     *image,
  302.     *next_image;
  303.  
  304.   ImageInfo
  305.     *image_info;
  306.  
  307.   int
  308.     status,
  309.     x;
  310.  
  311.   QuantizeInfo
  312.     *quantize_info;
  313.  
  314.   register int
  315.     i,
  316.     j;
  317.  
  318.   unsigned int
  319.     first_scene,
  320.     *image_marker,
  321.     image_number,
  322.     last_scene,
  323.     scene;
  324.  
  325.   unsigned long
  326.     state;
  327.  
  328.   XResourceInfo
  329.     resource_info;
  330.  
  331.   XrmDatabase
  332.     resource_database;
  333.  
  334.   /*
  335.     Set defaults.
  336.   */
  337. #if defined(WIN32)
  338.   SetErrorHandler(NTErrorHandler);
  339.   SetWarningHandler(NTWarningHandler);
  340. #endif
  341.   ReadCommandlLine(argc,&argv);
  342.   client_name=SetClientName(*argv);
  343.   display=(Display *) NULL;
  344.   first_scene=0;
  345.   image=(Image *) NULL;
  346.   image_marker=(unsigned int *) malloc((argc+1)*sizeof(unsigned int));
  347.   if (image_marker == (unsigned int *) NULL)
  348.     MagickError(ResourceLimitError,"Unable to display image",
  349.       "Memory allocation failed");
  350.   for (i=0; i <= argc; i++)
  351.     image_marker[i]=argc;
  352.   image_number=0;
  353.   last_scene=0;
  354.   resource_database=(XrmDatabase) NULL;
  355.   state=DefaultState;
  356.   /*
  357.     Check for server name specified on the command line.
  358.   */
  359.   ExpandFilenames(&argc,&argv);
  360.   server_name=(char *) NULL;
  361.   for (i=1; i < argc; i++)
  362.   {
  363.     /*
  364.       Check command line for server name.
  365.     */
  366.     option=argv[i];
  367.     if ((Extent(option) == 1) || ((*option != '-') && (*option != '+')))
  368.       continue;
  369.     if (strcmp("display",option+1) == 0)
  370.       {
  371.         /*
  372.           User specified server name.
  373.         */
  374.         i++;
  375.         if (i == argc)
  376.           MagickError(OptionError,"Missing server name",option);
  377.         server_name=argv[i];
  378.         break;
  379.       }
  380.     if (strncmp("help",option+1,2) == 0)
  381.       Usage(client_name);
  382.   }
  383.   /*
  384.     Get user defaults from X resource database.
  385.   */
  386.   display=XOpenDisplay(server_name);
  387.   if (display == (Display *) NULL)
  388.     MagickError(XServerError,"Unable to connect to X server",
  389.       XDisplayName(server_name));
  390.   XSetErrorHandler(XError);
  391.   resource_database=XGetResourceDatabase(display,client_name);
  392.   XGetResourceInfo(resource_database,client_name,&resource_info);
  393.   image_info=(&resource_info.image_info);
  394.   image_info->density=
  395.     XGetResourceInstance(resource_database,client_name,"density",(char *) NULL);
  396.   if (image_info->density == (char *) NULL)
  397.     image_info->density=XGetScreenDensity(display);
  398.   resource_value=
  399.     XGetResourceInstance(resource_database,client_name,"interlace","none");
  400.   image_info->interlace=UndefinedInterlace;
  401.   if (Latin1Compare("None",resource_value) == 0)
  402.     image_info->interlace=NoInterlace;
  403.   if (Latin1Compare("Line",resource_value) == 0)
  404.     image_info->interlace=LineInterlace;
  405.   if (Latin1Compare("Plane",resource_value) == 0)
  406.     image_info->interlace=PlaneInterlace;
  407.   if (Latin1Compare("Partition",resource_value) == 0)
  408.     image_info->interlace=PartitionInterlace;
  409.   if (image_info->interlace == UndefinedInterlace)
  410.     MagickWarning(OptionWarning,"Unrecognized interlace type",resource_value);
  411.   image_info->page=XGetResourceInstance(resource_database,client_name,
  412.     "pageGeometry",(char *) NULL);
  413.   resource_value=
  414.     XGetResourceInstance(resource_database,client_name,"quality","75");
  415.   image_info->quality=atoi(resource_value);
  416.   resource_value=
  417.     XGetResourceInstance(resource_database,client_name,"verbose","False");
  418.   image_info->verbose=IsTrue(resource_value);
  419.   quantize_info=(&resource_info.quantize_info);
  420.   /*
  421.     Parse command line.
  422.   */
  423.   for (i=1; ((i <= argc) && !(state & ExitState)); i++)
  424.   {
  425.     if (i < argc)
  426.       option=argv[i];
  427.     else
  428.       if (image_number != 0)
  429.         break;
  430.       else
  431.         if (!isatty(STDIN_FILENO))
  432.           option="-";
  433.         else
  434.           option="logo:Untitled";
  435.     if ((Extent(option) > 1) && ((*option == '-') || (*option == '+')))
  436.       switch (*(option+1))
  437.       {
  438.         case 'b':
  439.         {
  440.           if (strncmp("backdrop",option+1,5) == 0)
  441.             {
  442.               resource_info.backdrop=(*option == '-');
  443.               break;
  444.             }
  445.           if ((strncmp("background",option+1,5) == 0) ||
  446.               (strncmp("bg",option+1,2) == 0))
  447.             {
  448.               resource_info.background_color=(char *) NULL;
  449.               if (*option == '-')
  450.                 {
  451.                   i++;
  452.                   if (i == argc)
  453.                     MagickError(OptionError,"Missing color",option);
  454.                   resource_info.background_color=argv[i];
  455.                 }
  456.               break;
  457.             }
  458.           if (strcmp("border",option+1) == 0)
  459.             {
  460.               if (*option == '-')
  461.                 {
  462.                   i++;
  463.                   if ((i == argc) || !IsGeometry(argv[i]))
  464.                     MagickError(OptionError,"Missing geometry",option);
  465.                 }
  466.               break;
  467.             }
  468.           if (strncmp("bordercolor",option+1,7) == 0)
  469.             {
  470.               resource_info.border_color=(char *) NULL;
  471.               if (*option == '-')
  472.                 {
  473.                   i++;
  474.                   if (i == argc)
  475.                     MagickError(OptionError,"Missing color",option);
  476.                   resource_info.border_color=argv[i];
  477.                 }
  478.               break;
  479.             }
  480.           if (strncmp("borderwidth",option+1,7) == 0)
  481.             {
  482.               resource_info.border_width=0;
  483.               if (*option == '-')
  484.                 {
  485.                   i++;
  486.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  487.                     MagickError(OptionError,"Missing width",option);
  488.                   resource_info.border_width=atoi(argv[i]);
  489.                 }
  490.               break;
  491.             }
  492.           MagickError(OptionError,"Unrecognized option",option);
  493.           break;
  494.         }
  495.         case 'c':
  496.         {
  497.           if (strncmp("colormap",option+1,6) == 0)
  498.             {
  499.               resource_info.colormap=PrivateColormap;
  500.               if (*option == '-')
  501.                 {
  502.                   i++;
  503.                   if (i == argc)
  504.                     MagickError(OptionError,"Missing type",option);
  505.                   option=argv[i];
  506.                   resource_info.colormap=UndefinedColormap;
  507.                   if (Latin1Compare("private",option) == 0)
  508.                     resource_info.colormap=PrivateColormap;
  509.                   if (Latin1Compare("shared",option) == 0)
  510.                     resource_info.colormap=SharedColormap;
  511.                   if (resource_info.colormap == UndefinedColormap)
  512.                     MagickError(OptionError,"Invalid colormap type",option);
  513.                 }
  514.               break;
  515.             }
  516.           if (strncmp("colors",option+1,7) == 0)
  517.             {
  518.               quantize_info->number_colors=0;
  519.               if (*option == '-')
  520.                 {
  521.                   i++;
  522.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  523.                     MagickError(OptionError,"Missing colors",option);
  524.                   quantize_info->number_colors=atoi(argv[i]);
  525.                 }
  526.               break;
  527.             }
  528.           if (strncmp("colorspace",option+1,7) == 0)
  529.             {
  530.               quantize_info->colorspace=RGBColorspace;
  531.               if (*option == '-')
  532.                 {
  533.                   i++;
  534.                   if (i == argc)
  535.                     MagickError(OptionError,"Missing type",option);
  536.                   option=argv[i];
  537.                   quantize_info->colorspace=UndefinedColorspace;
  538.                   if (Latin1Compare("cmyk",option) == 0)
  539.                     quantize_info->colorspace=CMYKColorspace;
  540.                   if (Latin1Compare("gray",option) == 0)
  541.                     {
  542.                       quantize_info->colorspace=GRAYColorspace;
  543.                       quantize_info->number_colors=256;
  544.                       quantize_info->tree_depth=8;
  545.                     }
  546.                   if (Latin1Compare("ohta",option) == 0)
  547.                     quantize_info->colorspace=OHTAColorspace;
  548.                   if (Latin1Compare("rgb",option) == 0)
  549.                     quantize_info->colorspace=RGBColorspace;
  550.                   if (Latin1Compare("transparent",option) == 0)
  551.                     quantize_info->colorspace=TransparentColorspace;
  552.                   if (Latin1Compare("xyz",option) == 0)
  553.                     quantize_info->colorspace=XYZColorspace;
  554.                   if (Latin1Compare("ycbcr",option) == 0)
  555.                     quantize_info->colorspace=YCbCrColorspace;
  556.                   if (Latin1Compare("yiq",option) == 0)
  557.                     quantize_info->colorspace=YIQColorspace;
  558.                   if (Latin1Compare("ypbpr",option) == 0)
  559.                     quantize_info->colorspace=YPbPrColorspace;
  560.                   if (Latin1Compare("yuv",option) == 0)
  561.                     quantize_info->colorspace=YUVColorspace;
  562.                   if (quantize_info->colorspace == UndefinedColorspace)
  563.                     MagickError(OptionError,"Invalid colorspace type",option);
  564.                 }
  565.               break;
  566.             }
  567.           if (strncmp("comment",option+1,4) == 0)
  568.             {
  569.               if (*option == '-')
  570.                 {
  571.                   i++;
  572.                   if (i == argc)
  573.                     MagickError(OptionError,"Missing comment",option);
  574.                 }
  575.               break;
  576.             }
  577.           if (strncmp("compress",option+1,5) == 0)
  578.             {
  579.               image_info->compression=NoCompression;
  580.               if (*option == '-')
  581.                 {
  582.                   i++;
  583.                   if (i == argc)
  584.                     MagickError(OptionError,"Missing type",option);
  585.                   option=argv[i];
  586.                   image_info->compression=UndefinedCompression;
  587.                   if (Latin1Compare("None",option) == 0)
  588.                     image_info->compression=NoCompression;
  589.                   if (Latin1Compare("JPEG",option) == 0)
  590.                     image_info->compression=JPEGCompression;
  591.                   if (Latin1Compare("LZW",option) == 0)
  592.                     image_info->compression=LZWCompression;
  593.                   if (Latin1Compare("RunlengthEncoded",option) == 0)
  594.                     image_info->compression=RunlengthEncodedCompression;
  595.                   if (Latin1Compare("Zip",option) == 0)
  596.                     image_info->compression=ZipCompression;
  597.                   if (image_info->compression == UndefinedCompression)
  598.                     MagickError(OptionError,"Invalid compression type",option);
  599.                 }
  600.               break;
  601.             }
  602.           if (strncmp("contrast",option+1,3) == 0)
  603.             break;
  604.           if (strncmp("crop",option+1,2) == 0)
  605.             {
  606.               if (*option == '-')
  607.                 {
  608.                   i++;
  609.                   if ((i == argc) || !IsGeometry(argv[i]))
  610.                     MagickError(OptionError,"Missing geometry",option);
  611.                 }
  612.               break;
  613.             }
  614.           MagickError(OptionError,"Unrecognized option",option);
  615.           break;
  616.         }
  617.         case 'd':
  618.         {
  619.           if (strncmp("debug",option+1,3) == 0)
  620.             {
  621.               resource_info.debug=(*option == '-');
  622.               break;
  623.             }
  624.           if (strncmp("delay",option+1,3) == 0)
  625.             {
  626.               resource_info.delay=0;
  627.               if (*option == '-')
  628.                 {
  629.                   i++;
  630.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  631.                     MagickError(OptionError,"Missing seconds",option);
  632.                   resource_info.delay=atoi(argv[i]);
  633.                 }
  634.               break;
  635.             }
  636.           if (strncmp("density",option+1,3) == 0)
  637.             {
  638.               image_info->density=(char *) NULL;
  639.               if (*option == '-')
  640.                 {
  641.                   i++;
  642.                   if ((i == argc) || !IsGeometry(argv[i]))
  643.                     MagickError(OptionError,"Missing geometry",option);
  644.                   image_info->density=argv[i];
  645.                 }
  646.               break;
  647.             }
  648.           if (strncmp("despeckle",option+1,3) == 0)
  649.             break;
  650.           if (strcmp("display",option+1) == 0)
  651.             {
  652.               image_info->server_name=(char *) NULL;
  653.               if (*option == '-')
  654.                 {
  655.                   i++;
  656.                   if (i == argc)
  657.                     MagickError(OptionError,"Missing server name",option);
  658.                   image_info->server_name=argv[i];
  659.                 }
  660.               break;
  661.             }
  662.           if (strncmp("dispose",option+1,5) == 0)
  663.             {
  664.               image_info->dispose=(char *) NULL;
  665.               if (*option == '-')
  666.                 {
  667.                   i++;
  668.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  669.                     MagickError(OptionError,"Missing method",option);
  670.                   image_info->dispose=PostscriptGeometry(argv[i]);
  671.                 }
  672.               break;
  673.             }
  674.           if (strncmp("dither",option+1,3) == 0)
  675.             {
  676.               quantize_info->dither=(*option == '-');
  677.               break;
  678.             }
  679.           MagickError(OptionError,"Unrecognized option",option);
  680.           break;
  681.         }
  682.         case 'e':
  683.         {
  684.           if (strncmp("edge",option+1,2) == 0)
  685.             {
  686.               if (*option == '-')
  687.                 {
  688.                   i++;
  689.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  690.                     MagickError(OptionError,"Missing factor",option);
  691.                 }
  692.               break;
  693.             }
  694.           if (strncmp("enhance",option+1,2) == 0)
  695.             break;
  696.           MagickError(OptionError,"Unrecognized option",option);
  697.           break;
  698.         }
  699.         case 'f':
  700.         {
  701.           if (strncmp("flip",option+1,3) == 0)
  702.             break;
  703.           if (strncmp("flop",option+1,3) == 0)
  704.             break;
  705.           if (strncmp("font",option+1,3) == 0)
  706.             {
  707.               image_info->font=(char *) NULL;
  708.               if (*option == '-')
  709.                 {
  710.                   i++;
  711.                   if (i == argc)
  712.                     MagickError(OptionError,"Missing font name",option);
  713.                   image_info->font=argv[i];
  714.                 }
  715.               resource_info.font=image_info->font;
  716.               break;
  717.             }
  718.           if ((strncmp("foreground",option+1,3) == 0) ||
  719.               (strncmp("fg",option+1,2) == 0))
  720.            {
  721.              resource_info.foreground_color=(char *) NULL;
  722.              if (*option == '-')
  723.                {
  724.                  i++;
  725.                  if (i == argc)
  726.                    MagickError(OptionError,"Missing foreground",option);
  727.                  resource_info.foreground_color=argv[i];
  728.                }
  729.               break;
  730.            }
  731.           if (strncmp("frame",option+1,2) == 0)
  732.             {
  733.               if (*option == '-')
  734.                 {
  735.                   i++;
  736.                   if ((i == argc) || !IsGeometry(argv[i]))
  737.                     MagickError(OptionError,"Missing geometry",option);
  738.                 }
  739.               break;
  740.             }
  741.           MagickError(OptionError,"Unrecognized option",option);
  742.           break;
  743.         }
  744.         case 'g':
  745.         {
  746.           if (strncmp("gamma",option+1,2) == 0)
  747.             {
  748.               i++;
  749.               if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  750.                 MagickError(OptionError,"Missing value",option);
  751.               break;
  752.             }
  753.           if (strncmp("geometry",option+1,2) == 0)
  754.             {
  755.               resource_info.image_geometry=(char *) NULL;
  756.               if (*option == '-')
  757.                 {
  758.                   i++;
  759.                   if ((i == argc) || !IsGeometry(argv[i]))
  760.                     MagickError(OptionError,"Missing geometry",option);
  761.                   resource_info.image_geometry=argv[i];
  762.                 }
  763.               break;
  764.             }
  765.           MagickError(OptionError,"Unrecognized option",option);
  766.           break;
  767.         }
  768.         case 'h':
  769.         {
  770.           if (strncmp("help",option+1,2) == 0)
  771.             Usage(client_name);
  772.           MagickError(OptionError,"Unrecognized option",option);
  773.           break;
  774.         }
  775.         case 'i':
  776.         {
  777.           if (strncmp("iconGeometry",option+1,5) == 0)
  778.             {
  779.               resource_info.icon_geometry=(char *) NULL;
  780.               if (*option == '-')
  781.                 {
  782.                   i++;
  783.                   if ((i == argc) || !IsGeometry(argv[i]))
  784.                     MagickError(OptionError,"Missing geometry",option);
  785.                   resource_info.icon_geometry=argv[i];
  786.                 }
  787.               break;
  788.             }
  789.           if (strncmp("iconic",option+1,5) == 0)
  790.             {
  791.               resource_info.iconic=(*option == '-');
  792.               break;
  793.             }
  794.           if (strncmp("immutable",option+1,5) == 0)
  795.             {
  796.               resource_info.immutable=(*option == '-');
  797.               break;
  798.             }
  799.           if (strncmp("interlace",option+1,3) == 0)
  800.             {
  801.               image_info->interlace=NoInterlace;
  802.               if (*option == '-')
  803.                 {
  804.                   i++;
  805.                   if (i == argc)
  806.                     MagickError(OptionError,"Missing type",option);
  807.                   option=argv[i];
  808.                   image_info->interlace=UndefinedInterlace;
  809.                   if (Latin1Compare("None",option) == 0)
  810.                     image_info->interlace=NoInterlace;
  811.                   if (Latin1Compare("Line",option) == 0)
  812.                     image_info->interlace=LineInterlace;
  813.                   if (Latin1Compare("Plane",option) == 0)
  814.                     image_info->interlace=PlaneInterlace;
  815.                   if (Latin1Compare("Partition",option) == 0)
  816.                     image_info->interlace=PartitionInterlace;
  817.                   if (image_info->interlace == UndefinedInterlace)
  818.                     MagickError(OptionError,"Invalid interlace type",option);
  819.                 }
  820.               break;
  821.             }
  822.           MagickError(OptionError,"Unrecognized option",option);
  823.           break;
  824.         }
  825.         case 'l':
  826.         {
  827.           if (strncmp("label",option+1,3) == 0)
  828.             {
  829.               if (*option == '-')
  830.                 {
  831.                   i++;
  832.                   if (i == argc)
  833.                     MagickError(OptionError,"Missing label name",option);
  834.                 }
  835.               break;
  836.             }
  837.           MagickError(OptionError,"Unrecognized option",option);
  838.           break;
  839.         }
  840.         case 'm':
  841.         {
  842.           if (strncmp("magnify",option+1,3) == 0)
  843.             {
  844.               resource_info.magnify=2;
  845.               if (*option == '-')
  846.                 {
  847.                   i++;
  848.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  849.                     MagickError(OptionError,"Missing level",option);
  850.                   resource_info.magnify=atoi(argv[i]);
  851.                 }
  852.               break;
  853.             }
  854.           if (strncmp("map",option+1,3) == 0)
  855.             {
  856.               argv[i]="+sans";
  857.               resource_info.map_type=(char *) NULL;
  858.               if (*option == '-')
  859.                 {
  860.                   argv[i]="-sans";
  861.                   i++;
  862.                   if (i == argc)
  863.                     MagickError(OptionError,"Missing map type",option);
  864.                   resource_info.map_type=argv[i];
  865.                 }
  866.               break;
  867.             }
  868.           if (strcmp("matte",option+1) == 0)
  869.             break;
  870.           if (strncmp("mattecolor",option+1,6) == 0)
  871.             {
  872.               resource_info.matte_color=(char *) NULL;
  873.               if (*option == '-')
  874.                 {
  875.                   i++;
  876.                   if (i == argc)
  877.                     MagickError(OptionError,"Missing color",option);
  878.                   resource_info.matte_color=argv[i];
  879.                 }
  880.               break;
  881.             }
  882.           if (strncmp("monochrome",option+1,3) == 0)
  883.             {
  884.               image_info->monochrome=(*option == '-');
  885.               if (image_info->monochrome)
  886.                 {
  887.                   quantize_info->number_colors=2;
  888.                   quantize_info->tree_depth=8;
  889.                   quantize_info->colorspace=GRAYColorspace;
  890.                 }
  891.               break;
  892.             }
  893.           MagickError(OptionError,"Unrecognized option",option);
  894.           break;
  895.         }
  896.         case 'n':
  897.         {
  898.           if (strncmp("name",option+1,2) == 0)
  899.             {
  900.               resource_info.name=(char *) NULL;
  901.               if (*option == '-')
  902.                 {
  903.                   i++;
  904.                   if (i == argc)
  905.                     MagickError(OptionError,"Missing name",option);
  906.                   resource_info.name=argv[i];
  907.                 }
  908.               break;
  909.             }
  910.           if (strncmp("negate",option+1,2) == 0)
  911.             break;
  912.           MagickError(OptionError,"Unrecognized option",option);
  913.           break;
  914.         }
  915.         case 'p':
  916.         {
  917.           if (strncmp("page",option+1,3) == 0)
  918.             {
  919.               image_info->page=(char *) NULL;
  920.               if (*option == '-')
  921.                 {
  922.                   i++;
  923.                   if (i == argc)
  924.                     MagickError(OptionError,"Missing page geometry",option);
  925.                   image_info->page=PostscriptGeometry(argv[i]);
  926.                 }
  927.               break;
  928.             }
  929.           MagickError(OptionError,"Unrecognized option",option);
  930.           break;
  931.         }
  932.         case 'q':
  933.         {
  934.           if (strncmp("quality",option+1,2) == 0)
  935.             {
  936.               image_info->quality=atoi(DefaultImageQuality);
  937.               if (*option == '-')
  938.                 {
  939.                   i++;
  940.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  941.                     MagickError(OptionError,"Missing quality",option);
  942.                   image_info->quality=atoi(argv[i]);
  943.                 }
  944.               break;
  945.             }
  946.           MagickError(OptionError,"Unrecognized option",option);
  947.           break;
  948.         }
  949.         case 'r':
  950.         {
  951.           if (strncmp("raise",option+1,2) == 0)
  952.             {
  953.               i++;
  954.               if ((i == argc) || !sscanf(argv[i],"%d",&x))
  955.                 MagickError(OptionError,"Missing bevel width",option);
  956.               break;
  957.             }
  958.           if (strncmp("remote",option+1,3) == 0)
  959.             {
  960.               Atom
  961.                 remote_atom;
  962.  
  963.               Window
  964.                 remote_window,
  965.                 root_window;
  966.  
  967.               root_window=XRootWindow(display,XDefaultScreen(display));
  968.               remote_atom=XInternAtom(display,"IM_PROTOCOLS",False);
  969.               remote_window=XWindowByProperty(display,root_window,remote_atom);
  970.               if (remote_window == (Window) NULL)
  971.                 break;
  972.               i++;
  973.               if (i == argc)
  974.                 MagickError(OptionError,"Missing command",option);
  975.               /*
  976.                 Send remote command.
  977.               */
  978.               remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",False);
  979.               XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
  980.                 PropModeReplace,(unsigned char *) argv[i],Extent(argv[i]));
  981.               XSync(display,False);
  982.               Exit(0);
  983.             }
  984.           if (strncmp("roll",option+1,3) == 0)
  985.             {
  986.               if (*option == '-')
  987.                 {
  988.                   i++;
  989.                   if ((i == argc) || !IsGeometry(argv[i]))
  990.                     MagickError(OptionError,"Missing geometry",option);
  991.                 }
  992.               break;
  993.             }
  994.           if (strncmp("rotate",option+1,3) == 0)
  995.             {
  996.               if (*option == '-')
  997.                 {
  998.                   i++;
  999.                   if ((i == argc) || !IsGeometry(argv[i]))
  1000.                     MagickError(OptionError,"Missing degrees",option);
  1001.                 }
  1002.               break;
  1003.             }
  1004.           MagickError(OptionError,"Unrecognized option",option);
  1005.           break;
  1006.         }
  1007.         case 's':
  1008.         {
  1009.           if (strncmp("sample",option+1,2) == 0)
  1010.             {
  1011.               if (*option == '-')
  1012.                 {
  1013.                   i++;
  1014.                   if ((i == argc) || !IsGeometry(argv[i]))
  1015.                     MagickError(OptionError,"Missing geometry",option);
  1016.                 }
  1017.               break;
  1018.             }
  1019.           if (strncmp("scene",option+1,3) == 0)
  1020.             {
  1021.               first_scene=0;
  1022.               last_scene=0;
  1023.               if (*option == '-')
  1024.                 {
  1025.                   i++;
  1026.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1027.                     MagickError(OptionError,"Missing scene number",option);
  1028.                   first_scene=atoi(argv[i]);
  1029.                   last_scene=first_scene;
  1030.                   (void) sscanf(argv[i],"%u-%u",&first_scene,&last_scene);
  1031.                 }
  1032.               break;
  1033.             }
  1034.           if (strncmp("segment",option+1,3) == 0)
  1035.             {
  1036.               if (*option == '-')
  1037.                 {
  1038.                   i++;
  1039.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1040.                     MagickError(OptionError,"Missing threshold",option);
  1041.                 }
  1042.               break;
  1043.             }
  1044.           if (strncmp("sharpen",option+1,5) == 0)
  1045.             {
  1046.               if (*option == '-')
  1047.                 {
  1048.                   i++;
  1049.                   if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1050.                     MagickError(OptionError,"Missing factor",option);
  1051.                 }
  1052.               break;
  1053.             }
  1054.           if (strncmp("shared_memory",option+1,5) == 0)
  1055.             {
  1056.               resource_info.use_shared_memory=(*option == '-');
  1057.               break;
  1058.             }
  1059.           if (strncmp("size",option+1,2) == 0)
  1060.             {
  1061.               image_info->size=(char *) NULL;
  1062.               if (*option == '-')
  1063.                 {
  1064.                   i++;
  1065.                   if ((i == argc) || !IsGeometry(argv[i]))
  1066.                     MagickError(OptionError,"Missing geometry",option);
  1067.                   image_info->size=argv[i];
  1068.                 }
  1069.               break;
  1070.             }
  1071.           MagickError(OptionError,"Unrecognized option",option);
  1072.           break;
  1073.         }
  1074.         case 't':
  1075.         {
  1076.           if (strncmp("text_font",option+1,3) == 0)
  1077.             {
  1078.               resource_info.text_font=(char *) NULL;
  1079.               if (*option == '-')
  1080.                 {
  1081.                   i++;
  1082.                   if (i == argc)
  1083.                     MagickError(OptionError,"Missing font name",option);
  1084.                   resource_info.text_font=argv[i];
  1085.                 }
  1086.               break;
  1087.             }
  1088.           if (strncmp("texture",option+1,5) == 0)
  1089.             {
  1090.               image_info->texture=(char *) NULL;
  1091.               if (*option == '-')
  1092.                 {
  1093.                   i++;
  1094.                   if (i == argc)
  1095.                     MagickError(OptionError,"Missing filename",option);
  1096.                   image_info->texture=argv[i];
  1097.                 }
  1098.               break;
  1099.             }
  1100.           if (strncmp("title",option+1,2) == 0)
  1101.             {
  1102.               resource_info.title=(char *) NULL;
  1103.               if (*option == '-')
  1104.                 {
  1105.                   i++;
  1106.                   if (i == argc)
  1107.                     MagickError(OptionError,"Missing title",option);
  1108.                   resource_info.title=argv[i];
  1109.                 }
  1110.               break;
  1111.             }
  1112.           if (strncmp("treedepth",option+1,3) == 0)
  1113.             {
  1114.               quantize_info->tree_depth=0;
  1115.               if (*option == '-')
  1116.                 {
  1117.                   i++;
  1118.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1119.                     MagickError(OptionError,"Missing depth",option);
  1120.                   quantize_info->tree_depth=atoi(argv[i]);
  1121.                 }
  1122.               break;
  1123.             }
  1124.           MagickError(OptionError,"Unrecognized option",option);
  1125.           break;
  1126.         }
  1127.         case 'u':
  1128.         {
  1129.           if (strncmp("update",option+1,2) == 0)
  1130.             {
  1131.               resource_info.update=(*option == '-');
  1132.               if (*option == '-')
  1133.                 {
  1134.                   i++;
  1135.                   if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1136.                     MagickError(OptionError,"Missing seconds",option);
  1137.                   resource_info.delay=atoi(argv[i]);
  1138.                 }
  1139.               break;
  1140.             }
  1141.           if (strncmp("use_pixmap",option+1,2) == 0)
  1142.             {
  1143.               resource_info.use_pixmap=(*option == '-');
  1144.               break;
  1145.             }
  1146.           MagickError(OptionError,"Unrecognized option",option);
  1147.           break;
  1148.         }
  1149.         case 'v':
  1150.         {
  1151.           if (strncmp("verbose",option+1,2) == 0)
  1152.             {
  1153.               image_info->verbose=(*option == '-');
  1154.               break;
  1155.             }
  1156.           if (strncmp("visual",option+1,3) == 0)
  1157.             {
  1158.               resource_info.visual_type=(char *) NULL;
  1159.               if (*option == '-')
  1160.                 {
  1161.                   i++;
  1162.                   if (i == argc)
  1163.                     MagickError(OptionError,"Missing visual class",option);
  1164.                   resource_info.visual_type=argv[i];
  1165.                 }
  1166.               break;
  1167.             }
  1168.           MagickError(OptionError,"Unrecognized option",option);
  1169.           break;
  1170.         }
  1171.         case 'w':
  1172.         {
  1173.           if (strcmp("window",option+1) == 0)
  1174.             {
  1175.               resource_info.window_id=(char *) NULL;
  1176.               if (*option == '-')
  1177.                 {
  1178.                   i++;
  1179.                   if (i == argc)
  1180.                     MagickError(OptionError,"Missing id, name, or 'root'",
  1181.                       option);
  1182.                   resource_info.window_id=argv[i];
  1183.                 }
  1184.               break;
  1185.             }
  1186.           if (strncmp("window_group",option+1,7) == 0)
  1187.             {
  1188.               resource_info.window_group=(char *) NULL;
  1189.               if (*option == '-')
  1190.                 {
  1191.                   i++;
  1192.                   if (i == argc)
  1193.                     MagickError(OptionError,"Missing id, name, or 'root'",
  1194.                       option);
  1195.                   resource_info.window_group=argv[i];
  1196.                 }
  1197.               break;
  1198.             }
  1199.           if (strncmp("write",option+1,2) == 0)
  1200.             {
  1201.               resource_info.write_filename=(char *) NULL;
  1202.               if (*option == '-')
  1203.                 {
  1204.                   i++;
  1205.                   if (i == argc)
  1206.                     MagickError(OptionError,"Missing file name",option);
  1207.                   resource_info.write_filename=argv[i];
  1208.                   if (IsAccessible(resource_info.write_filename))
  1209.                     {
  1210.                       char
  1211.                         answer[2];
  1212.  
  1213.                       (void) fprintf(stderr,"Overwrite %s? ",
  1214.                         resource_info.write_filename);
  1215.                       (void) fgets(answer,sizeof(answer),stdin);
  1216.                       if (!((*answer == 'y') || (*answer == 'Y')))
  1217.                         Exit(0);
  1218.                     }
  1219.                 }
  1220.               break;
  1221.             }
  1222.           MagickError(OptionError,"Unrecognized option",option);
  1223.           break;
  1224.         }
  1225.         case '?':
  1226.         {
  1227.           Usage(client_name);
  1228.           break;
  1229.         }
  1230.         default:
  1231.         {
  1232.           MagickError(OptionError,"Unrecognized option",option);
  1233.           break;
  1234.         }
  1235.       }
  1236.     else
  1237.       {
  1238.         /*
  1239.           Option is a file name.
  1240.         */
  1241.         for (scene=first_scene; scene <= last_scene ; scene++)
  1242.         {
  1243.           /*
  1244.             Read image.
  1245.           */
  1246.           (void) strcpy(image_info->filename,option);
  1247.           if (first_scene != last_scene)
  1248.             {
  1249.               char
  1250.                 filename[MaxTextExtent];
  1251.  
  1252.               /*
  1253.                 Form filename for multi-part images.
  1254.               */
  1255.               (void) sprintf(filename,image_info->filename,scene);
  1256.               if (strcmp(filename,image_info->filename) == 0)
  1257.                 (void) sprintf(filename,"%s.%u",image_info->filename,scene);
  1258.               (void) strcpy(image_info->filename,filename);
  1259.             }
  1260.           (void) strcpy(image_info->magick,"MIFF");
  1261.           image_info->colorspace=quantize_info->colorspace;
  1262.           image_info->dither=quantize_info->dither;
  1263.           image=ReadImage(image_info);
  1264.           if (image == (Image *) NULL)
  1265.             if ((i < (argc-1)) || (scene < last_scene))
  1266.               continue;
  1267.             else
  1268.               {
  1269.                 state|=ExitState;
  1270.                 break;
  1271.               }
  1272.           do
  1273.           {
  1274.             /*
  1275.               Transmogrify image as defined by the image processing options.
  1276.             */
  1277.             resource_info.quantum=1;
  1278.             MogrifyImage(image_info,i,argv,&image);
  1279.             if (first_scene != last_scene)
  1280.               image->scene=scene;
  1281.             /*
  1282.               Display image to X server.
  1283.             */
  1284.             if (resource_info.window_id != (char *) NULL)
  1285.               {
  1286.                 /*
  1287.                   Display image to a specified X window.
  1288.                 */
  1289.                 status=XDisplayBackgroundImage(display,&resource_info,image);
  1290.                 if (status)
  1291.                   state|=RetainColorsState;
  1292.                 if (resource_info.delay == 0)
  1293.                   state|=ExitState;
  1294.               }
  1295.             else
  1296.               do
  1297.               {
  1298.                 Image
  1299.                   *loaded_image;
  1300.  
  1301.                 /*
  1302.                   Display image to X server.
  1303.                 */
  1304.                 loaded_image=
  1305.                   XDisplayImage(display,&resource_info,argv,argc,&image,&state);
  1306.                 if (loaded_image == (Image *) NULL)
  1307.                   break;
  1308.                 while ((loaded_image != (Image *) NULL) &&
  1309.                        (!(state & ExitState)))
  1310.                 {
  1311.                   if (loaded_image->montage != (char *) NULL)
  1312.                     {
  1313.                       /*
  1314.                         User selected a visual directory image (montage).
  1315.                       */
  1316.                       DestroyImages(image);
  1317.                       image=loaded_image;
  1318.                       break;
  1319.                     }
  1320.                   MogrifyImage(image_info,i,argv,&loaded_image);
  1321.                   if (first_scene != last_scene)
  1322.                     image->scene=scene;
  1323.                   next_image=XDisplayImage(display,&resource_info,argv,argc,
  1324.                     &loaded_image,&state);
  1325.                   if ((next_image == (Image *) NULL) &&
  1326.                       (loaded_image->next != (Image *) NULL))
  1327.                     {
  1328.                       DestroyImages(image);
  1329.                       image=loaded_image->next;
  1330.                       loaded_image=(Image *) NULL;
  1331.                     }
  1332.                   else
  1333.                     {
  1334.                       if (loaded_image != image)
  1335.                         DestroyImages(loaded_image);
  1336.                       loaded_image=next_image;
  1337.                     }
  1338.                 }
  1339.               } while (!(state & ExitState));
  1340.             if (resource_info.write_filename != (char *) NULL)
  1341.               {
  1342.                 /*
  1343.                   Write image.
  1344.                 */
  1345.                 (void) strcpy(image->filename,resource_info.write_filename);
  1346.                 (void) WriteImage(image_info,image);
  1347.               }
  1348.             if (image_info->verbose)
  1349.               DescribeImage(image,stdout,False);
  1350.             /*
  1351.               Proceed to next/previous image.
  1352.             */
  1353.             next_image=image;
  1354.             if (state & FormerImageState)
  1355.               for (j=0; j < resource_info.quantum; j++)
  1356.               {
  1357.                 next_image=next_image->previous;
  1358.                 if (next_image == (Image *) NULL)
  1359.                   break;
  1360.               }
  1361.             else
  1362.               for (j=0; j < resource_info.quantum; j++)
  1363.               {
  1364.                 next_image=next_image->next;
  1365.                 if (next_image == (Image *) NULL)
  1366.                   break;
  1367.               }
  1368.             if (next_image != (Image *) NULL)
  1369.               image=next_image;
  1370.           } while ((next_image != (Image *) NULL) && !(state & ExitState));
  1371.           /*
  1372.             Free image resources.
  1373.           */
  1374.           DestroyImages(image);
  1375.           if (!(state & FormerImageState))
  1376.             image_marker[i]=image_number++;
  1377.           else
  1378.             {
  1379.               /*
  1380.                 Proceed to previous image.
  1381.               */
  1382.               for (i--; i > 0; i--)
  1383.                 if (image_marker[i] == (image_number-2))
  1384.                   break;
  1385.               if (image_number != 0)
  1386.                 image_number--;
  1387.             }
  1388.           if (state & ExitState)
  1389.             break;
  1390.         }
  1391.       }
  1392.     /*
  1393.       Determine if we should proceed to the first image.
  1394.     */
  1395.     if ((i == (argc-1)) || (argc == 1))
  1396.       if (!(state & ExitState))
  1397.         if (resource_info.window_id == (char *) NULL)
  1398.           {
  1399.             i=0;
  1400.             image_number=0;
  1401.           }
  1402.   }
  1403.   if (state & RetainColorsState)
  1404.     {
  1405.       XRetainWindowColors(display,XRootWindow(display,XDefaultScreen(display)));
  1406.       XSync(display,False);
  1407.     }
  1408.   Exit(0);
  1409.   return(False);
  1410. }
  1411.