diff --git a/src/image.rs b/src/image.rs
index 996bb06..f917171 100644
--- a/src/image.rs
+++ b/src/image.rs
@@ -1,3 +1,8 @@
+pub mod linear_rgb;
+pub mod srgb;
+pub use linear_rgb::*;
+pub use srgb::*;
+
pub mod farbfeld;
pub use farbfeld::*;
@@ -19,28 +24,6 @@ pub enum Error {
Io(std::io::Error),
}
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub struct SRGBA {
- pub r: f32,
- pub g: f32,
- pub b: f32,
- pub a: f32,
-}
-
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub struct SRGB {
- pub r: f32,
- pub g: f32,
- pub b: f32,
-}
-
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub struct LinearRGB {
- pub r: f32,
- pub g: f32,
- pub b: f32,
-}
-
pub trait Format
{
fn read(input: &mut I) -> Result, Error>
where
@@ -178,184 +161,6 @@ impl From for Error {
}
}
-impl SRGBA {
- pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self {
- Self { r, g, b, a }
- }
-}
-
-impl std::ops::AddAssign for SRGBA {
- fn add_assign(&mut self, other: SRGBA) {
- self.r += other.r;
- self.g += other.g;
- self.b += other.b;
- self.a += other.a;
- }
-}
-
-impl std::ops::MulAssign for SRGBA {
- fn mul_assign(&mut self, scalar: f32) {
- self.r *= scalar;
- self.g *= scalar;
- self.b *= scalar;
- self.a *= scalar;
- }
-}
-
-impl std::ops::DivAssign for SRGBA {
- fn div_assign(&mut self, scalar: f32) {
- self.r /= scalar;
- self.g /= scalar;
- self.b /= scalar;
- self.a /= scalar;
- }
-}
-
-impl std::ops::Mul for SRGBA {
- type Output = Self;
-
- fn mul(mut self, scalar: f32) -> Self {
- self *= scalar;
- self
- }
-}
-
-impl std::ops::Div for SRGBA {
- type Output = Self;
-
- fn div(mut self, scalar: f32) -> Self {
- self /= scalar;
- self
- }
-}
-
-impl std::default::Default for SRGBA {
- fn default() -> Self {
- Self {
- r: 0.0,
- g: 0.0,
- b: 0.0,
- a: 0.0,
- }
- }
-}
-
-impl SRGB {
- pub fn new(r: f32, g: f32, b: f32) -> Self {
- Self { r, g, b }
- }
-}
-
-impl std::ops::AddAssign for SRGB {
- fn add_assign(&mut self, other: SRGB) {
- self.r += other.r;
- self.g += other.g;
- self.b += other.b;
- }
-}
-
-impl std::ops::MulAssign for SRGB {
- fn mul_assign(&mut self, scalar: f32) {
- self.r *= scalar;
- self.g *= scalar;
- self.b *= scalar;
- }
-}
-
-impl std::ops::DivAssign for SRGB {
- fn div_assign(&mut self, scalar: f32) {
- self.r /= scalar;
- self.g /= scalar;
- self.b /= scalar;
- }
-}
-
-impl std::ops::Mul for SRGB {
- type Output = Self;
-
- fn mul(mut self, scalar: f32) -> Self {
- self *= scalar;
- self
- }
-}
-
-impl std::ops::Div for SRGB {
- type Output = Self;
-
- fn div(mut self, scalar: f32) -> Self {
- self /= scalar;
- self
- }
-}
-
-impl std::default::Default for SRGB {
- fn default() -> Self {
- Self {
- r: 0.0,
- g: 0.0,
- b: 0.0,
- }
- }
-}
-
-impl LinearRGB {
- pub fn new(r: f32, g: f32, b: f32) -> Self {
- Self { r, g, b }
- }
-}
-
-impl std::ops::AddAssign for LinearRGB {
- fn add_assign(&mut self, other: LinearRGB) {
- self.r += other.r;
- self.g += other.g;
- self.b += other.b;
- }
-}
-
-impl std::ops::MulAssign for LinearRGB {
- fn mul_assign(&mut self, scalar: f32) {
- self.r *= scalar;
- self.g *= scalar;
- self.b *= scalar;
- }
-}
-
-impl std::ops::DivAssign for LinearRGB {
- fn div_assign(&mut self, scalar: f32) {
- self.r /= scalar;
- self.g /= scalar;
- self.b /= scalar;
- }
-}
-
-impl std::ops::Mul for LinearRGB {
- type Output = Self;
-
- fn mul(mut self, scalar: f32) -> Self {
- self *= scalar;
- self
- }
-}
-
-impl std::ops::Div for LinearRGB {
- type Output = Self;
-
- fn div(mut self, scalar: f32) -> Self {
- self /= scalar;
- self
- }
-}
-
-impl std::default::Default for LinearRGB {
- fn default() -> Self {
- Self {
- r: 0.0,
- g: 0.0,
- b: 0.0,
- }
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/image/linear_rgb.rs b/src/image/linear_rgb.rs
new file mode 100644
index 0000000..5b10484
--- /dev/null
+++ b/src/image/linear_rgb.rs
@@ -0,0 +1,64 @@
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct LinearRGB {
+ pub r: f32,
+ pub g: f32,
+ pub b: f32,
+}
+
+impl LinearRGB {
+ pub fn new(r: f32, g: f32, b: f32) -> Self {
+ Self { r, g, b }
+ }
+}
+
+impl std::ops::AddAssign for LinearRGB {
+ fn add_assign(&mut self, other: LinearRGB) {
+ self.r += other.r;
+ self.g += other.g;
+ self.b += other.b;
+ }
+}
+
+impl std::ops::MulAssign for LinearRGB {
+ fn mul_assign(&mut self, scalar: f32) {
+ self.r *= scalar;
+ self.g *= scalar;
+ self.b *= scalar;
+ }
+}
+
+impl std::ops::DivAssign for LinearRGB {
+ fn div_assign(&mut self, scalar: f32) {
+ self.r /= scalar;
+ self.g /= scalar;
+ self.b /= scalar;
+ }
+}
+
+impl std::ops::Mul for LinearRGB {
+ type Output = Self;
+
+ fn mul(mut self, scalar: f32) -> Self {
+ self *= scalar;
+ self
+ }
+}
+
+impl std::ops::Div for LinearRGB {
+ type Output = Self;
+
+ fn div(mut self, scalar: f32) -> Self {
+ self /= scalar;
+ self
+ }
+}
+
+impl std::default::Default for LinearRGB {
+ fn default() -> Self {
+ Self {
+ r: 0.0,
+ g: 0.0,
+ b: 0.0,
+ }
+ }
+}
diff --git a/src/image/srgb.rs b/src/image/srgb.rs
new file mode 100644
index 0000000..a9a0abb
--- /dev/null
+++ b/src/image/srgb.rs
@@ -0,0 +1,134 @@
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct SRGBA {
+ pub r: f32,
+ pub g: f32,
+ pub b: f32,
+ pub a: f32,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct SRGB {
+ pub r: f32,
+ pub g: f32,
+ pub b: f32,
+}
+
+impl SRGBA {
+ pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self {
+ Self { r, g, b, a }
+ }
+}
+
+impl std::ops::AddAssign for SRGBA {
+ fn add_assign(&mut self, other: SRGBA) {
+ self.r += other.r;
+ self.g += other.g;
+ self.b += other.b;
+ self.a += other.a;
+ }
+}
+
+impl std::ops::MulAssign for SRGBA {
+ fn mul_assign(&mut self, scalar: f32) {
+ self.r *= scalar;
+ self.g *= scalar;
+ self.b *= scalar;
+ self.a *= scalar;
+ }
+}
+
+impl std::ops::DivAssign for SRGBA {
+ fn div_assign(&mut self, scalar: f32) {
+ self.r /= scalar;
+ self.g /= scalar;
+ self.b /= scalar;
+ self.a /= scalar;
+ }
+}
+
+impl std::ops::Mul for SRGBA {
+ type Output = Self;
+
+ fn mul(mut self, scalar: f32) -> Self {
+ self *= scalar;
+ self
+ }
+}
+
+impl std::ops::Div for SRGBA {
+ type Output = Self;
+
+ fn div(mut self, scalar: f32) -> Self {
+ self /= scalar;
+ self
+ }
+}
+
+impl std::default::Default for SRGBA {
+ fn default() -> Self {
+ Self {
+ r: 0.0,
+ g: 0.0,
+ b: 0.0,
+ a: 0.0,
+ }
+ }
+}
+
+impl SRGB {
+ pub fn new(r: f32, g: f32, b: f32) -> Self {
+ Self { r, g, b }
+ }
+}
+
+impl std::ops::AddAssign for SRGB {
+ fn add_assign(&mut self, other: SRGB) {
+ self.r += other.r;
+ self.g += other.g;
+ self.b += other.b;
+ }
+}
+
+impl std::ops::MulAssign for SRGB {
+ fn mul_assign(&mut self, scalar: f32) {
+ self.r *= scalar;
+ self.g *= scalar;
+ self.b *= scalar;
+ }
+}
+
+impl std::ops::DivAssign for SRGB {
+ fn div_assign(&mut self, scalar: f32) {
+ self.r /= scalar;
+ self.g /= scalar;
+ self.b /= scalar;
+ }
+}
+
+impl std::ops::Mul for SRGB {
+ type Output = Self;
+
+ fn mul(mut self, scalar: f32) -> Self {
+ self *= scalar;
+ self
+ }
+}
+
+impl std::ops::Div for SRGB {
+ type Output = Self;
+
+ fn div(mut self, scalar: f32) -> Self {
+ self /= scalar;
+ self
+ }
+}
+
+impl std::default::Default for SRGB {
+ fn default() -> Self {
+ Self {
+ r: 0.0,
+ g: 0.0,
+ b: 0.0,
+ }
+ }
+}