pub use flate2::Compression;
use Encoder;
use filter::Standard;
use std::io::{self, Write};
#[repr(u8)]
#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
pub enum ColorFormat {
Gray = 0,
RGB = 2,
Palette = 3,
GrayA = 4,
RGBA = 6,
}
impl ColorFormat {
pub fn channels(self) -> usize {
use self::ColorFormat::*;
match self {
Gray => 1,
RGB => 3,
Palette => 1,
GrayA => 2,
RGBA => 4,
}
}
}
#[derive(Debug)]
pub struct Options {
pub level: Compression,
pub width: u32,
pub height: u32,
pub depth: u8,
pub format: ColorFormat,
pub buffer: usize,
}
impl Options {
pub fn smallest(width: u32, height: u32) -> Self {
Options {
level: Compression::best(),
width,
height,
depth: 8,
format: ColorFormat::RGBA,
buffer: 32 * 1024,
}
}
pub fn fastest(width: u32, height: u32) -> Self {
Options {
level: Compression::fast(),
width,
height,
depth: 8,
format: ColorFormat::RGBA,
buffer: 32 * 1024,
}
}
pub fn build<W>(&self, sink: W) -> io::Result<Encoder<W, Standard>>
where
W: Write,
{
Encoder::new(self, sink)
}
pub fn stride(&self) -> usize {
(
self.width as usize *
self.depth as usize *
self.format.channels() as usize
+ 7) / 8
}
}