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
 
impl Renderer
Sourcepub fn new(settings: Settings, resolution: USizeVec2) -> Self
 
pub fn new(settings: Settings, resolution: USizeVec2) -> Self
Create a new instance of the renderer with the specified settings.
Sourcepub fn render_pixel(&self, position: USizeVec2, channel: usize) -> f32
 
pub fn render_pixel(&self, position: USizeVec2, channel: usize) -> f32
Render a single pixel and include noise if the noise feature is enabled.
Sourcepub 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,
 
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.
pub fn render_to_array<T>(settings: Settings, target: &mut ArrayViewMut3<'_, T>)
Auto Trait Implementations§
impl Freeze for Renderer
impl RefUnwindSafe for Renderer
impl Send for Renderer
impl Sync for Renderer
impl Unpin for Renderer
impl UnwindSafe for Renderer
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
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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