mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-24 14:45:36 +00:00
BE change https://github.com/Comfy-Org/ComfyUI/pull/13322 ## Summary Add RANGE widget for image levels adjustment - Add RangeEditor widget with three display modes: plain, gradient, and histogram - Support optional midpoint (gamma) control for non-linear midtone adjustment - Integrate histogram display from upstream node outputs ## Screenshots (if applicable) <img width="1450" height="715" alt="image" src="https://github.com/user-attachments/assets/864976af-9eb7-4dd0-9ce1-2f5d7f003117" /> <img width="1431" height="701" alt="image" src="https://github.com/user-attachments/assets/7ee2af65-f87a-407b-8bf2-6ec59a1dff59" /> <img width="705" height="822" alt="image" src="https://github.com/user-attachments/assets/7bcb8f17-795f-498a-9f8a-076ed6c05a98" /> ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10936-Range-editor-33b6d73d365081089e8be040b40f6c8a) by [Unito](https://www.unito.io)
24 lines
823 B
TypeScript
24 lines
823 B
TypeScript
import { clamp } from 'es-toolkit'
|
|
|
|
import type { RangeValue } from '@/lib/litegraph/src/types/widgets'
|
|
|
|
export function positionToGamma(position: number): number {
|
|
// Avoid log2(0) = -Infinity and log2(1) = 0 (division by zero in gamma)
|
|
const clamped = clamp(position, 0.001, 0.999)
|
|
return -Math.log2(clamped)
|
|
}
|
|
|
|
export function gammaToPosition(gamma: number): number {
|
|
return Math.pow(2, -gamma)
|
|
}
|
|
|
|
export function isRangeValue(value: unknown): value is RangeValue {
|
|
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
return false
|
|
const v = value as Record<string, unknown>
|
|
const hasFiniteBounds = Number.isFinite(v.min) && Number.isFinite(v.max)
|
|
const hasValidMidpoint =
|
|
v.midpoint === undefined || Number.isFinite(v.midpoint)
|
|
return hasFiniteBounds && hasValidMidpoint
|
|
}
|