diff --git a/einkfb.c b/einkfb.c index b5a3bf50b..b87c4905f 100644 --- a/einkfb.c +++ b/einkfb.c @@ -41,8 +41,8 @@ inline void fbInvert4BppTo8Bpp(FBInfo *fb) { fb_pitch = fb->real_buf->pitch; /* copy bitmap from 4bpp shadow blitbuffer to framebuffer */ - for (i = (h-1); i > 0; i--) { - for (j = (w-1)/2; j > 0; j--) { + for (i = (h-1); i >= 0; i--) { + for (j = (w-1)/2; j >= 0; j--) { fb_buf[i*fb_pitch + j*2] = shadow_buf[i*pitch + j]; fb_buf[i*fb_pitch + j*2] &= 0xF0; fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F; @@ -60,18 +60,18 @@ inline void fb4BppTo8Bpp(FBInfo *fb) { shadow_buf = fb->buf->data; fb_buf = fb->real_buf->data; - /* h is 1024 for PaperWhite */ + /* h is 1024 for PaperWhite's shadow buffer */ h = fb->buf->h; - /* w is 758 for PaperWhite */ + /* w is 758 for PaperWhite's shadow buffer */ w = fb->buf->w; - /* pitch is 384 for shadow buffer */ + /* pitch is 376 for shadow buffer */ pitch = fb->buf->pitch; - /* pitch is 768 for PaperWhite */ + /* pitch is 768 for PaperWhite's framebuffer */ fb_pitch = fb->real_buf->pitch; /* copy bitmap from 4bpp shadow blitbuffer to framebuffer */ - for (i = (h-1); i > 0; i--) { - for (j = (w-1)/2; j > 0; j--) { + for (i = (h-1); i >= 0; i--) { + for (j = (w-1)/2; j >= 0; j--) { fb_buf[i*fb_pitch + j*2] = shadow_buf[i*pitch + j]; fb_buf[i*fb_pitch + j*2] &= 0xF0; fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F; @@ -222,10 +222,16 @@ static int openFrameBuffer(lua_State *L) { } if (fb->vinfo.bits_per_pixel == 8) { - /* for 8bpp K4, PaperWhite, we create a shadow 4bpp blitbuffer. These - * models use 16 scale 8bpp framebuffer, so we still cheat it as 4bpp + /* for 8bpp K4, PaperWhite, we create a shadow 4bpp blitbuffer. + * These models use 16 scale 8bpp framebuffer, so they are + * actually fake 8bpp FB. Therefore, we still treat them as 4bpp + * + * For PaperWhite, the screen width is 758, but FB's line_length + * is 768. So when doing the screen update, you still need to + * fill 768 pixels per line, but the trailing 10 px for each + * line is actually ignored by driver. * */ - fb->buf->pitch = fb->finfo.line_length / 2; + fb->buf->pitch = fb->vinfo.xres / 2; fb->buf->data = (uint8_t *)calloc(fb->buf->pitch * fb->vinfo.yres, sizeof(uint8_t)); if (!fb->buf->data) { diff --git a/frontend/ui/screen.lua b/frontend/ui/screen.lua index 5844af55d..2f5a8840a 100644 --- a/frontend/ui/screen.lua +++ b/frontend/ui/screen.lua @@ -42,7 +42,6 @@ Codes for rotation modes: Screen = { width = 0, height = 0, - pitch = 0, native_rotation_mode = nil, cur_rotation_mode = 0, @@ -53,12 +52,11 @@ Screen = { } function Screen:init() - _, self.height = self.fb:getSize() - -- for unknown strange reason, pitch*2 is less than screen width in KPW - -- so we need to calculate width by pitch here - self.pitch = self.fb:getPitch() - self.width = self.pitch * 2 - self.bb = Blitbuffer.new(self.width, self.height, self.pitch) + -- for unknown strange reason, pitch*2 is 10 px more than screen width in KPW + self.width, self.height = self.fb:getSize() + -- Blitbuffer still uses inverted 4bpp bitmap, so pitch should be + -- (self.width / 2) + self.bb = Blitbuffer.new(self.width, self.height, self.width/2) if self.width > self.height then -- For another unknown strange reason, self.fb:getOrientation always -- return 0 in KPW, even though we are in landscape mode. @@ -102,7 +100,7 @@ function Screen:getDPI() end function Screen:getPitch() - return self.ptich + return self.fb:getPitch() end function Screen:getNativeRotationMode() @@ -133,8 +131,7 @@ function Screen:setRotationMode(mode) end self.cur_rotation_mode = mode self.bb:free() - self.pitch = self.width/2 - self.bb = Blitbuffer.new(self.width, self.height, self.pitch) + self.bb = Blitbuffer.new(self.width, self.height, self.width/2) -- update mode for input module Input.rotation = mode end @@ -170,11 +167,11 @@ function Screen:saveCurrentBB() local width, height = self:getWidth(), self:getHeight() if not self.saved_bb then - self.saved_bb = Blitbuffer.new(width, height, self:getPitch()) + self.saved_bb = Blitbuffer.new(width, height, self.width/2) end if self.saved_bb:getWidth() ~= width then self.saved_bb:free() - self.saved_bb = Blitbuffer.new(width, height, self:getPitch()) + self.saved_bb = Blitbuffer.new(width, height, self.width/2) end self.saved_bb:blitFullFrom(self.bb) end