2021-05-15 16:59:51 +01:00
|
|
|
use serde_derive::{Serialize, Deserialize};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
|
|
|
|
pub struct Image {
|
|
|
|
|
pub name: String,
|
|
|
|
|
/// colour indexes - todo convert to [u8; 64]?
|
|
|
|
|
pub pixels: Vec<u8>,
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 17:04:46 +01:00
|
|
|
// impl Image {
|
|
|
|
|
// fn from(intermediate: IntermediateImage) -> Image {
|
|
|
|
|
// Image {
|
|
|
|
|
// name: intermediate.name.to_owned(),
|
|
|
|
|
// pixels: intermediate.pixels.split_whitespace().collect::<String>().chars().map(
|
|
|
|
|
// |char|char as u8
|
|
|
|
|
// ).collect()
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2021-05-15 16:59:51 +01:00
|
|
|
|
|
|
|
|
/// for toml purposes
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub(crate) struct IntermediateImages {
|
|
|
|
|
/// singular so each image is named "image" instead of "images" in toml
|
|
|
|
|
image: Vec<IntermediateImage>,
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 17:04:46 +01:00
|
|
|
// impl IntermediateImages {
|
|
|
|
|
// fn to_images(&self) -> Vec<Image> {
|
|
|
|
|
// self.image.iter().map(|intermediate|
|
|
|
|
|
// Image::from(intermediate.clone())
|
|
|
|
|
// ).collect()
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2021-05-15 16:59:51 +01:00
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
|
pub(crate) struct IntermediateImage {
|
|
|
|
|
name: String,
|
|
|
|
|
pixels: String,
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 17:04:46 +01:00
|
|
|
// impl IntermediateImage {
|
|
|
|
|
// // todo refactor
|
|
|
|
|
// fn from(image: Image) -> IntermediateImage {
|
|
|
|
|
// let mut string = "\n".to_string();
|
|
|
|
|
//
|
|
|
|
|
// let sqrt = (image.pixels.len() as f64).sqrt() as usize;
|
|
|
|
|
// for line in image.pixels.chunks(sqrt) {
|
|
|
|
|
// for pixel in line {
|
|
|
|
|
// string.push_str(&format!("{}", *pixel));
|
|
|
|
|
// }
|
|
|
|
|
// string.push('\n');
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// IntermediateImage {
|
|
|
|
|
// name: image.name.to_owned(),
|
|
|
|
|
// /// todo wtf? I guess this crate doesn't handle multiline strings correctly
|
|
|
|
|
// pixels: format!("\"\"{}\"\"", string),
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2021-05-15 16:59:51 +01:00
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod test {
|
|
|
|
|
// #[test]
|
|
|
|
|
// fn test_image_from_toml() {
|
|
|
|
|
// let str = include_str!("test-resources/basic/images.toml");
|
|
|
|
|
// let output: Image = toml::from_str(str).unwrap();
|
|
|
|
|
// let expected = crate::mock::image::avatar();
|
|
|
|
|
// assert_eq!(output, expected);
|
|
|
|
|
// }
|
|
|
|
|
}
|