Typo
[linux_from_scratch_hints.git] / OLD / lzw_graphics.txt
blob2ce506d9720f49f40866dee06f7b933fcd2be0f0
1 Title:          LZW Compression for Graphics Libraries in BLFS
2 BLFS VERSION:   1.0
3 Author:         Michael A. Peters <mpeters@mac.com>
5 SYNOPSIS:
6         Adding LZW compression to graphics applications that can utilize it
8 HINT:
9 ver 1.0
10 08/05/2003
12 Contents
13 --------
15         0. Preface
16         1. Why care about LZW
17         2. Legal Issues
18         3. Giflib as replacement for libungif
19                 3a. Makefile Issues
20         4. libtiff
21         5. gd library
23 0. Preface
24 ----------
25         In the early 1980's a compression algorithm known as LZW emerged that
26         was very good at lossless compression of data. This algorithm was used
27         in a variety of software products, such as the UNIX compress command.
29         LZW was chosen as the compression algorithm for the CompuServe GIF image
30         format, as well as the TIFF image format. A free library emerged called
31         Giflib that allowed freeware and shareware authors to write programs for
32         the GIF image format, and as a result, the GIF image format became very
33         popular.
35         A company called Unisys existed that owned a patent on this algorithm,
36         but they did not complain until the GIF image format was already in very
37         wide use. At that point in time, they decided they wanted to charge a
38         very expensive licensing fee to use the LZW compression algorithm.
40         Since free software is free, this became a problem for the free software
41         industry. The result was that LZW was ripped out of several products.
43         This document tells you how to put it back in since many countries do
44         not recognize the Unisys software patent, and the patent is very close
45         to expiring in the U.S. if it has not expired already.
47 1. Why Care About LZW
48 ---------------------
49         The PNG image format has largely replaced the GIF image in the free
50         software world. However, the evil was not with LZW - but rather, with
51         the software patent that restricted its use without licensing.
52         
53         Since the compression algorithm itself is a very good one, there is no
54         reason not to use it where we can. Also, while PNG can be used as a
55         replacement for GIF, there is not really a suitable replacement for the
56         TIFF image format. Patching LZW support back into libtiff will allow the
57         creation of compressed TIFF images, and the compression makes a big
58         difference in the final file size.
59         
60 2. Legal Issues
61 ---------------
62         In some countries it may not be legal to use the LZW algorithm without
63         paying a license fee. To the best of my knowledge the patent expires in
64         June 2003 in the United States. However, I believe the patent does not
65         expire in Japan until June 2004. You are advised to follow your local
66         law with respect to using the LZW compression algorithm and any license
67         fees that you are required to pay to do so. You are also advised to
68         look up the patent expiration date yourself, rather than rely on the
69         information I provide. I am not a patent lawyer.
70         
71 3. Giflib as replacement for libungif
72 -------------------------------------
73         libungif was written as a replacement for Giflib. libungif does not use
74         LZW but instead produces uncompressed GIF images. If you would rather
75         produce compressed GIF images, then build Giflib instead of libungif.
76         
77         Giflib 4.1.0 can be downloaded from:
78         http://ftp.rge.com/pub/multimedia/libungif/giflib-4.1.0.tar.gz
79         
80         Follow the same build instructions for libungif in the BLFS book.
81         
82 3a. Makefile Issues
83 -------------------
84         Most configure scripts will find libgif in your library path and use
85         that if you don't have libungif install. This is not universally true.
86         Some packages, such as emacs, will specifically look for libungif.
87         
88         There are two ways to solve this issue. The first to make the following
89         symlinks in your /usr/lib directory:
90                 ln -s libgif.a libungif.a
91                 ln -s libgif.la libungif.la
92                 ln -s libgif.so libungif.so
93                 ln -s libgif.so.4 libungif.so.4
94                 ln -s libgif.so.4.1.0 libungif.so.4.1.0
96         The second method, which is a little cleaner IMHO, is to modify the
97         configure scripts and Makefiles of the source to the software before
98         building it. For example, with emacs, there are two files that need
99         to be edited: configure and src/Makefile.in
100         
101         In both files you just need to change every reference of lungif to lgif:
102         
103         cp configure configure.orig &&
104         sed -e s?"ungif"?"gif"? < configure.orig > configure &&
105         cd src &&
106         cp Makefile.in Makefile.in.orig &&
107         sed -e s?"ungif"?"gif"? < Makefile.in.orig > Makefile.in &&
108         cd ..
109         
110         Then you can proceed to build as normal and emacs will use libgif.
111         
112 4. libtiff
113 ----------
114         To put LZW compression back into libtiff, all you need to do is apply
115         the LZW Compression Kit to the source before building it.
116         You can download the kit from:
117         ftp://ftp.remotesensing.org/libtiff/libtiff-lzw-compression-kit-1.3.tar.gz
118         
119         The official instructions in the kit say:
120         "Just copy tif_lzw.c over the copy in libtiff and rebuild libtiff."
121         
122         In other words, unpack the libtiff source as you would while following
123         the BLFS instructions. Before you do anything else, also unpack the
124         libtiff-lzw-compression-kit and replace the tif_lzw.c file in the
125         libtiff source directory with the one in the compression kit.
126         
127         Then continue to build libtiff as described in the BLFS book.
128         
129 5. gd library
130 -------------
131         Most applications that offer gif support will use libgif or libungif.
132         However, some applications will look for gif support in the gd library
133         and use gd for gif support if it finds it.
134         
135         The author of the gd library no longer includes any gif support in his
136         library. However, we can patch gif support (with LZW compression) back
137         into gif so that software that wants to use gd for gif support can find
138         it.
139         
140         The gd library can be downloaded from:
141         http://www.boutell.com/gd/http/gd-2.0.12.tar.gz
142         
143         The patch to the gd library can be downloaded from:
144         http://downloads.rhyme.com.au/gd/patch_gd2.0.12_gif_20030401.gz
145         
146         to build:
147         patch -p1 < ../patch_gd2.0.12_gif_20030401 &&
148         ./configure --prefix=/usr &&
149         make &&
150         make install &&
151         /sbin/ldconfig
152         
153         It is best to build gd after building zlib, libpng, freetype2, libjpeg,
154         and XFree86 - as gd will use those libraries if configure finds them.
156         
157         
158