Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 1 | __ __ ____ ____ ____ |
| 2 | / \\/ \/ _ \/ _ )/ _ \ |
| 3 | \ / __/ _ \ __/ |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 4 | \__\__/\____/\_____/__/ ____ ___ |
| 5 | / _/ / \ \ / _ \/ _/ |
| 6 | / \_/ / / \ \ __/ \__ |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 7 | \____/____/\_____/_____/____/v0.4.1 |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 8 | |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 9 | Description: |
| 10 | ============ |
| 11 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 12 | WebP codec: library to encode and decode images in WebP format. This package |
| 13 | contains the library that can be used in other programs to add WebP support, |
| 14 | as well as the command line tools 'cwebp' and 'dwebp'. |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 15 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 16 | See http://developers.google.com/speed/webp |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 17 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 18 | Latest sources are available from http://www.webmproject.org/code/ |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 19 | |
| 20 | It is released under the same license as the WebM project. |
| 21 | See http://www.webmproject.org/license/software/ or the |
| 22 | file "COPYING" file for details. An additional intellectual |
| 23 | property rights grant can be found in the file PATENTS. |
| 24 | |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 25 | Building: |
| 26 | ========= |
| 27 | |
Vikas Arora | 1e7bf88 | 2013-03-13 16:43:18 -0700 | [diff] [blame] | 28 | Windows build: |
| 29 | -------------- |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 30 | |
| 31 | By running: |
| 32 | |
| 33 | nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output |
| 34 | |
| 35 | the directory output\release-static\(x64|x86)\bin will contain the tools |
| 36 | cwebp.exe and dwebp.exe. The directory output\release-static\(x64|x86)\lib will |
| 37 | contain the libwebp static library. |
| 38 | The target architecture (x86/x64) is detected by Makefile.vc from the Visual |
| 39 | Studio compiler (cl.exe) available in the system path. |
| 40 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 41 | Unix build using makefile.unix: |
| 42 | ------------------------------- |
| 43 | |
| 44 | On platforms with GNU tools installed (gcc and make), running |
| 45 | |
| 46 | make -f makefile.unix |
| 47 | |
| 48 | will build the binaries examples/cwebp and examples/dwebp, along |
| 49 | with the static library src/libwebp.a. No system-wide installation |
| 50 | is supplied, as this is a simple alternative to the full installation |
| 51 | system based on the autoconf tools (see below). |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 52 | Please refer to makefile.unix for additional details and customizations. |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 53 | |
| 54 | Using autoconf tools: |
| 55 | --------------------- |
| 56 | When building from git sources, you will need to run autogen.sh to generate the |
| 57 | configure script. |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 58 | |
| 59 | ./configure |
| 60 | make |
| 61 | make install |
| 62 | |
| 63 | should be all you need to have the following files |
| 64 | |
| 65 | /usr/local/include/webp/decode.h |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 66 | /usr/local/include/webp/encode.h |
| 67 | /usr/local/include/webp/types.h |
| 68 | /usr/local/lib/libwebp.* |
| 69 | /usr/local/bin/cwebp |
| 70 | /usr/local/bin/dwebp |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 71 | |
| 72 | installed. |
| 73 | |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 74 | Note: A decode-only library, libwebpdecoder, is available using the |
| 75 | '--enable-libwebpdecoder' flag. The encode library is built separately and can |
| 76 | be installed independently using a minor modification in the corresponding |
| 77 | Makefile.am configure files (see comments there). See './configure --help' for |
| 78 | more options. |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 79 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 80 | SWIG bindings: |
| 81 | -------------- |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 82 | |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 83 | To generate language bindings from swig/libwebp.swig at least swig-1.3 |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 84 | (http://www.swig.org) is required. |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 85 | |
| 86 | Currently the following functions are mapped: |
| 87 | Decode: |
| 88 | WebPGetDecoderVersion |
| 89 | WebPGetInfo |
| 90 | WebPDecodeRGBA |
| 91 | WebPDecodeARGB |
| 92 | WebPDecodeBGRA |
| 93 | WebPDecodeBGR |
| 94 | WebPDecodeRGB |
| 95 | |
| 96 | Encode: |
| 97 | WebPGetEncoderVersion |
| 98 | WebPEncodeRGBA |
| 99 | WebPEncodeBGRA |
| 100 | WebPEncodeRGB |
| 101 | WebPEncodeBGR |
| 102 | WebPEncodeLosslessRGBA |
| 103 | WebPEncodeLosslessBGRA |
| 104 | WebPEncodeLosslessRGB |
| 105 | WebPEncodeLosslessBGR |
| 106 | |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 107 | See swig/README for more detailed build instructions. |
| 108 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 109 | Java bindings: |
| 110 | |
| 111 | To build the swig-generated JNI wrapper code at least JDK-1.5 (or equivalent) |
| 112 | is necessary for enum support. The output is intended to be a shared object / |
| 113 | DLL that can be loaded via System.loadLibrary("webp_jni"). |
| 114 | |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 115 | Python bindings: |
| 116 | |
| 117 | To build the swig-generated Python extension code at least Python 2.6 is |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 118 | required. Python < 2.6 may build with some minor changes to libwebp.swig or the |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 119 | generated code, but is untested. |
| 120 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 121 | Encoding tool: |
| 122 | ============== |
| 123 | |
| 124 | The examples/ directory contains tools for encoding (cwebp) and |
| 125 | decoding (dwebp) images. |
| 126 | |
| 127 | The easiest use should look like: |
| 128 | cwebp input.png -q 80 -o output.webp |
| 129 | which will convert the input file to a WebP file using a quality factor of 80 |
| 130 | on a 0->100 scale (0 being the lowest quality, 100 being the best. Default |
| 131 | value is 75). |
| 132 | You might want to try the -lossless flag too, which will compress the source |
| 133 | (in RGBA format) without any loss. The -q quality parameter will in this case |
| 134 | control the amount of processing time spent trying to make the output file as |
| 135 | small as possible. |
| 136 | |
| 137 | A longer list of options is available using the -longhelp command line flag: |
| 138 | |
| 139 | > cwebp -longhelp |
| 140 | Usage: |
| 141 | cwebp [-preset <...>] [options] in_file [-o out_file] |
| 142 | |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 143 | If input size (-s) for an image is not specified, it is |
| 144 | assumed to be a PNG, JPEG, TIFF or WebP file. |
| 145 | |
| 146 | Options: |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 147 | -h / -help ............ short help |
| 148 | -H / -longhelp ........ long help |
| 149 | -q <float> ............. quality factor (0:small..100:big) |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 150 | -alpha_q <int> ......... transparency-compression quality (0..100) |
| 151 | -preset <string> ....... preset setting, one of: |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 152 | default, photo, picture, |
| 153 | drawing, icon, text |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 154 | -preset must come first, as it overwrites other parameters |
| 155 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 156 | -m <int> ............... compression method (0=fast, 6=slowest) |
| 157 | -segments <int> ........ number of segments to use (1..4) |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 158 | -size <int> ............ target size (in bytes) |
| 159 | -psnr <float> .......... target PSNR (in dB. typically: 42) |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 160 | |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 161 | -s <int> <int> ......... input size (width x height) for YUV |
| 162 | -sns <int> ............. spatial noise shaping (0:off, 100:max) |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 163 | -f <int> ............... filter strength (0=off..100) |
| 164 | -sharpness <int> ....... filter sharpness (0:most .. 7:least sharp) |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 165 | -strong ................ use strong filter instead of simple (default) |
| 166 | -nostrong .............. use simple filter instead of strong |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 167 | -partition_limit <int> . limit quality to fit the 512k limit on |
| 168 | the first partition (0=no degradation ... 100=full) |
| 169 | -pass <int> ............ analysis pass number (1..10) |
| 170 | -crop <x> <y> <w> <h> .. crop picture with the given rectangle |
| 171 | -resize <w> <h> ........ resize picture (after any cropping) |
Vikas Arora | 1e7bf88 | 2013-03-13 16:43:18 -0700 | [diff] [blame] | 172 | -mt .................... use multi-threading if available |
| 173 | -low_memory ............ reduce memory usage (slower encoding) |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 174 | -map <int> ............. print map of extra info |
| 175 | -print_psnr ............ prints averaged PSNR distortion |
| 176 | -print_ssim ............ prints averaged SSIM distortion |
| 177 | -print_lsim ............ prints local-similarity distortion |
| 178 | -d <file.pgm> .......... dump the compressed output (PGM file) |
| 179 | -alpha_method <int> .... transparency-compression method (0..1) |
| 180 | -alpha_filter <string> . predictive filtering for alpha plane, |
| 181 | one of: none, fast (default) or best |
| 182 | -alpha_cleanup ......... clean RGB values in transparent area |
| 183 | -blend_alpha <hex> ..... blend colors against background color |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 184 | expressed as RGB values written in |
| 185 | hexadecimal, e.g. 0xc0e0d0 for red=0xc0 |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 186 | green=0xe0 and blue=0xd0 |
| 187 | -noalpha ............... discard any transparency information |
| 188 | -lossless .............. encode image losslessly |
| 189 | -hint <string> ......... specify image characteristics hint, |
| 190 | one of: photo, picture or graph |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 191 | |
Vikas Arora | 1e7bf88 | 2013-03-13 16:43:18 -0700 | [diff] [blame] | 192 | -metadata <string> ..... comma separated list of metadata to |
| 193 | copy from the input to the output if present. |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 194 | Valid values: all, none (default), exif, icc, xmp |
Vikas Arora | 1e7bf88 | 2013-03-13 16:43:18 -0700 | [diff] [blame] | 195 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 196 | -short ................. condense printed message |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 197 | -quiet ................. don't print anything |
| 198 | -version ............... print version number and exit |
| 199 | -noasm ................. disable all assembly optimizations |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 200 | -v ..................... verbose, e.g. print encoding/decoding times |
| 201 | -progress .............. report encoding progress |
| 202 | |
| 203 | Experimental Options: |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 204 | -jpeg_like ............. roughly match expected JPEG size |
| 205 | -af .................... auto-adjust filter strength |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 206 | -pre <int> ............. pre-processing filter |
| 207 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 208 | The main options you might want to try in order to further tune the |
| 209 | visual quality are: |
| 210 | -preset |
| 211 | -sns |
| 212 | -f |
| 213 | -m |
| 214 | |
| 215 | Namely: |
| 216 | * 'preset' will set up a default encoding configuration targeting a |
| 217 | particular type of input. It should appear first in the list of options, |
| 218 | so that subsequent options can take effect on top of this preset. |
| 219 | Default value is 'default'. |
| 220 | * 'sns' will progressively turn on (when going from 0 to 100) some additional |
| 221 | visual optimizations (like: segmentation map re-enforcement). This option |
| 222 | will balance the bit allocation differently. It tries to take bits from the |
| 223 | "easy" parts of the picture and use them in the "difficult" ones instead. |
| 224 | Usually, raising the sns value (at fixed -q value) leads to larger files, |
| 225 | but with better quality. |
| 226 | Typical value is around '75'. |
| 227 | * 'f' option directly links to the filtering strength used by the codec's |
| 228 | in-loop processing. The higher the value, the smoother the |
| 229 | highly-compressed area will look. This is particularly useful when aiming |
| 230 | at very small files. Typical values are around 20-30. Note that using the |
Vikas Arora | 1e7bf88 | 2013-03-13 16:43:18 -0700 | [diff] [blame] | 231 | option -strong/-nostrong will change the type of filtering. Use "-f 0" to |
| 232 | turn filtering off. |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 233 | * 'm' controls the trade-off between encoding speed and quality. Default is 4. |
| 234 | You can try -m 5 or -m 6 to explore more (time-consuming) encoding |
| 235 | possibilities. A lower value will result in faster encoding at the expense |
| 236 | of quality. |
| 237 | |
| 238 | Decoding tool: |
| 239 | ============== |
| 240 | |
| 241 | There is a decoding sample in examples/dwebp.c which will take |
| 242 | a .webp file and decode it to a PNG image file (amongst other formats). |
| 243 | This is simply to demonstrate the use of the API. You can verify the |
| 244 | file test.webp decodes to exactly the same as test_ref.ppm by using: |
| 245 | |
| 246 | cd examples |
| 247 | ./dwebp test.webp -ppm -o test.ppm |
| 248 | diff test.ppm test_ref.ppm |
| 249 | |
| 250 | The full list of options is available using -h: |
| 251 | |
| 252 | > dwebp -h |
| 253 | Usage: dwebp in_file [options] [-o out_file] |
| 254 | |
| 255 | Decodes the WebP image file to PNG format [Default] |
| 256 | Use following options to convert into alternate image formats: |
| 257 | -pam ......... save the raw RGBA samples as a color PAM |
| 258 | -ppm ......... save the raw RGB samples as a color PPM |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 259 | -bmp ......... save as uncompressed BMP format |
| 260 | -tiff ........ save as uncompressed TIFF format |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 261 | -pgm ......... save the raw YUV samples as a grayscale PGM |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 262 | file with IMC4 layout |
| 263 | -yuv ......... save the raw YUV samples in flat layout |
Vikas Arora | 1e7bf88 | 2013-03-13 16:43:18 -0700 | [diff] [blame] | 264 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 265 | Other options are: |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 266 | -version .... print version number and exit |
| 267 | -nofancy ..... don't use the fancy YUV420 upscaler |
| 268 | -nofilter .... disable in-loop filtering |
| 269 | -nodither .... disable dithering |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 270 | -dither <d> .. dithering strength (in 0..100) |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 271 | -mt .......... use multi-threading |
| 272 | -crop <x> <y> <w> <h> ... crop output with the given rectangle |
| 273 | -scale <w> <h> .......... scale the output (*after* any cropping) |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 274 | -alpha ....... only save the alpha plane |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 275 | -incremental . use incremental decoding (useful for tests) |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 276 | -h ....... this help message |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 277 | -v ....... verbose (e.g. print encoding/decoding times) |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 278 | -noasm ....... disable all assembly optimizations |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 279 | |
| 280 | Visualization tool: |
| 281 | =================== |
| 282 | |
| 283 | There's a little self-serve visualization tool called 'vwebp' under the |
| 284 | examples/ directory. It uses OpenGL to open a simple drawing window and show |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 285 | a decoded WebP file. It's not yet integrated in the automake build system, but |
| 286 | you can try to manually compile it using the recommendations below. |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 287 | |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 288 | Usage: vwebp in_file [options] |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 289 | |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 290 | Decodes the WebP image file and visualize it using OpenGL |
| 291 | Options are: |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 292 | -version .... print version number and exit |
| 293 | -noicc ....... don't use the icc profile if present |
| 294 | -nofancy ..... don't use the fancy YUV420 upscaler |
| 295 | -nofilter .... disable in-loop filtering |
| 296 | -dither <int> dithering strength (0..100), default=50 |
| 297 | -mt .......... use multi-threading |
| 298 | -info ........ print info |
| 299 | -h ....... this help message |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 300 | |
| 301 | Keyboard shortcuts: |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 302 | 'c' ................ toggle use of color profile |
| 303 | 'i' ................ overlay file information |
| 304 | 'q' / 'Q' / ESC .... quit |
Vikas Arora | 0406ce1 | 2013-08-09 15:57:12 -0700 | [diff] [blame] | 305 | |
| 306 | Building: |
| 307 | --------- |
| 308 | |
| 309 | Prerequisites: |
| 310 | 1) OpenGL & OpenGL Utility Toolkit (GLUT) |
| 311 | Linux: |
| 312 | $ sudo apt-get install freeglut3-dev mesa-common-dev |
| 313 | Mac + XCode: |
| 314 | - These libraries should be available in the OpenGL / GLUT frameworks. |
| 315 | Windows: |
| 316 | http://freeglut.sourceforge.net/index.php#download |
| 317 | |
| 318 | 2) (Optional) qcms (Quick Color Management System) |
| 319 | i. Download qcms from Mozilla / Chromium: |
| 320 | http://hg.mozilla.org/mozilla-central/file/0e7639e3bdfb/gfx/qcms |
| 321 | http://src.chromium.org/viewvc/chrome/trunk/src/third_party/qcms |
| 322 | ii. Build and archive the source files as libqcms.a / qcms.lib |
| 323 | iii. Update makefile.unix / Makefile.vc |
| 324 | a) Define WEBP_HAVE_QCMS |
| 325 | b) Update include / library paths to reference the qcms directory. |
| 326 | |
| 327 | Build using makefile.unix / Makefile.vc: |
| 328 | $ make -f makefile.unix examples/vwebp |
| 329 | > nmake /f Makefile.vc CFG=release-static \ |
| 330 | ../obj/x64/release-static/bin/vwebp.exe |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 331 | |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 332 | Animated GIF conversion: |
| 333 | ======================== |
| 334 | Animated GIF files can be converted to WebP files with animation using the |
| 335 | gif2webp utility available under examples/. The files can then be viewed using |
| 336 | vwebp. |
| 337 | |
| 338 | Usage: |
| 339 | gif2webp [options] gif_file -o webp_file |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 340 | Options: |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 341 | -h / -help ............ this help |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 342 | -lossy ................. encode image using lossy compression |
| 343 | -mixed ................. for each frame in the image, pick lossy |
| 344 | or lossless compression heuristically |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 345 | -q <float> ............. quality factor (0:small..100:big) |
| 346 | -m <int> ............... compression method (0=fast, 6=slowest) |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 347 | -kmin <int> ............ min distance between key frames |
| 348 | -kmax <int> ............ max distance between key frames |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 349 | -f <int> ............... filter strength (0=off..100) |
| 350 | -metadata <string> ..... comma separated list of metadata to |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 351 | copy from the input to the output if present |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 352 | Valid values: all, none, icc, xmp (default) |
| 353 | -mt .................... use multi-threading if available |
| 354 | |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 355 | -version ............... print version number and exit |
| 356 | -v ..................... verbose |
| 357 | -quiet ................. don't print anything |
Vikas Arora | 8b72022 | 2014-01-02 16:48:02 -0800 | [diff] [blame] | 358 | |
| 359 | Building: |
| 360 | --------- |
| 361 | With the libgif development files installed, gif2webp can be built using |
| 362 | makefile.unix: |
| 363 | $ make -f makefile.unix examples/gif2webp |
| 364 | |
| 365 | or using autoconf: |
| 366 | $ ./configure --enable-everything |
| 367 | $ make |
| 368 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 369 | Encoding API: |
| 370 | ============= |
| 371 | |
| 372 | The main encoding functions are available in the header src/webp/encode.h |
| 373 | The ready-to-use ones are: |
| 374 | size_t WebPEncodeRGB(const uint8_t* rgb, int width, int height, int stride, |
| 375 | float quality_factor, uint8_t** output); |
| 376 | size_t WebPEncodeBGR(const uint8_t* bgr, int width, int height, int stride, |
| 377 | float quality_factor, uint8_t** output); |
| 378 | size_t WebPEncodeRGBA(const uint8_t* rgba, int width, int height, int stride, |
| 379 | float quality_factor, uint8_t** output); |
| 380 | size_t WebPEncodeBGRA(const uint8_t* bgra, int width, int height, int stride, |
| 381 | float quality_factor, uint8_t** output); |
| 382 | |
| 383 | They will convert raw RGB samples to a WebP data. The only control supplied |
| 384 | is the quality factor. |
| 385 | |
| 386 | There are some variants for using the lossless format: |
| 387 | |
| 388 | size_t WebPEncodeLosslessRGB(const uint8_t* rgb, int width, int height, |
| 389 | int stride, uint8_t** output); |
| 390 | size_t WebPEncodeLosslessBGR(const uint8_t* bgr, int width, int height, |
| 391 | int stride, uint8_t** output); |
| 392 | size_t WebPEncodeLosslessRGBA(const uint8_t* rgba, int width, int height, |
| 393 | int stride, uint8_t** output); |
| 394 | size_t WebPEncodeLosslessBGRA(const uint8_t* bgra, int width, int height, |
| 395 | int stride, uint8_t** output); |
| 396 | |
| 397 | Of course in this case, no quality factor is needed since the compression |
| 398 | occurs without loss of the input values, at the expense of larger output sizes. |
| 399 | |
| 400 | Advanced encoding API: |
| 401 | ---------------------- |
| 402 | |
| 403 | A more advanced API is based on the WebPConfig and WebPPicture structures. |
| 404 | |
| 405 | WebPConfig contains the encoding settings and is not tied to a particular |
| 406 | picture. |
| 407 | WebPPicture contains input data, on which some WebPConfig will be used for |
| 408 | compression. |
| 409 | The encoding flow looks like: |
| 410 | |
| 411 | -------------------------------------- BEGIN PSEUDO EXAMPLE |
| 412 | |
| 413 | #include <webp/encode.h> |
| 414 | |
| 415 | // Setup a config, starting form a preset and tuning some additional |
| 416 | // parameters |
| 417 | WebPConfig config; |
| 418 | if (!WebPConfigPreset(&config, WEBP_PRESET_PHOTO, quality_factor)) |
| 419 | return 0; // version error |
| 420 | } |
| 421 | // ... additional tuning |
| 422 | config.sns_strength = 90; |
| 423 | config.filter_sharpness = 6; |
| 424 | config_error = WebPValidateConfig(&config); // not mandatory, but useful |
| 425 | |
| 426 | // Setup the input data |
| 427 | WebPPicture pic; |
| 428 | if (!WebPPictureInit(&pic)) { |
| 429 | return 0; // version error |
| 430 | } |
| 431 | pic.width = width; |
| 432 | pic.height = height; |
| 433 | // allocated picture of dimension width x height |
| 434 | if (!WebPPictureAllocate(&pic)) { |
| 435 | return 0; // memory error |
| 436 | } |
| 437 | // at this point, 'pic' has been initialized as a container, |
| 438 | // and can receive the Y/U/V samples. |
| 439 | // Alternatively, one could use ready-made import functions like |
| 440 | // WebPPictureImportRGB(), which will take care of memory allocation. |
| 441 | // In any case, past this point, one will have to call |
| 442 | // WebPPictureFree(&pic) to reclaim memory. |
| 443 | |
| 444 | // Set up a byte-output write method. WebPMemoryWriter, for instance. |
| 445 | WebPMemoryWriter wrt; |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 446 | WebPMemoryWriterInit(&wrt); // initialize 'wrt' |
| 447 | |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 448 | pic.writer = MyFileWriter; |
| 449 | pic.custom_ptr = my_opaque_structure_to_make_MyFileWriter_work; |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 450 | |
| 451 | // Compress! |
| 452 | int ok = WebPEncode(&config, &pic); // ok = 0 => error occurred! |
| 453 | WebPPictureFree(&pic); // must be called independently of the 'ok' result. |
| 454 | |
| 455 | // output data should have been handled by the writer at that point. |
Vikas Arora | af51b94 | 2014-08-28 10:51:12 -0700 | [diff] [blame] | 456 | // -> compressed data is the memory buffer described by wrt.mem / wrt.size |
| 457 | |
| 458 | // deallocate the memory used by compressed data |
| 459 | WebPMemoryWriterClear(&wrt); |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 460 | |
| 461 | -------------------------------------- END PSEUDO EXAMPLE |
| 462 | |
| 463 | Decoding API: |
| 464 | ============= |
| 465 | |
| 466 | This is mainly just one function to call: |
| 467 | |
| 468 | #include "webp/decode.h" |
| 469 | uint8_t* WebPDecodeRGB(const uint8_t* data, size_t data_size, |
| 470 | int* width, int* height); |
| 471 | |
| 472 | Please have a look at the file src/webp/decode.h for the details. |
| 473 | There are variants for decoding in BGR/RGBA/ARGB/BGRA order, along with |
| 474 | decoding to raw Y'CbCr samples. One can also decode the image directly into a |
| 475 | pre-allocated buffer. |
| 476 | |
| 477 | To detect a WebP file and gather the picture's dimensions, the function: |
| 478 | int WebPGetInfo(const uint8_t* data, size_t data_size, |
| 479 | int* width, int* height); |
| 480 | is supplied. No decoding is involved when using it. |
| 481 | |
| 482 | Incremental decoding API: |
| 483 | ========================= |
| 484 | |
| 485 | In the case when data is being progressively transmitted, pictures can still |
| 486 | be incrementally decoded using a slightly more complicated API. Decoder state |
| 487 | is stored into an instance of the WebPIDecoder object. This object can be |
| 488 | created with the purpose of decoding either RGB or Y'CbCr samples. |
| 489 | For instance: |
| 490 | |
| 491 | WebPDecBuffer buffer; |
| 492 | WebPInitDecBuffer(&buffer); |
| 493 | buffer.colorspace = MODE_BGR; |
| 494 | ... |
| 495 | WebPIDecoder* idec = WebPINewDecoder(&buffer); |
| 496 | |
| 497 | As data is made progressively available, this incremental-decoder object |
| 498 | can be used to decode the picture further. There are two (mutually exclusive) |
| 499 | ways to pass freshly arrived data: |
| 500 | |
| 501 | either by appending the fresh bytes: |
| 502 | |
| 503 | WebPIAppend(idec, fresh_data, size_of_fresh_data); |
| 504 | |
| 505 | or by just mentioning the new size of the transmitted data: |
| 506 | |
| 507 | WebPIUpdate(idec, buffer, size_of_transmitted_buffer); |
| 508 | |
| 509 | Note that 'buffer' can be modified between each call to WebPIUpdate, in |
| 510 | particular when the buffer is resized to accommodate larger data. |
| 511 | |
| 512 | These functions will return the decoding status: either VP8_STATUS_SUSPENDED if |
| 513 | decoding is not finished yet or VP8_STATUS_OK when decoding is done. Any other |
| 514 | status is an error condition. |
| 515 | |
| 516 | The 'idec' object must always be released (even upon an error condition) by |
| 517 | calling: WebPDelete(idec). |
| 518 | |
| 519 | To retrieve partially decoded picture samples, one must use the corresponding |
| 520 | method: WebPIDecGetRGB or WebPIDecGetYUVA. |
| 521 | It will return the last displayable pixel row. |
| 522 | |
| 523 | Lastly, note that decoding can also be performed into a pre-allocated pixel |
| 524 | buffer. This buffer must be passed when creating a WebPIDecoder, calling |
| 525 | WebPINewRGB() or WebPINewYUVA(). |
| 526 | |
| 527 | Please have a look at the src/webp/decode.h header for further details. |
| 528 | |
| 529 | Advanced Decoding API: |
| 530 | ====================== |
| 531 | |
| 532 | WebP decoding supports an advanced API which provides on-the-fly cropping and |
| 533 | rescaling, something of great usefulness on memory-constrained environments like |
| 534 | mobile phones. Basically, the memory usage will scale with the output's size, |
| 535 | not the input's, when one only needs a quick preview or a zoomed in portion of |
| 536 | an otherwise too-large picture. Some CPU can be saved too, incidentally. |
| 537 | |
| 538 | -------------------------------------- BEGIN PSEUDO EXAMPLE |
| 539 | // A) Init a configuration object |
| 540 | WebPDecoderConfig config; |
| 541 | CHECK(WebPInitDecoderConfig(&config)); |
| 542 | |
| 543 | // B) optional: retrieve the bitstream's features. |
| 544 | CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); |
| 545 | |
| 546 | // C) Adjust 'config' options, if needed |
| 547 | config.options.no_fancy_upsampling = 1; |
| 548 | config.options.use_scaling = 1; |
| 549 | config.options.scaled_width = scaledWidth(); |
| 550 | config.options.scaled_height = scaledHeight(); |
| 551 | // etc. |
| 552 | |
| 553 | // D) Specify 'config' output options for specifying output colorspace. |
| 554 | // Optionally the external image decode buffer can also be specified. |
| 555 | config.output.colorspace = MODE_BGRA; |
| 556 | // Optionally, the config.output can be pointed to an external buffer as |
| 557 | // well for decoding the image. This externally supplied memory buffer |
| 558 | // should be big enough to store the decoded picture. |
| 559 | config.output.u.RGBA.rgba = (uint8_t*) memory_buffer; |
| 560 | config.output.u.RGBA.stride = scanline_stride; |
| 561 | config.output.u.RGBA.size = total_size_of_the_memory_buffer; |
| 562 | config.output.is_external_memory = 1; |
| 563 | |
| 564 | // E) Decode the WebP image. There are two variants w.r.t decoding image. |
| 565 | // The first one (E.1) decodes the full image and the second one (E.2) is |
| 566 | // used to incrementally decode the image using small input buffers. |
| 567 | // Any one of these steps can be used to decode the WebP image. |
| 568 | |
| 569 | // E.1) Decode full image. |
| 570 | CHECK(WebPDecode(data, data_size, &config) == VP8_STATUS_OK); |
| 571 | |
| 572 | // E.2) Decode image incrementally. |
| 573 | WebPIDecoder* const idec = WebPIDecode(NULL, NULL, &config); |
| 574 | CHECK(idec != NULL); |
| 575 | while (bytes_remaining > 0) { |
| 576 | VP8StatusCode status = WebPIAppend(idec, input, bytes_read); |
| 577 | if (status == VP8_STATUS_OK || status == VP8_STATUS_SUSPENDED) { |
| 578 | bytes_remaining -= bytes_read; |
| 579 | } else { |
| 580 | break; |
| 581 | } |
| 582 | } |
| 583 | WebPIDelete(idec); |
| 584 | |
| 585 | // F) Decoded image is now in config.output (and config.output.u.RGBA). |
| 586 | // It can be saved, displayed or otherwise processed. |
| 587 | |
| 588 | // G) Reclaim memory allocated in config's object. It's safe to call |
| 589 | // this function even if the memory is external and wasn't allocated |
| 590 | // by WebPDecode(). |
| 591 | WebPFreeDecBuffer(&config.output); |
| 592 | |
| 593 | -------------------------------------- END PSEUDO EXAMPLE |
Eric Hassold | 9aea642 | 2011-01-04 17:22:46 -0800 | [diff] [blame] | 594 | |
| 595 | Bugs: |
| 596 | ===== |
| 597 | |
| 598 | Please report all bugs to our issue tracker: |
| 599 | http://code.google.com/p/webp/issues |
| 600 | Patches welcome! See this page to get started: |
| 601 | http://www.webmproject.org/code/contribute/submitting-patches/ |
| 602 | |
| 603 | Discuss: |
| 604 | ======== |
| 605 | |
| 606 | Email: webp-discuss@webmproject.org |
Vikas Arora | a241572 | 2012-08-09 16:18:58 -0700 | [diff] [blame] | 607 | Web: http://groups.google.com/a/webmproject.org/group/webp-discuss |