Highlights: invert dialog colors in night mode#14923
Merged
Merged
Conversation
Frenzie
reviewed
Feb 4, 2026
| if Screen.night_mode then | ||
| local r, g, b = Blitbuffer.HIGHLIGHT_COLORS[color_name]:match("#(..)(..)(..)") | ||
| return Blitbuffer.colorFromString(string.format("#%02x%02x%02x", | ||
| 255 - tonumber(r, 16), 255 - tonumber(g, 16), 255 - tonumber(b, 16))) |
Member
There was a problem hiding this comment.
I think bit.bxor(tonumber(r, 16), 0xFF) should do the same thing fwiw. (It doesn't matter here with just a few colors, but presumably it would when processing a picture pixel by pixel.)
Member
Author
There was a problem hiding this comment.
As far as AI advises, bit.bxor(x, 0xFF) is not faster than 255 - x.
Member
There was a problem hiding this comment.
Better to use AI to write a test in less than a minute than to ask it things it can't know. ;-)
local bit = require("bit")
local bxor = bit.bxor -- local cache
local function test(n)
local clock = os.clock
-- prebuild test data as hex strings, numbers
local hex = {}
local nums = {}
for x = 0, 255 do
hex[x] = ("%02X"):format(x)
nums[x] = x
end
-- warm-up
for i = 1, 10000 do
local x = nums[i % 256]
local _ = bxor(x, 0xFF)
local _ = 255 - x
end
print("=== Original: bxor(tonumber(x, 16), 0xFF) ===")
local start = clock()
for i = 1, n do
local h = hex[i % 256]
local x = tonumber(h, 16)
local y = bxor(x, 0xFF)
end
print(("time: %.6f s"):format(clock() - start))
print("=== Cached bxor(x, 0xFF) ===")
start = clock()
for i = 1, n do
local x = nums[i % 256]
local y = bxor(x, 0xFF)
end
print(("time: %.6f s"):format(clock() - start))
print("=== 255 - x (arithmetic) ===")
start = clock()
for i = 1, n do
local x = nums[i % 256]
local y = 255 - x
end
print(("time: %.6f s"):format(clock() - start))
print()
end
-- run with e.g. luajit test.lua 100000000
local n = tonumber(arg[1]) or 1e8
test(n)=== Original: bxor(tonumber(x, 16), 0xFF) ===
time: 2.501012 s
=== Cached bxor(x, 0xFF) ===
time: 0.042331 s
=== 255 - x (arithmetic) ===
time: 0.044898 s
=== Original: bxor(tonumber(x, 16), 0xFF) ===
time: 2.486529 s
=== Cached bxor(x, 0xFF) ===
time: 0.042634 s
=== 255 - x (arithmetic) ===
time: 0.040219 s
tl;dr There's no difference, at least on this AMD Ryzen 7 7800X3D. So I'm still wrong. :-) (I'll have to double check if it's the same on some actual ereaders though.)
0xstillb
pushed a commit
to 0xstillb/koreader-thai
that referenced
this pull request
May 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change is