Skip to content

feat(koptcontext): Add getAllPanelsFromPage() for panel detection#2257

Open
vmanojkumar wants to merge 2 commits intokoreader:masterfrom
vmanojkumar:feature/panel-navigation
Open

feat(koptcontext): Add getAllPanelsFromPage() for panel detection#2257
vmanojkumar wants to merge 2 commits intokoreader:masterfrom
vmanojkumar:feature/panel-navigation

Conversation

@vmanojkumar
Copy link

@vmanojkumar vmanojkumar commented Jan 21, 2026

Add a new method to detect all panels on a page using Leptonica's connected component analysis. This enables panel-by-panel navigation for comics and manga in KOReader.

Returns an array of panel bounding boxes {x, y, w, h} for panels that are at least 1/8 of page dimensions (filtering out small elements).


This change is Reviewable

Comment on lines +496 to +510
for box in boxaIterBoxes(bb) do
local pix_tmp = _gc_ptr(leptonica.pixClipRectangle(pixs, box, nil), pixDestroy)
local w = leptonica.pixGetWidth(pix_tmp)
local h = leptonica.pixGetHeight(pix_tmp)
-- check if it's panel or part of the panel, if it's part of the panel skip
if w >= img_w / 8 and h >= img_h / 8 then
local box_x, box_y, box_w, box_h = boxGetGeometry(box)
table.insert(panels, {
x = box_x,
y = box_y,
w = box_w,
h = box_h,
})
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be simplified to something like this (untested both functionally and performance-wise, regard as pseudocode)?

Suggested change
for box in boxaIterBoxes(bb) do
local pix_tmp = _gc_ptr(leptonica.pixClipRectangle(pixs, box, nil), pixDestroy)
local w = leptonica.pixGetWidth(pix_tmp)
local h = leptonica.pixGetHeight(pix_tmp)
-- check if it's panel or part of the panel, if it's part of the panel skip
if w >= img_w / 8 and h >= img_h / 8 then
local box_x, box_y, box_w, box_h = boxGetGeometry(box)
table.insert(panels, {
x = box_x,
y = box_y,
w = box_w,
h = box_h,
})
end
end
for box_x, box_y, box_w, box_h in boxaIterBoxGeometries(bb) do
if box_w >= img_w / 8 and box_h >= img_h / 8 then
panels[#panels + 1] = { x = box_x, y = box_y, w = box_w, h = box_h }
end
end

@vmanojkumar vmanojkumar force-pushed the feature/panel-navigation branch from b4071ef to ceb81d8 Compare January 31, 2026 08:37
h = box_h,
}
break -- we found panel, exit the loop and clean up memory
res = { x = box_x, y = box_y, w = box_w, h = box_h }
Copy link
Member

@Frenzie Frenzie Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep that spread out so it doesn't show as changed in the diff. I just randomly wrote it on one line without thinking about anything like that. :-)

Add a new method to detect all panels on a page using Leptonica's
connected component analysis. This enables panel-by-panel navigation
for comics and manga in KOReader.

Returns an array of panel bounding boxes {x, y, w, h} for panels
that are at least 1/8 of page dimensions (filtering out small elements).
@vmanojkumar vmanojkumar force-pushed the feature/panel-navigation branch from ceb81d8 to 4238faf Compare January 31, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants