Skip to main content

Rendered

Struct Rendered 

Source
pub struct Rendered {
    pub width: u32,
    pub height: u32,
    pub rgba: Vec<u8>,
}
Expand description

A rendered page: 8-bit RGBA, row-major, premultiplied by tiny-skia’s convention undone.

Fields§

§width: u32§height: u32§rgba: Vec<u8>

Straight (non-premultiplied) RGBA, four bytes per pixel.

Implementations§

Source§

impl Rendered

Source

pub fn to_png(&self) -> Result<Vec<u8>>

Encodes to PNG.

Examples found in repository?
examples/render.rs (line 21)
3fn main() {
4    let mut args = std::env::args().skip(1);
5    let Some(path) = args.next() else {
6        eprintln!("usage: render <file.pdf> [page] [dpi] [out.png]");
7        std::process::exit(2);
8    };
9    let index: usize = args.next().and_then(|s| s.parse().ok()).unwrap_or(0);
10    let dpi: f32 = args.next().and_then(|s| s.parse().ok()).unwrap_or(150.0);
11    let out = args.next().unwrap_or_else(|| "page.png".into());
12
13    let doc = rustium_pdf::Document::open(&path).expect("open");
14    let page = doc.page(index).expect("page");
15    let started = std::time::Instant::now();
16    let image = page
17        .render(&doc, rustium_pdf::RenderOptions::at_dpi(dpi))
18        .expect("render");
19    let elapsed = started.elapsed();
20
21    std::fs::write(&out, image.to_png().expect("encode")).expect("write");
22    println!(
23        "{out}: {}x{} at {dpi}dpi in {:.0}ms ({} glyphs, {} paths, {} images)",
24        image.width,
25        image.height,
26        elapsed.as_secs_f32() * 1000.0,
27        page.glyphs.len(),
28        page.paths.len(),
29        page.images.len()
30    );
31}

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.