Debian Codegraph @

src/cint.rs

raw symbols SCIP
1 use crate::Color;
2 use cint::{Alpha, ColorInterop, EncodedSrgb};
3
4 impl ColorInterop for Color {
5 type CintTy = Alpha<EncodedSrgb<f32>>;
6 }
7
8 impl From<Color> for EncodedSrgb<f32> {
9 fn from(c: Color) -> Self {
10 let Color { r, g, b, a: _ } = c;
11 EncodedSrgb { r, g, b }
12 }
13 }
14
15 impl From<EncodedSrgb<f32>> for Color {
16 fn from(c: EncodedSrgb<f32>) -> Self {
17 let EncodedSrgb { r, g, b } = c;
18 Self::new(r, g, b, 1.0)
19 }
20 }
21
22 impl From<Color> for EncodedSrgb<f64> {
23 fn from(c: Color) -> Self {
24 let Color { r, g, b, a: _ } = c;
25 let (r, g, b) = (r as f64, g as f64, b as f64);
26 EncodedSrgb { r, g, b }
27 }
28 }
29
30 impl From<EncodedSrgb<f64>> for Color {
31 fn from(c: EncodedSrgb<f64>) -> Self {
32 let EncodedSrgb { r, g, b } = c;
33 let (r, g, b) = (r as f32, g as f32, b as f32);
34 Self::new(r, g, b, 1.0)
35 }
36 }
37
38 impl From<Color> for Alpha<EncodedSrgb<f32>> {
39 fn from(c: Color) -> Self {
40 let Color { r, g, b, a } = c;
41 Alpha {
42 color: EncodedSrgb { r, g, b },
43 alpha: a,
44 }
45 }
46 }
47
48 impl From<Alpha<EncodedSrgb<f32>>> for Color {
49 fn from(c: Alpha<EncodedSrgb<f32>>) -> Self {
50 let Alpha {
51 color: EncodedSrgb { r, g, b },
52 alpha,
53 } = c;
54 Self::new(r, g, b, alpha)
55 }
56 }
57
58 impl From<Color> for Alpha<EncodedSrgb<f64>> {
59 fn from(c: Color) -> Self {
60 let Color { r, g, b, a } = c;
61 let (r, g, b, alpha) = (r as f64, g as f64, b as f64, a as f64);
62 Alpha {
63 color: EncodedSrgb { r, g, b },
64 alpha,
65 }
66 }
67 }
68
69 impl From<Alpha<EncodedSrgb<f64>>> for Color {
70 fn from(c: Alpha<EncodedSrgb<f64>>) -> Self {
71 let Alpha {
72 color: EncodedSrgb { r, g, b },
73 alpha,
74 } = c;
75 let (r, g, b, alpha) = (r as f32, g as f32, b as f32, alpha as f32);
76 Self::new(r, g, b, alpha)
77 }
78 }
79
80 impl From<Color> for EncodedSrgb<u8> {
81 fn from(c: Color) -> Self {
82 let [r, g, b, _] = c.to_rgba8();
83 EncodedSrgb { r, g, b }
84 }
85 }
86
87 impl From<EncodedSrgb<u8>> for Color {
88 fn from(c: EncodedSrgb<u8>) -> Self {
89 let EncodedSrgb { r, g, b } = c;
90 Self::from_rgba8(r, g, b, 255)
91 }
92 }
93
94 impl From<Color> for Alpha<EncodedSrgb<u8>> {
95 fn from(c: Color) -> Self {
96 let [r, g, b, alpha] = c.to_rgba8();
97 Alpha {
98 color: EncodedSrgb { r, g, b },
99 alpha,
100 }
101 }
102 }
103
104 impl From<Alpha<EncodedSrgb<u8>>> for Color {
105 fn from(c: Alpha<EncodedSrgb<u8>>) -> Self {
106 let Alpha {
107 color: EncodedSrgb { r, g, b },
108 alpha,
109 } = c;
110 Self::from_rgba8(r, g, b, alpha)
111 }
112 }