[PR #7974] [MERGED] fix(avatars): blink and talk pictures work on dark skin and hide the whole open eye (#7962) #8036

Closed
opened 2026-10-24 04:09:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: staging ← Head: fix/7962-avatar-blink-talk-threshold


📝 Commits (2)

  • 0c5dcb5 fix(avatars): blink and talk pictures work on dark skin and hide the whole open eye (#7962)
  • fa1d8ed Merge branch 'staging' into fix/7962-avatar-blink-talk-threshold

📊 Changes

2 files changed (+156 additions, -36 deletions)

View changed files

📝 packages/server/src/services/avatars/generation/variant-composite.ts (+97 -36)
📝 scripts/regressions/avatar-variant-composite.regression.ts (+59 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7962

Why this change

2D Avatars blink and talk pictures failed depending on the character's colours (#7962):

  • Dark skin: talk pictures were refused almost every time with "The image model didn't open the mouth in this picture. Try again." The reporter's dark-skinned character failed about 20 of 21 talk attempts. The compositor counted a pixel as changed only if its largest RGB channel moved by 48 or more, and needed the main group to average 64. A maroon mouth on dark purple skin moves by about 48, although it is clearly visible (CIE76 ΔE about 22).
  • Pale skin, light eyes: blinks were accepted, but the original open iris showed under the closed lid. Only the changed pixels were copied from the model's picture, and a light amber iris under a pale lid moves by only 31, so it stayed the face's own.

What changed

All in packages/server/src/services/avatars/generation/variant-composite.ts:

  • Detection uses perceptual colour difference. Changes are measured as CIE76 Lab distance: a change counts from ΔE 10, and the main group must average 12. A dark mouth on dark skin now counts the same way one on light skin does.

  • Compression noise is still refused. If the main group averages under ΔE 30, its change must be at least 0.6 of how much the face itself varies under it. JPEG ringing and chroma bleed sit on the face's own lines and edges and fall below that, while real edits change a spot by more than the face varies there. Groups smaller than longSide²/10 000 pixels (26 on a 512-pixel face) are scraps of redrawn lines, not an eye or a mouth.

  • The whole eye or mouth comes from the model. Every non-outline pixel inside each chosen group's own ellipse (through the corners of its box, plus the feather) is taken from the model's picture. An iris, an eye white or teeth that differ only a little from the face can no longer show through. Outside the generous ellipse the face stays byte for byte, and its alpha is kept everywhere, as before.

  • Alignment treats padding as white. Fit samples that fall past the edge of the model's picture now count as the white padding models add, instead of a full mismatch. Before this, a picture the model shifted and padded with white could be fitted at the wrong scale, which offset the eye or mouth by a couple of pixels.

  • New regression case. scripts/regressions/avatar-variant-composite.regression.ts covers the issue's model-independent repro:

    • the maroon mouth on dark purple skin is accepted;
    • a blink over pale amber eyes leaves no open iris;
    • the same dark face with only JPEG noise is still refused.

    The old compositor fails both the talk check (it throws) and the blink check (348 open-eye pixels left).

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

Agent-run checks:

  • Regressions passed: node ./scripts/run-regressions.mjs --filter for avatar-variant-composite, image-edit-reference and avatar-generation.
  • Harness of 96 synthetic cases (six skin tones; edits in place, shifted, zoomed and resized JPEG; no-change, noise-only, tone-shift and rotated negatives): 0 failures, against 30 on the old code.
  • Stress harness of 135 cases (anime eyes, "^" closed eyes, glasses, a hair strand over an eye, small and thin mouths, 160 px and 1024 px faces, greyscale, eyes near the outline, wobbled lines, blur, grain, strong tone shifts): 6 failures, against 42 on the old code. The 6 are listed under limits below.
  • Same-size JPEG of an unedited face (quality 40–90, 4:2:0 and 4:4:4): 0 of 216 accepted on the regression faces. On a wider probe of 576, 8 were accepted, all at quality 40. No real edit was missed.
  • Speed: compositor time is about 1.16× the old code.
  • Not run, at the maintainer's request: pnpm check (typecheck and lint), CodeRabbit and other local review tools.

Manual verification notes

  • Manually verify in the browser, with a dark-skinned character (skin around rgb 86,64,88): 2D Avatars → Blink and talk pictures → Make on the talk picture succeeds and shows an open mouth.
  • Manually verify, with a pale character with light (amber or light-blue) eyes: a generated blink shows a fully closed lid, with no strip of the open iris under the lash line.
  • Manually verify a light-skinned character's blink and talk pictures still look as before, with no new halo or seam around the eyes or mouth.
  • Manually verify that a talk or blink picture the model didn't actually change is still refused with the "didn't open the mouth" or "didn't close the eyes" message.

Known limits (none of these are new failures):

  • A picture rotated about 6° without an edit is still accepted, because the fit searches scale and shift but not rotation. The old code accepts these too.
  • At JPEG quality 40 with 4:2:0 chroma, a thin, saturated line on dark skin can still lose enough colour to count as a change. This showed up in 8 of 576 synthetic probes.
  • A hair lock the model redrew next to an eye can come through inside the eye's ellipse. In one stress case this was 49 pixels just above the allowed box.

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 (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

docs/agents/avatars.md § Blink and talk pictures already describes this behaviour without colour thresholds ("only the eyes … or the mouth … is taken from it"), so I made no docs change.

UI evidence (if applicable)

This is a server-side picture change with no UI change. Before/after crops from the synthetic harness:

  • Pale amber blink: the old compositor leaves the iris and a ghost upper lash line; the fix shows clean closed lids.
  • Dark purple talk picture: the old compositor refuses it; the fix accepts it with the maroon mouth.

🤖 Generated with Claude Code


🔄 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/7974 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/7962-avatar-blink-talk-threshold` --- ### 📝 Commits (2) - [`0c5dcb5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0c5dcb5c71b9eb5c1303159f3b0ca8e4a74b233d) fix(avatars): blink and talk pictures work on dark skin and hide the whole open eye (#7962) - [`fa1d8ed`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fa1d8edb6bbf3566b91028cb6aab90096412024e) Merge branch 'staging' into fix/7962-avatar-blink-talk-threshold ### 📊 Changes **2 files changed** (+156 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/avatars/generation/variant-composite.ts` (+97 -36) 📝 `scripts/regressions/avatar-variant-composite.regression.ts` (+59 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7962 ## Why this change 2D Avatars blink and talk pictures failed depending on the character's colours (#7962): - **Dark skin:** talk pictures were refused almost every time with "The image model didn't open the mouth in this picture. Try again." The reporter's dark-skinned character failed about 20 of 21 talk attempts. The compositor counted a pixel as changed only if its largest RGB channel moved by 48 or more, and needed the main group to average 64. A maroon mouth on dark purple skin moves by about 48, although it is clearly visible (CIE76 ΔE about 22). - **Pale skin, light eyes:** blinks were accepted, but the original open iris showed under the closed lid. Only the changed pixels were copied from the model's picture, and a light amber iris under a pale lid moves by only 31, so it stayed the face's own. ## What changed All in `packages/server/src/services/avatars/generation/variant-composite.ts`: - **Detection uses perceptual colour difference.** Changes are measured as CIE76 Lab distance: a change counts from ΔE 10, and the main group must average 12. A dark mouth on dark skin now counts the same way one on light skin does. - **Compression noise is still refused.** If the main group averages under ΔE 30, its change must be at least 0.6 of how much the face itself varies under it. JPEG ringing and chroma bleed sit on the face's own lines and edges and fall below that, while real edits change a spot by more than the face varies there. Groups smaller than longSide²/10 000 pixels (26 on a 512-pixel face) are scraps of redrawn lines, not an eye or a mouth. - **The whole eye or mouth comes from the model.** Every non-outline pixel inside each chosen group's own ellipse (through the corners of its box, plus the feather) is taken from the model's picture. An iris, an eye white or teeth that differ only a little from the face can no longer show through. Outside the generous ellipse the face stays byte for byte, and its alpha is kept everywhere, as before. - **Alignment treats padding as white.** Fit samples that fall past the edge of the model's picture now count as the white padding models add, instead of a full mismatch. Before this, a picture the model shifted and padded with white could be fitted at the wrong scale, which offset the eye or mouth by a couple of pixels. - **New regression case.** `scripts/regressions/avatar-variant-composite.regression.ts` covers the issue's model-independent repro: - the maroon mouth on dark purple skin is accepted; - a blink over pale amber eyes leaves no open iris; - the same dark face with only JPEG noise is still refused. The old compositor fails both the talk check (it throws) and the blink check (348 open-eye pixels left). ## 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` Agent-run checks: - **Regressions passed:** `node ./scripts/run-regressions.mjs --filter` for `avatar-variant-composite`, `image-edit-reference` and `avatar-generation`. - **Harness of 96 synthetic cases** (six skin tones; edits in place, shifted, zoomed and resized JPEG; no-change, noise-only, tone-shift and rotated negatives): 0 failures, against 30 on the old code. - **Stress harness of 135 cases** (anime eyes, "^" closed eyes, glasses, a hair strand over an eye, small and thin mouths, 160 px and 1024 px faces, greyscale, eyes near the outline, wobbled lines, blur, grain, strong tone shifts): 6 failures, against 42 on the old code. The 6 are listed under limits below. - **Same-size JPEG of an unedited face** (quality 40–90, 4:2:0 and 4:4:4): 0 of 216 accepted on the regression faces. On a wider probe of 576, 8 were accepted, all at quality 40. No real edit was missed. - **Speed:** compositor time is about 1.16× the old code. - **Not run, at the maintainer's request:** `pnpm check` (typecheck and lint), CodeRabbit and other local review tools. ### Manual verification notes - [ ] Manually verify in the browser, with a dark-skinned character (skin around rgb 86,64,88): 2D Avatars → Blink and talk pictures → **Make** on the talk picture succeeds and shows an open mouth. - [ ] Manually verify, with a pale character with light (amber or light-blue) eyes: a generated blink shows a fully closed lid, with no strip of the open iris under the lash line. - [ ] Manually verify a light-skinned character's blink and talk pictures still look as before, with no new halo or seam around the eyes or mouth. - [ ] Manually verify that a talk or blink picture the model didn't actually change is still refused with the "didn't open the mouth" or "didn't close the eyes" message. Known limits (none of these are new failures): - A picture rotated about 6° without an edit is still accepted, because the fit searches scale and shift but not rotation. The old code accepts these too. - At JPEG quality 40 with 4:2:0 chroma, a thin, saturated line on dark skin can still lose enough colour to count as a change. This showed up in 8 of 576 synthetic probes. - A hair lock the model redrew next to an eye can come through inside the eye's ellipse. In one stress case this was 49 pixels just above the allowed box. ## 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 (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `docs/agents/avatars.md` § Blink and talk pictures already describes this behaviour without colour thresholds ("only the eyes … or the mouth … is taken from it"), so I made no docs change. ## UI evidence (if applicable) This is a server-side picture change with no UI change. Before/after crops from the synthetic harness: - **Pale amber blink:** the old compositor leaves the iris and a ghost upper lash line; the fix shows clean closed lids. - **Dark purple talk picture:** the old compositor refuses it; the fix accepts it with the maroon mouth. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:09:51 +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#8036
No description provided.