aclysma / basis-universal-rs Goto Github PK
View Code? Open in Web Editor NEWBindings for Binomial LLC's basis-universal Supercompressed GPU Texture Codec
License: Apache License 2.0
Bindings for Binomial LLC's basis-universal Supercompressed GPU Texture Codec
License: Apache License 2.0
It's possible to get a CompressorImageRef from CompressorParams, drop CompressorParams, and cause undefined behavior by using CompressorImageRef. Some API improvements would enable rust borrow checking to catch this at compile time.
Could consider implementing:
CC @superdump
I've been working on writing bindings for the transcoder wasm that basis_universal provides so that I can parse and transcode basis files in wasm. I've got a repo for this here:
https://github.com/expenses/basis-universal-rs-wasm
It'd be fantastic if we could get support for this into this crate, so that wasm support just works. A couple of notes:
I had to set EXPORT_ES6=1
in the emscripten link flags:
I don't know if I strictly needed to do this, but it made binding with wasm-bindgen via #[wasm_bindgen(js_name = default)]
a lot easier.
The emscripten code loads the module asyncronously, which means you can't directly import the exports in wasm-bindgen because they're only created after initialisation. To work around this I had to use reflection to create the javascript classes: https://github.com/expenses/basis-universal-rs-wasm/blob/8274f56092c930bb0dfbb35b0386235a3c5a9813/src/lib.rs#L36-L38
By default the emscripten code attempts to load the wasm binary from a relative url. Because wasm-bindgen copies the referenced javascript module to a snippet such as pkg/snippets/basis-universal-wasm-8dd816e8505190b7/basis_universal/webgl/transcoder/build/basis_transcoder.js
but does not copy anything else. this load fails.
Luckily the code allows settings a wasmBinary
key in the object that's passed in, so you can provide your own wasm file: https://github.com/expenses/basis-universal-rs-wasm/blob/master/src/lib.rs#L26-L31. I just include_bytes!
the file for ease of use.
Because the wrapper API is quite different from the normal API, we're probably going to have to write our own wrapper to bring the APIs to parity.
This will all take a while, but I'll try to create good bindings for the .basisu
transcoder and work from there.
Upstream basis-universal now supports ktx2 files. It would be good if this library did as well.
@cwfitzgerald suggested preventing people from transcoding without first calling prepare by making prepare return a new type
When comparing the performance against the original CLI / basisu.exe version, it appears that multithreading doesn't work.
The timings in get on my machine with a test image:
I'm on Windows 10 x64 with this toolchain:
stable-x86_64-pc-windows-msvc (default)
rustc 1.68.0 (2c8cc3432 2023-03-06)
My code for reference
use basis_universal::*;
let img = image::open("test_image.png").unwrap();
basis_universal::encoder_init();
let mut params = CompressorParams::new();
params.set_print_status_to_stdout(true);
let mut compressor_image = params.source_image_mut(0);
compressor_image.init(&img.to_rgba8(), img.width(), img.height(), 4);
let mut compressor = encoding::Compressor::new(24); //explicit multi-threading
let compression_time = unsafe {
compressor.init(¶ms);
let t0 = std::time::Instant::now();
compressor.process().unwrap();
let t1 = std::time::Instant::now();
t1 - t0
};
println!("compression took {}secs", compression_time.as_secs_f32());
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.