From c20a7dea4a592ffc71e5e4dfc74593cb32edf19c Mon Sep 17 00:00:00 2001 From: Linghong Date: Mon, 17 Aug 2026 08:21:09 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8C=E7=BE=8E=E5=83=8F?= =?UTF-8?q?=E7=B4=A0=E5=AF=B9=E5=B0=8F=E4=BA=8E=204=20=E5=83=8F=E7=B4=A0?= =?UTF-8?q?=E8=BD=AF=E7=BD=91=E6=A0=BC=E8=AF=86=E5=88=AB=E5=81=8F=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 峰间距过滤器 4 会把 2–3 像素网格的相邻峰成对合并成 5–6,再取 P30 就把 683×1024 生成素材统一报成 5–6 像素格;改为 2 后不再合并峰。同时 walker 窗口起点向上取整且不早于上一条切线 +2,避免小步长时切出 1 像素格。 Co-Authored-By: Claude Fable 5 --- .../crates/platform-image/src/pixel_art_snapper.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server-rs/crates/platform-image/src/pixel_art_snapper.rs b/server-rs/crates/platform-image/src/pixel_art_snapper.rs index 846753f09..589a26a6f 100644 --- a/server-rs/crates/platform-image/src/pixel_art_snapper.rs +++ b/server-rs/crates/platform-image/src/pixel_art_snapper.rs @@ -28,7 +28,10 @@ const MAX_DECODE_ALLOC_BYTES: u64 = PIXEL_ART_MAX_IMAGE_PIXELS * 16; const KMEANS_SEED: u64 = 42; const MAX_KMEANS_ITERATIONS: usize = 15; const PEAK_THRESHOLD_MULTIPLIER: f64 = 0.2; -const PEAK_DISTANCE_FILTER: usize = 4; +// Two peaks can never be adjacent (the left `>=` / right `>` test forbids it), so `2` +// keeps every peak. The previous `4` merged the 2–3 px gaps of soft sub-4 px grids +// into 5–6 px ones and made every such grid come out about twice too coarse. +const PEAK_DISTANCE_FILTER: usize = 2; const STEP_SIZE_PERCENTILE: f64 = 0.3; const WALKER_SEARCH_WINDOW_RATIO: f64 = 0.35; const WALKER_MIN_SEARCH_WINDOW: f64 = 2.0; @@ -828,8 +831,12 @@ fn walk( break; } + // The window start is rounded up and never closer than 2 px to the previous cut: + // with steps of 2–3 px the fixed minimum window would otherwise reach back to + // `current + 1` and split 1 px cells off the real edge. let start = (target - search_window) - .max(current_position + 1.0) + .ceil() + .max(current_position + 2.0) .max(0.0) as usize; let end = ((target + search_window) as usize).min(limit); if end <= start {