oxidize_pdf/graphics/
color.rs1#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum Color {
6 Rgb(f64, f64, f64),
8 Gray(f64),
10 Cmyk(f64, f64, f64, f64),
12}
13
14impl Color {
15 pub fn rgb(r: f64, g: f64, b: f64) -> Self {
17 Color::Rgb(r.clamp(0.0, 1.0), g.clamp(0.0, 1.0), b.clamp(0.0, 1.0))
18 }
19
20 pub fn gray(value: f64) -> Self {
22 Color::Gray(value.clamp(0.0, 1.0))
23 }
24
25 pub fn cmyk(c: f64, m: f64, y: f64, k: f64) -> Self {
27 Color::Cmyk(
28 c.clamp(0.0, 1.0),
29 m.clamp(0.0, 1.0),
30 y.clamp(0.0, 1.0),
31 k.clamp(0.0, 1.0),
32 )
33 }
34
35 pub fn black() -> Self {
37 Color::Gray(0.0)
38 }
39
40 pub fn white() -> Self {
42 Color::Gray(1.0)
43 }
44
45 pub fn red() -> Self {
47 Color::Rgb(1.0, 0.0, 0.0)
48 }
49
50 pub fn green() -> Self {
52 Color::Rgb(0.0, 1.0, 0.0)
53 }
54
55 pub fn blue() -> Self {
57 Color::Rgb(0.0, 0.0, 1.0)
58 }
59
60 pub fn yellow() -> Self {
61 Color::Rgb(1.0, 1.0, 0.0)
62 }
63
64 pub fn cyan() -> Self {
65 Color::Rgb(0.0, 1.0, 1.0)
66 }
67
68 pub fn magenta() -> Self {
69 Color::Rgb(1.0, 0.0, 1.0)
70 }
71}