| 7 | progressive entropy coding by default in the JPEG compressor, as well as |
| 8 | splitting the spectrum of DCT coefficients into separate scans and using |
| 9 | Trellis quantisation. |
| 10 |
| 11 | Although it is based on libjpeg-turbo, mozjpeg is not intended to be a |
| 12 | general-purpose or high-performance JPEG library. Its performance is highly |
| 13 | "asymmetric". That is, the JPEG files it generates require much more time to |
| 14 | compress than to decompress. When the default settings are used, mozjpeg is |
| 15 | considerably slower than libjpeg-turbo or even libjpeg at compressing images. |
| 16 | Thus, it is not generally suitable for real-time compression. It is best used |
| 17 | as part of a web encoding workflow. |
| 18 |
| 19 |
| 20 | libjpeg API Extensibility Framework |
| 21 | =================================== |
| 22 |
| 23 | mozjpeg's implementation of the libjpeg API includes an extensibility framework |
| 24 | that allows new features to be added without modifying the transparent libjpeg |
| 25 | compress/decompress structures (which would break backward ABI compatibility.) |
| 26 | Extension parameters are placed into the opaque jpeg_comp_master structure, and |
| 27 | a set of accessor functions and globally unique tokens allows for |
| 28 | getting/setting those parameters without directly accessing the structure. |
| 29 |
| 30 | Currently, only the accessor functions necessary to support the mozjpeg |
| 31 | extensions are implemented, but the framework can be easily extended in the |
| 32 | future to accommodate additional simple parameter types, complex or |
| 33 | multi-valued parameters, or decompressor extensions. |
| 34 |
| 35 |
| 36 | The currently-implemented accessor functions are as follows: |
| 37 |
| 38 | boolean jpeg_c_bool_param_supported (j_compress_ptr cinfo, |
| 39 | J_BOOLEAN_PARAM param) |
| 40 | Returns TRUE if the given boolean extension parameter is supported by |
| 41 | this implementation of the libjpeg API, or FALSE otherwise. |
| 42 |
| 43 | void jpeg_c_set_bool_param (j_compress_ptr cinfo, |
| 44 | J_BOOLEAN_PARAM param, boolean value); |
| 45 | Set the given boolean extension parameter to the given value (TRUE or |
| 46 | FALSE.) |
| 47 |
| 48 | boolean jpeg_c_get_bool_param (j_compress_ptr cinfo, J_BOOLEAN_PARAM param) |
| 49 | Get the value of the given boolean extension parameter (TRUE or FALSE.) |
| 50 |
| 51 | boolean jpeg_c_float_param_supported (j_compress_ptr cinfo, |
| 52 | J_FLOAT_PARAM param) |
| 53 | Returns TRUE if the given floating point extension parameter is |
| 54 | supported by this implementation of the libjpeg API, or FALSE |
| 55 | otherwise. |
| 56 |
| 57 | void jpeg_c_set_float_param (j_compress_ptr cinfo, J_FLOAT_PARAM param, |
| 58 | float value) |
| 59 | Set the given floating point extension parameter to the given value. |
| 60 |
| 61 | float jpeg_c_get_float_param (j_compress_ptr cinfo, J_FLOAT_PARAM param); |
| 62 | Get the value of the given floating point extension parameter. |
| 63 |
| 64 | boolean jpeg_c_int_param_supported (j_compress_ptr cinfo, |
| 65 | J_INT_PARAM param) |
| 66 | Returns TRUE if the given integer extension parameter is supported by |
| 67 | this implementation of the libjpeg API, or FALSE otherwise. |
| 68 |
| 69 | void jpeg_c_set_int_param (j_compress_ptr cinfo, J_INT_PARAM param, |
| 70 | int value) |
| 71 | Set the given integer extension parameter to the given value. |
| 72 |
| 73 | int jpeg_c_get_int_param (j_compress_ptr cinfo, J_INT_PARAM param) |
| 74 | Get the value of the given integer extension parameter. |
| 75 |
| 76 |
| 77 | Boolean Extension Parameters Supported by mozjpeg |
| 78 | ------------------------------------------------- |
| 79 |
| 80 | * JBOOLEAN_OPTIMIZE_SCANS (default: TRUE) |
| 81 | Specifies whether scan parameters should be optimized. Parameter |
| 82 | optimization is done as in jpgcrush. jpeg_simple_progression() should be called |
| 83 | after setting JBOOLEAN_OPTIMIZE_SCANS. |
| 84 | When disabling JBOOLEAN_OPTIMIZE_SCANS, cinfo.scan_info should additionally be |
| 85 | set to NULL to disable use of the progressive coding mode, if so desired. |
| 86 |
| 87 | * JBOOLEAN_TRELLIS_QUANT (default: TRUE) |
| 88 | Specifies whether to apply trellis quantization. For each 8x8 block, trellis |
| 89 | quantization determines the best tradeoff between rate and distortion. |
| 90 |
| 91 | * JBOOLEAN_TRELLIS_QUANT_DC (default: TRUE) |
| 92 | Specifies whether to apply trellis quantization to DC coefficients. |
| 93 |
| 94 | * JBOOLEAN_TRELLIS_EOB_OPT (default: FALSE) |
| 95 | Specifies whether to optimize runs of zero blocks in trellis quantization. |
| 96 | This is applicable only when JBOOLEAN_USE_SCANS_IN_TRELLIS is enabled. |
| 97 |
| 98 | * JBOOLEAN_USE_LAMBDA_WEIGHT_TBL currently has no effect. |
| 99 |
| 100 | * JBOOLEAN_USE_SCANS_IN_TRELLIS (default: FALSE) |
| 101 | Specifies whether multiple scans should be considered during trellis |
| 102 | quantization. |
| 103 |
| 104 | * JBOOLEAN_TRELLIS_Q_OPT (default: FALSE) |
| 105 | Specifies whether to optimize the quantization table after trellis |
| 106 | quantization. If enabled, then a revised quantization table is derived so |
| 107 | as to minimize the reconstruction error of the quantized coefficients. |
| 108 |
| 109 | * JBOOLEAN_OVERSHOOT_DERINGING (default: TRUE) |
| 110 | Specifies whether overshooting is applied to samples with extreme values |
| 111 | (for example, 0 and 255 for 8-bit samples). Overshooting may reduce ringing |
| 112 | artifacts from compression, in particular in areas where black text appears |
| 113 | on a white background. |
| 114 |
| 115 |
| 116 | Floating Point Extension Parameters Supported by mozjpeg |
| 117 | -------------------------------------------------------- |
| 118 |
| 119 | * JFLOAT_LAMBDA_LOG_SCALE1 (default: 14.75) |
| 120 | JFLOAT_LAMBDA_LOG_SCALE2 (default: 16.5) |
| 121 | These parameters specify the lambda value used in trellis quantization. The |
| 122 | lambda value (Lagrange multiplier) in the |
| 123 | R + lambda * D |
| 124 | equation is derived from |
| 125 | lambda = 2^s1 / ((2^s2 + n) * q^2), |
| 126 | where s1 and s2 are the values of JFLOAT_LAMBDA_LOG_SCALE1 and |
| 127 | JFLOAT_LAMBDA_LOG_SCALE2, n is the average of the squared unquantized AC |
| 128 | coefficients within the current 8x8 block, and q is the quantization table |
| 129 | entry associated with the current coefficient frequency. If |
| 130 | JFLOAT_LAMBDA_LOG_SCALE2 is 0, then an alternate form is used that does not |
| 131 | rely on n: |
| 132 | lambda = 2^(s1-12) / q^2. |
| 133 |
| 134 | * JFLOAT_TRELLIS_DELTA_DC_WEIGHT (default: 0.0) |
| 135 | This parameter controls how distortion is calculated in DC trellis quantization |
| 136 | (enabled with JBOOLEAN_TRELLIS_QUANT_DC). It defines weighting between distortion |
| 137 | of the DC coefficient and distortion of the vertical gradient of DC coefficients. |
| 138 | The value of the parameter corresponds to the weight applied to the distortion |
| 139 | of the vertical gradient. |
| 140 |
| 141 |
| 142 | Integer Extension Parameters Supported by mozjpeg |
| 143 | ------------------------------------------------- |
| 144 |
| 145 | * JINT_COMPRESS_PROFILE (default: JCP_MAX_COMPRESSION) |
| 146 | Select a compression profile, which is a set of default parameters that will |
| 147 | achieve a desired compression goal. This parameter controls the behavior of |
| 148 | the jpeg_set_defaults() function. Thus, setting JINT_COMPRESS_PROFILE does |
| 149 | not cause any other parameters to be modified until jpeg_set_defaults() is |
| 150 | called. The following compression profiles are supported: |
| 151 |
| 152 | - JCP_MAX_COMPRESSION (default) |
| 153 | Increase the compression ratio as much as possible, at the expense of |
| 154 | increased encoding time. This enables progressive entropy coding and all |
| 155 | mozjpeg extensions. |
| 156 |
| 157 | - JCP_FASTEST |
| 158 | Use the libjpeg[-turbo] defaults (baseline entropy coding, no mozjpeg |
| 159 | extensions enabled.) |
| 160 |
| 161 | * JINT_TRELLIS_FREQ_SPLIT (default: 8) |
| 162 | Specifies the position within the zigzag scan at which the split between |
| 163 | scans is positioned in the context of trellis quantization. |
| 164 | JBOOLEAN_USE_SCANS_IN_TRELLIS must be enabled for this parameter to have any |
| 165 | effect. |
| 166 |
| 167 | * JINT_TRELLIS_NUM_LOOPS (default: 1) |
| 168 | Specifies the number of trellis quantization passes. Huffman tables are |
| 169 | updated between passes. |
| 170 |
| 171 | * JINT_BASE_QUANT_TBL_IDX (default: 3) |
| 172 | Specifies which quantization table set to use. The following options are |
| 173 | available: |
| 174 | 0 = Tables from JPEG Annex K |
| 175 | 1 = Flat table |
| 176 | 2 = Table tuned for MSSIM on Kodak image set |
| 177 | 3 = Table from http://www.imagemagick.org/discourse-server/viewtopic.php?f=22&t=20333&p=98008#p98008 |
| 178 | 4 = Table tuned for PSNR-HVS-M on Kodak image set |
| 179 | 5 = Table from: Relevance of Human Vision to JPEG-DCT Compression |
| 180 | (1992) Klein, Silverstein and Carney |
| 181 | 6 = Table from: DCTune Perceptual Optimization of Compressed Dental X-Rays |
| 182 | (1997) Watson, Taylor, Borthwick |
| 183 | 7 = Table from: A Visual Detection Model for DCT Coefficient Quantization |
| 184 | (12/9/93) Ahumada, Watson, Peterson |
| 185 | 8 = Table from: An Improved Detection Model for DCT Coefficient Quantization |
| 186 | (1993) Peterson, Ahumada and Watson |
| 187 |
| 188 | * JINT_DC_SCAN_OPT_MODE (default: 1) |
| 189 | Specifies the DC scan optimization mode. The following options are |
| 190 | available: |
| 191 | 0 = One scan for all components |
| 192 | 1 = One scan per component |
| 193 | 2 = Optimize between one scan for all components and one scan for the first |
| 194 | component plus one scan for the remaining components |
| 195 |