DRC | e74b086 | 2010-10-25 22:07:40 +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 |
| 7 | compression and decompression. libjpeg-turbo is generally 2-4x as fast |
| 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 |
| 16 | and TurboVNC. libjpeg-turbo generally performs in the range of 80-120% of |
| 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 |
| 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. |
| 22 | |
| 23 | |
| 24 | ******************************************************************************* |
| 25 | ** License |
| 26 | ******************************************************************************* |
| 27 | |
| 28 | Some of the optimizations to the Huffman encoder (jchuff.c) and decoder |
| 29 | (jdhuff.c) were borrowed from VirtualGL, and thus any distribution of |
| 30 | libjpeg-turbo which includes those optimizations must, as a whole, be subject |
| 31 | to the terms of the wxWindows Library Licence, Version 3.1. A copy of this |
| 32 | license can be found in this directory under LICENSE.txt. The wxWindows |
| 33 | Library License is based on the LGPL but includes provisions which allow the |
| 34 | Library to be statically linked into proprietary libraries and applications |
| 35 | without requiring the resulting binaries to be distributed under the terms of |
| 36 | the LGPL. |
| 37 | |
| 38 | The rest of the source code, apart from the Huffman codec optimizations, falls |
| 39 | under a less restrictive, BSD-style license (see README.) You can choose to |
| 40 | distribute libjpeg-turbo, as a whole, under this BSD-style license by simply |
| 41 | replacing the optimized jchuff.c and jdhuff.c with their unoptimized |
| 42 | counterparts from the libjpeg v6b source. |
| 43 | |
| 44 | |
| 45 | ******************************************************************************* |
| 46 | ** Using libjpeg-turbo |
| 47 | ******************************************************************************* |
| 48 | |
| 49 | ============================= |
| 50 | Replacing libjpeg at Run Time |
| 51 | ============================= |
| 52 | |
| 53 | If a Unix application is dynamically linked with libjpeg, then you can replace |
| 54 | libjpeg with libjpeg-turbo at run time by manipulating the LD_LIBRARY_PATH. |
| 55 | For 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 | |
| 70 | NOTE: {lib} can be lib, lib32, lib64, or lib/64, depending on the O/S and |
| 71 | architecture. |
| 72 | |
| 73 | System administrators can also replace the libjpeg sym links in /usr/{lib} with |
| 74 | links to the libjpeg dynamic library located in /opt/libjpeg-turbo/{lib}. This |
| 75 | will effectively accelerate every dynamically linked libjpeg application on the |
| 76 | system. |
| 77 | |
| 78 | The Windows distribution of the libjpeg-turbo SDK installs jpeg62.dll into |
| 79 | c:\libjpeg-turbo\bin, and the PATH environment variable can be modified such |
| 80 | that this directory is searched before any others that might contain |
| 81 | jpeg62.dll. However, if jpeg62.dll also exists in an application's install |
| 82 | directory, then Windows will load the application's version of it first. Thus, |
| 83 | if an application ships with jpeg62.dll, then back up the application's version |
| 84 | of jpeg62.dll and copy c:\libjpeg-turbo\bin\jpeg62.dll into the application's |
| 85 | install directory to accelerate it. |
| 86 | |
| 87 | The version of jpeg62.dll distributed in the libjpeg-turbo SDK requires the |
| 88 | Visual C++ 2008 C run time DLL (msvcr90.dll). This library ships with more |
| 89 | recent versions of Windows, but users of older versions can obtain it from the |
| 90 | Visual C++ 2008 Redistributable Package, which is available as a free download |
| 91 | from Microsoft's web site. |
| 92 | |
| 93 | NOTE: Features of libjpeg which require passing a C run time structure, such |
| 94 | as a file handle, from an application to libjpeg will probably not work with |
| 95 | the distributed version of jpeg62.dll unless the application is also built to |
| 96 | use the Visual C++ 2008 C run time DLL. In particular, this affects |
| 97 | jpeg_stdio_dest() and jpeg_stdio_src(). |
| 98 | |
| 99 | Mac applications typically embed their own copies of libjpeg.62.dylib inside |
| 100 | the (hidden) application bundle, so it is not possible to globally replace |
| 101 | libjpeg on OS X systems. If an application uses a shared library version of |
| 102 | libjpeg, then it may be possible to replace the application's version of it. |
| 103 | This would generally involve copying libjpeg.62.dylib into the appropriate |
| 104 | place in the application bundle and using install_name_tool to repoint the |
| 105 | dylib to the new directory. This requires an advanced knowledge of OS X and |
| 106 | would not survive an upgrade or a re-install of the application. Thus, it is |
| 107 | not recommended for most users. |
| 108 | |
| 109 | ======================= |
| 110 | Replacing TurboJPEG/IPP |
| 111 | ======================= |
| 112 | |
| 113 | libjpeg-turbo is a drop-in replacement for the TurboJPEG/IPP SDK used by |
| 114 | VirtualGL 2.1.x and TurboVNC 0.6 (and prior.) libjpeg-turbo contains a wrapper |
| 115 | library (TurboJPEG/OSS) that emulates the TurboJPEG API using libjpeg-turbo |
| 116 | instead of the closed source Intel Performance Primitives. You can replace the |
| 117 | TurboJPEG/IPP package on Linux systems with the libjpeg-turbo package in order |
| 118 | to make existing releases of VirtualGL 2.1.x and TurboVNC use the new codec at |
| 119 | run time. Note that the 64-bit libjpeg-turbo packages contain only 64-bit |
| 120 | binaries, whereas the TurboJPEG/IPP 64-bit packages contained both 64-bit and |
| 121 | 32-bit binaries. Thus, to replace a TurboJPEG/IPP 64-bit package, install |
| 122 | both the 64-bit and 32-bit versions of libjpeg-turbo. |
| 123 | |
| 124 | You can also build the VirtualGL 2.1.x and TurboVNC 0.6 source code with |
| 125 | the libjpeg-turbo SDK instead of TurboJPEG/IPP. It should work identically. |
| 126 | libjpeg-turbo also includes static library versions of TurboJPEG/OSS, which |
| 127 | are used to build TurboVNC 1.0 and later. |
| 128 | |
| 129 | ======================================== |
| 130 | Using libjpeg-turbo in Your Own Programs |
| 131 | ======================================== |
| 132 | |
| 133 | For the most part, libjpeg-turbo should work identically to libjpeg, so in |
| 134 | most cases, an application can be built against libjpeg and then run against |
| 135 | libjpeg-turbo. On Unix systems, you can build against libjpeg-turbo instead |
| 136 | of 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 |
| 143 | 64-bit application.) |
| 144 | |
| 145 | If 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 | |
| 151 | If 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 | |
| 157 | Building against libjpeg-turbo is useful, for instance, if you want to build an |
| 158 | application that leverages the libjpeg-turbo colorspace extensions (see below.) |
| 159 | On Linux and Solaris systems, you would still need to manipulate the |
| 160 | LD_LIBRARY_PATH or sym links appropriately to use libjpeg-turbo at run time. |
| 161 | On such systems, you can pass -R /opt/libjpeg-turbo/{lib} to the linker to |
| 162 | force the use of libjpeg-turbo at run time rather than libjpeg (also useful if |
| 163 | you want to leverage the colorspace extensions), or you can link against the |
| 164 | libjpeg-turbo static library. |
| 165 | |
| 166 | To force a Linux, Solaris, or MinGW application to link against the static |
| 167 | version of libjpeg-turbo, you can use the following linker options: |
| 168 | |
| 169 | -Wl,-Bstatic -ljpeg -Wl,-Bdynamic |
| 170 | |
| 171 | On OS X, simply add /opt/libjpeg-turbo/lib/libjpeg.a to the linker command |
| 172 | line (this also works on Linux and Solaris.) |
| 173 | |
| 174 | To build Visual C++ applications using libjpeg-turbo, add |
| 175 | c:\libjpeg-turbo[64]\include to your system or user INCLUDE environment |
| 176 | variable and c:\libjpeg-turbo[64]\lib to your system or user LIB environment |
| 177 | variable, and then link against either jpeg.lib (to use jpeg62.dll) or |
| 178 | jpeg-static.lib (to use the static version of libjpeg-turbo.) |
| 179 | |
| 180 | ===================== |
| 181 | Colorspace Extensions |
| 182 | ===================== |
| 183 | |
| 184 | libjpeg-turbo includes extensions which allow JPEG images to be compressed |
| 185 | directly from (and decompressed directly to) buffers which use BGR, BGRA, |
| 186 | RGBA, ABGR, and ARGB pixel ordering. This is implemented with six new |
| 187 | colorspace 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 | |
| 196 | Setting cinfo.in_color_space (compression) or cinfo.out_color_space |
| 197 | (decompression) to one of these values will cause libjpeg-turbo to read the |
| 198 | red, green, and blue values from (or write them to) the appropriate position in |
| 199 | the pixel when YUV conversion is performed. |
| 200 | |
| 201 | Your application can check for the existence of these extensions at compile |
| 202 | time with: |
| 203 | |
| 204 | #ifdef JCS_EXTENSIONS |
| 205 | |
| 206 | At run time, attempting to use these extensions with a version of libjpeg |
| 207 | that doesn't support them will result in a "Bogus input colorspace" error. |