Skip to content

Commit b74f3ba

Browse files
committed
serde for filters when serialize feature is enabled
1 parent 2e179cc commit b74f3ba

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

src/filters/filter.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::*;
22

33
/// Convert between colors
44
#[derive(Clone, Copy, Default, Debug)]
5+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
56
struct Convert<T: Color>(std::marker::PhantomData<T>);
67

78
/// Create new color conversion filter
@@ -16,6 +17,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Convert<D> {
1617
}
1718

1819
#[derive(Debug, Default)]
20+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1921
struct Saturation(pub f64);
2022

2123
/// Adjust saturation
@@ -33,6 +35,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Saturation {
3335
}
3436

3537
#[derive(Debug)]
38+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3639
struct Brightness(f64);
3740

3841
/// Adjust image brightness
@@ -49,6 +52,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Brightness {
4952
}
5053

5154
#[derive(Debug)]
55+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5256
struct Exposure(f64);
5357

5458
/// Adjust image exposure, the argument is the number of stops to increase or decrease exposure by
@@ -65,6 +69,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Exposure {
6569
}
6670

6771
#[derive(Debug)]
72+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6873
struct Contrast(pub f64);
6974

7075
/// Adjust image contrast
@@ -81,6 +86,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Contrast {
8186
}
8287

8388
#[derive(Debug)]
89+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8490
struct Crop(Region);
8591

8692
/// Crop an image
@@ -107,6 +113,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Crop {
107113
}
108114

109115
#[derive(Debug)]
116+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
110117
struct Invert;
111118

112119
/// Invert an image
@@ -123,6 +130,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Invert {
123130
}
124131

125132
#[derive(Debug)]
133+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
126134
struct Blend;
127135

128136
/// Average two images
@@ -139,6 +147,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Blend {
139147
}
140148

141149
#[derive(Debug)]
150+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
142151
struct GammaLog(f64);
143152

144153
/// Convert to log gamma
@@ -157,6 +166,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for GammaLog {
157166
}
158167

159168
#[derive(Debug)]
169+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
160170
struct GammaLin(f64);
161171

162172
/// Convert to linear gamma
@@ -259,6 +269,7 @@ impl<
259269
}
260270

261271
#[derive(Debug)]
272+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
262273
struct Clamp;
263274

264275
/// Clamp pixel values
@@ -273,6 +284,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Clamp {
273284
}
274285

275286
#[derive(Debug)]
287+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
276288
struct Normalize {
277289
min: f64,
278290
max: f64,
@@ -308,6 +320,7 @@ impl<T: Type, C: Color, U: Type, D: Color> Filter<T, C, U, D> for Normalize {
308320
}
309321

310322
#[derive(Debug)]
323+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
311324
struct Noop;
312325

313326
/// Filter that does nothing

src/filters/pipeline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::*;
33
/// Used to determine if a filter can be executed and interleaved at the pixel level or if the
44
/// whole filter needs to be evaulated before moving to the next filter
55
#[derive(Debug, PartialEq, Clone, Copy, Eq)]
6+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67
pub enum Schedule {
78
/// Allows pixel level composition
89
Pixel,

src/histogram.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::*;
22

33
/// Image histogram
44
#[derive(Debug, Clone, PartialEq, Eq)]
5+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
56
pub struct Histogram {
67
total: usize,
78
bins: Box<[usize]>,

src/kernel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::*;
55

66
/// 2-dimensional convolution kernel
77
#[derive(Debug, Clone, PartialEq)]
8+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89
pub struct Kernel {
910
rows: usize,
1011
cols: usize,

src/meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rayon::prelude::*;
66
use std::marker::PhantomData;
77

88
/// Image metadata
9-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
109
#[derive(Debug, Clone, PartialEq, Eq)]
10+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1111
pub struct Meta<T: Type, C: Color> {
1212
/// Image size
1313
pub size: Size,

0 commit comments

Comments
 (0)