blob: f60454ce41833265cd4254255858f30c590868e9 [file] [log] [blame]
DRC101f09a2010-02-12 22:52:37 +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
DRCce1546e2010-02-13 23:06:03 +00007compression and decompression. libjpeg-turbo is generally 2-4x as fast
DRC101f09a2010-02-12 22:52:37 +00008as 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
DRCce1546e2010-02-13 23:06:03 +000016and TurboVNC. libjpeg-turbo generally performs in the range of 80-120% of
DRC101f09a2010-02-12 22:52:37 +000017TurboJPEG/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
DRC68fef832010-02-16 05:29:10 +000020projects could take advantage of this technology. The libjpeg-turbo shared
21libraries can be used as drop-in replacements for libjpeg on most systems.
DRC101f09a2010-02-12 22:52:37 +000022
23
24*******************************************************************************
DRCce1546e2010-02-13 23:06:03 +000025** License
26*******************************************************************************
27
28Some of the optimizations to the Huffman encoder/decoder were borrowed from
DRC68fef832010-02-16 05:29:10 +000029VirtualGL, and thus the libjpeg-turbo distribution, as a whole, falls under the
30wxWindows Library Licence, Version 3.1. A copy of this license can be found in
31this directory under LICENSE.txt. The rest of the source code, apart from
32these modifications, falls under a less restrictive license (see README.)
DRCce1546e2010-02-13 23:06:03 +000033
34
35*******************************************************************************
DRC68fef832010-02-16 05:29:10 +000036** Using libjpeg-turbo
DRC101f09a2010-02-12 22:52:37 +000037*******************************************************************************
38
DRC68fef832010-02-16 05:29:10 +000039=============================
40Replacing libjpeg at Run Time
41=============================
DRC101f09a2010-02-12 22:52:37 +000042
DRC68fef832010-02-16 05:29:10 +000043If a Unix application is dynamically linked with libjpeg, then you can replace
44libjpeg with libjpeg-turbo at run time by manipulating the LD_LIBRARY_PATH.
45For instance:
DRC101f09a2010-02-12 22:52:37 +000046
DRC68fef832010-02-16 05:29:10 +000047 [Using libjpeg]
48 > time cjpeg <vgl_5674_0098.ppm >vgl_5674_0098.jpg
49 real 0m0.392s
50 user 0m0.074s
51 sys 0m0.020s
DRC101f09a2010-02-12 22:52:37 +000052
DRC68fef832010-02-16 05:29:10 +000053 [Using libjpeg-turbo]
54 > export LD_LIBRARY_PATH=/opt/libjpeg-turbo/{lib}:$LD_LIBRARY_PATH
55 > time cjpeg <vgl_5674_0098.ppm >vgl_5674_0098.jpg
56 real 0m0.109s
57 user 0m0.029s
58 sys 0m0.010s
DRC101f09a2010-02-12 22:52:37 +000059
DRC68fef832010-02-16 05:29:10 +000060NOTE: {lib} can be lib, lib32, lib64, or lib/amd64, depending on the O/S and
61architecture.
DRC101f09a2010-02-12 22:52:37 +000062
DRC68fef832010-02-16 05:29:10 +000063System administrators can also replace the libjpeg sym links in /usr/{lib} with
64links to the libjpeg dynamic library located in /opt/libjpeg-turbo/{lib}. This
65will effectively accelerate every dynamically linked libjpeg application on the
66system.
DRC101f09a2010-02-12 22:52:37 +000067
DRC0248dd92010-02-25 06:21:12 +000068The Windows distribution of the libjpeg-turbo SDK installs jpeg62.dll into
DRC7e0b4992010-02-25 05:52:44 +000069c:\libjpeg-turbo\bin, and the PATH environment variable can be modified such
70that this directory is searched before any others that might contain
71jpeg62.dll. However, if jpeg62.dll also exists in an application's install
72directory, then Windows will load the application's version of it first. Thus,
73if an application ships with jpeg62.dll, then back up the application's version
74of jpeg62.dll and copy c:\libjpeg-turbo\bin\jpeg62.dll into the application's
75install directory to accelerate it.
76
DRC0248dd92010-02-25 06:21:12 +000077The version of jpeg62.dll distributed in the libjpeg-turbo SDK requires the
78Visual C++ 2008 C run time DLL (msvcr90.dll). This library ships with more
79recent versions of Windows, but users of older versions can obtain it from the
80Visual C++ 2008 Redistributable Package, which is available as a free download
81from Microsoft's web site.
82
83NOTE: Features of libjpeg which require passing a C run time structure, such
84as a file handle, from an application to libjpeg will probably not work with
85the distributed version of jpeg62.dll unless the application is also built to
86use the Visual C++ 2008 C run time DLL. In particular, this affects
87jpeg_stdio_dest() and jpeg_stdio_src().
DRC101f09a2010-02-12 22:52:37 +000088
DRC68fef832010-02-16 05:29:10 +000089Mac applications typically embed their own copies of libjpeg.62.dylib inside
90the (hidden) application bundle, so it is not possible to globally replace
91libjpeg on OS X systems. If an application uses a shared library version of
92libjpeg, then it may be possible to replace the application's version of it.
93This would generally involve copying libjpeg.62.dylib into the appropriate
94place in the application bundle and using install_name_tool to repoint the
95dylib to the new directory. This requires an advanced knowledge of OS X and
96would not survive an upgrade or a re-install of the application. Thus, it is
97not recommended for most users.
DRC101f09a2010-02-12 22:52:37 +000098
DRC68fef832010-02-16 05:29:10 +000099=======================
100Replacing TurboJPEG/IPP
101=======================
DRC101f09a2010-02-12 22:52:37 +0000102
DRC68fef832010-02-16 05:29:10 +0000103libjpeg-turbo is a drop-in replacement for the TurboJPEG/IPP SDK used by
104VirtualGL 2.1.x (and prior) and TurboVNC. libjpeg-turbo contains a wrapper
105library (TurboJPEG/OSS) that emulates the TurboJPEG API using libjpeg-turbo
106instead of the closed source Intel Performance Primitives. You can replace the
107TurboJPEG/IPP package on Linux systems with the libjpeg-turbo package in order
108to make existing releases of VirtualGL 2.1.x and TurboVNC use the new codec at
109run time. Note that the 64-bit libjpeg-turbo packages contain only 64-bit
110binaries, whereas the TurboJPEG/IPP 64-bit packages contain both 64-bit and
11132-bit binaries. Thus, to replace a TurboJPEG/IPP 64-bit package, install
112both the 64-bit and 32-bit versions of libjpeg-turbo.
DRC101f09a2010-02-12 22:52:37 +0000113
DRC68fef832010-02-16 05:29:10 +0000114You can also build the VirtualGL 2.1.x and TurboVNC source code with
115the libjpeg-turbo SDK instead of TurboJPEG/IPP. It should work identically.
116libjpeg-turbo also includes static library versions of TurboJPEG/OSS, which
117are used to build VirtualGL 2.2 and later.
DRC101f09a2010-02-12 22:52:37 +0000118
DRC68fef832010-02-16 05:29:10 +0000119========================================
120Using libjpeg-turbo in Your Own Programs
121========================================
DRC101f09a2010-02-12 22:52:37 +0000122
DRC68fef832010-02-16 05:29:10 +0000123For the most part, libjpeg-turbo should work identically to libjpeg, so in
124most cases, an application can be built against libjpeg and then run against
125libjpeg-turbo. On Unix systems, you can build against libjpeg-turbo instead
126of libjpeg by setting
DRC101f09a2010-02-12 22:52:37 +0000127
DRC68fef832010-02-16 05:29:10 +0000128 CPATH=/opt/libjpeg-turbo/include
129 and
130 LIBRARY_PATH=/opt/libjpeg-turbo/{lib}
DRC101f09a2010-02-12 22:52:37 +0000131
DRC68fef832010-02-16 05:29:10 +0000132({lib} = lib, lib32, lib64, or lib/amd64, as appropriate.)
DRC101f09a2010-02-12 22:52:37 +0000133
DRC0a1f68e2010-02-24 07:24:26 +0000134If using Cygwin, then set
DRC101f09a2010-02-12 22:52:37 +0000135
DRC0a1f68e2010-02-24 07:24:26 +0000136 CPATH=/cygdrive/c/libjpeg-turbo-gcc/include
137 and
138 LIBRARY_PATH=/cygdrive/c/libjpeg-turbo-gcc/lib
139
140If using MinGW, then set
141
142 CPATH=/c/libjpeg-turbo-gcc/include
143 and
144 LIBRARY_PATH=/c/libjpeg-turbo-gcc/lib
145
146Building against libjpeg-turbo is useful, for instance, if you want to build an
147application that leverages the libjpeg-turbo colorspace extensions (see below.)
148On Linux and Solaris systems, you would still need to manipulate the
149LD_LIBRARY_PATH or sym links appropriately to use libjpeg-turbo at run time.
150On such systems, you can pass -R /opt/libjpeg-turbo/{lib} to the linker to
151force the use of libjpeg-turbo at run time rather than libjpeg (also useful if
152you want to leverage the colorspace extensions), or you can link against the
153libjpeg-turbo static library.
154
155To force a Linux, Solaris, or MinGW application to link against the static
156version of libjpeg-turbo, you can use the following linker options:
DRC101f09a2010-02-12 22:52:37 +0000157
DRC68fef832010-02-16 05:29:10 +0000158 -Wl,-Bstatic -ljpeg -Wl,-Bdynamic
DRC101f09a2010-02-12 22:52:37 +0000159
DRC0a1f68e2010-02-24 07:24:26 +0000160On OS X, simply add /opt/libjpeg-turbo/{lib}/libjpeg.a to the linker command
161line (this also works on Linux and Solaris.)
DRC101f09a2010-02-12 22:52:37 +0000162
DRC68fef832010-02-16 05:29:10 +0000163To build Visual C++ applications using libjpeg-turbo, add
164c:\libjpeg-turbo\include to your system or user INCLUDE environment variable
165and c:\libjpeg-turbo\lib to your system or user LIB environment variable, and
166then link against either jpeg.lib (to use jpeg62.dll) or jpeg-static.lib (to
167use the static version of libjpeg-turbo.)
DRC101f09a2010-02-12 22:52:37 +0000168
DRC68fef832010-02-16 05:29:10 +0000169=====================
170Colorspace Extensions
171=====================
DRC101f09a2010-02-12 22:52:37 +0000172
DRC68fef832010-02-16 05:29:10 +0000173libjpeg-turbo includes extensions which allow JPEG images to be compressed
174directly from (and decompressed directly to) buffers which use BGR, BGRA,
175RGBA, ABGR, and ARGB pixel ordering. This is implemented with six new
176colorspace constants:
DRC101f09a2010-02-12 22:52:37 +0000177
DRC68fef832010-02-16 05:29:10 +0000178 JCS_EXT_RGB /* red/green/blue */
179 JCS_EXT_RGBX /* red/green/blue/x */
180 JCS_EXT_BGR /* blue/green/red */
181 JCS_EXT_BGRX /* blue/green/red/x */
182 JCS_EXT_XBGR /* x/blue/green/red */
183 JCS_EXT_XRGB /* x/red/green/blue */
DRC101f09a2010-02-12 22:52:37 +0000184
DRC68fef832010-02-16 05:29:10 +0000185Setting cinfo.in_color_space (compression) or cinfo.out_color_space
186(decompression) to one of these values will cause libjpeg-turbo to read the
187red, green, and blue values from (or write them to) the appropriate position in
188the pixel when YUV conversion is performed.
DRC101f09a2010-02-12 22:52:37 +0000189
DRC68fef832010-02-16 05:29:10 +0000190Your application can check for the existence of these extensions at compile
191time with:
DRC101f09a2010-02-12 22:52:37 +0000192
DRC68fef832010-02-16 05:29:10 +0000193 #ifdef JCS_EXTENSIONS
DRC101f09a2010-02-12 22:52:37 +0000194
DRC68fef832010-02-16 05:29:10 +0000195At run time, attempting to use these extensions with a version of libjpeg
196that doesn't support them will result in a "Bogus input colorspace" error.