home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume5 / xldimage / patch3.1-2 < prev    next >
Encoding:
Internet Message Format  |  1993-04-28  |  83.6 KB

  1. From: kent@ssbell.IMD.Sterling.COM (Kent Landfield)
  2. Newsgroups: comp.sources.x
  3. Subject: v05i072: Xloadimage, Patch03, Part01/02
  4. Message-ID: <654@ssbell.IMD.Sterling.COM>
  5. Date: 5 Feb 90 05:23:03 GMT
  6. Approved: kent@ssbell.IMD.Sterling.COM (Kent Landfield)
  7.  
  8. Submitted-by: Jim Frost <jimf@saber.com>
  9. Posting-number: Volume 5, Issue 72
  10. Archive-name: xldimage/patch3.1-2
  11. Patch-To: xldimage: Volume 5, Issue 27-28,30
  12.  
  13. This is part 1 of a 2 part patch to xloadimage to bring it from
  14. patchlevel 02 to patchlevel 03.
  15.  
  16. There are many bug fixes and improvements in patchlevel 03, including
  17. a new loader for GIF images.  This version should work on most X
  18. servers, including those with depths of odd values such as 2 or 4 (eg
  19. 386/ix servers).  See the README file for more information.
  20.  
  21. Part 1, which follows, contains a patch file which should be applied
  22. to a virgin patchlevel 02 source directory.  Save it in the file
  23. "patch.03" and apply via "patch < patch.03".
  24.  
  25. Part 2 contains a shar file with the new GIF loader and associated
  26. header files.  Save it in the file "patch.03.shar" and unpack it via
  27. "sh patch.03.shar".
  28.  
  29. If you do not have xloadimage or do not have it updated to patchlevel
  30. 02, you can get the original source (distributed at patchlevel 01) and
  31. the 02 patch from the comp.sources.x archives, or you can get the full
  32. distribution from expo.lcs.mit.edu in /contrib/xloadimage.1.03.tar.Z
  33. via anonymous ftp.  The original source and 02 patch are also on expo
  34. but have been moved to /oldcontrib.
  35.  
  36. Feel free to email any questions or comments.
  37.  
  38. Enjoy,
  39.  
  40. jim frost
  41. saber software
  42. jimf@saber.com
  43.  
  44. -- patch.03: cut here --
  45. diff -c xloadimage.02/Imakefile xloadimage.03/Imakefile
  46. *** xloadimage.02/Imakefile    Sun Dec 31 16:03:09 1989
  47. --- xloadimage.03/Imakefile    Wed Dec 13 15:18:47 1989
  48. ***************
  49. *** 3,14 ****
  50.           DEPLIBS = $(DEPLIBS)
  51.   LOCAL_LIBRARIES = $(XLIB)
  52.              SRCS = bright.c clip.c compress.c dither.c faces.c fill.c \
  53. !           halftone.c imagetypes.c merge.c misc.c new.c \
  54.             options.c path.c pbm.c reduce.c root.c send.c \
  55.             sunraster.c value.c window.c xbitmap.c xloadimage.c \
  56.             xpixmap.c zio.c zoom.c
  57.              OBJS = bright.o clip.o compress.o dither.o faces.o fill.o \
  58. !           halftone.o imagetypes.o merge.o misc.o new.o \
  59.             options.o path.o pbm.o reduce.o root.o send.o \
  60.             sunraster.o value.o window.o xbitmap.o xloadimage.o \
  61.             xpixmap.o zio.o zoom.o
  62. --- 3,14 ----
  63.           DEPLIBS = $(DEPLIBS)
  64.   LOCAL_LIBRARIES = $(XLIB)
  65.              SRCS = bright.c clip.c compress.c dither.c faces.c fill.c \
  66. !           gif.c halftone.c imagetypes.c merge.c misc.c new.c \
  67.             options.c path.c pbm.c reduce.c root.c send.c \
  68.             sunraster.c value.c window.c xbitmap.c xloadimage.c \
  69.             xpixmap.c zio.c zoom.c
  70.              OBJS = bright.o clip.o compress.o dither.o faces.o fill.o \
  71. !           gif.o halftone.o imagetypes.o merge.o misc.o new.o \
  72.             options.o path.o pbm.o reduce.o root.o send.o \
  73.             sunraster.o value.o window.o xbitmap.o xloadimage.o \
  74.             xpixmap.o zio.o zoom.o
  75. diff -c xloadimage.02/Makefile.gcc xloadimage.03/Makefile.gcc
  76. *** xloadimage.02/Makefile.gcc    Sun Dec 31 16:03:09 1989
  77. --- xloadimage.03/Makefile.gcc    Wed Jan  3 15:30:20 1990
  78. ***************
  79. *** 1,6 ****
  80.   # Makefile for xloadimage using GNU C compiler
  81.   #
  82. ! # Copyright 1989 Jim Frost
  83.   #
  84.   # See file "copyright.h" for complete copyright information.
  85.   
  86. --- 1,6 ----
  87.   # Makefile for xloadimage using GNU C compiler
  88.   #
  89. ! # Copyright 1989, 1990 Jim Frost
  90.   #
  91.   # See file "copyright.h" for complete copyright information.
  92.   
  93. ***************
  94. *** 8,14 ****
  95.   CFLAGS= -O -fstrength-reduce -finline-functions -DSYSPATHFILE=\"/usr/lib/xloadimagerc\"
  96.   
  97.   LIBS= -lX11
  98. ! OBJS= bright.o clip.o compress.o dither.o faces.o fill.o \
  99.         halftone.o imagetypes.o merge.o misc.o new.o options.o path.o \
  100.         pbm.o reduce.o root.o send.o sunraster.o value.o window.o \
  101.         xbitmap.o xloadimage.o xpixmap.o zio.o zoom.o
  102. --- 8,14 ----
  103.   CFLAGS= -O -fstrength-reduce -finline-functions -DSYSPATHFILE=\"/usr/lib/xloadimagerc\"
  104.   
  105.   LIBS= -lX11
  106. ! OBJS= bright.o clip.o compress.o dither.o faces.o fill.o gif.o \
  107.         halftone.o imagetypes.o merge.o misc.o new.o options.o path.o \
  108.         pbm.o reduce.o root.o send.o sunraster.o value.o window.o \
  109.         xbitmap.o xloadimage.o xpixmap.o zio.o zoom.o
  110. diff -c xloadimage.02/Makefile.std xloadimage.03/Makefile.std
  111. *** xloadimage.02/Makefile.std    Sun Dec 31 16:03:10 1989
  112. --- xloadimage.03/Makefile.std    Wed Jan  3 15:30:10 1990
  113. ***************
  114. *** 1,6 ****
  115.   # Makefile for xloadimage using standard C compiler
  116.   #
  117. ! # Copyright 1989 Jim Frost
  118.   #
  119.   # See file "copyright.h" for complete copyright information.
  120.   
  121. --- 1,6 ----
  122.   # Makefile for xloadimage using standard C compiler
  123.   #
  124. ! # Copyright 1989, 1990 Jim Frost
  125.   #
  126.   # See file "copyright.h" for complete copyright information.
  127.   
  128. ***************
  129. *** 8,14 ****
  130.   CFLAGS= -O -DSYSPATHFILE=\"/usr/lib/xloadimagerc\"
  131.   
  132.   LIBS= -lX11
  133. ! OBJS= bright.o clip.o compress.o dither.o faces.o fill.o \
  134.         halftone.o imagetypes.o merge.o misc.o new.o options.o path.o \
  135.         pbm.o reduce.o root.o send.o sunraster.o value.o window.o \
  136.         xbitmap.o xloadimage.o xpixmap.o zio.o zoom.o
  137. --- 8,14 ----
  138.   CFLAGS= -O -DSYSPATHFILE=\"/usr/lib/xloadimagerc\"
  139.   
  140.   LIBS= -lX11
  141. ! OBJS= bright.o clip.o compress.o dither.o faces.o fill.o gif.o \
  142.         halftone.o imagetypes.o merge.o misc.o new.o options.o path.o \
  143.         pbm.o reduce.o root.o send.o sunraster.o value.o window.o \
  144.         xbitmap.o xloadimage.o xpixmap.o zio.o zoom.o
  145. diff -c xloadimage.02/README xloadimage.03/README
  146. *** xloadimage.02/README    Sun Dec 31 16:03:16 1989
  147. --- xloadimage.03/README    Wed Jan  3 12:41:10 1990
  148. ***************
  149. *** 3,41 ****
  150.   WHAT IS IT?
  151.   
  152.   This utility will view several types of images under X11, or load
  153. ! images onto the root window.  The current version supports X11 Bitmap,
  154. ! Portable Bitmap, Faces Project, and Sun Rasterfile images.  More are
  155. ! planned.
  156.   
  157.   A variety of options are available to modify images prior to viewing.
  158.   These options include clipping, dithering, depth reduction, zoom
  159. ! (either X or Y axis independently or both at once),
  160. ! brightening/darkening, and image merging.  When applicable, these
  161. ! options are done automatically (eg a color image to be displayed on a
  162. ! monochrome screen will be dithered automatically).
  163.   
  164. - IMPLEMENTATION
  165. - Most functions are not particularly fast, and some functions use
  166. - simple-minded algorithms deliberately over more advanced ones.  I
  167. - stressed portability over all and simplicity over performance.  I
  168. - believe the result is a usable, portable tool which should serve the
  169. - needs of most users.
  170. - The source code is basically in two parts: image manipulation routines
  171. - and everything else.  The image manipulation routines should be
  172. - completely independent of X, thus allowing people to use them under
  173. - other graphical systems.  No guarantees here, but I tried.
  174. - Performance-oriented people will notice that when loading a color
  175. - image, the colormap of the image is minimized (and all pixel values in
  176. - the image changed), then the colormap is redone (and all pixel values
  177. - in the image changed again) before sending to X.  This could be
  178. - reduced to only one remapping of the image but I wanted to keep the
  179. - image from X's grubby (greedy?) hands as long as possible, and the
  180. - image merging function really wants the image to have a minimized
  181. - colormap.
  182.   COMPILING
  183.   
  184.   There are three ways to compile xloadimage, depending on what
  185. --- 3,24 ----
  186.   WHAT IS IT?
  187.   
  188.   This utility will view several types of images under X11, or load
  189. ! images onto the root window.  The current version supports:
  190.   
  191. +     Faces Project
  192. +     GIF
  193. +     Portable Bitmap (PBM)
  194. +     Sun Rasterfile
  195. +     X11 Bitmap
  196. +     X Pixmap
  197.   A variety of options are available to modify images prior to viewing.
  198.   These options include clipping, dithering, depth reduction, zoom
  199. ! (either X or Y axis independently or both at once), brightening or
  200. ! darkening, and image merging.  When applicable, these options are done
  201. ! automatically (eg a color image to be displayed on a monochrome screen
  202. ! will be dithered automatically).
  203.   
  204.   COMPILING
  205.   
  206.   There are three ways to compile xloadimage, depending on what
  207. ***************
  208. *** 59,71 ****
  209.   After compiling and installing xloadimage, I recommend linking or
  210.   symlinking to the executable with the names "xview" and "xsetbg".  The
  211.   default behavior is slightly different when invoked with these
  212. ! commands (they're also easier to type).
  213.   
  214.   OWNERSHIP
  215.   
  216. ! I used the MIT X Consortium copyright with all of these functions,
  217. ! thereby allowing full freedom with the code so long as the copyright
  218. ! notices remain intact.  Free code can be good code.
  219.   
  220.   SUGGESTIONS AND BUG REPORTS
  221.   
  222. --- 42,80 ----
  223.   After compiling and installing xloadimage, I recommend linking or
  224.   symlinking to the executable with the names "xview" and "xsetbg".  The
  225.   default behavior is slightly different when invoked with these
  226. ! commands (they're also easier to type).  If you have a public image
  227. ! area you should consider setting the SYSPATHFILE option in the
  228. ! makefile and setting up a system-wide configuration file.  See the man
  229. ! page for information on the format of this file.
  230.   
  231. + IMPLEMENTATION
  232. + Most functions are not particularly fast, and some functions use
  233. + simple-minded algorithms deliberately over more advanced ones.  I
  234. + stressed portability over all and simplicity over performance.  I
  235. + believe the result is a usable, portable tool which should serve the
  236. + needs of most users.
  237. + The source code is basically in two parts: image manipulation routines
  238. + and everything else.  The image manipulation routines should be
  239. + completely independent of X, thus allowing people to use them under
  240. + other graphical systems.  No guarantees here, but I tried.
  241. + Performance-oriented people will notice that when loading a color
  242. + image, the colormap of the image is minimized (and all pixel values in
  243. + the image changed), then the colormap is redone (and all pixel values
  244. + in the image changed again) before sending to X.  This could be
  245. + reduced to only one remapping of the image but I wanted to keep the
  246. + image from X's grubby (greedy?) hands as long as possible, and the
  247. + image merging function really wants the image to have a minimized
  248. + colormap.
  249.   OWNERSHIP
  250.   
  251. ! I used a modified version of the MIT X Consortium copyright with all
  252. ! of these functions, thereby allowing full freedom with the code so
  253. ! long as the copyright notices remain intact.  Free code can be good
  254. ! code.  All contributions have similar notices.
  255.   
  256.   SUGGESTIONS AND BUG REPORTS
  257.   
  258. ***************
  259. *** 72,91 ****
  260.   Suggestions and bug reports should go to:
  261.   
  262.       Jim Frost
  263. !     madd@std.com
  264. !     ..uunet!world!madd
  265.   
  266.   Please include the version number and sample image data if you are
  267.   reporting a bug.
  268.   
  269.   Functions implementing new image types are welcomed; mail them to the
  270. ! same address and I'll do my best to distribute them.
  271.   
  272.   THANKS
  273.   
  274.   Special thanks to the crew at the Boston University Graphics Lab for
  275.   their assistance and sample images, and to bzs@std.com for his simple
  276. ! dithering algorithm (or what's left of it).
  277.   
  278.   HISTORY
  279.   
  280. --- 81,108 ----
  281.   Suggestions and bug reports should go to:
  282.   
  283.       Jim Frost
  284. !     jimf@saber.com
  285. !     ..harvard!saber!jimf
  286.   
  287.   Please include the version number and sample image data if you are
  288.   reporting a bug.
  289.   
  290.   Functions implementing new image types are welcomed; mail them to the
  291. ! same address and I'll do my best to distribute them.  Try do send them
  292. ! as public domain so I can keep the number of differing copyright
  293. ! messages to a minimum -- I'll use my standard message and leave the
  294. ! implementor's name and information in the file for credit.  I wouldn't
  295. ! copyright this stuff at all except that it's a requirement for X11
  296. ! distribution.
  297.   
  298.   THANKS
  299.   
  300.   Special thanks to the crew at the Boston University Graphics Lab for
  301.   their assistance and sample images, and to bzs@std.com for his simple
  302. ! dithering algorithm (or what's left of it).  Real special thanks to
  303. ! Kirk L. Johnson (tuna@athena.mit.edu) for a very nice GIF loader, and
  304. ! to Mark Snitily (zok!mark@apple.com) for 386/ix compatibility work and
  305. ! miscellaneous bug-tracking.
  306.   
  307.   HISTORY
  308.   
  309. ***************
  310. *** 103,105 ****
  311. --- 120,132 ----
  312.   the image up (with the old one moved to halftone.c), and a bug fix to
  313.   zoom.c to correct problems when zooming bitmaps.
  314.   
  315. + Patch 03 contained a new loader for GIF files.  The dither bits array
  316. + in dither.c was changed so it worked properly, and both dither.c and
  317. + halftone.c had minor bugs fixed.  Merge.c was modified to correct bugs
  318. + when merging RGB images.  Pbm.c was modified to handle raw format
  319. + images.  Root.c was modified to deny image loads which would change
  320. + the root window's colormap.  Send.c was modified to use shared colors
  321. + whenever possible and to handle color displays which have depths which
  322. + are not a multiple of 8.  Window.c was modified to avoid deleting the
  323. + default colormap, allowing proper operation on some servers prior to
  324. + X11R3 patchlevel 08.  There were many miscellaneous bug fixes.
  325. diff -c xloadimage.02/bright.c xloadimage.03/bright.c
  326. *** xloadimage.02/bright.c    Mon Nov  6 10:51:07 1989
  327. --- xloadimage.03/bright.c    Wed Dec  6 14:54:17 1989
  328. ***************
  329. *** 13,19 ****
  330.   
  331.   void brighten(image, percent, verbose)
  332.        Image        *image;
  333. !      int           percent;
  334.        unsigned int  verbose;
  335.   { int          a;
  336.     unsigned int newrgb;
  337. --- 13,19 ----
  338.   
  339.   void brighten(image, percent, verbose)
  340.        Image        *image;
  341. !      unsigned int  percent;
  342.        unsigned int  verbose;
  343.   { int          a;
  344.     unsigned int newrgb;
  345. diff -c xloadimage.02/compress.c xloadimage.03/compress.c
  346. *** xloadimage.02/compress.c    Mon Nov  6 10:51:09 1989
  347. --- xloadimage.03/compress.c    Wed Jan  3 15:31:07 1990
  348. ***************
  349. *** 4,11 ****
  350.    *
  351.    * jim frost 10.05.89
  352.    *
  353. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  354. !  * copyright information.
  355.    */
  356.   
  357.   #include "copyright.h"
  358. --- 4,11 ----
  359.    *
  360.    * jim frost 10.05.89
  361.    *
  362. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  363. !  * complete copyright information.
  364.    */
  365.   
  366.   #include "copyright.h"
  367. diff -c xloadimage.02/copyright.h xloadimage.03/copyright.h
  368. *** xloadimage.02/copyright.h    Mon Nov  6 10:51:10 1989
  369. --- xloadimage.03/copyright.h    Wed Jan  3 15:36:59 1990
  370. ***************
  371. *** 1,6 ****
  372.   #ifndef _JIM_COPYRIGHT_
  373.   /*
  374. !  * Copyright 1989 Jim Frost
  375.    *
  376.    * Permission to use, copy, modify, distribute, and sell this software
  377.    * and its documentation for any purpose is hereby granted without fee,
  378. --- 1,6 ----
  379.   #ifndef _JIM_COPYRIGHT_
  380.   /*
  381. !  * Copyright 1989, 1990 Jim Frost
  382.    *
  383.    * Permission to use, copy, modify, distribute, and sell this software
  384.    * and its documentation for any purpose is hereby granted without fee,
  385. diff -c xloadimage.02/dither.c xloadimage.03/dither.c
  386. *** xloadimage.02/dither.c    Sun Dec 31 16:03:11 1989
  387. --- xloadimage.03/dither.c    Wed Jan  3 15:31:22 1990
  388. ***************
  389. *** 7,13 ****
  390.    * jim frost 07.10.89
  391.    * Steve Losen 11.17.89
  392.    *
  393. !  * Copyright 1989 Jim Frost and Steve Losen.  See included file
  394.    * "copyright.h" for complete copyright information.
  395.    */
  396.   
  397. --- 7,13 ----
  398.    * jim frost 07.10.89
  399.    * Steve Losen 11.17.89
  400.    *
  401. !  * Copyright 1989, 1990 Jim Frost and Steve Losen.  See included file
  402.    * "copyright.h" for complete copyright information.
  403.    */
  404.   
  405. ***************
  406. *** 22,42 ****
  407.   
  408.   static byte DitherBits[GRAYS][4] = {
  409.     0xf, 0xf, 0xf, 0xf,
  410. !   0xf, 0xf, 0xf, 0x7,
  411. !   0xf, 0xf, 0xf, 0x3,
  412. !   0xf, 0xf, 0x7, 0x3,
  413. !   0xf, 0xf, 0x3, 0x3,
  414. !   0xf, 0xf, 0x3, 0x1,
  415. !   0xf, 0x7, 0x3, 0x1,
  416. !   0xf, 0x7, 0x1, 0x1,
  417. !   0x7, 0x7, 0x3, 0x0,
  418. !   0x7, 0x7, 0x1, 0x0,
  419. !   0x7, 0x3, 0x1, 0x0,
  420. !   0x7, 0x3, 0x0, 0x0,
  421. !   0x3, 0x3, 0x0, 0x0,
  422. !   0x3, 0x1, 0x0, 0x0,
  423. !   0x3, 0x0, 0x0, 0x0,
  424. !   0x1, 0x0, 0x0, 0x0,
  425.     0x0, 0x0, 0x0, 0x0
  426.   };
  427.   
  428. --- 22,42 ----
  429.   
  430.   static byte DitherBits[GRAYS][4] = {
  431.     0xf, 0xf, 0xf, 0xf,
  432. !   0xe, 0xf, 0xf, 0xf,
  433. !   0xe, 0xf, 0xb, 0xf,
  434. !   0xa, 0xf, 0xb, 0xf,
  435. !   0xa, 0xf, 0xa, 0xf,
  436. !   0xa, 0xd, 0xa, 0xf,
  437. !   0xa, 0xd, 0xa, 0x7,
  438. !   0xa, 0x5, 0xa, 0x7,
  439. !   0xa, 0x5, 0xa, 0x5,
  440. !   0x8, 0x5, 0xa, 0x5,
  441. !   0x8, 0x5, 0x2, 0x5,
  442. !   0x0, 0x5, 0x2, 0x5,
  443. !   0x0, 0x5, 0x0, 0x5,
  444. !   0x0, 0x4, 0x0, 0x5,
  445. !   0x0, 0x4, 0x0, 0x1,
  446. !   0x0, 0x0, 0x0, 0x1,
  447.     0x0, 0x0, 0x0, 0x0
  448.   };
  449.   
  450. ***************
  451. *** 47,59 ****
  452.        Image        *cimage;
  453.        unsigned int  verbose;
  454.   { Image         *image;
  455. !   unsigned char *sp, *dp, *dp2; /* data pointers */
  456. !   unsigned int   dindex;        /* index into dither array */
  457. !   unsigned int   spl;           /* source pixel length in bytes */
  458. !   unsigned int   dll;           /* destination line length in bytes */
  459. !   Pixel          color;         /* pixel color */
  460. !   unsigned int  *index;         /* index into dither array for a given pixel */
  461. !   unsigned int   a, x, y;       /* random counters */
  462.   
  463.     goodImage(cimage, "dither");
  464.     if (! RGBP(cimage))
  465. --- 47,59 ----
  466.        Image        *cimage;
  467.        unsigned int  verbose;
  468.   { Image         *image;
  469. !   unsigned char *sp, *dp; /* data pointers */
  470. !   unsigned int   dindex;  /* index into dither array */
  471. !   unsigned int   spl;     /* source pixel length in bytes */
  472. !   unsigned int   dll;     /* destination line length in bytes */
  473. !   Pixel          color;   /* pixel color */
  474. !   unsigned int  *index;   /* index into dither array for a given pixel */
  475. !   unsigned int   x, y;    /* random counters */
  476.   
  477.     goodImage(cimage, "dither");
  478.     if (! RGBP(cimage))
  479. ***************
  480. *** 84,94 ****
  481.   
  482.     if (cimage->depth <= 16) {
  483.       index= (unsigned int *)malloc(sizeof(unsigned int) * cimage->rgb.used);
  484. !     for (x= 0; x < cimage->rgb.used; x++)
  485.         *(index + x)=
  486.       ((unsigned long)(*(cimage->rgb.red + x)) +
  487.        *(cimage->rgb.green + x) +
  488.        *(cimage->rgb.blue + x)) / GRAYSTEP;
  489.     }
  490.     else
  491.       index= NULL;
  492. --- 84,97 ----
  493.   
  494.     if (cimage->depth <= 16) {
  495.       index= (unsigned int *)malloc(sizeof(unsigned int) * cimage->rgb.used);
  496. !     for (x= 0; x < cimage->rgb.used; x++) {
  497.         *(index + x)=
  498.       ((unsigned long)(*(cimage->rgb.red + x)) +
  499.        *(cimage->rgb.green + x) +
  500.        *(cimage->rgb.blue + x)) / GRAYSTEP;
  501. +       if (*(index + x) >= GRAYS)
  502. +     *(index + x)= GRAYS - 1;
  503. +     }
  504.     }
  505.     else
  506.       index= NULL;
  507. ***************
  508. *** 103,112 ****
  509.         color= memToVal(sp, spl);
  510.         if (index)
  511.       dindex= *(index + color);
  512. !       else
  513.       dindex= ((unsigned long)(*(cimage->rgb.red + color)) +
  514.            *(cimage->rgb.green + color) +
  515.            *(cimage->rgb.blue + color)) / GRAYSTEP;
  516.         if (DitherBits[dindex][y & 3] & (1 << (x & 3)))
  517.        dp[x / 8] |= 1 << (7 - (x & 7));
  518.         sp += spl;
  519. --- 106,118 ----
  520.         color= memToVal(sp, spl);
  521.         if (index)
  522.       dindex= *(index + color);
  523. !       else {
  524.       dindex= ((unsigned long)(*(cimage->rgb.red + color)) +
  525.            *(cimage->rgb.green + color) +
  526.            *(cimage->rgb.blue + color)) / GRAYSTEP;
  527. +     if (dindex >= GRAYS)
  528. +       dindex= GRAYS - 1;
  529. +       }
  530.         if (DitherBits[dindex][y & 3] & (1 << (x & 3)))
  531.        dp[x / 8] |= 1 << (7 - (x & 7));
  532.         sp += spl;
  533. Only in xloadimage.03: gif.c
  534. Only in xloadimage.03: gif.h
  535. diff -c xloadimage.02/halftone.c xloadimage.03/halftone.c
  536. *** xloadimage.02/halftone.c    Sun Dec 31 16:01:50 1989
  537. --- xloadimage.03/halftone.c    Wed Jan  3 15:36:35 1990
  538. ***************
  539. *** 6,13 ****
  540.    *
  541.    * jim frost 07.10.89
  542.    *
  543. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  544. !  * copyright information.
  545.    */
  546.   
  547.   #include "copyright.h"
  548. --- 6,13 ----
  549.    *
  550.    * jim frost 07.10.89
  551.    *
  552. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  553. !  * complete copyright information.
  554.    */
  555.   
  556.   #include "copyright.h"
  557. ***************
  558. *** 62,68 ****
  559.      */
  560.   
  561.     if (verbose) {
  562. !     printf("  Dithering image...");
  563.       fflush(stdout);
  564.     }
  565.     image= newBitImage(cimage->width * 4, cimage->height * 4);
  566. --- 62,68 ----
  567.      */
  568.   
  569.     if (verbose) {
  570. !     printf("  Halftoning image...");
  571.       fflush(stdout);
  572.     }
  573.     image= newBitImage(cimage->width * 4, cimage->height * 4);
  574. ***************
  575. *** 83,93 ****
  576.   
  577.     if (cimage->depth <= 16) {
  578.       index= (unsigned int *)malloc(sizeof(unsigned int) * cimage->rgb.used);
  579. !     for (x= 0; x < cimage->rgb.used; x++)
  580.         *(index + x)=
  581.       ((unsigned long)(*(cimage->rgb.red + x)) +
  582.        *(cimage->rgb.green + x) +
  583.        *(cimage->rgb.blue + x)) / GRAYSTEP;
  584.     }
  585.     else
  586.       index= NULL;
  587. --- 83,96 ----
  588.   
  589.     if (cimage->depth <= 16) {
  590.       index= (unsigned int *)malloc(sizeof(unsigned int) * cimage->rgb.used);
  591. !     for (x= 0; x < cimage->rgb.used; x++) {
  592.         *(index + x)=
  593.       ((unsigned long)(*(cimage->rgb.red + x)) +
  594.        *(cimage->rgb.green + x) +
  595.        *(cimage->rgb.blue + x)) / GRAYSTEP;
  596. +       if (*(index + x) >= GRAYS) /* rounding errors can do this */
  597. +     *(index + x)= GRAYS - 1;
  598. +     }
  599.     }
  600.     else
  601.       index= NULL;
  602. ***************
  603. *** 103,112 ****
  604.         color= memToVal(sp, spl);
  605.         if (index)
  606.       dindex= *(index + color);
  607. !       else
  608.       dindex= ((unsigned long)(*(cimage->rgb.red + color)) +
  609.            *(cimage->rgb.green + color) +
  610.            *(cimage->rgb.blue + color)) / GRAYSTEP;
  611.   
  612.         /* loop for the four Y bits in the dither pattern, putting all
  613.          * four X bits in at once.  if you think this would be hard to
  614. --- 106,118 ----
  615.         color= memToVal(sp, spl);
  616.         if (index)
  617.       dindex= *(index + color);
  618. !       else {
  619.       dindex= ((unsigned long)(*(cimage->rgb.red + color)) +
  620.            *(cimage->rgb.green + color) +
  621.            *(cimage->rgb.blue + color)) / GRAYSTEP;
  622. +     if (dindex >= GRAYS) /* rounding errors can do this */
  623. +       dindex= GRAYS - 1;
  624. +       }
  625.   
  626.         /* loop for the four Y bits in the dither pattern, putting all
  627.          * four X bits in at once.  if you think this would be hard to
  628. diff -c xloadimage.02/image.h xloadimage.03/image.h
  629. *** xloadimage.02/image.h    Sun Dec 31 16:03:11 1989
  630. --- xloadimage.03/image.h    Wed Dec  6 15:12:34 1989
  631. ***************
  632. *** 56,63 ****
  633. --- 56,69 ----
  634.   
  635.   Image *clip(); /* clip.c */
  636.   
  637. + void brighten(); /* bright.c */
  638. + void compress(); /* compress.c */
  639.   Image *dither(); /* dither.c */
  640.   
  641. + void fill(); /* fill.c */
  642.   void fold(); /* fold.c */
  643.   
  644.   Image *halftone(); /* halftone.c */
  645. ***************
  646. *** 66,72 ****
  647.   void   identifyImage();
  648.   void   goodImage();
  649.   
  650. ! Image *mergeImages(); /* merge.c */
  651.   
  652.   char  *dupString(); /* new.c */
  653.   Image *newBitImage();
  654. --- 72,78 ----
  655.   void   identifyImage();
  656.   void   goodImage();
  657.   
  658. ! void merge(); /* merge.c */
  659.   
  660.   char  *dupString(); /* new.c */
  661.   Image *newBitImage();
  662. ***************
  663. *** 82,90 ****
  664. --- 88,100 ----
  665.   void reduceRGBMap(); /* reduce.c */
  666.   void reduce();
  667.   
  668. + void imageOnRoot(); /* root.c */
  669.   unsigned long memToVal(); /* value.c */
  670.   void          valToMem();
  671.   unsigned long memToValLSB();
  672.   void          valToMemLSB();
  673. + void imageInWindow(); /* window.c */
  674.   
  675.   Image *zoom(); /* zoom.c */
  676. diff -c xloadimage.02/imagetypes.h xloadimage.03/imagetypes.h
  677. *** xloadimage.02/imagetypes.h    Sun Dec 31 16:03:12 1989
  678. --- xloadimage.03/imagetypes.h    Wed Dec 13 15:21:36 1989
  679. ***************
  680. *** 10,15 ****
  681. --- 10,16 ----
  682.   Image *facesLoad();
  683.   Image *pbmLoad();
  684.   Image *sunRasterLoad();
  685. + Image *gifLoad();
  686.   Image *xbitmapLoad();
  687.   Image *xpixmapLoad();
  688.   
  689. ***************
  690. *** 16,21 ****
  691. --- 17,23 ----
  692.   int facesIdent();
  693.   int pbmIdent();
  694.   int sunRasterIdent();
  695. + int gifIdent();
  696.   int xbitmapIdent();
  697.   int xpixmapIdent();
  698.   
  699. ***************
  700. *** 30,35 ****
  701. --- 32,38 ----
  702.     sunRasterIdent, sunRasterLoad, "Sun Rasterfile",
  703.     pbmIdent,       pbmLoad,       "Portable Bit Map (PBM)",
  704.     facesIdent,     facesLoad,     "Faces Project",
  705. +   gifIdent,       gifLoad,       "GIF Image",
  706.     xpixmapIdent,   xpixmapLoad,   "X Pixmap",
  707.     xbitmapIdent,   xbitmapLoad,   "X Bitmap",
  708.     NULL,           NULL,          NULL
  709. Only in xloadimage.03: kljcpyrght.h
  710. diff -c xloadimage.02/merge.c xloadimage.03/merge.c
  711. *** xloadimage.02/merge.c    Mon Nov  6 10:51:20 1989
  712. --- xloadimage.03/merge.c    Wed Jan  3 15:32:16 1990
  713. ***************
  714. *** 4,11 ****
  715.    *
  716.    * jim frost 09.27.89
  717.    *
  718. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  719. !  * copyright information.
  720.    */
  721.   
  722.   #include "copyright.h"
  723. --- 4,11 ----
  724.    *
  725.    * jim frost 09.27.89
  726.    *
  727. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  728. !  * complete copyright information.
  729.    */
  730.   
  731.   #include "copyright.h"
  732. ***************
  733. *** 20,38 ****
  734.     if (dest->rgb.used + src->rgb.used > dest->rgb.size) {
  735.       newRGBMapData(&newcolors, dest->rgb.used + src->rgb.used);
  736.       newcolors.used= newcolors.size;
  737. !     for (a= 0, b= 0; a < dest->rgb.used; a++, b++) {
  738. !       *(newcolors.red + b)= *(dest->rgb.red + a);
  739. !       *(newcolors.green + b)= *(dest->rgb.green + a);
  740. !       *(newcolors.blue + b)= *(dest->rgb.blue + a);
  741.       }
  742. !     for (b= 0; a < src->rgb.used; a++, b++) {
  743. !       *(newcolors.red + b)= *(src->rgb.red + a);
  744. !       *(newcolors.green + b)= *(src->rgb.green + a);
  745. !       *(newcolors.blue + b)= *(src->rgb.blue + a);
  746.       }
  747.   
  748.       reduceRGBMap(&newcolors, dest->rgb.size, verbose);
  749. -     dest->rgb.used= dest->rgb.size;
  750.       
  751.       for (a= 0; a < dest->rgb.used; a++) {             /* put new colors into */
  752.         *(dest->rgb.red + a)= *(newcolors.red + a);     /* old colormaps */
  753. --- 20,37 ----
  754.     if (dest->rgb.used + src->rgb.used > dest->rgb.size) {
  755.       newRGBMapData(&newcolors, dest->rgb.used + src->rgb.used);
  756.       newcolors.used= newcolors.size;
  757. !     for (a= 0; a < dest->rgb.used; a++) {
  758. !       *(newcolors.red + a)= *(dest->rgb.red + a);
  759. !       *(newcolors.green + a)= *(dest->rgb.green + a);
  760. !       *(newcolors.blue + a)= *(dest->rgb.blue + a);
  761.       }
  762. !     for (b= 0; b < src->rgb.used; a++, b++) {
  763. !       *(newcolors.red + a)= *(src->rgb.red + b);
  764. !       *(newcolors.green + a)= *(src->rgb.green + b);
  765. !       *(newcolors.blue + a)= *(src->rgb.blue + b);
  766.       }
  767.   
  768.       reduceRGBMap(&newcolors, dest->rgb.size, verbose);
  769.       
  770.       for (a= 0; a < dest->rgb.used; a++) {             /* put new colors into */
  771.         *(dest->rgb.red + a)= *(newcolors.red + a);     /* old colormaps */
  772. ***************
  773. *** 44,50 ****
  774.         *(src->rgb.green + a)= *(newcolors.green + a + dest->rgb.used);
  775.         *(src->rgb.blue + a)= *(newcolors.blue + a + dest->rgb.used);
  776.       }
  777. -     freeRGBMapData(&newcolors);
  778.     }
  779.     else
  780.       for (a= 0; a < src->rgb.used; a++, (dest->rgb.used)++) {
  781. --- 43,48 ----
  782. ***************
  783. *** 136,142 ****
  784.     unsigned int  x, y;
  785.     byte         *destline, *srcline;
  786.     byte         *destpixel, *srcpixel;
  787. !   byte          srcstartmask, srcmask;
  788.   
  789.     if (verbose) {
  790.       printf("  Merging bitmap image onto RGB image...");
  791. --- 134,140 ----
  792.     unsigned int  x, y;
  793.     byte         *destline, *srcline;
  794.     byte         *destpixel, *srcpixel;
  795. !   byte          srcmask;
  796.   
  797.     if (verbose) {
  798.       printf("  Merging bitmap image onto RGB image...");
  799. ***************
  800. *** 219,232 ****
  801.     for (x= 0; x < src->rgb.used; x++) {
  802.       for (y= 0; y < dest->rgb.used; y++)
  803.         if ((*(dest->rgb.red + y) == *(src->rgb.red + x)) &&
  804. !       (*(dest->rgb.red + y) == *(src->rgb.red + x)) &&
  805. !       (*(dest->rgb.red + y) == *(src->rgb.red + x))) {
  806.       *(index + x)= y;
  807.       break;
  808.         }
  809.       if (y == dest->rgb.used)
  810. !       printf("merge: warning: Can't map source pixel %d to destination\n",
  811. !          x);
  812.     }
  813.   
  814.     destlinelen= dest->width * dest->pixlen;
  815. --- 217,239 ----
  816.     for (x= 0; x < src->rgb.used; x++) {
  817.       for (y= 0; y < dest->rgb.used; y++)
  818.         if ((*(dest->rgb.red + y) == *(src->rgb.red + x)) &&
  819. !       (*(dest->rgb.green + y) == *(src->rgb.green + x)) &&
  820. !       (*(dest->rgb.blue + y) == *(src->rgb.blue + x))) {
  821.       *(index + x)= y;
  822.       break;
  823.         }
  824.       if (y == dest->rgb.used)
  825. !       if (y < dest->rgb.size) {
  826. !     *(dest->rgb.red + y)= *(src->rgb.red + x);
  827. !     *(dest->rgb.green + y)= *(src->rgb.green + x);
  828. !     *(dest->rgb.blue + y)= *(src->rgb.blue + x);
  829. !     *(index + x)= y;
  830. !     dest->rgb.used++;
  831. !       }
  832. !       else {
  833. !     printf("merge: warning: To few colors in destination colormap?!?\n");
  834. !     *(index + x)= 0;
  835. !       }
  836.     }
  837.   
  838.     destlinelen= dest->width * dest->pixlen;
  839. ***************
  840. *** 290,302 ****
  841.       cliph -= (dest->width - (aty + cliph));
  842.   
  843.     if (BITMAPP(dest) && (BITMAPP(src) || RGBP(src)))
  844. !     bitmapToBitmap(src, dest, atx, aty, clipw, cliph, verbose);
  845.     else {
  846.       mergeColors(dest, src, verbose);
  847.       if (RGBP(dest) && BITMAPP(src))
  848. !       bitmapToRGB(src, dest, atx, aty, clipw, cliph, verbose);
  849.       else if (RGBP(dest) && RGBP(src))
  850. !       RGBToRGB(src, dest, atx, aty, clipw, cliph, verbose);
  851.       else {
  852.         printf("merge: Can't merge these two types of images (sorry)\n");
  853.         exit(1);
  854. --- 297,312 ----
  855.       cliph -= (dest->width - (aty + cliph));
  856.   
  857.     if (BITMAPP(dest) && (BITMAPP(src) || RGBP(src)))
  858. !     bitmapToBitmap(src, dest, (unsigned int)atx, (unsigned int)aty,
  859. !            clipw, cliph, verbose);
  860.     else {
  861.       mergeColors(dest, src, verbose);
  862.       if (RGBP(dest) && BITMAPP(src))
  863. !       bitmapToRGB(src, dest, (unsigned int)atx, (unsigned int)aty,
  864. !           clipw, cliph, verbose);
  865.       else if (RGBP(dest) && RGBP(src))
  866. !       RGBToRGB(src, dest, (unsigned int)atx, (unsigned int)aty,
  867. !            clipw, cliph, verbose);
  868.       else {
  869.         printf("merge: Can't merge these two types of images (sorry)\n");
  870.         exit(1);
  871. diff -c xloadimage.02/misc.c xloadimage.03/misc.c
  872. *** xloadimage.02/misc.c    Sun Dec 31 16:03:12 1989
  873. --- xloadimage.03/misc.c    Wed Jan  3 15:32:37 1990
  874. ***************
  875. *** 4,11 ****
  876.    *
  877.    * jim frost 10.05.89
  878.    *
  879. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  880. !  * copyright information.
  881.    */
  882.   
  883.   #include "copyright.h"
  884. --- 4,11 ----
  885.    *
  886.    * jim frost 10.05.89
  887.    *
  888. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  889. !  * complete copyright information.
  890.    */
  891.   
  892.   #include "copyright.h"
  893. ***************
  894. *** 29,34 ****
  895. --- 29,35 ----
  896.     printf("  -quiet                - silence is golden\n");
  897.     printf("  -supported            - show supported image types\n");
  898.     printf("  -verbose              - whistle while you work\n");
  899. +   printf("  -version              - show version and patchlevel\n");
  900.     printf("  -view                 - view image in a window\n");
  901.     printf("Image_options:\n");
  902.     printf("  -at X,Y               - load image at location\n");
  903. ***************
  904. *** 69,75 ****
  905.     XColor        xcolor;
  906.     unsigned int  compressed= 0;
  907.   
  908. !   goodImage(image);
  909.   
  910.     /* clip the image if requested
  911.      */
  912. --- 70,76 ----
  913.     XColor        xcolor;
  914.     unsigned int  compressed= 0;
  915.   
  916. !   goodImage(image, "processImage");
  917.   
  918.     /* clip the image if requested
  919.      */
  920. ***************
  921. *** 149,154 ****
  922. --- 150,156 ----
  923.    * was issued.
  924.    */
  925.   
  926. + /* ARGSUSED */
  927.   int ioErrorHandler(disp)
  928.        Display *disp;
  929.   {
  930. diff -c xloadimage.02/new.c xloadimage.03/new.c
  931. *** xloadimage.02/new.c    Mon Nov  6 10:51:35 1989
  932. --- xloadimage.03/new.c    Wed Dec  6 14:56:08 1989
  933. ***************
  934. *** 49,55 ****
  935.     image= (Image *)lmalloc(sizeof(Image));
  936.     image->type= IBITMAP;
  937.     image->title= NULL;
  938. !   newRGBMapData(&(image->rgb), 2);
  939.     *(image->rgb.red)= *(image->rgb.green)= *(image->rgb.blue)= 65535;
  940.     *(image->rgb.red + 1)= *(image->rgb.green + 1)= *(image->rgb.blue + 1)= 0;
  941.     image->rgb.used= 2;
  942. --- 49,55 ----
  943.     image= (Image *)lmalloc(sizeof(Image));
  944.     image->type= IBITMAP;
  945.     image->title= NULL;
  946. !   newRGBMapData(&(image->rgb), (unsigned int)2);
  947.     *(image->rgb.red)= *(image->rgb.green)= *(image->rgb.blue)= 65535;
  948.     *(image->rgb.red + 1)= *(image->rgb.green + 1)= *(image->rgb.blue + 1)= 0;
  949.     image->rgb.used= 2;
  950. diff -c xloadimage.02/patchlevel xloadimage.03/patchlevel
  951. *** xloadimage.02/patchlevel    Sun Dec 31 16:03:17 1989
  952. --- xloadimage.03/patchlevel    Wed Jan  3 14:37:02 1990
  953. ***************
  954. *** 1 ****
  955. ! PATCHLEVEL 02
  956. --- 1,5 ----
  957. ! /* this defines the version and patchlevel of this version of xloadimage
  958. !  */
  959. ! #define VERSION    "1"
  960. ! #define PATCHLEVEL "03"
  961. diff -c xloadimage.02/path.c xloadimage.03/path.c
  962. *** xloadimage.02/path.c    Mon Nov  6 10:51:38 1989
  963. --- xloadimage.03/path.c    Wed Jan  3 15:33:01 1990
  964. ***************
  965. *** 4,11 ****
  966.    *
  967.    * jim frost 10.03.89
  968.    *
  969. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  970. !  * copyright information.
  971.    */
  972.   
  973.   #include "copyright.h"
  974. --- 4,11 ----
  975.    *
  976.    * jim frost 10.03.89
  977.    *
  978. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  979. !  * complete copyright information.
  980.    */
  981.   
  982.   #include "copyright.h"
  983. ***************
  984. *** 13,18 ****
  985. --- 13,19 ----
  986.   #include <sys/file.h>
  987.   #include <sys/types.h>
  988.   #include <sys/stat.h>
  989. + #include <unistd.h>
  990.   #include <pwd.h>
  991.   #include <errno.h>
  992.   
  993. ***************
  994. *** 62,73 ****
  995.   
  996.       if (!strncmp(tokenbuf, PathToken, strlen(PathToken))) {
  997.         secnum= PATHSECTION;
  998. !       if (sscanf(tokenbuf + strlen(PathToken), "%s", buf) == 0)
  999.       continue;
  1000.       }
  1001.       else if (!strncmp(tokenbuf, ExtToken, strlen(ExtToken))) {
  1002.         secnum= EXTSECTION;
  1003. !       if (sscanf(tokenbuf + strlen(ExtToken), "%s", buf) == 0)
  1004.       continue;
  1005.       }
  1006.       else
  1007. --- 63,74 ----
  1008.   
  1009.       if (!strncmp(tokenbuf, PathToken, strlen(PathToken))) {
  1010.         secnum= PATHSECTION;
  1011. !       if (sscanf(tokenbuf + strlen(PathToken), "%s", buf) != 1)
  1012.       continue;
  1013.       }
  1014.       else if (!strncmp(tokenbuf, ExtToken, strlen(ExtToken))) {
  1015.         secnum= EXTSECTION;
  1016. !       if (sscanf(tokenbuf + strlen(ExtToken), "%s", buf) != 1)
  1017.       continue;
  1018.       }
  1019.       else
  1020. ***************
  1021. *** 110,124 ****
  1022.       return;
  1023.     havepaths= 1;
  1024.   
  1025. - #ifdef SYSPATHFILE
  1026. -   readPathsAndExts(SYSPATHFILE);
  1027. - #endif
  1028.     if (pw= getpwuid(getuid())) {
  1029.       sprintf(buf, "%s/.xloadimagerc", pw->pw_dir);
  1030. !     readPathsAndExts(buf);
  1031.     }
  1032.     else
  1033.       printf("Can't find your password file entry?!?\n");
  1034.   }
  1035.   
  1036.   /* find an image with paths and extensions from defaults files.  returns
  1037. --- 111,128 ----
  1038.       return;
  1039.     havepaths= 1;
  1040.   
  1041.     if (pw= getpwuid(getuid())) {
  1042.       sprintf(buf, "%s/.xloadimagerc", pw->pw_dir);
  1043. !     if (! access(buf, R_OK)) {
  1044. !       readPathsAndExts(buf);
  1045. !       return; /* don't read system file if user has one */
  1046. !     }
  1047.     }
  1048.     else
  1049.       printf("Can't find your password file entry?!?\n");
  1050. + #ifdef SYSPATHFILE
  1051. +   readPathsAndExts(SYSPATHFILE);
  1052. + #endif
  1053.   }
  1054.   
  1055.   /* find an image with paths and extensions from defaults files.  returns
  1056. diff -c xloadimage.02/pbm.c xloadimage.03/pbm.c
  1057. *** xloadimage.02/pbm.c    Mon Nov  6 10:51:39 1989
  1058. --- xloadimage.03/pbm.c    Wed Jan  3 15:34:04 1990
  1059. ***************
  1060. *** 3,8 ****
  1061. --- 3,11 ----
  1062.    * portable bit map (pbm) format images
  1063.    *
  1064.    * jim frost 09.27.89
  1065. +  *
  1066. +  * patched by W. David Higgins (wdh@mkt.csd.harris.com) to support
  1067. +  * raw-format PBM files.
  1068.    */
  1069.   
  1070.   #include "xloadimage.h"
  1071. ***************
  1072. *** 19,24 ****
  1073. --- 22,28 ----
  1074.   #define NOTPBM     1 /* not a pbm file */
  1075.   #define PBMNORMAL  2 /* pbm normal type file */
  1076.   #define PBMCOMPACT 3 /* pbm compacty type file */
  1077. + #define PBMRAWBITS 4 /* pbm raw bits type file */
  1078.   
  1079.   static void initializeTable()
  1080.   { unsigned int a;
  1081. ***************
  1082. *** 83,89 ****
  1083.   static int isPBM(zf, name, width, height, verbose)
  1084.        ZFILE        *zf;
  1085.        char         *name;
  1086. !      int          *width, *height;
  1087.        unsigned int  verbose;
  1088.   { unsigned char buf[4];
  1089.   
  1090. --- 87,93 ----
  1091.   static int isPBM(zf, name, width, height, verbose)
  1092.        ZFILE        *zf;
  1093.        char         *name;
  1094. !      unsigned int *width, *height;
  1095.        unsigned int  verbose;
  1096.   { unsigned char buf[4];
  1097.   
  1098. ***************
  1099. *** 99,104 ****
  1100. --- 103,115 ----
  1101.         printf("%s is a %dx%d PBM image\n", name, *width, *height);
  1102.       return(PBMNORMAL);
  1103.     }
  1104. +   if (memToVal(buf, 2) == memToVal("P4", 2)) {
  1105. +     if (((*width= pbmReadInt(zf)) < 0) || ((*height= pbmReadInt(zf)) < 0))
  1106. +       return(NOTPBM);
  1107. +     if (verbose)
  1108. +       printf("%s is a %dx%d RawBits PBM image\n", name, *width, *height);
  1109. +     return(PBMRAWBITS);
  1110. +   }
  1111.     if (memToVal(buf, 2) == 0x2a17) {
  1112.       if (zread(zf, buf, 4) != 4)
  1113.         return(NOTPBM);
  1114. ***************
  1115. *** 113,125 ****
  1116.   
  1117.   int pbmIdent(fullname, name)
  1118.        char *fullname, *name;
  1119. ! { ZFILE *zf;
  1120. !   int    width, height, ret;
  1121.   
  1122.     if (! (zf= zopen(fullname, name)))
  1123.       return(0);
  1124.   
  1125. !   ret= isPBM(zf, name, &width, &height, 1);
  1126.     zclose(zf);
  1127.     return(ret != NOTPBM);
  1128.   }
  1129. --- 124,136 ----
  1130.   
  1131.   int pbmIdent(fullname, name)
  1132.        char *fullname, *name;
  1133. ! { ZFILE        *zf;
  1134. !   unsigned int  width, height, ret;
  1135.   
  1136.     if (! (zf= zopen(fullname, name)))
  1137.       return(0);
  1138.   
  1139. !   ret= isPBM(zf, name, &width, &height, (unsigned int)1);
  1140.     zclose(zf);
  1141.     return(ret != NOTPBM);
  1142.   }
  1143. ***************
  1144. *** 130,136 ****
  1145.   { ZFILE        *zf;
  1146.     Image        *image;
  1147.     unsigned int  x, y;
  1148. !   int           width, height;
  1149.     unsigned int  linelen;
  1150.     byte          srcmask, destmask;
  1151.     byte         *destptr, *destline;
  1152. --- 141,147 ----
  1153.   { ZFILE        *zf;
  1154.     Image        *image;
  1155.     unsigned int  x, y;
  1156. !   unsigned int  width, height;
  1157.     unsigned int  linelen;
  1158.     byte          srcmask, destmask;
  1159.     byte         *destptr, *destline;
  1160. ***************
  1161. *** 185,190 ****
  1162. --- 196,241 ----
  1163.       }
  1164.       break;
  1165.   
  1166. +   case PBMRAWBITS:
  1167. +     image= newBitImage(width, height);
  1168. +     destline= image->data;
  1169. +     linelen= (width + 7) / 8;
  1170. +     numbytes= linelen * height;
  1171. +     srcmask= 0;        /* force initial read */
  1172. +     numread= 0;
  1173. +     for (y= 0; y < height; y++) {
  1174. +       destptr= destline;
  1175. +       destmask= 0x80;
  1176. +       if (srcmask != 0x80) {
  1177. +         srcmask= 0x80;
  1178. +     if ((numread < numbytes) && ((src= zgetc(zf)) == EOF)) {
  1179. +        printf("%s: Short image\n", fullname);
  1180. +        zclose(zf);
  1181. +        exit(1);
  1182. +     }
  1183. +     numread++;
  1184. +       }
  1185. +       for (x= 0; x < width; x++) {
  1186. +     if (src & srcmask)
  1187. +       *destptr |= destmask;
  1188. +     if (! (destmask >>= 1)) {
  1189. +       destmask= 0x80;
  1190. +       destptr++;
  1191. +     }
  1192. +     if (! (srcmask >>= 1)) {
  1193. +       srcmask= 0x80;
  1194. +       if ((numread < numbytes) && ((src= zgetc(zf)) == EOF)) {
  1195. +         printf("%s: Short image\n", fullname);
  1196. +         zclose(zf);
  1197. +         exit(1);
  1198. +       }
  1199. +       numread++;
  1200. +     }
  1201. +       }
  1202. +       destline += linelen;
  1203. +     }
  1204. +     break;
  1205. +  
  1206.     case PBMCOMPACT:
  1207.       image= newBitImage(width, height);
  1208.       destline= image->data;
  1209. diff -c xloadimage.02/reduce.c xloadimage.03/reduce.c
  1210. *** xloadimage.02/reduce.c    Mon Nov  6 10:51:40 1989
  1211. --- xloadimage.03/reduce.c    Wed Jan  3 15:34:29 1990
  1212. ***************
  1213. *** 4,11 ****
  1214.    *
  1215.    * jim frost 07.06.89
  1216.    *
  1217. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1218. !  * copyright information.
  1219.    */
  1220.   
  1221.   #include "copyright.h"
  1222. --- 4,11 ----
  1223.    *
  1224.    * jim frost 07.06.89
  1225.    *
  1226. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1227. !  * complete copyright information.
  1228.    */
  1229.   
  1230.   #include "copyright.h"
  1231. ***************
  1232. *** 46,51 ****
  1233. --- 46,52 ----
  1234.     unsigned long qdist, bdist;
  1235.   
  1236.     bdist= 0xffffffff;
  1237. +   bcolor= 0;
  1238.     for (qcolor= color + 1; qcolor < rgb->used; qcolor++)
  1239.       if ((qdist= colorDistance(rgb, color, qcolor)) && (qdist < bdist)) {
  1240.         bdist= qdist;
  1241. ***************
  1242. *** 56,63 ****
  1243.   }
  1244.   
  1245.   void reduceRGBMap(rgb, n, verbose)
  1246. !      RGBMap *rgb;
  1247. !      int     verbose;
  1248.   { unsigned int   numcolors;
  1249.     Pixel          a, b;
  1250.     Pixel          lowextreme, highextreme; /* intensity extremes */
  1251. --- 57,65 ----
  1252.   }
  1253.   
  1254.   void reduceRGBMap(rgb, n, verbose)
  1255. !      RGBMap       *rgb;
  1256. !      unsigned int  n;
  1257. !      unsigned int  verbose;
  1258.   { unsigned int   numcolors;
  1259.     Pixel          a, b;
  1260.     Pixel          lowextreme, highextreme; /* intensity extremes */
  1261. ***************
  1262. *** 169,177 ****
  1263.       *(best + a)= bestColor(rgb, a, dists + a);
  1264.     }
  1265.   
  1266. !   lfree(best);
  1267. !   lfree(dists);
  1268. !   lfree(same);
  1269.   
  1270.     if (verbose)
  1271.       printf("done\n");
  1272. --- 171,179 ----
  1273.       *(best + a)= bestColor(rgb, a, dists + a);
  1274.     }
  1275.   
  1276. !   lfree((byte *)best);
  1277. !   lfree((byte *)dists);
  1278. !   lfree((byte *)same);
  1279.   
  1280.     if (verbose)
  1281.       printf("done\n");
  1282. ***************
  1283. *** 182,188 ****
  1284.        unsigned int  n, verbose;
  1285.   { char buf[BUFSIZ];
  1286.   
  1287. !   goodImage(image);
  1288.     if (! RGBP(image)) /* we're AT&T */
  1289.       return;
  1290.     compress(image, verbose);
  1291. --- 184,190 ----
  1292.        unsigned int  n, verbose;
  1293.   { char buf[BUFSIZ];
  1294.   
  1295. !   goodImage(image, "reduce");
  1296.     if (! RGBP(image)) /* we're AT&T */
  1297.       return;
  1298.     compress(image, verbose);
  1299. ***************
  1300. *** 189,194 ****
  1301.     reduceRGBMap(&(image->rgb), n, verbose);
  1302.     compress(image, verbose);
  1303.     sprintf(buf, "%s (%d colors)", image->title, image->rgb.used);
  1304. !   lfree(image->title);
  1305.     image->title= dupString(buf);
  1306.   }
  1307. --- 191,197 ----
  1308.     reduceRGBMap(&(image->rgb), n, verbose);
  1309.     compress(image, verbose);
  1310.     sprintf(buf, "%s (%d colors)", image->title, image->rgb.used);
  1311. !   if (image->title)
  1312. !     lfree((byte *)image->title);
  1313.     image->title= dupString(buf);
  1314.   }
  1315. diff -c xloadimage.02/root.c xloadimage.03/root.c
  1316. *** xloadimage.02/root.c    Mon Nov  6 10:51:42 1989
  1317. --- xloadimage.03/root.c    Wed Jan  3 15:34:57 1990
  1318. ***************
  1319. *** 4,11 ****
  1320.    *
  1321.    * jim frost 10.03.89
  1322.    *
  1323. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1324. !  * copyright information.
  1325.    */
  1326.   
  1327.   #include "copyright.h"
  1328. --- 4,11 ----
  1329.    *
  1330.    * jim frost 10.03.89
  1331.    *
  1332. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1333. !  * complete copyright information.
  1334.    */
  1335.   
  1336.   #include "copyright.h"
  1337. ***************
  1338. *** 23,34 ****
  1339.     if (! sendImageToX(disp, scrn, DefaultVisual(disp, scrn), image,
  1340.                &pixmap, &xcmap, verbose))
  1341.       exit(1);
  1342.     XSetWindowBackgroundPixmap(disp, RootWindow(disp, scrn), pixmap);
  1343. -   XSetWindowColormap(disp, RootWindow(disp, scrn), xcmap);
  1344. -   if (install)
  1345. -     XInstallColormap(disp, scrn, xcmap);
  1346.     XClearWindow(disp, RootWindow(disp, scrn));
  1347. -   XFreeColormap(disp, xcmap);
  1348.     XFreePixmap(disp, pixmap);
  1349.     XSetCloseDownMode(disp, RetainPermanent);
  1350.   }
  1351. --- 23,40 ----
  1352.     if (! sendImageToX(disp, scrn, DefaultVisual(disp, scrn), image,
  1353.                &pixmap, &xcmap, verbose))
  1354.       exit(1);
  1355. +   /* changing the root colormap is A Bad Thing, so deny it.
  1356. +    */
  1357. +   if (xcmap != DefaultColormap(disp, scrn)) {
  1358. +     printf("Loading image onto root would change default colormap (sorry)\n");
  1359. +     XFreePixmap(disp, pixmap);
  1360. +     exit(1);
  1361. +   }
  1362.     XSetWindowBackgroundPixmap(disp, RootWindow(disp, scrn), pixmap);
  1363.     XClearWindow(disp, RootWindow(disp, scrn));
  1364.     XFreePixmap(disp, pixmap);
  1365.     XSetCloseDownMode(disp, RetainPermanent);
  1366.   }
  1367. diff -c xloadimage.02/send.c xloadimage.03/send.c
  1368. *** xloadimage.02/send.c    Mon Nov  6 11:00:04 1989
  1369. --- xloadimage.03/send.c    Wed Jan  3 15:35:19 1990
  1370. ***************
  1371. *** 4,11 ****
  1372.    *
  1373.    * jim frost 10.02.89
  1374.    *
  1375. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1376. !  * copyright information.
  1377.    */
  1378.   
  1379.   #include "copyright.h"
  1380. --- 4,11 ----
  1381.    *
  1382.    * jim frost 10.02.89
  1383.    *
  1384. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1385. !  * complete copyright information.
  1386.    */
  1387.   
  1388.   #include "copyright.h"
  1389. ***************
  1390. *** 20,27 ****
  1391.        Colormap     *cmap;
  1392.        unsigned int  verbose;
  1393.   { Pixel        *index;
  1394. !   unsigned int  a, newmap, x, y;
  1395. !   byte         *pixptr;
  1396.     XColor        xcolor;
  1397.     XGCValues     gcv;
  1398.     GC            gc;
  1399. --- 20,28 ----
  1400.        Colormap     *cmap;
  1401.        unsigned int  verbose;
  1402.   { Pixel        *index;
  1403. !   unsigned int  a, b, newmap, x, y, linelen, ddepth;
  1404. !   unsigned long plane;
  1405. !   byte         *pixptr, *destline, *destptr, *bitplane, destmask;
  1406.     XColor        xcolor;
  1407.     XGCValues     gcv;
  1408.     GC            gc;
  1409. ***************
  1410. *** 49,103 ****
  1411.     if (visual == DefaultVisual(disp, scrn)) {
  1412.       *cmap= DefaultColormap(disp, scrn);
  1413.       newmap= 0;
  1414. -   }
  1415. -   else {
  1416. -     if ((visual->class == PseudoColor) || (visual->class == GrayScale))
  1417. -       *cmap= XCreateColormap(disp, scrn, AllocNone);
  1418. -     else
  1419. -       *cmap= XCreateColormap(disp, scrn, AllocAll);
  1420. -     newmap= 1;
  1421. -   }
  1422.   
  1423. !   /* here's where we have fun; we try to build a reasonable colormap from
  1424. !    * whatever X will give us.  ugh.  blech.  gag.  puke.  barf.
  1425. !    */
  1426.   
  1427. -   if ((visual->class == PseudoColor) || (visual->class == GrayScale)) {
  1428.       for (a= 0; a < image->rgb.used; a++) {
  1429. !       if (! XAllocColorCells(disp, *cmap, False, NULL, 0, index + a, 1))
  1430. !     if (newmap)
  1431. !       break;
  1432.       else {
  1433. !       *cmap= XCopyColormapAndFree(disp, *cmap);
  1434.         newmap= 1;
  1435. !       a--;
  1436.       }
  1437.       }
  1438.       if (a < image->rgb.used)     /* can't get enough colors, so reduce */
  1439.         reduce(image, a, verbose); /* the colormap to fit what we have */
  1440. !     for (a= 0; a < image->rgb.used; a++) {
  1441. !       xcolor.pixel= *(index + a);
  1442. !       xcolor.red= *(image->rgb.red + a);
  1443. !       xcolor.green= *(image->rgb.green + a);
  1444. !       xcolor.blue= *(image->rgb.blue + a);
  1445.         XStoreColor(disp, *cmap, &xcolor);
  1446.       }
  1447.     }
  1448. -   else if ((visual->class == StaticColor) || (visual->class == StaticGray)) {
  1449. -     for (a= 0; a < image->rgb.used; a++) {
  1450. -       xcolor.red= *(image->rgb.red + a);
  1451. -       xcolor.green= *(image->rgb.green + a);
  1452. -       xcolor.blue= *(image->rgb.blue + a);
  1453. -       if (! XAllocColor(disp, *cmap, &xcolor)) {
  1454. -     printf("sendImageToX: XAllocColor failed on StaticGrey visual\n");
  1455. -     return(0);
  1456. -       }
  1457. -       *(index + a)= xcolor.pixel;
  1458. -     }
  1459. -   }
  1460.   
  1461.     *pixmap= XCreatePixmap(disp, RootWindow(disp, scrn), image->width,
  1462. !              image->height, DefaultDepth(disp, scrn));
  1463.   
  1464.     /* blast the image across
  1465.      */
  1466. --- 50,113 ----
  1467.     if (visual == DefaultVisual(disp, scrn)) {
  1468.       *cmap= DefaultColormap(disp, scrn);
  1469.       newmap= 0;
  1470.   
  1471. !     /* allocate colors shareable (if we can)
  1472. !      */
  1473.   
  1474.       for (a= 0; a < image->rgb.used; a++) {
  1475. !       xcolor.red= *(image->rgb.red + a);
  1476. !       xcolor.green= *(image->rgb.green + a);
  1477. !       xcolor.blue= *(image->rgb.blue + a);
  1478. !       if (! XAllocColor(disp, *cmap, &xcolor))
  1479. !     if ((visual->class == StaticColor) || (visual->class == StaticGray)) {
  1480. !       printf("sendImageToX: XAllocColor failed on a static visual\n");
  1481. !       return(0);
  1482. !     }
  1483.       else {
  1484. !       /* we can't allocate the colors shareable so free all the colors
  1485. !        * we had allocated and create a private colormap
  1486. !        */
  1487. !       for (b= 0; b < a; b++)
  1488. !         XFreeColors(disp, *cmap, index + b, 1, 0);
  1489. !       *cmap= XCreateColormap(disp, RootWindow(disp, scrn), visual,
  1490. !                  AllocNone);
  1491.         newmap= 1;
  1492. !       break;
  1493.       }
  1494. +       *(index + a)= xcolor.pixel;
  1495.       }
  1496. +   }
  1497. +   else {
  1498. +     if ((visual->class == PseudoColor) || (visual->class == GrayScale)) {
  1499. +       *cmap= XCreateColormap(disp, RootWindow(disp, scrn), AllocNone);
  1500. +     }
  1501. +     else
  1502. +       *cmap= XCreateColormap(disp, RootWindow(disp, scrn), AllocAll);
  1503. +     newmap= 1;
  1504. +   }
  1505. +   if (newmap) {
  1506. +     for (a= 0; a < image->rgb.used; a++) /* count entries we got */
  1507. +       if (! XAllocColorCells(disp, *cmap, False, NULL, 0, index + a, 1))
  1508. +     break;
  1509.       if (a < image->rgb.used)     /* can't get enough colors, so reduce */
  1510.         reduce(image, a, verbose); /* the colormap to fit what we have */
  1511. !     for (b= 0; b < a; b++) {
  1512. !       xcolor.pixel= *(index + b);
  1513. !       xcolor.red= *(image->rgb.red + b);
  1514. !       xcolor.green= *(image->rgb.green + b);
  1515. !       xcolor.blue= *(image->rgb.blue + b);
  1516.         XStoreColor(disp, *cmap, &xcolor);
  1517.       }
  1518.     }
  1519.   
  1520. +   ddepth= DefaultDepth(disp, scrn);
  1521.     *pixmap= XCreatePixmap(disp, RootWindow(disp, scrn), image->width,
  1522. !              image->height, ddepth);
  1523.   
  1524.     /* blast the image across
  1525.      */
  1526. ***************
  1527. *** 120,130 ****
  1528.   
  1529.     case IRGB:
  1530.   
  1531. !     /* modify pixel values to fit the colormap
  1532.        */
  1533.   
  1534.       if (verbose) {
  1535. !       printf("  Modifying image to conform to X colormap...");
  1536.         fflush(stdout);
  1537.       }
  1538.       pixptr= image->data;
  1539. --- 130,140 ----
  1540.   
  1541.     case IRGB:
  1542.   
  1543. !     /* modify image data to match colormap and pack pixels if necessary
  1544.        */
  1545.   
  1546.       if (verbose) {
  1547. !       printf("  Building XImage...");
  1548.         fflush(stdout);
  1549.       }
  1550.       pixptr= image->data;
  1551. ***************
  1552. *** 134,145 ****
  1553.            pixptr, image->pixlen);
  1554.       pixptr += image->pixlen;
  1555.         }
  1556.       if (verbose)
  1557.         printf("done\n");
  1558.   
  1559.       gcv.function= GXcopy;
  1560.       gc= XCreateGC(disp, *pixmap, GCFunction, &gcv);
  1561. !     ximage= XCreateImage(disp, visual, image->depth, ZPixmap, 0, image->data,
  1562.                image->width, image->height, 8, 0);
  1563.       ximage->byte_order= MSBFirst; /* trust me, i know what i'm talking about */
  1564.   
  1565. --- 144,208 ----
  1566.            pixptr, image->pixlen);
  1567.       pixptr += image->pixlen;
  1568.         }
  1569.       if (verbose)
  1570.         printf("done\n");
  1571.   
  1572. +     /* if the destination depth is not a multiple of 8, then we send each
  1573. +      * plane as a bitmap because otherwise we would have to pack the pixel
  1574. +      * data and the XImage format is pretty vague about how that should
  1575. +      * be done.  this is not as fast as it would be if it were packed but
  1576. +      * it should be a lot more portable and only slightly slower.
  1577. +      */
  1578. +     if (ddepth % 8) {
  1579. +       gcv.function= GXcopy;
  1580. +       gcv.background= 0;
  1581. +       gc= XCreateGC(disp, *pixmap, GCFunction | GCBackground, &gcv);
  1582. +       linelen= (image->width / 8) + (image->width % 8 ? 1 : 0);
  1583. +       bitplane= lmalloc(image->height * linelen);
  1584. +       ximage= XCreateImage(disp, visual, 1, XYBitmap, 0, bitplane,
  1585. +                image->width, image->height, 8, 0);
  1586. +       ximage->bitmap_bit_order= MSBFirst;
  1587. +       ximage->byte_order= MSBFirst;
  1588. +       for (plane= 1 << (ddepth - 1); plane; plane >>= 1) {
  1589. +     pixptr= image->data;
  1590. +     destline= bitplane;
  1591. +     for (y= 0; y < image->height; y++) {
  1592. +       destmask= 0x80;
  1593. +       destptr= destline;
  1594. +       for (x= 0; x < image->width; x++) {
  1595. +         if (*pixptr & plane)
  1596. +           *destptr |= destmask;
  1597. +         else
  1598. +           *destptr &= ~destmask;
  1599. +         if (!(destmask >>= 1)) {
  1600. +           destmask= 0x80;
  1601. +           destptr++;
  1602. +         }
  1603. +         pixptr += image->pixlen;
  1604. +       }
  1605. +       destline += linelen;
  1606. +     }
  1607. +     XSetForeground(disp, gc, plane);
  1608. +     XSetPlaneMask(disp, gc, plane);
  1609. +     XPutImage(disp, *pixmap, gc, ximage, 0, 0, 0, 0,
  1610. +           image->width, image->height);
  1611. +       }
  1612. +       ximage->data= NULL;
  1613. +       XDestroyImage(ximage);
  1614. +       lfree(bitplane);
  1615. +       break;
  1616. +     }
  1617. +     /* send image across in one whack
  1618. +      */
  1619.       gcv.function= GXcopy;
  1620.       gc= XCreateGC(disp, *pixmap, GCFunction, &gcv);
  1621. !     ximage= XCreateImage(disp, visual, ddepth, ZPixmap, 0, image->data,
  1622.                image->width, image->height, 8, 0);
  1623.       ximage->byte_order= MSBFirst; /* trust me, i know what i'm talking about */
  1624.   
  1625. ***************
  1626. *** 154,159 ****
  1627.       printf("sendImageToX: bad image type\n");
  1628.       return(0);
  1629.     }
  1630. !   lfree(index);
  1631.     return(1);
  1632.   }
  1633. --- 217,222 ----
  1634.       printf("sendImageToX: bad image type\n");
  1635.       return(0);
  1636.     }
  1637. !   lfree((byte *)index);
  1638.     return(1);
  1639.   }
  1640. diff -c xloadimage.02/value.c xloadimage.03/value.c
  1641. *** xloadimage.02/value.c    Sun Dec 31 16:03:13 1989
  1642. --- xloadimage.03/value.c    Wed Dec  6 15:20:32 1989
  1643. ***************
  1644. *** 14,21 ****
  1645.   #include "image.h"
  1646.   
  1647.   unsigned long memToVal(p, len)
  1648. !      byte *p;
  1649. !      int   len;
  1650.   { unsigned int  a;
  1651.     unsigned long i;
  1652.   
  1653. --- 14,21 ----
  1654.   #include "image.h"
  1655.   
  1656.   unsigned long memToVal(p, len)
  1657. !      byte         *p;
  1658. !      unsigned int  len;
  1659.   { unsigned int  a;
  1660.     unsigned long i;
  1661.   
  1662. ***************
  1663. *** 55,62 ****
  1664.        byte          *p;
  1665.        unsigned long  val;
  1666.        unsigned int   len;
  1667. ! { int a;
  1668.     while (len--) {
  1669.       *(p++)= val & 0xff;
  1670.       val >>= 8;
  1671. --- 55,61 ----
  1672.        byte          *p;
  1673.        unsigned long  val;
  1674.        unsigned int   len;
  1675. ! {
  1676.     while (len--) {
  1677.       *(p++)= val & 0xff;
  1678.       val >>= 8;
  1679. diff -c xloadimage.02/window.c xloadimage.03/window.c
  1680. *** xloadimage.02/window.c    Mon Nov  6 11:00:11 1989
  1681. --- xloadimage.03/window.c    Wed Jan  3 15:35:42 1990
  1682. ***************
  1683. *** 4,11 ****
  1684.    *
  1685.    * jim frost 10.03.89
  1686.    *
  1687. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1688. !  * copyright information.
  1689.    */
  1690.   
  1691.   #include "copyright.h"
  1692. --- 4,11 ----
  1693.    *
  1694.    * jim frost 10.03.89
  1695.    *
  1696. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1697. !  * complete copyright information.
  1698.    */
  1699.   
  1700.   #include "copyright.h"
  1701. ***************
  1702. *** 20,30 ****
  1703.        Cursor       *cursor;
  1704.   { XSetWindowAttributes swa;
  1705.   
  1706. !   if ((ww == iw) && (wh == ih))
  1707.       swa.cursor= XCreateFontCursor(disp, XC_icon);
  1708. !   else if ((ww < iw) && (wh == ih))
  1709.       swa.cursor= XCreateFontCursor(disp, XC_sb_h_double_arrow);
  1710. !   else if ((ww == iw) && (wh < ih))
  1711.       swa.cursor= XCreateFontCursor(disp, XC_sb_v_double_arrow);
  1712.     else
  1713.       swa.cursor= XCreateFontCursor(disp, XC_fleur);
  1714. --- 20,30 ----
  1715.        Cursor       *cursor;
  1716.   { XSetWindowAttributes swa;
  1717.   
  1718. !   if ((ww >= iw) && (wh >= ih))
  1719.       swa.cursor= XCreateFontCursor(disp, XC_icon);
  1720. !   else if ((ww < iw) && (wh >= ih))
  1721.       swa.cursor= XCreateFontCursor(disp, XC_sb_h_double_arrow);
  1722. !   else if ((ww >= iw) && (wh < ih))
  1723.       swa.cursor= XCreateFontCursor(disp, XC_sb_v_double_arrow);
  1724.     else
  1725.       swa.cursor= XCreateFontCursor(disp, XC_fleur);
  1726. ***************
  1727. *** 117,123 ****
  1728.     XSetNormalHints(disp, window, &sh);
  1729.   
  1730.     gcv.function= GXcopy;
  1731. !   gc= XCreateGC(disp, window, GCFunction, &gcv);
  1732.     XMapWindow(disp, window);
  1733.     pixx= pixy= 0;
  1734.     lastx= lasty= -1;
  1735. --- 117,124 ----
  1736.     XSetNormalHints(disp, window, &sh);
  1737.   
  1738.     gcv.function= GXcopy;
  1739. !   gcv.foreground= 0;
  1740. !   gc= XCreateGC(disp, window, GCFunction | GCForeground, &gcv);
  1741.     XMapWindow(disp, window);
  1742.     pixx= pixy= 0;
  1743.     lastx= lasty= -1;
  1744. ***************
  1745. *** 133,147 ****
  1746.       lasty= event.button.y;
  1747.       break;
  1748.         }
  1749. - #ifdef NUKE_ME
  1750. -       XDestroyWindow(disp, window);
  1751. -       XFreeCursor(disp, swa.cursor);
  1752. -       XFreePixmap(disp, pixmap);
  1753. -       XFreeColormap(disp, xcmap);
  1754. -       return;
  1755. - #else
  1756.         break;
  1757. - #endif
  1758.   
  1759.       case KeyPress: {
  1760.         char buf[128];
  1761. --- 134,140 ----
  1762. ***************
  1763. *** 153,159 ****
  1764.           XDestroyWindow(disp, window);
  1765.           XFreeCursor(disp, swa.cursor);
  1766.           XFreePixmap(disp, pixmap);
  1767. !         XFreeColormap(disp, xcmap);
  1768.           return;
  1769.         }
  1770.       }
  1771. --- 146,153 ----
  1772.           XDestroyWindow(disp, window);
  1773.           XFreeCursor(disp, swa.cursor);
  1774.           XFreePixmap(disp, pixmap);
  1775. !     if (xcmap != DefaultColormap(disp, scrn))
  1776. !           XFreeColormap(disp, xcmap);
  1777.           return;
  1778.         }
  1779.       }
  1780. ***************
  1781. *** 160,165 ****
  1782. --- 154,161 ----
  1783.         break;
  1784.   
  1785.       case MotionNotify:
  1786. +       if ((image->width <= winwidth) && (image->height <= winheight))
  1787. +     break; /* we're AT&T */
  1788.         mousex= event.button.x;
  1789.         mousey= event.button.y;
  1790.         while (XCheckTypedEvent(disp, MotionNotify, &event) == True) {
  1791. ***************
  1792. *** 170,209 ****
  1793.         pixy += lasty - mousey;
  1794.         lastx= mousex;
  1795.         lasty= mousey;
  1796. !       if (pixx < 0)
  1797. !     pixx= 0;
  1798. !       if (pixy < 0)
  1799. !     pixy= 0;
  1800. !       if (pixx + winwidth > image->width)
  1801. !     pixx= image->width - winwidth;
  1802. !       if (pixy + winheight > image->height)
  1803. !     pixy= image->height - winheight;
  1804.         XCopyArea(disp, pixmap, window, gc,
  1805.           pixx, pixy, winwidth, winheight, 0, 0);
  1806.         break;
  1807.   
  1808.       case ConfigureNotify:
  1809.   
  1810. -       /* if we got resized too big, fix it.  it's a stupid window manager.
  1811. -        */
  1812. -       if ((event.configure.width > image->width) ||
  1813. -       (event.configure.height > image->height)) {
  1814. -     if (event.configure.width > image->width)
  1815. -       winwidth= image->width;
  1816. -     else
  1817. -       winwidth= event.configure.width;
  1818. -     if (event.configure.height > image->height)
  1819. -       winheight= image->height;
  1820. -     else
  1821. -       winheight= event.configure.height;
  1822. -     XResizeWindow(disp, window, winwidth, winheight);
  1823. -       }
  1824. -       else {
  1825. -     winwidth= event.configure.width;
  1826. -     winheight= event.configure.height;
  1827. -       }
  1828.         /* configure the cursor to indicate which directions we can drag
  1829.          */
  1830.   
  1831. --- 166,191 ----
  1832.         pixy += lasty - mousey;
  1833.         lastx= mousex;
  1834.         lasty= mousey;
  1835. !       if (image->width > winwidth) {
  1836. !     if (pixx < 0)
  1837. !       pixx= 0;
  1838. !     if (pixx + winwidth > image->width)
  1839. !       pixx= image->width - winwidth;
  1840. !       }
  1841. !       if (image->height > winheight) {
  1842. !     if (pixy < 0)
  1843. !       pixy= 0;
  1844. !     if (pixy + winheight > image->height)
  1845. !       pixy= image->height - winheight;
  1846. !       }
  1847.         XCopyArea(disp, pixmap, window, gc,
  1848.           pixx, pixy, winwidth, winheight, 0, 0);
  1849.         break;
  1850.   
  1851.       case ConfigureNotify:
  1852. +       winwidth= event.configure.width;
  1853. +       winheight= event.configure.height;
  1854.   
  1855.         /* configure the cursor to indicate which directions we can drag
  1856.          */
  1857.   
  1858. ***************
  1859. *** 211,216 ****
  1860. --- 193,202 ----
  1861.       pixx= image->width - winwidth;
  1862.         if (pixy + winheight > image->height)
  1863.       pixy= image->height - winheight;
  1864. +       if (winwidth > image->width)
  1865. +     pixx= 0;
  1866. +       if (winheight > image->height)
  1867. +     pixy= 0;
  1868.         setCursor(disp, window, image->width, image->height,
  1869.           winwidth, winheight, &(swa.cursor));
  1870.   
  1871. ***************
  1872. *** 224,230 ****
  1873.       case DestroyNotify:
  1874.         XFreeCursor(disp, swa.cursor);
  1875.         XFreePixmap(disp, pixmap);
  1876. !       XFreeColormap(disp, xcmap);
  1877.         return;
  1878.   
  1879.       case Expose:
  1880. --- 210,217 ----
  1881.       case DestroyNotify:
  1882.         XFreeCursor(disp, swa.cursor);
  1883.         XFreePixmap(disp, pixmap);
  1884. !       if (xcmap != DefaultColormap(disp, scrn))
  1885. !     XFreeColormap(disp, xcmap);
  1886.         return;
  1887.   
  1888.       case Expose:
  1889. diff -c xloadimage.02/xbitmap.c xloadimage.03/xbitmap.c
  1890. *** xloadimage.02/xbitmap.c    Mon Nov  6 11:00:08 1989
  1891. --- xloadimage.03/xbitmap.c    Wed Dec  6 15:07:38 1989
  1892. ***************
  1893. *** 241,247 ****
  1894.        char         *fullname, *name;
  1895.   { Image *image;
  1896.   
  1897. !   if (image= xbitmapLoad(fullname, name, 1)) {
  1898.       freeImage(image);
  1899.       return(1);
  1900.     }
  1901. --- 241,247 ----
  1902.        char         *fullname, *name;
  1903.   { Image *image;
  1904.   
  1905. !   if (image= xbitmapLoad(fullname, name, (unsigned int)1)) {
  1906.       freeImage(image);
  1907.       return(1);
  1908.     }
  1909. diff -c xloadimage.02/xloadimage.c xloadimage.03/xloadimage.c
  1910. *** xloadimage.02/xloadimage.c    Sun Dec 31 16:03:14 1989
  1911. --- xloadimage.03/xloadimage.c    Wed Jan  3 15:36:19 1990
  1912. ***************
  1913. *** 4,15 ****
  1914.    *
  1915.    * jim frost 09.27.89
  1916.    *
  1917. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1918. !  * copyright information.
  1919.    */
  1920.   
  1921.   #include "copyright.h"
  1922.   #include "xloadimage.h"
  1923.   
  1924.   /* options array and definitions
  1925.    */
  1926. --- 4,16 ----
  1927.    *
  1928.    * jim frost 09.27.89
  1929.    *
  1930. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1931. !  * complete copyright information.
  1932.    */
  1933.   
  1934.   #include "copyright.h"
  1935.   #include "xloadimage.h"
  1936. + #include "patchlevel"
  1937.   
  1938.   /* options array and definitions
  1939.    */
  1940. ***************
  1941. *** 27,32 ****
  1942. --- 28,34 ----
  1943.     "quiet",
  1944.     "supported",
  1945.     "verbose",
  1946. +   "version",
  1947.     "view",
  1948.   
  1949.     "at", /* image options */
  1950. ***************
  1951. *** 57,77 ****
  1952.   #define QUIET     9
  1953.   #define SUPPORTED 10
  1954.   #define VERBOSE   11
  1955. ! #define VIEW      12
  1956.   
  1957. ! #define AT         13
  1958. ! #define BACKGROUND 14
  1959. ! #define BRIGHT     15
  1960. ! #define CENTER     16
  1961. ! #define CLIP       17
  1962. ! #define COLORS     18
  1963. ! #define DITHER     19
  1964. ! #define FOREGROUND 20
  1965. ! #define HALFTONE   21
  1966. ! #define NAME       22
  1967. ! #define XZOOM      23
  1968. ! #define YZOOM      24
  1969. ! #define ZOOM       25
  1970.   
  1971.   /* if an image loader needs to have our display and screen, it will get
  1972.    * them from here.  this is done to keep most of the image routines
  1973. --- 59,80 ----
  1974.   #define QUIET     9
  1975.   #define SUPPORTED 10
  1976.   #define VERBOSE   11
  1977. ! #define VER_NUM   12
  1978. ! #define VIEW      13
  1979.   
  1980. ! #define AT         14
  1981. ! #define BACKGROUND 15
  1982. ! #define BRIGHT     16
  1983. ! #define CENTER     17
  1984. ! #define CLIP       18
  1985. ! #define COLORS     19
  1986. ! #define DITHER     20
  1987. ! #define FOREGROUND 21
  1988. ! #define HALFTONE   22
  1989. ! #define NAME       23
  1990. ! #define XZOOM      24
  1991. ! #define YZOOM      25
  1992. ! #define ZOOM       26
  1993.   
  1994.   /* if an image loader needs to have our display and screen, it will get
  1995.    * them from here.  this is done to keep most of the image routines
  1996. ***************
  1997. *** 129,134 ****
  1998. --- 132,149 ----
  1999.     winx= winy= winwidth= winheight= 0;
  2000.   
  2001.     imagecount= 0;
  2002. +   for (a= 0; a < MAXIMAGES; a++) {
  2003. +     images[a].name= NULL;
  2004. +     images[a].atx= images[a].aty= 0;
  2005. +     images[a].bright= 0;
  2006. +     images[a].center= 0;
  2007. +     images[a].clipx= images[a].clipy= 0;
  2008. +     images[a].clipw= images[a].cliph= 0;
  2009. +     images[a].dither= 0;
  2010. +     images[a].colors= 0;
  2011. +     images[a].fg= images[a].bg= NULL;
  2012. +     images[a].xzoom= images[a].yzoom= 0;
  2013. +   }
  2014.     for (a= 1; a < argc; a++) {
  2015.       switch (optionNumber(argv[a], Options)) {
  2016.       case OPT_BADOPT:
  2017. ***************
  2018. *** 199,206 ****
  2019. --- 214,227 ----
  2020.         verbose= 1;
  2021.         break;
  2022.   
  2023. +     case VER_NUM:
  2024. +       printf("Xloadimage version %s patchlevel %s by Jim Frost\n",
  2025. +          VERSION, PATCHLEVEL);
  2026. +       break;
  2027.       case VIEW:
  2028.         onroot= 0;
  2029. +       break;
  2030.   
  2031.       /* process options local to an image
  2032.        */
  2033. ***************
  2034. *** 330,336 ****
  2035.         *dispimage->rgb.green= xcolor.green;
  2036.         *dispimage->rgb.blue= xcolor.blue;
  2037.       }
  2038. !     fill(dispimage, 0, 0, winwidth, winheight, 0, verbose);
  2039.     }
  2040.   
  2041.     /* load in each named image
  2042. --- 351,357 ----
  2043.         *dispimage->rgb.green= xcolor.green;
  2044.         *dispimage->rgb.blue= xcolor.blue;
  2045.       }
  2046. !     fill(dispimage, 0, 0, winwidth, winheight, 0);
  2047.     }
  2048.   
  2049.     /* load in each named image
  2050. diff -c xloadimage.02/xloadimage.h xloadimage.03/xloadimage.h
  2051. *** xloadimage.02/xloadimage.h    Mon Nov  6 10:51:58 1989
  2052. --- xloadimage.03/xloadimage.h    Wed Dec  6 15:08:47 1989
  2053. ***************
  2054. *** 38,43 ****
  2055. --- 38,45 ----
  2056.   /* function declarations
  2057.    */
  2058.   
  2059. + void supportedImageTypes(); /* imagetypes.c */
  2060.   ZFILE *zopen(); /* io.c */
  2061.   int    zread();
  2062.   int    zgetc();
  2063. diff -c xloadimage.02/xloadimage.man xloadimage.03/xloadimage.man
  2064. *** xloadimage.02/xloadimage.man    Sun Dec 31 16:03:15 1989
  2065. --- xloadimage.03/xloadimage.man    Wed Jan  3 15:51:00 1990
  2066. ***************
  2067. *** 1,4 ****
  2068. ! .TH XLOADIMAGE 1 "7 October 1989"
  2069.   .SH NAME
  2070.   xloadimage, xsetbg, xview \- load images into an X11 window or onto
  2071.   the root window
  2072. --- 1,4 ----
  2073. ! .TH XLOADIMAGE 1 "13 December 1989"
  2074.   .SH NAME
  2075.   xloadimage, xsetbg, xview \- load images into an X11 window or onto
  2076.   the root window
  2077. ***************
  2078. *** 7,14 ****
  2079.   .SH DESCRIPTION
  2080.   \fIXloadimage\fR displays images in an X11 window or loads them onto
  2081.   the root window.  See the \fIIMAGE TYPES\fR section below for
  2082. ! supported image types.  Compressed images will automatically be
  2083. ! uncompressed.
  2084.   .PP
  2085.   If the destination display cannot support the number of colors in the
  2086.   image, the image will be dithered (monochrome destination) or have its
  2087. --- 7,13 ----
  2088.   .SH DESCRIPTION
  2089.   \fIXloadimage\fR displays images in an X11 window or loads them onto
  2090.   the root window.  See the \fIIMAGE TYPES\fR section below for
  2091. ! supported image types.
  2092.   .PP
  2093.   If the destination display cannot support the number of colors in the
  2094.   image, the image will be dithered (monochrome destination) or have its
  2095. ***************
  2096. *** 19,25 ****
  2097.   single image.  The \fI-at\fR and \fI-center\fR options control where
  2098.   subsequent images will be loaded onto the initial image.  Any
  2099.   combination of color image depths and/or monochrome images may be
  2100. ! loaded at one time.
  2101.   .PP
  2102.   A variety of image manipulations can be specified, including
  2103.   brightening, clipping, dithering, depth-reduction, and zooming.  Most
  2104. --- 18,26 ----
  2105.   single image.  The \fI-at\fR and \fI-center\fR options control where
  2106.   subsequent images will be loaded onto the initial image.  Any
  2107.   combination of color image depths and/or monochrome images may be
  2108. ! loaded at one time.  If merging two color images would overload the
  2109. ! number of available colormap entries, the number of colors shared
  2110. ! between the images will be automatically reduced to fit.
  2111.   .PP
  2112.   A variety of image manipulations can be specified, including
  2113.   brightening, clipping, dithering, depth-reduction, and zooming.  Most
  2114. ***************
  2115. *** 27,38 ****
  2116.   for above accuracy.
  2117.   .PP
  2118.   If you are viewing a large image in a window, the initial window will
  2119. ! be at most 90% of the size of the display.  You may move the image
  2120. ! around in the window by dragging with the first mouse button.  The
  2121. ! cursor will indicate which directions you may drag, if any.  You may
  2122. ! exit the window by typing 'q' or 'Q' when the keyboard focus is on the
  2123. ! window.
  2124.   .PP
  2125.   \fIXsetbg\fR is equivalent to \fIxloadimage -onroot -quiet\fR and
  2126.   \fIxview\fR is equivalent to \fIxloadimage -view -verbose\fR.
  2127.   .SH GLOBAL OPTIONS
  2128. --- 28,44 ----
  2129.   for above accuracy.
  2130.   .PP
  2131.   If you are viewing a large image in a window, the initial window will
  2132. ! be at most 90% of the size of the display (unless the window manager
  2133. ! does not correctly handle window size requests).  You may move the
  2134. ! image around in the window by dragging with the first mouse button.
  2135. ! The cursor will indicate which directions you may drag, if any.  You
  2136. ! may exit the window by typing 'q' or 'Q' when the keyboard focus is on
  2137. ! the window.
  2138.   .PP
  2139. + A wide variety of common image manipulations can be done by mixing and
  2140. + matching the available options.  See the section entitled \fIHINTS FOR
  2141. + GOOD IMAGE DISPLAYS\fR for some ideas.
  2142. + .PP
  2143.   \fIXsetbg\fR is equivalent to \fIxloadimage -onroot -quiet\fR and
  2144.   \fIxview\fR is equivalent to \fIxloadimage -view -verbose\fR.
  2145.   .SH GLOBAL OPTIONS
  2146. ***************
  2147. *** 43,52 ****
  2148.   This sets the background portion of the window which is not covered by
  2149.   any images to be \fIcolor\fR.
  2150.   .TP
  2151. - -colors \fIn\fR
  2152. - Specify the maximum number of colors to use in the image.  This is a
  2153. - way to forcibly reduce the depth of an image.
  2154. - .TP
  2155.   -display \fIdisplay_name\fR
  2156.   X11 display name to send the image(s) to.
  2157.   .TP
  2158. --- 49,54 ----
  2159. ***************
  2160. *** 74,80 ****
  2161.   -onroot
  2162.   Load image(s) onto the root window instead of viewing in a window.
  2163.   This is the opposite of \fI-view\fR.  \fIXSetbg\fR has this option set
  2164. ! by default.
  2165.   .TP
  2166.   -path
  2167.   Displays the image path and image suffixes which will be used when
  2168. --- 76,83 ----
  2169.   -onroot
  2170.   Load image(s) onto the root window instead of viewing in a window.
  2171.   This is the opposite of \fI-view\fR.  \fIXSetbg\fR has this option set
  2172. ! by default.  Loading with the -onroot option will fail if enough
  2173. ! sharable colors cannot be allocated from the default colormap.
  2174.   .TP
  2175.   -path
  2176.   Displays the image path and image suffixes which will be used when
  2177. ***************
  2178. *** 93,98 ****
  2179. --- 96,106 ----
  2180.   image it's playing with and any special processing that it has to do. 
  2181.   This is the default for \fIxview\fR and \fIxloadimage\fR. 
  2182.   .TP
  2183. + -version
  2184. + Print the version number and patchlevel of this version of
  2185. + \fIxloadimage\fR.  Versions prior to version 1, patchlevel 03 do not
  2186. + have this option and should be updated.
  2187. + .TP
  2188.   -view
  2189.   View image(s) in a window.  This is the opposite of \fI-onroot\fR and
  2190.   the default for \fIxsetbg\fR. 
  2191. ***************
  2192. *** 100,105 ****
  2193. --- 108,119 ----
  2194.   The following options may preceed each image.  These options are
  2195.   local to the image they preceed. 
  2196.   .TP
  2197. + -at \fIX\fR,\fIY\fR
  2198. + Indicates coordinates to load the image at on the first image.  If
  2199. + this is an option to the first image, and the \fI-onroot\fR option is
  2200. + specified, the image will be loaded at the given location on the
  2201. + display background. 
  2202. + .TP
  2203.   -background \fIcolor\fR
  2204.   Use \fIcolor\fR as the background color instead of the default
  2205.   (usually white but this depends on the image type) if you are
  2206. ***************
  2207. *** 115,125 ****
  2208.   the first image, and the \fI-onroot\fR option is specified, the image
  2209.   will be centered on the display background. 
  2210.   .TP
  2211. ! -at \fIX\fR,\fIY\fR
  2212. ! Indicates coordinates to load the image at on the first image.  If
  2213. ! this is an option to the first image, and the \fI-onroot\fR option is
  2214. ! specified, the image will be loaded at the given location on the
  2215. ! display background. 
  2216.   .TP
  2217.   -clip \fIX\fR,\fIY\fR,\fIW\fR,\fIH\fR
  2218.   Clip the image before loading it.  \fIX\fR and \fIY\fR define the
  2219. --- 129,137 ----
  2220.   the first image, and the \fI-onroot\fR option is specified, the image
  2221.   will be centered on the display background. 
  2222.   .TP
  2223. ! -colors \fIn\fR
  2224. ! Specify the maximum number of colors to use in the image.  This is a
  2225. ! way to forcibly reduce the depth of an image.
  2226.   .TP
  2227.   -clip \fIX\fR,\fIY\fR,\fIW\fR,\fIH\fR
  2228.   Clip the image before loading it.  \fIX\fR and \fIY\fR define the
  2229. ***************
  2230. *** 161,173 ****
  2231.   .TP
  2232.   -zoom \fIpercentage\fR
  2233.   Zoom both the X and Y axes by \fIpercentage\fR.  See \fI-xzoom\fR for
  2234. ! more information. 
  2235.   .SH EXAMPLES
  2236.   To load the rasterfile "my.image" onto the background and replicate
  2237.   it to fill the entire background:
  2238.   .sp
  2239.   .ti +5
  2240. ! xloadimage my.image
  2241.   .PP
  2242.   To load a monochrome image "my.image" onto the background, using red
  2243.   as the foreground color, replicate the image, and overlay
  2244. --- 173,187 ----
  2245.   .TP
  2246.   -zoom \fIpercentage\fR
  2247.   Zoom both the X and Y axes by \fIpercentage\fR.  See \fI-xzoom\fR for
  2248. ! more information.  Technically the percentage actually zoomed is the
  2249. ! square of the number supplied since the zoom is to both axes, but I
  2250. ! opted for consistency instead of accuracy.
  2251.   .SH EXAMPLES
  2252.   To load the rasterfile "my.image" onto the background and replicate
  2253.   it to fill the entire background:
  2254.   .sp
  2255.   .ti +5
  2256. ! xloadimage -onroot my.image
  2257.   .PP
  2258.   To load a monochrome image "my.image" onto the background, using red
  2259.   as the foreground color, replicate the image, and overlay
  2260. ***************
  2261. *** 181,202 ****
  2262.   .sp
  2263.   .ti +5
  2264.   xloadimage -center -clip 10,10,100,0 my.image
  2265.   .SH PATHS AND EXTENSIONS
  2266. ! The file ~/.xloadimagerc (and optionally a system-wide file which is
  2267. ! system-specific) defines the path and default extensions that
  2268. ! .I xloadimage
  2269. ! will use when looking for images.  The file can have two statements:
  2270. ! "path=" and "extension=" (the equals signs must follow the word with
  2271. ! no spaces between).  Everything following the "path=" keyword
  2272. ! will be prepended to the supplied image name if the supplied name does
  2273. ! not specify an existing file.  The paths will be searched in the order
  2274. ! they are specified.  Everything following the "extension=" keyword
  2275. ! will be appended to the supplied image name if the supplied name does
  2276. ! not specify and existing file.  As with paths, these extensions will
  2277. ! be searched in the order they are given.  Comments are any portion of
  2278. ! a line following a hash-mark (#).  The following is a sample
  2279. ! ~/.xloadimagerc file:
  2280.   .PP
  2281.   .nf
  2282.     # paths to look for images in
  2283.     path= /usr/local/images
  2284. --- 195,287 ----
  2285.   .sp
  2286.   .ti +5
  2287.   xloadimage -center -clip 10,10,100,0 my.image
  2288. + .PP
  2289. + To double the size of an image:
  2290. + .sp
  2291. + .ti +5
  2292. + xloadimage -zoom 200 my.image
  2293. + .PP
  2294. + To halve the size of an image:
  2295. + .sp
  2296. + .ti +5
  2297. + xloadimage -zoom 50 my.image
  2298. + .PP
  2299. + To brighten a dark image:
  2300. + .sp
  2301. + .ti +5
  2302. + xloadimage -brighten 150 my.image
  2303. + .PP
  2304. + To darken a bright image:
  2305. + .sp
  2306. + .ti +5
  2307. + xloadimage -brighten 50 my.image
  2308. + .SH HINTS FOR GOOD IMAGE DISPLAYS
  2309. + Since images are likely to come from a variety of sources, they may be
  2310. + in a variety of aspect ratios which may not be supported by your
  2311. + display.  The \fI-xzoom\fR and \fI-yzoom\fR options can be used to
  2312. + change the aspect ratio of an image before display.  If you use these
  2313. + options, it is recommended that you increase the size of one of the
  2314. + dimensions instead of shrinking the other, since shrinking looses
  2315. + detail.  For instance, many GIF images have an X:Y ratio of about 2:1.
  2316. + You can correct this for viewing on a 1:1 display with either
  2317. + \fI-xzoom 50\fR or \fI-yzoom 200\fR (reduce X axis to 50% of its size
  2318. + and expand Y axis to 200% of its size, respectively) but the latter
  2319. + should be used so no detail is lost in the conversion.
  2320. + .PP
  2321. + When merging images, the first image loaded is used to determine the
  2322. + depth of the merged image.  This becomes a problem if the first image
  2323. + is monochrome and other images are color, since the other images will
  2324. + be dithered to monochrome before merging.  You can get around this
  2325. + behavior by using the \fI-geometry\fR option to specify the size of
  2326. + the destination image -- this will force \fIxloadimage\fR to use the
  2327. + default depth of the display instead of 1.  The standard behavior
  2328. + might be modified in the future if it becomes a problem.
  2329. + .PP
  2330. + You can perform image processing on a small portion of an image by
  2331. + loading the image more than once and using the \fI-at\fR and
  2332. + \fI-clip\fR options.  Load the image, then load it again and clip,
  2333. + position, and process the second.  To brighten a 100x100 rectangular
  2334. + portion of an image located at (50,50), for instance, you could type:
  2335. + .sp
  2336. + .ti +5
  2337. + xloadimage my.image -at 50,50 -clip 50,50,100,100 -brighten 150 my.image
  2338. + .PP
  2339. + One common use of \fIxloadimage\fR is to load images onto the root
  2340. + window.  Unfortunately there is no agreed-upon method of freeing some
  2341. + root window resources, such as colormap entries, nor is there a way to
  2342. + modify the root window colormap without confusing most window
  2343. + managers.  For this reason, \fIxloadimage\fR will not allow the
  2344. + loading of images onto the root window if it cannot allocate shared
  2345. + colors from the root window's colormap.  I suggest the avoidance of
  2346. + multiple color image loads onto the root window, as these eat up root
  2347. + window shareable colormap entries.  If you wish to have a slideshow,
  2348. + display the images in a window.  A future implementation of
  2349. + \fIxloadimage\fR will have a \fI-fullscreen\fR (or maybe
  2350. + \fI-slideshow\fR) option, but this is as yet unavailable.
  2351. + .PP
  2352. + One common complaint is that \fIxloadimage\fR does not have a
  2353. + \fI-reverse\fR function for inverting monochrome images.  In fact,
  2354. + this function is a special-case of the foreground and background
  2355. + coloring options.  To invert an image with a black foreground and
  2356. + white background (which is standard), use \fI-foreground white
  2357. + -background black\fR.  This will work on both color and monochrome
  2358. + displays.
  2359.   .SH PATHS AND EXTENSIONS
  2360. ! The file ~/.xloadimagerc (and optionally a system-wide file) defines
  2361. ! the path and default extensions that \fIxloadimage\fR will use when
  2362. ! looking for images.  This file can have two statements: "path=" and
  2363. ! "extension=" (the equals signs must follow the word with no spaces
  2364. ! between).  Everything following the "path=" keyword will be prepended
  2365. ! to the supplied image name if the supplied name does not specify an
  2366. ! existing file.  The paths will be searched in the order they are
  2367. ! specified.  Everything following the "extension=" keyword will be
  2368. ! appended to the supplied image name if the supplied name does not
  2369. ! specify an existing file.  As with paths, these extensions will be
  2370. ! searched in the order they are given.  Comments are any portion of a
  2371. ! line following a hash-mark (#).
  2372.   .PP
  2373. + The following is a sample ~/.xloadimagerc file:
  2374. + .PP
  2375.   .nf
  2376.     # paths to look for images in
  2377.     path= /usr/local/images
  2378. ***************
  2379. *** 206,216 ****
  2380. --- 291,309 ----
  2381.     # default extensions for images; .Z is automatic; scanned in order
  2382.     extension= .csun .msun .sun .face .xbm .bm
  2383.   .fi
  2384. + .PP
  2385. + Versions of \fIxloadimage\fR prior to version 01, patchlevel 03 would
  2386. + load the system-wide file (if any), followed by the user's file.  This
  2387. + behavior made it difficult for the user to configure her environment
  2388. + if she didn't want the default.  Newer versions will ignore the
  2389. + system-wide file if a personal configuration file exists.
  2390.   .SH IMAGE TYPES
  2391.   .PP
  2392.   \fIXloadimage\fR currently supports the following image types:
  2393. + .sp
  2394.   .nf
  2395.     Faces Project images
  2396. +   GIF images
  2397.     Portable Bitmap (PBM) images
  2398.     Sun monochrome rasterfiles
  2399.     Sun color RGB rasterfiles
  2400. ***************
  2401. *** 219,247 ****
  2402.     X pixmap files
  2403.   .fi
  2404.   .PP
  2405. ! Both normal and compact PBM images are supported.  Both standard and
  2406. ! run-length encoded Sun rasterfiles are supported.
  2407.   .SH AUTHOR
  2408.   .nf
  2409.   Jim Frost
  2410. ! Software Tool & Die
  2411. ! madd@std.com
  2412.   .fi
  2413.   .SH BUGS
  2414. ! Zooming dithered images is UGLY.
  2415.   .PP
  2416. ! Loading images onto the root with PseudoColor or GrayScale displays
  2417. ! can cause colormap problems (and may interfere with window manager
  2418. ! operation) if there are not enough colors in the default colormap to
  2419. ! allocate all of the colors read/write.  This can happen on images
  2420. ! which have too many unique colors or if images are loaded onto the
  2421. ! root in succession.  Since there is currently no X standard for
  2422. ! changing the root colormap, this problem may or may not be corrected
  2423. ! in the future.
  2424.   .PP
  2425. ! Since \fIxloadimage\fR does not want a window larger than the image to
  2426. ! be displayed, it resizes the window to fit the image if the window
  2427. ! manager resizes the window to a size which is too large.  This could
  2428. ! cause a conflict if the window manager responds to the resize request
  2429. ! by resizing the window to the larger size.  This should be rare given
  2430. ! the state of current window managers and has never been observed.
  2431. --- 312,401 ----
  2432.     X pixmap files
  2433.   .fi
  2434.   .PP
  2435. ! Normal, compact, and raw PBM images are supported.  Both standard and
  2436. ! run-length encoded Sun rasterfiles are supported.  Any image whose
  2437. ! name ends in .Z is assumed to be a compressed image and will be
  2438. ! filtered through "uncompress".
  2439.   .SH AUTHOR
  2440.   .nf
  2441.   Jim Frost
  2442. ! Saber Software
  2443. ! jimf@saber.com
  2444.   .fi
  2445. + .PP
  2446. + Other contributing people include Barry Shein (bzs@std.com), Kirk L.
  2447. + Johnson (tuna@athena.mit.edu), Mark Snitilly (zok!mark@apple.com), and
  2448. + W. David Higgins (wdh@mkt.csd.harris.com).
  2449. + .SH FILES
  2450. + .nf
  2451. + .in +5
  2452. + xloadimage            - the image loader and viewer
  2453. + xsetbg                - pseudonym which quietly sets the background
  2454. + xview                 - pseudonym which views in a window
  2455. + /usr/lib/xloadimagerc - default system-wide configuration file
  2456. + ~/.xloadimagerc       - user's personal configuration file
  2457. + .in -5
  2458. + .fi
  2459. + .SH COPYRIGHT
  2460. + Copyright (c) 1989, 1990 Jim Frost and others.
  2461. + .PP
  2462. + \fIXloadimage\fR is copywritten material with a very loose copyright
  2463. + allowing unlimited modification and distribution if the copyright
  2464. + notices are left intact.  Various portions are copywritten by various
  2465. + people, but all use a modification of the MIT copyright notice.
  2466. + Please check the source for complete copyright information.  The
  2467. + intent is to keep the source free, not to stifle its distribution, so
  2468. + please write to me if you have any questions.
  2469.   .SH BUGS
  2470. ! Zooming dithered images, especially downwards, is UGLY.
  2471.   .PP
  2472. ! The dithering algorithm used by \fI-dither\fR could be better, and
  2473. ! both \fI-dither\fR and \fI-halftone\fR assume that a color's
  2474. ! brightness is the sum of its RGB values, which is not correct but has
  2475. ! the advantage of being simple and fast.
  2476.   .PP
  2477. ! Images can come in a variety of aspect ratios.  \fIXloadimage\fR cannot
  2478. ! detect what aspect ratio the particular image being loaded has, nor
  2479. ! the aspect ratio of the destination display, so images with differing
  2480. ! aspect ratios from the destination display will appear distorted.  See
  2481. ! \fIHINTS FOR GOOD IMAGE DISPLAYS\fR for more information.
  2482. ! .PP
  2483. ! The GIF format allows more than one image to be stored in a single GIF
  2484. ! file, but \fIxloadimage\fR will only display the first.
  2485. ! .PP
  2486. ! Only PseudoColor, GrayScale, StaticColor, and StaticGray visuals are
  2487. ! supported.  These are the most common visuals so this isn't usually a
  2488. ! problem.
  2489. ! .PP
  2490. ! You cannot load an image onto the root window if the default visual is
  2491. ! not supported by \fIxloadimage\fR.
  2492. ! .PP
  2493. ! If color images with substantially differing colormaps are loaded onto
  2494. ! the root window, eventually there will be no more sharable colors in
  2495. ! the default colormap and subsequent image loads onto the root window
  2496. ! will fail.  This is the result of limitations within X and a lack of
  2497. ! any protocol for handling root window and/or default colormap changes.
  2498. ! .PP
  2499. ! One of the pseudonyms for \fIxloadimage\fR, \fIxview\fR, is the same
  2500. ! name as Sun uses for their SunView-under-X package.  This will be
  2501. ! confusing if you're one of those poor souls who has to use Sun's
  2502. ! XView.
  2503. ! .PP
  2504. ! Some window managers do not correctly handle window size requests.  In
  2505. ! particular, versions of the twm window manager prior to X11R4 will use
  2506. ! the MaxSize hint instead of the PSize hint, causing images which
  2507. ! are larger than the screen to display in a window larger than the
  2508. ! screen, something which is normally avoided.  These versions of twm
  2509. ! also ignore the MaxSize argument's real function, to limit the maximum
  2510. ! size of the window, and allow the window to be resized larger than the
  2511. ! image.  If this happens, \fIxloadimage\fR merely places the image in
  2512. ! the upper-left corner of the window and uses the zero-value'ed pixel
  2513. ! for any space which is not covered by the image.  This behavior is
  2514. ! less-than-graceful but so are window managers which are cruel enough
  2515. ! to ignore such details.
  2516. ! .PP
  2517. ! The order in which operations are performed on an image is independent
  2518. ! of the order in which they were specified on the command line.
  2519. ! Wherever possible I tried to order operations in such a way as to look
  2520. ! the best possible (zooming before dithering, for instance) or to
  2521. ! increase speed (zooming downward before compressing, for instance).
  2522. diff -c xloadimage.02/xpixmap.c xloadimage.03/xpixmap.c
  2523. *** xloadimage.02/xpixmap.c    Sun Dec 31 16:01:52 1989
  2524. --- xloadimage.03/xpixmap.c    Wed Dec  6 15:17:31 1989
  2525. ***************
  2526. *** 39,44 ****
  2527. --- 39,45 ----
  2528.     char           buf[BUFSIZ];
  2529.     char           what[BUFSIZ];
  2530.     char          *p;
  2531. +   char          *imagetitle;
  2532.     unsigned int   value;
  2533.     unsigned int   format;  /* image format */
  2534.     unsigned int   w, h;    /* image dimensions */
  2535. ***************
  2536. *** 112,132 ****
  2537.   
  2538.     if (p= rindex(what, '_')) {     /* get the name in the image if there is */
  2539.       *p= '\0';                     /* one */
  2540. !     image->title= dupString(what);
  2541.     }
  2542.     else {
  2543.       p= what;
  2544. !     image->title= dupString(name);
  2545.     }
  2546.   
  2547.     if (verbose)
  2548.       printf("%s is a %dx%d X Pixmap image with %d colors titled '%s'\n",
  2549. !        name, w, h, ncolors, image->title);
  2550.   
  2551.     for (depth= 1, value= 2; value < ncolors; value <<= 1, depth++)
  2552.       ;
  2553.     image= newRGBImage(w, h, depth);
  2554.     image->rgb.used= ncolors;
  2555.   
  2556.     /* read the colors array and build the image colormap
  2557.      */
  2558. --- 113,134 ----
  2559.   
  2560.     if (p= rindex(what, '_')) {     /* get the name in the image if there is */
  2561.       *p= '\0';                     /* one */
  2562. !     imagetitle= dupString(what);
  2563.     }
  2564.     else {
  2565.       p= what;
  2566. !     imagetitle= dupString(name);
  2567.     }
  2568.   
  2569.     if (verbose)
  2570.       printf("%s is a %dx%d X Pixmap image with %d colors titled '%s'\n",
  2571. !        name, w, h, ncolors, imagetitle);
  2572.   
  2573.     for (depth= 1, value= 2; value < ncolors; value <<= 1, depth++)
  2574.       ;
  2575.     image= newRGBImage(w, h, depth);
  2576.     image->rgb.used= ncolors;
  2577. +   image->title= dupString(imagetitle);
  2578.   
  2579.     /* read the colors array and build the image colormap
  2580.      */
  2581. ***************
  2582. *** 227,235 ****
  2583.   }
  2584.   
  2585.   int xpixmapIdent(fullname, name)
  2586.   { Image *image;
  2587.   
  2588. !   if (image= xpixmapLoad(fullname, name, 1)) {
  2589.       freeImage(image);
  2590.       return(1);
  2591.     }
  2592. --- 229,238 ----
  2593.   }
  2594.   
  2595.   int xpixmapIdent(fullname, name)
  2596. +      char *fullname, *name;
  2597.   { Image *image;
  2598.   
  2599. !   if (image= xpixmapLoad(fullname, name, (unsigned int)1)) {
  2600.       freeImage(image);
  2601.       return(1);
  2602.     }
  2603. diff -c xloadimage.02/zio.c xloadimage.03/zio.c
  2604. *** xloadimage.02/zio.c    Mon Nov  6 10:52:00 1989
  2605. --- xloadimage.03/zio.c    Wed Dec  6 15:19:19 1989
  2606. ***************
  2607. *** 16,27 ****
  2608.   { ZFILE *zf;
  2609.     char   buf[BUFSIZ];
  2610.   
  2611. !   zf= (ZFILE *)lmalloc(sizeof(ZFILE));
  2612.     if ((strlen(name) > 2) && !strcmp(".Z", name + (strlen(name) - 2))) {
  2613.       zf->type= ZPIPE;
  2614.       sprintf(buf, "uncompress -c %s", name);
  2615.       if (! (zf->stream= popen(buf, "r"))) {
  2616. !       lfree(zf);
  2617.         return(NULL);
  2618.       }
  2619.       return(zf);
  2620. --- 16,27 ----
  2621.   { ZFILE *zf;
  2622.     char   buf[BUFSIZ];
  2623.   
  2624. !   zf= (ZFILE *)lmalloc((unsigned int)sizeof(ZFILE));
  2625.     if ((strlen(name) > 2) && !strcmp(".Z", name + (strlen(name) - 2))) {
  2626.       zf->type= ZPIPE;
  2627.       sprintf(buf, "uncompress -c %s", name);
  2628.       if (! (zf->stream= popen(buf, "r"))) {
  2629. !       lfree((byte *)zf);
  2630.         return(NULL);
  2631.       }
  2632.       return(zf);
  2633. ***************
  2634. *** 28,34 ****
  2635.     }
  2636.     zf->type= ZSTANDARD;
  2637.     if (! (zf->stream= fopen(name, "r"))) {
  2638. !     lfree(zf);
  2639.       return(NULL);
  2640.     }
  2641.     return(zf);
  2642. --- 28,34 ----
  2643.     }
  2644.     zf->type= ZSTANDARD;
  2645.     if (! (zf->stream= fopen(name, "r"))) {
  2646. !     lfree((byte *)zf);
  2647.       return(NULL);
  2648.     }
  2649.     return(zf);
  2650. ***************
  2651. *** 73,77 ****
  2652.       printf("zclose: bad ZFILE structure\n");
  2653.       exit(1);
  2654.     }
  2655. !   lfree(zf);
  2656.   }
  2657. --- 73,77 ----
  2658.       printf("zclose: bad ZFILE structure\n");
  2659.       exit(1);
  2660.     }
  2661. !   lfree((byte *)zf);
  2662.   }
  2663. diff -c xloadimage.02/zoom.c xloadimage.03/zoom.c
  2664. *** xloadimage.02/zoom.c    Sun Dec 31 16:03:16 1989
  2665. --- xloadimage.03/zoom.c    Wed Dec  6 15:21:20 1989
  2666. ***************
  2667. *** 162,169 ****
  2668.     }
  2669.   
  2670.     image->title= dupString(buf);
  2671. !   lfree(xindex);
  2672. !   lfree(yindex);
  2673.     if (verbose)
  2674.       printf("done\n");
  2675.     return(image);
  2676. --- 162,169 ----
  2677.     }
  2678.   
  2679.     image->title= dupString(buf);
  2680. !   lfree((byte *)xindex);
  2681. !   lfree((byte *)yindex);
  2682.     if (verbose)
  2683.       printf("done\n");
  2684.     return(image);
  2685.  
  2686.  
  2687.