iced_graphics/
color.rs
1use crate::core::Color;
3
4use bytemuck::{Pod, Zeroable};
5
6#[derive(Debug, Clone, Copy, PartialEq, Zeroable, Pod)]
8#[repr(C)]
9pub struct Packed([f32; 4]);
10
11impl Packed {
12 pub fn components(self) -> [f32; 4] {
14 self.0
15 }
16}
17
18pub const GAMMA_CORRECTION: bool = internal::GAMMA_CORRECTION;
20
21pub fn pack(color: impl Into<Color>) -> Packed {
23 Packed(internal::pack(color.into()))
24}
25
26#[cfg(not(feature = "web-colors"))]
27mod internal {
28 use crate::core::Color;
29
30 pub const GAMMA_CORRECTION: bool = true;
31
32 pub fn pack(color: Color) -> [f32; 4] {
33 color.into_linear()
34 }
35}
36
37#[cfg(feature = "web-colors")]
38mod internal {
39 use crate::core::Color;
40
41 pub const GAMMA_CORRECTION: bool = false;
42
43 pub fn pack(color: Color) -> [f32; 4] {
44 [color.r, color.g, color.b, color.a]
45 }
46}