Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat: add color correction editor UI
Richie McIlroyf842cf965ecf
diff --git a/apps/desktop/src/routes/editor/ColorCorrectionSection.tsx b/apps/desktop/src/routes/editor/ColorCorrectionSection.tsxnew file mode 100644index 000000000..7b7dbee4b--- /dev/null+++ b/apps/desktop/src/routes/editor/ColorCorrectionSection.tsx@@ -0,0 +1,212 @@+import { Collapsible as KCollapsible } from "@kobalte/core/collapsible";+import { cx } from "cva";+import { createSignal, For, Show } from "solid-js";+import { produce } from "solid-js/store";+import { Toggle } from "~/components/Toggle";+import IconLucideGrip from "~icons/lucide/grip";+import IconLucideMousePointer2 from "~icons/lucide/mouse-pointer-2";+import IconLucideSlidersHorizontal from "~icons/lucide/sliders-horizontal";+import {+ COLOR_CORRECTION_PRESETS,+ COLOR_PRESET_CUSTOM,+ COLOR_PREVIEW_GRAIN,+ COLOR_PREVIEW_SCENE,+ type ColorCorrectionTarget,+ type ColorCorrectionValues,+ type ColorPresetDefinition,+} from "./colorCorrection";+import { useEditorContext } from "./context";+import { Field, Slider } from "./ui";++const ADJUST_SLIDERS: {+ key: keyof ColorCorrectionValues;+ label: string;+ min: number;+ max: number;+ /** Sliders that tune the selected look without demoting it to Custom. */+ keepsPreset?: boolean;+}[] = [+ { key: "intensity", label: "Strength", min: 0, max: 100, keepsPreset: true },+ { key: "exposure", label: "Exposure", min: -100, max: 100 },+ { key: "contrast", label: "Contrast", min: -100, max: 100 },+ { key: "saturation", label: "Saturation", min: -100, max: 100 },+ { key: "temperature", label: "Temperature", min: -100, max: 100 },+ { key: "tint", label: "Tint", min: -100, max: 100 },+ { key: "fade", label: "Fade", min: 0, max: 100 },+ { key: "splitTone", label: "Split Tone", min: -100, max: 100 },+ { key: "vignette", label: "Vignette", min: 0, max: 100 },+];++function ColorPresetPreview(props: { preset: ColorPresetDefinition }) {+ return (+ <div class="overflow-hidden relative w-full rounded-md aspect-video">+ <div+ class="absolute inset-0"+ style={{+ background: COLOR_PREVIEW_SCENE,+ filter: props.preset.preview.filter,+ }}+ />+ <Show when={props.preset.preview.overlay}>+ <div+ class="absolute inset-0"+ style={{+ background: props.preset.preview.overlay,+ "mix-blend-mode": "overlay",+ }}+ />+ </Show>+ <Show when={props.preset.values.vignette > 0}>+ <div+ class="absolute inset-0"+ style={{+ background: `radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, ${(+ props.preset.values.vignette * 0.75+ ).toFixed(3)}) 100%)`,+ }}+ />+ </Show>+ <Show when={props.preset.values.grain > 0}>+ <div+ class="absolute inset-0"+ style={{+ "background-image": COLOR_PREVIEW_GRAIN,+ opacity: Math.min(1, props.preset.values.grain * 1.2),+ "mix-blend-mode": "overlay",+ }}+ />+ </Show>+ </div>+ );+}++export function ColorCorrectionSection(props: {+ target: ColorCorrectionTarget;+ scrollRef?: HTMLDivElement;+}) {+ const { project, setProject } = useEditorContext();+ const [adjustOpen, setAdjustOpen] = createSignal(false);++ const grade = () => project.colorCorrection[props.target];++ const applyPreset = (preset: ColorPresetDefinition) => {+ setProject("colorCorrection", props.target, {+ preset: preset.id,+ ...preset.values,+ });+ };++ const setValue = (+ key: keyof ColorCorrectionValues,+ value: number,+ keepsPreset = false,+ ) => {+ setProject(+ "colorCorrection",+ props.target,+ produce((current) => {+ current[key] = value;+ if (!keepsPreset) current.preset = COLOR_PRESET_CUSTOM;+ }),+ );+ };++ const handleAdjustToggle = (open: boolean) => {+ setAdjustOpen(open);+ if (!open) return;+ setTimeout(() => {+ props.scrollRef?.scrollTo({+ top: props.scrollRef.scrollHeight,+ behavior: "smooth",+ });+ }, 200);+ };++ return (+ <>+ <Field+ name="Color Correction"+ icon={<IconLucideSlidersHorizontal class="size-4" />}+ >+ <div class="grid grid-cols-3 gap-2">+ <For each={COLOR_CORRECTION_PRESETS}>+ {(preset) => (+ <button+ type="button"+ title={preset.description}+ onClick={() => applyPreset(preset)}+ class={cx(+ "flex flex-col gap-1.5 rounded-lg border p-1.5 text-left transition-colors",+ grade().preset === preset.id+ ? "border-blue-9 ring-1 ring-blue-9"+ : "border-gray-3 hover:border-gray-5",+ )}+ >+ <ColorPresetPreview preset={preset} />+ <span class="px-0.5 text-xs font-medium text-gray-12">+ {preset.label}+ </span>+ </button>+ )}+ </For>+ </div>+ </Field>+ <Field name="Grain" icon={<IconLucideGrip class="size-4" />}>+ <Slider+ value={[grade().grain * 100]}+ onChange={(v) => setValue("grain", v[0] / 100, true)}+ minValue={0}+ maxValue={100}+ step={1}+ formatTooltip="%"+ />+ </Field>+ <Show when={props.target === "screen"}>+ <Field+ name="Apply to cursor"+ icon={<IconLucideMousePointer2 class="size-4" />}+ value={+ <Toggle+ checked={project.colorCorrection.gradeCursor}+ onChange={(gradeCursor) =>+ setProject("colorCorrection", "gradeCursor", gradeCursor)+ }+ />+ }+ />+ </Show>+ <div class="w-full">+ <KCollapsible open={adjustOpen()} onOpenChange={handleAdjustToggle}>+ <KCollapsible.Trigger class="flex gap-1 items-center w-full text-sm font-medium text-left group text-gray-12 hover:text-gray-10 transition duration-200 outline-hidden">+ Fine-tune colors+ <IconCapChevronDown class="transition-transform duration-200 size-5 group-data-expanded:rotate-180" />+ </KCollapsible.Trigger>+ <KCollapsible.Content class="overflow-hidden opacity-0 transition-opacity animate-collapsible-up data-expanded:animate-collapsible-down data-expanded:opacity-100">+ <div class="mt-4 space-y-6 font-medium">+ <For each={ADJUST_SLIDERS}>+ {(slider) => (+ <Field name={slider.label}>+ <Slider+ value={[Math.round(grade()[slider.key] * 100)]}+ onChange={(v) =>+ setValue(+ slider.key,+ v[0] / 100,+ slider.keepsPreset ?? false,+ )+ }+ minValue={slider.min}+ maxValue={slider.max}+ step={1}+ formatTooltip="%"+ />+ </Field>+ )}+ </For>+ </div>+ </KCollapsible.Content>+ </KCollapsible>+ </div>+ </>+ );+}diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsxindex 08cf05fc7..677748724 100644--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx@@ -108,6 +108,7 @@ import {MIN_VOLUME_DB,} from "./audio";import { BrandColorsDropdown } from "./BrandColorsDropdown";+import { ColorCorrectionSection } from "./ColorCorrectionSection";import { syncCaptionWordsWithText } from "./captions";import { getColorPreviewBorderColor, hexToRgb, RgbInput } from "./color-utils";import { type CornerRoundingType, useEditorContext } from "./context";@@ -2982,6 +2983,7 @@ function BackgroundConfig(props: {}}/></Field>+ <ColorCorrectionSection target="screen" scrollRef={props.scrollRef} />{/* <ComingSoonTooltip><Field name="Inset" icon={<IconCapInset />}><Slider@@ -3334,6 +3336,7 @@ function CameraConfig(props: { scrollRef: HTMLDivElement }) {/></div></Field>+ <ColorCorrectionSection target="camera" scrollRef={props.scrollRef} />{/* <ComingSoonTooltip><Field name="Shadow" icon={<IconCapShadow />}><Sliderdiff --git a/apps/desktop/src/routes/editor/colorCorrection.ts b/apps/desktop/src/routes/editor/colorCorrection.tsnew file mode 100644index 000000000..2ad1146e7--- /dev/null+++ b/apps/desktop/src/routes/editor/colorCorrection.ts@@ -0,0 +1,219 @@+import type {+ ColorCorrection,+ ColorCorrectionConfiguration,+} from "~/utils/tauri";++export type ColorCorrectionTarget = "screen" | "camera";++export type ColorCorrectionValues = Omit<ColorCorrection, "preset">;++export const COLOR_PRESET_NONE = "none";+export const COLOR_PRESET_CUSTOM = "custom";++export const IDENTITY_COLOR_VALUES: ColorCorrectionValues = {+ intensity: 1,+ exposure: 0,+ contrast: 0,+ saturation: 0,+ temperature: 0,+ tint: 0,+ fade: 0,+ splitTone: 0,+ vignette: 0,+ grain: 0,+};++export const DEFAULT_COLOR_CORRECTION: ColorCorrection = {+ preset: COLOR_PRESET_NONE,+ ...IDENTITY_COLOR_VALUES,+};++export function normalizeColorCorrection(+ config: ColorCorrectionConfiguration | undefined | null,+): ColorCorrectionConfiguration {+ return {+ screen: { ...DEFAULT_COLOR_CORRECTION, ...config?.screen },+ camera: { ...DEFAULT_COLOR_CORRECTION, ...config?.camera },+ gradeCursor: config?.gradeCursor ?? true,+ };+}++export type ColorPresetDefinition = {+ id: string;+ label: string;+ description: string;+ values: ColorCorrectionValues;+ /**+ * CSS approximation of the grade for the preset thumbnail. Vignette and+ * grain overlays are derived from `values` instead so they always match.+ */+ preview: {+ filter?: string;+ overlay?: string;+ };+};++/**+ * The shared thumbnail "scene" every preset preview grades: sky, warm light,+ * and deep shadow so contrast, temperature, and saturation shifts all read.+ */+export const COLOR_PREVIEW_SCENE =+ "linear-gradient(160deg, #60a5fa 0%, #e2e8f0 35%, #fb923c 62%, #1e293b 100%)";++/** Tiny SVG turbulence tile used to preview film grain on preset cards. */+export const COLOR_PREVIEW_GRAIN = `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='64' height='64'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/></filter><rect width='64' height='64' filter='url(%23n)'/></svg>")`;++export const COLOR_CORRECTION_PRESETS: ColorPresetDefinition[] = [+ {+ id: COLOR_PRESET_NONE,+ label: "None",+ description: "Original colors, no grade applied",+ values: { ...IDENTITY_COLOR_VALUES },+ preview: {},+ },+ {+ id: "cinematic",+ label: "Cinematic",+ description: "Teal shadows and orange highlights with light grain",+ values: {+ ...IDENTITY_COLOR_VALUES,+ contrast: 0.12,+ saturation: 0.06,+ temperature: 0.04,+ splitTone: 0.45,+ vignette: 0.18,+ grain: 0.12,+ },+ preview: {+ filter: "contrast(1.12) saturate(1.12)",+ overlay:+ "linear-gradient(135deg, rgba(13, 148, 136, 0.45), rgba(251, 146, 60, 0.4))",+ },+ },+ {+ id: "noir",+ label: "Noir",+ description: "High-contrast black and white with heavy grain",+ values: {+ ...IDENTITY_COLOR_VALUES,+ exposure: 0.04,+ contrast: 0.3,+ saturation: -1,+ fade: 0.06,+ vignette: 0.32,+ grain: 0.35,+ },+ preview: {+ filter: "grayscale(1) contrast(1.35) brightness(1.03)",+ },+ },+ {+ id: "vintage",+ label: "Vintage",+ description: "Faded warm film look with soft contrast",+ values: {+ ...IDENTITY_COLOR_VALUES,+ contrast: -0.06,+ saturation: -0.18,+ temperature: 0.22,+ tint: 0.08,+ fade: 0.28,+ vignette: 0.14,+ grain: 0.28,+ },+ preview: {+ filter: "sepia(0.5) contrast(0.92) saturate(0.8) brightness(1.05)",+ },+ },+ {+ id: "frost",+ label: "Frost",+ description: "Cool, crisp tones with muted color",+ values: {+ ...IDENTITY_COLOR_VALUES,+ contrast: 0.08,+ saturation: -0.08,+ temperature: -0.3,+ tint: -0.04,+ fade: 0.06,+ },+ preview: {+ filter: "saturate(0.88) contrast(1.06) hue-rotate(-10deg)",+ overlay:+ "linear-gradient(180deg, rgba(125, 211, 252, 0.5), rgba(59, 130, 246, 0.3))",+ },+ },+ {+ id: "golden",+ label: "Golden",+ description: "Warm golden-hour glow",+ values: {+ ...IDENTITY_COLOR_VALUES,+ exposure: 0.06,+ contrast: 0.06,+ saturation: 0.12,+ temperature: 0.38,+ fade: 0.04,+ vignette: 0.1,+ },+ preview: {+ filter: "sepia(0.3) saturate(1.2) contrast(1.05) brightness(1.06)",+ overlay:+ "linear-gradient(180deg, rgba(253, 186, 116, 0.4), rgba(251, 113, 36, 0.25))",+ },+ },+ {+ id: "midnight",+ label: "Midnight",+ description: "Dark, moody teal with subdued color",+ values: {+ ...IDENTITY_COLOR_VALUES,+ exposure: -0.08,+ contrast: 0.16,+ saturation: -0.22,+ temperature: -0.1,+ splitTone: 0.3,+ vignette: 0.28,+ grain: 0.18,+ },+ preview: {+ filter: "brightness(0.85) contrast(1.16) saturate(0.75)",+ overlay:+ "linear-gradient(180deg, rgba(15, 23, 42, 0.5), rgba(19, 78, 74, 0.45))",+ },+ },+ {+ id: "vivid",+ label: "Vivid",+ description: "Punchy saturation and contrast boost",+ values: {+ ...IDENTITY_COLOR_VALUES,+ exposure: 0.02,+ contrast: 0.14,+ saturation: 0.32,+ },+ preview: {+ filter: "saturate(1.45) contrast(1.14)",+ },+ },+ {+ id: "dreamy",+ label: "Dreamy",+ description: "Soft, airy pastels with lifted blacks",+ values: {+ ...IDENTITY_COLOR_VALUES,+ exposure: 0.08,+ contrast: -0.14,+ saturation: -0.04,+ temperature: 0.06,+ tint: 0.05,+ fade: 0.3,+ grain: 0.1,+ },+ preview: {+ filter: "brightness(1.1) contrast(0.85) saturate(0.95)",+ overlay:+ "linear-gradient(180deg, rgba(251, 207, 232, 0.45), rgba(196, 181, 253, 0.35))",+ },+ },+];diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.tsindex 7877d99ed..b4aee239b 100644--- a/apps/desktop/src/routes/editor/context.ts+++ b/apps/desktop/src/routes/editor/context.ts@@ -38,6 +38,7 @@ import {} from "~/utils/socket";import {type ClipSpeedAudioMode,+ type ColorCorrectionConfiguration,commands,type EditorPreviewQuality,events,@@ -74,6 +75,7 @@ import {transitionsAfterClipDelete,transitionsAfterClipSplit,} from "./clip-transitions";+import { normalizeColorCorrection } from "./colorCorrection";import type { MaskSegment } from "./masks";import type { SnapGuide } from "./snapping";import type { TextSegment } from "./text";@@ -225,6 +227,7 @@ export type EditorProjectConfiguration = Omit<timeline?: EditorTimelineConfiguration | null;captions: EditorCaptionsData | null;hiddenTextSegments?: number[];+ colorCorrection: ColorCorrectionConfiguration;};function withCornerDefaults<@@ -306,6 +309,7 @@ export function normalizeProject(captions,background: withCornerDefaults(config.background),camera: withCornerDefaults(config.camera),+ colorCorrection: normalizeColorCorrection(config.colorCorrection),};}diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex 7ad31e095..62f92eace 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -689,8 +689,8 @@ export type Camera3DBlurMode = "none" | "radial" | "directional" | "tiltShift"* One scalar keyframe on a per-property track. Interpolation between two* keyframes is a linear value lerp with time remapped by a cubic bezier whose* P1 comes from the left keyframe's `out_easing` and P2 from the right one's- * `in_easing` (a split-handle model). Absent handles default to- * cubic ease-in-out: P1 [0.65, 0], P2 [0.35, 1].+ * `in_easing` (a split-handle model). Absent handles default to cubic+ * ease-in-out: P1 [0.65, 0], P2 [0.35, 1].*/export type Camera3DKeyframe = {/**@@ -732,7 +732,7 @@ roll?: number;/*** Content plane pitch.*/-rotateX?: number;+rotateX?: number;/*** Content plane yaw.*/@@ -809,6 +809,66 @@ export type ClipSpeedAudioMode = "mute" | "maintainPitch" | "matchSpeed"export type ClipTransition = { segmentIndex: number; type: ClipTransitionType; duration: number }export type ClipTransitionType = "cross-fade" | "fade-through-black"export type ClipboardSource = "raw" | "rendered"+/**+ * Parametric color grade for a single layer (screen or camera). Every field+ * except `intensity` has 0 as its identity, so a default struct renders+ * exactly like no grade at all. Adjustment fields are normalized: -1..1 for+ * bipolar controls, 0..1 for unipolar ones.+ */+export type ColorCorrection = {+/**+ * UI preset id ("none", "cinematic", ..., or "custom"). The renderer+ * ignores this; the numeric fields below are the source of truth.+ */+preset: string;+/**+ * 0..1 master strength applied to every adjustment except `grain`,+ * which has its own dedicated control.+ */+intensity: number;+/**+ * -1..1, full scale is ±1.5 stops.+ */+exposure: number;+/**+ * -1..1 around a mid-gray pivot.+ */+contrast: number;+/**+ * -1..1; -1 is grayscale.+ */+saturation: number;+/**+ * -1..1; positive warms, negative cools.+ */+temperature: number;+/**+ * -1..1; positive shifts magenta, negative green.+ */+tint: number;+/**+ * 0..1 lifted-blacks film fade.+ */+fade: number;+/**+ * -1..1 teal-shadows/orange-highlights split toning (negative reverses).+ */+splitTone: number;+/**+ * 0..1 edge darkening within the layer's own rect.+ */+vignette: number;+/**+ * 0..1 animated film grain.+ */+grain: number }+export type ColorCorrectionConfiguration = { screen: ColorCorrection; camera: ColorCorrection;+/**+ * Whether the screen grade also covers the rendered cursor. On by+ * default so the pointer reads as part of the graded footage; off keeps+ * it crisp for legibility over vignettes and grain.+ */+gradeCursor: boolean }export type CommercialLicense = { licenseKey: string; expiryDate: number | null; refresh: number; activatedOn: number }export type Condition = { type: "captureTargetIs"; target: CaptureTargetKind } | { type: "recordingModeIs"; mode: AutomationRecordingMode } | { type: "durationAtLeast"; secs: number } | { type: "durationAtMost"; secs: number } | { type: "windowTitleContains"; pattern: string } | { type: "organizationIs"; id: string }export type CornerStyle = "squircle" | "rounded"@@ -993,6 +1053,12 @@ export type PostStudioRecordingBehaviour = "openEditor" | "showOverlay"export type Preset = { name: string; config: ProjectConfiguration }export type PresetsStore = { presets: Preset[]; default: number | null }export type ProjectConfiguration = { aspectRatio: AspectRatio | null; background: BackgroundConfiguration; camera: Camera; audio: AudioConfiguration; cursor: CursorConfiguration; hotkeys: HotkeysConfiguration; timeline: TimelineConfiguration | null; captions: CaptionsData | null; keyboard: KeyboardData | null; clips: ClipConfiguration[]; annotations: Annotation[]; screenMotionBlur?: number; screenMovementSpring?: ScreenMovementSpring;+/**+ * Per-layer cinematic color grades. Field-level default keeps old+ * project files (and old saved presets) deserializing to the identity+ * grade.+ */+colorCorrection?: ColorCorrectionConfiguration;/*** How text segment font sizes are interpreted. 0 (legacy): the renderer* multiplied `font_size` by `size.y / 0.2`, coupling glyph size to the