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
fix(canvas): apply color compensation when encoding images (#10178)
Josh Corbett94bd87706c89
diff --git a/docs/src/content/docs/Users Guide/03.Models/Local Models/sdxl.mdx b/docs/src/content/docs/Users Guide/03.Models/Local Models/sdxl.mdxindex d001941f18..31e562e42e 100644--- a/docs/src/content/docs/Users Guide/03.Models/Local Models/sdxl.mdx+++ b/docs/src/content/docs/Users Guide/03.Models/Local Models/sdxl.mdx@@ -95,8 +95,8 @@ Model Manager's **Default Settings**:The **Advanced** section of the Generate panel adds these controls for SDXL:- **VAE** and **VAE Precision** — see [VAE](#vae).-- **Color Compensation** — adjusts the input image to reduce color shifts during inpainting and- image-to-image. This control is available only for SDXL.+- **Color Compensation** — adjusts the input image to reduce color shifts during inpainting,+ outpainting, and image-to-image. This control is available only for SDXL.- **Seamless Tiling** — generates images that tile without visible seams, on the X axis, Y axis or both.- **HiDiffusion** — improves structure at higher resolutions (it is most noticeable at 1536px andabove). See [HiDiffusion](/users-guide/image-generation/advanced-topics/hidiffusion/).diff --git a/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.jsonindex 45480dc2eb..d0dd15fceb 100644--- a/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json+++ b/invokeai/frontend/webv2/src/features/generation/core/__snapshots__/generateGraphNodeTypes.json@@ -46,12 +46,15 @@"componentsFilled": {"diffusers": [],"standalone-components": [],- "diffusers-with-refiner": []+ "diffusers-with-refiner": [],+ "canvas-img2img-uncompensated": [],+ "canvas-img2img-compensated": []},"nodeTypes": ["collect","core_metadata","denoise_latents",+ "i2l","img_nsfw","img_watermark","integer",@@ -695,6 +698,7 @@"qwen_image_2_1_txt2img","qwen_image_txt2img","sd3_txt2img",+ "sdxl_img2img","sdxl_txt2img","txt2img","wan_txt2img",@@ -825,6 +829,9 @@8,9],+ "strength": [+ 0.6+ ],"t5_encoder": [],"use_cache": [true@@ -880,6 +887,7 @@],"denoising_start": [0,+ 0.4,0.8],"hidiffusion": [@@ -1411,6 +1419,30 @@"conditioning"]},+ "i2l": {+ "inputs": [+ "vae"+ ],+ "literalInputs": {+ "color_compensation": [+ "None",+ "SDXL"+ ],+ "fp32": [+ true+ ],+ "image": [],+ "is_intermediate": [+ true+ ],+ "use_cache": [+ true+ ]+ },+ "outputs": [+ "latents"+ ]+ },"ideogram4_caption_builder": {"inputs": ["prompt"@@ -1730,9 +1762,6 @@"vae"],"literalInputs": {- "color_compensation": [- "None"- ],"fp32": [true],diff --git a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.tsindex d48fe6ba52..ae0167371a 100644--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.test.ts@@ -387,6 +387,18 @@ describe('compileCanvasGraph', () => {});});+ describe.each(['img2img', 'inpaint', 'outpaint'] as const)('SDXL %s color compensation', (mode) => {+ it.each([+ { colorCompensation: true, expected: 'SDXL' },+ { colorCompensation: false, expected: 'None' },+ ])('sets $expected on the encoder when enabled=$colorCompensation', ({ colorCompensation, expected }) => {+ const { backendGraph } = compile(sdxlModel, mode, { settings: { colorCompensation } });++ expect(getNodeByType(backendGraph, 'i2l')).toMatchObject({ color_compensation: expected, fp32: true });+ expect(getNodeByType(backendGraph, 'l2i')).not.toHaveProperty('color_compensation');+ });+ });+describe('img2img per base', () => {it.each(BASE_CASES)('grafts a $model.base image-to-latents encode node',@@ -442,11 +454,16 @@ describe('compileCanvasGraph', () => {expect(getNodeByType(fp32.backendGraph, 'i2l')?.fp32).toBe(true);});- it('does not attach fp32 to non-SD encode nodes', () => {- const { backendGraph } = compile(fluxModel, 'img2img');+ it.each(BASE_CASES.filter(({ encodeType }) => encodeType !== 'i2l'))(+ 'does not attach SD-only VAE settings to $model.base encode nodes',+ ({ model, encodeType }) => {+ const { backendGraph } = compile(model, 'img2img', { settings: { colorCompensation: true } });+ const encode = getNodeByType(backendGraph, encodeType);- expect(getNodeByType(backendGraph, 'flux_vae_encode')?.fp32).toBeUndefined();- });+ expect(encode).not.toHaveProperty('fp32');+ expect(encode).not.toHaveProperty('color_compensation');+ }+ );it('threads the composite image name into the encode node', () => {const { backendGraph } = compile(sdxlModel, 'img2img', { compositeImageName: 'my-upload.png' });diff --git a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.ts b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.tsindex 9b35041f16..f7a8056529 100644--- a/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/canvas/compileCanvasGraph.ts@@ -390,7 +390,7 @@ const setMetadataMode = (graph: BackendGraphContract, mode: string, strength: nu}};-/** The SD `i2l` node carries fp32; every other family's encode node does not. */+/** Only the SD `i2l` node supports precision and color compensation settings. */const isSdI2l = (i2lType: string): boolean => i2lType === 'i2l';/** Adds the base-appropriate image-to-latents encode node fed by `imageName`. */@@ -404,7 +404,12 @@ const addEncodeNode = (id: 'canvas_i2l',...(imageName ? { image: { image_name: imageName } } : {}),type: i2lType,- ...(isSdI2l(i2lType) ? { fp32: settings.vaePrecision === 'fp32' } : {}),+ ...(isSdI2l(i2lType)+ ? {+ color_compensation: settings.colorCompensation ? 'SDXL' : 'None',+ fp32: settings.vaePrecision === 'fp32',+ }+ : {}),});const addInputResizeNode = (diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.test.tsindex 2841282d40..50b70f2728 100644--- a/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.test.ts@@ -212,7 +212,7 @@ describe('compileGenerateGraph', () => {expect(getEdge(graph, 'denoise_latents', 'unet')?.source.node_id).toBe('model_loader');expect(getEdge(graph, 'canvas_output', 'vae')?.source.node_id).toBe('model_loader');expect(graph.nodes.canvas_output?.fp32).toBe(true);- expect(graph.nodes.canvas_output?.color_compensation).toBe('None');+ expect(graph.nodes.canvas_output).not.toHaveProperty('color_compensation');});it('records the accelerator supplied by the orchestration boundary in metadata', () => {@@ -227,10 +227,11 @@ describe('compileGenerateGraph', () => {expect(getNodeByType(graph, 'core_metadata')?.rand_device).toBe('xpu');});- it('passes SDXL color compensation to the VAE decode node when enabled', () => {- const graph = compile(sdxlModel, { colorCompensation: true });+ it.each([true, false])('omits encoder-only color compensation from SDXL txt2img when enabled=%s', (enabled) => {+ const graph = compile(sdxlModel, { colorCompensation: enabled });- expect(graph.nodes.canvas_output?.color_compensation).toBe('SDXL');+ expect(getNodeByType(graph, 'i2l')).toBeUndefined();+ expect(graph.nodes.canvas_output).not.toHaveProperty('color_compensation');});it('coerces invalid SD schedulers before graph submission', () => {diff --git a/invokeai/frontend/webv2/src/features/generation/core/graph.ts b/invokeai/frontend/webv2/src/features/generation/core/graph.tsindex 77375d9c79..1c2810612e 100644--- a/invokeai/frontend/webv2/src/features/generation/core/graph.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/graph.ts@@ -331,7 +331,6 @@ const buildSDGraph = (const compelType = getCompelPromptNodeType(model.base);const activeLoras = getActiveCompatibleLoras(settings, model);const scheduler = coerceSchedulerForGraph(model, settings.scheduler);- const colorCompensation = settings.colorCompensation ? 'SDXL' : 'None';const supportsHiDiffusion = model.base === 'sd-1' || model.base === 'sdxl';const positivePrompt = addNode(graph, { id: 'positive_prompt', type: 'string' });@@ -452,7 +451,7 @@ const buildSDGraph = (const output = addDecodeOutput({denoise: refinerDenoise ?? denoise,graph,- l2iProps: { color_compensation: colorCompensation, fp32: settings.vaePrecision === 'fp32' },+ l2iProps: { fp32: settings.vaePrecision === 'fp32' },l2iType: 'l2i',model,outputIsIntermediate,diff --git a/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.test.ts b/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.test.tsindex d368f5fb29..f0d20ef7d7 100644--- a/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.test.ts+++ b/invokeai/frontend/webv2/src/features/generation/core/graphCoverage.test.ts@@ -16,6 +16,7 @@ import {SUPPORTED_GENERATE_BASES,withAddedReferenceImages,} from './baseGenerationPolicies';+import { compileCanvasGraph } from './canvas/compileCanvasGraph';import { compileGenerateGraph, GRAPH_BUILDERS } from './graph';import {buildContext,@@ -97,6 +98,38 @@ const refinerCase = () => {};};+// Canvas owns image encoding; both toggle values must reach the backend-validated literal contract.+const sdxlCanvasCase = (colorCompensation: boolean) => {+ const shape: ModelShape = {+ label: `canvas-img2img-${colorCompensation ? 'compensated' : 'uncompensated'}`,+ overrides: { format: 'diffusers' },+ };+ const { filled, model, settings } = satisfiedSettingsFor('sdxl', shape);+ const { backendGraph: graph } = compileCanvasGraph({+ bbox: { height: 1024, width: 1024, x: 0, y: 0 },+ compositeImageName: 'canvas-input.png',+ compositing: {+ coherenceEdgeSize: 16,+ coherenceMinDenoise: 0,+ coherenceMode: 'Gaussian Blur',+ infillColorValue: { a: 1, b: 0, g: 0, r: 0 },+ infillMethod: 'lama',+ infillPatchmatchDownscaleSize: 1,+ infillTileSize: 32,+ maskBlur: 16,+ outputOnlyMaskedRegions: false,+ },+ destination: 'canvas',+ mode: 'img2img',+ model,+ projectSettings: { useCpuNoise: true, useNsfwChecker: false, useWatermark: false },+ settings: { ...settings, colorCompensation },+ strength: 0.6,+ });++ return { base: 'sdxl' as const, filled, graph, shape };+};+// Edit references replace the style reference the tuned Krea-2 recipe carries, so they need their own case.const krea2EditCase = () => {const { filled, model, settings } = satisfiedSettingsFor('krea-2', KREA2_EDIT_SHAPE);@@ -299,6 +332,8 @@ describe('generate graph coverage', () => {[false, true].map((tuned) => ({ base, shape, ...compileForShape(base, shape, tuned) }))),refinerCase(),+ sdxlCanvasCase(false),+ sdxlCanvasCase(true),krea2EditCase(),];diff --git a/tests/app/invocations/test_frontend_graph_node_types.py b/tests/app/invocations/test_frontend_graph_node_types.pyindex 8e6e84aac2..e87c8e1187 100644--- a/tests/app/invocations/test_frontend_graph_node_types.py+++ b/tests/app/invocations/test_frontend_graph_node_types.py@@ -180,13 +180,6 @@ def _annotation(cls: type[BaseInvocation], field_name: str) -> Any:SILENTLY_IGNORED: dict[str, dict[str, set[str]]] = {"generate": {- # `color_compensation` is a field of `i2l`, the *encode* node — legacy web sets it only- # there, on the img2img/inpaint/outpaint paths. webv2 writes it onto the `l2i` decode node- # instead (`graph.ts`, `l2iProps`), where no such field exists, so the Generate tab's SDXL- # colour-compensation toggle changes nothing about the generated image. Invocations ignore- # extra fields rather than rejecting them, which is why this never surfaced as an enqueue- # error.- "l2i": {"color_compensation"},# `flux_ip_adapter` has no `method`: the FLUX adapter applies the whole image. webv2 shares# the SD reference-image card with FLUX, so its Full/Style/Composition mode is offered there# and sent, and changes nothing.