Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > KOReader

Notices

Reply
 
Thread Tools Search this Thread
Old 08-31-2020, 02:58 PM   #31
pazos
cosiñeiro
pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.
 
Posts: 634
Karma: 758480
Join Date: Apr 2014
Device: BQ Cervantes 4
Quote:
Originally Posted by Winkelschraube View Post
Wow pazos, that would be awesome. I thank you already. With my Poke 2 the folder "/Pictures" and the file is best "bookcover.png". So together "/Pictures/bookcover.png".

I will certainly take a look at it and learn something from it to understand how it works and to be able to make future adjustments myself.
Minimum changes are:

Code:
--- a/frontend/apps/reader/readerui.lua
+++ b/frontend/apps/reader/readerui.lua
@@ -555,6 +555,11 @@ function ReaderUI:doShowReader(file, provider)
         })
         self:showFileManager()
         return
+    else
+        local image = document:getCoverPageImage()
+        if image then
+            Device.screen.bb:writePNG("/home/pazos/Escritorio/test2.png", false, image)
+        end
     end
     if document.is_locked then
         logger.info("document is locked")
and

Code:
--- a/ffi/blitbuffer.lua
+++ b/ffi/blitbuffer.lua
@@ -1760,7 +1760,7 @@ write blitbuffer contents to a PNG file
 @param filename the name of the file to be created
 --]]
 local Png  -- lazy load ffi/png
-function BB_mt.__index:writePNG(filename, bgr)
+function BB_mt.__index:writePNG(filename, bgr, buffer)
     if not Png then Png = require("ffi/png") end
     local hook, mask, _ = debug.gethook()
     debug.sethook()
@@ -1770,7 +1770,8 @@ function BB_mt.__index:writePNG(filename, bgr)
     for y = 0, h-1 do
         local offset = 4 * w * y
         for x = 0, w-1 do
-            local c = self:getPixel(x, y):getColorRGB32()
+            local c = buffer and buffer:getPixel(x, y):getColorRGB32() or
+                self:getPixel(x, y):getColorRGB32()
             -- NOTE: Kobo's FB is BGR(A), we already trick MuPDF into doing it that way for us, so, keep faking it here!
             if bgr then
                 mem[offset] = c.b
give it a try on the emulator with some books (replace "/home/pazos/Escritorio/test2.png" with the path you want). If you're fine with the changes you can move them to android.


Probably the 2nd block of code can be upstreamed, because it doesn't affect current code in any way and is just a quick way of writting a png file from a memory buffer without having to write to the framebuffer first.
pazos is offline   Reply With Quote
Old 08-31-2020, 08:23 PM   #32
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 10,874
Karma: 18632486
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW & PW2; Kobo H2O & Forma
@pazos: The second hunk does make sense, but it's missing getting the width/height from buffer, too, because right now it uses the image buffer but with the framebuffer's dimensions .

(Which I realize may be the point, but then what happens if image buffer's dimension != framebuffer's dimension?)
NiLuJe is offline   Reply With Quote
Advert
Old 09-01-2020, 01:25 AM   #33
Winkelschraube
Connoisseur
Winkelschraube began at the beginning.
 
Winkelschraube's Avatar
 
Posts: 66
Karma: 10
Join Date: Jul 2020
Device: The amazing Onyx Poke2
Thank you very much. I see this eventing.
Winkelschraube is offline   Reply With Quote
Old 09-01-2020, 08:19 AM   #34
pazos
cosiñeiro
pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.
 
Posts: 634
Karma: 758480
Join Date: Apr 2014
Device: BQ Cervantes 4
Quote:
Originally Posted by NiLuJe View Post
@pazos: The second hunk does make sense, but it's missing getting the width/height from buffer, too, because right now it uses the image buffer but with the framebuffer's dimensions .

(Which I realize may be the point, but then what happens if image buffer's dimension != framebuffer's dimension?)
It seems that I was lucky on my tests. A "cover" that doesn't match framebuffer dimension is attached.

And the proper code, as suggested, would be:

Code:
--- a/ffi/blitbuffer.lua
+++ b/ffi/blitbuffer.lua
@@ -1760,17 +1760,19 @@ write blitbuffer contents to a PNG file
 @param filename the name of the file to be created
 --]]
 local Png  -- lazy load ffi/png
-function BB_mt.__index:writePNG(filename, bgr)
+function BB_mt.__index:writePNG(filename, bgr, buffer)
     if not Png then Png = require("ffi/png") end
     local hook, mask, _ = debug.gethook()
     debug.sethook()
-    local w, h = self:getWidth(), self:getHeight()
+    local w = buffer and buffer:getWidth() or self:getWidth()
+    local h = buffer and buffer:getHeight() or self:getHeight()
     local cdata = C.malloc(w * h * 4)
     local mem = ffi.cast("char*", cdata)
     for y = 0, h-1 do
         local offset = 4 * w * y
         for x = 0, w-1 do
-            local c = self:getPixel(x, y):getColorRGB32()
+            local c = buffer and buffer:getPixel(x, y):getColorRGB32() or
+                self:getPixel(x, y):getColorRGB32()
             -- NOTE: Kobo's FB is BGR(A), we already trick MuPDF into doing it that way for us, so, keep faking it here!
             if bgr then
                 mem[offset] = c.b
Attached Thumbnails
Click image for larger version

Name:	test2.png
Views:	38
Size:	178.9 KB
ID:	181684  
pazos is offline   Reply With Quote
Old 09-01-2020, 01:11 PM   #35
Winkelschraube
Connoisseur
Winkelschraube began at the beginning.
 
Winkelschraube's Avatar
 
Posts: 66
Karma: 10
Join Date: Jul 2020
Device: The amazing Onyx Poke2
Exclamation

Ok it works!!11! WOOHOO.

(Don't you really want to add this as an option? Calibre Companion should be able to do that as well. And KOReader is very much better )

But I have to build "./kodev release --debug android". I don't have a Google account to sign by myself. The file is very big and loading is very slow.

I still have one problem, the image on the Poke 2 screensaver is scaled to screen size. If the width of the cover image is very small, it will be cut off at the top and bottom because it will be scaled until it is full screen.

Is there an option to adjust the background of the image to the screen ratio?
Winkelschraube is offline   Reply With Quote
Advert
Old 09-01-2020, 01:26 PM   #36
Winkelschraube
Connoisseur
Winkelschraube began at the beginning.
 
Winkelschraube's Avatar
 
Posts: 66
Karma: 10
Join Date: Jul 2020
Device: The amazing Onyx Poke2
Pictures of the scaling problem attached.
Attached Thumbnails
Click image for larger version

Name:	picture.jpg
Views:	27
Size:	224.9 KB
ID:	181702   Click image for larger version

Name:	screensaver.jpg
Views:	29
Size:	386.5 KB
ID:	181703  
Winkelschraube is offline   Reply With Quote
Old 09-01-2020, 01:42 PM   #37
pazos
cosiñeiro
pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.
 
Posts: 634
Karma: 758480
Join Date: Apr 2014
Device: BQ Cervantes 4
Quote:
Originally Posted by Winkelschraube View Post

(Don't you really want to add this as an option? Calibre Companion should be able to do that as well. And KOReader is very much better )
Nope. This is a hack. PR are welcome but will take a bit more code than that. Also it is pretty easy to migrate stuff once after an update: see https://github.com/koreader/koreader...362eeee0fd87bf


Quote:
Originally Posted by Winkelschraube View Post
But I have to build "./kodev release --debug android". I don't have a Google account to sign by myself. The file is very big and loading is very slow.
You just need to sign it, you don't need a google account. There are plenty of online tutorials for that.


Quote:
Originally Posted by Winkelschraube View Post

I still have one problem, the image on the Poke 2 screensaver is scaled to screen size. If the width of the cover image is very small, it will be cut off at the top and bottom because it will be scaled until it is full screen.

Is there an option to adjust the background of the image to the screen ratio?
No with these changes. I'm afraid you'll need to rescale the image before calling writePNG.

Last edited by pazos; 09-01-2020 at 02:37 PM.
pazos is offline   Reply With Quote
Old 09-02-2020, 01:14 AM   #38
Winkelschraube
Connoisseur
Winkelschraube began at the beginning.
 
Winkelschraube's Avatar
 
Posts: 66
Karma: 10
Join Date: Jul 2020
Device: The amazing Onyx Poke2
Smile

Quote:
Originally Posted by pazos View Post
No with these changes. I'm afraid you'll need to rescale the image before calling writePNG.
I don't want to scale, I want to change the background of the image to keep the aspect ratio of the screen.

I was thinking about an imagemagic script that runs in the background and checks every 30 minutes if the image has been rewritten. Because I have no idea about Lua. But of course it is better to do it in KOReader, I will try it in the next weeks.


Thanks a lot for your help so far. This is really great.
Winkelschraube is offline   Reply With Quote
Old 09-04-2020, 09:10 AM   #39
elvvis
Member
elvvis began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Jan 2019
Device: PW4, tolino epos 2
Quote:
Originally Posted by Frenzie View Post
Parts of it would be theoretically quite simple, such as writing whatever you want as the screensaver to a file. But as @pazos said it's not quite clear to me if this isn't too low-level and device specific in a way that would require running the program as root. Please see https://github.com/koreader/koreader/issues/5732

This would be a great solution for a rooted Android e-Ink reader.
You would need an option for the screensaver so that the image can be saved in a certain format (jpg or png) in a user defined directory.
In the local KOReader installation you would only have to activate the screensaver in android/device.lua.
elvvis is offline   Reply With Quote
Old 09-22-2020, 01:25 PM   #40
Winkelschraube
Connoisseur
Winkelschraube began at the beginning.
 
Winkelschraube's Avatar
 
Posts: 66
Karma: 10
Join Date: Jul 2020
Device: The amazing Onyx Poke2
Smile

I removed the hack three weeks ago.
It did not work, whenever I clicked on a book in the file manager, KOReader started loading and eventually stopped. (I checked with "adb logcat".) When I tapped on the top of the screen, it finished loading (re-rendered the font each time). The image was also created. It worked fine when the Poke 2 was loaded with a USB cable. I did not notice any differences with adb.

Now I only changed the picture name in "screenshoter.lua" in line 42 to "screenshot.png" without date. So I just take a screenshot at the beginning of each book and that is the new screensaver.

Code:
self.screenshot_fn_fmt = screenshots_dir .. "screenshot.png"
But thank you all for your help and work. It was an honor for me.
Winkelschraube is offline   Reply With Quote
Old 10-13-2020, 05:59 AM   #41
Winkelschraube
Connoisseur
Winkelschraube began at the beginning.
 
Winkelschraube's Avatar
 
Posts: 66
Karma: 10
Join Date: Jul 2020
Device: The amazing Onyx Poke2
Talking

Quote:
Originally Posted by Winkelschraube View Post

Now I only changed the picture name in "screenshoter.lua" in line 42 to "screenshot.png" without date. So I just take a screenshot at the beginning of each book and that is the new screensaver.

Code:
self.screenshot_fn_fmt = screenshots_dir .. "screenshot.png"
At 2020.10 I have to do the same in https://github.com/koreader/koreader...iewer.lua#L661
Winkelschraube is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Use local file as cover image jma1 Recipes 1 03-09-2020 11:14 AM
AZW3 file loading incorrect cover in kindle grapebasil Library Management 1 03-15-2018 07:41 PM
Where else can a MOBI file have its cover image? Alissa Kindle Formats 6 07-13-2013 02:50 PM
Books loading into document file Mumgod Kindle Fire 14 02-07-2012 05:37 AM
Document converter (to pdf or image file) Bob Russell Lounge 1 09-09-2004 04:01 PM


All times are GMT -4. The time now is 09:35 AM.


MobileRead.com is a privately owned, operated and funded community.