M .gitignore => .gitignore +1 -0
@@ 1,1 1,2 @@
/target
+/ignored
M Cargo.toml => Cargo.toml +8 -1
@@ 1,6 1,6 @@
[package]
name = "text-to-piet"
-version = "0.2.0"
+version = "0.3.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ 12,3 12,10 @@ clap = { version = "~3.1", features = ["derive"] }
ron = "~0.7"
anyhow = "~1.0"
serde = { version = "~1.0", features = ["derive"] }
+
+[profile.small]
+inherits = "release"
+opt-level = "z"
+strip = "symbols"
+lto = true
+codegen-units = 1
A resources/binary/C/id => resources/binary/C/id +0 -0
A resources/binary/C/id.c => resources/binary/C/id.c +1 -0
@@ 0,0 1,1 @@
+int main() { return 0; }
A resources/binary/C/smol => resources/binary/C/smol +0 -0
M src/colors.rs => src/colors.rs +1 -0
@@ 225,6 225,7 @@ impl Color {
Instructions::DUP => (0, 4),
Instructions::POINTER => (1, 3),
Instructions::OUTCHAR => (2, 5),
+ Instructions::OUTNUM => (1, 5),
};
let next_tuple = (
M src/instructions.rs => src/instructions.rs +14 -0
@@ 24,6 24,7 @@ pub enum Instructions {
DUP,
POINTER,
OUTCHAR,
+ OUTNUM,
}
pub trait PietEncoder {
@@ 53,6 54,19 @@ pub trait PietEncoder {
instructions
}
+
+ fn encode_bytes(&self, bytes: &[u8]) -> Vec<Instructions> {
+ let mut instructions = self.gen_num(bytes[0] as i64);
+ instructions.push(DUP);
+ instructions.push(OUTNUM);
+
+ for (&prev, &n) in bytes.iter().zip(bytes[1..].iter()) {
+ instructions.append(&mut self.gen_num_prev(prev as i64, n as i64));
+ instructions.push(OUTNUM);
+ }
+
+ instructions
+ }
}
struct EncoderByDoubling {}
M src/main.rs => src/main.rs +3 -5
@@ 30,13 30,11 @@ struct Args {
fn main() -> Result<()> {
let args = Args::parse();
- let input = fs::read_to_string(args.input_file).context("Failed to read input file")?;
-
+ let input_bytes = fs::read(args.input_file).context("Failed to read input file")?;
let encoder = instructions::EncoderBFS::new("instruction_cache/bfs_instructions.ron");
+ let instrs_bytes = encoder.encode_bytes(&input_bytes);
- let instrs = encoder.encode_text(&input);
-
- let mut imager = piet_image::PietImager::with_instructions(instrs);
+ let mut imager = piet_image::PietImager::with_instructions(instrs_bytes);
if let Some(img_size) = args.img_size {
imager