Skip to content

Commit 98286ce

Browse files
authored
Merge pull request #506 from Shnatsel/improve-filter-documentation
Improve documentation on filters
2 parents d96defd + a64485a commit 98286ce

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/encoder.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,11 @@ impl<'a, W: Write> StreamWriter<'a, W> {
13461346
/// Set the used filter type for the next frame.
13471347
///
13481348
/// The default filter is [`FilterType::Sub`] which provides a basic prediction algorithm for
1349-
/// sample values based on the previous. For a potentially better compression ratio, at the
1350-
/// cost of more complex processing, try out [`FilterType::Paeth`].
1349+
/// sample values based on the previous.
1350+
///
1351+
/// For optimal compression ratio you should enable adaptive filtering
1352+
/// instead of setting a single filter for the entire image, see
1353+
/// [set_adaptive_filter](Self::set_adaptive_filter).
13511354
pub fn set_filter(&mut self, filter: FilterType) {
13521355
self.filter = filter;
13531356
}
@@ -1356,8 +1359,9 @@ impl<'a, W: Write> StreamWriter<'a, W> {
13561359
///
13571360
/// Adaptive filtering attempts to select the best filter for each line
13581361
/// based on heuristics which minimize the file size for compression rather
1359-
/// than use a single filter for the entire image. The default method is
1360-
/// [`AdaptiveFilterType::NonAdaptive`].
1362+
/// than use a single filter for the entire image.
1363+
///
1364+
/// The default method is [`AdaptiveFilterType::NonAdaptive`].
13611365
pub fn set_adaptive_filter(&mut self, adaptive_filter: AdaptiveFilterType) {
13621366
self.adaptive_filter = adaptive_filter;
13631367
}

src/filter.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ mod simd {
267267
/// Compression in general benefits from repetitive data. The filter is a content-aware method of
268268
/// compressing the range of occurring byte values to help the compression algorithm. Note that
269269
/// this does not operate on pixels but on raw bytes of a scanline.
270+
///
271+
/// Details on how each filter works can be found in the [PNG Book](http://www.libpng.org/pub/png/book/chapter09.html).
270272
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
271273
#[repr(u8)]
272274
pub enum FilterType {
@@ -297,12 +299,14 @@ impl FilterType {
297299
}
298300
}
299301

300-
/// The filtering method for preprocessing scanline data before compression.
302+
/// Adaptive filtering tries every possible filter for each row and uses a heuristic to select the best one.
303+
/// This improves compression ratio, but makes encoding slightly slower.
301304
///
302-
/// Adaptive filtering performs additional computation in an attempt to maximize
303-
/// the compression of the data. [`NonAdaptive`] filtering is the default.
305+
/// It is recommended to use `Adaptive` whenever you care about compression ratio.
306+
/// Filtering is quite cheap compared to other parts of encoding, but can contribute
307+
/// to the compression ratio significantly.
304308
///
305-
/// [`NonAdaptive`]: AdaptiveFilterType::NonAdaptive
309+
/// `NonAdaptive` filtering is the default.
306310
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
307311
#[repr(u8)]
308312
pub enum AdaptiveFilterType {

0 commit comments

Comments
 (0)