koreader-base icon indicating copy to clipboard operation
koreader-base copied to clipboard

Handle HW nightmode with inkview

Open rjd22 opened this issue 3 years ago • 21 comments

This implementation enables night mode with inkview. Opening pictures in night mode will result in inverted pictures. But reading works fine.

IMG_20220212_192513 IMG_20220212_192523 IMG_20220212_192546


This change is Reviewable

rjd22 avatar Feb 12 '22 18:02 rjd22

The images shouldn't be inverted (or rather they should be pre-inverted and thereby set right). Did you test this by simply forcing framebuffer.night_mode to true without the associated frontend handling? Because otherwise something's broken.

Frenzie avatar Feb 12 '22 19:02 Frenzie

@Frenzie I tested it by enabling night mode in the front-end and opening the image. So it might be that full page images are not pre-inverted. It seems that the images in the list are shown properly.

rjd22 avatar Feb 12 '22 20:02 rjd22

So you're not talking about a unique issue on Pocketbook but simply correct behavior that is 100% identical to the emulator with regard to which pictures are and aren't inverted?

Frenzie avatar Feb 12 '22 21:02 Frenzie

If this is a simple sw inversion of the IV buffer, and doesn't actually toggle the EPDC_FLAG_ENABLE_INVERSION in the (next?) refresh ioctl, then it's very much not worth it, our own software inversion is probably more efficient and/or better integrated ;).

Check with strace whether this actually affects the refresh ioctls?

NiLuJe avatar Feb 12 '22 21:02 NiLuJe

@Frenzie at this moment it might be a pocketbook only issue. I will need to test why the image is not inverted when selecting a image. It might be caused by inkview itself. I will check this later.

@NiLuJe you might be right. I will check this later on.

rjd22 avatar Feb 12 '22 21:02 rjd22

The name sure makes it sound like our own https://github.com/koreader/koreader-base/blob/64bdeda85efe127357c9b969a8cc72b46521ad87/ffi/blitbuffer.lua#L1379-L1387 ;).

NiLuJe avatar Feb 12 '22 22:02 NiLuJe

@NiLuJe I've tried finding out how to install and run strace on my device. But am not sure where to install it ^^". Till now I only worked with the lua part of koreader and didn't work with the C part yet.

I've also contacted PocketBook for this since they have a better insight in the inner workings of inkview and might be able to answer this question while also pointing me to a better way to handle HW night mode (if that is even possible).

rjd22 avatar Feb 13 '22 13:02 rjd22

@Frenzie I don't have access to an emulator yet since I've been testing the changes only on my PocketBook till now (since I'm only doing PocketBook specific changes and fixes). But I've tested opening a .jpg picture on the PocketBook with software night mode on.

Navigating the pictures in the list work fine. They are inverted and then inverted back. But then opening the picture, it doesn't seem to be pre-inverted causing it to look inverted on the screen in night mode.

It might be that this is a PocketBook only issue but atm. I have no way to confirm that. The version of KoReader I'm using is 2021.12.1.

rjd22 avatar Feb 13 '22 14:02 rjd22

@rjd22 If they're fine in CoverBrowser you're probably seeing nothing unexpected. However, like @NiLuJe said if it's just doing the same thing as our own software inversion function there's no point to it. :-)

Frenzie avatar Feb 13 '22 14:02 Frenzie

You'll need shell access ;). It's just a simple binary in a tarball, which you can use to trace KOReader with a call that might look like strace -fittTvy -e trace=ioctl -p $(pidof reader.lua).

That said, given that some/most PBs run on a sunxi SoC with no actual HW inversion support, I wouldn't necessarily spend more time on this, and just go w/ flipping canHWInvert ;).

NiLuJe avatar Feb 13 '22 17:02 NiLuJe

@NiLuJe okay, let's do that. I'm reopening the other PR and leaving this one open for PocketBook to take a look at (I linked this PR in the message I send them and they seem to be watching us 😉). After that I will start making some cleanup PR's to clean up some broken/dead code.

rjd22 avatar Feb 13 '22 19:02 rjd22

I got the following response from the Pocketbook developers today:

As far as we understand, you have already implemented the inversion on application level, unfortunately, we do not support inversion on hardware level. We also noticed, that in KoReader the pictures which are images in jpg, png and so on, are displayed inverted in night mode, but at the same time books illustrations are displayed correctly in night mode during reading, but that is a bug in KoReader, the same bug is in KoReader for black and white devices.

@Frenzie do you know if not inverting images is a bug or supposed to happen?

rjd22 avatar Mar 09 '22 16:03 rjd22

@rjd22 Definitely not a bug.

Frenzie avatar Mar 09 '22 17:03 Frenzie

@rjd22 At least it's definitely not a bug if it meets these conditions: https://github.com/koreader/koreader-base/pull/1453#issuecomment-1037490623

Frenzie avatar Mar 09 '22 17:03 Frenzie

Night mode is supposed to look like this. Pictures pre-inverted so that they are inverted back into being not being inverted in the end result. Screenshot_2022-03-09_18-19-06

Frenzie avatar Mar 09 '22 17:03 Frenzie

@Frenzie could you check in your emulator what happens if you open a .jpg file in night mode? Does that look correct in the emulator?

rjd22 avatar Mar 09 '22 17:03 rjd22

No, those are inverted.

Frenzie avatar Mar 09 '22 17:03 Frenzie

Most likely that is the behavior the developers of pocketbook are talking about. But in that case it might not be a pocketbook specific issue but something that also happens to other devices.

rjd22 avatar Mar 09 '22 17:03 rjd22

PicDocument possibly doesn't do the double invert trick, yeah. Check if opening one of those w/ mupdf instead works to confirm ;).

NiLuJe avatar Mar 09 '22 18:03 NiLuJe

MuPDF doesn't do that either, so not sure what you expect. :-P

Frenzie avatar Mar 09 '22 20:03 Frenzie

Oops, quite right, we only do that in CRe ^^.

NiLuJe avatar Mar 09 '22 22:03 NiLuJe

Closing this. As we discussed some time ago it's better to let KoReader handle the night mode than moving it to Inkview.

rjd22 avatar Dec 03 '22 15:12 rjd22