Create colours module with colour definitions
This commit is contained in:
1 parent
7f29c5abbb
commit
f25e9a00a8
4 files changed
+25
-23
No files matched your search
+2
-15
@@ -2,27 +2,14 @@ mod common;
|
|||||||
|
|
||||||
use ccvl::*;
|
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<image::SRGBA>) {
|
fn draw(contour: &contour::Contour, img: &mut image::Image<image::SRGBA>) {
|
||||||
let n = contour.vertices.len();
|
let n = contour.vertices.len();
|
||||||
for i in 0..n {
|
for i in 0..n {
|
||||||
let (x0, y0) = contour.vertices[i];
|
let (x0, y0) = contour.vertices[i];
|
||||||
let (x1, y1) = contour.vertices[(i + 1) % n];
|
let (x1, y1) = contour.vertices[(i + 1) % n];
|
||||||
let colour = match contour.kind {
|
let colour = match contour.kind {
|
||||||
contour::Kind::Outer => OUTER,
|
contour::Kind::Outer => colours::GREEN,
|
||||||
contour::Kind::Inner => INNER,
|
contour::Kind::Inner => colours::BLUE,
|
||||||
};
|
};
|
||||||
draw::line(x0, y0, x1, y1, img, colour);
|
draw::line(x0, y0, x1, y1, img, colour);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-8
@@ -2,20 +2,13 @@ mod common;
|
|||||||
|
|
||||||
use ccvl::*;
|
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 {
|
fn main() -> std::process::ExitCode {
|
||||||
common::process_image(|mut img| {
|
common::process_image(|mut img| {
|
||||||
let greyscale = img.map(|p| image::Luminance::from(p));
|
let greyscale = img.map(|p| image::Luminance::from(p));
|
||||||
let edges = filter::canny(greyscale);
|
let edges = filter::canny(greyscale);
|
||||||
for line in hough::lines(10.0, edges) {
|
for line in hough::lines(10.0, edges) {
|
||||||
let ((x0, y0), (x1, y1)) = endpoints(line, img.extent);
|
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
|
img
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
pub mod colours;
|
||||||
pub mod contour;
|
pub mod contour;
|
||||||
pub mod draw;
|
pub mod draw;
|
||||||
pub mod filter;
|
pub mod filter;
|
||||||
|
|||||||
Reference in new issue
Block a user