pub struct KoiFrame { /* private fields */ }Expand description
A renderer-owned, fixed-size frame with row-major RGBA pixels.
Implementations§
Source§impl KoiFrame
impl KoiFrame
Sourcepub fn as_rgba_bytes(&self) -> &[u8] ⓘ
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§
impl Eq for KoiFrame
impl StructuralPartialEq for KoiFrame
Auto Trait Implementations§
impl Freeze for KoiFrame
impl RefUnwindSafe for KoiFrame
impl Send for KoiFrame
impl Sync for KoiFrame
impl Unpin for KoiFrame
impl UnsafeUnpin for KoiFrame
impl UnwindSafe for KoiFrame
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