Skip to main content

KoiFrame

Struct KoiFrame 

Source
pub struct KoiFrame { /* private fields */ }
Expand description

A renderer-owned, fixed-size frame with row-major RGBA pixels.

Implementations§

Source§

impl KoiFrame

Source

pub fn as_rgba_bytes(&self) -> &[u8] ⓘ

The pixels as bytes, row by row from the top left, four channels per pixel: red, green, blue, alpha. The length is the canvas area times four.

Examples found in repository?
examples/generate-library.rs (line 404)
382fn encode_overview(
383    rendered_frames: &[KoiFrame],
384    background_color: [u8; 4],
385) -> Result<Vec<u8>, png::EncodingError> {
386    let overview_scale = STATIC_EXPORT_SCALE as usize;
387    let frame_width = FRAME_WIDTH_PIXELS as usize;
388    let frame_height = FRAME_HEIGHT_PIXELS as usize;
389    let overview_width = frame_width * GROWTH_SAMPLES.len() * overview_scale;
390    let overview_height =
391        frame_height * rendered_frames.len() / GROWTH_SAMPLES.len() * overview_scale;
392    let mut overview_pixels = background_color.repeat(overview_width * overview_height);
393    for (pixel_index, pixel_channels) in overview_pixels
394        .as_chunks_mut::<4>()
395        .0
396        .iter_mut()
397        .enumerate()
398    {
399        let source_x = pixel_index % overview_width / overview_scale;
400        let source_y = pixel_index / overview_width / overview_scale;
401        let frame_index = source_y / frame_height * GROWTH_SAMPLES.len() + source_x / frame_width;
402        let source_index = (source_y % frame_height * frame_width + source_x % frame_width) * 4;
403        let source_channels =
404            &rendered_frames[frame_index].as_rgba_bytes()[source_index..source_index + 4];
405        if source_channels[3] != 0 {
406            pixel_channels.copy_from_slice(source_channels);
407        }
408    }
409    let mut png_bytes = Vec::new();
410    let mut png_encoder = png::Encoder::new(
411        &mut png_bytes,
412        overview_width as u32,
413        overview_height as u32,
414    );
415    png_encoder.set_color(png::ColorType::Rgba);
416    png_encoder.set_depth(png::BitDepth::Eight);
417    let mut png_writer = png_encoder.write_header()?;
418    png_writer.write_image_data(&overview_pixels)?;
419    png_writer.finish()?;
420    Ok(png_bytes)
421}

Trait Implementations§

Source§

impl Debug for KoiFrame

Source§

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

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

impl Eq for KoiFrame

Source§

impl PartialEq for KoiFrame

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for KoiFrame

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 = !

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.