home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume20 / imagemgc / part25 < prev    next >
Encoding:
Text File  |  1993-07-13  |  50.4 KB  |  1,571 lines

  1. Newsgroups: comp.sources.x
  2. From: cristy@eplrx7.es.duPont.com (Cristy)
  3. Subject: v20i081:  imagemagic - X11 image processing and display, Part25/38
  4. Message-ID: <1993Jul14.232002.22341@sparky.sterling.com>
  5. X-Md4-Signature: 84d3a45eb540f6690e85acca38ba5ec4
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 23:20:02 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: cristy@eplrx7.es.duPont.com (Cristy)
  12. Posting-number: Volume 20, Issue 81
  13. Archive-name: imagemagic/part25
  14. Environment: X11
  15. Supersedes: imagemagic: Volume 13, Issue 17-37
  16.  
  17. #!/bin/sh
  18. # this is magick.25 (part 25 of ImageMagick)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file ImageMagick/display.c continued
  21. #
  22. if test ! -r _shar_seq_.tmp; then
  23.     echo 'Please unpack part 1 first!'
  24.     exit 1
  25. fi
  26. (read Scheck
  27.  if test "$Scheck" != 25; then
  28.     echo Please unpack part "$Scheck" next!
  29.     exit 1
  30.  else
  31.     exit 0
  32.  fi
  33. ) < _shar_seq_.tmp || exit 1
  34. if test ! -f _shar_wnt_.tmp; then
  35.     echo 'x - still skipping ImageMagick/display.c'
  36. else
  37. echo 'x - continuing file ImageMagick/display.c'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/display.c' &&
  39. %                                                                             %
  40. %                                                                             %
  41. %   X T i l e I m a g e W i n d o w                                           %
  42. %                                                                             %
  43. %                                                                             %
  44. %                                                                             %
  45. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  46. %
  47. %  Function XTileImageWindow determines which individual tile of a composite
  48. %  image was choosen with a button press and then displays it.
  49. %
  50. %  The format of the XTileImageWindow routine is:
  51. %
  52. %    tiled_image=XTileImageWindow(display,resource_info,window,image,event)
  53. %
  54. %  A description of each parameter follows:
  55. %
  56. %    o tiled_image:  XTileImageWindow reads the tiled image and returns
  57. %      it.  A null image is returned if an error occurs.
  58. %
  59. %    o display: Specifies a connection to an X server;  returned from
  60. %      XOpenDisplay.
  61. %
  62. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  63. %
  64. %    o window: Specifies a pointer to a XWindows structure.
  65. %
  66. %    o image: Specifies a pointer to a Image structure; returned from
  67. %      ReadImage.
  68. %
  69. %    o event: Specifies a pointer to a XEvent structure.  If it is NULL,
  70. %      the entire image is refreshed.
  71. %
  72. %
  73. */
  74. static Image *XTileImageWindow(display,resource_info,window,image,event)
  75. Display
  76. X  *display;
  77. X
  78. XXResourceInfo
  79. X  *resource_info;
  80. X
  81. XXWindows
  82. X  *window;
  83. X
  84. Image
  85. X  *image;
  86. X
  87. XXEvent
  88. X  *event;
  89. {
  90. X  char
  91. X    filename[2048],
  92. X    text[2048];
  93. X
  94. X  Image
  95. X    *tiled_image;
  96. X
  97. X  int
  98. X    tile,
  99. X    x,
  100. X    y;
  101. X
  102. X  register char
  103. X    *p,
  104. X    *q;
  105. X
  106. X  unsigned int
  107. X    height,
  108. X    width;
  109. X
  110. X  unsigned long
  111. X    scale_factor;
  112. X
  113. X  /*
  114. X    Tile image is relative to composite image configuration.
  115. X  */
  116. X  x=0;
  117. X  y=0;
  118. X  width=image->columns;
  119. X  height=image->rows;
  120. X  if (window->image.clip_geometry != (char *) NULL)
  121. X    (void) XParseGeometry(window->image.clip_geometry,&x,&y,&width,&height);
  122. X  scale_factor=UpShift(width)/window->image.ximage->width;
  123. X  event->xbutton.x+=window->image.x;
  124. X  event->xbutton.x=DownShift(event->xbutton.x*scale_factor)+x;
  125. X  scale_factor=UpShift(height)/window->image.ximage->height;
  126. X  event->xbutton.y+=window->image.y;
  127. X  event->xbutton.y=DownShift(event->xbutton.y*scale_factor)+y;
  128. X  /*
  129. X    Determine size and location of individual tiles of the composite.
  130. X  */
  131. X  x=0;
  132. X  y=0;
  133. X  width=image->columns;
  134. X  height=image->rows;
  135. X  (void) XParseGeometry(image->montage,&x,&y,&width,&height);
  136. X  tile=((event->xbutton.y-y)/height)*((image->columns-x)/width)+
  137. X    (event->xbutton.x-x)/width;
  138. X  if (tile < 0)
  139. X    {
  140. X      /*
  141. X        Button press is outside any tile.
  142. X      */
  143. X      XBell(display,0);
  144. X      return((Image *) NULL);
  145. X    }
  146. X  /*
  147. X    Determine file name from the tile directory.
  148. X  */
  149. X  p=image->directory;
  150. X  while ((tile != 0) && (*p != '\0'))
  151. X  {
  152. X    if (*p == '\n')
  153. X      tile--;
  154. X    p++;
  155. X  }
  156. X  if (*p == '\0')
  157. X    {
  158. X      /*
  159. X        Button press is outside any tile.
  160. X      */
  161. X      XBell(display,0);
  162. X      return((Image *) NULL);
  163. X    }
  164. X  q=p;
  165. X  while ((*q != '\n') && (*q != '\0'))
  166. X    q++;
  167. X  (void) strncpy(filename,p,q-p);
  168. X  filename[q-p]='\0';
  169. X  /*
  170. X    Map info window.
  171. X  */
  172. X  (void) strcpy(text," Loading image... ");
  173. X  XSetWindowExtents(display,&window->info,text);
  174. X  XMapWindow(display,window->info.id);
  175. X  XDisplayInfoString(display,&window->info,text);
  176. X  /*
  177. X    Load tile image.
  178. X  */
  179. X  XDefineCursor(display,window->image.id,window->image.busy_cursor);
  180. X  XFlush(display);
  181. X  (void) strcpy(resource_info->image_info->filename,filename);
  182. X  tiled_image=ReadImage(resource_info->image_info);
  183. X  XDefineCursor(display,window->image.id,window->image.cursor);
  184. X  XWithdrawWindow(display,window->info.id,window->info.screen);
  185. X  if (tiled_image == (Image *) NULL)
  186. X    XPopupAlert(display,&window->popup,"unable to load image",filename);
  187. X  return(tiled_image);
  188. }
  189. X
  190. /*
  191. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  192. %                                                                             %
  193. %                                                                             %
  194. %                                                                             %
  195. %   X S e t C l i p G e o m e t r y                                           %
  196. %                                                                             %
  197. %                                                                             %
  198. %                                                                             %
  199. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  200. %
  201. %  Function XSetClipGeometry accepts a clipping geometry relative to the
  202. %  image window and translates it to a clipping geometry relative to the
  203. %  image.
  204. %
  205. %  The format of the XSetClipGeometry routine is:
  206. %
  207. %    XSetClipGeometry(display,window,clip_info,image)
  208. %
  209. %  A description of each parameter follows:
  210. %
  211. %    o display: Specifies a connection to an X server; returned from
  212. %      XOpenDisplay.
  213. %
  214. %    o window: Specifies a pointer to a XWindows structure.
  215. %
  216. %    o clip_info:  A pointer to a RectangleInfo that defines a region of the
  217. %      image window to clip.
  218. %
  219. %    o image: Specifies a pointer to a Image structure.
  220. %
  221. %
  222. */
  223. static void XSetClipGeometry(display,window,clip_info,image)
  224. Display
  225. X  *display;
  226. X
  227. XXWindows
  228. X  *window;
  229. X
  230. RectangleInfo
  231. X  *clip_info;
  232. X
  233. Image
  234. X  *image;
  235. {
  236. X  char
  237. X    text[2048];
  238. X
  239. X  int
  240. X    x,
  241. X    y;
  242. X
  243. X  unsigned int
  244. X    height,
  245. X    width;
  246. X
  247. X  unsigned long
  248. X    scale_factor;
  249. X
  250. X  /*
  251. X    Display info on clipping rectangle.
  252. X  */
  253. X  (void) sprintf(text," %ux%u+%u+%u ",window->image.width,
  254. X    window->image.height,window->image.width,window->image.height);
  255. X  XSetWindowExtents(display,&window->info,text);
  256. X  XMapWindow(display,window->info.id);
  257. X  (void) sprintf(text," %ux%u%+d%+d",clip_info->width,clip_info->height,
  258. X    clip_info->x,clip_info->y);
  259. X  XDisplayInfoString(display,&window->info,text);
  260. X  /*
  261. X    Clipping geometry is relative to any previous clip geometry.
  262. X  */
  263. X  x=0;
  264. X  y=0;
  265. X  width=image->columns;
  266. X  height=image->rows;
  267. X  if (window->image.clip_geometry != (char *) NULL)
  268. X    (void) XParseGeometry(window->image.clip_geometry,&x,&y,&width,&height);
  269. X  else
  270. X    {
  271. X      /*
  272. X        Allocate clip geometry string.
  273. X      */
  274. X      window->image.clip_geometry=(char *) malloc(2048*sizeof(char));
  275. X      if (window->image.clip_geometry == (char *) NULL)
  276. X        Error("unable to clip X image",window->image.name);
  277. X    }
  278. X  /*
  279. X    Define the clip geometry string from the clipping rectangle.
  280. X  */
  281. X  scale_factor=UpShift(width)/window->image.ximage->width;
  282. X  clip_info->x+=window->image.x;
  283. X  if (clip_info->x > 0)
  284. X    x+=DownShift(clip_info->x*scale_factor);
  285. X  width=DownShift(clip_info->width*scale_factor);
  286. X  if (width == 0)
  287. X    width=1;
  288. X  scale_factor=UpShift(height)/window->image.ximage->height;
  289. X  clip_info->y+=window->image.y;
  290. X  if (clip_info->y > 0)
  291. X    y+=DownShift(clip_info->y*scale_factor);
  292. X  height=DownShift(clip_info->height*scale_factor);
  293. X  if (height == 0)
  294. X    height=1;
  295. X  (void) sprintf(window->image.clip_geometry,"%ux%u%+d%+d",width,height,x,y);
  296. }
  297. X
  298. /*
  299. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  300. %                                                                             %
  301. %                                                                             %
  302. %                                                                             %
  303. %   X W r i t e I m a g e W i n d o w                                         %
  304. %                                                                             %
  305. %                                                                             %
  306. %                                                                             %
  307. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  308. %
  309. %  Function XWriteImageWindow writes an image to a file.
  310. %
  311. %  The format of the XWriteImageWindow routine is:
  312. %
  313. %    status=XWriteImageWindow(display,resource_info,window,image)
  314. %
  315. %  A description of each parameter follows:
  316. %
  317. %    o status: Function XWriteImageWindow return True if the image is
  318. %      loaded.  False is returned is there is a memory shortage or if the
  319. %      image fails to load.
  320. %
  321. %    o display: Specifies a connection to an X server; returned from
  322. %      XOpenDisplay.
  323. %
  324. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  325. %
  326. %    o window: Specifies a pointer to a XWindows structure.
  327. %
  328. %    o image: Specifies a pointer to a Image structure;  returned from
  329. %      ReadImage.
  330. %
  331. %
  332. */
  333. static unsigned int XWriteImageWindow(display,resource_info,window,image)
  334. Display
  335. X  *display;
  336. X
  337. XXResourceInfo
  338. X  *resource_info;
  339. X
  340. XXWindows
  341. X  *window;
  342. X
  343. Image
  344. X  **image;
  345. {
  346. X  char
  347. X    filename[2048],
  348. X    text[2048];
  349. X
  350. X  Image
  351. X    *output_image;
  352. X
  353. X  /*
  354. X    Request file name from user.
  355. X  */
  356. X  (void) strcpy(filename,(*image)->filename);
  357. X  if (resource_info->write_filename != (char *) NULL)
  358. X    (void) strcpy(filename,resource_info->write_filename);
  359. X  XPopupQuery(display,&window->popup,"File name:",filename);
  360. X  if (*filename == '\0')
  361. X    return(True);
  362. X  /*
  363. X    Alert user we are busy.
  364. X  */
  365. X  XDefineCursor(display,window->image.id,window->image.busy_cursor);
  366. X  (void) strcpy(text," Writing image... ");
  367. X  XSetWindowExtents(display,&window->info,text);
  368. X  XMapWindow(display,window->info.id);
  369. X  XDisplayInfoString(display,&window->info,text);
  370. X  XFlush(display);
  371. X  /*
  372. X    Copy image before applying image transforms.
  373. X  */
  374. X  (*image)->orphan=True;
  375. X  output_image=CopyImage(*image,(*image)->columns,(*image)->rows,True);
  376. X  (*image)->orphan=False;
  377. X  if (output_image == (Image *) NULL)
  378. X    {
  379. X      XPopupAlert(display,&window->popup,"unable to write X image",
  380. X        window->image.name);
  381. X      XDefineCursor(display,window->image.id,window->image.cursor);
  382. X      XWithdrawWindow(display,window->info.id,window->info.screen);
  383. X      return(False);
  384. X    }
  385. X  if ((window->image.clip_geometry != (char *) NULL) ||
  386. X     (output_image->columns != window->image.ximage->width) ||
  387. X     (output_image->rows != window->image.ximage->height))
  388. X    {
  389. X      char
  390. X        image_geometry[2048];
  391. X
  392. X      /*
  393. X        Clip and/or scale image.
  394. X      */
  395. X      (void) sprintf(image_geometry,"%dx%d",window->image.ximage->width,
  396. X        window->image.ximage->height);
  397. X      TransformImage(&output_image,window->image.clip_geometry,
  398. X        image_geometry,(char *) NULL);
  399. X    }
  400. X  if (resource_info->colorspace == GRAYColorspace)
  401. X    QuantizeImage(output_image,256,8,resource_info->dither,GRAYColorspace,True);
  402. X  if (resource_info->monochrome)
  403. X    QuantizeImage(output_image,2,8,resource_info->dither,GRAYColorspace,True);
  404. X  if (resource_info->number_colors != 0)
  405. X    if ((output_image->class == DirectClass) ||
  406. X        (output_image->colors > resource_info->number_colors))
  407. X      {
  408. X        QuantizeImage(output_image,resource_info->number_colors,
  409. X          resource_info->tree_depth,resource_info->dither,
  410. X          resource_info->colorspace,True);
  411. X        SyncImage(output_image);
  412. X      }
  413. X  (void) strcpy(output_image->filename,filename);
  414. X  (void) WriteImage(resource_info->image_info,output_image);
  415. X  DestroyImage(output_image);
  416. X  XDefineCursor(display,window->image.id,window->image.cursor);
  417. X  XWithdrawWindow(display,window->info.id,window->info.screen);
  418. X  return(True);
  419. }
  420. X
  421. /*
  422. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  423. %                                                                             %
  424. %                                                                             %
  425. %                                                                             %
  426. %    M a i n                                                                  %
  427. %                                                                             %
  428. %                                                                             %
  429. %                                                                             %
  430. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  431. %
  432. %
  433. */
  434. int main(argc,argv)
  435. int
  436. X  argc;
  437. X
  438. char
  439. X  **argv;
  440. {
  441. X  char
  442. X    *clip_geometry,
  443. X    *density,
  444. X    *option,
  445. X    *page_geometry,
  446. X    *resource_value,
  447. X    *scale_geometry,
  448. X    *server_name,
  449. X    *window_id;
  450. X
  451. X  Display
  452. X    *display;
  453. X
  454. X  double
  455. X    gamma;
  456. X
  457. X  int
  458. X    degrees,
  459. X    i,
  460. X    x;
  461. X
  462. X  unsigned int
  463. X    compression,
  464. X    enhance,
  465. X    *image_marker,
  466. X    image_number,
  467. X    interlace,
  468. X    inverse,
  469. X    noise,
  470. X    normalize,
  471. X    quality,
  472. X    reflect,
  473. X    scene,
  474. X    verbose;
  475. X
  476. X  unsigned long
  477. X    state;
  478. X
  479. X  XrmDatabase
  480. X    resource_database,
  481. X    server_database;
  482. X
  483. X  XResourceInfo
  484. X    resource_info;
  485. X
  486. X  /*
  487. X    Display usage profile if there are no command line arguments.
  488. X  */
  489. X  client_name=(*argv);
  490. X  if (argc < 2)
  491. X    Usage(True);
  492. X  /*
  493. X    Set defaults.
  494. X  */
  495. X  display=(Display *) NULL;
  496. X  image_marker=(unsigned int *) malloc(argc*sizeof(unsigned int));
  497. X  if (image_marker == (unsigned int *) NULL)
  498. X    Error("unable to display image","memory allocation failed");
  499. X  for (i=0; i < argc; i++)
  500. X    image_marker[i]=argc;
  501. X  image_number=0;
  502. X  resource_database=(XrmDatabase) NULL;
  503. X  server_name=(char *) NULL;
  504. X  state=DefaultState;
  505. X  window_id=(char *) NULL;
  506. X  /*
  507. X    Check for server name specified on the command line.
  508. X  */
  509. X  for (i=1; i < argc; i++)
  510. X  {
  511. X    /*
  512. X      Check command line for server name.
  513. X    */
  514. X    option=argv[i];
  515. X    if (((int) strlen(option) > 1) && ((*option == '-') || (*option == '+')))
  516. X      if (strncmp("display",option+1,3) == 0)
  517. X        {
  518. X          /*
  519. X            User specified server name.
  520. X          */
  521. X          i++;
  522. X          if (i == argc)
  523. X            Error("missing server name on -display",(char *) NULL);
  524. X          server_name=argv[i];
  525. X          break;
  526. X        }
  527. X  }
  528. X  /*
  529. X    Open X server connection.
  530. X  */
  531. X  display=XOpenDisplay(server_name);
  532. X  if (display == (Display *) NULL)
  533. X    Error("unable to connect to X server",XDisplayName(server_name));
  534. X  /*
  535. X    Set our forgiving error handler.
  536. X  */
  537. X  XSetErrorHandler(XError);
  538. X  /*
  539. X    Initialize resource database.
  540. X  */
  541. X  XrmInitialize();
  542. X  XGetDefault(display,client_name,"dummy");
  543. X  resource_database=XrmGetDatabase(display);
  544. X  resource_value=XResourceManagerString(display);
  545. X  if (resource_value == (char *) NULL)
  546. X    resource_value="";
  547. X  server_database=XrmGetStringDatabase(resource_value);
  548. X  XrmMergeDatabases(server_database,&resource_database);
  549. X  /*
  550. X    Get user defaults from X resource database.
  551. X  */
  552. X  XGetResourceInfo(resource_database,client_name,&resource_info);
  553. X  clip_geometry=
  554. X    XGetResource(resource_database,client_name,"clipGeometry",(char *) NULL);
  555. X  resource_value=XGetResource(resource_database,client_name,"compression",
  556. X    "RunlengthEncoded");
  557. X  if (Latin1Compare("qencoded",resource_value) == 0)
  558. X    compression=QEncodedCompression;
  559. X  else
  560. X    compression=RunlengthEncodedCompression;
  561. X  density=XGetResource(resource_database,client_name,"density",(char *) NULL);
  562. X  resource_value=XGetResource(resource_database,client_name,"enhance","False");
  563. X  enhance=IsTrue(resource_value);
  564. X  resource_value=XGetResource(resource_database,client_name,"gamma","0.0");
  565. X  gamma=atof(resource_value);
  566. X  resource_value=
  567. X    XGetResource(resource_database,client_name,"interlace","none");
  568. X  interlace=UndefinedInterlace;
  569. X  if (Latin1Compare("none",resource_value) == 0)
  570. X    interlace=NoneInterlace;
  571. X  if (Latin1Compare("line",resource_value) == 0)
  572. X    interlace=LineInterlace;
  573. X  if (Latin1Compare("plane",resource_value) == 0)
  574. X    interlace=PlaneInterlace;
  575. X  if (interlace == UndefinedInterlace)
  576. X    Warning("unrecognized interlace type",resource_value);
  577. X  resource_value=XGetResource(resource_database,client_name,"inverse","False");
  578. X  inverse=IsTrue(resource_value);
  579. X  resource_value=XGetResource(resource_database,client_name,"noise","False");
  580. X  noise=IsTrue(resource_value);
  581. X  resource_value=
  582. X    XGetResource(resource_database,client_name,"normalize","False");
  583. X  normalize=IsTrue(resource_value);
  584. X  page_geometry=
  585. X    XGetResource(resource_database,client_name,"pageGeometry",(char *) NULL);
  586. X  resource_value=XGetResource(resource_database,client_name,"quality","75");
  587. X  quality=atoi(resource_value);
  588. X  resource_value=XGetResource(resource_database,client_name,"reflect","False");
  589. X  reflect=IsTrue(resource_value);
  590. X  resource_value=XGetResource(resource_database,client_name,"rotate","0");
  591. X  degrees=atoi(resource_value);
  592. X  scale_geometry=
  593. X    XGetResource(resource_database,client_name,"scaleGeometry",(char *) NULL);
  594. X  resource_value=XGetResource(resource_database,client_name,"scene","0");
  595. X  scene=atoi(resource_value);
  596. X  resource_value=XGetResource(resource_database,client_name,"verbose","False");
  597. X  verbose=IsTrue(resource_value);
  598. X  window_id=
  599. X    XGetResource(resource_database,client_name,"windowId",(char *) NULL);
  600. X  /*
  601. X    Parse command line.
  602. X  */
  603. X  for (i=1; ((i < argc) && !(state & ExitState)); i++)
  604. X  {
  605. X    option=argv[i];
  606. X    if (((int) strlen(option) > 1) && ((*option == '-') || (*option == '+')))
  607. X      switch (*(option+1))
  608. X      {
  609. X        case 'b':
  610. X        {
  611. X          if (strncmp("backdrop",option+1,5) == 0)
  612. X            {
  613. X              resource_info.backdrop=(*option == '-');
  614. X              break;
  615. X            }
  616. X          if (strncmp("background",option+1,5) == 0)
  617. X            {
  618. X              resource_info.background_color=(char *) NULL;
  619. X              if (*option == '-')
  620. X                {
  621. X                  i++;
  622. X                  if (i == argc)
  623. X                    Error("missing color on -background",(char *) NULL);
  624. X                  resource_info.background_color=argv[i];
  625. X                }
  626. X              break;
  627. X            }
  628. X          if (strncmp("bordercolor",option+1,7) == 0)
  629. X            {
  630. X              resource_info.border_color=(char *) NULL;
  631. X              if (*option == '-')
  632. X                {
  633. X                  i++;
  634. X                  if (i == argc)
  635. X                    Error("missing color on -bordercolor",(char *) NULL);
  636. X                  resource_info.border_color=argv[i];
  637. X                }
  638. X              break;
  639. X            }
  640. X          if (strncmp("borderwidth",option+1,7) == 0)
  641. X            {
  642. X              resource_info.border_width=0;
  643. X              if (*option == '-')
  644. X                {
  645. X                  i++;
  646. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  647. X                    Error("missing width on -borderwidth",(char *) NULL);
  648. X                  resource_info.border_width=atoi(argv[i]);
  649. X                }
  650. X              break;
  651. X            }
  652. X          Error("unrecognized option",option);
  653. X          break;
  654. X        }
  655. X        case 'c':
  656. X        {
  657. X          if (strncmp("clip",option+1,2) == 0)
  658. X            {
  659. X              clip_geometry=(char *) NULL;
  660. X              if (*option == '-')
  661. X                {
  662. X                  i++;
  663. X                  if (i == argc)
  664. X                    Error("missing geometry on -clip",(char *) NULL);
  665. X                  clip_geometry=argv[i];
  666. X                }
  667. X              break;
  668. X            }
  669. X          if (strncmp("colormap",option+1,6) == 0)
  670. X            {
  671. X              resource_info.colormap=PrivateColormap;
  672. X              if (*option == '-')
  673. X                {
  674. X                  i++;
  675. X                  if (i == argc)
  676. X                    Error("missing type on -colormap",(char *) NULL);
  677. X                  option=argv[i];
  678. X                  resource_info.colormap=UndefinedColormap;
  679. X                  if (Latin1Compare("private",option) == 0)
  680. X                    resource_info.colormap=PrivateColormap;
  681. X                  if (Latin1Compare("shared",option) == 0)
  682. X                    resource_info.colormap=SharedColormap;
  683. X                  if (resource_info.colormap == UndefinedColormap)
  684. X                    Error("invalid colormap type on -colormap",option);
  685. X                }
  686. X              break;
  687. X            }
  688. X          if (strncmp("colors",option+1,7) == 0)
  689. X            {
  690. X              resource_info.number_colors=0;
  691. X              if (*option == '-')
  692. X                {
  693. X                  i++;
  694. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  695. X                    Error("missing colors on -colors",(char *) NULL);
  696. X                  resource_info.number_colors=atoi(argv[i]);
  697. X                }
  698. X              break;
  699. X            }
  700. X          if (strncmp("colorspace",option+1,7) == 0)
  701. X            {
  702. X              resource_info.colorspace=RGBColorspace;
  703. X              if (*option == '-')
  704. X                {
  705. X                  i++;
  706. X                  if (i == argc)
  707. X                    Error("missing type on -colorspace",(char *) NULL);
  708. X                  option=argv[i];
  709. X                  resource_info.colorspace=UndefinedColorspace;
  710. X                  if (Latin1Compare("gray",option) == 0)
  711. X                    resource_info.colorspace=GRAYColorspace;
  712. X                  if (Latin1Compare("rgb",option) == 0)
  713. X                    resource_info.colorspace=RGBColorspace;
  714. X                  if (Latin1Compare("xyz",option) == 0)
  715. X                    resource_info.colorspace=XYZColorspace;
  716. X                  if (Latin1Compare("ycbcr",option) == 0)
  717. X                    resource_info.colorspace=YCbCrColorspace;
  718. X                  if (Latin1Compare("yiq",option) == 0)
  719. X                    resource_info.colorspace=YIQColorspace;
  720. X                  if (Latin1Compare("yuv",option) == 0)
  721. X                    resource_info.colorspace=YUVColorspace;
  722. X                  if (resource_info.colorspace == UndefinedColorspace)
  723. X                    Error("invalid colorspace type on -colorspace",option);
  724. X                }
  725. X              break;
  726. X            }
  727. X          if (strncmp("compress",option+1,3) == 0)
  728. X            {
  729. X              compression=NoCompression;
  730. X              if (*option == '-')
  731. X                {
  732. X                  i++;
  733. X                  if (i == argc)
  734. X                    Error("missing type on -compress",(char *) NULL);
  735. X                  option=argv[i];
  736. X                  if (Latin1Compare("runlengthencoded",option) == 0)
  737. X                    compression=RunlengthEncodedCompression;
  738. X                  else
  739. X                    if (Latin1Compare("qencoded",option) == 0)
  740. X                      compression=QEncodedCompression;
  741. X                    else
  742. X                      Error("invalid compression type on -compress",option);
  743. X                }
  744. X              break;
  745. X            }
  746. X          Error("unrecognized option",option);
  747. X          break;
  748. X        }
  749. X        case 'd':
  750. X        {
  751. X          if (strncmp("debug",option+1,3) == 0)
  752. X            {
  753. X              resource_info.debug=(*option == '-');
  754. X              break;
  755. X            }
  756. X          if (strncmp("delay",option+1,3) == 0)
  757. X            {
  758. X              resource_info.delay=0;
  759. X              if (*option == '-')
  760. X                {
  761. X                  i++;
  762. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  763. X                    Error("missing seconds on -delay",(char *) NULL);
  764. X                  resource_info.delay=atoi(argv[i]);
  765. X                }
  766. X              break;
  767. X            }
  768. X          if (strncmp("density",option+1,3) == 0)
  769. X            {
  770. X              density=(char *) NULL;
  771. X              if (*option == '-')
  772. X                {
  773. X                  i++;
  774. X                  if (i == argc)
  775. X                    Error("missing geometry on -density",(char *) NULL);
  776. X                  density=argv[i];
  777. X                }
  778. X              break;
  779. X            }
  780. X          if (strncmp("display",option+1,3) == 0)
  781. X            {
  782. X              server_name=(char *) NULL;
  783. X              if (*option == '-')
  784. X                {
  785. X                  i++;
  786. X                  if (i == argc)
  787. X                    Error("missing server name on -display",(char *) NULL);
  788. X                  server_name=argv[i];
  789. X                }
  790. X              resource_info.server_name=server_name;
  791. X              break;
  792. X            }
  793. X          if (strncmp("dither",option+1,3) == 0)
  794. X            {
  795. X              resource_info.dither=(*option == '-');
  796. X              break;
  797. X            }
  798. X          Error("unrecognized option",option);
  799. X          break;
  800. X        }
  801. X        case 'e':
  802. X        {
  803. X          if (strncmp("enhance",option+1,2) == 0)
  804. X            {
  805. X              enhance=(*option == '-');
  806. X              break;
  807. X            }
  808. X          Error("unrecognized option",option);
  809. X          break;
  810. X        }
  811. X        case 'f':
  812. X        {
  813. X          if (strncmp("font",option+1,3) == 0)
  814. X            {
  815. X              resource_info.font=(char *) NULL;
  816. X              if (*option == '-')
  817. X                {
  818. X                  i++;
  819. X                  if (i == argc)
  820. X                    Error("missing font name on -font",(char *) NULL);
  821. X                  resource_info.font=argv[i];
  822. X                }
  823. X              break;
  824. X            }
  825. X         if (strncmp("foreground",option+1,3) == 0)
  826. X           {
  827. X             resource_info.foreground_color=(char *) NULL;
  828. X             if (*option == '-')
  829. X               {
  830. X                 i++;
  831. X                 if (i == argc)
  832. X                   Error("missing foreground on -foreground",(char *) NULL);
  833. X                 resource_info.foreground_color=argv[i];
  834. X               }
  835. X              break;
  836. X           }
  837. X          Error("unrecognized option",option);
  838. X          break;
  839. X        }
  840. X        case 'g':
  841. X        {
  842. X          if (strncmp("gamma",option+1,2) == 0)
  843. X            {
  844. X              gamma=0.0;
  845. X              if (*option == '-')
  846. X                {
  847. X                  i++;
  848. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  849. X                    Error("missing gamma on -gamma",(char *) NULL);
  850. X                  gamma=atof(argv[i]);
  851. X                }
  852. X              break;
  853. X            }
  854. X          if (strncmp("geometry",option+1,2) == 0)
  855. X            {
  856. X              resource_info.image_geometry=(char *) NULL;
  857. X              if (*option == '-')
  858. X                {
  859. X                  i++;
  860. X                  if (i == argc)
  861. X                    Error("missing geometry on -geometry",(char *) NULL);
  862. X                  resource_info.image_geometry=argv[i];
  863. X                }
  864. X              break;
  865. X            }
  866. X          Error("unrecognized option",option);
  867. X          break;
  868. X        }
  869. X        case 'h':
  870. X        {
  871. X          Usage(True);
  872. X          break;
  873. X        }
  874. X        case 'i':
  875. X        {
  876. X          if (strncmp("iconGeometry",option+1,5) == 0)
  877. X            {
  878. X              resource_info.icon_geometry=(char *) NULL;
  879. X              if (*option == '-')
  880. X                {
  881. X                  i++;
  882. X                  if (i == argc)
  883. X                    Error("missing geometry on -iconGeometry",(char *) NULL);
  884. X                  resource_info.icon_geometry=argv[i];
  885. X                }
  886. X              break;
  887. X            }
  888. X          if (strncmp("iconic",option+1,5) == 0)
  889. X            {
  890. X              resource_info.iconic=(*option == '-');
  891. X              break;
  892. X            }
  893. X          if (strncmp("interlace",option+1,3) == 0)
  894. X            {
  895. X              interlace=NoneInterlace;
  896. X              if (*option == '-')
  897. X                {
  898. X                  i++;
  899. X                  if (i == argc)
  900. X                    Error("missing type on -interlace",(char *) NULL);
  901. X                  option=argv[i];
  902. X                  interlace=UndefinedInterlace;
  903. X                  if (Latin1Compare("none",option) == 0)
  904. X                    interlace=NoneInterlace;
  905. X                  if (Latin1Compare("line",option) == 0)
  906. X                    interlace=LineInterlace;
  907. X                  if (Latin1Compare("plane",option) == 0)
  908. X                    interlace=PlaneInterlace;
  909. X                  if (interlace == UndefinedInterlace)
  910. X                    Error("invalid interlace type on -interlace",option);
  911. X                }
  912. X              break;
  913. X            }
  914. X          if (strncmp("inverse",option+1,2) == 0)
  915. X            {
  916. X              inverse=(*option == '-');
  917. X              break;
  918. X            }
  919. X          Error("unrecognized option",option);
  920. X          break;
  921. X        }
  922. X        case 'm':
  923. X        {
  924. X          if (strncmp("magnify",option+1,3) == 0)
  925. X            {
  926. X              resource_info.magnify=2;
  927. X              if (*option == '-')
  928. X                {
  929. X                  i++;
  930. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  931. X                    Error("missing level on -magnify",(char *) NULL);
  932. X                  resource_info.magnify=atoi(argv[i]);
  933. X                }
  934. X              break;
  935. X            }
  936. X          if (strncmp("map",option+1,3) == 0)
  937. X            {
  938. X              resource_info.map_type=(char *) NULL;
  939. X              if (*option == '-')
  940. X                {
  941. X                  i++;
  942. X                  if (i == argc)
  943. X                    Error("missing map type on -map",(char *) NULL);
  944. X                  resource_info.map_type=argv[i];
  945. X                }
  946. X              break;
  947. X            }
  948. X          if (strncmp("monochrome",option+1,2) == 0)
  949. X            {
  950. X              resource_info.monochrome=(*option == '-');
  951. X              break;
  952. X            }
  953. X          Error("unrecognized option",option);
  954. X          break;
  955. X        }
  956. X        case 'n':
  957. X        {
  958. X          if (strncmp("name",option+1,2) == 0)
  959. X            {
  960. X              resource_info.name=(char *) NULL;
  961. X              if (*option == '-')
  962. X                {
  963. X                  i++;
  964. X                  if (i == argc)
  965. X                    Error("missing name on -name",(char *) NULL);
  966. X                  resource_info.name=argv[i];
  967. X                }
  968. X              break;
  969. X            }
  970. X          if (strncmp("noise",option+1,3) == 0)
  971. X            {
  972. X              noise=(*option == '-');
  973. X              break;
  974. X            }
  975. X          if (strncmp("normalize",option+1,3) == 0)
  976. X            {
  977. X              normalize=(*option == '-');
  978. X              break;
  979. X            }
  980. X          Error("unrecognized option",option);
  981. X          break;
  982. X        }
  983. X        case 'p':
  984. X        {
  985. X          if (strncmp("page",option+1,2) == 0)
  986. X            {
  987. X              page_geometry=(char *) NULL;
  988. X              if (*option == '-')
  989. X                {
  990. X                  i++;
  991. X                  if (i == argc)
  992. X                    Error("missing page geometry on -page",(char *) NULL);
  993. X                  page_geometry=argv[i];
  994. X                }
  995. X              break;
  996. X            }
  997. X          Error("unrecognized option",option);
  998. X          break;
  999. X        }
  1000. X        case 'q':
  1001. X        {
  1002. X          i++;
  1003. X          if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1004. X            Error("missing quality on -quality",(char *) NULL);
  1005. X          quality=atoi(argv[i]);;
  1006. X          break;
  1007. X        }
  1008. X        case 'r':
  1009. X        {
  1010. X          if (strncmp("reflect",option+1,2) == 0)
  1011. X            {
  1012. X              reflect=(*option == '-');
  1013. X              break;
  1014. X            }
  1015. X          if (strncmp("rotate",option+1,3) == 0)
  1016. X            {
  1017. X              degrees=0;
  1018. X              if (*option == '-')
  1019. X                {
  1020. X                  i++;
  1021. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1022. X                    Error("missing degrees on -rotate",(char *) NULL);
  1023. X                  degrees=atoi(argv[i]);
  1024. X                }
  1025. X              break;
  1026. X            }
  1027. X          Error("unrecognized option",option);
  1028. X          break;
  1029. X        }
  1030. X        case 's':
  1031. X        {
  1032. X          if (strncmp("scale",option+1,3) == 0)
  1033. X            {
  1034. X              scale_geometry=(char *) NULL;
  1035. X              if (*option == '-')
  1036. X                {
  1037. X                  i++;
  1038. X                  if ((i == argc) || !sscanf(argv[i],"%f",(float *) &x))
  1039. X                    Error("missing scale geometry on -scale",(char *) NULL);
  1040. X                  scale_geometry=argv[i];
  1041. X                }
  1042. X              break;
  1043. X            }
  1044. X          if (strncmp("scene",option+1,3) == 0)
  1045. X            {
  1046. X              scene=0;
  1047. X              if (*option == '-')
  1048. X                {
  1049. X                  i++;
  1050. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1051. X                    Error("missing scene number on -scene",(char *) NULL);
  1052. X                  scene=atoi(argv[i]);
  1053. X                }
  1054. X              break;
  1055. X            }
  1056. X          Error("unrecognized option",option);
  1057. X          break;
  1058. X        }
  1059. X        case 't':
  1060. X        {
  1061. X          if (strncmp("title",option+1,2) == 0)
  1062. X            {
  1063. X              resource_info.title=(char *) NULL;
  1064. X              if (*option == '-')
  1065. X                {
  1066. X                  i++;
  1067. X                  if (i == argc)
  1068. X                    Error("missing title on -title",(char *) NULL);
  1069. X                  resource_info.title=argv[i];
  1070. X                }
  1071. X              break;
  1072. X            }
  1073. X          if (strncmp("treedepth",option+1,2) == 0)
  1074. X            {
  1075. X              resource_info.tree_depth=0;
  1076. X              if (*option == '-')
  1077. X                {
  1078. X                  i++;
  1079. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1080. X                    Error("missing depth on -treedepth",(char *) NULL);
  1081. X                  resource_info.tree_depth=atoi(argv[i]);
  1082. X                }
  1083. X              break;
  1084. X            }
  1085. X          Error("unrecognized option",option);
  1086. X          break;
  1087. X        }
  1088. X        case 'u':
  1089. X        {
  1090. X          if (strncmp("update",option+1,2) == 0)
  1091. X            {
  1092. X              resource_info.update=(*option == '-');
  1093. X              if (*option == '-')
  1094. X                {
  1095. X                  i++;
  1096. X                  if ((i == argc) || !sscanf(argv[i],"%d",&x))
  1097. X                    Error("missing seconds on -update",(char *) NULL);
  1098. X                  resource_info.delay=atoi(argv[i]);
  1099. X                }
  1100. X              break;
  1101. X            }
  1102. X          if (strncmp("use_pixmap",option+1,2) == 0)
  1103. X            {
  1104. X              resource_info.use_pixmap=(*option == '-');
  1105. X              break;
  1106. X            }
  1107. X          Error("unrecognized option",option);
  1108. X          break;
  1109. X        }
  1110. X        case 'v':
  1111. X        {
  1112. X          if (strncmp("verbose",option+1,2) == 0)
  1113. X            {
  1114. X              verbose=(*option == '-');
  1115. X              break;
  1116. X            }
  1117. X          if (strncmp("visual",option+1,2) == 0)
  1118. X            {
  1119. X              resource_info.visual_type=(char *) NULL;
  1120. X              if (*option == '-')
  1121. X                {
  1122. X                  i++;
  1123. X                  if (i == argc)
  1124. X                    Error("missing visual class on -visual",(char *) NULL);
  1125. X                  resource_info.visual_type=argv[i];
  1126. X                }
  1127. X              break;
  1128. X            }
  1129. X          Error("unrecognized option",option);
  1130. X          break;
  1131. X        }
  1132. X        case 'w':
  1133. X        {
  1134. X          if (strncmp("window",option+1,2) == 0)
  1135. X            {
  1136. X              window_id=(char *) NULL;
  1137. X              if (*option == '-')
  1138. X                {
  1139. X                  i++;
  1140. X                  if (i == argc)
  1141. X                    Error("missing id, name, or 'root' on -window",
  1142. X                      (char *) NULL);
  1143. X                  window_id=argv[i];
  1144. X                }
  1145. X              break;
  1146. X            }
  1147. X          if (strncmp("write",option+1,2) == 0)
  1148. X            {
  1149. X              resource_info.write_filename=(char *) NULL;
  1150. X              if (*option == '-')
  1151. X                {
  1152. X                  i++;
  1153. X                  if (i == argc)
  1154. X                    Error("missing file name on -write",(char *) NULL);
  1155. X                  resource_info.write_filename=argv[i];
  1156. X                  if (access(resource_info.write_filename,0) == 0)
  1157. X                    {
  1158. X                      char
  1159. X                        answer[2];
  1160. X
  1161. X                      (void) fprintf(stderr,"Overwrite %s? ",
  1162. X                        resource_info.write_filename);
  1163. X                      (void) gets(answer);
  1164. X                      if (!((*answer == 'y') || (*answer == 'Y')))
  1165. X                        exit(1);
  1166. X                    }
  1167. X                }
  1168. X              break;
  1169. X            }
  1170. X          Error("unrecognized option",option);
  1171. X          break;
  1172. X        }
  1173. X        default:
  1174. X        {
  1175. X          Error("unrecognized option",option);
  1176. X          break;
  1177. X        }
  1178. X      }
  1179. X    else
  1180. X      {
  1181. X        double
  1182. X          normalized_maximum_error,
  1183. X          normalized_mean_error;
  1184. X
  1185. X        Image
  1186. X          *image,
  1187. X          info_image,
  1188. X          *next_image;
  1189. X
  1190. X        ImageInfo
  1191. X          image_info;
  1192. X
  1193. X        time_t
  1194. X          start_time;
  1195. X
  1196. X        unsigned int
  1197. X          mean_error_per_pixel;
  1198. X
  1199. X        unsigned long
  1200. X          total_colors;
  1201. X
  1202. X        /*
  1203. X          Option is a file name: begin by reading image from specified file.
  1204. X        */
  1205. X        start_time=time((time_t *) NULL);
  1206. X        GetImageInfo(&image_info);
  1207. X        (void) strcpy(image_info.filename,option);
  1208. X        image_info.server_name=resource_info.server_name;
  1209. X        image_info.font=resource_info.font;
  1210. X        image_info.geometry=resource_info.image_geometry;
  1211. X        image_info.page=page_geometry;
  1212. X        image_info.density=density;
  1213. X        image_info.border_color=resource_info.border_color;
  1214. X        image_info.interlace=interlace;
  1215. X        image_info.monochrome=resource_info.monochrome;
  1216. X        image_info.quality=quality;
  1217. X        image_info.verbose=verbose;
  1218. X        resource_info.image_info=(&image_info);
  1219. X        image=ReadImage(&image_info);
  1220. X        if (image == (Image *) NULL)
  1221. X          if (*option == '-')
  1222. X            break;
  1223. X          else
  1224. X            continue;
  1225. X        do
  1226. X        {
  1227. X          info_image=(*image);
  1228. X          if (scene != 0)
  1229. X            image->scene=scene;
  1230. X          total_colors=0;
  1231. X          /*
  1232. X            Transform image as defined by the clip, image and scale geometries.
  1233. X          */
  1234. X          TransformImage(&image,clip_geometry,resource_info.image_geometry,
  1235. X            scale_geometry);
  1236. X          if (reflect)
  1237. X            {
  1238. X              Image
  1239. X                *reflected_image;
  1240. X
  1241. X              /*
  1242. X                Reverse image scanlines.
  1243. X              */
  1244. X              reflected_image=ReflectImage(image);
  1245. X              if (reflected_image != (Image *) NULL)
  1246. X                {
  1247. X                  DestroyImage(image);
  1248. X                  image=reflected_image;
  1249. X                }
  1250. X            }
  1251. X          if ((degrees % 360) != 0)
  1252. X            {
  1253. X              Image
  1254. X                *rotated_image;
  1255. X
  1256. X              /*
  1257. X                Rotate image.
  1258. X              */
  1259. X              rotated_image=RotateImage(image,(double) degrees,False);
  1260. X              if (rotated_image != (Image *) NULL)
  1261. X                {
  1262. X                  DestroyImage(image);
  1263. X                  image=rotated_image;
  1264. X                }
  1265. X            }
  1266. X          if (enhance)
  1267. X            {
  1268. X              Image
  1269. X                *enhanced_image;
  1270. X
  1271. X              /*
  1272. X                Enhance image.
  1273. X              */
  1274. X              enhanced_image=EnhanceImage(image);
  1275. X              if (enhanced_image != (Image *) NULL)
  1276. X                {
  1277. X                  DestroyImage(image);
  1278. X                  image=enhanced_image;
  1279. X                }
  1280. X            }
  1281. X          if (noise)
  1282. X            {
  1283. X              Image
  1284. X                *noisy_image;
  1285. X
  1286. X              /*
  1287. X                Reduce noise in image.
  1288. X              */
  1289. X              noisy_image=NoisyImage(image);
  1290. X              if (noisy_image != (Image *) NULL)
  1291. X                {
  1292. X                  DestroyImage(image);
  1293. X                  image=noisy_image;
  1294. X                }
  1295. X            }
  1296. X          if (gamma > 0.0)
  1297. X            GammaImage(image,gamma);
  1298. X          if (inverse)
  1299. X            InverseImage(image);
  1300. X          if (normalize)
  1301. X            NormalizeImage(image);
  1302. X          if (resource_info.monochrome)
  1303. X            QuantizeImage(image,2,8,resource_info.dither,GRAYColorspace,True);
  1304. X          if (resource_info.colorspace == GRAYColorspace)
  1305. X            QuantizeImage(image,256,8,resource_info.dither,GRAYColorspace,True);
  1306. X          if (resource_info.number_colors != 0)
  1307. X            if ((image->class == DirectClass) ||
  1308. X                (image->colors > resource_info.number_colors))
  1309. X              {
  1310. X                /*
  1311. X                  Reduce the number of colors in the image.
  1312. X                */
  1313. X                QuantizeImage(image,resource_info.number_colors,
  1314. X                  resource_info.tree_depth,resource_info.dither,
  1315. X                  resource_info.colorspace,True);
  1316. X                if (verbose)
  1317. X                  {
  1318. X                    /*
  1319. X                      Measure quantization error.
  1320. X                    */
  1321. X                    QuantizationError(image,&mean_error_per_pixel,
  1322. X                      &normalized_mean_error,&normalized_maximum_error);
  1323. X                    total_colors=NumberColors(image,(FILE *) NULL);
  1324. X                  }
  1325. X                SyncImage(image);
  1326. X              }
  1327. X          /*
  1328. X            Display image to X server.
  1329. X          */
  1330. X          if (compression != UndefinedCompression)
  1331. X            image->compression=compression;
  1332. X          else
  1333. X            image->compression=info_image.compression;
  1334. X          if (window_id != (char *) NULL)
  1335. X            {
  1336. X              /*
  1337. X                Display image to a specified X window.
  1338. X              */
  1339. X              XDisplayBackgroundImage(display,&resource_info,window_id,image);
  1340. X              state&=ExitState;
  1341. X            }
  1342. X          else
  1343. X            do
  1344. X            {
  1345. X              Image
  1346. X                *loaded_image;
  1347. X
  1348. X              /*
  1349. X                Display montage image.
  1350. X              */
  1351. X              loaded_image=
  1352. X                XDisplayImage(display,&resource_info,argv,argc,&image,&state);
  1353. X              if (loaded_image == (Image *) NULL)
  1354. X                break;
  1355. X              while ((loaded_image != (Image *) NULL) && (!(state & ExitState)))
  1356. X              {
  1357. X                next_image=XDisplayImage(display,&resource_info,argv,argc,
  1358. X                  &loaded_image,&state);
  1359. X                DestroyImage(loaded_image);
  1360. X                loaded_image=next_image;
  1361. X              }
  1362. X            } while (!(state & ExitState));
  1363. X          if (resource_info.write_filename != (char *) NULL)
  1364. X            {
  1365. X              /*
  1366. X                Write image.
  1367. X              */
  1368. X              (void) strcpy(image->filename,resource_info.write_filename);
  1369. X              (void) WriteImage(&image_info,image);
  1370. X            }
  1371. X          if (verbose)
  1372. X            {
  1373. X              /*
  1374. X                Display detailed info about the image.
  1375. X              */
  1376. X              (void) fprintf(stderr,"[%u] %s",
  1377. X                image->scene == 0 ? image_number : image->scene,
  1378. X                info_image.filename);
  1379. X              if (resource_info.write_filename != (char *) NULL)
  1380. X                (void) fprintf(stderr,"=>%s",resource_info.write_filename);
  1381. X              (void) fprintf(stderr," %ux%u",info_image.columns,
  1382. X                info_image.rows);
  1383. X              if ((info_image.columns != image->columns) ||
  1384. X                  (info_image.rows != image->rows))
  1385. X                (void) fprintf(stderr,"=>%ux%u",image->columns,image->rows);
  1386. X              if (image->class == DirectClass)
  1387. X                (void) fprintf(stderr," DirectClass ");
  1388. X              else
  1389. X                if (total_colors == 0)
  1390. X                  (void) fprintf(stderr," PseudoClass %uc",image->colors);
  1391. X                else
  1392. X                  {
  1393. X                    (void) fprintf(stderr," PseudoClass %lu=>%uc",total_colors,
  1394. X                      image->colors);
  1395. X                    (void) fprintf(stderr," %u/%.6f/%.6fe",mean_error_per_pixel,
  1396. X                      normalized_mean_error,normalized_maximum_error);
  1397. X                  }
  1398. X              (void) fprintf(stderr," %s %lds\n",image->magick,
  1399. X                time((time_t *) NULL)-start_time+1);
  1400. X            }
  1401. X          /*
  1402. X            Proceed to next/previous image.
  1403. X          */
  1404. X          if (state & LastImageState)
  1405. X            next_image=image->previous;
  1406. X          else
  1407. X            next_image=image->next;
  1408. X          if (next_image != (Image *) NULL)
  1409. X            image=next_image;
  1410. X        } while ((next_image != (Image *) NULL) && !(state & ExitState));
  1411. X        /*
  1412. X          Free image resources.
  1413. X        */
  1414. X        DestroyImages(image);
  1415. X        if (!(state & LastImageState))
  1416. X          image_marker[i]=image_number++;
  1417. X        else
  1418. X          {
  1419. X            /*
  1420. X              Proceed to previous image.
  1421. X            */
  1422. X            for (i--; i > 0; i--)
  1423. X              if (image_marker[i] == (image_number-2))
  1424. X                break;
  1425. X            if (image_number != 0)
  1426. X              image_number--;
  1427. X          }
  1428. X      }
  1429. X    if (i == (argc-1))
  1430. X      if ((resource_info.delay != 0) && (image_number != 1))
  1431. X        {
  1432. X          /*
  1433. X            Proceed to first image.
  1434. X          */
  1435. X          i=0;
  1436. X          image_number=0;
  1437. X        }
  1438. X  }
  1439. X  if (image_number == 0)
  1440. X    Error("missing an image file name",(char *) NULL);
  1441. X  XCloseDisplay(display);
  1442. X  (void) free((char *) image_marker);
  1443. X  return(False);
  1444. }
  1445. SHAR_EOF
  1446. echo 'File ImageMagick/display.c is complete' &&
  1447. chmod 0644 ImageMagick/display.c ||
  1448. echo 'restore of ImageMagick/display.c failed'
  1449. Wc_c="`wc -c < 'ImageMagick/display.c'`"
  1450. test 202798 -eq "$Wc_c" ||
  1451.     echo 'ImageMagick/display.c: original size 202798, current size' "$Wc_c"
  1452. rm -f _shar_wnt_.tmp
  1453. fi
  1454. # ============= ImageMagick/display.man ==============
  1455. if test -f 'ImageMagick/display.man' -a X"$1" != X"-c"; then
  1456.     echo 'x - skipping ImageMagick/display.man (File already exists)'
  1457.     rm -f _shar_wnt_.tmp
  1458. else
  1459. > _shar_wnt_.tmp
  1460. echo 'x - extracting ImageMagick/display.man (Text)'
  1461. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/display.man' &&
  1462. .ad l
  1463. .nh
  1464. .TH display 1 "10 October 1992" "ImageMagick"
  1465. .SH NAME
  1466. display - display an image on any workstation running X
  1467. .SH SYNOPSIS
  1468. .B "display" [ \fIoptions\fP ...] \fIfile\fP
  1469. [ [ \fIoptions\fP ...] \fIfile\fP ...]
  1470. .SH DESCRIPTION
  1471. \fBdisplay\fP is a machine architecture independent image processing
  1472. and display program.  It can display an image on any workstation
  1473. display running an X server.  \fBdisplay\fP first determines the
  1474. hardware capabilities of the workstation.  If the number of unique
  1475. colors in the image is less than or equal to the number the workstation
  1476. can support, the image is displayed in an X window.  Otherwise the
  1477. number of colors in the image is first reduced to match the color
  1478. resolution of the workstation before it is displayed.
  1479. .PP
  1480. This means that a continuous-tone 24 bits-per-pixel image can display on a
  1481. 8 bit pseudo-color device or monochrome device.  In most instances the
  1482. reduced color image closely resembles the original.  Alternatively, a
  1483. monochrome or pseudo-color image can display on a continuous-tone 24
  1484. bits-per-pixel device.
  1485. .SH EXAMPLES
  1486. To scale an image of a cockatoo to exactly 640 pixels in width and 480
  1487. pixels in height and position the window at location (200,200), use:
  1488. .PP
  1489. .B
  1490. X     display -geometry 640x480\+200\+200 cockatoo.miff
  1491. .PP
  1492. To display an image of a cockatoo without a border centered on a
  1493. backdrop, use:
  1494. .PP
  1495. .B
  1496. X     display +borderwidth -backdrop cockatoo.miff
  1497. .PP
  1498. To tile an image of a cockatoo onto the root window, use:
  1499. .PP
  1500. .B
  1501. X     display -window root cockatoo.miff
  1502. .SH OPTIONS
  1503. .TP 5
  1504. .B "-backdrop"
  1505. display the image centered on a backdrop.
  1506. X
  1507. This backdrop covers the entire workstation screen and is useful for
  1508. hiding other X window activity while viewing the image.   The color of
  1509. the backdrop is specified as the background color.  Refer to \fBX
  1510. RESOURCES\fP for details.
  1511. .TP 5
  1512. .B "-clip \fI<width>x<height>{\+-}<x offset>{\+-}<y offset>\fP"
  1513. preferred size and location of the clipped image.  See \fBX(1)\fP for details
  1514. about the geometry specification.
  1515. X
  1516. Use clipping to apply image processing options to, or display, a
  1517. particular area of an image.
  1518. X
  1519. The equivalent X resource for this option is \fBclipGeometry\fP
  1520. (class \fBClipGeometry\fP).  See \fBX RESOURCES\fP for details.
  1521. .TP 5
  1522. .B "-colormap \fItype\fP"
  1523. the type of colormap: \fBShared\fP or \fBPrivate\fP.
  1524. X
  1525. This option only applies when the default X server visual is
  1526. \fIPseudoColor\fP or \fIGrayScale\fP.  Refer to \fB-visual\fP for more
  1527. details.  By default, a shared colormap is allocated.  The image shares
  1528. colors with other X clients.  Some image colors could be approximated,
  1529. therefore your image may look very different than intended.  Choose
  1530. \fBPrivate\fP and the image colors appear exactly as they are
  1531. defined.  However, other clients may go "technicolor" when the image
  1532. colormap is installed.
  1533. .TP 5
  1534. .B "-colors \fIvalue\fP"
  1535. preferred number of colors in the image.
  1536. X
  1537. The actual number of colors in the image may be less than your request,
  1538. but never more.  Note, this is a color reduction option.  Images with
  1539. less unique colors than specified with this option will remain unchanged.
  1540. Refer to \fBquantize(9)\fP for more details.
  1541. X
  1542. Note, options \fB-dither\fP, \fB-colorspace\fP, and \fB-treedepth\fP affect
  1543. the color reduction algorithm.
  1544. .TP 5
  1545. .B "-colorspace \fIvalue\fP"
  1546. the type of colorspace: \fBGRAY\fP, \fBRGB\fP, \fBXYZ\fP, \fBYCbCr\fP,
  1547. \fBYIQ\fP, or \fBYUV\fP.
  1548. X
  1549. Color reduction, by default, takes place in the RGB color space.
  1550. Empirical evidence suggests that distances in color spaces such as YUV
  1551. or YIQ correspond to perceptual color differences more closely
  1552. than do distances in RGB space.  These color spaces may give better
  1553. results when color reducing an image.  Refer to \fBquantize(9)\fP for
  1554. more details.
  1555. X
  1556. The \fB-colors\fP or \fB-monochrome\fP option is required for this option
  1557. SHAR_EOF
  1558. true || echo 'restore of ImageMagick/display.man failed'
  1559. fi
  1560. echo 'End of ImageMagick part 25'
  1561. echo 'File ImageMagick/display.man is continued in part 26'
  1562. echo 26 > _shar_seq_.tmp
  1563. exit 0
  1564.  
  1565. exit 0 # Just in case...
  1566. -- 
  1567.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1568. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  1569.  "It's intuitively obvious to the |
  1570.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1571.