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

  1. Newsgroups: comp.sources.x
  2. From: cristy@eplrx7.es.duPont.com (Cristy)
  3. Subject: v20i064:  imagemagic - X11 image processing and display, Part08/38
  4. Message-ID: <1993Jul14.175432.1069@sparky.sterling.com>
  5. X-Md4-Signature: b2d0e0a673bc378c63c4c75fc48c894c
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Wed, 14 Jul 1993 17:54:32 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: cristy@eplrx7.es.duPont.com (Cristy)
  12. Posting-number: Volume 20, Issue 64
  13. Archive-name: imagemagic/part08
  14. Environment: X11
  15. Supersedes: imagemagic: Volume 13, Issue 17-37
  16.  
  17. #!/bin/sh
  18. # this is magick.08 (part 8 of ImageMagick)
  19. # do not concatenate these parts, unpack them in order with /bin/sh
  20. # file ImageMagick/Manifest.ps continued
  21. #
  22. if test ! -r _shar_seq_.tmp; then
  23.     echo 'Please unpack part 1 first!'
  24.     exit 1
  25. fi
  26. (read Scheck
  27.  if test "$Scheck" != 8; then
  28.     echo Please unpack part "$Scheck" next!
  29.     exit 1
  30.  else
  31.     exit 0
  32.  fi
  33. ) < _shar_seq_.tmp || exit 1
  34. if test ! -f _shar_wnt_.tmp; then
  35.     echo 'x - still skipping ImageMagick/Manifest.ps'
  36. else
  37. echo 'x - continuing file ImageMagick/Manifest.ps'
  38. sed 's/^X//' << 'SHAR_EOF' >> 'ImageMagick/Manifest.ps' &&
  39. {gsave 86.0 exch lineto stroke grestore} forall
  40. showpage
  41. SHAR_EOF
  42. echo 'File ImageMagick/Manifest.ps is complete' &&
  43. chmod 0644 ImageMagick/Manifest.ps ||
  44. echo 'restore of ImageMagick/Manifest.ps failed'
  45. Wc_c="`wc -c < 'ImageMagick/Manifest.ps'`"
  46. test 2670 -eq "$Wc_c" ||
  47.     echo 'ImageMagick/Manifest.ps: original size 2670, current size' "$Wc_c"
  48. rm -f _shar_wnt_.tmp
  49. fi
  50. # ============= ImageMagick/PreRvIcccm.c ==============
  51. if test -f 'ImageMagick/PreRvIcccm.c' -a X"$1" != X"-c"; then
  52.     echo 'x - skipping ImageMagick/PreRvIcccm.c (File already exists)'
  53.     rm -f _shar_wnt_.tmp
  54. else
  55. > _shar_wnt_.tmp
  56. echo 'x - extracting ImageMagick/PreRvIcccm.c (Text)'
  57. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/PreRvIcccm.c' &&
  58. #include "display.h"
  59. #include "image.h"
  60. #include "X.h"
  61. X
  62. #ifdef PRE_R5_ICCCM
  63. /*
  64. X  Compatibility routines for pre X11R5 ICCCM.
  65. */
  66. XXrmDatabase XrmGetDatabase(display)
  67. Display
  68. X  *display;
  69. {
  70. X  return(display->db);
  71. }
  72. #endif
  73. X
  74. #ifdef PRE_R4_ICCCM
  75. /*
  76. X  Compatibility routines for pre X11R4 ICCCM.
  77. */
  78. XXClassHint *XAllocClassHint()
  79. {
  80. X  return((XClassHint *) malloc(sizeof(XClassHint)));
  81. }
  82. X
  83. XXIconSize *XAllocIconSize()
  84. {
  85. X  return((XIconSize *) malloc(sizeof(XIconSize)));
  86. }
  87. X
  88. XXSizeHints *XAllocSizeHints()
  89. {
  90. X  return((XSizeHints *) malloc(sizeof(XSizeHints)));
  91. }
  92. X
  93. Status XReconfigureWMWindow(display,window,screen_number,value_mask,values)
  94. Display
  95. X  *display;
  96. X
  97. Window
  98. X  window;
  99. X
  100. int
  101. X  screen_number;
  102. X
  103. unsigned int
  104. X  value_mask;
  105. X
  106. XXWindowChanges
  107. X  *values;
  108. {
  109. X  return(XConfigureWindow(display,window,value_mask,values));
  110. }
  111. X
  112. XXStandardColormap *XAllocStandardColormap()
  113. {
  114. X  return((XStandardColormap *) malloc(sizeof(XStandardColormap)));
  115. }
  116. X
  117. XXWMHints *XAllocWMHints()
  118. {
  119. X  return((XWMHints *) malloc(sizeof(XWMHints)));
  120. }
  121. X
  122. Status XGetRGBColormaps(display,window,colormap,count,property)
  123. Display
  124. X  *display;
  125. X
  126. Window
  127. X  window;
  128. X
  129. XXStandardColormap
  130. X  **colormap;
  131. X
  132. int
  133. X  *count;
  134. X
  135. Atom
  136. X  property;
  137. {
  138. X  *count=1;
  139. X  return(XGetStandardColormap(display,window,colormap,property));
  140. }
  141. X
  142. Status XGetWMColormapWindows(display,window,colormap_windows,number_windows)
  143. Display
  144. X  *display;
  145. X
  146. Window
  147. X  window,
  148. X  **colormap_windows;
  149. X
  150. int
  151. X  *number_windows;
  152. {
  153. X  Atom
  154. X    actual_type,
  155. X    *data,
  156. X    property;
  157. X
  158. X  int
  159. X    actual_format,
  160. X    status;
  161. X
  162. X  unsigned long
  163. X    leftover,
  164. X    number_items;
  165. X
  166. X  property=XInternAtom(display,"WM_COLORMAP_WINDOWS",False);
  167. X  if (property == None)
  168. X    return(False);
  169. X  /*
  170. X    Get the window property.
  171. X  */
  172. X  *data=(Atom) NULL;
  173. X  status=XGetWindowProperty(display,window,property,0L,1000000L,False,
  174. X    XA_WINDOW,&actual_type,&actual_format,&number_items,&leftover,
  175. X    (unsigned char **) &data);
  176. X  if (status != Success)
  177. X    return(False);
  178. X  if ((actual_type != XA_WINDOW) || (actual_format != 32))
  179. X    {
  180. X      if (data != (Atom *) NULL)
  181. X        Xfree((char *) data);
  182. X      return(False);
  183. X    }
  184. X  *colormap_windows=(Window *) data;
  185. X  *number_windows=(int) number_items;
  186. X  return(True);
  187. }
  188. X
  189. Status XGetWMName(display,window,text_property)
  190. Display
  191. X  *display;
  192. X
  193. Window
  194. X  window;
  195. X
  196. XXTextProperty
  197. X  *text_property;
  198. {
  199. X  char
  200. X    *window_name;
  201. X
  202. X  if (XFetchName(display,window,&window_name) == 0)
  203. X    return(False);
  204. X  text_property->value=(unsigned char *) window_name;
  205. X  text_property->encoding=XA_STRING;
  206. X  text_property->format=8;
  207. X  text_property->nitems=strlen(window_name);
  208. X  return(True);
  209. }
  210. X
  211. char *XResourceManagerString(display)
  212. Display
  213. X  *display;
  214. {
  215. X  return display->xdefaults;
  216. }
  217. X
  218. void XrmDestroyDatabase(database)
  219. XXrmDatabase
  220. X  database;
  221. {
  222. }
  223. X
  224. int XSetWMName(display,window,property)
  225. Display
  226. X  *display;
  227. X
  228. Window
  229. X  window;
  230. X
  231. XXTextProperty
  232. X  *property;
  233. {
  234. X  XStoreName(display,window,property->value);
  235. }
  236. X
  237. int XStringListToTextProperty(argv,argc,property)
  238. char
  239. X  **argv;
  240. X
  241. int
  242. X  argc;
  243. X
  244. XXTextProperty
  245. X  *property;
  246. {
  247. X  register int
  248. X    i;
  249. X
  250. X  register unsigned int
  251. X    number_bytes;
  252. X
  253. X  XTextProperty
  254. X     protocol;
  255. X
  256. X  number_bytes=0;
  257. X  for (i=0; i < argc; i++)
  258. X    number_bytes+=(unsigned int) ((argv[i] ? strlen(argv[i]) : 0)+1);
  259. X  protocol.encoding=XA_STRING;
  260. X  protocol.format=8;
  261. X  protocol.nitems=0;
  262. X  if (number_bytes)
  263. X    protocol.nitems=number_bytes-1;
  264. X  protocol.value=NULL;
  265. X  if (number_bytes <= 0)
  266. X    {
  267. X      protocol.value=(unsigned char *) malloc(sizeof(char));
  268. X      if (!protocol.value)
  269. X        return(False);
  270. X      *protocol.value='\0';
  271. X    }
  272. X  else
  273. X    {
  274. X      register char
  275. X        *buffer;
  276. X
  277. X      buffer=(char *) malloc(number_bytes*sizeof(char));
  278. X      if (buffer == (char *) NULL)
  279. X        return(False);
  280. X      protocol.value=(unsigned char *) buffer;
  281. X      for (i=0; i < argc; i++)
  282. X      {
  283. X        char
  284. X          *argument;
  285. X
  286. X        argument=argv[i];
  287. X        if (!argument)
  288. X          *buffer++='\0';
  289. X        else
  290. X          {
  291. X            (void) strcpy(buffer,argument);
  292. X            buffer+=(strlen(argument)+1);
  293. X          }
  294. X      }
  295. X    }
  296. X  *property=protocol;
  297. X  return(True);
  298. }
  299. X
  300. void XSetWMProperties(display,window,window_name,icon_name,argv,argc,
  301. X  size_hints,manager_hints,class_hint)
  302. Display
  303. X  *display;
  304. X
  305. Window
  306. X  window;
  307. X
  308. XXTextProperty
  309. X  *window_name,
  310. X  *icon_name;
  311. X
  312. char
  313. X  **argv;
  314. X
  315. int
  316. X  argc;
  317. X
  318. XXSizeHints
  319. X  *size_hints;
  320. X
  321. XXWMHints *manager_hints;
  322. X
  323. XXClassHint
  324. X  *class_hint;
  325. {
  326. X  XSetStandardProperties(display,window,window_name->value,icon_name,None,
  327. X    argv,argc,size_hints);
  328. X  XSetWMHints(display,window,manager_hints);
  329. X  XSetClassHint(display,window,class_hint);
  330. }
  331. X
  332. Status XSetWMProtocols(display,window,protocols,count)
  333. Display
  334. X  *display;
  335. X
  336. Window
  337. X  window;
  338. X
  339. Atom
  340. X  *protocols;
  341. X
  342. int
  343. X  count;
  344. {
  345. X  Atom
  346. X    protocols_property;
  347. X
  348. X  protocols_property=XInternAtom(display,"WM_PROTOCOLS",False);
  349. X  XChangeProperty(display,window,protocols_property,XA_ATOM,32,PropModeReplace,
  350. X    (unsigned char *) protocols, count);
  351. X  return(True);
  352. }
  353. X
  354. VisualID XVisualIDFromVisual(visual)
  355. Visual
  356. X  *visual;
  357. {
  358. X  return(visual->visualid);
  359. }
  360. X
  361. Status XWithdrawWindow(display,window,screen)
  362. Display
  363. X  *display;
  364. X
  365. Window
  366. X  window;
  367. X
  368. int
  369. X  screen;
  370. {
  371. X  return(XUnmapWindow(display,window));
  372. }
  373. X
  374. int XWMGeometry(display,screen,user_geometry,default_geometry,border_width,
  375. X  size_hints,x,y,width,height,gravity)
  376. Display
  377. X  *display;
  378. X
  379. int
  380. X  screen;
  381. X
  382. char
  383. X  *user_geometry,
  384. X  *default_geometry;
  385. X
  386. unsigned int
  387. X  border_width;
  388. X
  389. XXSizeHints
  390. X  *size_hints;
  391. X
  392. int
  393. X  *x,
  394. X  *y,
  395. X  *width,
  396. X  *height,
  397. X  *gravity;
  398. {
  399. X  int
  400. X    status;
  401. X
  402. X  status=XGeometry(display,screen,user_geometry,default_geometry,border_width,
  403. X    0,0,0,0,x,y,width,height);
  404. X  *gravity=NorthWestGravity;
  405. X  return(status);
  406. }
  407. #endif
  408. SHAR_EOF
  409. chmod 0644 ImageMagick/PreRvIcccm.c ||
  410. echo 'restore of ImageMagick/PreRvIcccm.c failed'
  411. Wc_c="`wc -c < 'ImageMagick/PreRvIcccm.c'`"
  412. test 5666 -eq "$Wc_c" ||
  413.     echo 'ImageMagick/PreRvIcccm.c: original size 5666, current size' "$Wc_c"
  414. rm -f _shar_wnt_.tmp
  415. fi
  416. # ============= ImageMagick/PreRvIcccm.h ==============
  417. if test -f 'ImageMagick/PreRvIcccm.h' -a X"$1" != X"-c"; then
  418.     echo 'x - skipping ImageMagick/PreRvIcccm.h (File already exists)'
  419.     rm -f _shar_wnt_.tmp
  420. else
  421. > _shar_wnt_.tmp
  422. echo 'x - extracting ImageMagick/PreRvIcccm.h (Text)'
  423. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/PreRvIcccm.h' &&
  424. #ifdef PRE_R5_ICCCM
  425. /*
  426. X  Compatability defines for pre X11R5 ICCCM.
  427. */
  428. extern XrmDatabase
  429. X  XrmGetDatabase();
  430. #endif
  431. X
  432. #ifdef PRE_R4_ICCCM
  433. /*
  434. X  Compatability defines for pre X11R4 ICCCM.
  435. */
  436. #ifdef vms
  437. #define XMaxRequestSize(display)  16384
  438. #endif
  439. X
  440. #define XInductColormap(display,colormap)  XInstallColormap(display,colormap)
  441. #define XUninductColormap(display,colormap)  XUninstallColormap(display,colormap)
  442. X
  443. typedef struct _XTextProperty
  444. {
  445. X  unsigned char
  446. X    *value;
  447. X
  448. X  Atom
  449. X    encoding;
  450. X
  451. X  int
  452. X    format;
  453. X
  454. X  unsigned long
  455. X    nitems;
  456. } XTextProperty;
  457. X
  458. /*
  459. X  Pre R4 ICCCM compatibility routines.
  460. */
  461. char 
  462. X  *XResourceManagerString();
  463. X
  464. extern int
  465. X  XWMGeometry();
  466. X
  467. extern Status
  468. X  XGetRGBColormaps(),
  469. X  XGetWMName(),
  470. X  XReconfigureWMWindow(),
  471. X  XSetWMProtocols(),
  472. X  XWithdrawWindow();
  473. X
  474. extern XClassHint
  475. X  *XAllocClassHint();
  476. X
  477. extern XIconSize
  478. X  *XAllocIconSize();
  479. X
  480. extern XSizeHints
  481. X  *XAllocSizeHints();
  482. X
  483. extern XStandardColormap
  484. X  *XAllocStandardColormap();
  485. X
  486. extern XWMHints
  487. X  *XAllocWMHints();
  488. X
  489. extern VisualID
  490. X  XVisualIDFromVisual();
  491. X
  492. extern void
  493. X  XrmDestroyDatabase(),
  494. X  XSetWMProperties();
  495. #else
  496. #define XInductColormap(display,colormap)
  497. #define XUninductColormap(display,colormap)
  498. #endif
  499. SHAR_EOF
  500. chmod 0644 ImageMagick/PreRvIcccm.h ||
  501. echo 'restore of ImageMagick/PreRvIcccm.h failed'
  502. Wc_c="`wc -c < 'ImageMagick/PreRvIcccm.h'`"
  503. test 1201 -eq "$Wc_c" ||
  504.     echo 'ImageMagick/PreRvIcccm.h: original size 1201, current size' "$Wc_c"
  505. rm -f _shar_wnt_.tmp
  506. fi
  507. # ============= ImageMagick/README ==============
  508. if test -f 'ImageMagick/README' -a X"$1" != X"-c"; then
  509.     echo 'x - skipping ImageMagick/README (File already exists)'
  510.     rm -f _shar_wnt_.tmp
  511. else
  512. > _shar_wnt_.tmp
  513. echo 'x - extracting ImageMagick/README (Text)'
  514. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/README' &&
  515. AUTHOR
  516. X
  517. X  The author is cristy@dupont.com.  Comments, suggestions, or bug
  518. X  reports are welcome, but be kind.  This software is NOT shareware.
  519. X  However, I am interested in who might be using it.  Please consider
  520. X  sending me a picture postcard of the area where you live.  Send
  521. X  postcards to
  522. X
  523. X    John Cristy
  524. X    5 Middleton Lane
  525. X    Landenberg, PA  19350
  526. X
  527. X
  528. AVAILABLILITY
  529. X
  530. X  Anonymous FTP at export.lcs.mit.edu, file contrib/ImageMagick.tar.Z.
  531. X
  532. X
  533. UNIX COMPILATION
  534. X
  535. X  Type:
  536. X
  537. X    uncompress ImageMagick.tar.Z
  538. X    tar xvf ImageMagick.tar
  539. X    cd ImageMagick
  540. X    xmkmf
  541. X    make Makefiles
  542. X    make
  543. X
  544. X  If you do not have 'xmkmf', edit 'Makefile' as required by your
  545. X  hardware environment and type 'make'.
  546. X
  547. X  Finally type:
  548. X
  549. X    display images/aquarium.miff
  550. X    display -monochrome -dither images/aquarium.miff
  551. X
  552. X  If the image colors are not correct use this command:
  553. X
  554. X    display -visual default images/aquarium.miff
  555. X
  556. X  You can find other example images in the 'images' directory.
  557. X
  558. X  Be sure to read the manual pages for the display, animate, montage,
  559. X  import, mogrify, and convert utilities.
  560. X
  561. X  The ImageMagick utilites read and write MIFF images.  Refer to the
  562. X  end of this message for more information about MIFF.  Use `convert'
  563. X  to convert images to and from the MIFF format.
  564. X
  565. X  Some ImageMagick utilities recognizes these image formats:
  566. X
  567. X       Tag       Description
  568. X       ----------------------------------------------------
  569. X       AVS       AVS X image file
  570. X       BMP       Microsoft Windows bitmap image file
  571. X       EPS       Adobe Encapsulated Postscript
  572. X       GIF       Compuserve Graphics image file
  573. X       JPEG
  574. X       PCX       ZSoft IBM PC Paintbrush file
  575. X       PICT      Apple Macintosh QuickDraw/PICT file
  576. X       PNM       Portable bitmap
  577. X       PS        Adobe PostScript file
  578. X       RLE       Utah Raster Toolkit
  579. X       SUN       SUN raster
  580. X       TGA       Truevision Targa image file
  581. X       TIFF      Tagged Image File Format
  582. X       VICAR
  583. X       VIFF      Khoros Visualization image file.
  584. X       XBM       X11 bitmap
  585. X       XWD       X11 window dump
  586. X
  587. X  and for your convenience automatically converts the alien image
  588. X  format to MIFF at execution time.  However, the MIFF image format has
  589. X  several advantages over most image formats (i.e. runlength encoding,
  590. X  digital signature on an image colormap, etc.).  ImageMagick is
  591. X  designed to exploit these advantages.  Whenever possible convert an
  592. X  alien image format to the MIFF format before using the various
  593. X  ImageMagick programs.
  594. X
  595. X  Other formats are also recognized.  See CONVERT(1) for a list of
  596. X  valid image formats.  You can specify a particular image format by
  597. X  prefixing the image filename with the image type and a colon (i.e.
  598. X  ps:image.ps).
  599. X
  600. X  ImageMagick requires GNU's Ghostscript software available via FTP as
  601. X  ftp.uu.net:systems/gnu/ghostscript-2.6.1.tar.gz to read the
  602. X  Postscript format.  For ImageMagick to read Postscript files, `gs'
  603. X  must be in your execution path and the `pbmraw' and `ppmraw' devices
  604. X  must be recognized.  Add it to your 'DEVICE_DEVS' define in your
  605. X  Ghostscript `Makefile' and recompile.
  606. X
  607. X  ImageMagick requires the Independent JPEG Group's software available via 
  608. X  FTP as ftp.uu.net:graphics/jpeg/jpegsrc.v4.tar.Z to read the JPEG image
  609. X  format.
  610. X
  611. X  ImageMagick requires Sam Leffler's TIFF software available via FTP as 
  612. X  sgi.com:graphics/tiff/v3.2beta.tar.Z to read the TIFF image format.
  613. X
  614. X  To display images in the JPEG or TIFF format, get the JPEG and TIFF
  615. X  archives and build ImageMagick as follows:
  616. X
  617. X    cd ImageMagick
  618. X    mkdir jpeg
  619. X    cd jpeg
  620. X    zcat jpegsrc.v4.tar.Z | tar xvof -
  621. X    cp jmemnobs.c jmemsys.c
  622. X    cp makefile.unix Makefile
  623. X    make libjpeg.a
  624. X    cd ..
  625. X    mkdir tiff
  626. X    cd tiff
  627. X    zcat v3.2beta.tar.Z | tar xvof -
  628. X    cd libtiff
  629. X    cp Makefile.sun Makefile
  630. X    make
  631. X    cd ../..
  632. X    < edit Magick.tmpl and define HasJPEG and HasTIFF lines as instructed >
  633. X    touch decode.c
  634. X    touch encode.c
  635. X    xmkmf
  636. X    make Makefiles
  637. X    make
  638. X
  639. X  You can now display images in the JPEG or TIFF format.
  640. X
  641. X  If you have a colormapped X server, the number of unique colors in an
  642. X  image must first be reduced to match the requirements of your server
  643. X  before it can be displayed.  ImageMagick tries to make the color reduced
  644. X  image closely resemble the original.  However, this process can be
  645. X  time consuming.  To speed it up, ImageMagick trades image quality for
  646. X  processing time.  For the "best" image possible, type
  647. X
  648. X      display -colors 256 -dither image.jpeg
  649. X
  650. X  or add this to your X resources file:
  651. X
  652. X      display.colors: 256
  653. X
  654. X  This example assumes your server supports 256 colors.  Choose
  655. X  whatever value is appropriate for your X server.  Alternatively if
  656. X  you intend to view the image frequently, reduce the number of colors
  657. X  to match the resolution of your X server once and write to a new
  658. X  image.  Then display this new image.  For example,
  659. X
  660. X      convert -colors 256 -dither image.jpeg image.miff
  661. X      display image.miff
  662. X
  663. X  The default dimensions of a Postscript page is 612x792.  If you prefer
  664. X  another default, change the PageWidth and PageHeight defines in encode.c.
  665. X
  666. X
  667. VMS COMPILATION
  668. X
  669. X  Type
  670. X
  671. X    @make
  672. X    set display/create/node=node_name::
  673. X
  674. X  where node_name is the DECNET X server to contact.
  675. X
  676. X  Finally type:
  677. X
  678. X    display images/aquarium.miff
  679. X    display -monochrome -dither images/aquarium.miff
  680. X
  681. X
  682. ANIMATION
  683. X
  684. X  An example animation sequence is available from anonymous FTP at
  685. X  export.lcs.mit.edu, file contrib/ImageMagick.animation.tar.Z Or
  686. X  alternatively, you can create this sequence yourself.  Just look at
  687. X  README in the scenes directory.
  688. X  
  689. X  To prevent color flashing on visuals that have colormaps, `animate'
  690. X  creates a single colormap from the image sequence.  This can be
  691. X  rather time consuming.  You can speed this operation up by reducing
  692. X  the colors in the image before you `animate' them.  Use `mogrify' to
  693. X  color reduce the images:
  694. X
  695. X    mogrify -colors 256 scenes/dna.[0-9]*
  696. X
  697. X  Note, the image sequence in ImageMagick.animation.tar.Z is already
  698. X  reduced.  Alternatively, you can use a Standard Colormap; or a
  699. X  static, direct, or true color visual.  You can define a Standard
  700. X  Colormap with `xstdcmap'.  For example, to use the "best" Standard
  701. X  Colormap, type:
  702. X
  703. X    xstdcmap -best
  704. X    animate -map best scenes/dna.[0-9]*
  705. X
  706. X  or to use a true color visual:
  707. X
  708. X    animate -visual truecolor scenes/dna.[0-9]*
  709. X
  710. X  Image filenames can appear in any order on the command line if the
  711. X  scene keyword is specified in the MIFF image.  Otherwise the images
  712. X  display in the order they appear on the command line.  A scene is
  713. X  specified when converting from another image format to MIFF by using
  714. X  the "scene" option with any filter.  Be sure to choose a scene number
  715. X  other than zero.  For example, to convert a TIFF image to a MIFF
  716. X  image as scene #2, type:
  717. X
  718. X    convert -scene 2 image.tiff image.miff
  719. X
  720. X
  721. NOTES
  722. X
  723. X  1.  If you get a compile error on XTextProperty in PreRvIcccm.h,
  724. X      change it to _XTextProperty. If you get a compile error on
  725. X      XVisualIDFromVisual in PreRvIcccm.c, change it to
  726. X      _XVisualIDFromVisual.
  727. X
  728. X  2.  24 bit images are reduced to 244 colors on an 8 bit display to
  729. X      help prevent colormap flashing.  If you want all 256 colors, type
  730. X
  731. X        display -colors 256 image.miff
  732. X
  733. X      To further help reduce colormap flashing, do not install the
  734. X      default standard colormap (RGB_DEFAULT_MAP).
  735. X
  736. X  3.  Machine dependancies:
  737. X
  738. X      For MacX, set the DISPLAY variable to host:0.2 for the color
  739. X      rootless window.
  740. X
  741. X      I suspect all the following problems will be fixed when these
  742. X      vendors upgrade to X11R4.  I find conditional compilation
  743. X      statements offensive.  So if you have any of the following
  744. X      problems, the fix must be applied manually.
  745. X
  746. X      MIPS does not always generate exposure events correctly when
  747. X      displaying a monochrome image on their color server.  Holes in the
  748. X      image may appear when an area is blocked then exposed.  I do not
  749. X      currently have a solution for this problem.
  750. X
  751. X      Images do not dislay correctly on the IBM R6000 visual with 4096
  752. X      colors.  However they do display correctly on the visual with 256
  753. X      colors.  Until IBM fixes their server, type xdpyinfo to determine 
  754. X      the ID of the 256 color visual and type
  755. X
  756. X        display -visual 0x???? image.miff
  757. X
  758. X      On the Stardent put
  759. X
  760. X        *installColormap:  on
  761. X
  762. X      in your X resource file.
  763. X
  764. X      Digital and Tektronix has a bug in their servers.  When converting
  765. X      from LSBFirst to MSBFirst X server (or visa-versa) you may get the 
  766. X      error
  767. X
  768. X        Illegal unit size: 8 found in routine: _normalizeimagebits
  769. X
  770. X      On some HP's you may get a memory fault when exiting display(1).
  771. X      To fix this problem comment out the XCLoseDisplay line near the
  772. X      last line of display.c and recompile.  Under HPUX 9.0 the compiler
  773. X      has a bug.  You might have to compile image.c unoptimized to
  774. X      prevent bus errors with montage(1).
  775. X
  776. X  4.  On occasion, a window manager (twm) may get in strange state which will 
  777. X      cause the display program to work improperly.  Fix this by restarting the
  778. X      window manager.
  779. X
  780. X  5.  If the image is displayed with incorrect colors, try using a different
  781. X      visual.  Type xdpyinfo and choose an alternative visual (if one exists)
  782. X      by either visual class or visual id.  For example, to specifically 
  783. X      choose a PseudoColor visual on a server that supports it, type
  784. X
  785. X        display -visual pseudocolor image.miff
  786. X
  787. X  6.  Make sure that the include file math.h defines the function atof as
  788. X      type double.  Otherwise the -gamma option will not work properly.
  789. X
  790. X  7.  If you get a compile error on "WithdrawnState", replace
  791. X      "WithdrawnState" with "0";
  792. X
  793. X
  794. MIFF IMAGE FORMAT
  795. X
  796. X  MIFF is an image format which I developed.  I like it because it
  797. X
  798. X    1) It is machine independant.  It can be read on virtually any
  799. X       computer.  No byte swapping is necessary.
  800. X
  801. X    2) It has a text header.  Most image formats are coded in binary
  802. X       and you cannot easily tell attributes about the image.  Use
  803. X       'more' on MIFF image files and the attributes are displayed in
  804. X       text form.
  805. X
  806. X    3) It can handle runlength-encoded images.  Although most scanned
  807. X       images do not benefit from runlength-encoding, most
  808. X       computer-generated images do.  Images of mostly uniform colors
  809. X       have a high compression ratio and therefore take up less memory
  810. X       and disk space.
  811. X
  812. X    4) It allows a scene number to be specified.  This allows you to
  813. X       specify an animation sequence out-of-order on the command line.
  814. X       The correct order is determined by the scene number of each
  815. X       image.
  816. X
  817. X    5) MIFF computes a digital signature for colormapped images.  This
  818. X       is useful for animating a sequence of images on a colormapped X
  819. X       server.  If all signatures match in the image sequence,
  820. X       computing a global colormap is not necessary.
  821. X
  822. X  One way to get an image into MIFF format is to use `convert'.  or
  823. X  read it from an X window using the 'import' program.  Alternatively,
  824. X  type the necessary header information in a file with a text editor.
  825. X  Next, dump the binary bytes into another file.  Finally, type
  826. X
  827. X    cat header binary_image | display -write image.miff -
  828. X
  829. X  For example, suppose you have a raw red, green, blue image file on
  830. X  disk that is 640 by 480.  The header file would look like this:
  831. X
  832. X    id=ImageMagick columns=640 rows=480 :
  833. X
  834. X  The image file would have red, green, blue tuples (rgbrgbrgb...).
  835. X
  836. X  Refer to the 'display' manual page for more details.
  837. X
  838. COPYRIGHT
  839. X
  840. X  Copyright 1993 E. I. du Pont de Nemours & Company
  841. X
  842. X  Permission to use, copy, modify, distribute, and sell this software and
  843. X  its documentation for any purpose is hereby granted without fee,
  844. X  provided that the above copyright notice appear in all copies and that
  845. X  both that copyright notice and this permission notice appear in
  846. X  supporting documentation, and that the name of E. I. du Pont de Nemours
  847. X  & Company not be used in advertising or publicity pertaining to
  848. X  distribution of the software without specific, written prior
  849. X  permission.  E. I. du Pont de Nemours & Company makes no representations
  850. X  about the suitability of this software for any purpose.  It is provided
  851. X  "as is" without express or implied warranty.
  852. X
  853. X  E. I. du Pont de Nemours & Company disclaims all warranties with regard
  854. X  to this software, including all implied warranties of merchantability
  855. X  and fitness, in no event shall E. I. du Pont de Nemours & Company be
  856. X  liable for any special, indirect or consequential damages or any
  857. X  damages whatsoever resulting from loss of use, data or profits, whether
  858. X  in an action of contract, negligence or other tortious action, arising
  859. X  out of or in connection with the use or performance of this software.
  860. SHAR_EOF
  861. chmod 0644 ImageMagick/README ||
  862. echo 'restore of ImageMagick/README failed'
  863. Wc_c="`wc -c < 'ImageMagick/README'`"
  864. test 12850 -eq "$Wc_c" ||
  865.     echo 'ImageMagick/README: original size 12850, current size' "$Wc_c"
  866. rm -f _shar_wnt_.tmp
  867. fi
  868. # ============= ImageMagick/SYNOPSIS ==============
  869. if test -f 'ImageMagick/SYNOPSIS' -a X"$1" != X"-c"; then
  870.     echo 'x - skipping ImageMagick/SYNOPSIS (File already exists)'
  871.     rm -f _shar_wnt_.tmp
  872. else
  873. > _shar_wnt_.tmp
  874. echo 'x - extracting ImageMagick/SYNOPSIS (Text)'
  875. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/SYNOPSIS' &&
  876. ImageMagick is a collection of X11 image processing and display utilities.  It
  877. is available on export.lcs.mit.edu as contrib/ImageMagick.tar.Z.
  878. X
  879. cristy@dupont.com
  880. X
  881. ---
  882. X
  883. Display
  884. X
  885. X     Display is a machine architecture independent image
  886. X     processing and display program.  It can display an image on
  887. X     any workstation display running an X server.  Display first
  888. X     determines the hardware capabilities of the workstation.  If
  889. X     the number of unique colors in the image is less than or
  890. X     equal to the number the workstation can support, the image
  891. X     is displayed in an X window.  Otherwise the number of colors
  892. X     in the image is first reduced to match the color resolution
  893. X     of the workstation before it is displayed.
  894. X
  895. X     This means that a continuous-tone 24 bits/pixel image can
  896. X     display on a 8 bit pseudo-color device or monochrome device.
  897. X     In most instances the reduced color image closely resembles
  898. X     the original.  Alternatively, a monochrome or pseudo-color
  899. X     image can display on a continuous-tone 24 bits/pixels
  900. X     device.
  901. X
  902. X
  903. Import
  904. X
  905. X     Import reads an image from any visible window on an X server
  906. X     and outputs it as an image file.  You can capture a single
  907. X     window, the entire screen, or any rectangular portion of the
  908. X     screen.  You can use display (see display(1)) utility for
  909. X     redisplay, printing, editing, formatting, archiving, image
  910. X     processing, etc. of the captured image.
  911. X
  912. X     The target window can be specified by id, name, or may be
  913. X     selected by clicking the mouse in the desired window.  If
  914. X     you press a button and then drag, a rectangle will form
  915. X     which expands and contracts as the mouse moves.  To save the
  916. X     portion of the screen  defined by the rectangle, just
  917. X     release the button.  The keyboard bell is rung once at the
  918. X     beginning of the screen capture and twice when it completes.
  919. X
  920. X
  921. Animate
  922. X
  923. X     Animate displays a sequence of images on any workstation
  924. X     display running an X server.  Animate first determines the
  925. X     hardware capabilities of the workstation.  If the number of
  926. X     unique colors in an image is less than or equal to the
  927. X     number the workstation can support, the image is displayed
  928. X     in an X window.  Otherwise the number of colors in the image
  929. X     is first reduced to match the color resolution of the
  930. X     workstation before it is displayed.
  931. X
  932. X     This means that a continuous-tone 24 bits/pixel image can
  933. X     display on a 8 bit pseudo-color device or monochrome device.
  934. X     In most instances the reduced color image closely resembles
  935. X     the original.  Alternatively, a monochrome or pseudo-color
  936. X     image sequence can display on a continuous-tone 24
  937. X     bits/pixels device.
  938. X
  939. X
  940. Montage
  941. X
  942. X     Montage creates a composite image by combining several
  943. X     separate images.  The images are tiled on the composite
  944. X     image with the name of the image optionally appearing just
  945. X     below the individual tile.
  946. X
  947. X
  948. Mogrify
  949. X
  950. X     Mogrify transforms an image or a sequence of images.  These
  951. X     transforms include image scaling, image rotation, color
  952. X     reduction, and others.  The transmogrified image overwrites
  953. X     the original image.
  954. X
  955. X
  956. Convert
  957. X
  958. X     Convert converts an input file using one image format to an
  959. X     output file with a differing image format. By default, the
  960. X     image format is determined by it's magic number. To specify
  961. X     a particular image format, precede the filename with an
  962. X     image format name and a colon (i.e.  ps:image) or specify
  963. X     the image type as the filename suffix (i.e. image.ps).
  964. X     Specify file as - for standard input or output.  If file has
  965. X     the extension .Z, the file is decoded with uncompress.
  966. X
  967. X     Convert recognizes the following image formats:
  968. X
  969. X       Tag       Description
  970. X       ----------------------------------------------------
  971. X       ALPHA     Raw alpha bytes
  972. X       AVS       AVS X image file
  973. X       BMP       Microsoft Windows bitmap image file
  974. X       CMYK      Raw cyan, magenta, yellow, and black bytes
  975. X       EPS       Adobe Encapsulated Postscript
  976. X       FAX       Group 3
  977. X       GIF       Compuserve Graphics image file
  978. X       GRAY      Raw gray bytes
  979. X       JPEG
  980. X       MIFF      Machine Independant file format
  981. X       MTV
  982. X       PCX       ZSoft IBM PC Paintbrush file
  983. X       PICT      Apple Macintosh QuickDraw/PICT file
  984. X       PNM       Portable bitmap
  985. X       PS        Adobe PostScript file
  986. X       PS2       Adobe PostScript Level II file
  987. X       RGB       Raw red, green, and blue bytes
  988. X       RLE       Utah Raster Toolkit
  989. X       SUN       SUN raster
  990. X       TGA       Truevision Targa image file
  991. X       TEXT      raw text file;  read only
  992. X       TIFF      Tagged Image File Format
  993. X       VICAR
  994. X       VIFF      Khoros Visualization image file.
  995. X       X         select image from X server screen
  996. X       XC        constant image of X server background color
  997. X       XBM       X11 bitmap
  998. X       XWD       X11 window dump
  999. X       YUV       Raw Y, U, and V bytes
  1000. X
  1001. X
  1002. Combine
  1003. X
  1004. X     Combine combines images to create new images.
  1005. X
  1006. X
  1007. Segment
  1008. X
  1009. X     Segment segments an image by analyzing the histograms of the
  1010. X     color components and identifying units that are homogeneous
  1011. X     with the fuzzy c-means technique.  The scale-space filter
  1012. X     analyzes the histograms of the three color components of the
  1013. X     image and identifies a set of classes.  The extents of each
  1014. X     class is used to coarsely segment the image with
  1015. X     thresholding.  The color associated with each class is
  1016. X     determined by the mean color of all pixels within the
  1017. X     extents of a particular class.  Finally, any unclassified
  1018. X     pixels are assigned to the closest class with the fuzzy c-
  1019. X     means technique.
  1020. X
  1021. X
  1022. XXTP
  1023. X
  1024. X     Xtp is a utility for retrieving, listing, or printing files
  1025. X     from a remote network site, or sending files to a remote
  1026. X     network site.  Xtp performs most of the same functions as
  1027. X     the ftp program, but does not require any interactive
  1028. X     commands.  You simply specify the file transfer task on the
  1029. X     command line and xtp performs the task automatically.
  1030. SHAR_EOF
  1031. chmod 0644 ImageMagick/SYNOPSIS ||
  1032. echo 'restore of ImageMagick/SYNOPSIS failed'
  1033. Wc_c="`wc -c < 'ImageMagick/SYNOPSIS'`"
  1034. test 6075 -eq "$Wc_c" ||
  1035.     echo 'ImageMagick/SYNOPSIS: original size 6075, current size' "$Wc_c"
  1036. rm -f _shar_wnt_.tmp
  1037. fi
  1038. # ============= ImageMagick/X.c ==============
  1039. if test -f 'ImageMagick/X.c' -a X"$1" != X"-c"; then
  1040.     echo 'x - skipping ImageMagick/X.c (File already exists)'
  1041.     rm -f _shar_wnt_.tmp
  1042. else
  1043. > _shar_wnt_.tmp
  1044. echo 'x - extracting ImageMagick/X.c (Text)'
  1045. sed 's/^X//' << 'SHAR_EOF' > 'ImageMagick/X.c' &&
  1046. /*
  1047. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1048. %                                                                             %
  1049. %                                                                             %
  1050. %                                                                             %
  1051. %                                                                             %
  1052. %                                     X   X                                   %
  1053. %                                      X X                                    %
  1054. %                                       X                                     %
  1055. %                                      X X                                    %
  1056. %                                     X   X                                   %
  1057. %                                                                             %
  1058. %                          X11 Utility Routines for Display.                  %
  1059. %                                                                             %
  1060. %                                                                             %
  1061. %                                 Software Design                             %
  1062. %                                   John Cristy                               %
  1063. %                                    July 1992                                %
  1064. %                                                                             %
  1065. %                                                                             %
  1066. %  Copyright 1993 E. I. du Pont de Nemours & Company                          %
  1067. %                                                                             %
  1068. %  Permission to use, copy, modify, distribute, and sell this software and    %
  1069. %  its documentation for any purpose is hereby granted without fee,           %
  1070. %  provided that the above Copyright notice appear in all copies and that     %
  1071. %  both that Copyright notice and this permission notice appear in            %
  1072. %  supporting documentation, and that the name of E. I. du Pont de Nemours    %
  1073. %  & Company not be used in advertising or publicity pertaining to            %
  1074. %  distribution of the software without specific, written prior               %
  1075. %  permission.  E. I. du Pont de Nemours & Company makes no representations   %
  1076. %  about the suitability of this software for any purpose.  It is provided    %
  1077. %  "as is" without express or implied warranty.                               %
  1078. %                                                                             %
  1079. %  E. I. du Pont de Nemours & Company disclaims all warranties with regard    %
  1080. %  to this software, including all implied warranties of merchantability      %
  1081. %  and fitness, in no event shall E. I. du Pont de Nemours & Company be       %
  1082. %  liable for any special, indirect or consequential damages or any           %
  1083. %  damages whatsoever resulting from loss of use, data or profits, whether    %
  1084. %  in an action of contract, negligence or other tortious action, arising     %
  1085. %  out of or in connection with the use or performance of this software.      %
  1086. %                                                                             %
  1087. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1088. %
  1089. %
  1090. */
  1091. X
  1092. /*
  1093. X  Include declarations.
  1094. */
  1095. #include "display.h"
  1096. #include "image.h"
  1097. #include "X.h"
  1098. X
  1099. /*
  1100. X  State declarations.
  1101. */
  1102. #define ControlState  0x0001
  1103. #define DefaultState  0x0000
  1104. #define ExitState  0x0002
  1105. X
  1106. /*
  1107. X  External declarations.
  1108. */
  1109. extern char
  1110. X  *client_name;
  1111. X
  1112. extern void
  1113. X  Error _Declare((char *,char *));
  1114. X
  1115. /*
  1116. X  Forward declarations.
  1117. */
  1118. int
  1119. X  Latin1Compare _Declare((char *,char *));
  1120. X
  1121. static Image
  1122. X  *XGetWindowImage _Declare((Display *,Window,unsigned int,unsigned int));
  1123. X
  1124. static void
  1125. X  XHighlightRegion _Declare((Display *,Window,GC,RectangleInfo *)),
  1126. X  XMakeImageLSBFirst _Declare((XWindowInfo *,Image *, XImage *)),
  1127. X  XMakeImageMSBFirst _Declare((XWindowInfo *,Image *, XImage *));
  1128. X
  1129. static Window
  1130. X  XClientWindow _Declare((Display *,Window)),
  1131. X  XSelectWindow _Declare((Display *,RectangleInfo *)),
  1132. X  XWindowByProperty _Declare((Display *,Window,Atom));
  1133. X
  1134. /*
  1135. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1136. %                                                                             %
  1137. %                                                                             %
  1138. %                                                                             %
  1139. %   I s T r u e                                                               %
  1140. %                                                                             %
  1141. %                                                                             %
  1142. %                                                                             %
  1143. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1144. %
  1145. %  Function IsTrue returns True if the boolean is "true", "on", "yes" or "1".
  1146. %
  1147. %  The format of the IsTrue routine is:
  1148. %
  1149. %      option=IsTrue(boolean)
  1150. %
  1151. %  A description of each parameter follows:
  1152. %
  1153. %    o option: either True or False depending on the boolean parameter.
  1154. %
  1155. %    o boolean: Specifies a pointer to a character array.
  1156. %
  1157. %
  1158. */
  1159. unsigned int IsTrue(boolean)
  1160. char
  1161. X  *boolean;
  1162. {
  1163. X  if (boolean == (char *) NULL)
  1164. X    return(False);
  1165. X  if (Latin1Compare(boolean,"true") == 0)
  1166. X    return(True);
  1167. X  if (Latin1Compare(boolean,"on") == 0)
  1168. X    return(True);
  1169. X  if (Latin1Compare(boolean,"yes") == 0)
  1170. X    return(True);
  1171. X  if (Latin1Compare(boolean,"1") == 0)
  1172. X    return(True);
  1173. X  return(False);
  1174. }
  1175. X
  1176. /*
  1177. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1178. %                                                                             %
  1179. %                                                                             %
  1180. %                                                                             %
  1181. %   L a t i n 1 C o m p a r e                                                 %
  1182. %                                                                             %
  1183. %                                                                             %
  1184. %                                                                             %
  1185. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1186. %
  1187. %  Function Latin1Compare compares two null terminated Latin-1 strings,
  1188. %  ignoring case differences, and returns an integer greater than, equal
  1189. %  to, or less than 0, according to whether first is lexicographically
  1190. %  greater than, equal to, or less than second.  The two strings are
  1191. %  assumed to be encoded using ISO 8859-1.
  1192. %
  1193. %  The format of the Latin1Compare routine is:
  1194. %
  1195. %      Latin1Compare(first,second)
  1196. %
  1197. %  A description of each parameter follows:
  1198. %
  1199. %    o first: A pointer to the string to convert to Latin1 string.
  1200. %
  1201. %    o second: A pointer to the string to convert to Latin1 string.
  1202. %
  1203. %
  1204. */
  1205. int Latin1Compare(first,second)
  1206. char
  1207. X  *first,
  1208. X  *second;
  1209. {
  1210. X  register unsigned char
  1211. X   *p,
  1212. X   *q;
  1213. X
  1214. X  p=(unsigned char *) first;
  1215. X  q=(unsigned char *) second;
  1216. X  while ((*p != '\0') && (*q != '\0'))
  1217. X  {
  1218. X    register unsigned char
  1219. X      c,
  1220. X      d;
  1221. X
  1222. X    c=(*p);
  1223. X    d=(*q);
  1224. X    if (c != d)
  1225. X      {
  1226. X        /*
  1227. X          Try lowercasing and try again.
  1228. X        */
  1229. X        if ((c >= XK_A) && (c <= XK_Z))
  1230. X          c+=(XK_a-XK_A);
  1231. X        else
  1232. X          if ((c >= XK_Agrave) && (c <= XK_Odiaeresis))
  1233. X            c+=(XK_agrave-XK_Agrave);
  1234. X          else
  1235. X            if ((c >= XK_Ooblique) && (c <= XK_Thorn))
  1236. X              c+=(XK_oslash-XK_Ooblique);
  1237. X        if ((d >= XK_A) && (d <= XK_Z))
  1238. X          d+=(XK_a-XK_A);
  1239. X        else
  1240. X          if ((d >= XK_Agrave) && (d <= XK_Odiaeresis))
  1241. X            d+=(XK_agrave-XK_Agrave);
  1242. X          else if ((d >= XK_Ooblique) && (d <= XK_Thorn))
  1243. X            d+=(XK_oslash-XK_Ooblique);
  1244. X        if (c != d)
  1245. X          return(((int) c)-((int) d));
  1246. X      }
  1247. X    p++;
  1248. X    q++;
  1249. X  }
  1250. X  return(((int) *p)-((int) *q));
  1251. }
  1252. X
  1253. /*
  1254. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1255. %                                                                             %
  1256. %                                                                             %
  1257. %                                                                             %
  1258. %   L a t i n 1 U p p e r                                                     %
  1259. %                                                                             %
  1260. %                                                                             %
  1261. %                                                                             %
  1262. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1263. %
  1264. %  Function Latin1Upper copies a null terminated string from src to dst
  1265. %  (including the null), changing all Latin-1 lowercase letters to
  1266. %  uppercase.  The string is assumed to be encoded using ISO 8859-1.
  1267. %
  1268. %  The format of the Latin1Upper routine is:
  1269. %
  1270. %      Latin1Upper(string)
  1271. %
  1272. %  A description of each parameter follows:
  1273. %
  1274. %    o string: A pointer to the string to convert to upper-case Latin1.
  1275. %
  1276. %
  1277. */
  1278. static void Latin1Upper(string)
  1279. char
  1280. X  *string;
  1281. {
  1282. X  unsigned char
  1283. X    c;
  1284. X
  1285. X  c=(*string);
  1286. X  while (c != '\0')
  1287. X  {
  1288. X    if ((c >= XK_a) && (c <= XK_z))
  1289. X      *string=c-(XK_a-XK_A);
  1290. X    else
  1291. X      if ((c >= XK_agrave) && (c <= XK_odiaeresis))
  1292. X        *string=c-(XK_agrave-XK_Agrave);
  1293. X      else
  1294. X        if ((c >= XK_oslash) && (c <= XK_thorn))
  1295. X          *string=c-(XK_oslash-XK_Ooblique);
  1296. X    string++;
  1297. X    c=(*string);
  1298. X  }
  1299. }
  1300. X
  1301. /*
  1302. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1303. %                                                                             %
  1304. %                                                                             %
  1305. %                                                                             %
  1306. %   R e a d X I m a g e                                                       %
  1307. %                                                                             %
  1308. %                                                                             %
  1309. %                                                                             %
  1310. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1311. %
  1312. %  Procedure ReadXImage reads an image from an X window.
  1313. %
  1314. %  The format of the ReadXImage routine is:
  1315. %
  1316. %      image=ReadXImage(filename,server_name,frame,borders,screen,descend)
  1317. %
  1318. %  A description of each parameter follows:
  1319. %
  1320. %    o image: Specifies a pointer to the Image structure.
  1321. %
  1322. %    o filename: Specifies the name of the image to read.
  1323. %
  1324. %    o server_name: Specifies the name of the X server to read image from.
  1325. %
  1326. %    o frame: Specifies whether to include the window manager frame with the
  1327. %      image.
  1328. %
  1329. %    o borders: Specifies whether borders pixels are to be saved with
  1330. %      the image.
  1331. %
  1332. %    o screen: Specifies whether the GetImage request used to obtain the image
  1333. %      should be done on the root window, rather than directly on the specified
  1334. %      window.
  1335. %
  1336. %    o descend: If this option is zero the colormap of the chosen window is
  1337. %      used to obtain the red, green, and blue values.  Otherwise the image
  1338. %      is obtained by descending the window hierarchy and reading each
  1339. %      subwindow and its colormap.
  1340. %
  1341. %
  1342. */
  1343. Image *ReadXImage(filename,server_name,frame,borders,screen,descend)
  1344. char
  1345. X  *filename,
  1346. X  *server_name;
  1347. X
  1348. unsigned int
  1349. X  frame,
  1350. X  borders,
  1351. X  screen,
  1352. X  descend;
  1353. {
  1354. X  Display
  1355. X    *display;
  1356. X
  1357. X  Image
  1358. X    *image;
  1359. X
  1360. X  int
  1361. X    status,
  1362. X    x;
  1363. X
  1364. X  RectangleInfo
  1365. X    clip_info;
  1366. X
  1367. X  Window
  1368. X    client_window,
  1369. X    root_window,
  1370. X    target_window;
  1371. X
  1372. X  XTextProperty
  1373. X    window_name;
  1374. X
  1375. X  /*
  1376. X    Open X server connection.
  1377. X  */
  1378. X  display=XOpenDisplay(server_name);
  1379. X  if (display == (Display *) NULL)
  1380. X    {
  1381. X      Warning("unable to connect to X server",XDisplayName(server_name));
  1382. X      return((Image *) NULL);
  1383. X    }
  1384. X  /*
  1385. X    Set our forgiving error handler.
  1386. X  */
  1387. X  XSetErrorHandler(XError);
  1388. X  /*
  1389. X    Select target window.
  1390. X  */
  1391. X  clip_info.x=0;
  1392. X  clip_info.y=0;
  1393. X  clip_info.width=0;
  1394. X  clip_info.height=0;
  1395. X  root_window=XRootWindow(display,XDefaultScreen(display));
  1396. X  target_window=(Window) NULL;
  1397. X  if ((filename != (char *) NULL) && (*filename != '\0'))
  1398. X    if (Latin1Compare(filename,"root") == 0)
  1399. X      target_window=root_window;
  1400. X    else
  1401. X      {
  1402. X        /*
  1403. X          Select window by ID or name.
  1404. X        */
  1405. X        if (isdigit(*filename))
  1406. X          target_window=XWindowByID(display,root_window,
  1407. X            (Window) strtol(filename,(char **) NULL,0));
  1408. X        if (target_window == (Window) NULL)
  1409. X          target_window=XWindowByName(display,root_window,filename);
  1410. X        if (target_window == (Window) NULL)
  1411. X          Warning("No window with specified id exists",filename);
  1412. X      }
  1413. X  /*
  1414. X    If target window is not defined, interactively select one.
  1415. X  */
  1416. X  if (target_window == (Window) NULL)
  1417. X    target_window=XSelectWindow(display,&clip_info);
  1418. X  client_window=target_window;
  1419. X  if (target_window != root_window)
  1420. X    {
  1421. X      unsigned int
  1422. X        d;
  1423. X
  1424. X      /*
  1425. X        Get client window.
  1426. X      */
  1427. X      status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
  1428. X      if (status != 0)
  1429. X        {
  1430. X          client_window=XClientWindow(display,target_window);
  1431. X          if (!frame)
  1432. X            target_window=client_window;
  1433. X        }
  1434. X    }
  1435. X  if (screen)
  1436. X    {
  1437. X      int
  1438. X        y;
  1439. X
  1440. X      Window
  1441. X        child;
  1442. X
  1443. X      XWindowAttributes
  1444. X        window_attributes;
  1445. X
  1446. X      /*
  1447. X        Obtain window image directly from screen.
  1448. X      */
  1449. X      status=XGetWindowAttributes(display,target_window,&window_attributes);
  1450. X      if (status == False)
  1451. X        {
  1452. X          Warning("unable to read X window attributes",filename)
  1453. X          XCloseDisplay(display);
  1454. X          return((Image *) NULL);
  1455. X        }
  1456. X      XTranslateCoordinates(display,target_window,root_window,0,0,&x,&y,&child);
  1457. X      clip_info.x=x;
  1458. X      clip_info.y=y;
  1459. X      clip_info.width=window_attributes.width;
  1460. X      clip_info.height=window_attributes.height;
  1461. X      if (borders)
  1462. X        {
  1463. X          /*
  1464. X            Include border in image.
  1465. X          */
  1466. X          clip_info.x-=window_attributes.border_width;
  1467. X          clip_info.y-=window_attributes.border_width;
  1468. X          clip_info.width+=2*window_attributes.border_width;
  1469. X          clip_info.height+=2*window_attributes.border_width;
  1470. X        }
  1471. X      target_window=root_window;
  1472. X    }
  1473. X  /*
  1474. X    Alert the user not to alter the screen.
  1475. X  */
  1476. X  XBell(display,0);
  1477. X  /*
  1478. X    Get image by window id.
  1479. X  */
  1480. X  image=XGetWindowImage(display,target_window,borders,descend);
  1481. X  if (image == (Image *) NULL)
  1482. X    Warning("unable to read X window image",filename)
  1483. X  else
  1484. X    {
  1485. X      if ((clip_info.width != 0) && (clip_info.height != 0))
  1486. X        {
  1487. X          Image
  1488. X            *clipped_image;
  1489. X
  1490. X          /*
  1491. X            Clip image as defined by the clipping rectangle.
  1492. X          */
  1493. X          clipped_image=ClipImage(image,&clip_info);
  1494. X          if (clipped_image != (Image *) NULL)
  1495. X            {
  1496. X              DestroyImage(image);
  1497. X              image=clipped_image;
  1498. X            }
  1499. X        }
  1500. X      status=XGetWMName(display,target_window,&window_name);
  1501. X      if (status == True)
  1502. X        {
  1503. X          if ((filename != (char *) NULL) && (*filename == '\0'))
  1504. X            {
  1505. X              /*
  1506. X                Initialize image filename.
  1507. X              */
  1508. X              (void) strncpy(image->filename,(char *) window_name.value,
  1509. X                (int) window_name.nitems);
  1510. X              image->filename[window_name.nitems]='\0';
  1511. X            }
  1512. X          /*
  1513. X            Initialize image comment.
  1514. X          */
  1515. X          image->comments=(char *)
  1516. X            malloc((strlen((char *) window_name.value)+2048)*sizeof(char));
  1517. X          if (image->comments != (char *) NULL)
  1518. X            (void) sprintf(image->comments,
  1519. X              "\n  Imported from X11 window:  %*s\n",(int) window_name.nitems,
  1520. X              window_name.value);
  1521. X        }
  1522. X    }
  1523. X  /*
  1524. X    Alert the user we're done.
  1525. X  */
  1526. X  XBell(display,0);
  1527. X  XBell(display,0);
  1528. X  XCloseDisplay(display);
  1529. X  return(image);
  1530. }
  1531. X
  1532. /*
  1533. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1534. %                                                                             %
  1535. %                                                                             %
  1536. %                                                                             %
  1537. %   X A n n o t a t e I m a g e                                               %
  1538. %                                                                             %
  1539. %                                                                             %
  1540. %                                                                             %
  1541. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1542. %
  1543. %  Function XAnnotateImage annotates the image with text.
  1544. %
  1545. %  The format of the XAnnotateImage routine is:
  1546. %
  1547. %    status=XAnnotateImage(display,window,annotate_info,background,image)
  1548. %
  1549. %  A description of each parameter follows:
  1550. %
  1551. %    o status: Function XAnnotateImage returns True if the image is
  1552. %      successfully annotated with text.  False is returned is there is a
  1553. %      memory shortage.
  1554. %
  1555. %    o display: Specifies a connection to an X server;  returned from
  1556. %      XOpenDisplay.
  1557. %
  1558. %    o window: Specifies a pointer to a XWindowInfo structure.
  1559. %
  1560. %    o text: Specifies the text to annotate the image.
  1561. %
  1562. %    o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
  1563. %
  1564. %    o background: Specifies whether the background color is included in
  1565. %      the annotation.  Must be either True or False;
  1566. %
  1567. %    o image: Specifies a pointer to a Image structure;  returned from
  1568. %      ReadImage.
  1569. %
  1570. %
  1571. */
  1572. unsigned int XAnnotateImage(display,window,annotate_info,background,image)
  1573. Display
  1574. X  *display;
  1575. X
  1576. XXWindowInfo
  1577. X  *window;
  1578. X
  1579. XXAnnotateInfo
  1580. X  *annotate_info;
  1581. X
  1582. unsigned int
  1583. X  background;
  1584. X
  1585. Image
  1586. X  *image;
  1587. {
  1588. X  GC
  1589. X    graphic_context;
  1590. X
  1591. X  Image
  1592. X    *annotate_image;
  1593. X
  1594. X  int
  1595. X    x,
  1596. X    y;
  1597. X
  1598. X  Pixmap
  1599. X    annotate_pixmap;
  1600. X
  1601. X  register RunlengthPacket
  1602. X    *p,
  1603. X    *q;
  1604. X
  1605. X  unsigned int
  1606. X    height,
  1607. X    width;
  1608. X
  1609. X  XGCValues
  1610. X    graphic_context_value;
  1611. X
  1612. X  XImage
  1613. X    *annotate_ximage;
  1614. X
  1615. X  XPixelInfo
  1616. X    *pixel_info;
  1617. X
  1618. X  /*
  1619. X    Initialize annotated image.
  1620. X  */
  1621. X  if (!UncompressImage(image))
  1622. X    return(False);
  1623. X  /*
  1624. X    Initialize annotated pixmap.
  1625. X  */
  1626. X  annotate_pixmap=XCreatePixmap(display,window->id,annotate_info->width,
  1627. X    annotate_info->height,window->depth);
  1628. X  if (annotate_pixmap == (Pixmap) NULL)
  1629. X    return(False);
  1630. X  /*
  1631. X    Initialize graphics info.
  1632. X  */
  1633. X  graphic_context_value.background=0;
  1634. X  graphic_context_value.foreground=(unsigned long) (~0);
  1635. X  graphic_context_value.font=annotate_info->font_info->fid;
  1636. X  graphic_context=XCreateGC(display,window->id,GCBackground | GCFont |
  1637. X    GCForeground,&graphic_context_value);
  1638. X  if (graphic_context == (GC) NULL)
  1639. X    return(False);
  1640. X  /*
  1641. X    Draw text to pixmap.
  1642. X  */
  1643. X  XDrawImageString(display,annotate_pixmap,graphic_context,0,
  1644. X    annotate_info->font_info->ascent,annotate_info->text,
  1645. X    strlen(annotate_info->text));
  1646. X  XFreeGC(display,graphic_context);
  1647. X  /*
  1648. X    Initialize annotated X image.
  1649. X  */
  1650. X  annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
  1651. X    annotate_info->height,AllPlanes,ZPixmap);
  1652. X  if (annotate_ximage == (XImage *) NULL)
  1653. X    return(False);
  1654. X  XFreePixmap(display,annotate_pixmap);
  1655. X  /*
  1656. X    Initialize annotated image.
  1657. X  */
  1658. X  annotate_image=AllocateImage("MIFF");
  1659. X  if (annotate_image == (Image *) NULL)
  1660. X    return(False);
  1661. X  annotate_image->columns=annotate_info->width;
  1662. X  annotate_image->rows=annotate_info->height;
  1663. X  annotate_image->packets=annotate_image->columns*annotate_image->rows;
  1664. X  annotate_image->pixels=(RunlengthPacket *)
  1665. X    malloc((unsigned int) image->packets*sizeof(RunlengthPacket));
  1666. X  if (annotate_image->pixels == (RunlengthPacket *) NULL)
  1667. X    {
  1668. X      DestroyImage(annotate_image);
  1669. X      return(False);
  1670. X    }
  1671. X  /*
  1672. X    Transfer annotated X image to image.
  1673. SHAR_EOF
  1674. true || echo 'restore of ImageMagick/X.c failed'
  1675. fi
  1676. echo 'End of ImageMagick part 8'
  1677. echo 'File ImageMagick/X.c is continued in part 9'
  1678. echo 9 > _shar_seq_.tmp
  1679. exit 0
  1680.  
  1681. exit 0 # Just in case...
  1682. -- 
  1683.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  1684. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  1685.  "It's intuitively obvious to the |
  1686.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  1687.