Skip to content

fix: keep traced SVGs under the path command limit of laser software - #1920

Open
Marouane-elfadli wants to merge 2 commits into
KnifeLemon:mainfrom
Marouane-elfadli:fix/1917-trace-svg-command-limit
Open

Marouane-elfadli wants to merge 2 commits into
KnifeLemon:mainfrom
Marouane-elfadli:fix/1917-trace-svg-command-limit

Conversation

@Marouane-elfadli

Copy link
Copy Markdown
Contributor

What does this change?

Raster → SVG tracing now keeps the result under a budget of 40,000 path commands. If a trace is over the budget, it is retried with coarser settings (larger specks, looser curves, fewer colours, and finally a reduced working resolution) until it fits. This stops Flux Beam Studio from showing "The file may be too large or complex" and importing a black placeholder instead of the picture. Pictures already under the budget trace exactly as before.

Fixes #1917

Type of change

  • Bug fix
  • New feature or improvement
  • New format or engine
  • Translation
  • Documentation
  • Build, CI or dependencies

How was it tested?

  • dotnet format --verify-no-changes
  • dotnet test
  • Tried it in the app (what you converted or clicked, and on which OS):

Added a regression test, Busy_picture_stays_under_the_command_budget, in TracingTests.cs.

Screenshots (UI changes)

No UI changes.

Checklist

  • New UI strings are in all src/Filee.App/Assets/i18n/*.json files (no new UI strings)
  • New third-party code or binaries are listed in THIRD-PARTY-NOTICES.md (none added)
  • The PR does one thing (unrelated changes go in a separate PR)

@github-actions github-actions Bot added the bug Something isn't working label Nov 29, 2026

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, @Marouane-elfadli! Retrying with coarser settings until the SVG fits is a sensible approach. Halving the picture is also safe: WriteSvg scales from result.Width/Height, so a halved trace still fills the original size.

Blocking: CI fails at dotnet format

windows / build (win-x64) stops at dotnet format Filee.slnx --verify-no-changes --severity warn:

tests/Filee.Engines.Tests/TracingTests.cs(145,25): warning xUnit1051: Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken …
tests/Filee.Engines.Tests/TracingTests.cs(146,23): warning xUnit1051: …

Pass the test's token to both calls:

var unlimited = ImageTracer.Trace(rgba, size, size, settings with { MaxCommands = 0 }, ct: TestContext.Current.CancellationToken);
var limited = ImageTracer.Trace(rgba, size, size, settings, ct: TestContext.Current.CancellationToken);

The Linux jobs ran the tests, and they passed.

A question for the maintainer (no change needed yet)

The 40 000 cap applies to every trace, so a detailed trace that someone wants for print or editing gets simplified too, and there's no way to turn it off. We'll confirm whether the cap should stay on by default or become a preset option. Please wait for that answer before reworking anything.

Smaller points (optional)

  • After the last round, the result can still be over the budget, yet the SVG comment says "Simplified to N path commands (limit 40000)". It could say when the result didn't fit.
  • Each retry traces the whole picture again while the progress stays at 95 %. On a large photo that can mean several full traces. That's fine for now; I'm only noting it.
  • A CHANGELOG bullet under Unreleased, with a ko/en pair in the update block, would help. We can add it when merging if you prefer.

The branch starts from an October commit, but it merges into main cleanly, so you don't need to do anything there.

@KnifeLemon

Copy link
Copy Markdown
Owner

Hi @Marouane-elfadli, thanks for waiting. The maintainer has decided: the command budget becomes a tracing option, off by default, rather than applying to every trace. A detailed trace for printing or editing should stay as detailed as it is today, and people sending it to laser or CAD software can turn the budget on.

What that means for this PR:

  1. Preset field. Add bool LimitPathCommands to TracingOptions (src/Filee.Core/Presets/Preset.cs), default false, and copy it in Clone(). When it's on, the conversion passes MaxCommands = TraceSettings.DefaultMaxCommands; when it's off, it passes 0.
    • A preset without the field reads as off, so no schema step is needed, and existing presets trace exactly as they do now.
  2. Editor. Add a checkbox under Detail in the trace section of the preset editor, e.g. "Keep under 40,000 path commands (for laser and CAD software)". Use a new key next to presets.trace_detail.
    • The key goes in all 23 files in src/Filee.App/Assets/i18n/. English text in the other files is fine to start; we'll translate.
  3. Shared presets. Add ("limitCommands", Flag) to the trace object in SharedPresetRules, and add presets[].trace.limitCommands to the Fields list in src/Filee.Core/Gallery/SharedPresetVersions.cs as "2.6.0". PresetGalleryVersionTests fails without it.
  4. CI. dotnet format --severity warn fails on xUnit1051 at TracingTests.cs lines 145–146. Pass ct: TestContext.Current.CancellationToken to both ImageTracer.Trace calls.
  5. Small things from the first read:
    • If the last round is still over the budget, the SVG comment shouldn't say "Simplified to N (limit 40000)". Say it's still over.
    • A test that the option off leaves a busy picture untouched would be good.
  6. Housekeeping. Merge main, since the branch is based on an October commit. Add a CHANGELOG bullet and the ko/en pair in the <!-- update block, like the other entries.

If you'd rather not take this on, just say so and we'll finish it from here, keeping your credit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Converted file too large?

2 participants