|
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
|
use std::collections::HashMap;
|
|
use std::collections::HashMap;
|
|
use std::io::{Read, Seek, Write};
|
|
use std::io::{Read, Seek, Write};
|
|
|
|
|
|
-const CURRENT_VERSION: &'static str = "0";
|
|
|
|
|
|
+const CURRENT_VERSION: &str = "0";
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub enum StitchType {
|
|
pub enum StitchType {
|
|
@@ -16,11 +16,11 @@ pub enum StitchType {
|
|
}
|
|
}
|
|
|
|
|
|
impl StitchType {
|
|
impl StitchType {
|
|
- fn to_u8(&self) -> u8 {
|
|
|
|
|
|
+ fn to_u8(self) -> u8 {
|
|
match self {
|
|
match self {
|
|
- StitchType::Normal => 'x' as u8,
|
|
|
|
- StitchType::HalfUp => '/' as u8,
|
|
|
|
- StitchType::HalfDown => '\\' as u8,
|
|
|
|
|
|
+ StitchType::Normal => b'x',
|
|
|
|
+ StitchType::HalfUp => b'/',
|
|
|
|
+ StitchType::HalfDown => b'\\',
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -76,14 +76,10 @@ impl ThymeFile {
|
|
let payload = image
|
|
let payload = image
|
|
.iter()
|
|
.iter()
|
|
.map(|(_idx, pixel)| {
|
|
.map(|(_idx, pixel)| {
|
|
- if let Some(color) = lookup.get(&pixel) {
|
|
|
|
- Some(Stitch {
|
|
|
|
- color: *color,
|
|
|
|
- typ: StitchType::Normal,
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- None
|
|
|
|
- }
|
|
|
|
|
|
+ lookup.get(&pixel).map(|color| Stitch {
|
|
|
|
+ color: *color,
|
|
|
|
+ typ: StitchType::Normal,
|
|
|
|
+ })
|
|
})
|
|
})
|
|
.collect();
|
|
.collect();
|
|
|
|
|
|
@@ -209,14 +205,15 @@ impl ThymeFile {
|
|
fn json_stitches(&self) -> Vec<Option<IntermediateStitch>> {
|
|
fn json_stitches(&self) -> Vec<Option<IntermediateStitch>> {
|
|
self.payload
|
|
self.payload
|
|
.iter()
|
|
.iter()
|
|
- .map(|stitch| match stitch {
|
|
|
|
- Some(s) => Some(IntermediateStitch(s.typ.to_u8(), s.color.idx)),
|
|
|
|
- None => None,
|
|
|
|
|
|
+ .map(|stitch| {
|
|
|
|
+ stitch
|
|
|
|
+ .as_ref()
|
|
|
|
+ .map(|s| IntermediateStitch(s.typ.to_u8(), s.color.idx))
|
|
})
|
|
})
|
|
.collect()
|
|
.collect()
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn iter<'a>(&'a self) -> ThymeImageIterator<'a> {
|
|
|
|
|
|
+ pub fn iter(&self) -> ThymeImageIterator<'_> {
|
|
ThymeImageIterator {
|
|
ThymeImageIterator {
|
|
palette: &self.palette,
|
|
palette: &self.palette,
|
|
x: 0,
|
|
x: 0,
|