Skip to content

Commit

Permalink
Migrate to image 0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
okaneco committed Mar 1, 2022
1 parent 9fb0ea3 commit e501161
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/hog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ pub fn render_hist_grid(star_side: u32, grid: &View3d<'_, f32>, signed: bool) ->
let x_window = x as u32 * star_side;
let mut window = out.sub_image(x_window, y_window, star_side, star_side);
let hist = grid.inner_slice(x, y);
draw_star_mut(&mut window, hist, signed);
draw_star_mut(window.inner_mut(), hist, signed);
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/integral_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ impl<T: Primitive> ArrayData for Luma<T> {
}
}

impl<T: Primitive> ArrayData for Rgb<T> {
impl<T> ArrayData for Rgb<T>
where
Rgb<T>: Pixel<Subpixel = T>,
T: Primitive,
{
type DataType = [T; 3];

fn data(&self) -> Self::DataType {
Expand All @@ -195,7 +199,11 @@ impl<T: Primitive> ArrayData for Rgb<T> {
}
}

impl<T: Primitive> ArrayData for Rgba<T> {
impl<T> ArrayData for Rgba<T>
where
Rgba<T>: Pixel<Subpixel = T>,
T: Primitive,
{
type DataType = [T; 4];

fn data(&self) -> Self::DataType {
Expand Down
14 changes: 14 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub type ChannelMap<Pix, Sub> = <Pix as WithChannel<Sub>>::Pixel;

impl<T, U> WithChannel<U> for Rgb<T>
where
Rgb<T>: Pixel<Subpixel = T>,
Rgb<U>: Pixel<Subpixel = U>,
T: Primitive,
U: Primitive,
{
Expand All @@ -25,6 +27,8 @@ where

impl<T, U> WithChannel<U> for Rgba<T>
where
Rgba<T>: Pixel<Subpixel = T>,
Rgba<U>: Pixel<Subpixel = U>,
T: Primitive,
U: Primitive,
{
Expand All @@ -33,6 +37,8 @@ where

impl<T, U> WithChannel<U> for Luma<T>
where
Luma<T>: Pixel<Subpixel = T>,
Luma<U>: Pixel<Subpixel = U>,
T: Primitive,
U: Primitive,
{
Expand All @@ -41,6 +47,8 @@ where

impl<T, U> WithChannel<U> for LumaA<T>
where
LumaA<T>: Pixel<Subpixel = T>,
LumaA<U>: Pixel<Subpixel = U>,
T: Primitive,
U: Primitive,
{
Expand Down Expand Up @@ -414,6 +422,7 @@ where
pub fn red_channel<I, C>(image: &I) -> Image<Luma<C>>
where
I: GenericImage<Pixel = Rgb<C>>,
Rgb<C>: Pixel<Subpixel = C>,
C: Primitive,
{
map_colors(image, |p| Luma([p[0]]))
Expand Down Expand Up @@ -445,6 +454,7 @@ where
pub fn as_red_channel<I, C>(image: &I) -> Image<Rgb<C>>
where
I: GenericImage<Pixel = Luma<C>>,
Rgb<C>: Pixel<Subpixel = C>,
C: Primitive,
{
map_colors(image, |p| {
Expand Down Expand Up @@ -480,6 +490,7 @@ where
pub fn green_channel<I, C>(image: &I) -> Image<Luma<C>>
where
I: GenericImage<Pixel = Rgb<C>>,
Rgb<C>: Pixel<Subpixel = C>,
C: Primitive,
{
map_colors(image, |p| Luma([p[1]]))
Expand Down Expand Up @@ -511,6 +522,7 @@ where
pub fn as_green_channel<I, C>(image: &I) -> Image<Rgb<C>>
where
I: GenericImage<Pixel = Luma<C>>,
Rgb<C>: Pixel<Subpixel = C>,
C: Primitive,
{
map_colors(image, |p| {
Expand Down Expand Up @@ -546,6 +558,7 @@ where
pub fn blue_channel<I, C>(image: &I) -> Image<Luma<C>>
where
I: GenericImage<Pixel = Rgb<C>>,
Rgb<C>: Pixel<Subpixel = C>,
C: Primitive,
{
map_colors(image, |p| Luma([p[2]]))
Expand Down Expand Up @@ -577,6 +590,7 @@ where
pub fn as_blue_channel<I, C>(image: &I) -> Image<Rgb<C>>
where
I: GenericImage<Pixel = Luma<C>>,
Rgb<C>: Pixel<Subpixel = C>,
C: Primitive,
{
map_colors(image, |p| {
Expand Down
1 change: 1 addition & 0 deletions src/property_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub trait ArbitraryPixel {
fn shrink<I>(image: &I) -> Box<dyn Iterator<Item = Image<I::Pixel>>>
where
I: GenericImage,
I::Pixel: 'static,
{
let mut subs = vec![];

Expand Down
13 changes: 8 additions & 5 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
#[macro_use]
extern crate imageproc;

use image::{DynamicImage, GrayImage, ImageBuffer, Luma, Pixel, Rgb, RgbImage, Rgba, RgbaImage};
use image::{
DynamicImage, GrayImage, ImageBuffer, Luma, Pixel, PixelWithColorType, Rgb, RgbImage, Rgba,
RgbaImage,
};
use imageproc::{
definitions::{Clamp, HasBlack, HasWhite},
edges::canny,
Expand Down Expand Up @@ -65,7 +68,7 @@ impl FromDynamic for RgbaImage {
/// Loads an input image, applies a function to it and checks that the result matches a 'truth' image.
fn compare_to_truth<P, F>(input_file_name: &str, truth_file_name: &str, op: F)
where
P: Pixel<Subpixel = u8>,
P: Pixel<Subpixel = u8> + PixelWithColorType,
ImageBuffer<P, Vec<u8>>: FromDynamic,
F: Fn(&ImageBuffer<P, Vec<u8>>) -> ImageBuffer<P, Vec<u8>>,
{
Expand All @@ -80,7 +83,7 @@ fn compare_to_truth_with_tolerance<P, F>(
op: F,
tol: u8,
) where
P: Pixel<Subpixel = u8>,
P: Pixel<Subpixel = u8> + PixelWithColorType,
ImageBuffer<P, Vec<u8>>: FromDynamic,
F: Fn(&ImageBuffer<P, Vec<u8>>) -> ImageBuffer<P, Vec<u8>>,
{
Expand All @@ -94,7 +97,7 @@ fn compare_to_truth_with_tolerance<P, F>(
/// Checks that an image matches a 'truth' image.
fn compare_to_truth_image<P>(actual: &ImageBuffer<P, Vec<u8>>, truth_file_name: &str)
where
P: Pixel<Subpixel = u8>,
P: Pixel<Subpixel = u8> + PixelWithColorType,
ImageBuffer<P, Vec<u8>>: FromDynamic,
{
compare_to_truth_image_with_tolerance(actual, truth_file_name, 0u8);
Expand All @@ -106,7 +109,7 @@ fn compare_to_truth_image_with_tolerance<P>(
truth_file_name: &str,
tol: u8,
) where
P: Pixel<Subpixel = u8>,
P: Pixel<Subpixel = u8> + PixelWithColorType,
ImageBuffer<P, Vec<u8>>: FromDynamic,
{
if should_regenerate() {
Expand Down

0 comments on commit e501161

Please sign in to comment.