Skip to content

Commit 54789dc

Browse files
marstaikasny
andauthored
Add webp support (#33)
* add webp support * Use unreleased gltf version * Fix * Use patch * Don't enable gltf dependency on webp feature --------- Co-authored-by: Asger Nyman Christiansen <asgernyman@gmail.com>
1 parent abfedec commit 54789dc

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tiff = ["image/tiff"]
3030
tga = ["image/tga"]
3131
gif = ["image/gif"]
3232
bmp = ["image/bmp"]
33+
webp = ["image/webp", "gltf?/EXT_texture_webp"]
3334

3435
svg = ["dep:resvg"]
3536

@@ -59,3 +60,6 @@ serde = {version= "1", optional = true, features = ["derive", "rc"] }
5960

6061
[target.'cfg(target_arch = "wasm32")'.dependencies]
6162
web-sys = { version = "0.3", features = ['Document', 'Window'] }
63+
64+
[patch.crates-io]
65+
gltf = { git="https://github.com/gltf-rs/gltf", rev="a29fb756fd91913e3b6452036cdbe65a0932ac20" }

src/io/img.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ pub fn serialize_img(tex: &Texture2D, path: &Path) -> Result<RawAssets> {
136136
#[cfg(feature = "gif")]
137137
ImageFormat::Gif
138138
}
139+
"webp" => {
140+
#[cfg(not(feature = "webp"))]
141+
return Err(Error::FeatureMissing("webp".to_string()));
142+
#[cfg(feature = "webp")]
143+
ImageFormat::WebP
144+
}
139145
_ => return Err(Error::FailedSerialize(path.to_str().unwrap().to_string())),
140146
};
141147
let img = match &tex.data {
@@ -308,6 +314,13 @@ mod test {
308314
assert_eq!(tex.height, 512);
309315
}
310316

317+
#[cfg(feature = "webp")]
318+
#[test]
319+
pub fn webp() {
320+
test_serialize("webp");
321+
test_deserialize("webp");
322+
}
323+
311324
#[cfg(feature = "svg")]
312325
#[test]
313326
pub fn svg() {

test_data/test.webp

160 Bytes
Loading

0 commit comments

Comments
 (0)