blob: 40350d04ab3374fb2d70c052a33ecbc802eaee69 [file] [log] [blame]
DRCe74b0862010-10-25 22:07:40 +00001*******************************************************************************
2** Background
3*******************************************************************************
4
5libjpeg-turbo is a high-speed version of libjpeg for x86 and x86-64 processors
6which uses SIMD instructions (MMX, SSE2, etc.) to accelerate baseline JPEG
7compression and decompression. libjpeg-turbo is generally 2-4x as fast
8as the unmodified version of libjpeg, all else being equal.
9
10libjpeg-turbo was originally based on libjpeg/SIMD by Miyasaka Masaru, but
11the TigerVNC and VirtualGL projects made numerous enhancements to the codec,
12including improved support for Mac OS X, 64-bit support, support for 32-bit
13and big endian pixel formats, accelerated Huffman encoding/decoding, and
14various bug fixes. The goal was to produce a fully open source codec that
15could replace the partially closed source TurboJPEG/IPP codec used by VirtualGL
16and TurboVNC. libjpeg-turbo generally performs in the range of 80-120% of
17TurboJPEG/IPP. It is faster in some areas but slower in others.
18
19It was decided to split libjpeg-turbo into a separate SDK so that other
20projects could take advantage of this technology. The libjpeg-turbo shared
21libraries can be used as drop-in replacements for libjpeg on most systems.
22
23
24*******************************************************************************
25** License
26*******************************************************************************
27
28Some of the optimizations to the Huffman encoder (jchuff.c) and decoder
29(jdhuff.c) were borrowed from VirtualGL, and thus any distribution of
30libjpeg-turbo which includes those optimizations must, as a whole, be subject
31to the terms of the wxWindows Library Licence, Version 3.1. A copy of this
32license can be found in this directory under LICENSE.txt. The wxWindows
33Library License is based on the LGPL but includes provisions which allow the
34Library to be statically linked into proprietary libraries and applications
35without requiring the resulting binaries to be distributed under the terms of
36the LGPL.
37
38The rest of the source code, apart from the Huffman codec optimizations, falls
39under a less restrictive, BSD-style license (see README.) You can choose to
40distribute libjpeg-turbo, as a whole, under this BSD-style license by simply
41replacing the optimized jchuff.c and jdhuff.c with their unoptimized
42counterparts from the libjpeg v6b source.
43
44
45*******************************************************************************
46** Using libjpeg-turbo
47*******************************************************************************
48
49=============================
50Replacing libjpeg at Run Time
51=============================
52
53If a Unix application is dynamically linked with libjpeg, then you can replace
54libjpeg with libjpeg-turbo at run time by manipulating the LD_LIBRARY_PATH.
55For instance:
56
57 [Using libjpeg]
58 > time cjpeg <vgl_5674_0098.ppm >vgl_5674_0098.jpg
59 real 0m0.392s
60 user 0m0.074s
61 sys 0m0.020s
62
63 [Using libjpeg-turbo]
64 > export LD_LIBRARY_PATH=/opt/libjpeg-turbo/{lib}:$LD_LIBRARY_PATH
65 > time cjpeg <vgl_5674_0098.ppm >vgl_5674_0098.jpg
66 real 0m0.109s
67 user 0m0.029s
68 sys 0m0.010s
69
70NOTE: {lib} can be lib, lib32, lib64, or lib/64, depending on the O/S and
71architecture.
72
73System administrators can also replace the libjpeg sym links in /usr/{lib} with
74links to the libjpeg dynamic library located in /opt/libjpeg-turbo/{lib}. This
75will effectively accelerate every dynamically linked libjpeg application on the
76system.
77
78The Windows distribution of the libjpeg-turbo SDK installs jpeg62.dll into
79c:\libjpeg-turbo\bin, and the PATH environment variable can be modified such
80that this directory is searched before any others that might contain
81jpeg62.dll. However, if jpeg62.dll also exists in an application's install
82directory, then Windows will load the application's version of it first. Thus,
83if an application ships with jpeg62.dll, then back up the application's version
84of jpeg62.dll and copy c:\libjpeg-turbo\bin\jpeg62.dll into the application's
85install directory to accelerate it.
86
87The version of jpeg62.dll distributed in the libjpeg-turbo SDK requires the
88Visual C++ 2008 C run time DLL (msvcr90.dll). This library ships with more
89recent versions of Windows, but users of older versions can obtain it from the
90Visual C++ 2008 Redistributable Package, which is available as a free download
91from Microsoft's web site.
92
93NOTE: Features of libjpeg which require passing a C run time structure, such
94as a file handle, from an application to libjpeg will probably not work with
95the distributed version of jpeg62.dll unless the application is also built to
96use the Visual C++ 2008 C run time DLL. In particular, this affects
97jpeg_stdio_dest() and jpeg_stdio_src().
98
99Mac applications typically embed their own copies of libjpeg.62.dylib inside
100the (hidden) application bundle, so it is not possible to globally replace
101libjpeg on OS X systems. If an application uses a shared library version of
102libjpeg, then it may be possible to replace the application's version of it.
103This would generally involve copying libjpeg.62.dylib into the appropriate
104place in the application bundle and using install_name_tool to repoint the
105dylib to the new directory. This requires an advanced knowledge of OS X and
106would not survive an upgrade or a re-install of the application. Thus, it is
107not recommended for most users.
108
109=======================
110Replacing TurboJPEG/IPP
111=======================
112
113libjpeg-turbo is a drop-in replacement for the TurboJPEG/IPP SDK used by
114VirtualGL 2.1.x and TurboVNC 0.6 (and prior.) libjpeg-turbo contains a wrapper
115library (TurboJPEG/OSS) that emulates the TurboJPEG API using libjpeg-turbo
116instead of the closed source Intel Performance Primitives. You can replace the
117TurboJPEG/IPP package on Linux systems with the libjpeg-turbo package in order
118to make existing releases of VirtualGL 2.1.x and TurboVNC use the new codec at
119run time. Note that the 64-bit libjpeg-turbo packages contain only 64-bit
120binaries, whereas the TurboJPEG/IPP 64-bit packages contained both 64-bit and
12132-bit binaries. Thus, to replace a TurboJPEG/IPP 64-bit package, install
122both the 64-bit and 32-bit versions of libjpeg-turbo.
123
124You can also build the VirtualGL 2.1.x and TurboVNC 0.6 source code with
125the libjpeg-turbo SDK instead of TurboJPEG/IPP. It should work identically.
126libjpeg-turbo also includes static library versions of TurboJPEG/OSS, which
127are used to build TurboVNC 1.0 and later.
128
129========================================
130Using libjpeg-turbo in Your Own Programs
131========================================
132
133For the most part, libjpeg-turbo should work identically to libjpeg, so in
134most cases, an application can be built against libjpeg and then run against
135libjpeg-turbo. On Unix systems, you can build against libjpeg-turbo instead
136of libjpeg by setting
137
138 CPATH=/opt/libjpeg-turbo/include
139 and
140 LIBRARY_PATH=/opt/libjpeg-turbo/{lib}
141
142({lib} = lib32 or lib64, depending on whether you are building a 32-bit or a
14364-bit application.)
144
145If using Cygwin, then set
146
147 CPATH=/cygdrive/c/libjpeg-turbo-gcc[64]/include
148 and
149 LIBRARY_PATH=/cygdrive/c/libjpeg-turbo-gcc[64]/lib
150
151If using MinGW, then set
152
153 CPATH=/c/libjpeg-turbo-gcc[64]/include
154 and
155 LIBRARY_PATH=/c/libjpeg-turbo-gcc[64]/lib
156
157Building against libjpeg-turbo is useful, for instance, if you want to build an
158application that leverages the libjpeg-turbo colorspace extensions (see below.)
159On Linux and Solaris systems, you would still need to manipulate the
160LD_LIBRARY_PATH or sym links appropriately to use libjpeg-turbo at run time.
161On such systems, you can pass -R /opt/libjpeg-turbo/{lib} to the linker to
162force the use of libjpeg-turbo at run time rather than libjpeg (also useful if
163you want to leverage the colorspace extensions), or you can link against the
164libjpeg-turbo static library.
165
166To force a Linux, Solaris, or MinGW application to link against the static
167version of libjpeg-turbo, you can use the following linker options:
168
169 -Wl,-Bstatic -ljpeg -Wl,-Bdynamic
170
171On OS X, simply add /opt/libjpeg-turbo/lib/libjpeg.a to the linker command
172line (this also works on Linux and Solaris.)
173
174To build Visual C++ applications using libjpeg-turbo, add
175c:\libjpeg-turbo[64]\include to your system or user INCLUDE environment
176variable and c:\libjpeg-turbo[64]\lib to your system or user LIB environment
177variable, and then link against either jpeg.lib (to use jpeg62.dll) or
178jpeg-static.lib (to use the static version of libjpeg-turbo.)
179
180=====================
181Colorspace Extensions
182=====================
183
184libjpeg-turbo includes extensions which allow JPEG images to be compressed
185directly from (and decompressed directly to) buffers which use BGR, BGRA,
186RGBA, ABGR, and ARGB pixel ordering. This is implemented with six new
187colorspace constants:
188
189 JCS_EXT_RGB /* red/green/blue */
190 JCS_EXT_RGBX /* red/green/blue/x */
191 JCS_EXT_BGR /* blue/green/red */
192 JCS_EXT_BGRX /* blue/green/red/x */
193 JCS_EXT_XBGR /* x/blue/green/red */
194 JCS_EXT_XRGB /* x/red/green/blue */
195
196Setting cinfo.in_color_space (compression) or cinfo.out_color_space
197(decompression) to one of these values will cause libjpeg-turbo to read the
198red, green, and blue values from (or write them to) the appropriate position in
199the pixel when YUV conversion is performed.
200
201Your application can check for the existence of these extensions at compile
202time with:
203
204 #ifdef JCS_EXTENSIONS
205
206At run time, attempting to use these extensions with a version of libjpeg
207that doesn't support them will result in a "Bogus input colorspace" error.