Skip to content

Commit 87ecb95

Browse files
authored
feat: add webp support (#1384)
1 parent 99c1de3 commit 87ecb95

17 files changed

Lines changed: 1319 additions & 597 deletions

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "examples/server/frontend"]
55
path = examples/server/frontend
66
url = https://github.com/leejet/stable-ui.git
7+
[submodule "thirdparty/libwebp"]
8+
path = thirdparty/libwebp
9+
url = https://github.com/webmproject/libwebp.git

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ endif()
2929
# general
3030
#option(SD_BUILD_TESTS "sd: build tests" ${SD_STANDALONE})
3131
option(SD_BUILD_EXAMPLES "sd: build examples" ${SD_STANDALONE})
32+
option(SD_WEBP "sd: enable WebP image I/O support" ON)
3233
option(SD_CUDA "sd: cuda backend" OFF)
3334
option(SD_HIPBLAS "sd: rocm backend" OFF)
3435
option(SD_METAL "sd: metal backend" OFF)
@@ -77,6 +78,10 @@ if(SD_MUSA)
7778
add_definitions(-DSD_USE_CUDA)
7879
endif()
7980

81+
if(SD_WEBP)
82+
add_compile_definitions(SD_USE_WEBP)
83+
endif()
84+
8085
set(SD_LIB stable-diffusion)
8186

8287
file(GLOB SD_LIB_SOURCES

docs/build.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ git submodule init
1616
git submodule update
1717
```
1818

19+
## WebP Support in Examples
20+
21+
The example applications (`examples/cli` and `examples/server`) use `libwebp` to support WebP image I/O. This is enabled by default.
22+
23+
If you do not want WebP support, you can disable it at configure time:
24+
25+
```shell
26+
mkdir build && cd build
27+
cmake .. -DSD_WEBP=OFF
28+
cmake --build . --config Release
29+
```
30+
1931
## Build (CPU only)
2032

2133
If you don't have a GPU or CUDA installed, you can build a CPU-only version.

examples/cli/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
set(TARGET sd-cli)
22

33
add_executable(${TARGET}
4+
../common/log.cpp
5+
../common/media_io.cpp
46
image_metadata.cpp
57
main.cpp
68
)
79
install(TARGETS ${TARGET} RUNTIME)
810
target_link_libraries(${TARGET} PRIVATE stable-diffusion zip ${CMAKE_THREAD_LIBS_INIT})
11+
if(SD_WEBP)
12+
target_link_libraries(${TARGET} PRIVATE webp libwebpmux)
13+
endif()
914
target_compile_features(${TARGET} PUBLIC c_std_11 cxx_std_17)

examples/cli/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ usage: ./bin/sd-cli [options]
55
66
CLI Options:
77
-o, --output <string> path to write result image to. you can use printf-style %d format specifiers for image sequences (default:
8-
./output.png) (eg. output_%03d.png)
9-
--preview-path <string> path to write preview image to (default: ./preview.png)
8+
./output.png) (eg. output_%03d.png). For video generation, single-file outputs support .avi and animated .webp
9+
--preview-path <string> path to write preview image to (default: ./preview.png). Multi-frame previews support .avi and animated .webp
1010
--preview-interval <int> interval in denoising steps between consecutive updates of the image preview file (default is 1, meaning updating at
1111
every step)
1212
--output-begin-idx <int> starting index for output image sequence, must be non-negative (default 0 if specified %d in output path, 1 otherwise)

examples/cli/avi_writer.h

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)