[PR #8448] [MERGED] fix: preserve colored detail in sprite background cleanup #8609

Closed
opened 2026-11-07 16:45:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8448
Author: @SpicyMarinara
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/preserve-cutout-feathers


📝 Commits (3)

  • 4de6893 chore: start foreground-preserving sprite cleanup (#8447)
  • 1245573 fix: preserve sprite foreground details during chroma cleanup (#8447)
  • 8163d89 fix: preserve opaque sprite texture during cleanup

📊 Changes

3 files changed (+211 additions, -4 deletions)

View changed files

📝 packages/server/src/routes/sprites.routes.ts (+3 -0)
📝 packages/server/src/services/image/sprite-background.service.ts (+23 -4)
📝 scripts/regressions/sprite-background.regression.ts (+185 -0)

📄 Description

Linked issue

Closes #8447

Why this change

Builtin sprite cleanup can erase thin blue/gold ribbons and fade opaque nearby shades because it mistakes their color for green spill or a matte blend. This patch fixes those reproduced pixel cases and exposes a cleanup revision so a package can refresh its cached derivatives from the original source.

The paired Otome Hearth screenshots show missing ribbons, but the exact original image and engine used on that installation were not replayed. This PR does not claim the screenshots prove which cleanup path ran.

What changed

  • Preserves non-key blue, gold and teal details by classifying spill against the strongest opposing color channel while retaining the signed average for blend coverage.
  • Requires a closer color fit and actual matte contact before rewriting saturated-matte edge pixels, preserving opaque interior texture. Classified spill and substantial verified matte blends remain local matte contact for subsequent edges, so true green halos and partial-coverage edges still clean up; legacy white and already-transparent paths keep their existing behavior.
  • Adds optional top-level cleanupRevision: 2 to /api/sprites/cleanup/status and /api/sprites/cleanup, preserving existing request/cell fields and engine selection.
  • Adds regression proof for thin ribbons, enclosed color details, opaque edge shades and textured gold interiors 4–16 px from the matte, real/noisy blended edges, magenta/cyan mattes, and the additive route metadata.

Otome cache refresh is coordinated in Marinara-Agents#1849: after revision 2 is advertised it explicitly requests builtin, rebuilds from the raw source, and saves the actual response revision only after the derivative is stored. Engine auto/AI precedence is unchanged.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Agent-run checks on 8163d89b6fefa2beb5427f670d61497cd9f40ed9:

  • pnpm install and pnpm check passed. The existing HomeProfessorMariChat.tsx serverRun hook dependency warning remains.
  • node scripts/run-regressions.mjs --filter scripts/regressions/sprite-background.regression.ts: 1/1 passed (591 ms), including real Fastify status/cleanup injection with existing input shape and corrected output pixels.
  • The new tests failed on the old source before repair; their failure logs remain under .tmp/cutout-*before*.log. Existing green-background, dark-halo, enclosed-key-pocket, partial-alpha, white-background and style-profile controls were retained.
  • Local CodeRabbit review: three initial minor pixel cases were reproduced and fixed (teal detail and two noisy edge variants). Dottore's interior gold finding was reproduced before repair and fixed; a subsequent local review reproduced a wide half-red/green blend case and its focused control was added and fixed. Fresh local CodeRabbit review of the final delta against 12455735 completed with 0 findings across the two repair files.
  • Textured-gold regression: the old host changed 754 of 1,508 strictly checked opaque interior pixels 4–16 px from green matte; the repaired host changes 0. A suggested strict guard alone failed the unchanged soft-edge control; the final guard recognizes classified spill and substantial verified blends as local matte contact, and passes every existing assertion plus the new wide-blend control. Rendered gold proof and exact metrics.
  • Synthetic 96×96 proof: old staging changed 245 of 1,872 foreground pixels; the corrected algorithm changes 0. All 7,344 green background pixels are transparent. Rendered source/before/after PNGs were visually inspected; published raw PNG/metrics bytes were checked against the local files.
  • Every service caller was traced: generated sheets and cells, full-body and portrait expressions, saved-sprite cleanup with backups, and generic base64 cleanup. Their arguments, return buffer contract and error fallbacks remain compatible. The existing Engine client consumes cells and tolerates the optional metadata.
  • Docker CLI validation was unavailable because its daemon socket is not running. No provider/AI segmentation call was used for this local pixel proof.

Human follow-up:

  • Manually verify the affected original asset on its installation after the host and package updates.
  • Manually verify the Otome cache refresh uses the original source and retains the previous visible cutout if refresh fails.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened
  • Version/release files updated (only if this PR includes a version bump)

No release or storage format metadata changed. The cleanup revision is optional response metadata for derived-asset caches, separate from the application version. The existing user-facing cleanup controls and guide contract remain applicable.

UI evidence (if applicable)

Synthetic pixel artifacts and exact metrics.

Source on green

Before builtin cleanup

After builtin cleanup


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8448 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/preserve-cutout-feathers` --- ### 📝 Commits (3) - [`4de6893`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4de689377733abab947b18dab9ea6b117e9c58f0) chore: start foreground-preserving sprite cleanup (#8447) - [`1245573`](https://github.com/Pasta-Devs/Marinara-Engine/commit/12455735fd3e373a613d1fe9ef7e5592b6efd08f) fix: preserve sprite foreground details during chroma cleanup (#8447) - [`8163d89`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8163d89b6fefa2beb5427f670d61497cd9f40ed9) fix: preserve opaque sprite texture during cleanup ### 📊 Changes **3 files changed** (+211 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/sprites.routes.ts` (+3 -0) 📝 `packages/server/src/services/image/sprite-background.service.ts` (+23 -4) 📝 `scripts/regressions/sprite-background.regression.ts` (+185 -0) </details> ### 📄 Description ## Linked issue Closes #8447 ## Why this change Builtin sprite cleanup can erase thin blue/gold ribbons and fade opaque nearby shades because it mistakes their color for green spill or a matte blend. This patch fixes those reproduced pixel cases and exposes a cleanup revision so a package can refresh its cached derivatives from the original source. The paired Otome Hearth screenshots show missing ribbons, but the exact original image and engine used on that installation were not replayed. This PR does not claim the screenshots prove which cleanup path ran. ## What changed - Preserves non-key blue, gold and teal details by classifying spill against the strongest opposing color channel while retaining the signed average for blend coverage. - Requires a closer color fit and actual matte contact before rewriting saturated-matte edge pixels, preserving opaque interior texture. Classified spill and substantial verified matte blends remain local matte contact for subsequent edges, so true green halos and partial-coverage edges still clean up; legacy white and already-transparent paths keep their existing behavior. - Adds optional top-level `cleanupRevision: 2` to `/api/sprites/cleanup/status` and `/api/sprites/cleanup`, preserving existing request/cell fields and engine selection. - Adds regression proof for thin ribbons, enclosed color details, opaque edge shades and textured gold interiors 4–16 px from the matte, real/noisy blended edges, magenta/cyan mattes, and the additive route metadata. Otome cache refresh is coordinated in [Marinara-Agents#1849](https://github.com/Pasta-Devs/Marinara-Agents/pull/1849): after revision 2 is advertised it explicitly requests `builtin`, rebuilds from the raw source, and saves the actual response revision only after the derivative is stored. Engine auto/AI precedence is unchanged. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Agent-run checks on `8163d89b6fefa2beb5427f670d61497cd9f40ed9`: - `pnpm install` and `pnpm check` passed. The existing `HomeProfessorMariChat.tsx` `serverRun` hook dependency warning remains. - `node scripts/run-regressions.mjs --filter scripts/regressions/sprite-background.regression.ts`: 1/1 passed (591 ms), including real Fastify status/cleanup injection with existing input shape and corrected output pixels. - The new tests failed on the old source before repair; their failure logs remain under `.tmp/cutout-*before*.log`. Existing green-background, dark-halo, enclosed-key-pocket, partial-alpha, white-background and style-profile controls were retained. - Local CodeRabbit review: three initial minor pixel cases were reproduced and fixed (teal detail and two noisy edge variants). Dottore's interior gold finding was reproduced before repair and fixed; a subsequent local review reproduced a wide half-red/green blend case and its focused control was added and fixed. Fresh local CodeRabbit review of the final delta against `12455735` completed with 0 findings across the two repair files. - Textured-gold regression: the old host changed 754 of 1,508 strictly checked opaque interior pixels 4–16 px from green matte; the repaired host changes 0. A suggested strict guard alone failed the unchanged soft-edge control; the final guard recognizes classified spill and substantial verified blends as local matte contact, and passes every existing assertion plus the new wide-blend control. [Rendered gold proof](https://gist.githubusercontent.com/SpicyMarinara/79f20cf85eca708adce8a976fba25d34/raw/568d91b3859516be40c0e843576b8a1326e9d765/gold-proof-view.png) and [exact metrics](https://gist.githubusercontent.com/SpicyMarinara/79f20cf85eca708adce8a976fba25d34/raw/c24ba4dd335361f3e18d994387b207b77b47367f/gold-metrics.json). - Synthetic 96×96 proof: old staging changed 245 of 1,872 foreground pixels; the corrected algorithm changes 0. All 7,344 green background pixels are transparent. Rendered source/before/after PNGs were visually inspected; published raw PNG/metrics bytes were checked against the local files. - Every service caller was traced: generated sheets and cells, full-body and portrait expressions, saved-sprite cleanup with backups, and generic base64 cleanup. Their arguments, return buffer contract and error fallbacks remain compatible. The existing Engine client consumes `cells` and tolerates the optional metadata. - Docker CLI validation was unavailable because its daemon socket is not running. No provider/AI segmentation call was used for this local pixel proof. Human follow-up: - Manually verify the affected original asset on its installation after the host and package updates. - Manually verify the Otome cache refresh uses the original source and retains the previous visible cutout if refresh fails. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened - [ ] Version/release files updated (only if this PR includes a version bump) No release or storage format metadata changed. The cleanup revision is optional response metadata for derived-asset caches, separate from the application version. The existing user-facing cleanup controls and guide contract remain applicable. ## UI evidence (if applicable) [Synthetic pixel artifacts and exact metrics](https://gist.github.com/SpicyMarinara/79f20cf85eca708adce8a976fba25d34). ![Source on green](https://gist.githubusercontent.com/SpicyMarinara/79f20cf85eca708adce8a976fba25d34/raw/bf02fecb45bc751751a91d768a6c8cf5a6dc748e/source-view.png) ![Before builtin cleanup](https://gist.githubusercontent.com/SpicyMarinara/79f20cf85eca708adce8a976fba25d34/raw/060262b6946badef061403cf6f765ccd55b1e628/before-view.png) ![After builtin cleanup](https://gist.githubusercontent.com/SpicyMarinara/79f20cf85eca708adce8a976fba25d34/raw/d4bc6e0073f166e1ff766f612b22e36aa7f0cb2e/after-view.png) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:45:57 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8609
No description provided.