home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sources / misc / 4186 < prev    next >
Encoding:
Text File  |  1992-12-14  |  57.3 KB  |  1,674 lines

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