CSUF LogoCSUF Site Navigation
optics.csufresno.edu

FC5 Drawing & Image Manipulation Programs xv

Department of Electrical and Computer Engineering
Assistant Professor Gregory R. Kriehn
Forums
Wiki
FC5 xv
I can tell that I am starting to become a bit dated in my preferences, because one of my favorite image displays for the X window system, xv, needs some serious hacking in order to get it to compile properly in Fedora Core 5. I use it because it is simple, easy to use, and allows me to very quickly display, convert, and save different types of image formats. Call me old school, especially with this program, but I love it...

To get xv working, there are a bunch of patches that need to be applied to the source code, since the maintainer (for some reason), seems to prefer throwing up links to patches opposed to applying them to the source code and releasing a new version. At any rate, while patching the source code, I also like to hack the Makefile to ensure that the newest version of the TIFF and JPEG libraries are being used as well. We can use the stock PNG and ZLIB libraries included with FC5, but unfortunately, due to the nature of some of the .c (source code) files, we are going to have to install the newest version of the JPEG and TIFF libraries by hand (editing .c files is beyond the scope of what I am willing to do to get xv to compile). In addition to this, anything above gcc (Gnu C Compiler) Version 3.2 will not compile xv, so we'll have to use gcc32.

Download xv and the Appropriate Patches
Knowing this, head over to the download page for xv:

http://www.trilon.com/xv/downloads.html

and click on the first link under the xv 3.10a source distributions section, which will download xv-3.10a.tar.gz to your computer under ~/Desktop if you are using Firefox.
Once it downloads, change into the ~/Desktop directory:
~> cd ~/Desktop
and create a temporary patches directory:
~> mkdir patches
The next order of business is to scroll down to the Patches to xv 3.10a section of the website and download the appropriate patches. You may have to click around on a couple of the links to find the appropriate files. To help, I've gone ahead and summarized the needed patch files (and tarballs) here:

Patch Link NamePatch NameNeeded/Not Needed
Patch to fix Grab problemsgrabpatchNEEDED
Patch to fix Visual-picking problemvispatchNOT NEEDED
(Sun OS only!)
Patch to read & display multi-page TIFF filesmp-tiff-patchNEEDED
Patch to keep xv from crashing on Really Long Filenameslongname.patchNEEDED
Patch to fix XPM file output errorsxpm.patchNEEDED
Patch to Image display on certain I2-, I5-, or 16-bit X Displaysdeepcolor.patchNEEDED
Patch to GIF-reading codegifpatchNEEDED
Patch to fix non-functional grab on some X serversexceed_grab.patchNEEDED
READ THIS to compile XV on RedHat 6, and most other newer Linux distributionsxv-redhat6-readme.txtNEEDED INFO
Patch to compile XV on BeOSbeos.patchNOT NEEDED
(BeOS Only!)
Patch to fix TIFF files being written at 1200dpitiff1200.patchNEEDED
SECURITY PATCH for Postscript Filesgssafer.patchNEEDED
Patch to use Version 6 of the JPEG libraryjpegsrc.v6b.tar.gz
xv-3.10a.JPEG-patch
NEEDED
NEEDED
Patch to use Version 3.4 of the TIFF Librarytiff-v3.4-tar.gz
xv-3.10a.TIFF-patch
NOT NEEDED
NEEDED
Patch to read/write PNG filesxv-3.10a-png-1.2d.tar.gz
xvpng-1.2d-fix3.patch
NEEDED
NEEDED
Patch to 'read' PDF filespdf.patchNEEDED
Patch to use XV as a Netscape pluginwindowid.patchNEEDED
Patch to read 32-bit-per-pixel BMP filesbmp32.patchNEEDED

As you download each of the patches, and two compressed tarballs, move them into the patches directory:

~> mv [patchname/tarball] ~/Desktop/patches/.
Next, create an appropriate directory to install xv under /usr/local/src/xv:
~> sudo mkdir -p /usr/local/src/xv
Move the source tarball to the directory:
~> sudo mv ~/Desktop/xv-3.10a.tar.gz /usr/local/src/xv/.
Change into the xv directory:
~> cd /usr/local/src/xv
and decompress the source:
~> sudo tar vfzx xv-3.10a.tar.gz
Once the package has been decompressed, delete the source file, and change into the xv-3.10a directory:
~> sudo rm xv-3.10a.tar.gz
~> cd xv-3.10a
Finally, before we start patching, move the patches directory into the current working directory, and remove the default TIFF and JPEG libraries, since we are not going to use them:
~> sudo mv ~/Desktop/patches /usr/local/src/xv/xv-3.10a/.
~> sudo rm -r ./tiff
~> sudo rm -r ./jpeg
Apply the Patches
Next comes the application of all the patches
for simplicity, we will apply them in the same order that they are listed above, even though it means editing the Makefile more than once, and making a detour to install the newest version of the TIFF libraries from another site. To apply the patches, we will have to use the patch program, which takes a patch file containing the difference listing produced by the diff program and applies the differences to one or more of the original files, creating patched versions. The usage is:
~> patch [options] [originalfile [patchfile]]
The First 7 Patches
With this in mind, apply the following patches in order:

~> sudo patch < patches/grabpatch
~> sudo patch < patches/mp-tiff-patch
~> sudo patch < patches/longname.patch
~> sudo patch < patches/xpm.patch
~> sudo patch < patches/deepcolor.patch
~> sudo patch < patches/gifpatch
~> sudo patch < patches/exceed_grab.patch
Compiling for Linux and the tiff1200 and gssafer Patches
Next comes the information for compiling xv on linux systems. If you pull open the xv-redhat6-readme.txt file, you will notice some important information with respect to xv.h. I've cleaned up the grammar of what was written there, and changed the wording a bit to reflect the changes that are necessary for systems newer than RedHat 6 (yes, xv is old...):

The lines 118 - 120 in the "xv.h" header file should be commented out, otherwise you get an "already defined in stdio.h" error and compilation aborts:

     #  ifndef __NetBSD__
          extern char *sys_errlist[];    /*  this too...  */
     #  endif

Second, in the machine-specific options in the Makefile the Linux once should contain the exact path to X11 libraries, because "make" will not find them otherwise. This used to be located in "/usr/X11R6/lib". With FC5, the libraries are not found in "/usr/lib". So, line 105 reads:

     MCHN = -DLINUX -L/usr/lib

Based upon this information, open up the xv.h file using sudo and scroll down to Line 118. Edit out Lines 118 - 120 so that they look like:
/* #  ifndef __NetBSD__ */
/*     extern char *sys_errlist[]; */    /* this too... */
/* #  endif */
Save and exit. Next, open up the Makefile. Besides editing Line 105, while we are here, let's edit Line 4 as well so that we use the Gnu C Compiler Version 3.2. Line 4 should read:
CC = gcc32
Then scroll down to Line 105. Uncomment the line and provide the path for the X11 libraries:
MCHN = -DLINUX -L/usr/lib
Save and exit. Then go back to applying patches:
~> sudo patch < patches/tiff1200.patch
~> sudo patch < patches/gssafer.patch
Using the JPEG V6b Library
Next comes folding in the new JPEG and TIFF libraries. With respect to the JPEG libraries, JPEG V6b is the most current version (see http://www.ijg.org/), which is included in the jpegsrc.v6b.tar.gz tarball that we have already downloaded. Move it to the current working directory (from the patches directory) and uncompress it:

~> sudo mv patches/jpegsrc.v6b.tar.gz .
~> sudo tar vfzx jpegsrc.v6b.tar.gz
~> sudo rm jpegsrc.v6b.tar.gz
With this done, let's apply the patch:
~> sudo patch < patches/xv-3.10a.JPEG-patch
Using the TIFF V3.8 Library
For the TIFF libraries, we are going to have to detour and download the current version of libtiff and install it by hand, since the link provided by xv (
tiff-v3.4-tar.gz) is dated. The source file can be found at:

http://www.remotesensing.org/libtiff/

The current version, as of FC5, is V3.8.2. Click on the Master Download Site, ftp.remotesensing.org, followed by the tiff-3.8.2.tar.gz link to download it.
Create an appropriate directory to install the TIFF libraries under /usr/local/src/tiff:
~> sudo mkdir -p /usr/local/src/tiff
Move the source tarball to the directory:
~> sudo mv ~/Desktop/tiff-3.8.2.tar.gz /usr/local/src/tiff/.
Change into the tiff directory:
~> cd /usr/local/src/tiff
and decompress the source:
~> sudo tar vfzx tiff-3.8.2.tar.gz
Once the package has been decompressed, delete the source file, and change into the tiff-3.8.2 directory:
~> sudo rm tiff-3.8.2.tar.gz
~> cd tiff-3.8.2
Run the configure script:
~> sudo ./configure
Compile the TIFF libraries:
~> sudo make
and once compiling is finished, install them:
~> sudo make install
Verify that libtiff.a was installed in /usr/local/lib. With that done, change directories back to /usr/local/src/xv/xv-3.10a:
~> cd /usr/local/src/xv/xv-3.10a
and apply the TIFF patch:
~> sudo patch < patches/xv-3.10a.TIFF-patch
PNG Patches
Next comes the patch for PNG, which is a bit of a pain to apply as well. First, create a png directory and move the xv-3.10a-png-1.2d.tar.gz compressed tarball into it:

~> sudo mkdir png
~> sudo mv patches/xv-3.10a-png-1.2d.tar.gz png/.
Change into the png directory, uncompress the tarball, and delete it:
~> cd png
~> sudo tar vfzx xv-3.10a-png-1.2d.tar.gz
~> sudo rm xv-3.10a-png-1.2d.tar.gz
For whatever reason, the permissions of the files are set incorrectly. To change them, use chown and chmod:
~> sudo chown -R root.root *
~> sudo chown -R root.root *.*
~> sudo chmod -R go+r *
~> sudo chmod -R go+r *.*
With that done, copy the xvpng.c and bits/br_png files into the xv-3.10a source code directory:
~> sudo cp xvpng.c ./../.
~> sudo cp bits/br_png ./../bits/.
Before leaving the png subdirectory, we need to edit the xvpng.diff file and remove a few lines because part of the patch was already applied by the xpm.patch file. The lines that need to be removed are the following:
*** 1168,1174 ****

    case F_XPM:
      rv = WriteXPM   (fp, thepic, ptype, w, h, rp, gp, bp, nc, col,
!                    fullname, picComments);
    case F_FITS:
      rv = WriteFITS  (fp, thepic, ptype, w, h, rp, gp, bp, nc, col,
                     picComments);
--- 1180,1187 ----

    case F_XPM:
      rv = WriteXPM   (fp, thepic, ptype, w, h, rp, gp, bp, nc, col,
!                    fullname, picComments);
!     break;
    case F_FITS:
      rv = WriteFITS  (fp, thepic, ptype, w, h, rp, gp, bp, nc, col,
                     picComments);
***************
Remove the above lines and the above lines only! If you don't remove this part of the patch file, you will get an error when it is applied (although, it will apply the rest of the patches). Also, note that from this point forward, as a result of the previous patches that have already been applied, many of the patch lines will now be offset by a few lines in the source code. patch will complain, but will still work. With this in mind, change back to the base xv-3.10a directory:
~> cd ..
and apply the PNG patches:
~> sudo patch -p1 < png/xvpng.diff
~> sudo patch -p1 < png/xcmap.diff
The xvjpeg.diff and xvtiff.diff files located in the png directory are NOT NEEDED because they are identical to the xv-3.10a.JPEG-patch and xv-3.10a.TIFF-patch files, which have already been applied. However, we still need to apply the xvpng patch, which should be in your patches subdirectory:
~> sudo patch < patches/xvpng-1.2d-fix3.patch
The Last 3 Patches
And finally, apply the last three patches:

~> sudo patch < patches/pdf.patch
~> sudo patch < patches/windowid.patch
~> sudo patch < patches/bmp32.patch
Final Adjustments to the Makefile
With that done, we now have to edit the Makefile one more time to adjust the location of some of the libraries (we could not do it before, since the patches had not been applied yet). Open up the Makefile, and do a search for JPEG. Scroll down to the JPEGDIR line and modify it so that it reads:
JPEGDIR = jpeg-6b
since that was the directory that was created when we uncompressed the JPEG V6b libraries. From there, scroll down a bit to the PNGRDIR line, and change it to:
PNGDIR = /usr/include/libpng
Scroll down a bit more to the ZLIBDIR line, and change it to:
ZLIBDIR = /usr/include
And lastly, scroll down to the TIFFDIR line, and change it to:
TIFFDIR = /usr/local/lib
Compile and Install xv
Finally! xv is going to re-create the libjpeg.a file when we compile it (even though Fedora already has it) because a couple of source files need the jconfig.h and jerror.h header files. The PNG and ZLIB libraries are already included in FC5 (hence the changes to /usr/include/libpng and /usr/include, respectively). And for the TIFF library, we can use the newly created libtiff.a file in /usr/local/lib. If you couldn't guess by now, there is no configure file, so simply compile it:

~> sudo make
and install it:
~> sudo make install
With that done, source your .tcshrc file:
~> source ~/.tcshrc
and you are ready to finally use xv:
~> xv &
You now have a nifty little program that can be used to look at, save, and convert gif, jpeg, tiff, png, postscript, pbm/pgm/ppm, X11 bitmap, xpm, bmp, sun rasterfile, IRIS rgb, targa, fits, and pm picture files. For quick and dirty work, I still find it to be the simplest program out there. Enjoy!