dont know what dis was about, now it's time for revolution
This commit is contained in:
parent
d69011ddb6
commit
42bd1a49f4
4 changed files with 62 additions and 14 deletions
|
@ -10,7 +10,7 @@ package.keywords = ["databending", "data-bending", "bending", "bend", "art"]
|
|||
|
||||
[workspace.dependencies]
|
||||
fundsp = "0.18.2"
|
||||
image = "0.25.1"
|
||||
image = { version = "0.25.1", features = ["rayon"] }
|
||||
anyhow = "1.0.86"
|
||||
bingus = { version = "0.1.0", path = "bingus" }
|
||||
num-traits = "0.2.19"
|
||||
|
|
|
@ -15,6 +15,10 @@ crate-type = ["cdylib"]
|
|||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2"
|
||||
image = { workspace = true }
|
||||
dasp_sample = { workspace = true }
|
||||
bingus = { workspace = true }
|
||||
fundsp = { workspace = true }
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
|
|
@ -18,16 +18,13 @@
|
|||
a.download = filename;
|
||||
a.click();
|
||||
}
|
||||
const name = () => { return document.getElementById("name").value; };
|
||||
const files = () => { return Array.from(document.getElementById("files").files).map(x => x.name); };
|
||||
</script>
|
||||
<script type="module">
|
||||
import init, { greet } from "./pkg/bent.js";
|
||||
init().then(() => {
|
||||
document.getElementById("greet-button").onclick = () => {
|
||||
greet(name());
|
||||
};
|
||||
document.getElementById("download").onclick = () => {
|
||||
download(name(), "name.txt", "text/plain");
|
||||
document.getElementById("verify-button").onclick = () => {
|
||||
console.log(files());
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
@ -39,15 +36,12 @@
|
|||
|
||||
<form onsubmit="return false;">
|
||||
<p>
|
||||
<label>Enter your name:</label>
|
||||
<input type="text" id="name" />
|
||||
<label>Select some files:</label>
|
||||
<input type="file" id="files" multiple="true" />
|
||||
</p>
|
||||
<button id="greet-button">Greet</button>
|
||||
<button id="verify-button">Verify</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
||||
<p>
|
||||
<button id="download">Download</button>
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,4 +1,8 @@
|
|||
use wasm_bindgen::prelude::*;
|
||||
use bingus::rawdata::RawData;
|
||||
use dasp_sample::U24;
|
||||
use fundsp::math::uparc;
|
||||
use image::{ImageReader, RgbImage};
|
||||
use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*};
|
||||
#[allow(unused_macros)]
|
||||
#[macro_use]
|
||||
pub mod macros;
|
||||
|
@ -8,3 +12,49 @@ pub mod js;
|
|||
pub fn greet(name: &str) {
|
||||
println!("Hello, {name}!");
|
||||
}
|
||||
|
||||
#[wasm_bindgen(getter_with_clone)]
|
||||
pub struct ImageFile {
|
||||
pub name: String,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn process_files(files: Vec<ImageFile>) {
|
||||
files.into_iter().for_each(|file| {
|
||||
let img = RawData::<RgbImage>::new(
|
||||
ImageReader::open(file.name)
|
||||
.unwrap()
|
||||
.decode()
|
||||
.unwrap()
|
||||
.into_rgb8(),
|
||||
);
|
||||
img.par_pixels_mut().for_each(|px| {
|
||||
let sample = uparc(
|
||||
U24::new_unchecked((px[2] as i32) | ((px[1] as i32) << 8) | ((px[0] as i32) << 16))
|
||||
.to_sample(),
|
||||
);
|
||||
});
|
||||
let processed = RawData::<RgbImage>::new(
|
||||
RgbImage::from_raw(
|
||||
img.width(),
|
||||
img.height(),
|
||||
img.par_chunks_exact(3)
|
||||
.map(|px: &[u8]| {
|
||||
(px[2] as i32) | ((px[1] as i32) << 8) | ((px[0] as i32) << 16)
|
||||
})
|
||||
.map(U24::new_unchecked)
|
||||
.map(|x| uparc(x.to_sample()))
|
||||
.flat_map(|sample: f32| {
|
||||
let rgb: U24 = sample.to_sample();
|
||||
let rgo = ((rgb) >> 8.into()) << 8.into();
|
||||
let roo = ((rgo) >> 16.into()) << 16.into();
|
||||
vec![roo, rgo, rgb]
|
||||
})
|
||||
.collect::<Vec<u8>>(),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
let _ = processed;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue