Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(canvas): exposure entries and channel-scoped levels
Josh Corbett314eab28fd4e
diff --git a/invokeai/frontend/webv2/performance/browser-baseline.json b/invokeai/frontend/webv2/performance/browser-baseline.jsonindex e423e07759..59f7c83f4f 100644--- a/invokeai/frontend/webv2/performance/browser-baseline.json+++ b/invokeai/frontend/webv2/performance/browser-baseline.json@@ -25,13 +25,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 117.69999999552965,+ "domContentLoadedMedianMs": 123.40000000596046,"id": "launchpad","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 117.79999999701977,- "longestTaskMaxMs": 69,+ "loadMedianMs": 123.59999999403954,+ "longestTaskMaxMs": 73,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -41,24 +41,24 @@"fontRawBytes": 23664,"imageRawBytes": 0,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 38,- "scriptRawBytes": 1635291,+ "scriptRawBytes": 1635387,"scriptRequestCount": 34,- "totalRawBytes": 1820473+ "totalRawBytes": 1821488},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 0,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 38,- "scriptRawBytes": 1651644,+ "scriptRawBytes": 1651741,"scriptRequestCount": 34,- "totalRawBytes": 1838678+ "totalRawBytes": 1839703},- "routeReadyMedianMs": 256.70000000298023,+ "routeReadyMedianMs": 273.79999999701977,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "empty"},@@ -85,13 +85,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 113.20000000298023,+ "domContentLoadedMedianMs": 125,"id": "launchpad","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 113.29999999701977,- "longestTaskMaxMs": 69,+ "loadMedianMs": 125.1000000089407,+ "longestTaskMaxMs": 76,"owner": "app","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:launchpad",@@ -101,24 +101,24 @@"fontRawBytes": 23664,"imageRawBytes": 0,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 38,- "scriptRawBytes": 1635291,+ "scriptRawBytes": 1635387,"scriptRequestCount": 34,- "totalRawBytes": 1820473+ "totalRawBytes": 1821488},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 0,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 38,- "scriptRawBytes": 1651644,+ "scriptRawBytes": 1651741,"scriptRequestCount": 34,- "totalRawBytes": 1838678+ "totalRawBytes": 1839703},- "routeReadyMedianMs": 270.1000000014901,+ "routeReadyMedianMs": 289.40000000596046,"scriptSourceOwnerSet": "launchpad-static","stateProfile": "representative"},@@ -145,15 +145,15 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 113,+ "domContentLoadedMedianMs": 127.19999998807907,"id": "editor-minimal","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 113.10000000149012,- "longestTaskMaxMs": 94,+ "loadMedianMs": 127.29999999701977,+ "longestTaskMaxMs": 138,"owner": "workbench",- "projectSwitchMedianMs": 36.400000005960464,+ "projectSwitchMedianMs": 40.5,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -161,24 +161,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 115,- "scriptRawBytes": 3271494,+ "scriptRawBytes": 3273182,"scriptRequestCount": 110,- "totalRawBytes": 3613052+ "totalRawBytes": 3615659},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 115,- "scriptRawBytes": 3304209,+ "scriptRawBytes": 3305914,"scriptRequestCount": 110,- "totalRawBytes": 3649183+ "totalRawBytes": 3651816},- "routeReadyMedianMs": 654.3999999985099,+ "routeReadyMedianMs": 692.7000000029802,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -205,15 +205,15 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 112.60000000149012,+ "domContentLoadedMedianMs": 124.09999999403954,"id": "editor-minimal","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,"layoutSwitchMedianMs": 0,- "loadMedianMs": 112.80000000447035,- "longestTaskMaxMs": 185,+ "loadMedianMs": 124.29999999701977,+ "longestTaskMaxMs": 196,"owner": "workbench",- "projectSwitchMedianMs": 70.89999999850988,+ "projectSwitchMedianMs": 75.70000000298023,"readyMark": "invokeai:ready:widget:center:preview","remediationTicket": "deepen-widget-registry-loading","resourceBaseline": {@@ -221,24 +221,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 115,- "scriptRawBytes": 3271494,+ "scriptRawBytes": 3273182,"scriptRequestCount": 110,- "totalRawBytes": 3613052+ "totalRawBytes": 3615659},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 115,- "scriptRawBytes": 3304209,+ "scriptRawBytes": 3305914,"scriptRequestCount": 110,- "totalRawBytes": 3649183+ "totalRawBytes": 3651816},- "routeReadyMedianMs": 428.5,+ "routeReadyMedianMs": 469.59999999403954,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"},@@ -247,31 +247,31 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 286370,+ "largestAssetRawBytes": 290304,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 444668,+ "scriptRawBytes": 449083,"scriptRequestCount": 7,- "totalRawBytes": 444668+ "totalRawBytes": 449083},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 289234,+ "largestAssetRawBytes": 293208,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 449115,+ "scriptRawBytes": 453574,"scriptRequestCount": 7,- "totalRawBytes": 449115+ "totalRawBytes": 453574},- "domContentLoadedMedianMs": 113.5,+ "domContentLoadedMedianMs": 123.40000000596046,"id": "editor-canvas","layoutAckMedianMs": 2.2999999970197678,- "layoutReturnSwitchMedianMs": 53.20000000298023,- "layoutSwitchMedianMs": 93.5,- "loadMedianMs": 113.60000000149012,- "longestTaskMaxMs": 121,+ "layoutReturnSwitchMedianMs": 56.6000000089407,+ "layoutSwitchMedianMs": 97.5,+ "loadMedianMs": 123.5,+ "longestTaskMaxMs": 135,"owner": "canvas","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:canvas",@@ -281,24 +281,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 122,- "scriptRawBytes": 3716162,+ "scriptRawBytes": 3722265,"scriptRequestCount": 117,- "totalRawBytes": 4057720+ "totalRawBytes": 4064742},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 122,- "scriptRawBytes": 3753324,+ "scriptRawBytes": 3759488,"scriptRequestCount": 117,- "totalRawBytes": 4098298+ "totalRawBytes": 4105390},- "routeReadyMedianMs": 1046.2999999970198,+ "routeReadyMedianMs": 1069.7999999970198,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "empty"},@@ -307,31 +307,31 @@"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 286370,+ "largestAssetRawBytes": 290304,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 444668,+ "scriptRawBytes": 449083,"scriptRequestCount": 7,- "totalRawBytes": 444668+ "totalRawBytes": 449083},"activatedResourceLimits": {"cssRawBytes": 0,"fontRawBytes": 0,"imageRawBytes": 0,- "largestAssetRawBytes": 289234,+ "largestAssetRawBytes": 293208,"otherRawBytes": 0,"requestCount": 7,- "scriptRawBytes": 449115,+ "scriptRawBytes": 453574,"scriptRequestCount": 7,- "totalRawBytes": 449115+ "totalRawBytes": 453574},- "domContentLoadedMedianMs": 112.90000000596046,+ "domContentLoadedMedianMs": 122.09999999403954,"id": "editor-canvas",- "layoutAckMedianMs": 2.5,- "layoutReturnSwitchMedianMs": 49.80000000447035,- "layoutSwitchMedianMs": 89.80000000447035,- "loadMedianMs": 113,- "longestTaskMaxMs": 173,+ "layoutAckMedianMs": 2.6000000089406967,+ "layoutReturnSwitchMedianMs": 47.20000000298023,+ "layoutSwitchMedianMs": 80.70000000298023,+ "loadMedianMs": 122.20000000298023,+ "longestTaskMaxMs": 199,"owner": "canvas","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:canvas",@@ -341,24 +341,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 122,- "scriptRawBytes": 3716162,+ "scriptRawBytes": 3722265,"scriptRequestCount": 117,- "totalRawBytes": 4057720+ "totalRawBytes": 4064742},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 122,- "scriptRawBytes": 3753324,+ "scriptRawBytes": 3759488,"scriptRequestCount": 117,- "totalRawBytes": 4098298+ "totalRawBytes": 4105390},- "routeReadyMedianMs": 1124.2999999970198,+ "routeReadyMedianMs": 1165.0999999940395,"scriptSourceOwnerSet": "editor-canvas-static","stateProfile": "representative"},@@ -385,13 +385,13 @@"scriptRequestCount": 6,"totalRawBytes": 383461},- "domContentLoadedMedianMs": 116.39999999850988,+ "domContentLoadedMedianMs": 117.29999999701977,"id": "editor-workflow","layoutAckMedianMs": 2.2000000029802322,- "layoutReturnSwitchMedianMs": 31.700000002980232,- "layoutSwitchMedianMs": 88.79999999701977,- "loadMedianMs": 116.5,- "longestTaskMaxMs": 94,+ "layoutReturnSwitchMedianMs": 34.5,+ "layoutSwitchMedianMs": 92.8999999910593,+ "loadMedianMs": 117.5,+ "longestTaskMaxMs": 101,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -401,24 +401,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 122,- "scriptRawBytes": 3635745,+ "scriptRawBytes": 3637433,"scriptRequestCount": 116,- "totalRawBytes": 3992716+ "totalRawBytes": 3995323},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 122,- "scriptRawBytes": 3672103,+ "scriptRawBytes": 3673808,"scriptRequestCount": 116,- "totalRawBytes": 4032644+ "totalRawBytes": 4035277},- "routeReadyMedianMs": 1043.7999999970198,+ "routeReadyMedianMs": 1056.7000000029802,"scriptSourceOwnerSet": "editor-workflow-static","stateProfile": "empty"},@@ -445,13 +445,13 @@"scriptRequestCount": 6,"totalRawBytes": 383461},- "domContentLoadedMedianMs": 116,+ "domContentLoadedMedianMs": 119.70000000298023,"id": "editor-workflow",- "layoutAckMedianMs": 2.399999998509884,- "layoutReturnSwitchMedianMs": 39.20000000298023,- "layoutSwitchMedianMs": 125.70000000298023,- "loadMedianMs": 116.10000000149012,- "longestTaskMaxMs": 333,+ "layoutAckMedianMs": 2.5999999940395355,+ "layoutReturnSwitchMedianMs": 41,+ "layoutSwitchMedianMs": 123.59999999403954,+ "loadMedianMs": 119.79999999701977,+ "longestTaskMaxMs": 357,"owner": "workflow","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:workflow",@@ -461,24 +461,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 122,- "scriptRawBytes": 3635745,+ "scriptRawBytes": 3637433,"scriptRequestCount": 116,- "totalRawBytes": 3992716+ "totalRawBytes": 3995323},"resourceLimits": {"cssRawBytes": 17748,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 122,- "scriptRawBytes": 3672103,+ "scriptRawBytes": 3673808,"scriptRequestCount": 116,- "totalRawBytes": 4032644+ "totalRawBytes": 4035277},- "routeReadyMedianMs": 1142.3999999985099,+ "routeReadyMedianMs": 1181.0999999940395,"scriptSourceOwnerSet": "editor-workflow-static","stateProfile": "representative"},@@ -505,13 +505,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 113.40000000596046,+ "domContentLoadedMedianMs": 118.79999999701977,"id": "editor-gallery","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,- "layoutSwitchMedianMs": 24.799999997019768,- "loadMedianMs": 113.60000000149012,- "longestTaskMaxMs": 93,+ "layoutSwitchMedianMs": 24.5,+ "loadMedianMs": 118.90000000596046,+ "longestTaskMaxMs": 98,"owner": "gallery","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:gallery",@@ -521,24 +521,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 115,- "scriptRawBytes": 3271494,+ "scriptRawBytes": 3273182,"scriptRequestCount": 110,- "totalRawBytes": 3613052+ "totalRawBytes": 3615659},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 115,- "scriptRawBytes": 3304209,+ "scriptRawBytes": 3305914,"scriptRequestCount": 110,- "totalRawBytes": 3649183+ "totalRawBytes": 3651816},- "routeReadyMedianMs": 1244.5,+ "routeReadyMedianMs": 1277.6000000089407,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "empty"},@@ -565,13 +565,13 @@"scriptRequestCount": 0,"totalRawBytes": 0},- "domContentLoadedMedianMs": 115.40000000596046,+ "domContentLoadedMedianMs": 119.40000000596046,"id": "editor-gallery","layoutAckMedianMs": 0,"layoutReturnSwitchMedianMs": 0,- "layoutSwitchMedianMs": 84.09999999403954,- "loadMedianMs": 115.5,- "longestTaskMaxMs": 171,+ "layoutSwitchMedianMs": 89.5,+ "loadMedianMs": 119.5,+ "longestTaskMaxMs": 178,"owner": "gallery","projectSwitchMedianMs": 0,"readyMark": "invokeai:ready:widget:center:gallery",@@ -581,24 +581,24 @@"fontRawBytes": 23664,"imageRawBytes": 156376,"largestAssetRawBytes": 746376,- "otherRawBytes": 159359,+ "otherRawBytes": 160278,"requestCount": 115,- "scriptRawBytes": 3271494,+ "scriptRawBytes": 3273182,"scriptRequestCount": 110,- "totalRawBytes": 3613052+ "totalRawBytes": 3615659},"resourceLimits": {"cssRawBytes": 2181,"fontRawBytes": 23901,"imageRawBytes": 157940,"largestAssetRawBytes": 753840,- "otherRawBytes": 160953,+ "otherRawBytes": 161881,"requestCount": 115,- "scriptRawBytes": 3304209,+ "scriptRawBytes": 3305914,"scriptRequestCount": 110,- "totalRawBytes": 3649183+ "totalRawBytes": 3651816},- "routeReadyMedianMs": 1416.5999999940395,+ "routeReadyMedianMs": 1460.5,"scriptSourceOwnerSet": "editor-minimal-static","stateProfile": "representative"}diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex cc9b11efa2..915c41d239 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -2860,12 +2860,14 @@"brightness": "Brightness","channel": "Channel","channels": {- "b": "Blue",+ "rgb": "RGB",+ "r": "Red","g": "Green",- "r": "Red"+ "b": "Blue"},"contrast": "Contrast","curves": "Curves",+ "exposure": "Exposure","curvesHint": "Drag points to bend the curve. Double-click empty space to add a point; double-click a point to remove it.","levels": "Levels","inputLevels": "Input levels",diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.tsindex 37d2cb00f0..f9f2c3a2c7 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/contracts.ts@@ -181,6 +181,11 @@ interface CanvasAdjustmentEntryBase {*/export type CanvasAdjustmentEntry =| (CanvasAdjustmentEntryBase & { type: 'brightness-contrast'; brightness: number; contrast: number })+ | (CanvasAdjustmentEntryBase & {+ type: 'exposure';+ /** Photographic stops, −5 to +5, applied in linear light (2^stops). */+ stops: number;+ })| (CanvasAdjustmentEntryBase & {type: 'levels';/** Input remap: 0–255 with `inBlack < inWhite`; `gamma` is the midtone exponent base (1 = linear). */@@ -189,6 +194,8 @@ export type CanvasAdjustmentEntry =gamma: number;outBlack: number;outWhite: number;+ /** Which channels the remap drives; absent ⇒ all three. */+ channel?: 'rgb' | 'r' | 'g' | 'b';})| (CanvasAdjustmentEntryBase & { type: 'curves'; curves: CanvasAdjustmentCurves })| (CanvasAdjustmentEntryBase & { type: 'hsl'; saturation: number })diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/adjustments.test.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/adjustments.test.tsindex bd26959105..8bb2c573d6 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/adjustments.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/adjustments.test.ts@@ -31,6 +31,20 @@ const levels = (overrides: EntryOverrides = {}) =>({ gamma, id: 'lv', inBlack, inWhite, isEnabled: true, outBlack, outWhite, type: 'levels', ...overrides }) as const;+const exposure = (stops: number, overrides: EntryOverrides = {}) =>+ ({ id: 'ex', isEnabled: true, stops, type: 'exposure', ...overrides }) as const;+const channelLevels = (channel: 'rgb' | 'r' | 'g' | 'b', outWhite: number) =>+ ({+ channel,+ gamma: 1,+ id: 'clv',+ inBlack: 0,+ inWhite: 255,+ isEnabled: true,+ outBlack: 0,+ outWhite,+ type: 'levels',+ }) as const;const hue = (rotation: number, overrides: EntryOverrides = {}) =>({ id: 'hue', isEnabled: true, rotation, type: 'hue', ...overrides }) as const;const invert = (overrides: EntryOverrides = {}) =>@@ -176,6 +190,61 @@ describe('compileAdjustments', () => {});});+describe('exposure and channel-scoped levels', () => {+ it('treats zero stops as identity and any channel scope with default values as identity', () => {+ expect(isIdentityAdjustmentEntry(exposure(0))).toBe(true);+ expect(isIdentityAdjustmentEntry(exposure(0.5))).toBe(false);+ expect(isIdentityAdjustmentEntry(channelLevels('r', 255))).toBe(true);+ });++ it('applies exposure in linear light: +1 stop doubles linear energy', () => {+ // srgb 64 → linear ≈0.0513, doubled ≈0.1026 → srgb ≈90; srgb 188 → linear ≈0.503, doubled clamps → 255.+ const img = imageData([64, 188, 0, 255]);+ applyAdjustments(img, [exposure(1)]);+ expect(Math.abs(img.data[0]! - 90)).toBeLessThanOrEqual(1);+ expect(img.data[1]).toBe(255);+ expect(img.data[2]).toBe(0);+ });++ it('darkening by a stop then brightening by a stop returns close to the original midtones', () => {+ const img = imageData([128, 96, 160, 255]);+ applyAdjustments(img, [exposure(-1)]);+ applyAdjustments(img, [exposure(1)]);+ expect(Math.abs(img.data[0]! - 128)).toBeLessThanOrEqual(2);+ expect(Math.abs(img.data[1]! - 96)).toBeLessThanOrEqual(2);+ expect(Math.abs(img.data[2]! - 160)).toBeLessThanOrEqual(2);+ });++ it('a channel-scoped levels entry remaps only its channel', () => {+ const img = imageData([200, 200, 200, 255]);+ applyAdjustments(img, [channelLevels('g', 128)]);+ expect(img.data[0]).toBe(200);+ expect(img.data[1]).toBe(Math.round((200 / 255) * 128));+ expect(img.data[2]).toBe(200);+ });++ it('folds exposure and channel levels with neighbours into one LUT segment, bit-exact vs sequential', () => {+ const folded = compileAdjustments([exposure(0.5), channelLevels('b', 200), invert()]);+ expect(folded.map((segment) => segment.kind)).toEqual(['lut']);++ const sequential = imageData([10, 20, 30, 255, 200, 100, 50, 255]);+ applyAdjustments(sequential, [exposure(0.5)]);+ applyAdjustments(sequential, [channelLevels('b', 200)]);+ applyAdjustments(sequential, [invert()]);+ const combined = imageData([10, 20, 30, 255, 200, 100, 50, 255]);+ applyAdjustments(combined, [exposure(0.5), channelLevels('b', 200), invert()]);+ expect([...combined.data]).toEqual([...sequential.data]);+ });++ it('keys distinguish stops and channel scope but keep unscoped levels keys unchanged', () => {+ expect(adjustmentsKey([exposure(1)])).not.toBe(adjustmentsKey([exposure(2)]));+ expect(adjustmentsKey([levels(10, 240, 1, 0, 255)])).toBe(+ adjustmentsKey([{ ...levels(10, 240, 1, 0, 255), channel: 'rgb' }])+ );+ expect(adjustmentsKey([channelLevels('r', 128)])).not.toBe(adjustmentsKey([channelLevels('g', 128)]));+ });+});+describe('applyAdjustments', () => {it('is a no-op for an identity stack and never modifies alpha', () => {const img = imageData([10, 20, 30, 128]);diff --git a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/adjustments.ts b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/adjustments.tsindex d42ffa81d0..015c69c24b 100644--- a/invokeai/frontend/webv2/src/workbench/canvas-engine/render/adjustments.ts+++ b/invokeai/frontend/webv2/src/workbench/canvas-engine/render/adjustments.ts@@ -123,6 +123,8 @@ export const isIdentityAdjustmentEntry = (entry: CanvasAdjustmentEntry): booleanswitch (entry.type) {case 'brightness-contrast':return entry.brightness === 0 && entry.contrast === 0;+ case 'exposure':+ return entry.stops === 0;case 'levels':return (entry.inBlack === 0 &&@@ -193,6 +195,27 @@ const invertLut = (): Uint8ClampedArray => {return lut;};+const srgbToLinear = (v: number): number => (v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4));+const linearToSrgb = (v: number): number => (v <= 0.0031308 ? v * 12.92 : 1.055 * Math.pow(v, 1 / 2.4) - 0.055);++/** True exposure: 2^stops in linear light, not a gamma-space brightness multiply. */+const exposureLut = (stops: number): Uint8ClampedArray => {+ const factor = Math.pow(2, stops);+ const lut = new Uint8ClampedArray(LUT_SIZE);+ for (let i = 0; i < LUT_SIZE; i++) {+ lut[i] = clamp255(Math.round(linearToSrgb(Math.min(1, srgbToLinear(i / 255) * factor)) * 255));+ }+ return lut;+};++const identityLut = (): Uint8ClampedArray => {+ const lut = new Uint8ClampedArray(LUT_SIZE);+ for (let i = 0; i < LUT_SIZE; i++) {+ lut[i] = i;+ }+ return lut;+};+/** The SVG feColorMatrix `hueRotate` matrix: luminance-preserving rotation around the gray axis. */const hueRotateMatrix = (degrees: number): number[] => {const radians = (degrees * Math.PI) / 180;@@ -221,16 +244,28 @@ const composeLut = (inner: Uint8ClampedArray, outer: Uint8ClampedArray): Uint8Cl};const entryLuts = (- entry: Extract<CanvasAdjustmentEntry, { type: 'brightness-contrast' | 'levels' | 'invert' | 'curves' }>+ entry: Extract<CanvasAdjustmentEntry, { type: 'brightness-contrast' | 'exposure' | 'levels' | 'invert' | 'curves' }>): { r: Uint8ClampedArray; g: Uint8ClampedArray; b: Uint8ClampedArray } => {if (entry.type === 'curves') {return { b: buildCurveLut(entry.curves.b), g: buildCurveLut(entry.curves.g), r: buildCurveLut(entry.curves.r) };}+ if (entry.type === 'levels') {+ const lut = levelsLut(entry);+ const channel = entry.channel ?? 'rgb';+ if (channel === 'rgb') {+ return { b: lut, g: lut, r: lut };+ }+ return {+ b: channel === 'b' ? lut : identityLut(),+ g: channel === 'g' ? lut : identityLut(),+ r: channel === 'r' ? lut : identityLut(),+ };+ }const lut =entry.type === 'brightness-contrast'? brightnessContrastLut(entry.brightness, entry.contrast)- : entry.type === 'levels'- ? levelsLut(entry)+ : entry.type === 'exposure'+ ? exposureLut(entry.stops): invertLut();return { b: lut, g: lut, r: lut };};@@ -283,8 +318,11 @@ export const adjustmentsKey = (adjustments: CanvasAdjustmentsContract | undefineswitch (entry.type) {case 'brightness-contrast':return `bc:${entry.brightness},${entry.contrast}`;+ case 'exposure':+ return `ex:${entry.stops}`;case 'levels':- return `lv:${entry.inBlack},${entry.inWhite},${entry.gamma},${entry.outBlack},${entry.outWhite}`;+ // Unscoped entries keep their pre-`channel` key so caches survive.+ return `lv:${entry.channel && entry.channel !== 'rgb' ? `${entry.channel}:` : ''}${entry.inBlack},${entry.inWhite},${entry.gamma},${entry.outBlack},${entry.outWhite}`;case 'hsl':return `s:${entry.saturation}`;case 'hue':diff --git a/invokeai/frontend/webv2/src/workbench/canvasMigration.test.ts b/invokeai/frontend/webv2/src/workbench/canvasMigration.test.tsindex c2cef28ab3..a811d36d02 100644--- a/invokeai/frontend/webv2/src/workbench/canvasMigration.test.ts+++ b/invokeai/frontend/webv2/src/workbench/canvasMigration.test.ts@@ -122,6 +122,18 @@ describe('loadCanvasState', () => {{ gamma: 1.4, id: 'a4', inBlack: 12, inWhite: 240, isEnabled: true, outBlack: 5, outWhite: 250, type: 'levels' },{ id: 'a5', isEnabled: true, rotation: -45, type: 'hue' },{ id: 'a6', isEnabled: false, type: 'invert' },+ { id: 'a7', isEnabled: true, stops: -1.5, type: 'exposure' },+ {+ channel: 'g',+ gamma: 1,+ id: 'a8',+ inBlack: 0,+ inWhite: 255,+ isEnabled: true,+ outBlack: 0,+ outWhite: 128,+ type: 'levels',+ },];const adjustmentsOf = (loaded: CanvasStateContractV3) => {const layer = loaded.document.stacks.raster[0];diff --git a/invokeai/frontend/webv2/src/workbench/canvasMigration.ts b/invokeai/frontend/webv2/src/workbench/canvasMigration.tsindex 5d63aa1832..84e83c5630 100644--- a/invokeai/frontend/webv2/src/workbench/canvasMigration.ts+++ b/invokeai/frontend/webv2/src/workbench/canvasMigration.ts@@ -92,6 +92,7 @@ const zAdjustmentEntry = z.discriminatedUnion('type', [contrast: zFiniteNumber,type: z.literal('brightness-contrast'),}),+ z.object({ ...zAdjustmentBase, stops: zFiniteNumber, type: z.literal('exposure') }),z.object({ ...zAdjustmentBase, saturation: zFiniteNumber, type: z.literal('hsl') }),z.object({...zAdjustmentBase,@@ -101,6 +102,7 @@ const zAdjustmentEntry = z.discriminatedUnion('type', [z.object({...zAdjustmentBase,+ channel: z.enum(['rgb', 'r', 'g', 'b']).optional(),gamma: zFiniteNumber,inBlack: zFiniteNumber,inWhite: zFiniteNumber,diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/AdjustmentSettings.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/AdjustmentSettings.browser.test.tsxindex 62706e92b8..39eb05547a 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/AdjustmentSettings.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/AdjustmentSettings.browser.test.tsx@@ -174,6 +174,23 @@ describe('hue and levels editors', () => {expect(forward[0]).toEqual(initialEntries()[0]);});+ it('commits a channel scope change as one whole-stack patch keeping the remap values', async () => {+ await render('lv1');+ const trigger = host!.querySelector<HTMLElement>(+ '[aria-label="widgets.layers.adjustments.channel"] [data-part="trigger"], [data-part="trigger"]'+ )!;+ await settle(() => trigger.click());+ const option = [...document.querySelectorAll<HTMLElement>('[data-part="item"]')].find(+ (el) => el.textContent?.trim() === 'widgets.layers.adjustments.channels.r'+ )!;+ expect(option).toBeDefined();+ await settle(() => option.click());++ expect(commits).toHaveLength(1);+ const entry = forwardEntries(commits[0]!)[3] as Extract<CanvasAdjustmentEntry, { type: 'levels' }>;+ expect(entry).toMatchObject({ channel: 'r', gamma: 1, id: 'lv1', inBlack: 0, inWhite: 255 });+ });+it('commits a levels input-range change while the other fields keep their values', async () => {await render('lv1');const tracks = sliderTracks();diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/AdjustmentSettings.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/AdjustmentSettings.tsxindex 07ff07d3be..6fd7e561be 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/AdjustmentSettings.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/AdjustmentSettings.tsx@@ -1,4 +1,4 @@-import type { SliderValueChangeDetails } from '@chakra-ui/react';+import type { SelectValueChangeDetails, SliderValueChangeDetails } from '@chakra-ui/react';import type {CanvasAdjustmentCurves,CanvasAdjustmentEntry,@@ -195,6 +195,20 @@ const AdjustmentEntryEditor = ({/></Stack>);+ case 'exposure':+ return (+ <ScalarSlider+ field="stops"+ formatValue={formatStops}+ label={t('widgets.layers.adjustments.exposure')}+ max={5}+ min={-5}+ step={0.05}+ value={entry.stops}+ onCommit={handleScalarCommit}+ onLive={handleScalarLive}+ />+ );case 'hsl':return (<ScalarSlider@@ -239,7 +253,7 @@ const AdjustmentEntryEditor = ({}};-type ScalarField = 'brightness' | 'contrast' | 'saturation' | 'rotation';+type ScalarField = 'brightness' | 'contrast' | 'saturation' | 'rotation' | 'stops';type LevelsEntry = Extract<CanvasAdjustmentEntry, { type: 'levels' }>;const SCALAR_LABEL_KEYS: Record<ScalarField, string> = {@@ -247,9 +261,13 @@ const SCALAR_LABEL_KEYS: Record<ScalarField, string> = {contrast: 'widgets.layers.adjustments.contrast',rotation: 'widgets.layers.adjustments.hue',saturation: 'widgets.layers.adjustments.saturation',+ stops: 'widgets.layers.adjustments.exposure',};const formatDegrees = (value: number): string => `${Math.round(value)}°`;+const formatStops = (value: number): string => `${value > 0 ? '+' : ''}${value.toFixed(2)} EV`;++const LEVELS_CHANNELS = ['rgb', 'r', 'g', 'b'] as const;const ScalarSlider = ({field,@@ -339,6 +357,27 @@ const LevelsEditor = ({[t]);+ const channelCollection = useMemo(+ () =>+ createListCollection({+ items: LEVELS_CHANNELS.map((channel) => ({+ label: t(`widgets.layers.adjustments.channels.${channel}`),+ value: channel,+ })),+ }),+ [t]+ );+ const channelValue = useMemo(() => [entry.channel ?? 'rgb'], [entry.channel]);+ const handleChannelChange = useCallback(+ ({ value: v }: SelectValueChangeDetails) => {+ const channel = v[0] as LevelsEntry['channel'] | undefined;+ if (channel && channel !== (entry.channel ?? 'rgb')) {+ onCommit({ channel });+ }+ },+ [entry.channel, onCommit]+ );+const rangePatch = useCallback((v: number[], black: 'inBlack' | 'outBlack', white: 'inWhite' | 'outWhite'): Partial<LevelsEntry> | null =>v[0] !== undefined && v[1] !== undefined ? { [black]: v[0], [white]: v[1] } : null,@@ -399,6 +438,17 @@ const LevelsEditor = ({return (<Stack gap="3">+ <Field label={t('widgets.layers.adjustments.channel')}>+ <Select+ aria-label={t('widgets.layers.adjustments.channel')}+ collection={channelCollection}+ positioning={SELECT_POSITIONING}+ size="xs"+ value={channelValue}+ valueText={t(`widgets.layers.adjustments.channels.${entry.channel ?? 'rgb'}`)}+ onValueChange={handleChannelChange}+ />+ </Field><Field label={t('widgets.layers.adjustments.inputLevels')}><Slideraria-label={inputAria}diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildRow.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildRow.tsxindex f2d8cff60e..7a31aa2e80 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildRow.tsx+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayerChildRow.tsx@@ -3,6 +3,7 @@ import type { CSSProperties, FocusEvent, KeyboardEvent, MouseEvent } from 'reactimport { Box, HStack, Icon, Input, Text } from '@chakra-ui/react';import { useDraggable, useDroppable } from '@dnd-kit/core';import {+ ApertureIcon,ContrastIcon,DropletIcon,GaugeIcon,@@ -33,6 +34,7 @@ const stopPropagation = (event: { stopPropagation: () => void }): void => event.const CHILD_ROW_GLYPHS: Record<LayerChildRowKind, LucideIcon> = {'adjustment-brightness-contrast': SunMediumIcon,'adjustment-curves': SplineIcon,+ 'adjustment-exposure': ApertureIcon,'adjustment-hsl': DropletIcon,'adjustment-hue': RainbowIcon,'adjustment-invert': ContrastIcon,diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.test.tsindex 7951cc982b..c99f2671d4 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.test.ts@@ -209,6 +209,18 @@ describe('adjustment rows', () => {},{ id: 'h1', isEnabled: true, rotation: 90, type: 'hue' },{ id: 'i1', isEnabled: false, type: 'invert' },+ { id: 'e1', isEnabled: true, stops: 1.5, type: 'exposure' },+ {+ channel: 'r',+ gamma: 1,+ id: 'l2',+ inBlack: 0,+ inWhite: 255,+ isEnabled: true,+ outBlack: 0,+ outWhite: 200,+ type: 'levels',+ },]),])).vm@@ -217,6 +229,8 @@ describe('adjustment rows', () => {['adjustment-levels', 'l1', true, null],['adjustment-hue', 'h1', true, '90°'],['adjustment-invert', 'i1', false, null],+ ['adjustment-exposure', 'e1', true, '+1.5 EV'],+ ['adjustment-levels', 'l2', true, 'R'],]);});diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.tsindex bd7fd78766..aa07175794 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerChildRows.ts@@ -25,6 +25,7 @@ export type LayerChildRowKind =| 'mask-noise'| 'mask-denoise'| 'adjustment-brightness-contrast'+ | 'adjustment-exposure'| 'adjustment-levels'| 'adjustment-curves'| 'adjustment-hsl'@@ -40,6 +41,7 @@ export const adjustmentChildKind = (type: CanvasAdjustmentEntry['type']): Adjustconst ADJUSTMENT_KIND_OF: Record<CanvasAdjustmentEntry['type'], AdjustmentChildKind> = {'brightness-contrast': 'adjustment-brightness-contrast',curves: 'adjustment-curves',+ exposure: 'adjustment-exposure',hsl: 'adjustment-hsl',hue: 'adjustment-hue',invert: 'adjustment-invert',@@ -49,6 +51,7 @@ const ADJUSTMENT_KIND_OF: Record<CanvasAdjustmentEntry['type'], AdjustmentChildKconst CHILD_ROW_NAME_KEYS: Record<Exclude<LayerChildRowKind, 'reference-image'>, string> = {'adjustment-brightness-contrast': 'widgets.layers.modifiers.brightnessContrast','adjustment-curves': 'widgets.layers.adjustments.curves',+ 'adjustment-exposure': 'widgets.layers.adjustments.exposure','adjustment-hsl': 'widgets.layers.adjustments.saturation','adjustment-hue': 'widgets.layers.adjustments.hue','adjustment-invert': 'widgets.layers.adjustments.invert',@@ -70,8 +73,13 @@ const adjustmentDetail = (entry: CanvasAdjustmentEntry): string | null => {return signedPercent(entry.saturation);case 'hue':return `${Math.round(entry.rotation)}°`;- case 'brightness-contrast':+ case 'exposure': {+ const stops = Number(entry.stops.toFixed(2));+ return `${stops > 0 ? '+' : ''}${stops} EV`;+ }case 'levels':+ return entry.channel && entry.channel !== 'rgb' ? entry.channel.toUpperCase() : null;+ case 'brightness-contrast':case 'curves':case 'invert':return null;@@ -243,6 +251,7 @@ export const layerChildRemoveLabelKey = (kind: LayerChildRowKind): string => {case 'mask-denoise':return 'widgets.layers.modifiers.removeDenoise';case 'adjustment-brightness-contrast':+ case 'adjustment-exposure':case 'adjustment-levels':case 'adjustment-curves':case 'adjustment-hsl':diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.test.tsindex 3624680e7a..976ad1746f 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.test.ts@@ -456,6 +456,7 @@ describe('getLayerContextActions', () => {'transform','fit-to-bbox','add-brightness-contrast',+ 'add-exposure','add-levels','add-curves','add-hsl',@@ -540,6 +541,7 @@ describe('getLayerContextActions', () => {for (const id of ['fit-to-bbox','add-brightness-contrast',+ 'add-exposure','add-levels','add-curves','add-hsl',diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.tsindex 5c3d9dcb01..1480c7fe40 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextActions.ts@@ -16,6 +16,7 @@ import {lookupLayerBelow,} from '@workbench/canvas-engine/api';import {+ ApertureIcon,ArrowDownIcon,ArrowDownToLineIcon,ArrowUpIcon,@@ -55,6 +56,7 @@ export type LayerContextActionId =| 'add-noise'| 'add-denoise-limit'| 'add-brightness-contrast'+ | 'add-exposure'| 'add-levels'| 'add-curves'| 'add-hsl'@@ -434,6 +436,19 @@ export const LAYER_CONTEXT_ACTION_DEFINITIONS: readonly LayerContextActionDefinisubmenu: 'add-adjustment',supportedLayerTypes: RASTER_ONLY,},+ {+ defaultLabel: 'Exposure',+ handler: ({ effects }) => effects.addAdjustment('exposure'),+ icon: ApertureIcon,+ id: 'add-exposure',+ isEnabled: isLayerMutable,+ isVisible: alwaysVisible,+ labelKey: 'widgets.layers.adjustments.exposure',+ order: 31.05,+ section: 'primary',+ submenu: 'add-adjustment',+ supportedLayerTypes: RASTER_ONLY,+ },{defaultLabel: 'Levels',handler: ({ effects }) => effects.addAdjustment('levels'),diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextMenuLayout.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextMenuLayout.test.tsindex 16bf46b0a5..d91a4eec7c 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextMenuLayout.test.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerContextMenuLayout.test.ts@@ -87,7 +87,7 @@ describe('getLayerContextMenuLayout', () => {'transform','rename','fit-to-bbox',- 'add-adjustment(add-brightness-contrast,add-levels,add-curves,add-hsl,add-hue,add-invert)',+ 'add-adjustment(add-brightness-contrast,add-exposure,add-levels,add-curves,add-hsl,add-hue,add-invert)','filter','select-object','run-workflow',diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerOps.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerOps.tsindex 65a76db532..bace519070 100644--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/layerOps.ts+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/layerOps.ts@@ -259,6 +259,8 @@ export const createIdentityAdjustment = (type: CanvasAdjustmentEntry['type']): Cswitch (type) {case 'brightness-contrast':return { brightness: 0, contrast: 0, id, isEnabled: true, type };+ case 'exposure':+ return { id, isEnabled: true, stops: 0, type };case 'levels':return { gamma: 1, id, inBlack: 0, inWhite: 255, isEnabled: true, outBlack: 0, outWhite: 255, type };case 'curves':