2828/// assert_eq!(red.r, 255);
2929/// assert_eq!(red.g, 128);
3030/// assert_eq!(red.b, 0);
31- /// assert_eq!(red.a, 0xff);
3231///
3332/// let from_struct_literal = Pixel { r: 255, g: 0x80, b: 0, a: 0xff };
3433/// assert_eq!(red, from_struct_literal);
6362///
6463/// if cfg!(target_family = "wasm") {
6564/// // RGBX
66- /// assert_eq!(red, u32::from_ne_bytes([0xff, 0x00, 0x00, 0xff ]));
65+ /// assert_eq!(red, u32::from_ne_bytes([0xff, 0x00, 0x00, 0x00 ]));
6766/// } else {
6867/// // BGRX
69- /// assert_eq!(red, u32::from_ne_bytes([0x00, 0x00, 0xff, 0xff ]));
68+ /// assert_eq!(red, u32::from_ne_bytes([0x00, 0x00, 0xff, 0x00 ]));
7069/// }
7170/// ```
7271#[ repr( C ) ]
7372#[ repr( align( 4 ) ) ] // May help the compiler to see that this is a u32
74- #[ derive( Copy , Clone , Debug , Default , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
73+ #[ derive( Copy , Clone , Debug , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
7574pub struct Pixel {
7675 #[ cfg( target_family = "wasm" ) ]
7776 /// The red component.
@@ -97,17 +96,28 @@ pub struct Pixel {
9796 ///
9897 /// `0xff` here means opaque, whereas `0` means transparent.
9998 ///
100- /// NOTE: Transparency is yet poorly supported, see [#17], until that is resolved, you will
101- /// probably want to set this to `0xff`.
99+ /// NOTE: Transparency is not yet supported, see [#17], so this doesn't actually do anything.
102100 ///
103101 /// [#17]: https://github.com/rust-windowing/softbuffer/issues/17
104- pub a : u8 ,
102+ pub ( crate ) a : u8 ,
103+ }
104+
105+ impl Default for Pixel {
106+ /// A black opaque pixel.
107+ fn default ( ) -> Self {
108+ Self {
109+ r : 0 ,
110+ g : 0 ,
111+ b : 0 ,
112+ a : 0xff ,
113+ }
114+ }
105115}
106116
107117impl Pixel {
108118 /// Creates a new pixel from a red, a green and a blue component.
109119 ///
110- /// The alpha component is set to opaque.
120+ /// The pixel is opaque.
111121 ///
112122 /// # Example
113123 ///
@@ -123,7 +133,7 @@ impl Pixel {
123133
124134 /// Creates a new pixel from a blue, a green and a red component.
125135 ///
126- /// The alpha component is set to opaque.
136+ /// The pixel is opaque.
127137 ///
128138 /// # Example
129139 ///
0 commit comments