@vitavision/stage2d 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,7 +21,8 @@ deprecated predecessor, still exported unchanged.
21
21
 
22
22
  `ImageLayer` draws the photograph at its natural size. It can show a `preview` tier until
23
23
  the stage would magnify it, then load the full image and keep it, and it turns pixelated past
24
- `pixelatedAbove`. `StageButton` takes a `hint` and a `shortcut` for a richer tooltip, and
24
+ `pixelatedAbove`. `gain` and `gamma` draw it through a display tone curve (`gain × v^(1 / gamma)`
25
+ per channel, on screen only) for reading a dark or low-contrast frame. `StageButton` takes a `hint` and a `shortcut` for a richer tooltip, and
25
26
  `StageLayersMenu` is a layers button for `StageToolbar`. Code outside the stage, such as an
26
27
  inspector's "frame this", drives it through `ImageStage`'s `ref` (`StageHandle`: `frame`,
27
28
  `fit`, `zoomTo`). `initialView="fit"` opens a `null` view at fit even when the image would fit
package/dist/index.d.ts CHANGED
@@ -656,6 +656,8 @@ export declare function CompareLayer({ a, b, mode, split, defaultSplit, onSplitC
656
656
  * - **Pixelated past a zoom.** Above about 4× the browser's smoothing paints detail the
657
657
  * sensor never recorded; on a metrology bench the sensor's own samples are what is worth
658
658
  * looking at.
659
+ * - **A display tone curve.** A dark or low-contrast frame is read with a gain and a gamma
660
+ * applied on screen only (`gain`, `gamma`): the pixels the app measures are untouched.
659
661
  */
660
662
  /** A downscaled tier of the image, shown until the stage would magnify it. */
661
663
  interface ImageTier {
@@ -681,6 +683,20 @@ interface ImageLayerBaseProps {
681
683
  onLoad?: (() => void) | undefined;
682
684
  /** Called when the full image fails to load. */
683
685
  onError?: (() => void) | undefined;
686
+ /**
687
+ * Display gain: each channel is multiplied by it and clipped at white, after `gamma`.
688
+ * Defaults to 1. A negative value counts as 0, one that is not finite as 1.
689
+ *
690
+ * Like `gamma`, it changes what is drawn, never the image data: a way to read a dark or
691
+ * low-contrast frame, not a correction to measure on.
692
+ */
693
+ gain?: number | undefined;
694
+ /**
695
+ * Display gamma, as an image editor's levels control: each channel `v` (0 to 1, as encoded in
696
+ * the file) is drawn as `gain × v^(1 / gamma)`. Above 1 it lifts the shadows and mid-tones,
697
+ * below 1 it darkens them. Defaults to 1; a value that is not positive counts as 1.
698
+ */
699
+ gamma?: number | undefined;
684
700
  /** Merged onto both images with `cn`. */
685
701
  className?: string | undefined;
686
702
  }
@@ -707,11 +723,14 @@ type ImageLayerProps = ImageLayerBaseProps & ({
707
723
  * With a `preview`, the full image is wanted once the stage would magnify the preview, and
708
724
  * `onFullNeeded` says so; `src` can be supplied then rather than up front.
709
725
  *
726
+ * With a `gain` or `gamma` other than 1, both images are drawn through one SVG tone-curve filter
727
+ * (sRGB values, per channel) and carry `data-adjusted`.
728
+ *
710
729
  * Each image carries `data-tier` (`preview` or `full`); the full image carries `data-loaded`
711
730
  * once it has loaded, the preview carries `data-wants-full` from the moment the full image is
712
731
  * wanted until it has loaded, and both carry `data-pixelated` while pixelated.
713
732
  */
714
- export declare function ImageLayer({ src, preview, alt, pixelatedAbove, onFullNeeded, onLoad, onError, className }: ImageLayerProps): import("react").JSX.Element;
733
+ export declare function ImageLayer({ src, preview, alt, pixelatedAbove, onFullNeeded, onLoad, onError, gain, gamma, className }: ImageLayerProps): import("react").JSX.Element;
715
734
  //#endregion
716
735
  //#region src/components/stage/StageSurface.d.ts
717
736
  /** What a drag does as the pointer moves and when it is released, in image coordinates. */
package/dist/index.js CHANGED
@@ -2169,6 +2169,8 @@ function CompareLayer({ a, b, mode, split, defaultSplit = .5, onSplitChange, ori
2169
2169
  * - **Pixelated past a zoom.** Above about 4× the browser's smoothing paints detail the
2170
2170
  * sensor never recorded; on a metrology bench the sensor's own samples are what is worth
2171
2171
  * looking at.
2172
+ * - **A display tone curve.** A dark or low-contrast frame is read with a gain and a gamma
2173
+ * applied on screen only (`gain`, `gamma`): the pixels the app measures are untouched.
2172
2174
  */
2173
2175
  /**
2174
2176
  * The photograph at its natural size inside an `ImageStage`, with an optional preview tier
@@ -2178,12 +2180,17 @@ function CompareLayer({ a, b, mode, split, defaultSplit = .5, onSplitChange, ori
2178
2180
  * With a `preview`, the full image is wanted once the stage would magnify the preview, and
2179
2181
  * `onFullNeeded` says so; `src` can be supplied then rather than up front.
2180
2182
  *
2183
+ * With a `gain` or `gamma` other than 1, both images are drawn through one SVG tone-curve filter
2184
+ * (sRGB values, per channel) and carry `data-adjusted`.
2185
+ *
2181
2186
  * Each image carries `data-tier` (`preview` or `full`); the full image carries `data-loaded`
2182
2187
  * once it has loaded, the preview carries `data-wants-full` from the moment the full image is
2183
2188
  * wanted until it has loaded, and both carry `data-pixelated` while pixelated.
2184
2189
  */
2185
- function ImageLayer({ src, preview, alt, pixelatedAbove = 4, onFullNeeded, onLoad, onError, className }) {
2190
+ function ImageLayer({ src, preview, alt, pixelatedAbove = 4, onFullNeeded, onLoad, onError, gain, gamma, className }) {
2186
2191
  const stage = useStage();
2192
+ const curve = toneCurve(gain, gamma);
2193
+ const filterId = `stage-image-tone-${useId().replace(/[^A-Za-z0-9_-]/g, "")}`;
2187
2194
  const scale = stage.view.scale;
2188
2195
  const measured = stage.box.width > 0;
2189
2196
  const previewSrc = preview?.src ?? null;
@@ -2206,32 +2213,86 @@ function ImageLayer({ src, preview, alt, pixelatedAbove = 4, onFullNeeded, onLoa
2206
2213
  const fullReady = src !== void 0 && loaded === src;
2207
2214
  const pixelated = scale >= pixelatedAbove;
2208
2215
  const shared = cn("pointer-events-none absolute inset-0 h-full w-full select-none", className);
2209
- const rendering = pixelated ? "pixelated" : void 0;
2210
- return /* @__PURE__ */ jsxs(Fragment, { children: [preview && !fullReady && /* @__PURE__ */ jsx("img", {
2211
- src: preview.src,
2212
- alt: showFull ? "" : alt,
2213
- "aria-hidden": showFull ? true : void 0,
2214
- draggable: false,
2215
- "data-tier": "preview",
2216
- "data-wants-full": wanted ? "" : void 0,
2217
- "data-pixelated": pixelated ? "" : void 0,
2218
- className: shared,
2219
- style: { imageRendering: rendering }
2220
- }), showFull && /* @__PURE__ */ jsx("img", {
2221
- src,
2222
- alt,
2223
- draggable: false,
2224
- "data-tier": "full",
2225
- "data-loaded": fullReady ? "" : void 0,
2226
- "data-pixelated": pixelated ? "" : void 0,
2227
- onLoad: () => {
2228
- setLoaded(src);
2229
- onLoad?.();
2230
- },
2231
- onError: () => onError?.(),
2232
- className: cn(shared, preview && !fullReady && "opacity-0"),
2233
- style: { imageRendering: rendering }
2234
- })] });
2216
+ const style = {
2217
+ imageRendering: pixelated ? "pixelated" : void 0,
2218
+ filter: curve ? `url(#${filterId})` : void 0
2219
+ };
2220
+ const adjusted = curve ? "" : void 0;
2221
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2222
+ curve && /* @__PURE__ */ jsx("svg", {
2223
+ "aria-hidden": "true",
2224
+ width: "0",
2225
+ height: "0",
2226
+ className: "pointer-events-none absolute",
2227
+ focusable: "false",
2228
+ children: /* @__PURE__ */ jsx("filter", {
2229
+ id: filterId,
2230
+ colorInterpolationFilters: "sRGB",
2231
+ "data-tone-curve": "",
2232
+ children: /* @__PURE__ */ jsxs("feComponentTransfer", { children: [
2233
+ /* @__PURE__ */ jsx("feFuncR", {
2234
+ type: "gamma",
2235
+ amplitude: curve.amplitude,
2236
+ exponent: curve.exponent,
2237
+ offset: 0
2238
+ }),
2239
+ /* @__PURE__ */ jsx("feFuncG", {
2240
+ type: "gamma",
2241
+ amplitude: curve.amplitude,
2242
+ exponent: curve.exponent,
2243
+ offset: 0
2244
+ }),
2245
+ /* @__PURE__ */ jsx("feFuncB", {
2246
+ type: "gamma",
2247
+ amplitude: curve.amplitude,
2248
+ exponent: curve.exponent,
2249
+ offset: 0
2250
+ })
2251
+ ] })
2252
+ })
2253
+ }),
2254
+ preview && !fullReady && /* @__PURE__ */ jsx("img", {
2255
+ src: preview.src,
2256
+ alt: showFull ? "" : alt,
2257
+ "aria-hidden": showFull ? true : void 0,
2258
+ draggable: false,
2259
+ "data-tier": "preview",
2260
+ "data-wants-full": wanted ? "" : void 0,
2261
+ "data-pixelated": pixelated ? "" : void 0,
2262
+ "data-adjusted": adjusted,
2263
+ className: shared,
2264
+ style
2265
+ }),
2266
+ showFull && /* @__PURE__ */ jsx("img", {
2267
+ src,
2268
+ alt,
2269
+ draggable: false,
2270
+ "data-tier": "full",
2271
+ "data-loaded": fullReady ? "" : void 0,
2272
+ "data-pixelated": pixelated ? "" : void 0,
2273
+ "data-adjusted": adjusted,
2274
+ onLoad: () => {
2275
+ setLoaded(src);
2276
+ onLoad?.();
2277
+ },
2278
+ onError: () => onError?.(),
2279
+ className: cn(shared, preview && !fullReady && "opacity-0"),
2280
+ style
2281
+ })
2282
+ ] });
2283
+ }
2284
+ /**
2285
+ * The `feFuncX type="gamma"` parameters (`amplitude × v^exponent`) for a gain and a gamma, or
2286
+ * `null` when the curve is the identity and no filter is needed.
2287
+ */
2288
+ function toneCurve(gain, gamma) {
2289
+ const amplitude = gain === void 0 || !Number.isFinite(gain) ? 1 : Math.max(0, gain);
2290
+ const g = gamma === void 0 || !(gamma > 0) || !Number.isFinite(gamma) ? 1 : gamma;
2291
+ if (amplitude === 1 && g === 1) return null;
2292
+ return {
2293
+ amplitude,
2294
+ exponent: 1 / g
2295
+ };
2235
2296
  }
2236
2297
  //#endregion
2237
2298
  //#region src/components/stage/StageToolbar.tsx