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(
18 r.clamp(0.0, 1.0),
19 g.clamp(0.0, 1.0),
20 b.clamp(0.0, 1.0),
21 )
22 }
23
24 pub fn gray(value: f64) -> Self {
26 Color::Gray(value.clamp(0.0, 1.0))
27 }
28
29 pub fn cmyk(c: f64, m: f64, y: f64, k: f64) -> Self {
31 Color::Cmyk(
32 c.clamp(0.0, 1.0),
33 m.clamp(0.0, 1.0),
34 y.clamp(0.0, 1.0),
35 k.clamp(0.0, 1.0),
36 )
37 }
38
39 pub fn black() -> Self {
41 Color::Gray(0.0)
42 }
43
44 pub fn white() -> Self {
46 Color::Gray(1.0)
47 }
48
49 pub fn red() -> Self {
51 Color::Rgb(1.0, 0.0, 0.0)
52 }
53
54 pub fn green() -> Self {
56 Color::Rgb(0.0, 1.0, 0.0)
57 }
58
59 pub fn blue() -> Self {
61 Color::Rgb(0.0, 0.0, 1.0)
62 }
63
64 pub fn yellow() -> Self {
65 Color::Rgb(1.0, 1.0, 0.0)
66 }
67
68 pub fn cyan() -> Self {
69 Color::Rgb(0.0, 1.0, 1.0)
70 }
71
72 pub fn magenta() -> Self {
73 Color::Rgb(1.0, 0.0, 1.0)
74 }
75}