@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 +2 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.js +88 -27
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/stage/ImageLayer.tsx +63 -4
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`. `
|
|
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
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
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
|