Compare commits

..

No commits in common. "45ef41c3668b455dd8b42fab05be03f7b382ea57" and "ec44370d7e2ee30449e06875e3e1e4f004c33732" have entirely different histories.

3 changed files with 11 additions and 36 deletions

View File

@ -56,14 +56,14 @@ html(lang="en-gb")
label label
| brightness | brightness
input#brightness(type="range" min=-96 max=96 value=0) input#brightness(type="range" min=-64 max=64 value=0)
td(style="vertical-align: top;") td
label label
| palette | palette
select#palette select#palette
label label
input#dither(type="checkbox" checked=true) input#dither(type="checkbox")
| dither | dither
br br

View File

@ -93,7 +93,7 @@ async function run() {
} }
function new_game() { function new_game() {
console.debug(load_default_game()); load_default_game()
textareaGameDataInput.value = output(); textareaGameDataInput.value = output();
checkGameData(); checkGameData();
// we don't need to look at the default game data, so skip ahead to the image page // we don't need to look at the default game data, so skip ahead to the image page
@ -121,8 +121,7 @@ async function run() {
}); });
function setPaletteDropdown() { function setPaletteDropdown() {
const palettes = JSON.parse(get_palettes()); let palettes = JSON.parse(get_palettes());
console.debug(palettes);
selectPalette.innerHTML = ""; selectPalette.innerHTML = "";

View File

@ -4,8 +4,6 @@ use bitsy_parser::game::Game;
use bitsy_parser::image::Image; use bitsy_parser::image::Image;
use bitsy_parser::tile::Tile; use bitsy_parser::tile::Tile;
use image::{GenericImageView, Pixel, DynamicImage}; use image::{GenericImageView, Pixel, DynamicImage};
use image::imageops::ColorMap;
use image::imageops::FilterType::CatmullRom;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::sync::Mutex; use std::sync::Mutex;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
@ -64,7 +62,7 @@ pub fn load_game(game_data: String) -> String {
let palette_id = game.palette_ids()[0].clone(); let palette_id = game.palette_ids()[0].clone();
state.game = Some(game); state.game = Some(game);
state.palette = Some(palette_id); state.palette = Some(palette_id);
format!("Loaded game") "".to_string()
}, },
_ => { _ => {
state.game = None; state.game = None;
@ -85,7 +83,6 @@ pub fn load_image(image_base64: String) -> String {
Ok(image) => { Ok(image) => {
match image::load_from_memory(image.as_ref()) { match image::load_from_memory(image.as_ref()) {
Ok(image) => { Ok(image) => {
// todo get rid of magic numbers! what about Bitsy HD?
let image = image.resize(128, 128, CatmullRom); let image = image.resize(128, 128, CatmullRom);
state.image = Some(image); state.image = Some(image);
"OK" "OK"
@ -165,40 +162,19 @@ fn image_to_base64(image: &DynamicImage) -> String {
} }
fn render_preview(state: &State) -> DynamicImage { fn render_preview(state: &State) -> DynamicImage {
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba(); let mut buffer = state.image.as_ref().unwrap().clone().into_rgba();
// todo get actual chosen palette // todo get actual chosen palette
let palette_id = state.palette.as_ref().unwrap(); let palette_id = state.palette.as_ref().unwrap();
let palette = *&state.game.as_ref().unwrap().get_palette(palette_id).unwrap(); let palette = &state.game.as_ref().unwrap().get_palette(palette_id).unwrap();
let colour_map = crate::ColourMap::from(palette); let colour_map = crate::ColourMap::from(palette);
let mut buffer = image::imageops::brighten(&mut buffer, state.brightness); image::imageops::brighten(&mut buffer, state.brightness);
if state.dither { if state.dither {
image::imageops::dither(&mut buffer, &colour_map); image::imageops::dither(&mut buffer, &colour_map);
} else { } else {
// just do colour indexing image::imageops::colorops::index_colors(&mut buffer, &colour_map);
let indices = image::imageops::colorops::index_colors(&mut buffer, &colour_map);
// todo get rid of magic numbers! what about Bitsy HD?
buffer = image::ImageBuffer::from_fn(128, 128, |x, y| -> image::Rgba<u8> {
let p = indices.get_pixel(x, y);
colour_map
.lookup(p.0[0] as usize)
.expect("indexed color out-of-range")
.into()
});
let mut indexed = buffer.clone();
for (i, pixel) in buffer.pixels().enumerate() {
// todo get rid of magic numbers! what about Bitsy HD?
let mut pixel = image::Rgba::from(pixel.0);
colour_map.map_color(&mut pixel);
indexed.put_pixel(
(i % 128) as u32,
(i / 128) as u32,
pixel
);
}
} }
image::DynamicImage::ImageRgba8(buffer) image::DynamicImage::ImageRgba8(buffer)