Renderer

Struct Renderer 

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

Object to render bokeh kernels

This is the disc that being perceived as the ‘Bokeh’ This image will be used to convolute the entire image with.

§Usage

The object has three entry points (depending on the features enabled).

Make sure to create the settings first, then pass them to this object when calling Renderer::new(settings);

§Rendering

When not using any features, call the render_pixel() method for all coordinates in your image to fetch the result for each pixel.

Or provide your own ndarray where each value will be computed automatically with Renderer::render_to_array

§Example

use bokeh_creator::{Renderer, Settings};
use glam::USizeVec2;

let resolution = 64;
let settings = Settings::default();
let renderer = Renderer::new(settings, [resolution, resolution].into());
let mut image = vec![vec![0.0; resolution]; resolution];

// this is not the most efficient way, its just to showcase basic image processing
for (y, row) in image.iter_mut().enumerate() {
    for (x, pixel) in row.iter_mut().enumerate() {
        *pixel = renderer.render_pixel(USizeVec2::new(x, y), 0);
    }
}

Implementations§

Source§

impl Renderer

Source

pub fn new(settings: Settings, resolution: USizeVec2) -> Self

Create a new instance of the renderer with the specified settings.

Source

pub fn render_pixel(&self, position: USizeVec2, channel: usize) -> f32

Render a single pixel and include noise if the noise feature is enabled.

Source

pub fn render_to_image<P, T>( image: &mut ImageBuffer<P, Vec<T>>, settings: Settings, )
where P: Pixel<Subpixel = T> + Sync, T: Clone + Copy + NormalizedFloat<T> + AsPrimitive<f32> + AsPrimitive<f64> + Default,

Render the bokeh for the provided image.

Source

pub fn render_to_array<T>(settings: Settings, target: &mut ArrayViewMut3<'_, T>)

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V