@@ -84,6 +84,83 @@ impl Png {
8484 let end = start + self . scan_line_width ( ) * lines as usize ;
8585 start..end
8686 }
87+
88+ /// The method removes filter from all scan lines.
89+ ///
90+ /// # Example
91+ ///
92+ /// ```
93+ /// use png_glitch::PngGlitch;
94+ /// let mut png_glitch = PngGlitch::open("./etc/sample00.png").expect("The PNG file should be successfully parsed");
95+ /// png_glitch.remove_filter();
96+ /// png_glitch.save("./etc/removed-all.png").expect("The PNG file should be successfully saved")
97+ /// ```
98+ pub fn remove_filter ( & mut self ) {
99+ self . remove_filter_from ( 0 , self . height ( ) ) ;
100+ }
101+
102+ /// The method removes filter from the scan lines in specified region
103+ ///
104+ /// # Example
105+ ///
106+ /// ```
107+ /// use png_glitch::PngGlitch;
108+ /// let mut png_glitch = PngGlitch::open("./etc/sample00.png").expect("The PNG file should be successfully parsed");
109+ /// png_glitch.remove_filter_from(5, 10); // Remove filter from the scan line #5 - # 14
110+ /// png_glitch.save("./etc/removed-partial.png").expect("The PNG file should be successfully saved")
111+ /// ```
112+ pub fn remove_filter_from ( & mut self , from : u32 , lines : u32 ) {
113+ let index = if from > 0 { from - 1 } else { 0 } ;
114+ let mut lines = self . scan_lines_from ( index as usize , lines as usize ) ;
115+ lines. reverse ( ) ;
116+
117+ let mut previous = if from > 0 {
118+ lines. pop ( )
119+ } else {
120+ None
121+ } ;
122+ while !lines. is_empty ( ) {
123+ let last_index = lines. len ( ) - 1 ;
124+ lines[ last_index] . remove_filter ( previous. as_ref ( ) ) ;
125+ previous = lines. pop ( )
126+ }
127+ }
128+
129+ /// The method removes filter from all scan lines.
130+ ///
131+ /// # Example
132+ ///
133+ /// ```
134+ /// use png_glitch::{FilterType, PngGlitch};
135+ /// let mut png_glitch = PngGlitch::open("./etc/none.png").expect("The PNG file should be successfully parsed");
136+ /// png_glitch.apply_filter(FilterType::Sub);
137+ /// png_glitch.save("./etc/filter-all.png").expect("The PNG file should be successfully saved")
138+ /// ```
139+ pub fn apply_filter ( & mut self , filter : FilterType ) {
140+ self . apply_filter_from ( filter, 0 , self . height ( ) ) ;
141+ }
142+
143+ /// The method removes filter from scan lines in specified region
144+ ///
145+ /// # Example
146+ ///
147+ /// ```
148+ /// use png_glitch::{FilterType, PngGlitch};
149+ /// let mut png_glitch = PngGlitch::open("./etc/none.png").expect("The PNG file should be successfully parsed");
150+ /// png_glitch.apply_filter_from(FilterType::Sub, 5, 3); // Apply sub filter to the scan line #5, #6, and #7.
151+ /// png_glitch.save("./etc/filter-partial.png").expect("The PNG file should be successfully saved")
152+ /// ```
153+ pub fn apply_filter_from ( & mut self , filter_type : FilterType , from : u32 , lines : u32 ) {
154+ let mut lines = self . scan_lines_from ( from as usize , lines as usize ) ;
155+ let mut previous = lines. pop ( ) ;
156+
157+ while !lines. is_empty ( ) {
158+ if let Some ( mut line) = previous {
159+ previous = lines. pop ( ) ;
160+ line. apply_filter ( filter_type, previous. as_ref ( ) ) ;
161+ }
162+ }
163+ }
87164}
88165
89166impl TryFrom < & [ u8 ] > for Png {
0 commit comments