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