diff --git a/examples/contours.rs b/examples/contours.rs index ef4f52a..87b9c69 100644 --- a/examples/contours.rs +++ b/examples/contours.rs @@ -2,27 +2,14 @@ mod common; use ccvl::*; -const OUTER: image::SRGBA = image::SRGBA { - r: 0.0, - g: 1.0, - b: 0.0, - a: 1.0, -}; -const INNER: image::SRGBA = image::SRGBA { - r: 0.0, - g: 0.0, - b: 1.0, - a: 1.0, -}; - fn draw(contour: &contour::Contour, img: &mut image::Image) { let n = contour.vertices.len(); for i in 0..n { let (x0, y0) = contour.vertices[i]; let (x1, y1) = contour.vertices[(i + 1) % n]; let colour = match contour.kind { - contour::Kind::Outer => OUTER, - contour::Kind::Inner => INNER, + contour::Kind::Outer => colours::GREEN, + contour::Kind::Inner => colours::BLUE, }; draw::line(x0, y0, x1, y1, img, colour); } diff --git a/examples/hough.rs b/examples/hough.rs index 8a4e7ec..350f9b8 100644 --- a/examples/hough.rs +++ b/examples/hough.rs @@ -2,20 +2,13 @@ mod common; use ccvl::*; -const LINE: image::SRGBA = image::SRGBA { - r: 1.0, - g: 0.0, - b: 0.0, - a: 1.0, -}; - fn main() -> std::process::ExitCode { common::process_image(|mut img| { let greyscale = img.map(|p| image::Luminance::from(p)); let edges = filter::canny(greyscale); for line in hough::lines(10.0, edges) { let ((x0, y0), (x1, y1)) = endpoints(line, img.extent); - draw::line(x0, y0, x1, y1, &mut img, LINE); + draw::line(x0, y0, x1, y1, &mut img, colours::RED); } img }) diff --git a/src/colours.rs b/src/colours.rs new file mode 100644 index 0000000..5e9b77c --- /dev/null +++ b/src/colours.rs @@ -0,0 +1,21 @@ +use crate::*; + +macro_rules! hex { + ( $value:literal ) => { + image::SRGBA { + r: (($value >> 16) & 0xff) as f32 / 255.0, + g: (($value >> 8) & 0xff) as f32 / 255.0, + b: ($value & 0xff) as f32 / 255.0, + a: 1.0, + } + } +} + +pub const BLACK: image::SRGBA = hex!(0x000000); +pub const RED: image::SRGBA = hex!(0xff0000); +pub const GREEN: image::SRGBA = hex!(0x00ff00); +pub const BLUE: image::SRGBA = hex!(0x0000ff); +pub const CYAN: image::SRGBA = hex!(0x00ffff); +pub const MAGENTA: image::SRGBA = hex!(0xff00ff); +pub const YELLOW: image::SRGBA = hex!(0xffff00); +pub const WHITE: image::SRGBA = hex!(0xffffff); diff --git a/src/lib.rs b/src/lib.rs index 6e07453..a176d15 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +pub mod colours; pub mod contour; pub mod draw; pub mod filter;