[][src]Macro imageproc::gray_image

macro_rules! gray_image {
    () => { ... };
    (type: $channel_type:ty) => { ... };
    ($( $( $x: expr ),*);*) => { ... };
    (type: $channel_type:ty, $( $( $x: expr ),*);*) => { ... };
}

Helper for defining greyscale images.

Columns are separated by commas and rows by semi-colons. By default a subpixel type of u8 is used but this can be overridden, as shown in the examples.

Examples

use image::{GrayImage, ImageBuffer, Luma};

// An empty grayscale image with pixel type Luma<u8>
let empty = gray_image!();

assert_pixels_eq!(
    empty,
    GrayImage::from_raw(0, 0, vec![]).unwrap()
);

// A single pixel grayscale image with pixel type Luma<u8>
let single_pixel = gray_image!(1);

assert_pixels_eq!(
    single_pixel,
    GrayImage::from_raw(1, 1, vec![1]).unwrap()
);

// A single row grayscale image with pixel type Luma<u8>
let single_row = gray_image!(1, 2, 3);

assert_pixels_eq!(
    single_row,
    GrayImage::from_raw(3, 1, vec![1, 2, 3]).unwrap()
);

// A grayscale image with 2 rows and 3 columns
let image = gray_image!(
    1, 2, 3;
    4, 5, 6);

let equivalent = GrayImage::from_raw(3, 2, vec![
    1, 2, 3,
    4, 5, 6
]).unwrap();

// An empty grayscale image with pixel type Luma<i16>.
let empty_i16 = gray_image!(type: i16);

assert_pixels_eq!(
    empty_i16,
    ImageBuffer::<Luma<i16>, Vec<i16>>::from_raw(0, 0, vec![]).unwrap()
);

// A grayscale image with 2 rows, 3 columns and pixel type Luma<i16>
let image_i16 = gray_image!(type: i16,
    1, 2, 3;
    4, 5, 6);

let expected_i16 = ImageBuffer::<Luma<i16>, Vec<i16>>::from_raw(3, 2, vec![
    1, 2, 3,
    4, 5, 6]).unwrap();

assert_pixels_eq!(image_i16, expected_i16);