Compare commits
1 Commits
master
...
dithering-
Author | SHA1 | Date |
---|---|---|
Max Bradbury | 0324f5f389 |
|
@ -1,19 +1,20 @@
|
|||
[package]
|
||||
name = "pixsy"
|
||||
version = "0.710.0"
|
||||
version = "0.72.7"
|
||||
description = "convert images to Bitsy rooms"
|
||||
authors = ["Max Bradbury <max@tinybird.info>"]
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
repository = "https://tinybird.dev/max/pixsy"
|
||||
repository = "https://tinybird.dev/max/image-to-bitsy"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
base64 = "^0.12.3"
|
||||
bitsy-parser = "^0.710.0"
|
||||
bitsy-parser = "^0.72.5"
|
||||
dither = "^1.3.9"
|
||||
image = "^0.23.7"
|
||||
json = "^0.12.4"
|
||||
lazy_static = "^1.4.0"
|
||||
wasm-bindgen = "^0.2.78"
|
||||
wasm-bindgen = "=0.2.64" # newer versions are bugged...
|
||||
|
|
|
@ -22,11 +22,6 @@ button {
|
|||
white-space: nowrap;
|
||||
width: 100%;
|
||||
|
||||
&.half {
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
&.pagination:not(.normal) {
|
||||
position: absolute;
|
||||
bottom: 5vmin;
|
||||
|
|
49
index.pug
49
index.pug
|
@ -8,9 +8,11 @@ html(lang="en-gb")
|
|||
script(src="includes/croppie.min.js")
|
||||
body
|
||||
header
|
||||
h1 pixsy
|
||||
h1
|
||||
| pixsy
|
||||
//img(alt="pixsy" src="includes/pixsy.png")
|
||||
p.
|
||||
version 0.710.0
|
||||
convert images to Bitsy rooms
|
||||
|
|
||||
#[a(href="http://tinybird.info/image-to-bitsy/old/" target="_blank") old version]
|
||||
|
|
||||
|
@ -19,35 +21,12 @@ html(lang="en-gb")
|
|||
#[a(href="https://twitter.com/synth_ruiner") twitter]
|
||||
.pages
|
||||
.page#start
|
||||
p.
|
||||
#[b pixsy] is a tool for #[a(href="https://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 tested to be compatible with Bitsy version 7.10 and earlier.
|
||||
later versions may also work fine, but make sure you have a backup of your game data.
|
||||
p.
|
||||
#[b pixsy] does not currently work via the Itch desktop program.
|
||||
if pixsy does not work for you, please try the
|
||||
#[a(href="http://tinybird.info/image-to-bitsy/old/") old version] instead.
|
||||
p.
|
||||
if your image is already the correct size for a bitsy room (128×128),
|
||||
simply leave the zoom slider at the default setting.
|
||||
you can draw your room in a pixel-art program and import it here.
|
||||
p.
|
||||
full 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
|
||||
|
||||
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")
|
||||
input#game(type="file" autocomplete="off")
|
||||
br
|
||||
|
||||
textarea#game-data(
|
||||
|
@ -95,22 +74,24 @@ html(lang="en-gb")
|
|||
input#colour-foreground(type="color" value="#ffffff")
|
||||
|
||||
label
|
||||
input#dither(type="checkbox")
|
||||
| dither
|
||||
p (approximates a greyscale effect)
|
||||
br
|
||||
select#dither
|
||||
option None
|
||||
option(value="Atkinson" selected=true) Atkinson
|
||||
option(value="Bayer4x4") Bayer 4×4
|
||||
option(value="FloydSteinberg") Floyd-Steinberg
|
||||
|
||||
button.pagination.prev#back-to-image previous
|
||||
button.pagination.next#room-next add room
|
||||
.page.download
|
||||
h2 done!
|
||||
|
||||
p#added
|
||||
|
||||
textarea#output(autocomplete="off")
|
||||
h2 download
|
||||
|
||||
button#clipboard.half copy to clipboard
|
||||
button#download.half download
|
||||
textarea#output(autocomplete="off")
|
||||
br
|
||||
|
||||
button#download download
|
||||
|
||||
button.pagination.prev#add add another image
|
||||
button.pagination.start#reset start again
|
||||
|
|
22
script.js
22
script.js
|
@ -24,18 +24,6 @@ function download(filename, text) {
|
|||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
function copyToClipboard() {
|
||||
const button = el("clipboard");
|
||||
|
||||
el("output").select();
|
||||
document.execCommand("copy");
|
||||
button.innerText = "copied!";
|
||||
|
||||
setTimeout(() => {
|
||||
button.innerText = "copy to clipboard";
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function el(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
@ -76,7 +64,6 @@ async function run() {
|
|||
|
||||
const buttonAddImage = el("add");
|
||||
const buttonBackToImage = el("back-to-image");
|
||||
const buttonCopyToClipboard = el("clipboard")
|
||||
const buttonDownload = el("download");
|
||||
const buttonGameDataProceed = el("game-data-next");
|
||||
const buttonImageProceed = el("image-next");
|
||||
|
@ -139,12 +126,14 @@ async function run() {
|
|||
el("game").addEventListener("change", function() {
|
||||
readFile(this, function (e) {
|
||||
textareaGameDataInput.value = e.target.result;
|
||||
console.log(load_game(e.target.result));
|
||||
checkGameData();
|
||||
}, "text");
|
||||
});
|
||||
|
||||
function setPaletteDropdown() {
|
||||
const palettes = JSON.parse(get_palettes());
|
||||
console.debug(palettes);
|
||||
|
||||
selectPalette.innerHTML = "";
|
||||
|
||||
|
@ -164,9 +153,7 @@ async function run() {
|
|||
}
|
||||
|
||||
function checkGameData() {
|
||||
let result = load_game(textareaGameDataInput.value)
|
||||
|
||||
if (result === "Loaded game") {
|
||||
if (textareaGameDataInput.value.length > 0) {
|
||||
buttonGameDataProceed.removeAttribute("disabled");
|
||||
setPaletteDropdown();
|
||||
} else {
|
||||
|
@ -254,9 +241,6 @@ async function run() {
|
|||
download("output.bitsy", textareaGameDataOutput.value);
|
||||
}
|
||||
|
||||
buttonCopyToClipboard.addEventListener("click", copyToClipboard);
|
||||
buttonCopyToClipboard.addEventListener("touchend", copyToClipboard);
|
||||
|
||||
buttonDownload.addEventListener("click", handleDownload);
|
||||
buttonDownload.addEventListener("touchend", handleDownload);
|
||||
|
||||
|
|
81
src/lib.rs
81
src/lib.rs
|
@ -1,6 +1,9 @@
|
|||
#![feature(clamp)]
|
||||
|
||||
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;
|
||||
|
@ -25,12 +28,18 @@ enum SelectedPalette {
|
|||
}
|
||||
}
|
||||
|
||||
enum DitherAlgorithm {
|
||||
Atkinson,
|
||||
Bayer4x4,
|
||||
FloydSteinberg,
|
||||
}
|
||||
|
||||
struct State {
|
||||
game: Option<Game>,
|
||||
image: Option<DynamicImage>,
|
||||
room_name: Option<String>,
|
||||
palette: SelectedPalette,
|
||||
dither: bool,
|
||||
dither: Option<DitherAlgorithm>,
|
||||
brightness: i32,
|
||||
}
|
||||
|
||||
|
@ -41,7 +50,7 @@ lazy_static! {
|
|||
image: None,
|
||||
room_name: None,
|
||||
palette: SelectedPalette::None,
|
||||
dither: false,
|
||||
dither: Some(DitherAlgorithm::Atkinson),
|
||||
brightness: 0,
|
||||
}
|
||||
);
|
||||
|
@ -124,9 +133,15 @@ pub fn load_image(image_base64: String) -> String {
|
|||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn set_dither(dither: bool) {
|
||||
pub fn set_dither(dither: &str) {
|
||||
let mut state = STATE.lock().unwrap();
|
||||
state.dither = dither;
|
||||
|
||||
state.dither = match dither {
|
||||
"Atkinson" => Some(DitherAlgorithm::Atkinson),
|
||||
"Bayer4x4" => Some(DitherAlgorithm::Bayer4x4),
|
||||
"FloydSteinberg" => Some(DitherAlgorithm::FloydSteinberg),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -199,28 +214,58 @@ fn palette_from(bg: &bitsy_parser::Colour, fg: &bitsy_parser::Colour) -> bitsy_p
|
|||
}
|
||||
|
||||
fn render_preview(state: &State) -> DynamicImage {
|
||||
let mut buffer = state.image.as_ref().unwrap().clone().into_rgba8();
|
||||
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 {
|
||||
image::imageops::dither(&mut buffer, &colour_map);
|
||||
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]));
|
||||
// }
|
||||
} else {
|
||||
// just do colour indexing
|
||||
let indices = image::imageops::colorops::index_colors(&mut buffer, &colour_map);
|
||||
let colour_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);
|
||||
let p = colour_indices.get_pixel(x, y);
|
||||
|
||||
colour_map
|
||||
.lookup(p.0[0] as usize)
|
||||
|
@ -247,18 +292,18 @@ pub fn add_room() -> String {
|
|||
let mut state = STATE.lock().expect("Couldn't lock application state");
|
||||
|
||||
if state.game.is_none() {
|
||||
return "No game data loaded".into();
|
||||
return "No game data loaded".to_string();
|
||||
}
|
||||
|
||||
match &state.palette {
|
||||
SelectedPalette::None => { return "No palette selected".into(); },
|
||||
SelectedPalette::None => { return "No palette selected".to_string(); },
|
||||
_ => {}
|
||||
};
|
||||
|
||||
let mut game = state.game.clone().unwrap();
|
||||
|
||||
if state.image.is_none() {
|
||||
return "No image loaded".into();
|
||||
return "No image loaded".to_string();
|
||||
}
|
||||
|
||||
let palette_id = Some(match &state.palette {
|
||||
|
@ -290,7 +335,7 @@ pub fn add_room() -> String {
|
|||
|
||||
fn colour_match(a: &image::Rgb<u8>, b: &bitsy_parser::Colour) -> u8 {
|
||||
if a[0] == b.red && a[1] == b.green && a[2] == b.blue { 1 } else { 0 }
|
||||
}
|
||||
};
|
||||
|
||||
for y in (row * SD)..((row + 1) * SD) {
|
||||
for x in (column * SD)..((column + 1) * SD) {
|
||||
|
@ -377,7 +422,7 @@ mod test {
|
|||
load_default_game();
|
||||
load_image(include_str!("test-resources/colour_input.png.base64").trim().to_string());
|
||||
let output = get_preview();
|
||||
let expected = include_str!("test-resources/colour_input.png.base64.blueprint").trim();
|
||||
let expected = include_str!("test-resources/colour_input.png.base64.greyscale").trim();
|
||||
assert_eq!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kAC6VWal9f9SjeV4F6BM4T5tJTJb212sIzdBS3CUCFJe1nvYd397QFZyNwPvOsk15fPK9aoX+W6QFgMRZJlZ7v6SvkM9boCJiVMJeeKvqqPfKcegTTAwAuJSyXvep7eG9Pe3A+An6DWWiLrTPI86zFHnqW6QFgEWGhI76nR8n71ugomAfMpK6a2FNlzwO9s9wiACyCyp7v4b09lZYfRc6t8Dut81Y/e9apZ5kaAJZIWCh71YM9FbJ+B59HR+Cslib2VNnzQv8sUwMALMYiaI+t8zyzViFr0KsJvVHU2cJvHDnLWuylnmVqAFgiYSF6asW++gqtZ+yljoBZwky8Knq1hWdqhf5ZpgWAhVgAhazFnlrJfqtWRa9W6I+C+cxDk1YP7KstPEs9y7QAAEtUWKrVh9ZZq5dsnXuWOgrmJcw+0gP7VSv0zzItAC7EEtSq6FXRq6KvKnq1BWej8DeYaS21p1d75Dn1CKYFAFwmYbHab/Vk6wx65/ZTR+JMVPZ8kmdZgx49y7QAsACwBLUqPV9V9FVFr7bgbBT5G8w94tUe9Rx/likBYAleHq3UfvWVd8/tq0A9CmYyDwXqLbwH3MVXTeiNYEoAIBdimfRQe/qqkj7rZK+PjoJ5ySuz67MJc/Icf4YpAXABXt4aqodWL6nn6a1V0auCHwVzmae+g8+mJvTOMiUAkMuwiN5alfRZS6tX6d2xj46Cecm7s1tzsoc/w5QAuAAvb92j3kmfdZL9rMWeCtSjYfaoucxKmEsPPcOUAAAvLyyBr5q0emBflT3fgjujyN8aNZeZzEIFf4YpAWABXhzt4bkqejXZ61lv6UiYCaPmOg+YiUfPMCUAwMsDC1BXrbzSr73qW3BnJPweM1GgPguzmIMK/gxTApAL9GAx7qlSvdR+9WCvKlCP5orZzkzOzP8HNQ0vxIkGykwAAAAASUVORK5CYII=
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
Write your game's title here
|
||||
|
||||
# BITSY VERSION 7.5
|
||||
# BITSY VERSION 7.2
|
||||
|
||||
! ROOM_FORMAT 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue