Skip to content

fix(video): 首帧放大改用 NEAREST,不把 sprite 硬边糊掉 - #543

Open
johnnyzhang-eng wants to merge 1 commit into
1024XEngineer:mainfrom
johnnyzhang-eng:fix/first-frame-nearest-upscale
Open

fix(video): 首帧放大改用 NEAREST,不把 sprite 硬边糊掉#543
johnnyzhang-eng wants to merge 1 commit into
1024XEngineer:mainfrom
johnnyzhang-eng:fix/first-frame-nearest-upscale

Conversation

@johnnyzhang-eng

Copy link
Copy Markdown
Contributor

Closes #542

问题

_fit_first_frame 放大用 LANCZOS。放大是把一个源像素铺成一块,插值会在块边界造出源图里没有的中间色,把 sprite 的硬边糊成渐变 —— 而这张糊图正是喂给 i2v 的输入。

倍率越大越严重。同一函数、同一张双色硬边图,测成品里那条边的过渡带宽度:

源尺寸 放大倍率 NEAREST LANCZOS BICUBIC
64×64 11.2× 4px 20px 10px
128×128 5.6× 4px 10px 6px
256×256 2.8× 4px 5px 4px

小 sprite 受损最重,而 64×64 / 128×128 正是 #509 点名的场景。

交付侧的 _fit_to 早就是这条规则,其 docstring 原文:「序列帧是像素画,必须 NEAREST(插值会把硬边糊成灰边)」。首帧这一侧与它不一致。

方案

放大用 NEAREST,缩小仍用 LANCZOS(缩小反过来,NEAREST 会丢样出锯齿)。

不包含

  • 不改 JPEG 质量。JPEG q90 才是色数爆炸的主因:12 张真实生产母版走完整函数配对实测,源 7704 色 → 出来 23076 色,而 NEAREST 与 LANCZOS 分别是 23076 / 23370,1.0 倍、分不开。想减这部分损失是另一件事,要先确认供应商吃不吃更高质量或无损格式(PNG base64 曾实测 VENDOR_FAILED)
  • 不改出口的像素化开关。母版是像素画但交付帧不是,主因在那里而不在本 PR,另开 issue

验收

新增用例用 64×64 源(11.2× 放大),断言硬边过渡带 ≤8px。把滤波换回 LANCZOS 时该用例失败:

FAILED tests/test_sufy_video_download.py::test_upscaling_a_small_sprite_keeps_hard_edges_instead_of_interpolating_them

用例特意不拿色数当判据 —— 那个量在 JPEG 之后两种滤波分不开,拿它会得出「没区别」的错结论。

ruff check .lint-imports(2 kept, 0 broken)、pytest -q(1318 passed, 14 skipped)。

放大是把源像素铺成块,插值会造出源图没有的中间色;缩小仍用 LANCZOS。
与交付侧 _fit_to 的同一条规则对齐。

Closes 1024XEngineer#542
@vercel

vercel Bot commented Aug 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
windup Ignored Ignored Preview Aug 21, 2026 10:13am

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the complete fixed diff for the first-frame resize contract. The change applies NEAREST only when the fitted image is enlarged and preserves LANCZOS for reductions, matching the linked #542 requirement; the new regression test exercises the small-sprite hard-edge case. No actionable correctness, compatibility, or security findings remain.

Verification: git diff --check and Python compilation passed for both changed files. The focused pytest suite was not runnable in this workspace because uv, pytest, and Pillow are unavailable.

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

[Bug]: 首帧放大用插值,把 sprite 硬边糊成渐变后才喂给 i2v

2 participants