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
| brightness
input#brightness(type="range" min=-96 max=96 value=0)
td(style="vertical-align: top;")
input#brightness(type="range" min=-64 max=64 value=0)
td
label
| palette
select#palette
label
input#dither(type="checkbox" checked=true)
input#dither(type="checkbox")
| dither
br

View File

@ -93,7 +93,7 @@ async function run() {
}
function new_game() {
console.debug(load_default_game());
load_default_game()
textareaGameDataInput.value = output();
checkGameData();
// 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() {
const palettes = JSON.parse(get_palettes());
console.debug(palettes);
let palettes = JSON.parse(get_palettes());
selectPalette.innerHTML = "";

View File

@ -4,8 +4,6 @@ use bitsy_parser::game::Game;
use bitsy_parser::image::Image;
use bitsy_parser::tile::Tile;
use image::{GenericImageView, Pixel, DynamicImage};
use image::imageops::ColorMap;
use image::imageops::FilterType::CatmullRom;
use lazy_static::lazy_static;
use std::sync::Mutex;
use wasm_bindgen::prelude::*;
@ -64,7 +62,7 @@ pub fn load_game(game_data: String) -> String {
let palette_id = game.palette_ids()[0].clone();
state.game = Some(game);
state.palette = Some(palette_id);
format!("Loaded game")
"".to_string()
},
_ => {
state.game = None;
@ -85,7 +83,6 @@ pub fn load_image(image_base64: String) -> String {
Ok(image) => {
match image::load_from_memory(image.as_ref()) {
Ok(image) => {
// todo get rid of magic numbers! what about Bitsy HD?
let image = image.resize(128, 128, CatmullRom);
state.image = Some(image);
"OK"
@ -169,36 +166,15 @@ fn render_preview(state: &State) -> DynamicImage {
// todo get actual chosen palette
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 mut buffer = image::imageops::brighten(&mut buffer, state.brightness);
image::imageops::brighten(&mut buffer, state.brightness);
if state.dither {
image::imageops::dither(&mut buffer, &colour_map);
} else {
// just do colour indexing
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::imageops::colorops::index_colors(&mut buffer, &colour_map);
}
image::DynamicImage::ImageRgba8(buffer)