@@ -103,6 +103,7 @@ impl ColorType for Color {
103103impl ColorType for TriColor {
104104 const BITS_PER_PIXEL_PER_BUFFER : usize = 1 ;
105105 const BUFFER_COUNT : usize = 2 ;
106+
106107 fn bitmask ( & self , bwrbit : bool , pos : u32 ) -> ( u8 , u16 ) {
107108 let bit = 0x80 >> ( pos % 8 ) ;
108109 match self {
@@ -307,16 +308,16 @@ impl From<BinaryColor> for Color {
307308impl From < embedded_graphics_core:: pixelcolor:: Rgb888 > for Color {
308309 fn from ( rgb : embedded_graphics_core:: pixelcolor:: Rgb888 ) -> Self {
309310 use embedded_graphics_core:: pixelcolor:: RgbColor ;
310- if rgb == RgbColor :: BLACK {
311- Color :: Black
312- } else if rgb == RgbColor :: WHITE {
313- Color :: White
314- } else {
315- // choose closest color
316- if ( rgb . r ( ) as u16 + rgb . g ( ) as u16 + rgb . b ( ) as u16 ) > 255 * 3 / 2 {
317- Color :: White
318- } else {
319- Color :: Black
311+ match rgb {
312+ RgbColor :: BLACK => Color :: Black ,
313+ RgbColor :: WHITE => Color :: White ,
314+ _ => {
315+ // choose closest color
316+ if ( rgb . r ( ) as u16 + rgb . g ( ) as u16 + rgb . b ( ) as u16 ) > 255 * 3 / 2 {
317+ Color :: White
318+ } else {
319+ Color :: Black
320+ }
320321 }
321322 }
322323 }
@@ -369,13 +370,11 @@ impl From<BinaryColor> for TriColor {
369370impl From < embedded_graphics_core:: pixelcolor:: Rgb888 > for TriColor {
370371 fn from ( rgb : embedded_graphics_core:: pixelcolor:: Rgb888 ) -> Self {
371372 use embedded_graphics_core:: pixelcolor:: RgbColor ;
372- if rgb == RgbColor :: BLACK {
373- TriColor :: Black
374- } else if rgb == RgbColor :: WHITE {
375- TriColor :: White
376- } else {
373+ match rgb {
374+ RgbColor :: BLACK => TriColor :: Black ,
375+ RgbColor :: WHITE => TriColor :: White ,
377376 // there is no good approximation here since we don't know which color is 'chromatic'
378- TriColor :: Chromatic
377+ _ => TriColor :: Chromatic ,
379378 }
380379 }
381380}
0 commit comments