Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ display-window = ["sdl2"]
[dependencies]
approx = "0.5"
conv = "0.3.3"
image = { version = "0.23.6", default-features = false }
image = { version = "0.24.1", default-features = false }
itertools = "0.10"
nalgebra = { version = "0.30", default-features = false, features = ["std"] }
num = "0.4"
Expand All @@ -31,7 +31,7 @@ sdl2 = { version = "0.35", optional = true, default-features = false, features =

[dev-dependencies]
assert_approx_eq = "1.1.0"
image = "0.23.6"
image = "0.24.1"
quickcheck = "0.9.2"
wasm-bindgen-test = "0.3.14"

Expand Down
14 changes: 1 addition & 13 deletions src/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Trait definitions and type aliases.

use image::{Bgr, Bgra, ImageBuffer, Luma, LumaA, Pixel, Rgb, Rgba};
use image::{ImageBuffer, Luma, LumaA, Pixel, Rgb, Rgba};
use std::{i16, u16, u8};

/// An `ImageBuffer` containing Pixels of type P with storage `Vec<P::Subpixel>`.
Expand Down Expand Up @@ -64,18 +64,6 @@ impl_black_white!(
Rgba([u16::MIN, u16::MIN, u16::MIN, u16::MAX]),
Rgba([u16::MAX, u16::MAX, u16::MAX, u16::MAX])
);
impl_black_white!(Bgr<u8>, Bgr([u8::MIN; 3]), Bgr([u8::MAX; 3]));
impl_black_white!(Bgr<u16>, Bgr([u16::MIN; 3]), Bgr([u16::MAX; 3]));
impl_black_white!(
Bgra<u8>,
Bgra([u8::MIN, u8::MIN, u8::MIN, u8::MAX]),
Bgra([u8::MAX, u8::MAX, u8::MAX, u8::MAX])
);
impl_black_white!(
Bgra<u16>,
Bgra([u16::MIN, u16::MIN, u16::MIN, u16::MAX]),
Bgra([u16::MAX, u16::MAX, u16::MAX, u16::MAX])
);

/// Something with a 2d position.
pub trait Position {
Expand Down
2 changes: 0 additions & 2 deletions src/drawing/bezier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn draw_cubic_bezier_curve<I>(
) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand All @@ -39,7 +38,6 @@ pub fn draw_cubic_bezier_curve_mut<C>(
color: C::Pixel,
) where
C: Canvas,
C::Pixel: 'static,
{
// Bezier Curve function from: https://pomax.github.io/bezierinfo/#control
let cubic_bezier_curve = |t: f32| {
Expand Down
4 changes: 3 additions & 1 deletion src/drawing/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ impl<I: GenericImage> Canvas for Blend<I> {
}

fn draw_pixel(&mut self, x: u32, y: u32, color: Self::Pixel) {
self.0.get_pixel_mut(x, y).blend(&color)
let mut pix = self.0.get_pixel(x, y);
pix.blend(&color);
self.0.put_pixel(x, y, pix);
}
}
8 changes: 0 additions & 8 deletions src/drawing/conics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub fn draw_hollow_ellipse<I>(
) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand All @@ -52,7 +51,6 @@ pub fn draw_hollow_ellipse_mut<C>(
color: C::Pixel,
) where
C: Canvas,
C::Pixel: 'static,
{
// Circle drawing algorithm is faster, so use it if the given ellipse is actually a circle.
if width_radius == height_radius {
Expand Down Expand Up @@ -90,7 +88,6 @@ pub fn draw_filled_ellipse<I>(
) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand All @@ -116,7 +113,6 @@ pub fn draw_filled_ellipse_mut<C>(
color: C::Pixel,
) where
C: Canvas,
C::Pixel: 'static,
{
// Circle drawing algorithm is faster, so use it if the given ellipse is actually a circle.
if width_radius == height_radius {
Expand Down Expand Up @@ -204,7 +200,6 @@ pub fn draw_hollow_circle<I>(
) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand All @@ -218,7 +213,6 @@ where
pub fn draw_hollow_circle_mut<C>(canvas: &mut C, center: (i32, i32), radius: i32, color: C::Pixel)
where
C: Canvas,
C::Pixel: 'static,
{
let mut x = 0i32;
let mut y = radius;
Expand Down Expand Up @@ -252,7 +246,6 @@ where
pub fn draw_filled_circle_mut<C>(canvas: &mut C, center: (i32, i32), radius: i32, color: C::Pixel)
where
C: Canvas,
C::Pixel: 'static,
{
let mut x = 0i32;
let mut y = radius;
Expand Down Expand Up @@ -308,7 +301,6 @@ pub fn draw_filled_circle<I>(
) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand Down
1 change: 0 additions & 1 deletion src/drawing/cross.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ where
pub fn draw_cross<I>(image: &I, color: I::Pixel, x: i32, y: i32) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand Down
24 changes: 11 additions & 13 deletions src/drawing/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ fn clamp_point<I: GenericImage>(p: (f32, f32), image: &I) -> (f32, f32) {

/// Iterates over the image pixels in a line segment using
/// [Bresenham's line drawing algorithm](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm).
pub struct BresenhamLinePixelIter<'a, P: Pixel + 'static> {
pub struct BresenhamLinePixelIter<'a, P: Pixel> {
iter: BresenhamLineIter,
image: &'a Image<P>,
}

impl<'a, P: Pixel + 'static> BresenhamLinePixelIter<'a, P> {
impl<'a, P: Pixel> BresenhamLinePixelIter<'a, P> {
/// Creates a [`BresenhamLinePixelIter`](struct.BresenhamLinePixelIter.html) which will iterate over
/// the image pixels with coordinates between `start` and `end`.
pub fn new(
Expand All @@ -114,7 +114,7 @@ impl<'a, P: Pixel + 'static> BresenhamLinePixelIter<'a, P> {
}
}

impl<'a, P: Pixel + 'static> Iterator for BresenhamLinePixelIter<'a, P> {
impl<'a, P: Pixel> Iterator for BresenhamLinePixelIter<'a, P> {
type Item = &'a P;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -126,12 +126,12 @@ impl<'a, P: Pixel + 'static> Iterator for BresenhamLinePixelIter<'a, P> {

/// Iterates over the image pixels in a line segment using
/// [Bresenham's line drawing algorithm](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm).
pub struct BresenhamLinePixelIterMut<'a, P: Pixel + 'static> {
pub struct BresenhamLinePixelIterMut<'a, P: Pixel> {
iter: BresenhamLineIter,
image: &'a mut Image<P>,
}

impl<'a, P: Pixel + 'static> BresenhamLinePixelIterMut<'a, P> {
impl<'a, P: Pixel> BresenhamLinePixelIterMut<'a, P> {
/// Creates a [`BresenhamLinePixelIterMut`](struct.BresenhamLinePixelIterMut.html) which will iterate over
/// the image pixels with coordinates between `start` and `end`.
pub fn new(
Expand All @@ -154,7 +154,7 @@ impl<'a, P: Pixel + 'static> BresenhamLinePixelIterMut<'a, P> {
}
}

impl<'a, P: Pixel + 'static> Iterator for BresenhamLinePixelIterMut<'a, P> {
impl<'a, P: Pixel> Iterator for BresenhamLinePixelIterMut<'a, P> {
type Item = &'a mut P;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -179,7 +179,6 @@ pub fn draw_line_segment<I>(
) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand All @@ -195,7 +194,6 @@ where
pub fn draw_line_segment_mut<C>(canvas: &mut C, start: (f32, f32), end: (f32, f32), color: C::Pixel)
where
C: Canvas,
C::Pixel: 'static,
{
let (width, height) = canvas.dimensions();
let in_bounds = |x, y| x >= 0 && x < width as i32 && y >= 0 && y < height as i32;
Expand Down Expand Up @@ -230,7 +228,7 @@ pub fn draw_antialiased_line_segment<I, B>(
) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,

B: Fn(I::Pixel, I::Pixel, f32) -> I::Pixel,
{
let mut out = ImageBuffer::new(image.width(), image.height());
Expand All @@ -255,7 +253,7 @@ pub fn draw_antialiased_line_segment_mut<I, B>(
blend: B,
) where
I: GenericImage,
I::Pixel: 'static,

B: Fn(I::Pixel, I::Pixel, f32) -> I::Pixel,
{
let (mut x0, mut y0) = (start.0, start.1);
Expand Down Expand Up @@ -295,7 +293,7 @@ fn plot_wu_line<I, T, B>(
color: I::Pixel,
) where
I: GenericImage,
I::Pixel: 'static,

T: Fn(i32, i32) -> (i32, i32),
B: Fn(I::Pixel, I::Pixel, f32) -> I::Pixel,
{
Expand All @@ -314,7 +312,7 @@ fn plot_wu_line<I, T, B>(
struct Plotter<'a, I, T, B>
where
I: GenericImage,
I::Pixel: 'static,

T: Fn(i32, i32) -> (i32, i32),
B: Fn(I::Pixel, I::Pixel, f32) -> I::Pixel,
{
Expand All @@ -326,7 +324,7 @@ where
impl<'a, I, T, B> Plotter<'a, I, T, B>
where
I: GenericImage,
I::Pixel: 'static,

T: Fn(i32, i32) -> (i32, i32),
B: Fn(I::Pixel, I::Pixel, f32) -> I::Pixel,
{
Expand Down
1 change: 0 additions & 1 deletion src/drawing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub use self::text::{draw_text, draw_text_mut, text_size};
fn draw_if_in_bounds<C>(canvas: &mut C, x: i32, y: i32, color: C::Pixel)
where
C: Canvas,
C::Pixel: 'static,
{
if x >= 0 && x < canvas.width() as i32 && y >= 0 && y < canvas.height() as i32 {
canvas.draw_pixel(x as u32, y as u32, color);
Expand Down
2 changes: 0 additions & 2 deletions src/drawing/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::i32;
pub fn draw_polygon<I>(image: &I, poly: &[Point<i32>], color: I::Pixel) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand All @@ -32,7 +31,6 @@ where
pub fn draw_polygon_mut<C>(canvas: &mut C, poly: &[Point<i32>], color: C::Pixel)
where
C: Canvas,
C::Pixel: 'static,
{
if poly.is_empty() {
return;
Expand Down
4 changes: 0 additions & 4 deletions src/drawing/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::f32;
pub fn draw_hollow_rect<I>(image: &I, rect: Rect, color: I::Pixel) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand All @@ -26,7 +25,6 @@ where
pub fn draw_hollow_rect_mut<C>(canvas: &mut C, rect: Rect, color: C::Pixel)
where
C: Canvas,
C::Pixel: 'static,
{
let left = rect.left() as f32;
let right = rect.right() as f32;
Expand All @@ -46,7 +44,6 @@ where
pub fn draw_filled_rect<I>(image: &I, rect: Rect, color: I::Pixel) -> Image<I::Pixel>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand All @@ -60,7 +57,6 @@ where
pub fn draw_filled_rect_mut<C>(canvas: &mut C, rect: Rect, color: C::Pixel)
where
C: Canvas,
C::Pixel: 'static,
{
let canvas_bounds = Rect::at(0, 0).of_size(canvas.width(), canvas.height());
if let Some(intersection) = canvas_bounds.intersect(rect) {
Expand Down
1 change: 0 additions & 1 deletion src/drawing/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ pub fn draw_text<'a, I>(
where
I: GenericImage,
<I::Pixel as Pixel>::Subpixel: ValueInto<f32> + Clamp<f32>,
I::Pixel: 'static,
{
let mut out = ImageBuffer::new(image.width(), image.height());
out.copy_from(image, 0, 0).unwrap();
Expand Down
16 changes: 8 additions & 8 deletions src/filter/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ use std::cmp::{max, min};
#[must_use = "the function does not modify the original image"]
pub fn median_filter<P>(image: &Image<P>, x_radius: u32, y_radius: u32) -> Image<P>
where
P: Pixel<Subpixel = u8> + 'static,
P: Pixel<Subpixel = u8>,
{
let (width, height) = image.dimensions();

Expand Down Expand Up @@ -141,7 +141,7 @@ fn initialise_histogram_for_top_left_pixel<P>(
y_radius: u32,
) -> HistSet
where
P: Pixel<Subpixel = u8> + 'static,
P: Pixel<Subpixel = u8>,
{
let (width, height) = image.dimensions();
let kernel_size = (2 * x_radius + 1) * (2 * y_radius + 1);
Expand All @@ -166,7 +166,7 @@ where

fn slide_right<P>(hist: &mut HistSet, image: &Image<P>, x: u32, y: u32, rx: i32, ry: i32)
where
P: Pixel<Subpixel = u8> + 'static,
P: Pixel<Subpixel = u8>,
{
let (width, height) = image.dimensions();

Expand All @@ -189,7 +189,7 @@ fn slide_down_column<P>(
rx: i32,
ry: i32,
) where
P: Pixel<Subpixel = u8> + 'static,
P: Pixel<Subpixel = u8>,
{
let (width, height) = image.dimensions();
hist.set_to_median(out, x, 0);
Expand Down Expand Up @@ -217,7 +217,7 @@ fn slide_up_column<P>(
rx: i32,
ry: i32,
) where
P: Pixel<Subpixel = u8> + 'static,
P: Pixel<Subpixel = u8>,
{
let (width, height) = image.dimensions();
hist.set_to_median(out, x, height - 1);
Expand Down Expand Up @@ -265,7 +265,7 @@ impl HistSet {

fn incr<P>(&mut self, image: &Image<P>, x: u32, y: u32)
where
P: Pixel<Subpixel = u8> + 'static,
P: Pixel<Subpixel = u8>,
{
unsafe {
let pixel = image.unsafe_get_pixel(x, y);
Expand All @@ -280,7 +280,7 @@ impl HistSet {

fn decr<P>(&mut self, image: &Image<P>, x: u32, y: u32)
where
P: Pixel<Subpixel = u8> + 'static,
P: Pixel<Subpixel = u8>,
{
unsafe {
let pixel = image.unsafe_get_pixel(x, y);
Expand All @@ -295,7 +295,7 @@ impl HistSet {

fn set_to_median<P>(&self, image: &mut Image<P>, x: u32, y: u32)
where
P: Pixel<Subpixel = u8> + 'static,
P: Pixel<Subpixel = u8>,
{
unsafe {
let target = image.get_pixel_mut(x, y);
Expand Down
Loading