2
0
mirror of https://github.com/koreader/koreader synced 2024-11-11 19:11:14 +00:00

Merge pull request #750 from houqp/new_ui_code

bug fix for einkfb.c and screen.lua
This commit is contained in:
Huang Xin 2013-02-18 00:10:04 -08:00
commit 0835e9f34d
2 changed files with 26 additions and 23 deletions

View File

@ -41,8 +41,8 @@ inline void fbInvert4BppTo8Bpp(FBInfo *fb) {
fb_pitch = fb->real_buf->pitch; fb_pitch = fb->real_buf->pitch;
/* copy bitmap from 4bpp shadow blitbuffer to framebuffer */ /* copy bitmap from 4bpp shadow blitbuffer to framebuffer */
for (i = (h-1); i > 0; i--) { for (i = (h-1); i >= 0; i--) {
for (j = (w-1)/2; j > 0; j--) { 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] = shadow_buf[i*pitch + j];
fb_buf[i*fb_pitch + j*2] &= 0xF0; fb_buf[i*fb_pitch + j*2] &= 0xF0;
fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F; 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; shadow_buf = fb->buf->data;
fb_buf = fb->real_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; h = fb->buf->h;
/* w is 758 for PaperWhite */ /* w is 758 for PaperWhite's shadow buffer */
w = fb->buf->w; w = fb->buf->w;
/* pitch is 384 for shadow buffer */ /* pitch is 376 for shadow buffer */
pitch = fb->buf->pitch; pitch = fb->buf->pitch;
/* pitch is 768 for PaperWhite */ /* pitch is 768 for PaperWhite's framebuffer */
fb_pitch = fb->real_buf->pitch; fb_pitch = fb->real_buf->pitch;
/* copy bitmap from 4bpp shadow blitbuffer to framebuffer */ /* copy bitmap from 4bpp shadow blitbuffer to framebuffer */
for (i = (h-1); i > 0; i--) { for (i = (h-1); i >= 0; i--) {
for (j = (w-1)/2; j > 0; j--) { 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] = shadow_buf[i*pitch + j];
fb_buf[i*fb_pitch + j*2] &= 0xF0; fb_buf[i*fb_pitch + j*2] &= 0xF0;
fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F; 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) { if (fb->vinfo.bits_per_pixel == 8) {
/* for 8bpp K4, PaperWhite, we create a shadow 4bpp blitbuffer. These /* for 8bpp K4, PaperWhite, we create a shadow 4bpp blitbuffer.
* models use 16 scale 8bpp framebuffer, so we still cheat it as 4bpp * 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)); fb->buf->data = (uint8_t *)calloc(fb->buf->pitch * fb->vinfo.yres, sizeof(uint8_t));
if (!fb->buf->data) { if (!fb->buf->data) {

View File

@ -42,7 +42,6 @@ Codes for rotation modes:
Screen = { Screen = {
width = 0, width = 0,
height = 0, height = 0,
pitch = 0,
native_rotation_mode = nil, native_rotation_mode = nil,
cur_rotation_mode = 0, cur_rotation_mode = 0,
@ -53,12 +52,11 @@ Screen = {
} }
function Screen:init() function Screen:init()
_, self.height = self.fb:getSize() -- for unknown strange reason, pitch*2 is 10 px more than screen width in KPW
-- for unknown strange reason, pitch*2 is less than screen width in KPW self.width, self.height = self.fb:getSize()
-- so we need to calculate width by pitch here -- Blitbuffer still uses inverted 4bpp bitmap, so pitch should be
self.pitch = self.fb:getPitch() -- (self.width / 2)
self.width = self.pitch * 2 self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
self.bb = Blitbuffer.new(self.width, self.height, self.pitch)
if self.width > self.height then if self.width > self.height then
-- For another unknown strange reason, self.fb:getOrientation always -- For another unknown strange reason, self.fb:getOrientation always
-- return 0 in KPW, even though we are in landscape mode. -- return 0 in KPW, even though we are in landscape mode.
@ -102,7 +100,7 @@ function Screen:getDPI()
end end
function Screen:getPitch() function Screen:getPitch()
return self.ptich return self.fb:getPitch()
end end
function Screen:getNativeRotationMode() function Screen:getNativeRotationMode()
@ -133,8 +131,7 @@ function Screen:setRotationMode(mode)
end end
self.cur_rotation_mode = mode self.cur_rotation_mode = mode
self.bb:free() self.bb:free()
self.pitch = self.width/2 self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
self.bb = Blitbuffer.new(self.width, self.height, self.pitch)
-- update mode for input module -- update mode for input module
Input.rotation = mode Input.rotation = mode
end end
@ -170,11 +167,11 @@ function Screen:saveCurrentBB()
local width, height = self:getWidth(), self:getHeight() local width, height = self:getWidth(), self:getHeight()
if not self.saved_bb then 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 end
if self.saved_bb:getWidth() ~= width then if self.saved_bb:getWidth() ~= width then
self.saved_bb:free() self.saved_bb:free()
self.saved_bb = Blitbuffer.new(width, height, self:getPitch()) self.saved_bb = Blitbuffer.new(width, height, self.width/2)
end end
self.saved_bb:blitFullFrom(self.bb) self.saved_bb:blitFullFrom(self.bb)
end end