SLOHERO / PHOTOSHOT RESEARCHENGINEERING RECORD · 02IMPLEMENTATION / EVIDENCE / REPRODUCTION

Photoshot development · 02

Calibrating brightness and contrast: from a GitHub reference to ordered response sampling

A numerical failure, its source-level correction, and the boundary between historical chart measurements and a new 27-point replay.

Source scope: initial eead3ca / later v0.16.0 · 19f45ed. This record does not audit every feature of the current production editor.

Abstract

The feature was a non-destructive brightness/contrast adjustment integrated with masks, opacity and project persistence. Konva’s Contrast filter provided an inspected reference, while Photoshot used its own expressions and channel lookup tables. A September 2026 comparison exposed an intermediate approximation whose mean absolute RGB-channel error was 11.505 against Photoshop 27.3.1. Sampling measured brightness and contrast responses in that order reduced the recorded mean error to 0.241; reversing the order gave 1.150. We reproduce 27 archived gray outputs with the unchanged public engine and expose the underlying data. The full historical chart was not remeasured for this article.

1. Feature contract: a persistent adjustment layer

The objective was to change brightness and contrast through an editable adjustment, retain the original pixels, and preserve the chosen values when the project is reopened. The adjustment must participate in the existing mask, opacity and layer-order machinery. A working slider is therefore necessary but insufficient: it may update a number while the resulting pixel response is still wrong.

For an 8-bit channel, the engine can prepare a lookup from each input value 0–255 to an output response. The table is calculated when the adjustment is compiled and reused by pixel processing. This was already present in the initial implementation; it was not introduced by the later calibration fix. The substantive change was the transfer function and its order.1

2. Initial code and the observed numerical failure

The September 18 record shows Konva’s src/filters/Contrast.ts being opened before the initial adjustment engine was written. Photoshot’s first expressions brighten toward white or darken toward black, then apply contrast around normalized midpoint 0.5. The old-revision path remains in the public source so projects using that calculation retain their behavior. It is not identical to Konva’s formula.

On September 25, an intermediate normal-mode approximation was tested against Photoshop 27.3.1 with brightness +30 and contrast +20. Mean absolute RGB-channel difference was 11.505 and maximum difference was 25. For gray input 0, that build returned 25 instead of 0; for input 128 it returned 168 instead of 157. These are actual recorded failures. They belong to the tested intermediate build, not a retrospective measurement of the September 18 legacy expression.2

Listing 1 · retained legacy-revision path · src/adjustments.ts, L506–510 · 19f45ed
        if (t === 'brightness' && a.revision !== 2) {
          x = v.brightness < 0 ? x * (1 + v.brightness / 100) : x + ((1 - x) * v.brightness) / 100;
          const contrast = v.contrast < 0 ? 1 + v.contrast / 100 : 1 / (1 - v.contrast / 101);
          x = (x - 0.5) * contrast + 0.5;
        }

3. What the GitHub reference contributed

Konva normalizes each channel, moves its midpoint to zero, scales by a contrast factor, shifts back and clamps the result. Reading an actual pixel loop made its input range, channel handling and alpha boundary explicit. The short excerpt below shows the factor and part of the red-channel operation; it is a reference excerpt, not Photoshot production code.3

The record supports source consultation, not installation or verbatim transplantation of the Konva filter. Photoshot used separately written expressions, then revised them using measured response data. The distinction matters: a public implementation can be useful while still targeting a different response curve. The solution to the measured mismatch came from calibration and application-specific integration, not from claiming the reference was Photoshop’s implementation.

Listing 2 · external reference excerpt · Konva / Contrast.ts
const adjust = Math.pow((this.contrast() + 100) / 100, 2);
// …
red -= 0.5;
red *= adjust;
red += 0.5;
Table 1 | Source contribution and subsequent development
SourceUse categoryContributionDecision
Konva Contrast.tsInspected GitHub sourceMidpoint-based contrast pixel loopConsulted; not installed verbatim
Initial Photoshot engineApplication-specific expressionsBrightness then contrast; 256-entry LUTsOld revision retained
Photoshop calibrationMeasured response dataSingle-control gray-ramp outputsInput data, not Adobe source code
Photoshot revision 2Application-specific correctionResponse interpolation and ordered compositionIntegrated with existing layer machinery

Actual chronology: reference lookup and initial implementation on September 18, comparison and calibration on September 25. The reference was not first discovered after that numerical failure.

4. Correction: response data, interpolation and operation order

Calibration sampled a synthetic gray ramp in Photoshop normal mode: brightness from −150 to +150 and contrast from −50 to +100 in steps of 10, varying one control while holding the other at zero. The resulting response tables are retained in tone-response.ts. Intermediate control values and channel positions are interpolated through sampleResponse; the compiled RGB tables contain floating-point responses.

In revision 2 normal mode, the input passes through brightness first and contrast second. The order is part of the implementation: C(B(x)) is generally different from B(C(x)). The response calls are inside the existing 256-entry-per-channel compilation path; masks and opacity remain compositor responsibilities. Old revisions keep their prior branch, and the separate Legacy option must not be confused with the normal-mode measured response.14

Listing 3 · revised normal mode · src/adjustments.ts, L517–518 · 19f45ed
            x = sampleResponse(toneResponse.brightness, v.brightness, -150, x);
            x = sampleResponse(toneResponse.contrast, v.contrast, -50, x);
Listing 4 · existing channel-table compilation · src/adjustments.ts, L503–505 · 19f45ed
    const tables = ['r', 'g', 'b'].map((channel) =>
      Float64Array.from({ length: 256 }, (_, i) => {
        let x = i / 255;
The implemented brightness–contrast path
Fig. 1 | The implemented brightness–contrast path. Schematic of the revision 2 normal-mode path. RGB is transformed; alpha is preserved. Three channel tables contain 256 floating-point entries each. Masking and opacity follow the shared adjustment-layer contract. The reference implementation and Photoshot’s response integration are different sources.
SVG

5. Methods and results: archive versus new replay

The historical chart was 256 × 32 pixels: eight gray-ramp rows followed by mixed RGB rows. The comparison excluded alpha and evaluated 24,576 channel samples. In the archived order experiment, B → C gave mean error 0.2412109375 and maximum 1; C → B gave 1.1497395833 and maximum 4. The follow-up patched-engine run reported mean 0.241, maximum 1 and 75.88% exact channel matches. Those rounded figures describe the same stated test condition.

For this article we re-imported the unchanged public engine and checked its response tables against the archived calibration JSON. They match exactly. We also compiled +30/+20, +17/+13 and −65/−23, then evaluated the nine archived gray inputs for each setting: all 27 current outputs match the archived Photoshot values. The retained Photoshop values are comparison points, not newly generated reference exports. The original full-chart PNGs are unavailable in the reviewed folder, so their full-chart errors were not recalculated today.25

Recorded failure, correction and reversed-order control
Fig. 2 | Recorded failure, correction and reversed-order control. Archived September 25 chart comparison against Photoshop 27.3.1, normal mode, brightness +30 and contrast +20. a, Mean absolute error over 24,576 RGB-channel samples. b, Maximum absolute channel error. Each bar is one deterministic chart evaluation; no replicate uncertainty is implied. “Intermediate approximation” is not the initial September 18 legacy implementation.
SVGData
Table 2 | Historical full-chart measurements and current verification
Implementation / settingMean |Δ|Max |Δ|Origin
Intermediate approximation, +30/+2011.50525Historical
Response B → C, +30/+200.2412111Historical
Response C → B, +30/+201.1497404Historical
Additional setting +17/+130.2151Historical
Additional setting −65/−230.2291Historical

Columns: implementation / mean absolute channel error / maximum / measurement origin. Newly rerun: calibration tables equal archived data; 27/27 gray outputs equal archived Photoshot outputs. Those 27 samples do not re-estimate full-chart means.

Visible gray-value failure and a new source replay
Fig. 3 | Visible gray-value failure and a new source replay. a, Nine actual gray values from the archived intermediate failure, archived Photoshop output and the current source replay; patches visualize those numeric values, not a reconstructed historical screenshot. b, The current compiled response at +30/+20, with archived Photoshop samples. Desktop panel c shows residuals for all 27 retained gray samples across three settings. Every current output equals the archived Photoshot output.
SVGData

6. Result interpretation and remaining limits

The documented correction fixes a concrete numerical mismatch on the archived test chart and reproduces the retained gray outputs. The mean-error reduction is approximately 97.9% for that comparison, not a visual-quality percentage or a universal compatibility score. No confidence interval is supplied because this is a deterministic chart comparison, not independent repeated sampling. No rendering-speed benefit was measured.

A later portrait illustration uses brightness +18 and contrast +12. Its appearance must not be used as evidence for the +30/+20 chart statistics. Reproducing all pixels against a newly generated Photoshop export, checking further color profiles and running browser persistence/export checks remain distinct tasks. Part 3 extends the same adjustment architecture to levels and histogram controls.

Code, data and reproducibility

Download the retained measurement summary, new replay data and exact source listings. The full-chart source PNGs were not available for a new Photoshop comparison. The supplied replay harness checks the current source against archived values.

References and source identity

  1. Photoshot adjustments.ts · 19f45ed
  2. Archived comparison summary · 2026-09-25
  3. Konva · src/filters/Contrast.ts (consulted reference; moving master branch)
  4. Photoshot tone-response.ts · 19f45ed
  5. Source replay and archived gray values · 2026-11-01