Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(create): local Enhance takes any size and a chosen upscale model

purple53e43f24b010
diff --git a/src/components/create/experimental/Composer.tsx b/src/components/create/experimental/Composer.tsx
index 3cdc41f9..3ef4fc8f 100644
--- a/src/components/create/experimental/Composer.tsx
+++ b/src/components/create/experimental/Composer.tsx
@@ -25,7 +25,8 @@ import { subscribeInstallRuns, getInstallRun } from '../../../lib/model-install-
import { useWorkflowStore, shouldShowManagerNotice } from '../../../stores/workflowStore'
import { isInputHint, missingSourceHint, noPromptHint, shouldShowLaneHint } from './laneHint'
import { stageShowsSetupCard, laneModelCount } from './stageGate'
-import { localUpscaleReady, normalizeUpscaleFactor } from '../../../lib/local-upscale'
+import { localUpscaleReady } from '../../../lib/local-upscale'
+import { UpscaleSizeControls } from './UpscaleSizeControls'
import { frameRangeFor, framesOnRange } from '../../../lib/video-length'
import { needsMaskFor } from './maskGate'
import { ModelChip } from './ModelChip'
@@ -83,8 +84,6 @@ export function Composer({ onOpenAdvanced, onOpenWorkflows }: Props) {
const trainKind = useCreateStore((s) => s.trainKind)
const targetResolution = useCreateStore((s) => s.targetResolution)
const setTargetResolution = useCreateStore((s) => s.setTargetResolution)
- const upscaleFactor = useCreateStore((s) => s.upscaleFactor)
- const setUpscaleFactor = useCreateStore((s) => s.setUpscaleFactor)
const upscaleModelCount = useCreateStore((s) => s.upscaleModelList.length)
// Enhance Image on a Mac runs SeedVR2, which takes a factor and nothing
// else from Create (commands/mlx.rs mlx_upscale).
@@ -527,20 +526,7 @@ export function Composer({ onOpenAdvanced, onOpenWorkflows }: Props) {
{studioPick && studioPrice?.error && (
<span className="t-control text-red-300">{studioPrice.error}</span>
)}
- {meta.id === 'upscale' && backend === 'local' && !macUpscale && (
- <Tooltip content="How much larger the result is, per side.">
- <div>
- <Segmented
- size="sm"
- layoutId="upscale-factor"
- ariaLabel="Upscale factor"
- value={String(normalizeUpscaleFactor(upscaleFactor))}
- onChange={(v) => setUpscaleFactor(normalizeUpscaleFactor(Number(v)))}
- options={[{ value: '2', label: '2x' }, { value: '4', label: '4x' }]}
- />
- </div>
- </Tooltip>
- )}
+ {meta.id === 'upscale' && backend === 'local' && !macUpscale && <UpscaleSizeControls />}
{meta.id === 'upscale' && macUpscale && (
<Tooltip content="How much larger the picture gets. Up to 4096 pixels on the longest side.">
<div>
diff --git a/src/components/create/experimental/UpscaleSizeControls.tsx b/src/components/create/experimental/UpscaleSizeControls.tsx
new file mode 100644
index 00000000..0b115d19
--- /dev/null
+++ b/src/components/create/experimental/UpscaleSizeControls.tsx
@@ -0,0 +1,121 @@
+import { useState } from 'react'
+import { useCreateStore } from '../../../stores/createStore'
+import {
+ UPSCALE_FACTORS, UPSCALE_FACTOR_MAX, UPSCALE_FACTOR_MIN, UPSCALE_LONG_SIDES, UPSCALE_MAX_SIDE,
+ nativeUpscaleScale, normalizeUpscaleFactor, pickUpscaleModel, upscaleToolLabel,
+} from '../../../lib/local-upscale'
+import { commitNumber } from '../ui/NumberField'
+import { Select, type SelectOption } from '../ui/Select'
+import { Tooltip } from '../ui/Tooltip'
+
+const CUSTOM_FACTOR = 'custom-factor'
+const CUSTOM_LONG = 'custom-long'
+const AUTO = 'auto'
+const longLabel = (px: number) => px === 3840 ? '3840 px (4K)' : px === 7680 ? '7680 px (8K)' : px === 2048 ? '2048 px (2K)' : `${px} px`
+
+/**
+ * Enhance Image on local ComfyUI: the size of the result and the model that
+ * makes it. Discord 08.11.2026: "only x2 and x4, no advanced
+ * settings". The size is a factor from 1x to 8x or a target long side in
+ * pixels, the model any file in models/upscale_models. Above the model's own
+ * scale the rest is a plain resize (buildUpscaleWorkflow), and the menu says
+ * the model's scale so that is no surprise.
+ */
+export function UpscaleSizeControls() {
+ const factor = useCreateStore((s) => s.upscaleFactor)
+ const longSide = useCreateStore((s) => s.upscaleLongSide)
+ const setFactor = useCreateStore((s) => s.setUpscaleFactor)
+ const setLongSide = useCreateStore((s) => s.setUpscaleLongSide)
+ const models = useCreateStore((s) => s.upscaleModelList)
+ const picked = useCreateStore((s) => s.upscaleModelPick)
+ const setPicked = useCreateStore((s) => s.setUpscaleModelPick)
+ const [custom, setCustom] = useState<null | 'factor' | 'long'>(null)
+
+ const f = normalizeUpscaleFactor(factor)
+ const sizeValue = custom === 'factor' ? CUSTOM_FACTOR
+ : custom === 'long' ? CUSTOM_LONG
+ : longSide ? (UPSCALE_LONG_SIDES.includes(longSide) ? `long:${longSide}` : CUSTOM_LONG)
+ : UPSCALE_FACTORS.includes(f) ? `x:${f}` : CUSTOM_FACTOR
+ const sizeOptions: SelectOption[] = [
+ ...UPSCALE_FACTORS.map((x) => ({ value: `x:${x}`, label: `${x}x`, group: 'Factor' })),
+ { value: CUSTOM_FACTOR, label: sizeValue === CUSTOM_FACTOR && !custom ? `${f}x` : 'Other factor…', group: 'Factor' },
+ ...UPSCALE_LONG_SIDES.map((px) => ({ value: `long:${px}`, label: longLabel(px), group: 'Long side' })),
+ { value: CUSTOM_LONG, label: sizeValue === CUSTOM_LONG && !custom && longSide ? `${longSide} px` : 'Other long side…', group: 'Long side' },
+ ]
+ const onSize = (v: string) => {
+ if (v === CUSTOM_FACTOR) { setCustom('factor'); return }
+ if (v === CUSTOM_LONG) { setCustom('long'); if (!longSide) setLongSide(3840); return }
+ setCustom(null)
+ if (v.startsWith('x:')) setFactor(Number(v.slice(2)))
+ else setLongSide(Number(v.slice(5)))
+ }
+
+ const inUse = pickUpscaleModel(models, picked)
+ const modelOptions: SelectOption[] = [
+ { value: AUTO, label: inUse ? `Auto: ${upscaleToolLabel(inUse)}` : 'Auto' },
+ ...models.map((m) => {
+ const native = nativeUpscaleScale(m)
+ return { value: m, label: upscaleToolLabel(m), title: m, ...(native ? { tags: [{ label: `${native}x`, tone: 'quiet' as const }] } : {}) }
+ }),
+ ]
+
+ return (
+ <>
+ <Tooltip content="How large the result is: a factor per side, or the length of its longest side. Past the model's own scale (its 2x or 4x) the rest is a plain resize.">
+ <div className="w-28">
+ <Select size="sm" ariaLabel="Upscale size" options={sizeOptions} value={sizeValue} onChange={onSize} />
+ </div>
+ </Tooltip>
+ {(custom === 'factor' || (sizeValue === CUSTOM_FACTOR && !custom)) && (
+ <InlineNumber
+ ariaLabel="Upscale factor" suffix="x" value={f} min={UPSCALE_FACTOR_MIN} max={UPSCALE_FACTOR_MAX} step={0.05}
+ onCommit={(v) => { setFactor(v); setCustom(null) }}
+ />
+ )}
+ {(custom === 'long' || (sizeValue === CUSTOM_LONG && !custom)) && (
+ <InlineNumber
+ ariaLabel="Upscale long side" suffix="px" value={longSide ?? 3840} min={256} max={UPSCALE_MAX_SIDE} step={1}
+ onCommit={(v) => { setLongSide(v); setCustom(null) }}
+ />
+ )}
+ {models.length > 1 && (
+ <Tooltip content="The upscale model from ComfyUI's models/upscale_models. Auto takes RealESRGAN x4plus when it is there.">
+ <div className="w-40">
+ <Select
+ size="sm" ariaLabel="Upscale model" align="right" options={modelOptions}
+ value={picked && models.includes(picked) ? picked : AUTO}
+ onChange={(v) => setPicked(v === AUTO ? null : v)}
+ />
+ </div>
+ </Tooltip>
+ )}
+ </>
+ )
+}
+
+/** A small number box for the toolbar: what is typed is applied on Enter or
+ * when the box is left, inside its bounds. */
+function InlineNumber({ ariaLabel, suffix, value, min, max, step, onCommit }: {
+ ariaLabel: string; suffix: string; value: number; min: number; max: number; step: number; onCommit: (v: number) => void
+}) {
+ const [draft, setDraft] = useState<string | null>(null)
+ const commit = () => {
+ if (draft === null) return
+ const v = parseFloat(draft.replace(',', '.'))
+ setDraft(null)
+ if (!Number.isNaN(v)) onCommit(commitNumber(v, min, max, step))
+ }
+ return (
+ <div className="flex items-center h-7 px-2 rounded-[var(--radius-control)] bg-white/[0.04] border border-white/[0.08] focus-within:border-white/20">
+ <input
+ type="text" inputMode="decimal" aria-label={ariaLabel}
+ value={draft ?? String(value)}
+ onChange={(e) => setDraft(e.target.value)}
+ onBlur={commit}
+ onKeyDown={(e) => { if (e.key === 'Enter') commit() }}
+ className="bg-transparent outline-none w-14 t-control text-gray-200 lu-hud-num text-right"
+ />
+ <span className="t-mono text-gray-600 pl-1">{suffix}</span>
+ </div>
+ )
+}
diff --git a/src/components/create/experimental/__tests__/local-enhance-composer.test.tsx b/src/components/create/experimental/__tests__/local-enhance-composer.test.tsx
index ec0fa745..0da8cc73 100644
--- a/src/components/create/experimental/__tests__/local-enhance-composer.test.tsx
+++ b/src/components/create/experimental/__tests__/local-enhance-composer.test.tsx
@@ -1,8 +1,9 @@
// @vitest-environment jsdom
/**
- * Local Enhance Image (3.0.7) in the Composer: a 2x/4x choice instead of the
- * cloud's target resolution, no prompt field, no model picker, and a Create
- * button that waits for the source and for an upscale model.
+ * Local Enhance Image (3.0.7) in the Composer: a size menu instead of the
+ * cloud's target resolution (2x/4x until 3.1.0, see
+ * upscale-groesse-und-modell.test.tsx), no prompt field, no image model
+ * picker, and a Create button that waits for the source and an upscale model.
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { render, cleanup, screen, fireEvent } from '@testing-library/react'
@@ -39,13 +40,13 @@ beforeEach(() => {
afterEach(cleanup)
describe('the local Enhance composer', () => {
- it('offers 2x and 4x, 2x picked, and not the cloud target resolution', () => {
+ it('offers a size, 2x picked, and not the cloud target resolution', () => {
composer()
- const group = screen.getByRole('radiogroup', { name: 'Upscale factor' })
- expect(group.textContent).toBe('2x4x')
+ expect(screen.getByRole('button', { name: 'Upscale size' }).textContent).toContain('2x')
expect(screen.queryByText('8K')).toBeNull()
- expect(screen.getByRole('radio', { name: '2x' }).getAttribute('aria-checked')).toBe('true')
- fireEvent.click(screen.getByRole('radio', { name: '4x' }))
+ expect(screen.queryByRole('radiogroup', { name: 'Upscale factor' })).toBeNull()
+ fireEvent.click(screen.getByRole('button', { name: 'Upscale size' }))
+ fireEvent.click(screen.getByRole('option', { name: /^4x/ }))
expect(useCreateStore.getState().upscaleFactor).toBe(4)
})
diff --git a/src/components/create/experimental/__tests__/upscale-groesse-und-modell.test.tsx b/src/components/create/experimental/__tests__/upscale-groesse-und-modell.test.tsx
new file mode 100644
index 00000000..1a7567dd
--- /dev/null
+++ b/src/components/create/experimental/__tests__/upscale-groesse-und-modell.test.tsx
@@ -0,0 +1,149 @@
+// @vitest-environment jsdom
+/**
+ * 3.1.0, Discord 08.11.: "Enhance only does x2 and x4, no
+ * advanced settings". Local Enhance on ComfyUI now takes any factor from 1x
+ * to 8x or a target long side, and the upscale model from
+ * models/upscale_models. The real run is in useCreate-local-upscale.test.ts.
+ *
+ * Run: npx vitest run src/components/create/experimental/__tests__/upscale-groesse-und-modell.test.tsx
+ */
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
+import { render, cleanup, screen, fireEvent } from '@testing-library/react'
+
+vi.mock('../CreateContext', () => ({
+ useCreateExp: () => ({
+ generate: vi.fn(), cancel: vi.fn(), makeVoice: vi.fn(), quota: null,
+ samplerList: [], schedulerList: [], loraList: [], vaeList: [], refreshModelLists: vi.fn(),
+ connected: true, modelsLoaded: true, modelLoadError: null, mlxMissing: null,
+ installCapability: vi.fn(), installModelBundle: vi.fn(),
+ }),
+}))
+vi.mock('../../../../api/mlx-image', () => ({ isMlxImageHost: () => false }))
+
+import { Composer } from '../Composer'
+import { useCreateStore } from '../../../../stores/createStore'
+import { buildUpscaleWorkflow } from '../../../../api/dynamic-workflow'
+import {
+ normalizeUpscaleLongSide, pickUpscaleModel, upscaleFactorFor, upscaleSizeLabel, upscaleTooLargeLine,
+} from '../../../../lib/local-upscale'
+
+const X4 = 'RealESRGAN_x4plus.safetensors'
+const X2 = '2x-AnimeSharp.pth'
+const composer = () => render(<Composer onOpenAdvanced={() => {}} onOpenWorkflows={() => {}} />)
+const openSize = () => fireEvent.click(screen.getByRole('button', { name: 'Upscale size' }))
+const st = () => useCreateStore.getState()
+
+beforeEach(() => {
+ useCreateStore.setState({
+ backend: 'local', isGenerating: false, error: null, gallery: [], source: null,
+ upscaleFactor: 2, upscaleLongSide: null, upscaleModelPick: null, upscaleModelList: [X4],
+ } as never)
+ st().setIntent('upscale')
+})
+afterEach(cleanup)
+
+describe('the size menu', () => {
+ it('lists factors and long sides, not only 2x and 4x', () => {
+ composer()
+ openSize()
+ const rows = screen.getAllByRole('option').map((o) => o.textContent)
+ for (const want of ['1.5x', '2x', '3x', '4x', 'Other factor…', '2048 px (2K)', '3840 px (4K)', '7680 px (8K)', 'Other long side…']) {
+ expect(rows.some((r) => r?.startsWith(want))).toBe(true)
+ }
+ })
+
+ it('3x and a long side are kept, a long side replaces the factor and back', () => {
+ composer()
+ openSize()
+ fireEvent.click(screen.getByRole('option', { name: /^3x/ }))
+ expect(st().upscaleFactor).toBe(3)
+ openSize()
+ fireEvent.click(screen.getByRole('option', { name: /^3840 px/ }))
+ expect(st().upscaleLongSide).toBe(3840)
+ expect(screen.getByRole('button', { name: 'Upscale size' }).textContent).toContain('3840 px')
+ openSize()
+ fireEvent.click(screen.getByRole('option', { name: /^2x/ }))
+ expect([st().upscaleFactor, st().upscaleLongSide]).toEqual([2, null])
+ })
+
+ it('another factor is typed, and kept inside 1x to 8x', () => {
+ composer()
+ openSize()
+ fireEvent.click(screen.getByRole('option', { name: 'Other factor…' }))
+ const field = screen.getByRole('textbox', { name: 'Upscale factor' })
+ fireEvent.change(field, { target: { value: '2,5' } })
+ fireEvent.keyDown(field, { key: 'Enter' })
+ expect(st().upscaleFactor).toBe(2.5)
+ expect(screen.getByRole('button', { name: 'Upscale size' }).textContent).toContain('2.5x')
+ fireEvent.change(screen.getByRole('textbox', { name: 'Upscale factor' }), { target: { value: '12' } })
+ fireEvent.blur(screen.getByRole('textbox', { name: 'Upscale factor' }))
+ expect(st().upscaleFactor).toBe(8)
+ })
+
+ it('another long side is typed in pixels', () => {
+ composer()
+ openSize()
+ fireEvent.click(screen.getByRole('option', { name: 'Other long side…' }))
+ const field = screen.getByRole('textbox', { name: 'Upscale long side' })
+ fireEvent.change(field, { target: { value: '5000' } })
+ fireEvent.keyDown(field, { key: 'Enter' })
+ expect(st().upscaleLongSide).toBe(5000)
+ })
+})
+
+describe('the model menu', () => {
+ it('only one model: no menu, it is simply used', () => {
+ composer()
+ expect(screen.queryByRole('button', { name: 'Upscale model' })).toBeNull()
+ })
+
+ it('several: Auto names what it takes, a pick is saved, Auto clears it', () => {
+ useCreateStore.setState({ upscaleModelList: [X4, X2] } as never)
+ composer()
+ const menu = () => screen.getByRole('button', { name: 'Upscale model' })
+ expect(menu().textContent).toContain('Auto: RealESRGAN_x4plus')
+ fireEvent.click(menu())
+ fireEvent.click(screen.getByRole('option', { name: /^2x-AnimeSharp/ }))
+ expect(st().upscaleModelPick).toBe(X2)
+ fireEvent.click(menu())
+ fireEvent.click(screen.getByRole('option', { name: /^Auto/ }))
+ expect(st().upscaleModelPick).toBeNull()
+ })
+})
+
+describe('the rules', () => {
+ it('a long side becomes the factor of this picture, exactly', () => {
+ expect(upscaleFactorFor(1920, 1080, 2, 3840)).toBe(2)
+ expect(upscaleFactorFor(640, 480, 2, 1920)).toBe(3)
+ expect(upscaleFactorFor(640, 480, 2.5, null)).toBe(2.5)
+ expect([upscaleSizeLabel(1.5, null), upscaleSizeLabel(2, 3840)]).toEqual(['1.5x', '3840 px'])
+ expect([normalizeUpscaleLongSide(9000), normalizeUpscaleLongSide(10), normalizeUpscaleLongSide('x')]).toEqual([8192, 256, null])
+ })
+
+ it('a long side that does not enlarge is refused; the same size is allowed (a 1x restoration model)', () => {
+ expect(upscaleTooLargeLine(4000, 3000, 3840 / 4000, '3840 px')).toMatch(/already 4000×3000, larger than 3840 px/)
+ expect(upscaleTooLargeLine(4000, 3000, 1, '4000 px')).toBeNull()
+ })
+
+ it('a picked model counts only while ComfyUI still lists it', () => {
+ expect(pickUpscaleModel([X4, X2], X2)).toBe(X2)
+ expect(pickUpscaleModel([X4], X2)).toBe(X4)
+ })
+
+ it('past the model scale the rest is a resize: 8x on a 4x model, 1.5x on a 2x model', () => {
+ const methods = ['nearest-exact', 'bilinear', 'area', 'bicubic', 'lanczos']
+ const nodes = (m: string) => ({
+ LoadImage: {}, ImageUpscaleWithModel: {}, SaveImage: {},
+ UpscaleModelLoader: { input: { required: { model_name: [[m]] } } },
+ ImageScaleBy: { input: { required: { upscale_method: [methods] } } },
+ ImageScale: { input: { required: { upscale_method: [methods] } } },
+ })
+ const scaleOf = (model: string, factor: number) => {
+ const g = buildUpscaleWorkflow({ image: 'p.png', model, factor, sourceWidth: 640, sourceHeight: 480 }, nodes(model))
+ const n = Object.values(g).find((x) => x.class_type === 'ImageScaleBy')
+ return [n?.inputs.scale_by, n?.inputs.upscale_method]
+ }
+ expect(scaleOf(X4, 8)).toEqual([2, 'lanczos'])
+ expect(scaleOf(X2, 1.5)).toEqual([0.75, 'area'])
+ })
+})
diff --git a/src/hooks/__tests__/useCreate-local-upscale.test.ts b/src/hooks/__tests__/useCreate-local-upscale.test.ts
index 2c7a99c8..2dd10c0b 100644
--- a/src/hooks/__tests__/useCreate-local-upscale.test.ts
+++ b/src/hooks/__tests__/useCreate-local-upscale.test.ts
@@ -25,7 +25,7 @@ vi.mock('../../api/comfyui-nodes', async (orig) => ({
...((await orig()) as Record<string, unknown>),
getAllNodeInfo: vi.fn(async () => ({
LoadImage: {}, ImageUpscaleWithModel: {}, SaveImage: {}, ImageScale: {},
- UpscaleModelLoader: { input: { required: { model_name: [['RealESRGAN_x4plus.safetensors']] } } },
+ UpscaleModelLoader: { input: { required: { model_name: [['RealESRGAN_x4plus.safetensors', '2x-AnimeSharp.pth']] } } },
ImageScaleBy: { input: { required: { upscale_method: [['nearest-exact', 'bilinear', 'area', 'bicubic', 'lanczos']] } } },
})),
}))
@@ -134,6 +134,35 @@ describe('a local Enhance', () => {
const { result } = renderHook(() => useCreate())
await result.current.generate()
expect(sent.graphs).toEqual([])
- expect(useCreateStore.getState().error).toMatch(/Try 2x or a smaller image/)
+ expect(useCreateStore.getState().error).toMatch(/Pick a smaller size or a smaller image/)
+ })
+})
+
+describe('3.1.0: any size and a picked model (Discord 08.11.)', () => {
+ it('a long side of 1920 px on a 640×480 photo is 3x, through the 4x model and down', async () => {
+ useCreateStore.getState().setUpscaleLongSide(1920)
+ await run()
+ const scale = Object.values(sent.graphs[0]).find((n) => n.class_type === 'ImageScaleBy')?.inputs.scale_by
+ expect(scale).toBe(0.75)
+ expect([useCreateStore.getState().gallery[0].width, useCreateStore.getState().gallery[0].height]).toEqual([1920, 1440])
+ }, 15_000)
+
+ it('1.5x runs, and the model picked in the Composer is the one loaded', async () => {
+ useCreateStore.setState({ upscaleModelList: [UPSCALER, '2x-AnimeSharp.pth'] })
+ useCreateStore.getState().setUpscaleModelPick('2x-AnimeSharp.pth')
+ useCreateStore.getState().setUpscaleFactor(1.5)
+ await run()
+ const g = sent.graphs[0]
+ expect(Object.values(g).find((n) => n.class_type === 'UpscaleModelLoader')?.inputs.model_name).toBe('2x-AnimeSharp.pth')
+ expect(Object.values(g).find((n) => n.class_type === 'ImageScaleBy')?.inputs.scale_by).toBe(0.75)
+ expect(useCreateStore.getState().gallery[0].width).toBe(960)
+ }, 15_000)
+
+ it('a long side that does not enlarge is refused before ComfyUI is asked', async () => {
+ useCreateStore.getState().setUpscaleLongSide(512)
+ const { result } = renderHook(() => useCreate())
+ await result.current.generate()
+ expect(sent.graphs).toEqual([])
+ expect(useCreateStore.getState().error).toMatch(/already 640×480, larger than 512 px/)
})
})
diff --git a/src/hooks/useCreate.ts b/src/hooks/useCreate.ts
index 993e5edb..28ea8b1e 100644
--- a/src/hooks/useCreate.ts
+++ b/src/hooks/useCreate.ts
@@ -63,7 +63,7 @@ import {
} from '../api/comfyui-ws'
import { phaseForExecutingNode, phaseForExecutionStart, phaseForProgressStep, phaseForSaveNode } from '../lib/render-phase-labels'
import { buildDynamicWorkflow, buildLocalOpWorkflow, buildLocalUpscaleWorkflow, checkVideoOutputCapability, qwenEditResolution } from '../api/dynamic-workflow'
-import { normalizeUpscaleFactor, pickUpscaleModel, upscaleTarget, upscaleToolLabel, upscaleTooLargeLine } from '../lib/local-upscale'
+import { pickUpscaleModel, upscaleFactorFor, upscaleSizeLabel, upscaleTarget, upscaleToolLabel, upscaleTooLargeLine } from '../lib/local-upscale'
import { getAllNodeInfo, clearNodeCache } from '../api/comfyui-nodes'
import { cutoutModelOf, cutoutDownloadLine } from '../api/cutout-model'
import { apiNodes, type ComfyApiGraph, type ComfyExecutionMessage, type ComfyHistoryEntry } from '../types/comfy-graph'
@@ -832,8 +832,9 @@ export function useCreate() {
// model from models/upscale_models, no prompt and no picker model. A Mac
// never gets here with it (setBackend closes the tab there).
const isUpscale = mode === 'image' && state.utilityOp === 'upscale'
- const upscaleModel = isUpscale ? pickUpscaleModel(state.upscaleModelList) : null
- const upscaleFactor = normalizeUpscaleFactor(state.upscaleFactor)
+ const upscaleModel = isUpscale ? pickUpscaleModel(state.upscaleModelList, state.upscaleModelPick) : null
+ // A target long side becomes the factor of this picture (Discord 08.11.).
+ const upscaleFactor = upscaleFactorFor(source?.width || width, source?.height || height, state.upscaleFactor, state.upscaleLongSide)
// ── 2.5.8 specialized local lanes. music / lipsync / motion build their
// own core-node graphs (buildLocalOpWorkflow); extend rides the regular
@@ -1658,7 +1659,7 @@ export function useCreate() {
setError('No upscale model installed. Use Download & install above, then hit Create again.')
return
}
- const tooLarge = source ? upscaleTooLargeLine(source.width, source.height, upscaleFactor) : null
+ const tooLarge = source ? upscaleTooLargeLine(source.width, source.height, upscaleFactor, upscaleSizeLabel(state.upscaleFactor, state.upscaleLongSide)) : null
if (tooLarge) {
setError(tooLarge)
return
diff --git a/src/lib/__tests__/local-upscale.test.ts b/src/lib/__tests__/local-upscale.test.ts
index 5558e7f4..2824797b 100644
--- a/src/lib/__tests__/local-upscale.test.ts
+++ b/src/lib/__tests__/local-upscale.test.ts
@@ -29,10 +29,10 @@ describe('the scale an upscale model is trained for, from its name', () => {
})
describe('the factor', () => {
- it('defaults to 2x, and only 4 is 4', () => {
+ it('defaults to 2x and takes 1x to 8x on a grid of 0.05 (Discord 08.11.)', () => {
expect(DEFAULT_UPSCALE_FACTOR).toBe(2)
- expect(normalizeUpscaleFactor(4)).toBe(4)
- for (const v of [2, 3, 8, '4', null, undefined, NaN]) expect(normalizeUpscaleFactor(v)).toBe(2)
+ expect([4, 3, 8, 1.5, 1.23, 0.5, 12].map(normalizeUpscaleFactor)).toEqual([4, 3, 8, 1.5, 1.25, 1, 8])
+ for (const v of ['4', null, undefined, NaN]) expect(normalizeUpscaleFactor(v)).toBe(2)
})
it('the result is the source times the factor, per side', () => {
@@ -43,8 +43,8 @@ describe('the factor', () => {
it('a result past the longest side is refused with a sentence that names a way out', () => {
expect(upscaleTooLargeLine(2048, 1536, 4)).toBeNull()
expect(upscaleTooLargeLine(UPSCALE_MAX_SIDE / 2, 100, 2)).toBeNull()
- expect(upscaleTooLargeLine(3000, 2000, 4)).toMatch(/12000×8000.*Try 2x or a smaller image\.$/)
- expect(upscaleTooLargeLine(5000, 3000, 2)).toMatch(/10000×6000.*Try a smaller image\.$/)
+ expect(upscaleTooLargeLine(3000, 2000, 4)).toMatch(/^At 4x .*12000×8000.*Pick a smaller size or a smaller image\.$/)
+ expect(upscaleTooLargeLine(5000, 3000, 2)).toMatch(/10000×6000.*Pick a smaller size/)
})
})
diff --git a/src/lib/local-upscale.ts b/src/lib/local-upscale.ts
index 30e187f5..b0e3bb90 100644
--- a/src/lib/local-upscale.ts
+++ b/src/lib/local-upscale.ts
@@ -11,15 +11,46 @@
// A Mac has no ComfyUI and keeps Enhance as a cloud tool (intents.ts).
-/** The factors the Composer offers. 2x is the default: four times the side is
- * sixteen times the pixels, and most pictures do not need that. */
-export type UpscaleFactor = 2 | 4
-export const UPSCALE_FACTORS: readonly UpscaleFactor[] = [2, 4]
+/** How much larger the result is, per side. 2x is the default: four times the
+ * side is sixteen times the pixels, and most pictures do not need that.
+ * Discord 08.11.2026: 2x and 4x alone were too few, so any
+ * factor from 1x to 8x is taken, and a target long side instead. Above the
+ * model's own scale the rest is a plain resize (buildUpscaleWorkflow). */
+export type UpscaleFactor = number
+export const UPSCALE_FACTOR_MIN = 1
+export const UPSCALE_FACTOR_MAX = 8
+/** The factors the size menu lists; any other one is typed. */
+export const UPSCALE_FACTORS: readonly UpscaleFactor[] = [1.5, 2, 3, 4]
export const DEFAULT_UPSCALE_FACTOR: UpscaleFactor = 2
+/** The long sides the size menu lists, in pixels (2K, 4K UHD, 8K UHD). */
+export const UPSCALE_LONG_SIDES: readonly number[] = [2048, 3840, 7680]
-/** A persisted value from anywhere: only 4 is 4, everything else is the default. */
+/** A persisted or typed factor: inside 1 to 8 on a grid of 0.05, anything
+ * that is not a number is the default. */
export function normalizeUpscaleFactor(v: unknown): UpscaleFactor {
- return v === 4 ? 4 : DEFAULT_UPSCALE_FACTOR
+ if (typeof v !== 'number' || !Number.isFinite(v)) return DEFAULT_UPSCALE_FACTOR
+ const f = Math.round(Math.min(UPSCALE_FACTOR_MAX, Math.max(UPSCALE_FACTOR_MIN, v)) * 20) / 20
+ return f
+}
+
+/** A persisted or typed long side: a whole number from 256 to the largest
+ * side a result may have, or null (the factor counts). */
+export function normalizeUpscaleLongSide(v: unknown): number | null {
+ if (typeof v !== 'number' || !Number.isFinite(v)) return null
+ return Math.round(Math.min(UPSCALE_MAX_SIDE, Math.max(256, v)))
+}
+
+/** The factor a run takes: the long side over the image's longest side when
+ * a long side is set, else the factor. Not rounded, so the long side comes
+ * out exactly. */
+export function upscaleFactorFor(width: number, height: number, factor: number, longSide: number | null): number {
+ const long = Math.max(width, height)
+ return longSide && long > 0 ? longSide / long : normalizeUpscaleFactor(factor)
+}
+
+/** How the menu and the error lines name a size: "2x", "1.5x", "3840 px". */
+export function upscaleSizeLabel(factor: number, longSide: number | null): string {
+ return longSide ? `${longSide} px` : `${normalizeUpscaleFactor(factor)}x`
}
/** The file the setup card downloads (model-bundles.ts, getUpscaleBundles). */
@@ -49,9 +80,11 @@ export function nativeUpscaleScale(file: string): number | null {
return null
}
-/** The model a run takes: the starter file when it is there, else the first
+/** The model a run takes: the one picked in the Composer while ComfyUI
+ * still lists it, else the starter file when it is there, else the first
* one ComfyUI lists. Null with nothing installed. */
-export function pickUpscaleModel(list: readonly string[]): string | null {
+export function pickUpscaleModel(list: readonly string[], picked?: string | null): string | null {
+ if (picked && list.includes(picked)) return picked
const starter = list.find((m) => baseName(m).toLowerCase() === STARTER_UPSCALE_MODEL.toLowerCase())
return starter ?? list[0] ?? null
}
@@ -61,13 +94,15 @@ export function upscaleTarget(width: number, height: number, factor: UpscaleFact
return { width: Math.round(width * factor), height: Math.round(height * factor) }
}
-/** The sentence for a result that would be too large, or null when it fits. */
-export function upscaleTooLargeLine(width: number, height: number, factor: UpscaleFactor): string | null {
+/** The sentence for a size the run should not take, or null when it fits:
+ * more than UPSCALE_MAX_SIDE a side, or a long side that does not enlarge. */
+export function upscaleTooLargeLine(width: number, height: number, factor: UpscaleFactor, label = `${normalizeUpscaleFactor(factor)}x`): string | null {
const t = upscaleTarget(width, height, factor)
- if (Math.max(t.width, t.height) <= UPSCALE_MAX_SIDE) return null
- return factor === 4
- ? `At 4x this image would be ${t.width}×${t.height}, more than ${UPSCALE_MAX_SIDE} pixels a side. Try 2x or a smaller image.`
- : `At 2x this image would be ${t.width}×${t.height}, more than ${UPSCALE_MAX_SIDE} pixels a side. Try a smaller image.`
+ if (Math.max(t.width, t.height) > UPSCALE_MAX_SIDE) {
+ return `At ${label} this image would be ${t.width}×${t.height}, more than ${UPSCALE_MAX_SIDE} pixels a side. Pick a smaller size or a smaller image.`
+ }
+ if (factor < 1) return `The image is already ${width}×${height}, larger than ${label}. Pick a long side above ${Math.max(width, height)} px.`
+ return null
}
/**
diff --git a/src/stores/__tests__/local-upscale-store.test.ts b/src/stores/__tests__/local-upscale-store.test.ts
index b4b0da99..11fcfd93 100644
--- a/src/stores/__tests__/local-upscale-store.test.ts
+++ b/src/stores/__tests__/local-upscale-store.test.ts
@@ -71,12 +71,14 @@ describe('the bar', () => {
})
describe('the factor', () => {
- it('starts at 2x and takes only 2 or 4', () => {
+ it('starts at 2x and takes any factor from 1x to 8x', () => {
expect(st().upscaleFactor).toBe(2)
st().setUpscaleFactor(4)
expect(st().upscaleFactor).toBe(4)
- st().setUpscaleFactor(3 as never)
- expect(st().upscaleFactor).toBe(2)
+ st().setUpscaleFactor(3)
+ expect(st().upscaleFactor).toBe(3)
+ st().setUpscaleFactor(20)
+ expect(st().upscaleFactor).toBe(8)
})
})
diff --git a/src/stores/createStore.ts b/src/stores/createStore.ts
index c7118d6c..94d1d7fa 100644
--- a/src/stores/createStore.ts
+++ b/src/stores/createStore.ts
@@ -65,7 +65,7 @@ import { MAC_EDIT_DEAD_SIDE, MAC_EDIT_SIDE_INSTEAD, imageLaneModels, mlxTakesEdi
import { STUDIO_MODELS } from '../lib/render/studio-contract'
import { cloudModelsFor } from './cloudCatalogStore'
import { createRunModel } from '../lib/render/create-studio'
-import { DEFAULT_UPSCALE_FACTOR, normalizeUpscaleFactor, type UpscaleFactor } from '../lib/local-upscale'
+import { DEFAULT_UPSCALE_FACTOR, normalizeUpscaleFactor, normalizeUpscaleLongSide, type UpscaleFactor } from '../lib/local-upscale'
import { characterLoraFile, isLocalCharacter, type CharacterRef } from '../lib/character-ref'
import { triggerWordNote, typedTriggerWord } from '../lib/train-trigger'
import { loraLaneKey, moveLoraPick, sanitizeLoraLanes, switchLoraLane, type LoraPick } from '../lib/render/lora-lanes'
@@ -609,8 +609,15 @@ export interface CreateState {
/** Local Enhance Image: the files ComfyUI lists in models/upscale_models.
* Mirrored by fetchModels. Runtime-only. */
upscaleModelList: string[]
- /** Local Enhance Image: 2x or 4x the side. A preference, persisted. */
+ /** Local Enhance Image: how much larger per side, 1x to 8x. A
+ * preference, persisted. */
upscaleFactor: UpscaleFactor
+ /** Local Enhance Image: a target long side in pixels instead of the
+ * factor, or null for the factor. Persisted. */
+ upscaleLongSide: number | null
+ /** Local Enhance Image: the upscale model picked in the Composer, or null
+ * for the automatic choice (pickUpscaleModel). Persisted. */
+ upscaleModelPick: string | null
comfyRunning: boolean
/** Runtime-only: an upscaler is installed on this Mac (SeedVR2 on the
* second engine), so Enhance Image is a local tab there. Set by
@@ -702,6 +709,8 @@ export interface CreateState {
setMotionModelList: (list: ClassifiedModel[]) => void
setUpscaleModelList: (list: string[]) => void
setUpscaleFactor: (f: UpscaleFactor) => void
+ setUpscaleLongSide: (px: number | null) => void
+ setUpscaleModelPick: (model: string | null) => void
setExtendSource: (s: { jobId: string; url: string; label: string } | null) => void
setMusicDuration: (s: number) => void
setMusicLyrics: (l: string) => void
@@ -1221,6 +1230,8 @@ export const useCreateStore = create<CreateState>()(
motionModelList: [],
upscaleModelList: [] as string[],
upscaleFactor: DEFAULT_UPSCALE_FACTOR as UpscaleFactor,
+ upscaleLongSide: null as number | null,
+ upscaleModelPick: null as string | null,
comfyRunning: false,
mlxUpscale: false,
vhsInstallPrompt: null,
@@ -1576,7 +1587,9 @@ export const useCreateStore = create<CreateState>()(
setLipsyncModelList: (lipsyncModelList) => set({ lipsyncModelList }),
setMotionModelList: (motionModelList) => set({ motionModelList }),
setUpscaleModelList: (upscaleModelList) => set({ upscaleModelList }),
- setUpscaleFactor: (f) => set({ upscaleFactor: normalizeUpscaleFactor(f) }),
+ setUpscaleFactor: (f) => set({ upscaleFactor: normalizeUpscaleFactor(f), upscaleLongSide: null }),
+ setUpscaleLongSide: (px) => set({ upscaleLongSide: normalizeUpscaleLongSide(px) }),
+ setUpscaleModelPick: (upscaleModelPick) => set({ upscaleModelPick }),
setExtendSource: (extendSource) => set({ extendSource }),
setMusicDuration: (s2) => set({ musicDuration: Math.max(5, Math.min(240, Math.floor(s2))) }),
setMusicLyrics: (musicLyrics) => set({ musicLyrics: musicLyrics.slice(0, 2000) }),
@@ -1990,6 +2003,8 @@ export const useCreateStore = create<CreateState>()(
// price from yesterday is a lie, see the field's own doc comment.
cloudStudioOptions: state.cloudStudioOptions,
upscaleFactor: state.upscaleFactor,
+ upscaleLongSide: state.upscaleLongSide,
+ upscaleModelPick: state.upscaleModelPick,
}),
// Future schema bumps hook into migrate. NOTE: zustand only invokes it
// when the stored blob carries a NUMERIC version that differs — legacy
@@ -2035,6 +2050,8 @@ export const useCreateStore = create<CreateState>()(
// plus imageSubMode 'img2img'. Fixed on the raw blob, because the
// value is not a member of the current union any more.
if ('upscaleFactor' in safe) safe.upscaleFactor = normalizeUpscaleFactor(safe.upscaleFactor)
+ if ('upscaleLongSide' in safe) safe.upscaleLongSide = normalizeUpscaleLongSide(safe.upscaleLongSide)
+ if ('upscaleModelPick' in safe && typeof safe.upscaleModelPick !== 'string') safe.upscaleModelPick = null
if (safe.mode === 'i2i') {
safe.mode = 'image'
safe.imageSubMode = 'img2img'