🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.graphics.pixutils
Article #712

Six Patches for 'Xv'.

#712
From: Matthew Stier - Sun Visualizatio...
Date: Thu, 07 Nov 1991 15:26
1136 lines
37452 bytes
Below are serveral patches to 'Xv' patchlevel 3, as available from 
export.lcs.mit.edu:/contrib/xv.pl3.tar.Z.  They are to correct short 
comings that I have noticed.  They are as follows:

3a)  This is a rework of the patch file 'xv.patch3a' posted to 
     export.lcs.mit.edu:/contrib/xv.patch3a. I did not create this 
     patch, but have included it here for completeness. (I did create 
     the appropariate 'diff' file for 'patch' to work with.)

3b)  This patch fixes a simple bug in the Imakefile. Apparently some 
     makes do not like a macro as both lefthand and righthand value 
     in the same macro statement. (SunOS 4.1.1)

3c)  'Xv' is case sensitive to boolean resources.  I.E. "True" != "true".
     This patch fixes case sensitivity to boolean resources.

3d)  It is reasonably well known that 'Xv' trips up an 'XFreeColors' bug
     on some Xservers.  This patch removes the "-bfc" work around, and
     adds a error handling checks to eliminate the need for special
     flags or resources.

3e)  This patch loosens the "magic number" checks that 'Xv' does on gif files.
     Most GIF files that report to be "GIF89A" files, do not use any of the
     GIF89A features, and are perfectly readable by 'Xv'. (Once it can get
     past the "magic number" checks).

3f)  This is a rework of a patch provided on 'think.com'.  It permits 
     'Xv' to read "jpeg" files. (Without requiring pre-processing)
     The patch available on 'think.com' works with the an August release
     of the "Independent JPEG Group". This patch works with, and requires
     the 7-Oct-91 release of jpegsrc.v1.tar.Z available on 
     uunet.uu.net:/graphics/jpeg.

--
Matthew Lee Stier                          |
Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
Email: matthew.stier@East.Sun.COM          |
Phone: (919) 469-8300 fax: (919) 460-8355  | 


#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 11/07/1991 14:32 UTC by matthew@superdave
# Source directory /auto/home/matthew/src/X11/Xv
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   3187 -rw-r--r-- xv.patch.3a
#   1541 -rw-r--r-- xv.patch.3b.sco
#   3235 -rw-r--r-- xv.patch.3c.lc
#   5968 -rw-r--r-- xv.patch.3d.bfc
#   2495 -rw-r--r-- xv.patch.3e.gif
#  13605 -rw-r--r-- xv.patch.3f.jpeg
#
# ============= xv.patch.3a ==============
if test -f 'xv.patch.3a' -a X"$1" != X"-c"; then
	echo 'x - skipping xv.patch.3a (File already exists)'
else
echo 'x - extracting xv.patch.3a (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xv.patch.3a' &&
Here is a patch that was placed on export.lcs.mit.edu.  
It is included here for completeness.
--
Matthew Lee Stier                          |
Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
Email: matthew.stier@East.Sun.COM          |
Phone: (919) 469-8300 fax: (919) 460-8355  | 
X
*** /dev/null	Wed Nov  6 20:42:02 1991
--- README.3A	Tue Nov  5 04:39:22 1991
***************
*** 0 ****
--- 1,56 ----
+ There are a pair of common bugs in XV patchlevel 3 that the following fixes.
+ 
+ First, if you are running Sun's OpenWindows Version 2.0 on a color/grayscale
+ display, you *must* run XV with the '-bfc' option.  Otherwise the program will
+ eventually die with a Fatal X Error on a XFreeColors() call.  This is a bug in
+ the OW V2.0 X server, and has been fixed in V3.0.
+ 
+ IBM's AIX 3.1 X server has the same problem.
+ 
+ 
+ Secondly, if you are using olwm (the OpenLook Window Manager) or dxwm (Dec's
+ Window Manager), and possibly others, you should make the following marked
+ changes to the code and recompile.  This fixes a bug that would occur whenever
+ you changed the size of the window (via cropping, expanding, etc.)
+ 
+ 
+ In xv.c, in the function CheckForConfig():
+ 
+   /* returns true if there's a config event in which mainW changes size
+      in the event queue */
+ 
+ > XSync(theDisp, False);
+   foo = 0;
+   XCheckIfEvent(theDisp, &ev, IsConfig, &foo);
+   return foo;
+ 
+ 
+ In xv.c, in the function SetWindowPos():
+ 
+ >#ifdef TWMKLUDGE
+      /* all this bogus stuff is a work-around for weirdness in
+         twm where resize was giving 23 extra lines... */
+     XSync(theDisp,False);
+     XGetWindowAttributes(theDisp, mainW, &pxwa);
+     if (pxwa.height != xwa->height) {
+       XEvent xev;
+       /* eat configure event (and any Exposes) if there is one */
+       if (XCheckTypedWindowEvent(theDisp, mainW, ConfigureNotify, &xev)) {
+         while (XCheckTypedWindowEvent(theDisp, mainW, Expose, &xev));
+       }
+ 
+       XResizeWindow(theDisp, mainW, xwa->width,
+                     xwa->height - (pxwa.height - xwa->height));
+     }
+ >#endif /* TWMKLUDGE */
+ 
+ 
+ 
+ 
+ Once these changes have been made you should find XV patchlevel 3 to be fairly
+ bulletproof.  Enjoy!
+ 
+ 
+ John Bradley  -  University of Pennsylvania  -  bradley@cis.upenn.edu
+ 
+ June 18, 1991
*** orig/xv.c	Tue Nov  5 05:40:57 1991
--- xv.c	Tue Nov  5 21:47:46 1991
***************
*** 1791,1796 ****
--- 1791,1797 ----
X     * twm where resize was giving 23 extra lines...
X     * should do no harm if this bug is not present.
X     */
+ #ifdef TWMKLUDGE
X    XSync(theDisp,False);
X    XGetWindowAttributes(theDisp, mainW, &pxwa);
X    if (pxwa.height != xwa->height) {
***************
*** 1803,1808 ****
--- 1804,1810 ----
X      XResizeWindow(theDisp, mainW, xwa->width, 
X  		  xwa->height - (pxwa.height - xwa->height));
X    }
+ #endif /* TWMKLUDGE */
X  
X  }
X  
***************
*** 2039,2044 ****
--- 2041,2047 ----
X    /* returns true if there's a config event in which mainW changes size
X       in the event queue */
X  
+   XSync(theDisp, False);
X    foo = 0;
X    XCheckIfEvent(theDisp, &ev, IsConfig, &foo);
X    return foo;
SHAR_EOF
chmod 0644 xv.patch.3a ||
echo 'restore of xv.patch.3a failed'
Wc_c="`wc -c < 'xv.patch.3a'`"
test 3187 -eq "$Wc_c" ||
	echo 'xv.patch.3a: original size 3187, current size' "$Wc_c"
fi
# ============= xv.patch.3b.sco ==============
if test -f 'xv.patch.3b.sco' -a X"$1" != X"-c"; then
	echo 'x - skipping xv.patch.3b.sco (File already exists)'
else
echo 'x - extracting xv.patch.3b.sco (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xv.patch.3b.sco' &&
A simple patch to the makefile to correct a problem with some 'make' programs
(The make program provided with SunOS 4.1.1 did not like the same macro 
X as both lefthand and righthand value.)
--
Matthew Lee Stier                          |
Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
Email: matthew.stier@East.Sun.COM          |
Phone: (919) 469-8300 fax: (919) 460-8355  | 
X
*** /dev/null	Wed Nov  6 21:42:01 1991
--- README.SCO	Wed Nov  6 21:58:18 1991
***************
*** 0 ****
--- 1,8 ----
+ A simple patch to the makefile to correct a problem with some 'make' programs
+ (The make program provided with SunOS 4.1.1 did not like the same macro 
+  as both lefthand and righthand value.)
+ --
+ Matthew Lee Stier                          |
+ Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
+ Email: matthew.stier@East.Sun.COM          |
+ Phone: (919) 469-8300 fax: (919) 460-8355  | 
*** orig/Imakefile	Tue Nov  5 05:40:57 1991
--- Imakefile	Tue Nov  5 22:32:17 1991
***************
*** 77,79 ****
X  #if defined(SCOArchitecture)
! DEFINES= -DPOSIX -DNOITIMER
X  SYS_LIBRARIES=        $(XLIB) -lm -lc -lx
--- 77,79 ----
X  #if defined(SCOArchitecture)
! SCO_DEFINES= -DPOSIX -DNOITIMER
X  SYS_LIBRARIES=        $(XLIB) -lm -lc -lx
***************
*** 83,85 ****
X  
! DEFINES= $(DEFINES) $(UNIX) $(NEED_DIRENT) $(BROKECOLS) \
X  	 $(VPRINTF) $(TIMERS) $(ATT) $(USEMEM)
--- 83,85 ----
X  
! DEFINES= $(SCO_DEFINES) $(UNIX) $(NEED_DIRENT) $(BROKECOLS) \
X  	 $(VPRINTF) $(TIMERS) $(ATT) $(USEMEM)
SHAR_EOF
chmod 0644 xv.patch.3b.sco ||
echo 'restore of xv.patch.3b.sco failed'
Wc_c="`wc -c < 'xv.patch.3b.sco'`"
test 1541 -eq "$Wc_c" ||
	echo 'xv.patch.3b.sco: original size 1541, current size' "$Wc_c"
fi
# ============= xv.patch.3c.lc ==============
if test -f 'xv.patch.3c.lc' -a X"$1" != X"-c"; then
	echo 'x - skipping xv.patch.3c.lc (File already exists)'
else
echo 'x - extracting xv.patch.3c.lc (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xv.patch.3c.lc' &&
A patch to remove case sensitivity from resource boolean values.
All boolean checks are also moved to a seperate function. The boolean
values are listed in an array.  To add additional "positive" values
to the list, just add them before the null terminator in the keywords[]
array. (rd_boolean() function).  Remember to adjust MAXKEYWORDLEN to the
length of the longest string in the array.
--
Matthew Lee Stier                          |
Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
Email: matthew.stier@East.Sun.COM          |
Phone: (919) 469-8300 fax: (919) 460-8355  | 
X
*** /dev/null	Wed Nov  6 21:42:01 1991
--- README.LC	Wed Nov  6 21:53:32 1991
***************
*** 0 ****
--- 1,12 ----
+ A patch to remove case sensitivity from resource boolean values.
+ All boolean checks are also moved to a seperate function. The boolean
+ values are listed in an array.  To add additional "positive" values
+ to the list, just add them before the null terminator in the keywords[]
+ array. (rd_boolean() function).  Remember to adjust MAXKEYWORDLEN to the
+ length of the longest string in the array.
+ --
+ Matthew Lee Stier                          |
+ Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
+ Email: matthew.stier@East.Sun.COM          |
+ Phone: (919) 469-8300 fax: (919) 460-8355  | 
+ 
*** orig/xv.c	Tue Nov  5 05:40:57 1991
--- xv.c	Tue Nov  5 11:59:28 1991
***************
*** 97,99 ****
--- 97,100 ----
X  static int  rd_int();
X  static int  rd_str();
X  static int  rd_flag();
+ static int  rd_boolean();
***************
*** 2224,2233 ****
X    /* returns '1' if successful.  result in def_str */
X    
X    if (def_str = XGetDefault(theDisp, PROGNAME, name)) {
!     def_int = (strcmp(def_str, "on")==0) || 
!               (strcmp(def_str, "1")==0) ||
! 	      (strcmp(def_str, "true")==0) ||
! 	      (strcmp(def_str, "yes")==0);
X      return 1;
X      }
X  
--- 2225,2231 ----
X    /* returns '1' if successful.  result in def_str */
X    
X    if (def_str = XGetDefault(theDisp, PROGNAME, name)) {
!     def_int = rd_boolean(def_str);
X      return 1;
X      }
X  
***************
*** 2234,2236 ****
--- 2232,2286 ----
X    else return 0;
X  }
X      
+ /***********************************/
+ static int rd_boolean(value)
+ char *value;
+ {
+   int   i;
+   int   match;
+  
+ #define MAXKEYWORDLEN   4  /* the strlen() of largest element in keywords[] */
+  
+   char  tmp[MAXKEYWORDLEN + 1];
+   char *ptr;
+   static char *keywords[] = {
+     "1",
+     "on",
+     "yes",
+     "true",
+     (char *) 0
+   };
+  
+   /* Will 'value' fit in 'tmp' */
+   if (strlen(value) > MAXKEYWORDLEN)
+   { /* Nope, must no be a valid value */
+     return 0;
+   }
+   else
+   { /* get a local copy of value */
+     (void) strncpy(tmp, value, MAXKEYWORDLEN + 1);
+   }
+  
+   /* convert the local copy to lower case */
+   ptr = tmp;
+   while (*ptr != '\0')
+   {
+     *ptr = isupper(*ptr) ? tolower(*ptr) : *ptr;
+     ptr++;
+   }
+ 
+   /* search the array of keywords for a match */
+   i = 0;
+   match = 0;
+   while (keywords[i] != (char *) 0)
+   {
+     if (strcmp(tmp, keywords[i]) == 0)
+     {
+       match = 1;
+     }
+     i++;
+   }
+ 
+   return(match);
+ }
+   
SHAR_EOF
chmod 0644 xv.patch.3c.lc ||
echo 'restore of xv.patch.3c.lc failed'
Wc_c="`wc -c < 'xv.patch.3c.lc'`"
test 3235 -eq "$Wc_c" ||
	echo 'xv.patch.3c.lc: original size 3235, current size' "$Wc_c"
fi
# ============= xv.patch.3d.bfc ==============
if test -f 'xv.patch.3d.bfc' -a X"$1" != X"-c"; then
	echo 'x - skipping xv.patch.3d.bfc (File already exists)'
else
echo 'x - extracting xv.patch.3d.bfc (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xv.patch.3d.bfc' &&
This is a patch to get around the XFreeColors bug in some Xservers. 
It simple causes an alternate ErrorHandler to be installed during the
'XFreeColors()' function call.  The original error handler is reinstalled
after the function call, incase there are other problems.  
X
Note: I'd like to put a check in 'XvErrorHandler()' to make sure it was
an X_FreeColors error, and have it report all other errors.
--
Matthew Lee Stier                          |
Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
Email: matthew.stier@East.Sun.COM          |
Phone: (919) 469-8300 fax: (919) 460-8355  | 
X
*** /dev/null	Wed Nov  6 21:42:01 1991
--- README.BFC	Wed Nov  6 22:15:51 1991
***************
*** 0 ****
--- 1,13 ----
+ This is a patch to get around the XFreeColors bug in some Xservers. 
+ It simple causes an alternate ErrorHandler to be installed during the
+ 'XFreeColors()' function call.  The original error handler is reinstalled
+ after the function call, incase there are other problems.  
+ 
+ Note: I'd like to put a check in 'XvErrorHandler()' to make sure it was
+ an X_FreeColors error, and have it report all other errors.
+ --
+ Matthew Lee Stier                          |
+ Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
+ Email: matthew.stier@East.Sun.COM          |
+ Phone: (919) 469-8300 fax: (919) 460-8355  | 
+ 
*** xvgam.c.orig	Wed Nov  6 10:17:24 1991
--- xvgam.c	Wed Nov  6 12:36:15 1991
***************
*** 620,640 ****
X      LocalCmap = 0;
X    }
X    else {
!     if (!brokeFreeCols) {
!       for (i=0; i<nfcols; i++) 
! 	XFreeColors(theDisp, theCmap, &freecols[i], 1, 0L);
!     }
!     else {
!       for (i=0; i<nfcols; i++) {
! 	int j;
! 	for (j=0; j<i; j++) {
! 	  if (freecols[i] == freecols[j])   /* already been freed once */
! 	    break;
! 	}
! 	if (j==i)      /* wasn't found in already-freed list */
! 	  XFreeColors(theDisp, theCmap, &freecols[i], 1, 0L);
!       }
!     }
X  
X      if (nfcols) {
X        XFlush(theDisp);  /* just to make sure they're all freed right now... */
--- 620,626 ----
X      LocalCmap = 0;
X    }
X    else {
!     XFreeColors(theDisp, theCmap, freecols, 1, 0L, nfcols);
X  
X      if (nfcols) {
X        XFlush(theDisp);  /* just to make sure they're all freed right now... */
*** docs/xv.man.orig	Wed Nov  6 12:16:19 1991
--- docs/xv.man	Wed Nov  6 12:16:36 1991
***************
*** 783,795 ****
X  to 'abort' the current picture without waiting the full specified time by
X  using the 'Next' command.  (Resource name: <none>)
X  .PP
- .IP \fB\-bfc\fP 12
- Toggles the 'color freeing behavior'.  If you experience X Protocol Errors 
- when applying gamma corrections, or when loading multiple images, try 
- using this option.  Normally, this option turns on some workarounds for
- broken X servers, but if \fIxv\fP was built with the workarounds ON by
- default, this option will turn them OFF.  (Resource name:  
- brokeFreeCols.  Type: boolean)
X  
X  .SH SHORTCUTS
X  Commands and their keyboard equivalents:
--- 783,788 ----
*** xv.c.orig	Thu Nov 29 13:44:53 1990
--- xv.c	Wed Nov  6 23:19:04 1991
***************
*** 99,99 ****
--- 99,100 ----
X  static int  rd_flag();
+ static int  XvErrorHandler();
***************
*** 160,167 ****
X  
- #ifdef BROKEFREECOLS
-   brokeFreeCols = 1;
- #else
-   brokeFreeCols = 0;
- #endif
- 
X    defaspect = normaspect = 1.0;
--- 161,162 ----
***************
*** 212,214 ****
X    if (rd_int ("borderWidth"))   bwidth      = def_int;
-   if (rd_flag("brokeFreeCols")) brokeFreeCols = def_int;
X    if (rd_flag("centerPic"))     centerpic   = def_int;
--- 207,208 ----
***************
*** 296,300 ****
X  
-     else if (!strncmp(argv[i],"-bf",3))  /* brokeFreeCols */
-       brokeFreeCols = !brokeFreeCols;
- 
X      else if (!strncmp(argv[i],"-bg",3)) /* background color */
--- 290,291 ----
***************
*** 962,977 ****
X    }
-   else if (!brokeFreeCols) {
-     for (i=0; i<nfcols; i++) 
-       XFreeColors(theDisp, theCmap, &freecols[i], 1, 0L);
-   }
X    else {
!     for (i=0; i<nfcols; i++) {
!       int j;
!       for (j=0; j<i; j++) {
!         if (freecols[i] == freecols[j])   /* already been freed once */
! 	  break;
!       }
!       if (j==i)      /* wasn't found in already-freed list */
!         XFreeColors(theDisp, theCmap, &freecols[i], 1, 0L);
!     }
X    }
--- 953,956 ----
X    }
X    else {
!     XvFreeColors(theDisp, theCmap, freecols, 1, 0L, nfcols);
X    }
***************
*** 2238,2240 ****
--- 2217,2246 ----
X    else return 0;
X  }
X      
+ void XvFreeColors(display, colormap, pixels, npixels, planes, nfcols)
+   Display       * display;
+   Colormap        colormap;
+   unsigned long * pixels;
+   int             npixels;
+   unsigned long   planes;
+   int             nfcols;
+ {
+   int i;
+ 
+   XSetErrorHandler(XvErrorHandler); /* Handle X_FreeColors error messages */
+   for (i=0; i<nfcols; i++) 
+     XFreeColors(display, colormap, &pixels[i], npixels, planes);
+   XSync(theDisp, False); /* Sync the display so that there won't be */
+   XSetErrorHandler(0);   /* problems restoring the default error handler */
+ }
+ 
+ static int XvErrorHandler(display, err)
+ Display *display;
+ XErrorEvent *err;
+ {
+   /* 
+    * What should be done here?  Probably a check for request code 88
+    * And a call to the default error handle under all other errors
+    */
+ }  
+   
*** xv.h.orig	Thu Nov 29 13:45:35 1990
--- xv.h	Wed Nov  6 23:21:21 1991
***************
*** 372,374 ****
X                      rwthistime,    /* true if we DID use R/W color cells */
-                     brokeFreeCols, /* true if server has broken XFreeColors */
X                      fish,          /* turn on annoying fish */
--- 372,373 ----
***************
*** 430,431 ****
--- 429,431 ----
X  void MakeRootPic(void);
+ void XvFreeColors(Display*, Colormap, unsigned long*, int, unsigned long, int);
X  
***************
*** 572,573 ****
--- 572,574 ----
X  void MakeRootPic();
+ void XvFreeColors();
X  
SHAR_EOF
chmod 0644 xv.patch.3d.bfc ||
echo 'restore of xv.patch.3d.bfc failed'
Wc_c="`wc -c < 'xv.patch.3d.bfc'`"
test 5968 -eq "$Wc_c" ||
	echo 'xv.patch.3d.bfc: original size 5968, current size' "$Wc_c"
fi
# ============= xv.patch.3e.gif ==============
if test -f 'xv.patch.3e.gif' -a X"$1" != X"-c"; then
	echo 'x - skipping xv.patch.3e.gif (File already exists)'
else
echo 'x - extracting xv.patch.3e.gif (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xv.patch.3e.gif' &&
These patches permit 'xv' release 3 to read version "89a" gifs. 
The actual read and write code does not change, just the magic number checks.
(Most "GIF89A" gifs don't actually use any "GIF89A" features)
--
Matthew Lee Stier                          |
Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
Email: matthew.stier@East.Sun.COM          |
Phone: (919) 469-8300 fax: (919) 460-8355  | 
X
*** /dev/null	Wed Nov  6 21:42:01 1991
--- README.GIF	Wed Nov  6 21:46:41 1991
***************
*** 0 ****
--- 1,9 ----
+ These patches permit 'xv' release 3 to read version "89a" gifs. 
+ The actual read and write code does not change, just the magic number checks.
+ (Most "GIF89A" gifs don't actually use any "GIF89A" features)
+ --
+ Matthew Lee Stier                          |
+ Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
+ Email: matthew.stier@East.Sun.COM          |
+ Phone: (919) 469-8300 fax: (919) 460-8355  | 
+ 
*** orig/xv.c	Tue Nov  5 05:40:57 1991
--- xv.c	Tue Nov  5 12:33:35 1991
***************
*** 777,783 ****
X    fclose(fp);
X  
X    filetype = UNKNOWN;
!   if (strncmp(magicno,"GIF87",5)==0) filetype = GIF;
X  
X    else if (strncmp(magicno,"VIEW",4)==0 ||
X  	   strncmp(magicno,"WEIV",4)==0) filetype = PM;
--- 777,783 ----
X    fclose(fp);
X  
X    filetype = UNKNOWN;
!   if (strncmp(magicno,"GIF",3)==0) filetype = GIF;
X  
X    else if (strncmp(magicno,"VIEW",4)==0 ||
X  	   strncmp(magicno,"WEIV",4)==0) filetype = PM;
*** orig/xvgif.c	Tue Nov  5 12:33:46 1991
--- xvgif.c	Tue Nov  5 12:43:14 1991
***************
*** 88,94 ****
X      /* An output array used by the decompressor */
X  int OutCode[1025];
X  
! char *id = "GIF87a";
X  
X  static int EGApalette[16][3] = {
X    {0,0,0},       {0,0,128},     {0,128,0},     {0,128,128}, 
--- 88,95 ----
X      /* An output array used by the decompressor */
X  int OutCode[1025];
X  
! char *id87 = "GIF87a";
! char *id89 = "GIF89a";
X  
X  static int EGApalette[16][3] = {
X    {0,0,0},       {0,0,128},     {0,128,0},     {0,128,128}, 
***************
*** 140,146 ****
X    if (fread(ptr, filesize, 1, fp) != 1) 
X      return( GifError("GIF data read failed") );
X    
!   if (strncmp(ptr, id, 6)) 
X      return( GifError("not a GIF file"));
X    
X    ptr += 6;
--- 141,147 ----
X    if (fread(ptr, filesize, 1, fp) != 1) 
X      return( GifError("GIF data read failed") );
X    
!   if (strncmp(ptr, id87, 6) && strncmp(ptr, id89, 6)) 
X      return( GifError("not a GIF file"));
X    
X    ptr += 6;
SHAR_EOF
chmod 0644 xv.patch.3e.gif ||
echo 'restore of xv.patch.3e.gif failed'
Wc_c="`wc -c < 'xv.patch.3e.gif'`"
test 2495 -eq "$Wc_c" ||
	echo 'xv.patch.3e.gif: original size 2495, current size' "$Wc_c"
fi
# ============= xv.patch.3f.jpeg ==============
if test -f 'xv.patch.3f.jpeg' -a X"$1" != X"-c"; then
	echo 'x - skipping xv.patch.3f.jpeg (File already exists)'
else
echo 'x - extracting xv.patch.3f.jpeg (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'xv.patch.3f.jpeg' &&
This version of xv needs the JPEG software from the free JPEG working group.
It is based on xv patchlevel 3 and the JPEG working group's distribution
from 07-Oct-91. It's xv with a JPEG decoder module that allows you to view 
JPEG encoded images in addition to the standard xv formats.
X
This package consists of the followings files:
X
X  README.JPEG	- this file
X  xvjpeg.c      - the control module for the JPEG decoder
X  JPEGPATCH	- a set of patches to enable xv to use the decoder
X
If you have suggestions or comments please contact me at:
X
X	s_baur@iravcl.ira.uka.de
X
or via snail-mail:
X
X	Markus Baur
X	Leutschauer Str. 22
X	W-7500 Karlsruhe 41
X	Federal Republic of Germany
X
I would like to thank Tom Lane, Philip Gladstone, Luis Ortiz, and the other
members of the free JPEG working group for their JPEG implementation,
as well as John Bradley for xv.
X
NOTE: To this code applies the same as to the free JPEG working group's:
X      THIS CODE IS NOT COMPLETE NOR DEBUGGED.  It is not guaranteed to be 
X      useful for anything, nor to be compatible with subsequent releases.
X
Compilation
-----------
X
X  1) Apply the patches with:
X
X     - "patch -p < JPEGPATCH"
X
X  2) Edit the Imakefile:
X
X     - JPEGDIR should point to the directory where you have your JPEG
X       software
X
X  3) Just type "xmkmf" and "make" to get your executable.
X
To do:
------
X
X  - Adding the JPEG encoder part.
X
X  - Support for the coming JPEG in TIFF file format.
X
X  - It's rather ugly to look only at the first three bytes to determine
X    whether we have a JFIF file.
X
*** /dev/null	Tue Nov  5 21:42:02 1991
--- README.JPEG	Tue Nov  5 22:00:03 1991
***************
*** 0 ****
--- 1,55 ----
+ README.JPEG - 05 November 1991
+ --------------------------------
+ This version of xv needs the JPEG software from the free JPEG working group.
+ It is based on xv patchlevel 3 and the JPEG working group's distribution
+ from 07-Oct-91. It's xv with a JPEG decoder module that allows you to view 
+ JPEG encoded images in addition to the standard xv formats.
+ 
+ This package consists of the followings files:
+ 
+   README.JPEG	- this file
+   xvjpeg.c      - the control module for the JPEG decoder
+   JPEGPATCH	- a set of patches to enable xv to use the decoder
+ 
+ If you have suggestions or comments please contact me at:
+ 
+ 	s_baur@iravcl.ira.uka.de
+ 
+ or via snail-mail:
+ 
+ 	Markus Baur
+ 	Leutschauer Str. 22
+ 	W-7500 Karlsruhe 41
+ 	Federal Republic of Germany
+ 
+ I would like to thank Tom Lane, Philip Gladstone, Luis Ortiz, and the other
+ members of the free JPEG working group for their JPEG implementation,
+ as well as John Bradley for xv.
+ 
+ NOTE: To this code applies the same as to the free JPEG working group's:
+       THIS CODE IS NOT COMPLETE NOR DEBUGGED.  It is not guaranteed to be 
+       useful for anything, nor to be compatible with subsequent releases.
+ 
+ Compilation
+ -----------
+ 
+   1) Apply the patches with:
+ 
+      - "patch -p < JPEGPATCH"
+ 
+   2) Edit the Imakefile:
+ 
+      - JPEGDIR should point to the directory where you have your JPEG
+        software
+ 
+   3) Just type "xmkmf" and "make" to get your executable.
+ 
+ To do:
+ ------
+ 
+   - Adding the JPEG encoder part.
+ 
+   - Support for the coming JPEG in TIFF file format.
+ 
+   - It's rather ugly to look only at the first three bytes to determine
+     whether we have a JFIF file.
*** /src/X11Progs/xv/xv.c	Thu Nov 29 19:44:53 1990
--- xv.c	Wed Sep 18 20:24:00 1991
***************
*** 53,58 ****
--- 53,59 ----
X  #define PM      2
X  #define PBM     3
X  #define XBM     4
+ #define JFIF    5
X  
X  static unsigned long rootbg, rootfg;  /* fg/bg for root border */
X  static int    waitsec = -1;     /* seconds between pics. -1=wait for event */
***************
*** 779,784 ****
--- 780,789 ----
X    filetype = UNKNOWN;
X    if (strncmp(magicno,"GIF87",5)==0) filetype = GIF;
X  
+   else if (magicno[0] == -1 && 
+ 	   magicno[1] == -40 && 
+ 	   magicno[2] == -1) filetype = JFIF; 
+ 
X    else if (strncmp(magicno,"VIEW",4)==0 ||
X  	   strncmp(magicno,"WEIV",4)==0) filetype = PM;
X  
***************
*** 796,805 ****
X    SetISTR(ISTR_INFO,"Loading '%s'...",basename);
X  
X    switch (filetype) {
!   case GIF: i = LoadGIF(filename,ncols); break;
!   case PM:  i = LoadPM (filename,ncols); break;
!   case PBM: i = LoadPBM(filename,ncols); break;
!   case XBM: i = LoadXBM(filename,ncols); break;
X    }
X    WaitCursor();
X  
--- 801,811 ----
X    SetISTR(ISTR_INFO,"Loading '%s'...",basename);
X  
X    switch (filetype) {
!   case GIF:  i = LoadGIF (filename,ncols); break;
!   case PM:   i = LoadPM  (filename,ncols); break;
!   case PBM:  i = LoadPBM (filename,ncols); break;
!   case XBM:  i = LoadXBM (filename,ncols); break;
!   case JFIF: i = LoadJFIF(filename,ncols); break;
X    }
X    WaitCursor();
X  
*** /src/X11Progs/xv/xv.h	Thu Nov 29 19:45:35 1990
--- xv.h	Wed Sep 18 20:23:58 1991
***************
*** 558,560 ****
X  int LoadXBM(char *, int);
X  int WriteXBM(FILE *, byte *, int, int, char *);
X  
--- 558,563 ----
X  int LoadXBM(char *, int);
X  int WriteXBM(FILE *, byte *, int, int, char *);
X  
+ /**************************** XVJPEG.C ***************************/
+ int LoadJFIF(char *, int);
X  
***************
*** 632,635 ****
--- 633,638 ----
X  /**************************** XVXBM.C ***************************/
X  int LoadXBM(), WriteXBM();
X 
+ /**************************** XVJPEG.C ***************************/
+ int LoadJFIF();
X  
*** /dev/null	Tue Nov  5 21:42:02 1991
--- xvjpeg.c	Tue Nov  5 21:53:47 1991
***************
*** 0 ****
--- 1,206 ----
+ /*
+ * xvjpeg.c - load routine for 'jpeg' format pictures
+ *
+ * LoadJFIF(fname, numcols)  -  loads a JPEG pic, does 24to8 code if nec.
+ */
+ 
+ /*
+ * Author: Markus Baur, University of Karlsruhe (s_baur@iravcl.ira.uka.de)
+ * This software is provided "as is" without any express or implied warranty.
+ */
+ 
+ 
+ #include "xv.h"
+ #include "pm.h"
+ #include "jinclude.h"
+ 
+ boolean greyscale;
+ byte *pic24;
+ byte *CurImagePtr;
+ static long filesize;
+ 
+ static void d_ui_method_selection (cinfo)
+ decompress_info_ptr cinfo;
+ {
+   /* select output colorspace */
+   if (cinfo->jpeg_color_space == CS_GRAYSCALE) {
+     cinfo->out_color_space = CS_GRAYSCALE;
+     SetISTR(ISTR_FORMAT,"JFIF, greyscale. (%ld bytes)", filesize);
+     greyscale = TRUE;
+   } else {
+     cinfo->out_color_space = CS_RGB;
+     SetISTR(ISTR_FORMAT,"JFIF, color. (%ld bytes)", filesize);
+     greyscale = FALSE;
+   }
+   /* For now, always select PPM format. */
+   jselwppm(cinfo);
+ }
+ 
+ static void output_init (cinfo)
+ decompress_info_ptr cinfo;
+ {
+   pWIDE = cinfo->image_width;
+   pHIGH = cinfo->image_height;
+ 
+   if (cinfo->out_color_space == CS_GRAYSCALE) {
+     pic = (byte *) malloc(pWIDE * pHIGH);
+     if (!pic) FatalError("Not enough memory for Image");
+     CurImagePtr = pic;
+   } else {
+     pic24 = (byte *) malloc(pWIDE * pHIGH * 3);
+     if (!pic24) FatalError("Not enough memory for Image");
+     CurImagePtr = pic24;
+   }
+ }
+ 
+ static void put_color_map (cinfo, num_colors, colormap)
+ decompress_info_ptr cinfo;
+ {
+   /* never done, because we let xv quantize colors */
+   fprintf(stderr, "this should have never happened.\n");
+ }
+ 
+ static void put_pixel_rows (cinfo, num_rows, pixel_data)
+ decompress_info_ptr cinfo;
+ int num_rows;
+ JSAMPIMAGE pixel_data;
+ {
+   JSAMPROW ptr0, ptr1, ptr2;
+   long col;
+   long width = cinfo->image_width;
+   int row;
+ 
+   if (cinfo->out_color_space == CS_GRAYSCALE) {
+     for (row = 0; row < num_rows; row++) {
+       memcpy( CurImagePtr, pixel_data[0][row], width);
+       CurImagePtr += width;
+     }
+   } else {
+     for (row = 0; row < num_rows; row++) {
+       ptr0 = pixel_data[0][row];
+       ptr1 = pixel_data[1][row];
+       ptr2 = pixel_data[2][row];
+       for (col = width; col > 0; col--) {
+ 	*CurImagePtr++ = *ptr0++;
+ 	*CurImagePtr++ = *ptr1++;
+ 	*CurImagePtr++ = *ptr2++;
+       }
+     }
+   }
+ }
+ 
+ static void output_term (cinfo)
+ decompress_info_ptr cinfo;
+ {
+   /* no work required */
+ }
+ 
+ void jselwppm (cinfo)
+ decompress_info_ptr cinfo;
+ {
+   cinfo->methods->output_init = output_init;
+   cinfo->methods->put_color_map = put_color_map;
+   cinfo->methods->put_pixel_rows = put_pixel_rows;
+   cinfo->methods->output_term = output_term;
+ }
+ 
+ /*
+  * Reload the input buffer after it's been emptied, and return the next byte.
+  * See the JGETC macro for calling conditions.
+  *
+  * This routine would need to be replaced if reading JPEG data from something
+  * other than a stdio stream.
+  */
+  
+ METHODDEF int
+ read_jpeg_data (cinfo)
+ decompress_info_ptr cinfo;
+ {
+   cinfo->bytes_in_buffer = fread(cinfo->input_buffer + MIN_UNGET,
+                                  1, JPEG_BUF_SIZE,
+                                  cinfo->input_file);
+  
+   cinfo->next_input_byte = cinfo->input_buffer + MIN_UNGET;
+  
+   if (cinfo->bytes_in_buffer <= 0)
+     ERREXIT(cinfo->emethods, "Unexpected EOF in JPEG file");
+  
+   return JGETC(cinfo);
+ }
+  
+  
+ /*******************************************/
+ int LoadJFIF(fname,nc)
+ char *fname;
+ int   nc;
+ /*******************************************/
+ {
+ FILE  *fp;
+ struct decompress_info_struct cinfo;
+ struct decompress_methods_struct dc_methods;
+ struct external_methods_struct e_methods;
+ int i, c;
+ 
+ /* Initialize the system-dependent method pointers. */
+ cinfo.methods = &dc_methods;
+ cinfo.emethods = &e_methods;
+ jselerror(&e_methods);        /* error/trace message routines */
+ jselvirtmem(&e_methods);      /* memory allocation routines */
+ dc_methods.d_ui_method_selection = d_ui_method_selection;
+ dc_methods.read_jpeg_data = read_jpeg_data;
+ 
+ /* Allocate memory for input buffer. */
+ cinfo.input_buffer = (char *) (*cinfo.emethods->alloc_small)
+                               ((size_t) (JPEG_BUF_SIZE + MIN_UNGET));
+ cinfo.bytes_in_buffer = 0;    /* initialize buffer to empty */
+ 
+ /* Set up default input and output file references. */
+ /* (These may be overridden below.) */
+ cinfo.input_file = stdin;	/* i'll change that, be sure! */
+ cinfo.output_file = stdout;	/* only wanna read */
+ 
+ /* Set up default parameters. */
+ e_methods.trace_level = 0;
+ cinfo.output_gamma = 1.0;
+ cinfo.quantize_colors = FALSE;
+ cinfo.two_pass_quantize = FALSE;
+ cinfo.use_dithering = FALSE;
+ cinfo.desired_number_of_colors = 256;
+ cinfo.do_block_smoothing = FALSE;
+ cinfo.do_pixel_smoothing = FALSE;
+ cinfo.out_color_space = CS_RGB;
+ cinfo.jpeg_color_space = CS_UNKNOWN;
+ /* setting any other value in jpeg_color_space overrides heuristics */
+ /* in jrdjfif.c ... */
+ 
+ if ((cinfo.input_file = fopen(fname, "r")) == NULL) 
+   FatalError("Can't open file!");
+ 
+ /* figure out the file size (for Informational Purposes Only) */
+ fseek(cinfo.input_file, 0L, 2);
+ filesize = ftell(cinfo.input_file);
+ fseek(cinfo.input_file, 0L, 0);
+ 
+ /* Set up to read a JFIF or baseline-JPEG file. */
+ /* A smarter UI would inspect the first few bytes of the input file */
+ /* to determine its type. */
+ jselrjfif(&cinfo);
+ 
+ /* Do it! */
+ jpeg_decompress(&cinfo);
+ 
+ if (greyscale) {
+   /* fill in a greyscale colormap */
+   for (i=0; i<=255; i++) r[i] = g[i] = b[i] = i;
+ } else {
+   /* Convert to 8 bits depth and free 24 Bit Image */
+   Conv24to8(pic24, pWIDE, pHIGH, nc);
+   free(pic24);
+ };
+ 
+ /* Close input file */
+ fclose(cinfo.input_file);
+ 
+ /* Got it! */
+ return 0;
+ };
*** docs/xv.man.orig	Wed Nov  6 12:16:19 1991
--- docs/xv.man	Wed Nov  6 12:20:17 1991
***************
*** 4,10 ****
X  .SH SYNTAX
X  \fBxv\fP \fI[options] [filename [filename...]]\fP
X  .SH DESCRIPTION
! \fIxv\fP is an X11 program that displays images in the GIF, PBM, PGM, PPM, 
X  X11 bitmap, and PM formats on 1-, 4-, 6-, 8-, 24-, and 32-bit X displays.  
X  .SH OVERVIEW
X  \fIxv\fP displays one image at a time in an output window.  You can arbitrarily
--- 4,10 ----
X  .SH SYNTAX
X  \fBxv\fP \fI[options] [filename [filename...]]\fP
X  .SH DESCRIPTION
! \fIxv\fP is an X11 program that displays images in the JPEG, GIF, PBM, PGM, PPM, 
X  X11 bitmap, and PM formats on 1-, 4-, 6-, 8-, 24-, and 32-bit X displays.  
X  .SH OVERVIEW
X  \fIxv\fP displays one image at a time in an output window.  You can arbitrarily
*** Imakefile.orig	Thu Nov 29 14:27:51 1990
--- Imakefile	Wed Nov  6 22:54:11 1991
***************
*** 83,83 ****
--- 83,87 ----
X  
+ JPEGDIR = $(HOME)/jpeg
+ 
+ INCLUDES= -I$(JPEGDIR)
+ 
***************
*** 98,99 ****
--- 102,109 ----
X  
+ JOBJS =	$(JPEGDIR)/jerror.o $(JPEGDIR)/jrdjfif.o $(JPEGDIR)/jdcolor.o \
+ 	$(JPEGDIR)/jdhuff.o $(JPEGDIR)/jdmaster.o $(JPEGDIR)/jdmcu.o \
+ 	$(JPEGDIR)/jdpipe.o $(JPEGDIR)/jdsample.o $(JPEGDIR)/jrevdct.o \
+ 	$(JPEGDIR)/jutils.o $(JPEGDIR)/jvirtmem.o $(JPEGDIR)/jbsmooth.o \
+ 	$(JPEGDIR)/jquant1.o $(JPEGDIR)/jquant2.o
+ 
X  SRCS1 =	xv.c xv24to8.c xvbutt.c xvctrl.c xvdir.c xvfish.c xvgam.c\
***************
*** 100,102 ****
X  	xvgif.c xvgifwr.c xvinfo.c xvmisc.c xvpbm.c xvpm.c xvscrl.c\
! 	xvxbm.c vprintf.c
X  
--- 110,112 ----
X  	xvgif.c xvgifwr.c xvinfo.c xvmisc.c xvpbm.c xvpm.c xvscrl.c\
! 	xvxbm.c vprintf.c xvjpeg.c
X  
***************
*** 104,106 ****
X  	xvgif.o xvgifwr.o xvinfo.o xvmisc.o xvpbm.o xvpm.o xvscrl.o \
! 	xvxbm.o vprintf.o
X  
--- 114,116 ----
X  	xvgif.o xvgifwr.o xvinfo.o xvmisc.o xvpbm.o xvpm.o xvscrl.o \
! 	xvxbm.o vprintf.o xvjpeg.o $(JOBJS)
X  
***************
*** 111,112 ****
--- 121,126 ----
X  
+ #define IHaveSubdirs
+ #define PassCDebugFlags
+ SUBDIRS= $(JPEGDIR)
+ MakeSubdirs($(SUBDIRS))
X  ComplexProgramTarget_1(xv,,)
SHAR_EOF
chmod 0644 xv.patch.3f.jpeg ||
echo 'restore of xv.patch.3f.jpeg failed'
Wc_c="`wc -c < 'xv.patch.3f.jpeg'`"
test 13605 -eq "$Wc_c" ||
	echo 'xv.patch.3f.jpeg: original size 13605, current size' "$Wc_c"
fi
exit 0
-- 
Matthew Lee Stier                          |
Sun Microsystems ---  RTP, NC  27709-3447  |     "Wisconsin   Escapee"
Email: matthew.stier@East.Sun.COM          |
Phone: (919) 469-8300 fax: (919) 460-8355  | 
Technical Details
Message-ID: <5475@southeast.East.Sun.COM>
Path: arc1-ca.pugleaf.net!wupost!cs.utexas.edu!uunet!sun-barr!newstop!southeast!matthew

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!wupost!cs.utexas.edu!uunet!sun-barr!newstop!southeast!matthew
From: matthew@sunpix.East.Sun.COM (Matthew Stier - Sun Visualization Products)
Newsgroups: alt.graphics.pixutils,alt.sources,alt.sources.patches
Subject: Six Patches for 'Xv'.
Summary: patches gif jpeg xfreecolors
Message-ID: <5475@southeast.East.Sun.COM>
Date: 7 Nov 91 15:26:35 GMT
Sender: news@East.Sun.COM
Followup-To: alt.graphics.pixutils
Organization: Sun Microsystems, Research Triangle Park, NC
Lines: 1136