Create feature flags for more compression algorithms (#270)
This commit is contained in:
1 parent
dc2c67469b
commit
83e6d64751
8 files changed
+64
-15
No files matched your search
@@ -1,13 +1,19 @@
|
||||
use crate::tags::CompressionMethod;
|
||||
use std::io::{self, Write};
|
||||
|
||||
#[cfg(feature = "deflate")]
|
||||
mod deflate;
|
||||
#[cfg(feature = "lzw")]
|
||||
mod lzw;
|
||||
mod packbits;
|
||||
mod uncompressed;
|
||||
|
||||
#[cfg(feature = "deflate")]
|
||||
pub use self::deflate::{Deflate, DeflateLevel};
|
||||
|
||||
#[cfg(feature = "lzw")]
|
||||
pub use self::lzw::Lzw;
|
||||
|
||||
pub use self::packbits::Packbits;
|
||||
pub use self::uncompressed::Uncompressed;
|
||||
|
||||
@@ -30,7 +36,9 @@ pub trait Compression: CompressionAlgorithm {
|
||||
/// An enum to store each compression algorithm.
|
||||
pub enum Compressor {
|
||||
Uncompressed(Uncompressed),
|
||||
#[cfg(feature = "lzw")]
|
||||
Lzw(Lzw),
|
||||
#[cfg(feature = "deflate")]
|
||||
Deflate(Deflate),
|
||||
Packbits(Packbits),
|
||||
}
|
||||
@@ -46,7 +54,9 @@ impl CompressionAlgorithm for Compressor {
|
||||
fn write_to<W: Write>(&mut self, writer: &mut W, bytes: &[u8]) -> Result<u64, io::Error> {
|
||||
match self {
|
||||
Compressor::Uncompressed(algorithm) => algorithm.write_to(writer, bytes),
|
||||
#[cfg(feature = "lzw")]
|
||||
Compressor::Lzw(algorithm) => algorithm.write_to(writer, bytes),
|
||||
#[cfg(feature = "deflate")]
|
||||
Compressor::Deflate(algorithm) => algorithm.write_to(writer, bytes),
|
||||
Compressor::Packbits(algorithm) => algorithm.write_to(writer, bytes),
|
||||
}
|
||||
|
||||
@@ -34,12 +34,15 @@ use self::writer::*;
|
||||
///
|
||||
/// [Predictor::FloatingPoint] is currently not supported.
|
||||
pub type Predictor = crate::tags::Predictor;
|
||||
#[cfg(feature = "deflate")]
|
||||
pub type DeflateLevel = compression::DeflateLevel;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum Compression {
|
||||
Uncompressed,
|
||||
#[cfg(feature = "lzw")]
|
||||
Lzw,
|
||||
#[cfg(feature = "deflate")]
|
||||
Deflate(DeflateLevel),
|
||||
Packbits,
|
||||
}
|
||||
@@ -54,7 +57,9 @@ impl Compression {
|
||||
fn tag(&self) -> CompressionMethod {
|
||||
match self {
|
||||
Compression::Uncompressed => CompressionMethod::None,
|
||||
#[cfg(feature = "lzw")]
|
||||
Compression::Lzw => CompressionMethod::LZW,
|
||||
#[cfg(feature = "deflate")]
|
||||
Compression::Deflate(_) => CompressionMethod::Deflate,
|
||||
Compression::Packbits => CompressionMethod::PackBits,
|
||||
}
|
||||
@@ -63,7 +68,9 @@ impl Compression {
|
||||
fn get_algorithm(&self) -> Compressor {
|
||||
match self {
|
||||
Compression::Uncompressed => compression::Uncompressed {}.get_algorithm(),
|
||||
#[cfg(feature = "lzw")]
|
||||
Compression::Lzw => compression::Lzw {}.get_algorithm(),
|
||||
#[cfg(feature = "deflate")]
|
||||
Compression::Deflate(level) => compression::Deflate::with_level(*level).get_algorithm(),
|
||||
Compression::Packbits => compression::Packbits {}.get_algorithm(),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user