imageproc/drawing/
mod.rs

1//! Helpers for drawing basic shapes on images.
2//!
3//! Every `draw_` function comes in two variants: one creates a new copy of the input image, one modifies the image in place.
4//! The latter is more memory efficient, but you lose the original image.
5
6mod bezier;
7pub use self::bezier::{draw_cubic_bezier_curve, draw_cubic_bezier_curve_mut};
8
9mod canvas;
10pub use self::canvas::{Blend, Canvas};
11
12mod conics;
13pub use self::conics::{
14    draw_filled_circle, draw_filled_circle_mut, draw_filled_ellipse, draw_filled_ellipse_mut,
15    draw_hollow_circle, draw_hollow_circle_mut, draw_hollow_ellipse, draw_hollow_ellipse_mut,
16};
17
18mod cross;
19pub use self::cross::{draw_cross, draw_cross_mut};
20
21mod line;
22pub use self::line::{
23    draw_antialiased_line_segment, draw_antialiased_line_segment_mut, draw_line_segment,
24    draw_line_segment_mut, BresenhamLineIter, BresenhamLinePixelIter, BresenhamLinePixelIterMut,
25};
26
27mod polygon;
28pub use self::polygon::{draw_polygon, draw_polygon_mut};
29
30mod rect;
31pub use self::rect::{
32    draw_filled_rect, draw_filled_rect_mut, draw_hollow_rect, draw_hollow_rect_mut,
33};
34
35mod text;
36pub use self::text::{draw_text, draw_text_mut, text_size};
37
38// Set pixel at (x, y) to color if this point lies within image bounds,
39// otherwise do nothing.
40fn draw_if_in_bounds<C>(canvas: &mut C, x: i32, y: i32, color: C::Pixel)
41where
42    C: Canvas,
43{
44    if x >= 0 && x < canvas.width() as i32 && y >= 0 && y < canvas.height() as i32 {
45        canvas.draw_pixel(x as u32, y as u32, color);
46    }
47}