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: CompressionThe compression level.
width: u32The width of the image, in pixels.
height: u32The height of the image, in pixels.
depth: u8The number of bits in each channel.
format: ColorFormatThe format of the image.
buffer: usizeThe size of the compressed data buffer.
This value determines the maximum size of an IDAT chunk.
Implementations§
Source§impl Options
impl Options
Sourcepub fn smallest(width: u32, height: u32) -> Self
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}Sourcepub fn fastest(width: u32, height: u32) -> Self
pub fn fastest(width: u32, height: u32) -> Self
Specifies an 8-bit RGBA image optimizing for encoding speed.
Sourcepub fn build<W>(&self, sink: W) -> Result<Encoder<W, Standard>>where
W: Write,
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}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Options
impl RefUnwindSafe for Options
impl Send for Options
impl Sync for Options
impl Unpin for Options
impl UnwindSafe for Options
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more