Move pixel types into separate modules
This commit is contained in:
1 parent
8ab38776d5
commit
689144db8f
3 files changed
+203
-200
No files matched your search
+5
-200
@@ -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<P> {
|
||||
fn read<I>(input: &mut I) -> Result<Image<P>, Error>
|
||||
where
|
||||
@@ -178,184 +161,6 @@ impl From<std::io::Error> 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<f32> 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<f32> 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<f32> for SRGBA {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> 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<f32> for SRGB {
|
||||
fn mul_assign(&mut self, scalar: f32) {
|
||||
self.r *= scalar;
|
||||
self.g *= scalar;
|
||||
self.b *= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DivAssign<f32> for SRGB {
|
||||
fn div_assign(&mut self, scalar: f32) {
|
||||
self.r /= scalar;
|
||||
self.g /= scalar;
|
||||
self.b /= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<f32> for SRGB {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> 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<f32> for LinearRGB {
|
||||
fn mul_assign(&mut self, scalar: f32) {
|
||||
self.r *= scalar;
|
||||
self.g *= scalar;
|
||||
self.b *= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DivAssign<f32> for LinearRGB {
|
||||
fn div_assign(&mut self, scalar: f32) {
|
||||
self.r /= scalar;
|
||||
self.g /= scalar;
|
||||
self.b /= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<f32> for LinearRGB {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> 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::*;
|
||||
|
||||
@@ -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<f32> for LinearRGB {
|
||||
fn mul_assign(&mut self, scalar: f32) {
|
||||
self.r *= scalar;
|
||||
self.g *= scalar;
|
||||
self.b *= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DivAssign<f32> for LinearRGB {
|
||||
fn div_assign(&mut self, scalar: f32) {
|
||||
self.r /= scalar;
|
||||
self.g /= scalar;
|
||||
self.b /= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<f32> for LinearRGB {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<f32> 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<f32> 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<f32> for SRGBA {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> 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<f32> for SRGB {
|
||||
fn mul_assign(&mut self, scalar: f32) {
|
||||
self.r *= scalar;
|
||||
self.g *= scalar;
|
||||
self.b *= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DivAssign<f32> for SRGB {
|
||||
fn div_assign(&mut self, scalar: f32) {
|
||||
self.r /= scalar;
|
||||
self.g /= scalar;
|
||||
self.b /= scalar;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<f32> for SRGB {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(mut self, scalar: f32) -> Self {
|
||||
self *= scalar;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<f32> 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user