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