From 72d4e52009915513f6caf97f5db10deb2d4b083e Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Sat, 17 Nov 2018 15:33:00 +0200 Subject: [PATCH] [DISP] Works on raspi this way --- src/platform/display.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/platform/display.rs b/src/platform/display.rs index ab386f5..1f3a2f7 100644 --- a/src/platform/display.rs +++ b/src/platform/display.rs @@ -96,18 +96,21 @@ impl Display { } } + #[inline] + fn color_component(&self, chan: u16) -> u32 { + u32::from(if self.order == PixelOrder::BGR { + 2 - chan + } else { + chan + }) + } + pub fn putpixel(&mut self, x: u16, y: u16, color: u32) { - let c = |chan: u16| { - if self.order == PixelOrder::BGR { - 2 - chan - } else { - chan - } - }; - let f = |v: u32, chan: u16| unsafe { - *(self.base as *mut u8).offset( - (y as u32 * self.pitch + x as u32 * (self.depth / 8) + c(chan) as u32) as isize, - ) = v as u8; + let f = |mut v: u32, chan: u16| unsafe { + *(self.base as *mut u8) + .offset((u32::from(y) * self.pitch + + u32::from(x) * 4//(self.depth / 8) + + self.color_component(chan)) as isize) = v as u8; }; f(color & 0xff, 0);