Create Image types
This commit is contained in:
1 parent
5abc6ba12f
commit
cf1e5b165a
2 files changed
+48
-14
No files matched your search
@@ -0,0 +1,47 @@
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Pixel {
|
||||
pub r: f32,
|
||||
pub g: f32,
|
||||
pub b: f32,
|
||||
pub a: f32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct Extent {
|
||||
pub x: u32,
|
||||
pub y: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Image {
|
||||
pub extent: Extent,
|
||||
pub pixels: Vec<Pixel>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Invalid,
|
||||
Io(std::io::Error),
|
||||
}
|
||||
|
||||
pub trait Format {
|
||||
fn read<I>(input: &mut I) -> Result<Image, Error>
|
||||
where
|
||||
I: std::io::Read;
|
||||
|
||||
fn write<O>(output: &mut O, img: &Image) -> std::io::Result<()>
|
||||
where
|
||||
O: std::io::Write;
|
||||
}
|
||||
|
||||
impl Extent {
|
||||
pub fn size(&self) -> u32 {
|
||||
self.x * self.y
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
Error::Io(error)
|
||||
}
|
||||
}
|
||||
+1
-14
@@ -1,14 +1 @@
|
||||
pub fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
pub mod image;
|
||||
Reference in new issue
Block a user