blob: b6789f37a1f941e2452d85b138d258f899a3f747 [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
DRCae7fe0b2010-08-11 21:46:46 +000028Some 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.
DRC1e6b5b42010-03-20 20:00:51 +000037
DRCae7fe0b2010-08-11 21:46:46 +000038The 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.
DRCce1546e2010-02-13 23:06:03 +000043
44
45*******************************************************************************
DRC68fef832010-02-16 05:29:10 +000046** Using libjpeg-turbo
DRC101f09a2010-02-12 22:52:37 +000047*******************************************************************************
48
DRC68fef832010-02-16 05:29:10 +000049=============================
50Replacing libjpeg at Run Time
51=============================
DRC101f09a2010-02-12 22:52:37 +000052
DRC68fef832010-02-16 05:29:10 +000053If 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:
DRC101f09a2010-02-12 22:52:37 +000056
DRC68fef832010-02-16 05:29:10 +000057 [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
DRC101f09a2010-02-12 22:52:37 +000062
DRC68fef832010-02-16 05:29:10 +000063 [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
DRC101f09a2010-02-12 22:52:37 +000069
DRCff95aa62010-06-05 00:22:32 +000070NOTE: {lib} can be lib, lib32, lib64, or lib/64, depending on the O/S and
DRC68fef832010-02-16 05:29:10 +000071architecture.
DRC101f09a2010-02-12 22:52:37 +000072
DRC68fef832010-02-16 05:29:10 +000073System 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.
DRC101f09a2010-02-12 22:52:37 +000077
DRC5559c902010-10-18 02:21:10 +000078The Windows distribution of the libjpeg-turbo SDK installs the libjpeg-turbo
79DLL (jpeg62.dll, jpeg7.dll, or jpeg8.dll, depending on whether libjpeg v6b,
80v7, or v8 emulation is enabled) into c:\libjpeg-turbo[64]\bin, and the PATH
81environment variable can be modified such that this directory is searched
82before any others that might contain a libjpeg DLL. However, if a libjpeg
83DLL exists in an application's install directory, then Windows will load this
84DLL first whenever the application is launched. Thus, if an application ships
85with jpeg62.dll, jpeg7.dll, or jpeg8.dll, then back up the application's
86version of this DLL and copy c:\libjpeg-turbo\bin\jpeg*.dll into the
87application's install directory to accelerate it.
DRC7e0b4992010-02-25 05:52:44 +000088
DRC5559c902010-10-18 02:21:10 +000089The version of the libjpeg-turbo DLL distributed with the "official"
90libjpeg-turbo SDK requires the Visual C++ 2008 C run time DLL (msvcr90.dll).
91msvcr90.dll ships with more recent versions of Windows, but users of older
92Windows releases can obtain it from the Visual C++ 2008 Redistributable
93Package, which is available as a free download from Microsoft's web site.
DRC0248dd92010-02-25 06:21:12 +000094
95NOTE: Features of libjpeg which require passing a C run time structure, such
96as a file handle, from an application to libjpeg will probably not work with
DRC5559c902010-10-18 02:21:10 +000097the "official" version of the libjpeg-turbo DLL unless the application is also
98built to use the Visual C++ 2008 C run time DLL. In particular, this affects
DRC0248dd92010-02-25 06:21:12 +000099jpeg_stdio_dest() and jpeg_stdio_src().
DRC101f09a2010-02-12 22:52:37 +0000100
DRC5559c902010-10-18 02:21:10 +0000101Mac applications typically embed their own copies of the libjpeg dylib inside
DRC68fef832010-02-16 05:29:10 +0000102the (hidden) application bundle, so it is not possible to globally replace
103libjpeg on OS X systems. If an application uses a shared library version of
104libjpeg, then it may be possible to replace the application's version of it.
DRC5559c902010-10-18 02:21:10 +0000105This would generally involve copying libjpeg.*.dylib from libjpeg-turbo into
106the appropriate place in the application bundle and using install_name_tool to
107repoint the dylib to the new directory. This requires an advanced knowledge of
108OS X and would not survive an upgrade or a re-install of the application.
109Thus, it is not recommended for most users.
DRC101f09a2010-02-12 22:52:37 +0000110
DRC68fef832010-02-16 05:29:10 +0000111=======================
112Replacing TurboJPEG/IPP
113=======================
DRC101f09a2010-02-12 22:52:37 +0000114
DRC68fef832010-02-16 05:29:10 +0000115libjpeg-turbo is a drop-in replacement for the TurboJPEG/IPP SDK used by
DRCff95aa62010-06-05 00:22:32 +0000116VirtualGL 2.1.x and TurboVNC 0.6 (and prior.) libjpeg-turbo contains a wrapper
DRC68fef832010-02-16 05:29:10 +0000117library (TurboJPEG/OSS) that emulates the TurboJPEG API using libjpeg-turbo
118instead of the closed source Intel Performance Primitives. You can replace the
119TurboJPEG/IPP package on Linux systems with the libjpeg-turbo package in order
120to make existing releases of VirtualGL 2.1.x and TurboVNC use the new codec at
121run time. Note that the 64-bit libjpeg-turbo packages contain only 64-bit
DRCff95aa62010-06-05 00:22:32 +0000122binaries, whereas the TurboJPEG/IPP 64-bit packages contained both 64-bit and
DRC68fef832010-02-16 05:29:10 +000012332-bit binaries. Thus, to replace a TurboJPEG/IPP 64-bit package, install
124both the 64-bit and 32-bit versions of libjpeg-turbo.
DRC101f09a2010-02-12 22:52:37 +0000125
DRCff95aa62010-06-05 00:22:32 +0000126You can also build the VirtualGL 2.1.x and TurboVNC 0.6 source code with
DRC68fef832010-02-16 05:29:10 +0000127the libjpeg-turbo SDK instead of TurboJPEG/IPP. It should work identically.
128libjpeg-turbo also includes static library versions of TurboJPEG/OSS, which
DRCff95aa62010-06-05 00:22:32 +0000129are used to build TurboVNC 1.0 and later.
DRC101f09a2010-02-12 22:52:37 +0000130
DRC68fef832010-02-16 05:29:10 +0000131========================================
132Using libjpeg-turbo in Your Own Programs
133========================================
DRC101f09a2010-02-12 22:52:37 +0000134
DRC68fef832010-02-16 05:29:10 +0000135For the most part, libjpeg-turbo should work identically to libjpeg, so in
136most cases, an application can be built against libjpeg and then run against
DRC5559c902010-10-18 02:21:10 +0000137libjpeg-turbo. On Unix systems (including Cygwin), you can build against
138libjpeg-turbo instead of libjpeg by setting
DRC101f09a2010-02-12 22:52:37 +0000139
DRC68fef832010-02-16 05:29:10 +0000140 CPATH=/opt/libjpeg-turbo/include
141 and
142 LIBRARY_PATH=/opt/libjpeg-turbo/{lib}
DRC101f09a2010-02-12 22:52:37 +0000143
DRCff95aa62010-06-05 00:22:32 +0000144({lib} = lib32 or lib64, depending on whether you are building a 32-bit or a
14564-bit application.)
DRC101f09a2010-02-12 22:52:37 +0000146
DRC0a1f68e2010-02-24 07:24:26 +0000147If using MinGW, then set
148
DRC3dc1bc22010-05-10 22:18:10 +0000149 CPATH=/c/libjpeg-turbo-gcc[64]/include
DRC0a1f68e2010-02-24 07:24:26 +0000150 and
DRC3dc1bc22010-05-10 22:18:10 +0000151 LIBRARY_PATH=/c/libjpeg-turbo-gcc[64]/lib
DRC0a1f68e2010-02-24 07:24:26 +0000152
153Building against libjpeg-turbo is useful, for instance, if you want to build an
154application that leverages the libjpeg-turbo colorspace extensions (see below.)
155On Linux and Solaris systems, you would still need to manipulate the
156LD_LIBRARY_PATH or sym links appropriately to use libjpeg-turbo at run time.
157On such systems, you can pass -R /opt/libjpeg-turbo/{lib} to the linker to
158force the use of libjpeg-turbo at run time rather than libjpeg (also useful if
159you want to leverage the colorspace extensions), or you can link against the
160libjpeg-turbo static library.
161
162To force a Linux, Solaris, or MinGW application to link against the static
163version of libjpeg-turbo, you can use the following linker options:
DRC101f09a2010-02-12 22:52:37 +0000164
DRC68fef832010-02-16 05:29:10 +0000165 -Wl,-Bstatic -ljpeg -Wl,-Bdynamic
DRC101f09a2010-02-12 22:52:37 +0000166
DRCff95aa62010-06-05 00:22:32 +0000167On OS X, simply add /opt/libjpeg-turbo/lib/libjpeg.a to the linker command
DRC0a1f68e2010-02-24 07:24:26 +0000168line (this also works on Linux and Solaris.)
DRC101f09a2010-02-12 22:52:37 +0000169
DRC68fef832010-02-16 05:29:10 +0000170To build Visual C++ applications using libjpeg-turbo, add
DRC3dc1bc22010-05-10 22:18:10 +0000171c:\libjpeg-turbo[64]\include to your system or user INCLUDE environment
172variable and c:\libjpeg-turbo[64]\lib to your system or user LIB environment
DRC5559c902010-10-18 02:21:10 +0000173variable, and then link against either jpeg.lib (to use the DLL version of
174libjpeg-turbo) or jpeg-static.lib (to use the static version of libjpeg-turbo.)
DRC101f09a2010-02-12 22:52:37 +0000175
DRC68fef832010-02-16 05:29:10 +0000176=====================
177Colorspace Extensions
178=====================
DRC101f09a2010-02-12 22:52:37 +0000179
DRC68fef832010-02-16 05:29:10 +0000180libjpeg-turbo includes extensions which allow JPEG images to be compressed
DRC646e5a82010-11-18 19:55:29 +0000181directly from (and decompressed directly to) buffers which use BGR, BGRX,
182RGBX, XBGR, and XRGB pixel ordering. This is implemented with six new
DRC68fef832010-02-16 05:29:10 +0000183colorspace constants:
DRC101f09a2010-02-12 22:52:37 +0000184
DRC68fef832010-02-16 05:29:10 +0000185 JCS_EXT_RGB /* red/green/blue */
186 JCS_EXT_RGBX /* red/green/blue/x */
187 JCS_EXT_BGR /* blue/green/red */
188 JCS_EXT_BGRX /* blue/green/red/x */
189 JCS_EXT_XBGR /* x/blue/green/red */
190 JCS_EXT_XRGB /* x/red/green/blue */
DRC101f09a2010-02-12 22:52:37 +0000191
DRC68fef832010-02-16 05:29:10 +0000192Setting cinfo.in_color_space (compression) or cinfo.out_color_space
193(decompression) to one of these values will cause libjpeg-turbo to read the
194red, green, and blue values from (or write them to) the appropriate position in
195the pixel when YUV conversion is performed.
DRC101f09a2010-02-12 22:52:37 +0000196
DRC68fef832010-02-16 05:29:10 +0000197Your application can check for the existence of these extensions at compile
198time with:
DRC101f09a2010-02-12 22:52:37 +0000199
DRC68fef832010-02-16 05:29:10 +0000200 #ifdef JCS_EXTENSIONS
DRC101f09a2010-02-12 22:52:37 +0000201
DRC68fef832010-02-16 05:29:10 +0000202At run time, attempting to use these extensions with a version of libjpeg
203that doesn't support them will result in a "Bogus input colorspace" error.
DRC77e39642010-10-12 03:02:31 +0000204
205=================================
206libjpeg v7 and v8 API/ABI support
207=================================
208
209libjpeg v7 and v8 added new features to the API/ABI, and, unfortunately, the
210compression and decompression structures were extended in a backward-
211incompatible manner to accommodate these features. Thus, programs which are
212built to use libjpeg v7 or v8 did not work with libjpeg-turbo, since it is
213based on the libjpeg v6b code base. Although libjpeg v7 and v8 are still not
214as widely used as v6b, enough programs (including a few Linux distros) have
215made the switch that it was desirable to provide support for the libjpeg v7/v8
216API/ABI in libjpeg-turbo.
217
218Some of the libjpeg v7 and v8 features -- DCT scaling, to name one -- involve
219deep modifications to the code which cannot be accommodated by libjpeg-turbo
220without either breaking compatibility with libjpeg v6b or producing an
221unsupportable mess. In order to fully support libjpeg v8 with all of its
222features, we would have to essentially port the SIMD extensions to the libjpeg
223v8 code base and maintain two separate code trees. We are hesitant to do this
224until/unless the newer libjpeg code bases garner more community support and
225involvement and until/unless we have some notion of whether future libjpeg
226releases will also be backward-incompatible.
227
DRC5559c902010-10-18 02:21:10 +0000228By passing an argument of --with-jpeg7 or --with-jpeg8 to configure, or an
229argument of -DWITH_JPEG7=1 or -DWITH_JPEG8=1 to cmake, you can build a version
230of libjpeg-turbo which emulates the libjpeg v7 or v8b API/ABI, so that programs
231which are built against libjpeg v7 or v8 can be run with libjpeg-turbo. The
232following section describes which libjpeg v7+ features are supported and which
233aren't.
DRC77e39642010-10-12 03:02:31 +0000234
235libjpeg v7 and v8 Features:
236---------------------------
237
238Fully supported:
239
240-- cjpeg: Separate quality settings for luminance and chrominance
241 Note that the libpjeg v7+ API was extended to accommodate this feature only
242 for convenience purposes. It has always been possible to implement this
243 feature with libjpeg v6b (see rdswitch.c for an example.)
244
245-- cjpeg: 32-bit BMP support
246
247-- jpegtran: lossless cropping
248
249-- jpegtran: -perfect option
250
251-- rdjpgcom: -raw option
252
253-- rdjpgcom: locale awareness
254
255
256Fully supported when using libjpeg v7/v8 emulation:
257
258-- libjpeg: In-memory source and destination managers
259
260
261Not supported:
262
263-- libjpeg: DCT scaling in compressor
264 cinfo.scale_num and cinfo.scale_denom are silently ignored.
265
266-- libjpeg: IDCT scaling extensions in decompressor
267 libjpeg-turbo still supports IDCT scaling with scaling factors of 1/2, 1/4,
268 and 1/8 (same as libjpeg v6b.)
269
270-- libjpeg: Fancy downsampling in compressor
271 cinfo.do_fancy_downsampling is silently ignored.
272
273-- libjpeg: Arithmetic coding/decoding
274 Not supported due to patent concerns.
275
276-- jpegtran: Scaling
277 Seems to depend on the DCT scaling feature, which isn't supported.