Peach: Local-first video metadata scraper and media manager.
fix(cover): 折痕是一条带时切到带的另一侧,正封左缘不再留一道灰线
longmeidao65a45dab3641
diff --git a/src/peach/jav_poster_crop.py b/src/peach/jav_poster_crop.pyindex 70352dba8..a625f24fc 100644--- a/src/peach/jav_poster_crop.py+++ b/src/peach/jav_poster_crop.py@@ -112,7 +112,7 @@ MANUAL = "manual"MANUAL_SOURCE = "user:crop"#: 算法版本号。sidecar 记着它,落后的重算。改动判据、常数或框的形状都要进位。-ALGORITHM_VERSION = "poster-crop-v5"+ALGORITHM_VERSION = "poster-crop-v6"#: sidecar 与封面同名换后缀:`ABW-232.jpg` → `ABW-232.poster.json`。人脸取景是#: `.face.json`,两者同目录、同命名风格,各描述一件事:一个是脸在哪,一个是正封在哪。SIDECAR_SUFFIX = ".poster.json"@@ -245,11 +245,11 @@ def fold_column(width: int, height: int,top = max(window, key=profile.__getitem__)if profile[top] < peak * FOLD_MIN_STRENGTH:return None- edges = _rival_edges(profile, window, profile[top],- round(width * FOLD_EDGE_SPAN))+ span = round(width * FOLD_EDGE_SPAN)+ edges = _rival_edges(profile, window, profile[top], span)found = min(edges, key=lambda column: abs((width - column) / height - PANEL_ASPECT))baseline = statistics.median(profile[low:high + 1])- return _settled(profile, found, baseline, round(width * FOLD_SETTLE_LIMIT))+ return _settled(profile, found, baseline, round(width * FOLD_SETTLE_LIMIT), span)def center_panel(width: int, height: int, seams: Sequence[float] | None) -> dict | None:@@ -292,10 +292,22 @@ def _rival_edges(profile: list[float], window: range, top: float,return kept-def _settled(profile: list[float], found: int, baseline: float, limit: int) -> int:- """从斜坡最陡的那一列往右走到梯度落回基线,书脊的最后几列留在框外。"""+def _settled(profile: list[float], found: int, baseline: float, limit: int,+ band: int = 0) -> int:+ """从斜坡最陡的那一列往右走到梯度落回基线,书脊的最后几列留在框外。++ 折痕常常是一条带:书脊边、几列灰色的折线阴影、再一道边才到正封。两道边之间梯度+ 会短暂落回基线,停在那里就把阴影带进了框,卡片左缘留一道细线(ABF-328:1139 与+ 1148 两道边,中间 7 列灰)。所以先找 `band` 列内最后一道和折痕相当的边,从它再往右+ 走。阴影带只有几列宽;放到整个走程,正封里紧挨折痕的标题字与人物边缘也会被当成+ 带的另一侧(DVDMS-996 会切进画面 20 列)。另一侧那道边自己也得过峭壁那一关+ (`FOLD_MIN_STRENGTH`):折痕本身偏弱的封套,正封里一片花哨的画面处处都和它相当。+ """stop = min(found + limit, len(profile) - 1)- for column in range(found + 1, stop + 1):+ closing = max(profile[found] * FOLD_RIVAL_RATIO, max(profile) * FOLD_MIN_STRENGTH)+ edge = max((column for column in range(found + 1, min(found + band, stop) + 1)+ if profile[column] >= closing), default=found)+ for column in range(edge + 1, stop + 1):if profile[column] <= baseline:return columnreturn stopdiff --git a/tests/test_jav_poster_crop.py b/tests/test_jav_poster_crop.pyindex ffd22a2e3..4b78cc6ea 100644--- a/tests/test_jav_poster_crop.py+++ b/tests/test_jav_poster_crop.py@@ -121,7 +121,9 @@ class MethodTests(unittest.TestCase):self.assertIsNotNone(profile)found = jav_poster_crop.fold_column(width, height, profile)self.assertIsNotNone(found, "画上去的折痕没被找到")- self.assertLessEqual(abs(found - fold), 2, found)+ # 那条三列宽的黑线整条留在框外,正封从它右边开始。+ self.assertGreaterEqual(found, fold + 3, found)+ self.assertLessEqual(found - (fold + 3), 2, found)box = jav_poster_crop.front_panel_box(width, height, profile)self.assertEqual(box["method"], FOLD)self.assertEqual((box["x0"], box["x1"], box["y0"], box["y1"]),@@ -232,6 +234,34 @@ class MethodTests(unittest.TestCase):profile[column] = 0.5 # 斜坡右边一直不落回基线self.assertEqual(jav_poster_crop.fold_column(800, 539, profile), 426)+ @staticmethod+ def banded_fold(closing_edge: int) -> list[float]:+ """ABF-328 的折痕照着量出来的梯度:书脊边、七列灰色阴影、另一道边才到正封。"""+ profile = [0.3] * 2184+ profile[1139], profile[1140] = 0.73, 0.56+ for column in range(1141, 1147):+ profile[column] = 0.2+ profile[closing_edge - 1], profile[closing_edge] = 0.56, 0.59+ profile[closing_edge + 1] = 0.06+ return profile++ def test_a_shadow_band_beside_the_fold_stays_outside_the_front(self):+ """两道边之间梯度短暂落回基线;停在那儿,卡片左缘就留下一道灰线。"""+ self.assertEqual(jav_poster_crop.fold_column(2184, 1477, self.banded_fold(1148)), 1149)++ def test_an_edge_well_inside_the_front_is_content_not_the_band(self):+ """离折痕超过一道边的宽度,那是正封里的标题字或人物边缘,不是阴影带的另一侧。"""+ self.assertEqual(jav_poster_crop.fold_column(2184, 1477, self.banded_fold(1160)), 1141)++ def test_a_busy_front_beside_a_weak_fold_is_not_mistaken_for_the_band(self):+ """折痕本身偏弱时,正封里一片花哨的画面处处都和它相当,那些边都不够峭壁。"""+ profile = [0.1] * 2184+ profile[100] = 1.0 # 窗外画面里最强的那道边+ profile[1139] = 0.4+ for column in range(1141, 1150):+ profile[column] = 0.3 if column % 2 else 0.32+ self.assertEqual(jav_poster_crop.fold_column(2184, 1477, profile), 1140)+def test_a_thick_spine_puts_both_of_its_edges_in_the_window(self):"""书脊厚到两条边都落进窗里时按形状挑:左边那条更强,右边那条才是折痕。"""profile = [0.0] * 3762