Skip to content

fix(raster): colorBalance keeps luma at the clamp; pin mix formulas - #597

Merged
github-actions[bot] merged 1 commit into
devfrom
lead/tone-pack-r1-b2
Oct 19, 2026
Merged

github-actions[bot] merged 1 commit into
devfrom
lead/tone-pack-r1-b2

Conversation

@prakashUXtech

@prakashUXtech prakashUXtech commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Anatomy round 1, batch r1-b2 for tone-pack: the ColorMix fixes (blackAndWhite, channelMixer, colorBalance). Part of #432.

What changed and which test proves it:

  • colorBalance keeps luma at the clamp (TP-4 contract). With preserveLuminosity the result was scaled by L/lo and then clamped, so a channel pushed above 1 lost luma: encoded [1, 1, 0.2] with highlights [0, 0, -100] lost about 6.6e-3. Now, when the scaled result has a channel above 1, the chroma is pulled toward the grey at L by the largest k in 0...1 that fits (out = L + (s - L) * k). Both s and L are non-negative, so only the upper bound limits k. The result's luma is L exactly. Proof: ColorMixTests.preserveKeepsLuma now covers inputs over the full 0...1 range, channels at 1, and that exact case. It fails before the fix (mutation G3: Scene commands #4 puts the old behaviour back and is caught).
  • Non-finite errors name the field. checkFinite is now called once per field: "blackAndWhite yellows", "channelMixer green", "colorBalance highlights" and so on. Proof: ColorMixTests.nanNamesField.
  • Docs. Each of the three doc comments now says "Out-of-range values are clamped; non-finite values throw RasterError.invalid". colorBalance's comment also describes the chroma pull. The clamp is pinned by GrayMix(reds: 500) == GrayMix(reds: 300) in betweenRangesAndTint.
  • Zone weights and the negative branch. New test ColorMixTests.highlightsAndMidtonesByZone (with preserveLuminosity false) checks greys 0, 0.1, 0.5, 0.95 and 1 under highlights [100,0,0], midtones [100,0,0] and shadows [-100,0,0]. Each value is compared within 1e-5 to the documented formula.
  • channelMixer formula. New test ColorMixTests.matrixRowsAndConstant: on a seeded opaque buffer, each output channel equals clamp(row·(r,g,b,1), 0, 1) within 1e-6, and a pixel whose sum is above 1 gives exactly 1.
  • blackAndWhite interpolation, tint and weight clamp. New test ColorMixTests.betweenRangesAndTint covers three things. Hue-30 orange gives the interpolated grey 0.5. A tint on mid grey matches the W3C soft-light reference with r > g > b, and gives half the offset at tint alpha 0.5. The weight clamp is pinned as above.

Mutation entries added to Tests/mutations/CoreRaster.ColorMix.json: the luma k limit, the highlights smoothstep edge, the negative-shift direction, the channelMixer constant column and row order, the hue interpolation and the tint alpha. scripts/mutate --run --changed-since origin/dev reports 10/10 caught. I also checked by hand that the tests catch these mutants: the weight clamp removed, the output clamp removed, midtones dropped and the tint dropped.

No platform API is new here. The change uses only Swift stdlib SIMD operators that this file already uses, so I did not look anything up in the docs tools.

Belt-Lead: act-1a150bfbcf7-sfwy
Feature: tone-pack
Slice: TP-mix
Mutate: 10/10 CoreRaster.ColorMix
Fast-Check: pass
Head: 46a38b9


@prakashUXtech prakashUXtech added the fast-lane Small green PR, auto-merge when eligible label Oct 19, 2026 — with Claude
@github-actions
github-actions Bot merged commit 1808edc into dev Oct 19, 2026
1 check passed
@github-actions github-actions Bot added the fast-lane-merged Merged by the fast lane; review after the fact label Oct 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Fast lane: merged into dev (198 lines, 3 files, Fast-Check marker).

prakashUXtech added a commit that referenced this pull request Oct 19, 2026
@github-actions github-actions Bot mentioned this pull request Oct 19, 2026
prakashUXtech added a commit to qbtrix/creative-apps that referenced this pull request Oct 19, 2026
…rallel (#3126)

Moves the creative-core pin from bf5426e to 0de5687, the head of core
`main` (green, promoted from dev). The range has the resident-rendering
speedups from qbtrix/creative-core#620: the batched composite commits
without waiting, the resident dirty check is storage identity instead of
a pixel compare, and the Float16 tile upload vectorizes. It also has
qbtrix/creative-core#626, which repoints the mutation anchor #620 moved.

Core range (58 commits):
qbtrix/creative-core@bf5426e...0de5687

Core PRs in the range: qbtrix/creative-core#567 qbtrix/creative-core#568
qbtrix/creative-core#569 qbtrix/creative-core#570
qbtrix/creative-core#571 qbtrix/creative-core#573
qbtrix/creative-core#574 qbtrix/creative-core#575
qbtrix/creative-core#576 qbtrix/creative-core#577
qbtrix/creative-core#578 qbtrix/creative-core#579
qbtrix/creative-core#580 qbtrix/creative-core#581
qbtrix/creative-core#582 qbtrix/creative-core#583
qbtrix/creative-core#584 qbtrix/creative-core#585
qbtrix/creative-core#586 qbtrix/creative-core#587
qbtrix/creative-core#588 qbtrix/creative-core#589
qbtrix/creative-core#590 qbtrix/creative-core#591
qbtrix/creative-core#592 qbtrix/creative-core#593
qbtrix/creative-core#594 qbtrix/creative-core#595
qbtrix/creative-core#596 qbtrix/creative-core#597
qbtrix/creative-core#598 qbtrix/creative-core#599
qbtrix/creative-core#600 qbtrix/creative-core#601
qbtrix/creative-core#602 qbtrix/creative-core#603
qbtrix/creative-core#605 qbtrix/creative-core#606
qbtrix/creative-core#607 qbtrix/creative-core#608
qbtrix/creative-core#609 qbtrix/creative-core#612
qbtrix/creative-core#613 qbtrix/creative-core#614
qbtrix/creative-core#615 qbtrix/creative-core#616
qbtrix/creative-core#617 qbtrix/creative-core#618
qbtrix/creative-core#619 qbtrix/creative-core#620
qbtrix/creative-core#621 qbtrix/creative-core#622
qbtrix/creative-core#623 qbtrix/creative-core#625
qbtrix/creative-core#626

Besides the pin:
- `project.yml` gets the same revision, as in #3023.
- `PhotoWorkspace.residentComposited` syncs a region's layer tiles
across the cores (through `PhotoLayerComposite.inParallel`), as the CPU
route renders its tiles. Steps keep their order. On a brush frame that
crosses two tiles the sync went from about 0.73 ms to 0.39 ms.
- `Tests/render-budgets.md` has the new 8K table and says where a
resident brush frame's time goes.

8K brush frame, release on the M2 Pro (median of three runs; the Mac was
loaded, with another Photo running): CPU 1.0 ms, GPU-resident 1.4 ms
(was 1.7). The GPU route is still behind the CPU. Most of what's left is
the display into the presenter's texture, which waits about 0.55 ms for
the GPU because the presenter draws from its own queue. Full redraw on
the resident route is 31 ms (was 35) and the first picture 166 ms (was
192).

Checked locally on macOS: `scripts/bump-core`'s steps at 0de5687. `swift
build --build-tests` passed. Every `*ModelTests` target passed except
four Library wall-clock budget tests
(`oneEditOnSixtyPhotosStaysInBudget`, `cullOneWithinBudget`,
`beginImportWithinBudget`, `orderRebuildWithinBudget`), which went over
in the parallel run on the loaded Mac and pass when run alone. The brush
perf suites (PhotoBrushDisplayTests, PhotoBrushLatencyTests,
PhotoBrushInkLatencyTests) passed. With the parallel sync on top,
`PhotoModelTests` and `PhotoRenderBackendTests` passed (647 tests), and
`PhotoRenderBudgetTests` ran in release with
`Tests/SuiteUITests/SegmentedTabsTests.swift` set aside, since it
doesn't link in release on SDK 27.
prakashUXtech added a commit that referenced this pull request Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fast-lane Small green PR, auto-merge when eligible fast-lane-merged Merged by the fast lane; review after the fact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant