11use super :: color_traits:: { Alpha , AlphaMut , AssociatedAlpha , Luminance , LuminanceMut , Pixel , RGB , RGBMut , Rec709Primaries , SRGB } ;
22use super :: discrete_srgb:: { float_to_srgb_u8, srgb_u8_to_float} ;
33use bytemuck:: { Pod , Zeroable } ;
4+ use core:: fmt:: Debug ;
45use core:: hash:: Hash ;
56use half:: f16;
67#[ cfg( target_arch = "spirv" ) ]
7- use spirv_std :: num_traits:: Euclid ;
8+ use num_traits:: Euclid ;
89#[ cfg( target_arch = "spirv" ) ]
9- use spirv_std :: num_traits:: float:: Float ;
10+ use num_traits:: float:: Float ;
1011
1112#[ repr( C ) ]
12- #[ derive( Debug , Default , Clone , Copy , PartialEq , Pod , Zeroable ) ]
13+ #[ derive( Default , Clone , Copy , PartialEq , Pod , Zeroable ) ]
14+ #[ cfg_attr( not( target_arch = "spirv" ) , derive( Debug ) ) ]
1315#[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , serde:: Serialize , serde:: Deserialize ) ) ]
1416pub struct RGBA16F {
1517 red : f16 ,
@@ -18,6 +20,14 @@ pub struct RGBA16F {
1820 alpha : f16 ,
1921}
2022
23+ /// hack around half still masking out impl Debug for f16 on spirv
24+ #[ cfg( target_arch = "spirv" ) ]
25+ impl core:: fmt:: Debug for RGBA16F {
26+ fn fmt ( & self , _f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
27+ Ok ( ( ) )
28+ }
29+ }
30+
2131impl From < Color > for RGBA16F {
2232 #[ inline( always) ]
2333 fn from ( c : Color ) -> Self {
@@ -215,7 +225,7 @@ pub struct Color {
215225
216226#[ allow( clippy:: derived_hash_with_manual_eq) ]
217227impl Hash for Color {
218- fn hash < H : std :: hash:: Hasher > ( & self , state : & mut H ) {
228+ fn hash < H : core :: hash:: Hasher > ( & self , state : & mut H ) {
219229 self . red . to_bits ( ) . hash ( state) ;
220230 self . green . to_bits ( ) . hash ( state) ;
221231 self . blue . to_bits ( ) . hash ( state) ;
@@ -256,7 +266,7 @@ impl AlphaMut for Color {
256266}
257267
258268impl Pixel for Color {
259- #[ cfg( not ( target_arch = "spirv" ) ) ]
269+ #[ cfg( feature = "std" ) ]
260270 fn to_bytes ( & self ) -> Vec < u8 > {
261271 self . to_rgba8_srgb ( ) . to_vec ( )
262272 }
@@ -793,6 +803,7 @@ impl Color {
793803 /// let color = Color::from_rgba8_srgb(0x52, 0x67, 0xFA, 0x61); // Premultiplied alpha
794804 /// assert_eq!("3240a261", color.to_rgba_hex_srgb()); // Equivalent hex incorporating premultiplied alpha
795805 /// ```
806+ #[ cfg( feature = "std" ) ]
796807 pub fn to_rgba_hex_srgb ( & self ) -> String {
797808 let gamma = self . to_gamma_srgb ( ) ;
798809 format ! (
@@ -810,6 +821,7 @@ impl Color {
810821 /// let color = Color::from_rgba8_srgb(0x52, 0x67, 0xFA, 0x61); // Premultiplied alpha
811822 /// assert_eq!("3240a2", color.to_rgb_hex_srgb()); // Equivalent hex incorporating premultiplied alpha
812823 /// ```
824+ #[ cfg( feature = "std" ) ]
813825 pub fn to_rgb_hex_srgb ( & self ) -> String {
814826 self . to_gamma_srgb ( ) . to_rgb_hex_srgb_from_gamma ( )
815827 }
@@ -820,6 +832,7 @@ impl Color {
820832 /// let color = Color::from_rgba8_srgb(0x52, 0x67, 0xFA, 0x61); // Premultiplied alpha
821833 /// assert_eq!("3240a2", color.to_rgb_hex_srgb()); // Equivalent hex incorporating premultiplied alpha
822834 /// ```
835+ #[ cfg( feature = "std" ) ]
823836 pub fn to_rgb_hex_srgb_from_gamma ( & self ) -> String {
824837 format ! ( "{:02x?}{:02x?}{:02x?}" , ( self . r( ) * 255. ) as u8 , ( self . g( ) * 255. ) as u8 , ( self . b( ) * 255. ) as u8 )
825838 }
0 commit comments