### Build and Install with Autoconf Tools Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Standard build and installation process using autoconf tools after generating the configure script. Installs headers, libraries, and binaries to /usr/local. ```shell ./configure make make install ``` -------------------------------- ### Example Usage of Python libwebp Bindings Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/swig/README.md Import the libwebp module in Python and print the decoder version and available attributes. Ensure the installation path is in sys.path. ```python import glob import sys sys.path.append(glob.glob('pylocal/lib/python*/site-packages')[0]) from com.google.webp import libwebp print "libwebp decoder version: %x" % libwebp.WebPGetDecoderVersion() print "libwebp attributes:" for attr in dir(libwebp): print attr ``` -------------------------------- ### Install Headers and Libraries Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Installs the built targets, including headers and libraries, to their designated locations based on CMAKE_INSTALL_INCLUDEDIR, CMAKE_INSTALL_LIBDIR, and CMAKE_INSTALL_BINDIR. ```cmake install( TARGETS ${INSTALLED_LIBRARIES} EXPORT ${PROJECT_NAME}Targets PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webp INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Compile and Run JNI Example Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/swig/README.md Compile the Java example and run it, specifying the library path for the JNI library. ```shell $ javac -cp libwebp.jar libwebp_jni_example.java $ java -Djava.library.path=. -cp libwebp.jar:. libwebp_jni_example ``` -------------------------------- ### img2webp Example Command Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md An example demonstrating how to combine file and frame options to create a looped, animated WebP file with different input image types and durations. ```shell img2webp -loop 2 in0.png -lossy in1.jpg -d 80 in2.tiff -o out.webp ``` -------------------------------- ### Install Man Pages Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Installs the man pages for the libwebp command-line tools. This ensures that users can access documentation for tools like cwebp, dwebp, etc., after installation. ```cmake set(MAN_PAGES cwebp.1 dwebp.1 gif2webp.1 img2webp.1 vwebp.1 webpmux.1 webpinfo.1) set(EXEC_BUILDS "CWEBP" "DWEBP" "GIF2WEBP" "IMG2WEBP" "VWEBP" "WEBPMUX" "WEBPINFO") list(LENGTH MAN_PAGES MAN_PAGES_LENGTH) math(EXPR MAN_PAGES_RANGE "${MAN_PAGES_LENGTH} - 1") foreach(I_MAN RANGE ${MAN_PAGES_RANGE}) list(GET EXEC_BUILDS ${I_MAN} EXEC_BUILD) if(WEBP_BUILD_${EXEC_BUILD}) list(GET MAN_PAGES ${I_MAN} MAN_PAGE) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT doc) endif() endforeach() ``` -------------------------------- ### Install CMake Configuration Files Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Installs the generated CMake configuration files to the specified destination. These files are necessary for other projects to find and use the installed libwebp package. ```cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/WebPConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/WebPConfig.cmake" DESTINATION ${ConfigPackageLocation}) ``` -------------------------------- ### Build Python SWIG Bindings for libwebp Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/swig/README.md Build and install the Python SWIG bindings. Use --prefix to specify an installation location. ```shell $ python setup.py build_ext $ python setup.py install --prefix=pylocal ``` -------------------------------- ### Install libwebp using vcpkg Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Download and install libwebp using the vcpkg dependency manager. This is a convenient way to manage libwebp as a dependency in your projects. ```shell git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install libwebp ``` -------------------------------- ### Install Sharpyuv Library Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Installs the sharpyuv library, its public headers, and related files to their designated locations based on CMake installation variables. ```cmake install( TARGETS sharpyuv EXPORT ${PROJECT_NAME}Targets PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webp/sharpyuv INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/webp ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Install build tools for CMake Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Install necessary build tools, including essential build packages and CMake, on a Debian-like system for compiling libwebp. ```shell $ sudo apt-get install build-essential cmake ``` -------------------------------- ### gif2webp Build with makefile.unix Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Build the gif2webp tool using the provided makefile.unix. Ensure libgif development files are installed. ```shell $ make -f makefile.unix examples/gif2webp ``` -------------------------------- ### Install Build Tools on Debian Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Installs essential build tools like gcc and Gradle on Debian-based systems. ```shell $ sudo apt-get install build-essential gradle ``` -------------------------------- ### Serve WebP Demo with Python HTTP Server Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/webp_js/README.md Start a simple HTTP server in the webp_js directory to serve the demo HTML page and WebP image. Access the demo via http://localhost:8080. ```shell cd webp_js && python3 -m http.server 8080 ``` -------------------------------- ### Example Usage of JNI libwebp Bindings Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/swig/README.md Load the JNI library and call libwebp functions from Java. This example prints the decoder version and lists available methods. ```java import com.google.webp.libwebp; import java.lang.reflect.Method; public class libwebp_jni_example { static { System.loadLibrary("webp_jni"); } /** * usage: java -cp libwebp.jar:. libwebp_jni_example */ public static void main(String argv[]) { final int version = libwebp.WebPGetDecoderVersion(); System.out.println("libwebp version: " + Integer.toHexString(version)); System.out.println("libwebp methods:"); final Method[] libwebpMethods = libwebp.class.getDeclaredMethods(); for (int i = 0; i < libwebpMethods.length; i++) { System.out.println(libwebpMethods[i]); } } } ``` -------------------------------- ### Install Build Dependencies on Debian-like Systems Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Installs necessary build tools for libwebp on Debian-based systems. This is a prerequisite for building from git sources. ```shell $ sudo apt-get install gcc make autoconf automake libtool ``` -------------------------------- ### gif2webp Usage Example Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Basic command-line usage for converting a GIF to WebP with animation. Specify input GIF and output WebP file. ```shell gif2webp [options] gif_file -o webp_file ``` -------------------------------- ### Build dwebp Executable Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Configures the dwebp command-line tool, linking it with necessary utility and image decoding/encoding libraries. It also specifies runtime installation destination. ```cmake parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "DWEBP_SRCS" "dwebp") add_executable(dwebp ${DWEBP_SRCS}) target_link_libraries(dwebp exampleutil imagedec imageenc) target_include_directories(dwebp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) install(TARGETS dwebp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Build libwebpmux Library Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Configures the libwebpmux library, linking it with the main webp library. It sets public headers, output name, and prepares it for installation and pkg-config integration. ```cmake parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/mux "WEBP_MUX_SRCS" "") add_library(libwebpmux ${WEBP_MUX_SRCS}) target_link_libraries(libwebpmux webp) target_include_directories(libwebpmux PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) set_version(src/mux/Makefile.am libwebpmux webpmux) set_target_properties( libwebpmux PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux.h;\\ ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux_types.h;\\ ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h;") set_target_properties(libwebpmux PROPERTIES OUTPUT_NAME webpmux) list(APPEND INSTALLED_LIBRARIES libwebpmux) configure_pkg_config("src/mux/libwebpmux.pc") ``` -------------------------------- ### Initialize WebP Decoding Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/webp_js/index.html Initializes the WebP decoding module by wrapping the C function 'WebPToSDL' for use in JavaScript. This setup is required before any decoding can occur. ```javascript var Module = { noInitialRun : true }; 'use strict'; // main wrapper for the function decoding a WebP into a canvas object var WebpToCanvas; function init() { WebpToCanvas = Module.cwrap('WebPToSDL', 'number', ['array', 'number']); } window.onload = init; ``` -------------------------------- ### Build cwebp Executable Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Configures the cwebp command-line tool, linking it with utility, image decoding, and webp libraries. It also sets up include directories and specifies the runtime installation destination. ```cmake parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "CWEBP_SRCS" "cwebp") add_executable(cwebp ${CWEBP_SRCS}) target_link_libraries(cwebp exampleutil imagedec webp) target_include_directories(cwebp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}) install(TARGETS cwebp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Example Sequence of WebP Lossless Bitstream Elements Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/webp-lossless-bitstream-spec.txt Illustrates a possible sequence of elements within a WebP lossless bitstream, combining header, transform, and data components. ```abnf RIFF-header image-size %b1 subtract-green-tx %b1 predictor-tx %b0 color-cache-info %b0 prefix-codes lz77-coded-image ``` -------------------------------- ### Install Git Commit Hook Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CONTRIBUTING.md Install the commit-msg hook to automatically add an ID to your commits for tracking. ```bash curl -Lo .git/hooks/commit-msg https://chromium-review.googlesource.com/tools/hooks/commit-msg && chmod u+x .git/hooks/commit-msg ``` -------------------------------- ### Build vwebp with Makefile.vc Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Compile the `vwebp` tool using the provided Windows Makefile.vc. ```shell nmake /f Makefile.vc CFG=release-static \ ../obj/x64/release-static/bin/vwebp.exe ``` -------------------------------- ### Build vwebp with makefile.unix Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Compile the `vwebp` tool using the provided Unix makefile. ```shell make -f makefile.unix examples/vwebp ``` -------------------------------- ### Configure img2webp Executable Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Sets up the build for the img2webp executable, including necessary include directories and library linking. ```cmake include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "IMG2WEBP_SRCS" "img2webp") add_executable(img2webp ${IMG2WEBP_SRCS}) target_link_libraries(img2webp exampleutil imagedec imageioutil webp libwebpmux) target_include_directories(img2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### Windows Build with nmake Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Use this command to build libwebp on Windows using nmake. It generates static libraries and executables in the output directory. ```batch nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output ``` -------------------------------- ### Install CMake Export Package Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Installs the CMake export package for the project, enabling find_package() usage in other projects. Configures the package location using CMAKE_INSTALL_DATADIR. ```cmake set(ConfigPackageLocation ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake/) install(EXPORT ${PROJECT_NAME}Targets NAMESPACE ${PROJECT_NAME}:: DESTINATION ${ConfigPackageLocation}) ``` -------------------------------- ### gif2webp Build with autoconf Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Build the gif2webp tool using autoconf. This method requires configuring the build first. ```shell $ ./configure --enable-everything $ make ``` -------------------------------- ### Display dwebp Help Message Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Shows how to display the usage information and available options for the `dwebp` command-line tool. ```shell dwebp -h ``` -------------------------------- ### Configure Pkg-Config File Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt A CMake function to configure and install pkg-config files. It handles template substitution and conditionally removes '-lm' for MSVC. ```cmake function(configure_pkg_config FILE) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.in" "${CMAKE_CURRENT_BINARY_DIR}/${FILE}" @ONLY) if(HAVE_MATH_LIBRARY) # MSVC doesn't have libm file(READ ${CMAKE_CURRENT_BINARY_DIR}/${FILE} data) string(REPLACE "-lm" "" data ${data}) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${FILE} ${data}) endif() install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${FILE}" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endfunction() ``` -------------------------------- ### Build anim_diff Tool Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Builds the anim_diff utility using either makefile.unix or autoconf. Ensure libgif development files are installed for makefile.unix. ```shell $ make -f makefile.unix examples/anim_diff ``` ```shell $ ./configure --enable-everything $ make ``` -------------------------------- ### Configure anim_dump Executable Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Defines the anim_dump executable, linking necessary libraries and include directories. This is used for building the animation dump example. ```cmake include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS} ${WEBP_DEP_GIF_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "ANIM_DUMP_SRCS" "anim_dump") add_executable(anim_dump ${ANIM_DUMP_SRCS}) target_link_libraries( anim_dump exampleutil imagedec imageenc imageioutil webp webpdemux ${WEBP_DEP_GIF_LIBRARIES}) target_include_directories(anim_dump PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) ``` -------------------------------- ### Configure anim_diff Executable Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Defines the anim_diff executable, linking necessary libraries and include directories. This is used for building the animation difference example. ```cmake include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS} ${WEBP_DEP_GIF_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "ANIM_DIFF_SRCS" "anim_diff") add_executable(anim_diff ${ANIM_DIFF_SRCS}) target_link_libraries( anim_diff exampleutil imagedec imageenc imageioutil webp webpdemux ${WEBP_DEP_GIF_LIBRARIES}) target_include_directories(anim_diff PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) ``` -------------------------------- ### WebP Mux Tool Usage Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Demonstrates the various command-line options for the webpmux tool, used for manipulating WebP files. Use -help for a full list of options. ```shell > webpmux -help ``` -------------------------------- ### Build Utility Libraries with CMake Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Configures and builds several static utility libraries (exampleutil, imageioutil, imagedec, imageenc) if specific build flags are enabled. These libraries provide helper functionalities for image processing and manipulation. ```cmake if(WEBP_BUILD_ANIM_UTILS OR WEBP_BUILD_CWEBP OR WEBP_BUILD_DWEBP OR WEBP_BUILD_GIF2WEBP OR WEBP_BUILD_IMG2WEBP OR WEBP_BUILD_VWEBP OR WEBP_BUILD_WEBPMUX OR WEBP_BUILD_WEBPINFO) # Example utility library. parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "EXAMPLEUTIL_SRCS" "example_util_[^ ]*") list(APPEND EXAMPLEUTIL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/examples/stopwatch.h) add_library(exampleutil STATIC ${EXAMPLEUTIL_SRCS}) target_include_directories( exampleutil PUBLIC $) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEIOUTILS_SRCS" "imageio_util_[^ ]*") add_library(imageioutil STATIC ${IMAGEIOUTILS_SRCS}) target_link_libraries(imageioutil webp) target_link_libraries(exampleutil imageioutil) # Image-decoding utility library. parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEDEC_SRCS" "imagedec_[^ ]*") add_library(imagedec STATIC ${IMAGEDEC_SRCS}) target_link_libraries(imagedec imageioutil webpdemux webp ${WEBP_DEP_IMG_LIBRARIES}) # Image-encoding utility library. parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEENC_SRCS" "imageenc_[^ ]*") add_library(imageenc STATIC ${IMAGEENC_SRCS}) target_link_libraries(imageenc imageioutil webp) set_property( TARGET exampleutil imageioutil imagedec imageenc PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src) endif() if(WEBP_BUILD_DWEBP) ``` -------------------------------- ### Configure Package Configuration File Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Configures the main package configuration file for CMake. This is used to help other projects find and use the installed library. ```cmake include(CMakePackageConfigHelpers) # Fix libwebpmux reference. The target name libwebpmux is used for compatibility # purposes, but the library mentioned in WebPConfig.cmake should be the # unprefixed version. Note string(...) can be replaced with list(TRANSFORM ...) # if cmake_minimum_required is >= 3.12. string(REGEX REPLACE "libwebpmux" "webpmux" INSTALLED_LIBRARIES "${INSTALLED_LIBRARIES}") if(MSVC) # For compatibility with nmake, MSVC builds use a custom prefix (lib) that # needs to be included in the library name. string(REGEX REPLACE "[A-Za-z0-9_]+" "${CMAKE_STATIC_LIBRARY_PREFIX}\\0" INSTALLED_LIBRARIES "${INSTALLED_LIBRARIES}") endif() configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/WebPConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/WebPConfig.cmake INSTALL_DESTINATION ${ConfigPackageLocation} PATH_VARS CMAKE_INSTALL_INCLUDEDIR) ``` -------------------------------- ### img2webp Usage Syntax Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Basic syntax for using the img2webp command-line tool. Specify file and frame options before the output file. ```shell img2webp [file_options] [[frame_options] frame_file]... [-o webp_file] ``` -------------------------------- ### WebP Mux: Get Options Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Extracts specific data like ICC profiles, EXIF, XMP metadata, or individual frames from a WebP file. ```shell webpmux -get icc INPUT -o OUTPUT webpmux -get exif INPUT -o OUTPUT webpmux -get xmp INPUT -o OUTPUT webpmux -get frame n INPUT -o OUTPUT ``` -------------------------------- ### Retrieve Bitstream Features Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/api.md Get the features of the WebP bitstream, such as dimensions and format, before full decoding. This is useful for validating input or preparing output buffers. ```c // B) optional: retrieve the bitstream's features. CHECK(WebPGetFeatures(data, data_size, &config.input) == VP8_STATUS_OK); ``` -------------------------------- ### Configure Extras Library Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Configures the 'extras' static library by parsing Makefiles for source files and setting include directories. ```cmake set(EXTRAS_MAKEFILE "${CMAKE_CURRENT_SOURCE_DIR}/extras") parse_makefile_am(${EXTRAS_MAKEFILE} "WEBP_EXTRAS_SRCS" "libwebpextras_la") parse_makefile_am(${EXTRAS_MAKEFILE} "GET_DISTO_SRCS" "get_disto") parse_makefile_am(${EXTRAS_MAKEFILE} "WEBP_QUALITY_SRCS" "webp_quality") parse_makefile_am(${EXTRAS_MAKEFILE} "VWEBP_SDL_SRCS" "vwebp_sdl") # libextras add_library(extras STATIC ${WEBP_EXTRAS_SRCS}) target_include_directories( extras PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src) ``` -------------------------------- ### Configure webpinfo Executable Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Configures the webpinfo executable by parsing Makefiles and linking necessary libraries. ```cmake include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "WEBPINFO_SRCS" "webpinfo") add_executable(webpinfo ${WEBPINFO_SRCS}) target_link_libraries(webpinfo exampleutil imageioutil) target_include_directories(webpinfo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src) install(TARGETS webpinfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Find WebP package in CMake project Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Integrate libwebp into your CMake project by finding the installed package. This makes WebP include directories and libraries available. ```cmake find_package(WebP) ``` -------------------------------- ### Initialize Advanced Decoder Configuration Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/api.md Set up the configuration object for advanced WebP decoding, which supports features like cropping and rescaling. Ensure the configuration is properly initialized. ```c // A) Init a configuration object WebPDecoderConfig config; CHECK(WebPInitDecoderConfig(&config)); ``` -------------------------------- ### WebP Lossless Bitstream RIFF Header Structure Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/webp-lossless-bitstream-spec.txt Defines the basic structure of a WebP lossless bitstream, starting with the RIFF header and followed by the image header and stream. ```abnf format = RIFF-header image-header image-stream RIFF-header = %s"RIFF" 4OCTET %s"WEBPVP8L" 4OCTET image-header = 14BIT 14BIT alpha-is-used version image-size = 14BIT 14BIT ; width - 1, height - 1 alpha-is-used = 1BIT version = 3BIT ; 0 image-stream = optional-transform spatially-coded-image ``` -------------------------------- ### Initialize WebP Source Directories and Parse Makefiles Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Sets the base directory for WebP source files and then calls the `parse_Makefile_am` function for various subdirectories (dec, demux, dsp, enc, utils) to populate source file lists for different components. ```cmake set(WEBP_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) parse_makefile_am(${WEBP_SRC_DIR}/dec "WEBP_DEC_SRCS" "") parse_makefile_am(${WEBP_SRC_DIR}/demux "WEBP_DEMUX_SRCS" "") parse_makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_COMMON_SRCS" "COMMON") parse_makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_ENC_SRCS" "ENC") parse_makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_ENC_SRCS" "dsp_[^ ]*") parse_makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_DEC_SRCS" "decode_[^ ]*") parse_makefile_am(${WEBP_SRC_DIR}/enc "WEBP_ENC_SRCS" "") parse_makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_COMMON_SRCS" "COMMON") parse_makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_ENC_SRCS" "ENC") parse_makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_DEC_SRCS" "decode_[^ ]*") ``` -------------------------------- ### Get WebP Image Information Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/api.md Retrieve the dimensions (width and height) of a WebP image without performing the full decoding process. This is useful for pre-allocating buffers or displaying thumbnails. ```c int WebPGetInfo(const uint8_t* data, size_t data_size, int* width, int* height); ``` -------------------------------- ### WebP Visualization Tool Usage Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Launch `vwebp` to decode and visualize a WebP image using OpenGL. This tool is located in the examples/ directory. ```shell vwebp in_file [options] ``` -------------------------------- ### Decode Image Dimensions Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/webp-lossless-bitstream-spec.txt Reads the 14-bit integers for image width and height from the bitstream, adding 1 to each to get the actual dimensions. This limits the maximum image size to 16384x16384 pixels. ```c int image_width = ReadBits(14) + 1; int image_height = ReadBits(14) + 1; ``` -------------------------------- ### WebP Info Options Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Command-line options for `webpinfo` to control output verbosity and detail. ```shell -version ........... Print version number and exit. -quiet ............. Do not show chunk parsing information. -diag .............. Show parsing error diagnosis. -summary ........... Show chunk stats summary. -bitstream_info .... Parse bitstream header. ``` -------------------------------- ### vwebp Visualization Options Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Command-line options for `vwebp` to control image decoding and rendering. ```shell -version ..... print version number and exit -noicc ....... don't use the icc profile if present -nofancy ..... don't use the fancy YUV420 upscaler -nofilter .... disable in-loop filtering -dither dithering strength (0..100), default=50 -noalphadither disable alpha plane dithering -usebgcolor .. display background color -mt .......... use multi-threading -info ........ print info -h ........... this help message ``` -------------------------------- ### Convert WebP to YUV Flat Layout Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Use the `-yuv` option to save the raw YUV samples in a flat layout. ```shell dwebp input.webp -yuv -o output.yuv ``` -------------------------------- ### Get Prefix Code Group for Pixel Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/webp-lossless-bitstream-spec.txt Retrieves the appropriate prefix code group for a given pixel (x, y) in an ARGB image using meta prefix codes derived from the entropy image. Assumes existence of PrefixCodeGroup structure and prefix_code_groups array. ```c int position = (y >> prefix_bits) * prefix_image_width + (x >> prefix_bits); int meta_prefix_code = (entropy_image[position] >> 8) & 0xffff; PrefixCodeGroup prefix_group = prefix_code_groups[meta_prefix_code]; ``` -------------------------------- ### Decode Animated WebP Image with AnimDecoder API Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/api.md Use the AnimDecoder API to decode animated WebP images. Initialize decoder options, create a new decoder, get animation info, and iterate through frames. Render each frame's buffer based on its timestamp. Do not free the buffer as it's owned by the decoder. Reset the decoder for each loop iteration and delete it when done. ```c WebPAnimDecoderOptions dec_options; WebPAnimDecoderOptionsInit(&dec_options); // Tune 'dec_options' as needed. WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options); WebPAnimInfo anim_info; WebPAnimDecoderGetInfo(dec, &anim_info); for (uint32_t i = 0; i < anim_info.loop_count; ++i) { while (WebPAnimDecoderHasMoreFrames(dec)) { uint8_t* buf; int timestamp; WebPAnimDecoderGetNext(dec, &buf, ×tamp); // ... (Render 'buf' based on 'timestamp'). // ... (Do NOT free 'buf', as it is owned by 'dec'). } WebPAnimDecoderReset(dec); } const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec); // ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data). WebPAnimDecoderDelete(dec); ``` -------------------------------- ### Create and Assemble WebP with Mux API Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/api.md Use the Mux API to create a WebP object, set image data, ICC profile, and XMP metadata, then assemble it into the WebP RIFF format. Ensure to clear the output data after use. ```c int copy_data = 0; WebPMux* mux = WebPMuxNew(); // ... (Prepare image data). WebPMuxSetImage(mux, &image, copy_data); // ... (Prepare ICC profile data). WebPMuxSetChunk(mux, "ICCP", &icc_profile, copy_data); // ... (Prepare XMP metadata). WebPMuxSetChunk(mux, "XMP ", &xmp, copy_data); // Get data from mux in WebP RIFF format. WebPMuxAssemble(mux, &output_data); WebPMuxDelete(mux); // ... (Consume output_data; e.g. write output_data.bytes to file). WebPDataClear(&output_data); ``` -------------------------------- ### Create main webp Library from OBJECT Libraries Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Aggregates several OBJECT libraries (webpdecode, webpdsp, webpencode, webputils) into the main 'webp' library. It links against 'sharpyuv' and other specified dependencies. ```cmake add_library(webp $ $ $ $) target_link_libraries(webp sharpyuv) if(XCODE) libwebp_add_stub_file(webp) endif() target_link_libraries(webp ${WEBP_DEP_LIBRARIES}) ``` -------------------------------- ### Build libwebp with CMake Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Generate Makefiles using CMake and build libwebp from git sources. This process is standard for projects using CMake as their build system. ```shell mkdir build && cd build && cmake ../ make make install ``` -------------------------------- ### Build All Executables with Gradle Wrapper Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Executes the Gradle wrapper to build all specified executables when working with git sources. ```shell ./gradlew buildAllExecutables ``` -------------------------------- ### Initialize Incremental Decoder Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/api.md Create and initialize a WebPIDecoder object for incremental decoding. Specify the desired output colorspace (e.g., MODE_BGR) and optionally provide a pre-allocated buffer. ```c WebPDecBuffer buffer; WebPInitDecBuffer(&buffer); buffer.colorspace = MODE_BGR; ... WebPIDecoder* idec = WebPINewDecoder(&buffer); ``` -------------------------------- ### dwebp Usage Information Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md The standard usage string for the `dwebp` tool, indicating input file, options, and output file. ```shell > dwebp -h Usage: dwebp in_file [options] [-o out_file] ``` -------------------------------- ### Enable executables with CMake Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Configure the CMake build to include specific executables like cwebp and dwebp. Use CMake options to enable desired components. ```shell cmake -DWEBP_BUILD_CWEBP=ON -DWEBP_BUILD_DWEBP=ON ../ ``` -------------------------------- ### Add Executable for webp_quality Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Defines the webp_quality executable, linking it with exampleutil, imagedec, and extras libraries. Include directories are also set. ```cmake add_executable(webp_quality ${WEBP_QUALITY_SRCS}) target_link_libraries(webp_quality exampleutil imagedec extras) target_include_directories(webp_quality PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ``` -------------------------------- ### Build JNI SWIG Bindings for libwebp Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/swig/README.md Compile the JNI wrapper for libwebp. Ensure you have the correct include paths for your JDK. ```shell $ gcc -shared -fPIC -fno-strict-aliasing -O2 \ -I/path/to/your/jdk/includes \ libwebp_java_wrap.c \ -lwebp \ -o libwebp_jni.so ``` -------------------------------- ### WebP Encoding Options Overview Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Provides a detailed list of command-line options for the cwebp tool, covering quality, compression, filtering, resizing, and metadata. ```shell -h / -help ............. short help -H / -longhelp ......... long help -q ............. quality factor (0:small..100:big), default=75 -alpha_q ......... transparency-compression quality (0..100), default=100 -preset ....... preset setting, one of: default, photo, picture, drawing, icon, text -preset must come first, as it overwrites other parameters -z ............... activates lossless preset with given level in [0:fast, ..., 9:slowest] -m ............... compression method (0=fast, 6=slowest), default=4 -segments ........ number of segments to use (1..4), default=4 -size ............ target size (in bytes) -psnr .......... target PSNR (in dB. typically: 42) -s ......... input size (width x height) for YUV -sns ............. spatial noise shaping (0:off, 100:max), default=50 -f ............... filter strength (0=off..100), default=60 -sharpness ....... filter sharpness (0:most .. 7:least sharp), default=0 -strong ................ use strong filter instead of simple (default) -nostrong .............. use simple filter instead of strong -sharp_yuv ............. use sharper (and slower) RGB->YUV conversion -partition_limit . limit quality to fit the 512k limit on the first partition (0=no degradation ... 100=full) -pass ............ analysis pass number (1..10) -qrange .... specifies the permissible quality range (default: 0 100) -crop .. crop picture with the given rectangle -resize ........ resize picture (*after* any cropping) -mt .................... use multi-threading if available -low_memory ............ reduce memory usage (slower encoding) -map ............. print map of extra info -print_psnr ............ prints averaged PSNR distortion -print_ssim ............ prints averaged SSIM distortion -print_lsim ............ prints local-similarity distortion -d .......... dump the compressed output (PGM file) -alpha_method .... transparency-compression method (0..1), default=1 -alpha_filter . predictive filtering for alpha plane, one of: none, fast (default) or best -exact ................. preserve RGB values in transparent area, default=off -blend_alpha ..... blend colors against background color expressed as RGB values written in hexadecimal, e.g. 0xc0e0d0 for red=0xc0 green=0xe0 and blue=0xd0 -noalpha ............... discard any transparency information -lossless .............. encode image losslessly, default=off -near_lossless ... use near-lossless image preprocessing (0..100=off), default=100 -hint ......... specify image characteristics hint, one of: photo, picture or graph -metadata ..... comma separated list of metadata to copy from the input to the output if present. Valid values: all, none (default), exif, icc, xmp -short ................. condense printed message -quiet ................. don't print anything -version ............... print version number and exit -noasm ................. disable all assembly optimizations -v ..................... verbose, e.g. print encoding/decoding times -progress .............. report encoding progress ``` -------------------------------- ### Decode WebP to PPM and Compare Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Demonstrates decoding a WebP file to a PPM image and verifying its integrity by comparing it with a reference file. ```shell cd examples ./dwebp test.webp -ppm -o test.ppm diff test.ppm test_ref.ppm ``` -------------------------------- ### Initialize and Populate Code Length Codes (WebP Lossless) Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/webp-lossless-bitstream-spec.txt Initializes an array for code length codes and populates it based on the order specified in kCodeLengthCodeOrder by reading 3 bits for each relevant code length. ```c int kCodeLengthCodes = 19; int kCodeLengthCodeOrder[kCodeLengthCodes] = { 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; int code_length_code_lengths[kCodeLengthCodes] = { 0 }; // All zeros for (i = 0; i < num_code_lengths; ++i) { code_length_code_lengths[kCodeLengthCodeOrder[i]] = ReadBits(3); } ``` -------------------------------- ### WebP File Analysis Tool Usage Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Use `webpinfo` to inspect the structure and header information of WebP files. Options must precede input files. ```shell webpinfo [options] in_files ``` -------------------------------- ### Configure webp Library Properties Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Sets public and install-time include directories for the 'webp' library. It also specifies the public header files for the library. ```cmake target_include_directories( webp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} PUBLIC $ $) set_target_properties( webp PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/webp/decode.h;\${CMAKE_CURRENT_SOURCE_DIR}/src/webp/encode.h;\${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h") ``` -------------------------------- ### Clone libwebp Repository Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CONTRIBUTING.md Clone the libwebp repository locally to begin making changes. ```bash git clone https://chromium.googlesource.com/webm/libwebp && cd libwebp ``` -------------------------------- ### Unix Build with makefile.unix Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Builds binaries and the static library on Unix-like systems with GNU tools. Refer to makefile.unix for customization. ```shell make -f makefile.unix ``` -------------------------------- ### Display cwebp Long Help Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Displays the full list of available command-line options for the cwebp tool. This is useful for understanding all available parameters for encoding. ```shell > cwebp -longhelp Usage: cwebp [-preset <...>][options] in_file [-o out_file] ``` -------------------------------- ### Advanced WebP Encoding Workflow Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/api.md This snippet outlines the advanced encoding process using WebPConfig and WebPPicture structures. It involves setting up configuration, allocating picture data, defining a writer, and performing the compression. Remember to free the picture and clear the writer afterwards. ```c #include // Setup a config, starting form a preset and tuning some additional // parameters WebPConfig config; if (!WebPConfigPreset(&config, WEBP_PRESET_PHOTO, quality_factor)) { return 0; // version error } // ... additional tuning config.sns_strength = 90; config.filter_sharpness = 6; config_error = WebPValidateConfig(&config); // not mandatory, but useful // Setup the input data WebPPicture pic; if (!WebPPictureInit(&pic)) { return 0; // version error } pic.width = width; pic.height = height; // allocated picture of dimension width x height if (!WebPPictureAlloc(&pic)) { return 0; // memory error } // at this point, 'pic' has been initialized as a container, // and can receive the Y/U/V samples. // Alternatively, one could use ready-made import functions like // WebPPictureImportRGB(), which will take care of memory allocation. // In any case, past this point, one will have to call // WebPPictureFree(&pic) to reclaim memory. // Set up a byte-output write method. WebPMemoryWriter, for instance. WebPMemoryWriter wrt; WebPMemoryWriterInit(&wrt); // initialize 'wrt' pic.writer = MyFileWriter; pic.custom_ptr = my_opaque_structure_to_make_MyFileWriter_work; // Compress! int ok = WebPEncode(&config, &pic); // ok = 0 => error occurred! WebPPictureFree(&pic); // must be called independently of the 'ok' result. // output data should have been handled by the writer at that point. // -> compressed data is the memory buffer described by wrt.mem / wrt.size // deallocate the memory used by compressed data WebPMemoryWriterClear(&wrt); ``` -------------------------------- ### Convert WebP to Grayscale PGM Format Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/tools.md Use the `-pgm` option to save the raw YUV samples in IMC4 layout as a grayscale PGM file. ```shell dwebp input.webp -pgm -o output.pgm ``` -------------------------------- ### Build libwebp for MIPS Linux Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/building.md Configure and build libwebp for MIPS Linux, supporting both 32-bit and 64-bit architectures. Ensure the MIPS toolchain is added to your PATH. ```shell # Add toolchain to PATH export PATH=$PATH:/path/to/toolchain/bin # 32-bit build for mips32r5 (p5600) HOST=mips-mti-linux-gnu MIPS_CFLAGS="-O3 -mips32r5 -mabi=32 -mtune=p5600 -mmsa -mfp64 \ -msched-weight -mload-store-pairs -fPIE" MIPS_LDFLAGS="-mips32r5 -mabi=32 -mmsa -mfp64 -pie" # 64-bit build for mips64r6 (i6400) HOST=mips-img-linux-gnu MIPS_CFLAGS="-O3 -mips64r6 -mabi=64 -mtune=i6400 -mmsa -mfp64 \ -msched-weight -mload-store-pairs -fPIE" MIPS_LDFLAGS="-mips64r6 -mabi=64 -mmsa -mfp64 -pie" ./configure --host=${HOST} --build=`config.guess` \ CC="${HOST}-gcc -EL" \ CFLAGS="$MIPS_CFLAGS" \ LDFLAGS="$MIPS_LDFLAGS" make make install ``` -------------------------------- ### Generate HTML Spec with Syntax Highlighting Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/doc/specs_generation.md Generate HTML documentation with inline CSS syntax highlighting using kramdown and CodeRay. Specify 'style' for inline CSS and ' ' for line numbers. ```shell kramdown doc/webp-lossless-bitstream-spec.txt --template \ doc/template.html --coderay-css style --coderay-line-numbers ' ' \ --coderay-default-lang c > \ doc/output/webp-lossless-bitstream-spec.html ``` -------------------------------- ### Build vwebp_sdl with SDL2 Support Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Conditionally builds the vwebp_sdl executable if WEBP_BUILD_VWEBP is enabled and SDL2 is found. It links against SDL2 libraries and sets necessary include directories and compile definitions. ```cmake find_package(SDL2 QUIET) if(WEBP_BUILD_VWEBP AND SDL2_FOUND) add_executable(vwebp_sdl ${VWEBP_SDL_SRCS}) target_link_libraries(vwebp_sdl ${SDL2_LIBRARIES} imageioutil webp) target_include_directories( vwebp_sdl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ${SDL2_INCLUDE_DIRS}) set(WEBP_HAVE_SDL 1) target_compile_definitions(vwebp_sdl PUBLIC WEBP_HAVE_SDL) endif() endif() ``` -------------------------------- ### Configure gif2webp Executable Source: https://github.com/voidtools/voidimageviewer/blob/master/libwebp/CMakeLists.txt Configures the build for the gif2webp executable. It links against several utility and library targets and sets private include directories. ```cmake include_directories(${WEBP_DEP_GIF_INCLUDE_DIRS}) parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "GIF2WEBP_SRCS" "gif2webp") add_executable(gif2webp ${GIF2WEBP_SRCS}) target_link_libraries(gif2webp exampleutil imageioutil webp libwebpmux ${WEBP_DEP_GIF_LIBRARIES}) target_include_directories(gif2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src) ```