home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume34 / imagemagick / part18 < prev    next >
Text File  |  1992-12-14  |  58KB  |  1,668 lines

  1. Newsgroups: comp.sources.misc
  2. From: cristy@eplrx7.es.duPont.com (John Cristy)
  3. Subject:  v34i046:  imagemagick - X11 image processing and display v2.2, Part18/26
  4. Message-ID: <1992Dec15.035626.22640@sparky.imd.sterling.com>
  5. X-Md4-Signature: af87bfbfdd9aa5f5609066949479dbc2
  6. Date: Tue, 15 Dec 1992 03:56:26 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: cristy@eplrx7.es.duPont.com (John Cristy)
  10. Posting-number: Volume 34, Issue 46
  11. Archive-name: imagemagick/part18
  12. Environment: UNIX, VMS, X11, SGI, DEC, Cray, Sun, Vax
  13.  
  14. #!/bin/sh
  15. # this is Part.18 (part 18 of a multipart archive)
  16. # do not concatenate these parts, unpack them in order with /bin/sh
  17. # file ImageMagick/X.c continued
  18. #
  19. if test ! -r _shar_seq_.tmp; then
  20.     echo 'Please unpack part 1 first!'
  21.     exit 1
  22. fi
  23. (read Scheck
  24.  if test "$Scheck" != 18; then
  25.     echo Please unpack part "$Scheck" next!
  26.     exit 1
  27.  else
  28.     exit 0
  29.  fi
  30. ) < _shar_seq_.tmp || exit 1
  31. if test ! -f _shar_wnt_.tmp; then
  32.     echo 'x - still skipping ImageMagick/X.c'
  33. else
  34. echo 'x - continuing file ImageMagick/X.c'
  35. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/X.c' &&
  36. %
  37. %  Function XWindowByID locates a child window with a given ID.  If not window
  38. %  with the given name is found, 0 is returned.   Only the window specified
  39. %  and its subwindows are searched.
  40. %
  41. %  The format of the XWindowByID function is:
  42. %
  43. %      child=XWindowByID(display,window,id)
  44. %
  45. %  A description of each parameter follows:
  46. %
  47. %    o child: XWindowByID returns the window with the specified
  48. %      id.  If no windows are found, XWindowByID returns 0.
  49. %
  50. %    o display: Specifies a pointer to the Display structure;  returned from
  51. %      XOpenDisplay.
  52. %
  53. %    o id: Specifies the id of the window to locate.
  54. %
  55. %
  56. */
  57. Window XWindowByID(display,root_window,id)
  58. Display
  59. X  *display;
  60. X
  61. Window
  62. X  root_window;
  63. X
  64. unsigned long
  65. X  id;
  66. {
  67. X  register int
  68. X    i;
  69. X
  70. X  unsigned int
  71. X    number_children;
  72. X
  73. X  Window
  74. X    child,
  75. X    *children,
  76. X    window;
  77. X
  78. X  if (root_window == id)
  79. X    return(id);
  80. X  if (!XQueryTree(display,root_window,&child,&child,&children,&number_children))
  81. X    return((Window) NULL);
  82. X  window=(Window) NULL;
  83. X  for (i=0; i < number_children; i++)
  84. X  {
  85. X    /*
  86. X      Search each child and their children.
  87. X    */
  88. X    window=XWindowByID(display,children[i],id);
  89. X    if (window != (Window) NULL)
  90. X      break;
  91. X  }
  92. X  if (children != (Window *) NULL)
  93. X    XFree((void *) children);
  94. X  return(window);
  95. }
  96. X
  97. /*
  98. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  99. %                                                                             %
  100. %                                                                             %
  101. %                                                                             %
  102. %   X W i n d o w B y N a m e                                                 %
  103. %                                                                             %
  104. %                                                                             %
  105. %                                                                             %
  106. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  107. %
  108. %  Function XWindowByName locates a window with a given name on a display.
  109. %  If no window with the given name is found, 0 is returned. If more than
  110. %  one window has the given name, the first one is returned.  Only root and
  111. %  its children are searched.
  112. %
  113. %  The format of the XWindowByName function is:
  114. %
  115. %      window=XWindowByName(display,root_window,name)
  116. %
  117. %  A description of each parameter follows:
  118. %
  119. %    o window: XWindowByName returns the window id.
  120. %
  121. %    o display: Specifies a pointer to the Display structure;  returned from
  122. %      XOpenDisplay.
  123. %
  124. %    o root_window: Specifies the id of the root window.
  125. %
  126. %    o name: Specifies the name of the window to locate.
  127. %
  128. %
  129. */
  130. Window XWindowByName(display,root_window,name)
  131. Display
  132. X  *display;
  133. X
  134. Window
  135. X  root_window;
  136. X
  137. char
  138. X  *name;
  139. {
  140. X  register int
  141. X    i;
  142. X
  143. X  unsigned int
  144. X    number_children;
  145. X
  146. X  Window
  147. X    *children,
  148. X    child,
  149. X    window;
  150. X
  151. X  XTextProperty
  152. X    window_name;
  153. X
  154. X  if (XGetWMName(display,root_window,&window_name) != 0)
  155. X    if (strcmp((char *) window_name.value,name) == 0)
  156. X      return(root_window);
  157. X  if (!XQueryTree(display,root_window,&child,&child,&children,&number_children))
  158. X    return((Window) NULL);
  159. X  window=(Window) NULL;
  160. X  for (i=0; i < number_children; i++)
  161. X  {
  162. X    /*
  163. X      Search each child and their children.
  164. X    */
  165. X    window=XWindowByName(display,children[i],name);
  166. X    if (window != (Window) NULL)
  167. X      break;
  168. X  }
  169. X  if (children != (Window *) NULL)
  170. X    XFree((void *) children);
  171. X  return(window);
  172. }
  173. X
  174. /*
  175. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  176. %                                                                             %
  177. %                                                                             %
  178. %                                                                             %
  179. %   X W i n d o w B y P r o p e r y                                           %
  180. %                                                                             %
  181. %                                                                             %
  182. %                                                                             %
  183. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  184. %
  185. %  Function XWindowByProperty locates a child window with a given property.
  186. %  If no window with the given name is found, 0 is returned.  If more than
  187. %  one window has the given property, the first one is returned.  Only the
  188. %  window specified and its subwindows are searched.
  189. %
  190. %  The format of the XWindowByProperty function is:
  191. %
  192. %      child=XWindowByProperty(display,window,property)
  193. %
  194. %  A description of each parameter follows:
  195. %
  196. %    o child: XWindowByProperty returns the window id with the specified
  197. %      property.  If no windows are found, XWindowByProperty returns 0.
  198. %
  199. %    o display: Specifies a pointer to the Display structure;  returned from
  200. %      XOpenDisplay.
  201. %
  202. %    o property: Specifies the property of the window to locate.
  203. %
  204. %
  205. */
  206. Window XWindowByProperty(display,window,property)
  207. Display
  208. X  *display;
  209. X
  210. Window
  211. X  window;
  212. X
  213. Atom
  214. X  property;
  215. {
  216. X  Atom
  217. X    type;
  218. X
  219. X  int
  220. X    format,
  221. X    status;
  222. X
  223. X  unsigned char
  224. X    *data;
  225. X
  226. X  unsigned int
  227. X    i,
  228. X    number_children;
  229. X
  230. X  unsigned long
  231. X    after,
  232. X    number_items;
  233. X
  234. X  Window
  235. X    *children,
  236. X    child,
  237. X    parent,
  238. X    root;
  239. X
  240. X  if (XQueryTree(display,window,&root,&parent,&children,&number_children) == 0)
  241. X    return((Window) NULL);
  242. X  type=(Atom) NULL;
  243. X  child=(Window) NULL;
  244. X  for (i=0; (i < number_children) && (child == (Window) NULL); i++)
  245. X  {
  246. X    status=XGetWindowProperty(display,children[i],property,0L,0L,False,
  247. X      (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
  248. X    if ((status == Success) && (type != (Atom) NULL))
  249. X      child=children[i];
  250. X  }
  251. X  for (i=0; (i < number_children) && (child == (Window) NULL); i++)
  252. X    child=XWindowByProperty(display,children[i],property);
  253. X  if (children != (Window *) NULL)
  254. X    XFree((void *) children);
  255. X  return(child);
  256. }
  257. SHAR_EOF
  258. echo 'File ImageMagick/X.c is complete' &&
  259. chmod 0644 ImageMagick/X.c ||
  260. echo 'restore of ImageMagick/X.c failed'
  261. Wc_c="`wc -c < 'ImageMagick/X.c'`"
  262. test 188131 -eq "$Wc_c" ||
  263.     echo 'ImageMagick/X.c: original size 188131, current size' "$Wc_c"
  264. rm -f _shar_wnt_.tmp
  265. fi
  266. # ============= ImageMagick/animate.h ==============
  267. if test -f 'ImageMagick/animate.h' -a X"$1" != X"-c"; then
  268.     echo 'x - skipping ImageMagick/animate.h (File already exists)'
  269.     rm -f _shar_wnt_.tmp
  270. else
  271. > _shar_wnt_.tmp
  272. echo 'x - extracting ImageMagick/animate.h (Text)'
  273. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/animate.h' &&
  274. /*
  275. X  Define declarations.
  276. */
  277. #ifdef SYSV
  278. #include <poll.h>
  279. poll((struct poll *) 0, (size_t) 0, usec / 1000);
  280. #define Delay(milliseconds)  \
  281. X  poll((struct poll *) 0,(size_t) 0,milliseconds/1000);
  282. #else
  283. #ifdef vms
  284. #define Delay(milliseconds)
  285. #else
  286. #define Delay(milliseconds)  \
  287. {  \
  288. X  struct timeval  \
  289. X    timeout;  \
  290. X  \
  291. X  timeout.tv_usec=(milliseconds % 1000)*1000;  \
  292. X  timeout.tv_sec=milliseconds/1000;  \
  293. X  select(0,(void *) 0,(void *) 0,(void *) 0,&timeout);  \
  294. }
  295. #endif
  296. #endif
  297. SHAR_EOF
  298. chmod 0644 ImageMagick/animate.h ||
  299. echo 'restore of ImageMagick/animate.h failed'
  300. Wc_c="`wc -c < 'ImageMagick/animate.h'`"
  301. test 485 -eq "$Wc_c" ||
  302.     echo 'ImageMagick/animate.h: original size 485, current size' "$Wc_c"
  303. rm -f _shar_wnt_.tmp
  304. fi
  305. # ============= ImageMagick/animate.c ==============
  306. if test -f 'ImageMagick/animate.c' -a X"$1" != X"-c"; then
  307.     echo 'x - skipping ImageMagick/animate.c (File already exists)'
  308.     rm -f _shar_wnt_.tmp
  309. else
  310. > _shar_wnt_.tmp
  311. echo 'x - extracting ImageMagick/animate.c (Text)'
  312. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/animate.c' &&
  313. /*
  314. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  315. %                                                                             %
  316. %                                                                             %
  317. %                                                                             %
  318. %              AAA   N   N  IIIII  M   M   AAA   TTTTT  EEEEE                 %
  319. %             A   A  NN  N    I    MM MM  A   A    T    E                     %
  320. %             AAAAA  N N N    I    M M M  AAAAA    T    EEE                   %
  321. %             A   A  N  NN    I    M   M  A   A    T    E                     %
  322. %             A   A  N   N  IIIII  M   M  A   A    T    EEEEE                 %
  323. %                                                                             %
  324. %                                                                             %
  325. %          Animate Machine Independent File Format Image via X11.             %
  326. %                                                                             %
  327. %                                                                             %
  328. %                                                                             %
  329. %                           Software Design                                   %
  330. %                             John Cristy                                     %
  331. %                              July 1992                                      %
  332. %                                                                             %
  333. %                                                                             %
  334. %  Copyright 1992 E. I. du Pont de Nemours & Company                          %
  335. %                                                                             %
  336. %  Permission to use, copy, modify, distribute, and sell this software and    %
  337. %  its documentation for any purpose is hereby granted without fee,           %
  338. %  provided that the above Copyright notice appear in all copies and that     %
  339. %  both that Copyright notice and this permission notice appear in            %
  340. %  supporting documentation, and that the name of E. I. du Pont de Nemours    %
  341. %  & Company not be used in advertising or publicity pertaining to            %
  342. %  distribution of the software without specific, written prior               %
  343. %  permission.  E. I. du Pont de Nemours & Company makes no representations   %
  344. %  about the suitability of this software for any purpose.  It is provided    %
  345. %  "as is" without express or implied warranty.                               %
  346. %                                                                             %
  347. %  E. I. du Pont de Nemours & Company disclaims all warranties with regard    %
  348. %  to this software, including all implied warranties of merchantability      %
  349. %  and fitness, in no event shall E. I. du Pont de Nemours & Company be       %
  350. %  liable for any special, indirect or consequential damages or any           %
  351. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  352. %  in an action of contract, negligence or other tortious action, arising     %
  353. %  out of or in connection with the use or performance of this software.      %
  354. %                                                                             %
  355. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  356. %
  357. %  Animate displays a sequence of images in the MIFF format on any
  358. %  workstation display running an X server.  Animate first determines the
  359. %  hardware capabilities of the workstation.  If the number of unique
  360. %  colors in an image is less than or equal to the number the workstation
  361. %  can support, the image is displayed in an X window.  Otherwise the
  362. %  number of colors in the image is first reduced to match the color
  363. %  resolution of the workstation before it is displayed.
  364. %
  365. %  This means that a continuous-tone 24 bits-per-pixel image can display on a
  366. %  8 bit pseudo-color device or monochrome device.  In most instances the
  367. %  reduced color image closely resembles the original.  Alternatively, a
  368. %  monochrome or pseudo-color image can display on a continuous-tone 24
  369. %  bits-per-pixel device.
  370. %
  371. %  The Animate program command syntax is:
  372. %
  373. %  Usage: animate [options ...] file [ [options ...] file ...]
  374. %
  375. %  Where options include:
  376. %    -backdrop            display image centered on a backdrop
  377. %    -clip geometry       preferred size and location of the clipped image
  378. %    -colormap type       Shared or Private
  379. %    -colors value        preferred number of colors in the image
  380. %    -colorspace type     GRAY, RGB, XYZ, YIQ, or YUV
  381. %    -delay milliseconds  display the next image after pausing
  382. %    -density geometry    vertical and horizonal density of the image
  383. %    -display server      display image to this X server
  384. %    -dither              apply Floyd/Steinberg error diffusion to image
  385. %    -gamma value         level of gamma correction
  386. %    -geometry geometry   preferred size and location of the image window
  387. %    -map type            display image using this Standard Colormap
  388. %    -monochrome          transform image to black and white
  389. %    -reflect             reverse image scanlines
  390. %    -rotate degrees      apply Paeth rotation to the image
  391. %    -scale geometry      preferred size factors of the image
  392. %    -treedepth value     depth of the color classification tree
  393. %    -verbose             print detailed information about the image
  394. %    -visual type         display image using this visual type
  395. %
  396. %  In addition to those listed above, you can specify these standard X
  397. %  resources as command line options:  -background, -bordercolor,
  398. %  -borderwidth, -font, -foreground, -iconGeometry, -iconic, -name, or
  399. %  -title.
  400. %
  401. %  Change '-' to '+' in any option above to reverse its effect.  For
  402. %  example, specify +compress to store the image as uncompressed.
  403. %
  404. %  By default, the image format of `file' is determined by its magic
  405. %  number.  To specify a particular image format, precede the filename
  406. %  with an image format name and a colon (i.e. mtv:image) or specify the
  407. %  image type as the filename suffix (i.e. image.mtv).  Specify 'file' as
  408. %  '-' for standard input or output.
  409. %
  410. %  Buttons:
  411. %    1    press and drag to select a command from a pop-up menu
  412. %
  413. %  Keyboard accelerators:
  414. %    p    press to animate the sequence of images
  415. %    s    press to display the next image in the sequence
  416. %    .    press to continually display the sequence of images
  417. %    a    press to automatically reverse the sequence of images
  418. %    <    press to slow the display of the images
  419. %    >    press to speed-up the display of the images
  420. %    f    press to animate in the forward direction
  421. %    r    press to animate in the reverse direction
  422. %    i    press to display information about the image
  423. %    q    press to discard all images and exit program
  424. %
  425. %
  426. */
  427. X
  428. /*
  429. X  Include declarations.
  430. */
  431. #include "display.h"
  432. #include "image.h"
  433. #include "alien.h"
  434. #include "X.h"
  435. X
  436. /*
  437. X  State declarations.
  438. */
  439. #define AutoReverseAnimationState 0x0001
  440. #define ConfigureWindowState  0x0002
  441. #define DefaultState  0x0004
  442. #define ExitState  0x0008
  443. #define ForwardAnimationState 0x0010
  444. #define HighlightState  0x0020
  445. #define InfoMappedState  0x0040
  446. #define PlayAnimationState 0x0080
  447. #define RepeatAnimationState 0x0100
  448. #define StepAnimationState 0x0200
  449. X
  450. /*
  451. X  Global declarations.
  452. */
  453. char
  454. X  *application_name;
  455. X
  456. /*
  457. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  458. %                                                                             %
  459. %                                                                             %
  460. %                                                                             %
  461. %   D e l a y                                                                 %
  462. %                                                                             %
  463. %                                                                             %
  464. %                                                                             %
  465. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  466. %
  467. %  Function Delay suspends animation for the number of milliseconds specified.
  468. %
  469. %  The format of the Delay routine is:
  470. %
  471. %      Delay(milliseconds)
  472. %
  473. %  A description of each parameter follows:
  474. %
  475. %    o milliseconds: Specifies the number of milliseconds to delay before
  476. %      returning.
  477. %
  478. %
  479. */
  480. static void Timer()
  481. {
  482. }
  483. X
  484. void Delay(milliseconds)
  485. unsigned long
  486. X  milliseconds;
  487. {
  488. #ifdef unix
  489. #ifdef SYSV
  490. #include <sys/poll.h>
  491. X  if (milliseconds == 0)
  492. X    return;
  493. X  (void) poll((struct pollfd *) NULL,(unsigned long) NULL,
  494. X    (int) (milliseconds/1000));
  495. #else
  496. X  struct timeval
  497. X    timer;
  498. X
  499. X  if (milliseconds == 0)
  500. X    return;
  501. X  timer.tv_sec=milliseconds/1000;
  502. X  timer.tv_usec=(milliseconds % 1000)*1000;
  503. X  (void) select(0,(fd_set *) NULL,(fd_set *) NULL,(fd_set *) NULL,&timer);
  504. #endif
  505. #endif
  506. }
  507. X
  508. /*
  509. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  510. %                                                                             %
  511. %                                                                             %
  512. %                                                                             %
  513. %   E r r o r                                                                 %
  514. %                                                                             %
  515. %                                                                             %
  516. %                                                                             %
  517. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  518. %
  519. %  Function Error displays an error message and then terminates the program.
  520. %
  521. %  The format of the Error routine is:
  522. %
  523. %      Error(message,qualifier)
  524. %
  525. %  A description of each parameter follows:
  526. %
  527. %    o message: Specifies the message to display before terminating the
  528. %      program.
  529. %
  530. %    o qualifier: Specifies any qualifier to the message.
  531. %
  532. %
  533. */
  534. void Error(message,qualifier)
  535. char
  536. X  *message,
  537. X  *qualifier;
  538. {
  539. X  (void) fprintf(stderr,"%s: %s",application_name,message);
  540. X  if (qualifier != (char *) NULL)
  541. X    (void) fprintf(stderr," (%s)",qualifier);
  542. X  (void) fprintf(stderr,".\n");
  543. X  exit(1);
  544. }
  545. X
  546. /*
  547. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  548. %                                                                             %
  549. %                                                                             %
  550. %                                                                             %
  551. %   U s a g e                                                                 %
  552. %                                                                             %
  553. %                                                                             %
  554. %                                                                             %
  555. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  556. %
  557. %  Function Usage displays the program command syntax.
  558. %
  559. %  The format of the Usage routine is:
  560. %
  561. %      Usage(terminate)
  562. %
  563. %  A description of each parameter follows:
  564. %
  565. %    o terminate: The program will exit if the value is not zero.
  566. %
  567. %
  568. */
  569. static void Usage(terminate)
  570. unsigned int
  571. X  terminate;
  572. {
  573. X  char
  574. X    **p;
  575. X
  576. X  static char
  577. X    *buttons[]=
  578. X    {
  579. X      "1    press and drag to select a command from a pop-up menu",
  580. X      (char *) NULL
  581. X    },
  582. X    *keys[]=
  583. X    {
  584. X      "0-9  press to change the level of delay",
  585. X      "p    press to animate the sequence of images",
  586. X      "s    press to display the next image in the sequence",
  587. X      ".    press to continually display the sequence of images",
  588. X      "a    press to automatically reverse the sequence of images",
  589. X      "<    press to slow the display of the images",
  590. X      ">    press to speed-up the display of images",
  591. X      "f    press to animate in the forward direction",
  592. X      "r    press to animate in the reverse direction",
  593. X      "i    press to display information about the image",
  594. X      "q    press to discard all images and exit program",
  595. X      (char *) NULL
  596. X    },
  597. X    *options[]=
  598. X    {
  599. X      "-backdrop            display image centered on a backdrop",
  600. X      "-clip geometry       preferred size and location of the clipped image",
  601. X      "-colormap type       Shared or Private",
  602. X      "-colors value        preferred number of colors in the image",
  603. X      "-colorspace type     GRAY, RGB, XYZ, YIQ, or YUV",
  604. X      "-delay milliseconds  display the next image after pausing",
  605. X      "-density geometry    vertical and horizonal density of the image",
  606. X      "-display server      display image to this X server",
  607. X      "-dither              apply Floyd/Steinberg error diffusion to image",
  608. X      "-gamma value         level of gamma correction",
  609. X      "-geometry geometry   preferred size and location of the image window",
  610. X      "-map type            display image using this Standard Colormap",
  611. X      "-monochrome          transform image to black and white",
  612. X      "-reflect             reflect the image scanlines",
  613. X      "-rotate degrees      apply Paeth rotation to the image",
  614. X      "-scale geometry      preferred size factors of the image",
  615. X      "-treedepth value     depth of the color classification tree",
  616. X      "-verbose             print detailed information about the image",
  617. X      "-visual type         display image using this visual type",
  618. X      (char *) NULL
  619. X    };
  620. X  (void) fprintf(stderr,
  621. X    "Usage: %s [-options ...] file [ [-options ...] file ...]\n",
  622. X    application_name);
  623. X  (void) fprintf(stderr,"\nWhere options include: \n");
  624. X  for (p=options; *p != (char *) NULL; p++)
  625. X    (void) fprintf(stderr,"  %s\n",*p);
  626. X  (void) fprintf(stderr,
  627. X    "\nIn addition to those listed above, you can specify these standard X\n");
  628. X  (void) fprintf(stderr,
  629. X    "resources as command line options:  -background, -bordercolor,\n");
  630. X  (void) fprintf(stderr,
  631. X    "-borderwidth, -font, -foreground, -iconGeometry, -iconic, -name, or\n");
  632. X  (void) fprintf(stderr,"-title.\n");
  633. X  (void) fprintf(stderr,
  634. X    "\nChange '-' to '+' in any option above to reverse its effect.  For\n");
  635. X  (void) fprintf(stderr,
  636. X    "example, specify +compress to store the image as uncompressed.\n");
  637. X  (void) fprintf(stderr,
  638. X    "\nBy default, the image format of `file' is determined by its magic\n");
  639. X  (void) fprintf(stderr,
  640. X    "number.  To specify a particular image format, precede the filename\n");
  641. X  (void) fprintf(stderr,
  642. X    "with an image format name and a colon (i.e. mtv:image) or specify the\n");
  643. X  (void) fprintf(stderr,
  644. X    "image type as the filename suffix (i.e. image.mtv).  Specify 'file' as\n");
  645. X  (void) fprintf(stderr,"'-' for standard input or output.\n");
  646. X  (void) fprintf(stderr,"\nButtons: \n");
  647. X  for (p=buttons; *p != (char *) NULL; p++)
  648. X    (void) fprintf(stderr,"  %s\n",*p);
  649. X  (void) fprintf(stderr,"\nKeyboard accelerators: \n");
  650. X  for (p=keys; *p != (char *) NULL; p++)
  651. X    (void) fprintf(stderr,"  %s\n",*p);
  652. X  if (terminate)
  653. X    exit(1);
  654. }
  655. X
  656. /*
  657. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  658. %                                                                             %
  659. %                                                                             %
  660. %                                                                             %
  661. %   U s e r C o m m a n d                                                     %
  662. %                                                                             %
  663. %                                                                             %
  664. %                                                                             %
  665. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  666. %
  667. %  Function UserCommand makes a transform to the image or image window as
  668. %  specified by a user menu button or keyboard command.
  669. %
  670. %  The format of the UserCommand routine is:
  671. %
  672. %    UserCommand(display,resource_info,window,image,command,state);
  673. %
  674. %  A description of each parameter follows:
  675. %
  676. %    o display: Specifies a connection to an X server; returned from
  677. %      XOpenDisplay.
  678. %
  679. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  680. %
  681. %    o window: Specifies a pointer to a XWindows structure.
  682. %
  683. %    o image: Specifies a pointer to a Image structure;  UserCommand
  684. %      may transform the image and return a new image pointer.
  685. %
  686. %    o state: Specifies an unsigned int;  UserCommand may return a
  687. %      modified state.
  688. %
  689. %
  690. */
  691. static void UserCommand(display,resource_info,window,command,image,state)
  692. Display
  693. X  *display;
  694. X
  695. XXResourceInfo
  696. X  *resource_info;
  697. X
  698. XXWindows
  699. X  *window;
  700. X
  701. char
  702. X  command;
  703. X
  704. Image
  705. X  **image;
  706. X
  707. unsigned int
  708. X  *state;
  709. {
  710. X  if (*state & InfoMappedState)
  711. X    XWithdrawWindow(display,window->info.id,window->info.screen);
  712. X  /*
  713. X    Process user command.
  714. X  */
  715. X  switch (command)
  716. X  {
  717. X    case ' ':
  718. X    case '\0':
  719. X      break;
  720. X    case '<':
  721. X    {
  722. X      resource_info->delay<<=1;
  723. X      if (resource_info->delay == 0)
  724. X        resource_info->delay=1;
  725. X      break;
  726. X    }
  727. X    case '>':
  728. X    {
  729. X      resource_info->delay>>=1;
  730. X      break;
  731. X    }
  732. X    case '.':
  733. X    {
  734. X      *state|=RepeatAnimationState;
  735. X      *state&=(~AutoReverseAnimationState);
  736. X      *state|=PlayAnimationState;
  737. X      break;
  738. X    }
  739. X    case 'a':
  740. X    {
  741. X      *state|=AutoReverseAnimationState;
  742. X      *state&=(~RepeatAnimationState);
  743. X      *state|=PlayAnimationState;
  744. X      break;
  745. X    }
  746. X    case 'f':
  747. X    {
  748. X      *state=ForwardAnimationState;
  749. X      *state&=(~AutoReverseAnimationState);
  750. X      break;
  751. X    }
  752. X    case 'i':
  753. X    {
  754. X      char
  755. X        text[2048];
  756. X
  757. X      /*
  758. X        Display information about the image in the info window.
  759. X      */
  760. X      (void) sprintf(text," [%u] %s %ux%u \0",(*image)->scene,
  761. X        (*image)->filename,window->image.width,window->image.height);
  762. X      if ((*image)->colors > 0)
  763. X        (void) sprintf(text,"%s%uc \0",text,(*image)->colors);
  764. X      (void) strcat(text,(*image)->magick);
  765. X      XSetWindowExtents(window->info,text,2);
  766. X      XMapWindow(display,window->info.id);
  767. X      XDrawImageString(display,window->info.id,window->info.graphic_context,2,
  768. X        window->info.font_info->ascent+2,text,(unsigned int) strlen(text));
  769. X      break;
  770. X    }
  771. X    case 'p':
  772. X    {
  773. X      *state|=PlayAnimationState;
  774. X      *state&=(~AutoReverseAnimationState);
  775. X      break;
  776. X    }
  777. X    case 's':
  778. X    case '\n':
  779. X    {
  780. X      *state|=StepAnimationState;
  781. X      *state&=(~PlayAnimationState);
  782. X      break;
  783. X    }
  784. X    case 'q':
  785. X    {
  786. X      /*
  787. X        Exit program
  788. X      */
  789. X      *state|=ExitState;  /* exit program */
  790. X      break;
  791. X    }
  792. X    case 'r':
  793. X    case '\r':
  794. X    {
  795. X      *state&=(~ForwardAnimationState);
  796. X      *state&=(~AutoReverseAnimationState);
  797. X      break;
  798. X    }
  799. X    default:
  800. X    {
  801. X      XBell(display,0);
  802. X      break;
  803. X    }
  804. X  }
  805. }
  806. X
  807. /*
  808. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  809. %                                                                             %
  810. %                                                                             %
  811. %                                                                             %
  812. %   X A n i m a t e I m a g e                                                 %
  813. %                                                                             %
  814. %                                                                             %
  815. %                                                                             %
  816. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  817. %
  818. %  Function XAnimateImage displays an image via X11.
  819. %
  820. %  The format of the XAnimateImage routine is:
  821. %
  822. %      XAnimateImage(display,resource_info,argv,argc,image,number_scenes)
  823. %
  824. %  A description of each parameter follows:
  825. %
  826. %    o display: Specifies a connection to an X server;  returned from
  827. %      XOpenDisplay.
  828. %
  829. %    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  830. %
  831. %    o argv: Specifies the application's argument list.
  832. %
  833. %    o argc: Specifies the number of arguments.
  834. %
  835. %    o image: Specifies a pointer to a Image structure; returned from
  836. %      ReadImage.
  837. %
  838. %    o number_scenes: Specifies the number of scenes to animate.
  839. %
  840. %
  841. */
  842. static int LinearCompare(x,y)
  843. void
  844. X  *x,
  845. X  *y;
  846. {
  847. X  Image
  848. X    **image_1,
  849. X    **image_2;
  850. X
  851. X  image_1=(Image **) x;
  852. X  image_2=(Image **) y;
  853. X  return((int) (*image_1)->scene-(int) (*image_2)->scene);
  854. }
  855. X
  856. static void XAnimateImage(display,resource_info,argv,argc,images,number_scenes)
  857. Display
  858. X  *display;
  859. X
  860. XXResourceInfo
  861. X  *resource_info;
  862. X
  863. char
  864. X  **argv;
  865. X
  866. int
  867. X  argc;
  868. X
  869. Image
  870. X  **images;
  871. X
  872. unsigned int
  873. X  number_scenes;
  874. {
  875. #define MaxWindows  9
  876. X
  877. X  Atom
  878. X    delete_property,
  879. X    protocols_property;
  880. X
  881. X  char
  882. X    text[2048];
  883. X
  884. X  Cursor
  885. X    arrow_cursor,
  886. X    watch_cursor;
  887. X
  888. X  GC
  889. X    graphic_context;
  890. X
  891. X  int
  892. X    i,
  893. X    scene;
  894. X
  895. X  unsigned int
  896. X    number_windows,
  897. X    state,
  898. X    status;
  899. X
  900. X  Window
  901. X    root_window;
  902. X
  903. X  XClassHint
  904. X    *class_hint;
  905. X
  906. X  XEvent
  907. X    event;
  908. X
  909. X  XFontStruct
  910. X    *font_info;
  911. X
  912. X  XGCValues
  913. X    graphic_context_value;
  914. X
  915. X  XPixelInfo
  916. X    pixel_info;
  917. X
  918. X  XStandardColormap
  919. X    *map_info;
  920. X
  921. X  XVisualInfo
  922. X    *visual_info;
  923. X
  924. X  XWindowInfo
  925. X    *magick_windows[MaxWindows];
  926. X
  927. X  XWindows
  928. X    *window;
  929. X
  930. X  XWMHints
  931. X    *manager_hints;
  932. X
  933. X  /*
  934. X    Sort images by increasing scene number.
  935. X  */
  936. X  (void) qsort((void *) images,(int) number_scenes,sizeof(Image *),
  937. X    LinearCompare);
  938. X  /*
  939. X    Allocate standard colormap.
  940. X  */
  941. X  if (resource_info->debug)
  942. X    XSynchronize(display,True);
  943. X  map_info=XAllocStandardColormap();
  944. X  if (map_info == (XStandardColormap *) NULL)
  945. X    Error("unable to create standard colormap","memory allocation failed");
  946. X  map_info->colormap=(Colormap) NULL;
  947. X  pixel_info.pixels=(unsigned long *) NULL;
  948. X  /*
  949. X    Get the best visual this server supports.
  950. X  */
  951. X  visual_info=XBestVisualInfo(display,resource_info->visual_type,
  952. X    resource_info->map_type,map_info);
  953. X  if (visual_info == (XVisualInfo *) NULL)
  954. X    Error("unable to get visual",resource_info->visual_type);
  955. X  if (resource_info->debug)
  956. X    {
  957. X      (void) fprintf(stderr,"Visual:\n");
  958. X      (void) fprintf(stderr,"  visual id: 0x%lx\n",visual_info->visualid);
  959. X      (void) fprintf(stderr,"  class: %s\n",XVisualClassName(visual_info));
  960. X      (void) fprintf(stderr,"  depth: %d planes\n",visual_info->depth);
  961. X      (void) fprintf(stderr,"  size of colormap: %d entries\n",
  962. X        visual_info->colormap_size);
  963. X      (void) fprintf(stderr,"  red, green, blue masks: 0x%lx 0x%lx 0x%lx\n",
  964. X        visual_info->red_mask,visual_info->green_mask,visual_info->blue_mask);
  965. X      (void) fprintf(stderr,"  significant bits in color: %d bits\n",
  966. X        visual_info->bits_per_rgb);
  967. X    }
  968. X  /*
  969. X    Initialize cursor.
  970. X  */
  971. X  arrow_cursor=XCreateFontCursor(display,XC_arrow);
  972. X  watch_cursor=XCreateFontCursor(display,XC_watch);
  973. X  if ((arrow_cursor == (Cursor) NULL) || (watch_cursor == (Cursor) NULL))
  974. X    Error("unable to create cursor",(char *) NULL);
  975. X  /*
  976. X    Initialize atoms.
  977. X  */
  978. X  protocols_property=XInternAtom(display,"WM_PROTOCOLS",False);
  979. X  delete_property=XInternAtom(display,"WM_DELETE_WINDOW",False);
  980. X  if ((protocols_property == (Atom) NULL) || (delete_property == (Atom) NULL))
  981. X    Error("unable to create property",(char *) NULL);
  982. X  /*
  983. X    Allocate class and manager hints.
  984. X  */
  985. X  class_hint=XAllocClassHint();
  986. X  manager_hints=XAllocWMHints();
  987. X  if ((class_hint == (XClassHint *) NULL) ||
  988. X      (manager_hints == (XWMHints *) NULL))
  989. X    Error("unable to allocate X hints",(char *) NULL);
  990. X  /*
  991. X    Initialize window id's.
  992. X  */
  993. X  window=(XWindows *) malloc(sizeof(XWindows));
  994. X  if (window == (XWindows *) NULL)
  995. X    Error("unable to create X windows","memory allocation failed");
  996. X  number_windows=0;
  997. X  magick_windows[number_windows++]=(&window->backdrop);
  998. X  magick_windows[number_windows++]=(&window->icon);
  999. X  magick_windows[number_windows++]=(&window->image);
  1000. X  magick_windows[number_windows++]=(&window->info);
  1001. X  magick_windows[number_windows++]=(&window->popup);
  1002. X  for (i=0; i < number_windows; i++)
  1003. X    magick_windows[i]->id=(Window) NULL;
  1004. X  if (resource_info->map_type == (char *) NULL)
  1005. X    if ((visual_info->class != TrueColor) &&
  1006. X        (visual_info->class != DirectColor))
  1007. X      {
  1008. X        unsigned int
  1009. X          identical_colormap;
  1010. X
  1011. X        /*
  1012. X          Determine if the sequence of images has the identical colormap.
  1013. X        */
  1014. X        identical_colormap=True;
  1015. X        for (scene=0; scene < number_scenes; scene++)
  1016. X        {
  1017. X          if ((images[scene]->class == DirectClass) ||
  1018. X              (images[scene]->colors > visual_info->colormap_size))
  1019. X            {
  1020. X              /*
  1021. X                Image has more colors than the visual supports.
  1022. X              */
  1023. X              status=UnpackImage(images[scene]);
  1024. X              if (status == False)
  1025. X                Error("unable to unpack image",(char *) NULL);
  1026. X              QuantizeImage(images[scene],(unsigned int)
  1027. X                visual_info->colormap_size,resource_info->tree_depth,
  1028. X                resource_info->dither,resource_info->colorspace,False);
  1029. X            }
  1030. X          if (images[scene]->signature == (char *) NULL)
  1031. X            ColormapSignature(images[scene]);
  1032. X          status=strcmp(images[scene]->signature,images[0]->signature);
  1033. X          if (status != 0)
  1034. X            identical_colormap=False;
  1035. X        }
  1036. X        if (!identical_colormap)
  1037. X          {
  1038. X            /*
  1039. X              Create a single colormap for the sequence of images.
  1040. X            */
  1041. X            for (scene=0; scene < number_scenes; scene++)
  1042. X              if (images[scene]->packed_pixels != (unsigned char *) NULL)
  1043. X                {
  1044. X                  status=UnpackImage(images[scene]);
  1045. X                  if (status == False)
  1046. X                    Error("unable to unpack image",(char *) NULL);
  1047. X                }
  1048. X            QuantizeImages(images,number_scenes,(Image *) NULL,(unsigned int)
  1049. X              visual_info->colormap_size,resource_info->tree_depth,
  1050. X              resource_info->dither,resource_info->colorspace,False);
  1051. X          }
  1052. X      }
  1053. X  /*
  1054. X    Initialize Standard Colormap.
  1055. X  */
  1056. X  if (images[0]->packed_pixels != (unsigned char *) NULL)
  1057. X    {
  1058. X      status=UnpackImage(images[0]);
  1059. X      if (status == False)
  1060. X        Error("unable to unpack image",(char *) NULL);
  1061. X    }
  1062. X  XMakeStandardColormap(display,visual_info,resource_info,&pixel_info,
  1063. X    images[0],map_info);
  1064. X  /*
  1065. X    Color cursors.
  1066. X  */
  1067. X  XRecolorCursor(display,arrow_cursor,&pixel_info.background_color,
  1068. X    &pixel_info.foreground_color);
  1069. X  XRecolorCursor(display,watch_cursor,&pixel_info.background_color,
  1070. X    &pixel_info.foreground_color);
  1071. X  /*
  1072. X    Initialize font info.
  1073. X  */
  1074. X  (void) sprintf(text," [%u] %s %ux%u \0",images[0]->scene,images[0]->filename,
  1075. X    images[0]->columns,images[0]->rows);
  1076. X  if (images[0]->colors > 0)
  1077. X    (void) sprintf(text,"%s%uc \0",text,images[0]->colors);
  1078. X  font_info=XBestFont(display,resource_info,text,images[0]->columns);
  1079. X  if (font_info == (XFontStruct *) NULL)
  1080. X    Error("unable to load font",resource_info->font);
  1081. X  /*
  1082. X    Initialize class and manager hints.
  1083. X  */
  1084. X  if (resource_info->name == (char *) NULL)
  1085. X    class_hint->res_name=application_name;
  1086. X  else
  1087. X    class_hint->res_name=resource_info->name;
  1088. X  class_hint->res_class=(char *) "ImageMagick";
  1089. X  manager_hints->flags=InputHint | StateHint;
  1090. X  manager_hints->input=False;
  1091. X  manager_hints->initial_state=NormalState;
  1092. X  /*
  1093. X    Window superclass.
  1094. X  */
  1095. X  window->superclass.id=(Window) NULL;
  1096. X  window->superclass.screen=visual_info->screen;
  1097. X  window->superclass.depth=visual_info->depth;
  1098. X  window->superclass.visual_info=visual_info;
  1099. X  window->superclass.map_info=map_info;
  1100. X  window->superclass.pixel_info=(&pixel_info);
  1101. X  window->superclass.font_info=font_info;
  1102. X  window->superclass.cursor=arrow_cursor;
  1103. X  window->superclass.busy_cursor=watch_cursor;
  1104. X  window->superclass.name=(char *) NULL;
  1105. X  window->superclass.geometry=(char *) NULL;
  1106. X  window->superclass.icon_name=(char *) NULL;
  1107. X  window->superclass.icon_geometry=resource_info->icon_geometry;
  1108. X  window->superclass.clip_geometry=(char *) NULL;
  1109. X  window->superclass.flags=PSize;
  1110. X  window->superclass.x=0;
  1111. X  window->superclass.y=0;
  1112. X  window->superclass.width=1;
  1113. X  window->superclass.height=1;
  1114. X  window->superclass.min_width=1;
  1115. X  window->superclass.min_height=1;
  1116. X  window->superclass.width_inc=1;
  1117. X  window->superclass.height_inc=1;
  1118. X  window->superclass.border_width=WindowBorderWidth;
  1119. X  window->superclass.immutable=True;
  1120. X  window->superclass.ximage=(XImage *) NULL;
  1121. X  window->superclass.pixmap=(Pixmap) NULL;
  1122. X  window->superclass.attributes.background_pixel=
  1123. X    pixel_info.background_color.pixel;
  1124. X  window->superclass.attributes.background_pixmap=(Pixmap) NULL;
  1125. X  window->superclass.attributes.backing_store=WhenMapped;
  1126. X  window->superclass.attributes.bit_gravity=ForgetGravity;
  1127. X  window->superclass.attributes.border_pixel=pixel_info.border_color.pixel;
  1128. X  window->superclass.attributes.colormap=map_info->colormap;
  1129. X  window->superclass.attributes.cursor=arrow_cursor;
  1130. X  window->superclass.attributes.do_not_propagate_mask=NoEventMask;
  1131. X  window->superclass.attributes.event_mask=NoEventMask;
  1132. X  window->superclass.attributes.override_redirect=False;
  1133. X  window->superclass.attributes.save_under=True;
  1134. X  window->superclass.attributes.win_gravity=NorthWestGravity;
  1135. X  window->superclass.graphic_context=(GC) NULL;
  1136. X  window->superclass.ximage=(XImage *) NULL;
  1137. X  root_window=XRootWindow(display,visual_info->screen);
  1138. X  XMakeWindow(display,root_window,argv,argc,class_hint,manager_hints,
  1139. X    delete_property,&window->superclass);
  1140. X  if (resource_info->debug)
  1141. X    (void) fprintf(stderr,"Window id: 0x%lx (superclass)\n",
  1142. X      window->superclass.id);
  1143. X  /*
  1144. X    Initialize graphic context.
  1145. X  */
  1146. X  graphic_context_value.background=pixel_info.background_color.pixel;
  1147. X  graphic_context_value.foreground=pixel_info.foreground_color.pixel;
  1148. X  graphic_context_value.font=font_info->fid;
  1149. X  graphic_context_value.function=GXcopy;
  1150. X  graphic_context_value.line_width=2;
  1151. X  graphic_context_value.graphics_exposures=False;
  1152. X  graphic_context_value.plane_mask=AllPlanes;
  1153. X  graphic_context=XCreateGC(display,window->superclass.id,GCBackground |
  1154. X    GCFont | GCForeground | GCFunction | GCGraphicsExposures | GCLineWidth |
  1155. X    GCPlaneMask,&graphic_context_value);
  1156. X  if (graphic_context == (GC) NULL)
  1157. X    Error("unable to create graphic context",(char *) NULL);
  1158. X  window->superclass.graphic_context=graphic_context;
  1159. X  graphic_context_value.background=pixel_info.foreground_color.pixel;
  1160. X  graphic_context_value.foreground=pixel_info.background_color.pixel;
  1161. X  graphic_context=XCreateGC(display,window->superclass.id,GCBackground |
  1162. X    GCFont | GCForeground | GCFunction | GCLineWidth | GCPlaneMask,
  1163. X    &graphic_context_value);
  1164. X  if (graphic_context == (GC) NULL)
  1165. X    Error("unable to create graphic context",(char *) NULL);
  1166. X  window->superclass.highlight_context=graphic_context;
  1167. X  XDestroyWindow(display,window->superclass.id);
  1168. X  window->superclass.id=(Window) NULL;
  1169. X  /*
  1170. X    Initialize icon window.
  1171. X  */
  1172. X  XGetWindowInfo(&window->superclass,&window->icon);
  1173. X  XBestIconSize(display,&window->icon,images[0]);
  1174. X  window->icon.attributes.event_mask=ExposureMask | StructureNotifyMask;
  1175. X  manager_hints->flags=InputHint | StateHint;
  1176. X  manager_hints->input=False;
  1177. X  manager_hints->initial_state=IconicState;
  1178. X  XMakeWindow(display,root_window,argv,argc,class_hint,manager_hints,
  1179. X    delete_property,&window->icon);
  1180. X  if (resource_info->debug)
  1181. X    (void) fprintf(stderr,"Window id: 0x%lx (icon)\n",window->icon.id);
  1182. X  /*
  1183. X    Initialize image window.
  1184. X  */
  1185. X  XGetWindowInfo(&window->superclass,&window->image);
  1186. X  window->image.name=(char *) malloc(2048*sizeof(char));
  1187. X  window->image.icon_name=(char *) malloc(2048*sizeof(char));
  1188. X  if ((window->image.name == NULL) || (window->image.icon_name == NULL))
  1189. X    Error("unable to create image window","memory allocation failed");
  1190. X  if (resource_info->title != (char *) NULL)
  1191. X    {
  1192. X      (void) strcpy(window->image.name,resource_info->title);
  1193. X      (void) strcpy(window->image.icon_name,resource_info->title);
  1194. X    }
  1195. X  else
  1196. X    {
  1197. X      register char
  1198. X        *p;
  1199. X
  1200. X      (void) strcpy(window->image.name,"ImageMagick: ");
  1201. X      (void) strcat(window->image.name,images[0]->filename);
  1202. X      p=window->image.name;
  1203. X      while (*p != '\0')
  1204. X      {
  1205. X        if (*p == '.')
  1206. X          {
  1207. X            *p='\0';
  1208. X            break;
  1209. X          }
  1210. X        p++;
  1211. X      }
  1212. X      (void) strcpy(window->image.icon_name,images[0]->filename);
  1213. X      p=window->image.icon_name;
  1214. X      while (*p != '\0')
  1215. X      {
  1216. X        if (*p == '.')
  1217. X          {
  1218. X            *p='\0';
  1219. X            break;
  1220. X          }
  1221. X        p++;
  1222. X      }
  1223. X    }
  1224. X  window->image.geometry=resource_info->image_geometry;
  1225. X  window->image.width=images[0]->columns;
  1226. X  if (window->image.width > XDisplayWidth(display,visual_info->screen))
  1227. X    window->image.width=XDisplayWidth(display,visual_info->screen);
  1228. X  window->image.height=images[0]->rows;
  1229. X  if (window->image.height > XDisplayHeight(display,visual_info->screen))
  1230. X    window->image.height=XDisplayHeight(display,visual_info->screen);
  1231. X  window->image.border_width=resource_info->border_width;
  1232. X  XGetWindowInfo(&window->superclass,&window->backdrop);
  1233. X  if (resource_info->backdrop)
  1234. X    {
  1235. X      unsigned int
  1236. X        height,
  1237. X        width;
  1238. X
  1239. X      /*
  1240. X        Initialize backdrop window.
  1241. X      */
  1242. X      window->backdrop.cursor=XMakeInvisibleCursor(display,root_window);
  1243. X      if (window->backdrop.cursor == (Cursor) NULL)
  1244. X        Error("unable to create cursor",(char *) NULL);
  1245. X      window->backdrop.name="ImageMagick Background";
  1246. X      window->backdrop.flags=USSize | USPosition;
  1247. X      window->backdrop.width=XDisplayWidth(display,visual_info->screen);
  1248. X      window->backdrop.height=XDisplayHeight(display,visual_info->screen);
  1249. X      window->backdrop.border_width=0;
  1250. X      window->backdrop.immutable=True;
  1251. X      window->backdrop.attributes.cursor=window->backdrop.cursor;
  1252. X      window->backdrop.attributes.do_not_propagate_mask=
  1253. X        ButtonPressMask | ButtonReleaseMask;
  1254. X      window->backdrop.attributes.override_redirect=True;
  1255. X      manager_hints->flags=IconWindowHint | InputHint | StateHint;
  1256. X      manager_hints->icon_window=window->icon.id;
  1257. X      manager_hints->input=True;
  1258. X      manager_hints->initial_state=
  1259. X        resource_info->iconic ? IconicState : NormalState;
  1260. X      XMakeWindow(display,root_window,argv,argc,class_hint,manager_hints,
  1261. X        delete_property,&window->backdrop);
  1262. X      if (resource_info->debug)
  1263. X        (void) fprintf(stderr,"Window id: 0x%lx (backdrop)\n",
  1264. X          window->backdrop.id);
  1265. X      XSetTransientForHint(display,window->backdrop.id,window->backdrop.id);
  1266. X      XMapWindow(display,window->backdrop.id);
  1267. X      XInstallColormap(display,map_info->colormap);
  1268. X      XSetInputFocus(display,window->backdrop.id,RevertToNone,CurrentTime);
  1269. X      /*
  1270. X        Position image in the center the backdrop.
  1271. X      */
  1272. X      window->image.flags|=USPosition;
  1273. X      window->image.x=0;
  1274. X      width=images[0]->columns+window->image.border_width;
  1275. X      if (width < XDisplayWidth(display,visual_info->screen))
  1276. X        window->image.x=XDisplayWidth(display,visual_info->screen)/2-width/2;
  1277. X      window->image.y=0;
  1278. X      height=images[0]->rows+window->image.border_width;
  1279. X      if (height < XDisplayHeight(display,visual_info->screen))
  1280. X        window->image.y=XDisplayHeight(display,visual_info->screen)/2-height/2;
  1281. X    }
  1282. X  window->image.immutable=False;
  1283. X  window->image.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
  1284. X    ButtonReleaseMask | EnterWindowMask | ExposureMask | KeyPressMask |
  1285. X    LeaveWindowMask | OwnerGrabButtonMask | StructureNotifyMask;
  1286. X  manager_hints->flags=IconWindowHint | InputHint | StateHint;
  1287. X  manager_hints->icon_window=window->icon.id;
  1288. X  manager_hints->input=True;
  1289. X  manager_hints->initial_state=
  1290. X    resource_info->iconic ? IconicState : NormalState;
  1291. X  XMakeWindow(display,(resource_info->backdrop ? window->backdrop.id :
  1292. X    root_window),argv,argc,class_hint,manager_hints,delete_property,
  1293. X    &window->image);
  1294. X  if (resource_info->debug)
  1295. X    (void) fprintf(stderr,"Window id: 0x%lx (image)\n",window->image.id);
  1296. X  XMapWindow(display,window->image.id);
  1297. X  window->image.x=0;
  1298. X  window->image.y=0;
  1299. X  /*
  1300. X    Initialize image X image structure.
  1301. X  */
  1302. X  status=XMakeImage(display,resource_info,&window->image,images[0],
  1303. X    images[0]->columns,images[0]->rows);
  1304. X  status|=XMakePixmap(display,resource_info,&window->image);
  1305. X  if (status == False)
  1306. X    Error("unable to create X image",(char *) NULL);
  1307. X  if (resource_info->debug)
  1308. X    {
  1309. X      (void) fprintf(stderr,"Image: [%u] %s %ux%u ",images[0]->scene,
  1310. X        images[0]->filename,images[0]->columns,images[0]->rows);
  1311. X      if (images[0]->colors > 0)
  1312. X        (void) fprintf(stderr,"%uc ",images[0]->colors);
  1313. X      (void) fprintf(stderr,"%s\n",images[0]->magick);
  1314. X    }
  1315. X  XRefreshWindow(display,&window->image,(XEvent *) NULL);
  1316. X  /*
  1317. X    Initialize popup window.
  1318. X  */
  1319. X  XGetWindowInfo(&window->superclass,&window->popup);
  1320. X  window->popup.name="ImageMagick Popup";
  1321. X  window->popup.flags=PSize | PPosition;
  1322. X  window->popup.attributes.override_redirect=True;
  1323. X  window->popup.attributes.save_under=True;
  1324. X  window->popup.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
  1325. X    ButtonReleaseMask | EnterWindowMask | ExposureMask | LeaveWindowMask |
  1326. X    OwnerGrabButtonMask;
  1327. X  manager_hints->flags=InputHint | StateHint | WindowGroupHint;
  1328. X  manager_hints->input=False;
  1329. X  manager_hints->initial_state=NormalState;
  1330. X  manager_hints->window_group=window->image.id;
  1331. X  XMakeWindow(display,root_window,argv,argc,class_hint,manager_hints,
  1332. X    delete_property,&window->popup);
  1333. X  if (resource_info->debug)
  1334. X    (void) fprintf(stderr,"Window id: 0x%lx (popup)\n",window->popup.id);
  1335. X  XSetTransientForHint(display,window->popup.id,window->image.id);
  1336. X  /*
  1337. X    Initialize info window.
  1338. X  */
  1339. X  XGetWindowInfo(&window->superclass,&window->info);
  1340. X  window->info.name="ImageMagick Info";
  1341. X  window->info.flags=PSize | PPosition;
  1342. X  window->info.x=2;
  1343. X  window->info.y=2;
  1344. X  window->info.attributes.event_mask=StructureNotifyMask;
  1345. X  manager_hints->flags=InputHint | StateHint | WindowGroupHint;
  1346. X  manager_hints->input=False;
  1347. X  manager_hints->initial_state=NormalState;
  1348. X  manager_hints->window_group=window->image.id;
  1349. X  XMakeWindow(display,window->image.id,argv,argc,class_hint,manager_hints,
  1350. X    delete_property,&window->info);
  1351. X  if (resource_info->debug)
  1352. X    (void) fprintf(stderr,"Window id: 0x%lx (info)\n",window->info.id);
  1353. X  /*
  1354. X    Initialize image pixmaps structure.
  1355. X  */
  1356. X  XDefineCursor(display,window->image.id,window->image.busy_cursor);
  1357. X  XMapWindow(display,window->info.id);
  1358. X  window->image.pixmaps=(Pixmap *) malloc(number_scenes*sizeof(Pixmap));
  1359. X  if (window->image.pixmaps == (Pixmap *) NULL)
  1360. X    Error("unable to animate images","memory allocation failed");
  1361. X  window->image.pixmaps[0]=window->image.pixmap;
  1362. X  for (scene=1; scene < number_scenes; scene++)
  1363. X  {
  1364. X    /*
  1365. X      Display information about the image in the info window.
  1366. X    */
  1367. X    (void) sprintf(text," [%u] %s %ux%u \0",images[scene]->scene,
  1368. X      images[scene]->filename,window->image.width,window->image.height);
  1369. X    if (images[scene]->colors > 0)
  1370. X      (void) sprintf(text,"%s%uc \0",text,images[scene]->colors);
  1371. X    XSetWindowExtents(window->info,text,2);
  1372. X    XDrawImageString(display,window->info.id,window->info.graphic_context,2,
  1373. X      window->info.font_info->ascent+2,text,(unsigned int) strlen(text));
  1374. X    XFlush(display);
  1375. X    /*
  1376. X      Create X image.
  1377. X    */
  1378. X    window->image.pixmap=(Pixmap) NULL;
  1379. X    if (images[scene]->packed_pixels != (unsigned char *) NULL)
  1380. X      {
  1381. X        status=UnpackImage(images[scene]);
  1382. X        if (status == False)
  1383. X          Error("unable to unpack image",(char *) NULL);
  1384. X      }
  1385. X    status=XMakeImage(display,resource_info,&window->image,images[scene],
  1386. X      images[scene]->columns,images[scene]->rows);
  1387. X    status|=XMakePixmap(display,resource_info,&window->image);
  1388. X    if (status == False)
  1389. X      Error("unable to create X image",(char *) NULL);
  1390. X    if (resource_info->debug)
  1391. X      {
  1392. X        (void) fprintf(stderr,"Image: [%u] %s %ux%u ",images[scene]->scene,
  1393. X          images[scene]->filename,images[scene]->columns,images[scene]->rows);
  1394. X        if (images[scene]->colors > 0)
  1395. X          (void) fprintf(stderr,"%uc ",images[scene]->colors);
  1396. X        (void) fprintf(stderr,"%s\n",images[scene]->magick);
  1397. X      }
  1398. X    /*
  1399. X      Free image pixels.
  1400. X    */
  1401. X    (void) free((char *) images[scene]->pixels);
  1402. X    images[scene]->pixels=(RunlengthPacket *) NULL;
  1403. X    /*
  1404. X      Refresh image window.
  1405. X    */
  1406. X    window->image.pixmaps[scene]=window->image.pixmap;
  1407. X    XRefreshWindow(display,&window->image,(XEvent *) NULL);
  1408. X    XSync(display,False);
  1409. X  }
  1410. X  XWithdrawWindow(display,window->info.id,window->info.screen);
  1411. X  XDefineCursor(display,window->image.id,window->image.cursor);
  1412. X  /*
  1413. X    Respond to events.
  1414. X  */
  1415. X  state=DefaultState;
  1416. X  scene=0;
  1417. X  do
  1418. X  {
  1419. X    if (XEventsQueued(display,QueuedAfterFlush) == 0)
  1420. X      if ((state & PlayAnimationState) || (state & StepAnimationState))
  1421. X        {
  1422. X          if (state & InfoMappedState)
  1423. X            XWithdrawWindow(display,window->info.id,window->info.screen);
  1424. X          /*
  1425. X            Copy X pixmap to image window.
  1426. X          */
  1427. X          window->image.pixmap=window->image.pixmaps[scene];
  1428. X          XRefreshWindow(display,&window->image,(XEvent *) NULL);
  1429. X          XSync(display,False);
  1430. X          if (state & StepAnimationState)
  1431. X            {
  1432. X              state&=(~StepAnimationState);
  1433. X              UserCommand(display,resource_info,window,'i',&images[scene],
  1434. X                &state);
  1435. X            }
  1436. X          if (resource_info->delay > 0)
  1437. X            Delay((unsigned long) resource_info->delay);
  1438. X          if (state & ForwardAnimationState)
  1439. X            {
  1440. X              /*
  1441. X                Forward animation:  increment scene number.
  1442. X              */
  1443. X              scene++;
  1444. X              if (scene == number_scenes)
  1445. X                if (state & AutoReverseAnimationState)
  1446. X                  {
  1447. X                    state&=(~ForwardAnimationState);
  1448. X                    scene--;
  1449. X                  }
  1450. X                else
  1451. X                  {
  1452. X                    if (!(state & RepeatAnimationState))
  1453. X                      state&=(~PlayAnimationState);
  1454. X                    scene=0;
  1455. X                  }
  1456. X            }
  1457. X          else
  1458. X            {
  1459. X              /*
  1460. X                Reverse animation:  decrement scene number.
  1461. X              */
  1462. X              scene--;
  1463. X              if (scene < 0)
  1464. X                if (state & AutoReverseAnimationState)
  1465. X                  {
  1466. X                    state|=ForwardAnimationState;
  1467. X                    scene=0;
  1468. X                  }
  1469. X                else
  1470. X                  {
  1471. X                    if (!(state & RepeatAnimationState))
  1472. X                      state&=(~PlayAnimationState);
  1473. X                    scene=number_scenes-1;
  1474. X                  }
  1475. X            }
  1476. X          continue;
  1477. X        }
  1478. X    /*
  1479. X      Handle a window event.
  1480. X    */
  1481. X    XNextEvent(display,&event);
  1482. X    switch (event.type)
  1483. X    {
  1484. X      case ButtonPress:
  1485. X      {
  1486. X        if (event.xbutton.window == window->image.id)
  1487. X          switch (event.xbutton.button)
  1488. X          {
  1489. X            case Button1:
  1490. X            {
  1491. X              static char
  1492. X                command[2048],
  1493. X                *MenuCommand="ips.a<>frq",
  1494. X                *MenuSelections[]=
  1495. X                {
  1496. X                  "Image Info",
  1497. X                  "Play",
  1498. X                  "Step",
  1499. X                  "Repeat",
  1500. X                  "Auto Reverse",
  1501. X                  "Slower",
  1502. X                  "Faster",
  1503. X                  "Forward",
  1504. X                  "Reverse",
  1505. X                  "Quit"
  1506. X                };
  1507. X
  1508. X              static int
  1509. X                command_number;
  1510. X
  1511. X              /*
  1512. X                Select a command from the pop-up menu.
  1513. X              */
  1514. X              command_number=XPopupMenu(display,&window->popup,
  1515. X                event.xbutton.x_root,event.xbutton.y_root,"Commands",
  1516. X                MenuSelections,sizeof(MenuSelections)/sizeof(char *),command);
  1517. X              if (*command != '\0')
  1518. X                UserCommand(display,resource_info,window,
  1519. X                  MenuCommand[command_number],&images[scene],&state);
  1520. X              break;
  1521. X            }
  1522. X            default:
  1523. X              break;
  1524. X          }
  1525. X        break;
  1526. X      }
  1527. X      case ClientMessage:
  1528. X      {
  1529. X        /*
  1530. X          If client window delete message, exit.
  1531. X        */
  1532. X        if (event.xclient.message_type == protocols_property)
  1533. X          if (*event.xclient.data.l == delete_property)
  1534. X            if (event.xclient.window == window->image.id)
  1535. X              state|=ExitState;
  1536. X            else
  1537. X              XWithdrawWindow(display,event.xclient.window,visual_info->screen);
  1538. X        break;
  1539. X      }
  1540. X      case ConfigureNotify:
  1541. X      {
  1542. X        if (resource_info->debug)
  1543. X          (void) fprintf(stderr,"Configure Notify: 0x%lx %dx%d+%d+%d\n",
  1544. X            event.xconfigure.window,event.xconfigure.width,
  1545. X            event.xconfigure.height,event.xconfigure.x,event.xconfigure.y);
  1546. X        if (event.xconfigure.window == window->image.id)
  1547. X          {
  1548. X            /*
  1549. X              Image window has a new configuration.
  1550. X            */
  1551. X            window->image.width=event.xconfigure.width;
  1552. X            window->image.height=event.xconfigure.height;
  1553. X            break;
  1554. X          }
  1555. X        if (event.xconfigure.window == window->icon.id)
  1556. X          {
  1557. X            /*
  1558. X              Icon window has a new configuration.
  1559. X            */
  1560. X            window->icon.width=event.xconfigure.width;
  1561. X            window->icon.height=event.xconfigure.height;
  1562. X            break;
  1563. X          }
  1564. X      }
  1565. X      case EnterNotify:
  1566. X      {
  1567. X        /*
  1568. X          Selectively install colormap.
  1569. X        */
  1570. X        if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
  1571. X          if (event.xcrossing.mode != NotifyUngrab)
  1572. X            XInductColormap(display,map_info->colormap);
  1573. X        if (window->backdrop.id != (Window) NULL)
  1574. X          if (event.xbutton.window == window->image.id)
  1575. X            {
  1576. X              XInstallColormap(display,map_info->colormap);
  1577. X              XSetInputFocus(display,window->image.id,RevertToNone,CurrentTime);
  1578. X              break;
  1579. X            }
  1580. X        break;
  1581. X      }
  1582. X      case Expose:
  1583. X      {
  1584. X        if (resource_info->debug)
  1585. X          (void) fprintf(stderr,"Expose: 0x%lx %dx%d+%d+%d\n",
  1586. X            event.xexpose.window,event.xexpose.width,event.xexpose.height,
  1587. X            event.xexpose.x,event.xexpose.y);
  1588. X        /*
  1589. X          Repaint windows that are now exposed.
  1590. X        */
  1591. X        if (event.xexpose.window == window->image.id)
  1592. X          {
  1593. X            window->image.pixmap=window->image.pixmaps[scene];
  1594. X            XRefreshWindow(display,&window->image,&event);
  1595. X            break;
  1596. X          }
  1597. X        break;
  1598. X      }
  1599. X      case KeyPress:
  1600. X      {
  1601. X        static char
  1602. X          command[2048];
  1603. X
  1604. X        static KeySym
  1605. X          key_symbol;
  1606. X
  1607. X        /*
  1608. X          Respond to a user key press.
  1609. X        */
  1610. X        if (state & ConfigureWindowState)
  1611. X          {
  1612. X            XBell(display,0);
  1613. X            break;
  1614. X          }
  1615. X        *command='\0';
  1616. X        XLookupString((XKeyEvent *) &event.xkey,command,sizeof(command),
  1617. X          &key_symbol,(XComposeStatus *) NULL);
  1618. X        if (key_symbol == XK_Help)
  1619. X          Usage(False);
  1620. X        else
  1621. X          if (!IsCursorKey(key_symbol))
  1622. X            UserCommand(display,resource_info,window,*command,&images[scene],
  1623. X              &state);
  1624. X        break;
  1625. X      }
  1626. X      case LeaveNotify:
  1627. X      {
  1628. X        /*
  1629. X          Selectively uninstall colormap.
  1630. X        */
  1631. X        if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
  1632. X          if (event.xcrossing.mode != NotifyUngrab)
  1633. X            XUninductColormap(display,map_info->colormap);
  1634. X        break;
  1635. X      }
  1636. X      case MapNotify:
  1637. X      {
  1638. X        if (resource_info->debug)
  1639. X          (void) fprintf(stderr,"Map Notify: 0x%lx\n",event.xmap.window);
  1640. X        if (event.xmap.window == window->image.id)
  1641. X          {
  1642. X            state=ForwardAnimationState | PlayAnimationState;
  1643. X            break;
  1644. X          }
  1645. X        if (event.xmap.window == window->info.id)
  1646. X          {
  1647. X            state|=InfoMappedState;
  1648. X            break;
  1649. X          }
  1650. X        if (event.xmap.window == window->icon.id)
  1651. X          {
  1652. X            /*
  1653. X              Create icon pixmap.
  1654. X            */
  1655. X            status=XMakeImage(display,resource_info,&window->icon,images[0],
  1656. X              window->icon.width,window->icon.height);
  1657. X            status|=XMakePixmap(display,resource_info,&window->icon);
  1658. X            if (status == False)
  1659. X              Error("unable to create icon image",(char *) NULL);
  1660. SHAR_EOF
  1661. true || echo 'restore of ImageMagick/animate.c failed'
  1662. fi
  1663. echo 'End of  part 18'
  1664. echo 'File ImageMagick/animate.c is continued in part 19'
  1665. echo 19 > _shar_seq_.tmp
  1666. exit 0
  1667. exit 0 # Just in case...
  1668.