-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<link data-trunk rel="css" href="./styles.css" /> | ||
<link rel="stylesheet" | ||
href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" | ||
/> | ||
</head> | ||
<body></body> | ||
<head> | ||
<link data-trunk rel="css" href="./styles.css" /> | ||
<link | ||
data-trunk | ||
rel="rust" href="../../Cargo.toml" | ||
data-bin="cega-webc" | ||
data-cargo-no-default-features | ||
data-cargo-features="webc" | ||
/> | ||
<script> | ||
const fileReader = new FileReader(); | ||
fileReader.onloadend = function() { | ||
var array = new Int8Array(fileReader.result); | ||
document.getElementById('preview').src = window.wasmBindings.png(array); | ||
} | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const fileInput = document.getElementById('file-input'); | ||
fileInput.addEventListener("change", e => fileReader.readAsArrayBuffer(fileInput.files[0])); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<h1>Process your CGA/EGAs</h1> | ||
<input id="file-input" multiple="false" type="file" accept=".bin,.cga,.ega,.cega" /> | ||
<img id="preview" src="" /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
#![cfg(feature = "webc")] | ||
|
||
use base64::engine::general_purpose::STANDARD; | ||
use base64::Engine; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use cega::color::palette::palette_from_abbr; | ||
use cega::file_data::Raw; | ||
use cega::parser::ParserType; | ||
use cega::png; | ||
|
||
#[wasm_bindgen] | ||
pub fn png(data: &[u8]) -> String { | ||
let file_data = Raw::new(data); | ||
let parser = ParserType::CGA; | ||
let image = file_data.parse(parser, 320); | ||
let palette = palette_from_abbr("cga0"); | ||
let mut bytes: Vec<u8> = Vec::new(); | ||
let _ = png::write_to(&mut bytes, image.data(), palette.clone()); | ||
format!("data:application/png;base64,{}", STANDARD.encode(bytes)) | ||
} | ||
|
||
fn main() {} |