3 Commits

Author SHA1 Message Date
b157007ff3 restrict file types and add help text about game data 2020-11-28 18:33:11 +00:00
704f710047 fix syntax 2020-11-28 15:57:19 +00:00
5c4259d222 better splash page for now 2020-11-28 15:15:40 +00:00
3 changed files with 34 additions and 63 deletions

View File

@@ -13,7 +13,6 @@ crate-type = ["cdylib"]
[dependencies]
base64 = "^0.12.3"
bitsy-parser = "^0.72.5"
dither = "^1.3.9"
image = "^0.23.7"
json = "^0.12.4"
lazy_static = "^1.4.0"

View File

@@ -12,7 +12,7 @@ html(lang="en-gb")
| pixsy
//img(alt="pixsy" src="includes/pixsy.png")
p.
convert images to Bitsy rooms
version 0.72.7
|
#[a(href="http://tinybird.info/image-to-bitsy/old/" target="_blank") old version]
|
@@ -21,12 +21,30 @@ html(lang="en-gb")
#[a(href="https://twitter.com/synth_ruiner") twitter]
.pages
.page#start
p.
#[b pixsy] is a tool for #[a(href="http://bitsy.org/") Bitsy Game Maker]
that allows you to generate a room from an image and add it to your game.
p this version is compatible with Bitsy version 7.2 and earlier.
p.
#[b pixsy] does not currently work via the Itch desktop program.
some users are also currently reporting problems.
if pixsy does not work for you, please try the
#[a(href="http://tinybird.info/image-to-bitsy/old/") old version] instead.
p.
instructions can be found on the
#[a(href="https://ruin.itch.io/pixsy/") itch.io page] -
scroll down to "how to use".
button.normal.pagination.next#new create a new bitsy game
button.normal.pagination.next#load load an existing bitsy game
.page.game-data
h2 game data
input#game(type="file" autocomplete="off")
p.
your game data is available from the #[i game data] window in bitsy,
under the #[i tools] dropdown.
input#game(type="file" accept=".bitsy,.txt" autocomplete="off")
br
textarea#game-data(
@@ -74,12 +92,9 @@ html(lang="en-gb")
input#colour-foreground(type="color" value="#ffffff")
label
input#dither(type="checkbox" checked=true)
| dither
select#dither
option None
option(value="Atkinson" selected=true) Atkinson
option(value="Bayer4x4") Bayer 4×4
option(value="FloydSteinberg") Floyd-Steinberg
br
button.pagination.prev#back-to-image previous
button.pagination.next#room-next add room

View File

@@ -3,7 +3,6 @@
use bitsy_parser::game::Game;
use bitsy_parser::image::Image;
use bitsy_parser::tile::Tile;
use dither::prelude::Dither;
use image::{GenericImageView, Pixel, DynamicImage};
use image::imageops::ColorMap;
use image::imageops::FilterType::CatmullRom;
@@ -28,18 +27,12 @@ enum SelectedPalette {
}
}
enum DitherAlgorithm {
Atkinson,
Bayer4x4,
FloydSteinberg,
}
struct State {
game: Option<Game>,
image: Option<DynamicImage>,
room_name: Option<String>,
palette: SelectedPalette,
dither: Option<DitherAlgorithm>,
dither: bool,
brightness: i32,
}
@@ -50,7 +43,7 @@ lazy_static! {
image: None,
room_name: None,
palette: SelectedPalette::None,
dither: Some(DitherAlgorithm::Atkinson),
dither: true,
brightness: 0,
}
);
@@ -133,15 +126,9 @@ pub fn load_image(image_base64: String) -> String {
}
#[wasm_bindgen]
pub fn set_dither(dither: &str) {
pub fn set_dither(dither: bool) {
let mut state = STATE.lock().unwrap();
state.dither = match dither {
"Atkinson" => Some(DitherAlgorithm::Atkinson),
"Bayer4x4" => Some(DitherAlgorithm::Bayer4x4),
"FloydSteinberg" => Some(DitherAlgorithm::FloydSteinberg),
_ => None,
}
state.dither = dither;
}
#[wasm_bindgen]
@@ -217,55 +204,25 @@ fn render_preview(state: &State) -> DynamicImage {
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba();
let palette = match &state.palette {
SelectedPalette::None => {
bitsy_parser::mock::game_default().palettes[0].clone()
},
SelectedPalette::Existing { id } => {
state.game.as_ref().unwrap().get_palette(id).unwrap().clone()
},
SelectedPalette::New { background, foreground } => {
palette_from(background, foreground)
},
SelectedPalette::None => bitsy_parser::mock::game_default().palettes[0].clone(),
SelectedPalette::Existing { id } => state.game.as_ref().unwrap().get_palette(id).unwrap().clone(),
SelectedPalette::New { background, foreground } => palette_from(background, foreground),
};
let colour_map = crate::ColourMap::from(&palette);
// adjust brightness
let mut buffer = image::imageops::brighten(
&mut buffer,
state.brightness
);
let mut buffer = image::imageops::brighten(&mut buffer, state.brightness);
if state.dither.is_some() {
// image::imageops::dither(&mut buffer, &colour_map);
// so, what needs doing?
// convert the buffer to the format required by the dither crate
let dither_img = dither::prelude::Img::new(buffer.iter(), 128).unwrap();
// run the dither according to user preference
// todo what is the quantise function supposed to be like?
// dither::ditherer::ATKINSON.dither(dither_img, colour_map);
// convert the dither format back to an ImageBuffer
// buffer = image::ImageBuffer::new(128, 128); //from_vec(128, 128, pixels).unwrap();
//
// for pixel in dither_img.iter() {
// // todo enumerate?
// buffer.put_pixel(0,0, image::Rgba::from([0,0,0,0]));
// }
if state.dither {
image::imageops::dither(&mut buffer, &colour_map);
} else {
// just do colour indexing
let colour_indices = 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 = colour_indices.get_pixel(x, y);
let p = indices.get_pixel(x, y);
colour_map
.lookup(p.0[0] as usize)