Options

Struct Options 

Source
pub struct Options {
    pub level: Compression,
    pub width: u32,
    pub height: u32,
    pub depth: u8,
    pub format: ColorFormat,
    pub buffer: usize,
}
Expand description

Image properties and compression options.

Fields§

§level: Compression

The compression level.

§width: u32

The width of the image, in pixels.

§height: u32

The height of the image, in pixels.

§depth: u8

The number of bits in each channel.

§format: ColorFormat

The format of the image.

§buffer: usize

The size of the compressed data buffer.

This value determines the maximum size of an IDAT chunk.

Implementations§

Source§

impl Options

Source

pub fn smallest(width: u32, height: u32) -> Self

Specifies an 8-bit RGBA image optimizing for image size.

Examples found in repository?
examples/flag.rs (line 9)
8fn main() {
9    let mut enc = Options::smallest(480, 360)
10        .build(File::create("flag.png").unwrap())
11        .unwrap();
12
13    meta::text(
14        &mut enc,
15        meta::Keyword::Author,
16        "Ram Kaniyur",
17    ).unwrap();
18
19    let mut row = [255; 480 * 4];
20
21    for x in 0..480 {
22        let i = x * 4;
23
24        if x < 160 {
25            row[i] = 0;
26        } else if x < 320 {
27            row[i + 1] = 0;
28        } else {
29            row[i + 2] = 0;
30        }
31    }
32
33    for _y in 0..360 {
34        enc.write(&row).unwrap();
35    }
36
37    enc.finish().unwrap();
38}
Source

pub fn fastest(width: u32, height: u32) -> Self

Specifies an 8-bit RGBA image optimizing for encoding speed.

Source

pub fn build<W>(&self, sink: W) -> Result<Encoder<W, Standard>>
where W: Write,

Make a new encoder with these options and the default filter.

To customize the filter as well, see Encoder::new.

Examples found in repository?
examples/flag.rs (line 10)
8fn main() {
9    let mut enc = Options::smallest(480, 360)
10        .build(File::create("flag.png").unwrap())
11        .unwrap();
12
13    meta::text(
14        &mut enc,
15        meta::Keyword::Author,
16        "Ram Kaniyur",
17    ).unwrap();
18
19    let mut row = [255; 480 * 4];
20
21    for x in 0..480 {
22        let i = x * 4;
23
24        if x < 160 {
25            row[i] = 0;
26        } else if x < 320 {
27            row[i + 1] = 0;
28        } else {
29            row[i + 2] = 0;
30        }
31    }
32
33    for _y in 0..360 {
34        enc.write(&row).unwrap();
35    }
36
37    enc.finish().unwrap();
38}
Source

pub fn stride(&self) -> usize

The number of bytes occupied by a single row of the uncompressed image.

Trait Implementations§

Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a Options> for None

Source§

fn from(_: &Options) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Options> for Standard

Source§

fn from(opts: &Options) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.