8000 feat: global color grade + opinionated filters (VHS · Super-8 · Decay · Noir · Sepia · Instant) by johannboehme · Pull Request #60 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions frontend/src/editor/components/ColorGradePanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Color-grade section for the Overlays panel — the corrective/creative grade
// applied UNDER the filters and accents. ONE grade per project (no add/remove,
// no looks): grouped grading controls in pipeline order, each writing the
// `colorGrade` GradeParams vector. Reuses the panel's card + slider idioms.
import { useEditorStore } from "../store";
import type { GradeParams } from "../fx/looks";
import { ChunkyButton } from "./ChunkyButton";
import { ParamSlider } from "./ParamSlider";

type Group = "TONE" | "COLOR" | "WHEELS";

interface Control {
key: keyof GradeParams;
label: string;
group: Group;
/** unipolar 0..100 (else bipolar -100..100). */
uni?: boolean;
/** engine value -> display int. */
to: (v: number) => number;
/** display int -> engine value. */
from: (d: number) => number;
}

// Display maps the engine ranges to friendly -100..100 / 0..100 sliders.
const CONTROLS: Control[] = [
{ key: "exposure", label: "EXPOSURE", group: "TONE", to: (v) => Math.round(v * 100), from: (d) => d / 100 },
{ key: "contrast", label: "CONTRAST", group: "TONE", to: (v) => Math.round(v * 100), from: (d) => d / 100 },
{ key: "blackPoint", label: "BLACK", group: "TONE", to: (v) => Math.round((v / 0.2) * 100), from: (d) => (d / 100) * 0.2 },
{ key: "fade", label: "FADE", group: "TONE", uni: true, to: (v) => Math.round(v * 100), from: (d) => d / 100 },
{ key: "saturation", label: "SATURATION", group: "COLOR", to: (v) => Math.round((v - 1) * 100), from: (d) => 1 + d / 100 },
{ key: "temp", label: "TEMP", group: "COLOR", to: (v) => Math.round(v * 100), from: (d) => d / 100 },
{ key: "tint", label: "TINT", group: "COLOR", to: (v) => Math.round(v * 100), from: (d) => d / 100 },
{ key: "shadowsLift", label: "SHADOWS", group: "WHEELS", to: (v) => Math.round(v * 100), from: (d) => d / 100 },
{ key: "gamma", label: "MIDTONES", group: "WHEELS", to: (v) => Math.round(v * 100), from: (d) => d / 100 },
{ key: "highlightsGain", label: "HIGHLIGHTS", group: "WHEELS", to: (v) => Math.round(v * 100), from: (d) => d / 100 },
];

const GROUPS: { id: Group; title: string }[] = [
{ id: "TONE", title: "Tone" },
{ id: "COLOR", title: "Color" },
{ id: "WHEELS", title: "Shadows · Midtones · Highlights" },
];

export function ColorGradePanel() {
const colorGrade = useEditorStore((s) => s.colorGrade);
const setColorGrade = useEditorStore((s) => s.setColorGrade);
const resetColorGrade = useEditorStore((s) => s.resetColorGrade);

return (
<section className="flex flex-col gap-3">
<div className="flex items-center justify-between">
<span className="label">Color grade</span>
<ChunkyButton size="sm" variant="ghost" >
RESET
</ChunkyButton>
</div>

<div className="rounded-md bg-paper-deep p-3 shadow-pressed flex flex-col gap-3">
{GROUPS.map((g, gi) => (
<div
key={g.id}
className={[
"flex flex-col gap-2",
gi > 0 ? "pt-3 border-t border-rule" : "",
].join(" ")}
>
<span className="font-mono text-[9px] tracking-label uppercase text-ink-3">
{g.title}
</span>
{CONTROLS.filter((c) => c.group === g.id).map((c) => (
<ParamSlider
key={c.key}
label={c.label}
value={c.to(colorGrade[c.key])}
min={c.uni ? 0 : -100}
max={100}
bipolar={!c.uni}
=> setColorGrade({ [c.key]: c.from(d) })}
/>
))}
</div>
))}
</div>
</section>
);
}
72 changes: 72 additions & 0 deletions frontend/src/editor/components/FilterStack.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { beforeEach, describe, expect, it } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
import { FilterStack } from "./FilterStack";
import { useEditorStore } from "../store";

const S = () => useEditorStore.getState();

describe("FilterStack", () => {
beforeEach(() => S().reset());

it("shows an empty state and a working ADD button", () => {
render(<FilterStack />);
expect(screen.getByText(/No filters yet/i)).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: "ADD" }));
expect(S().filterSlots).toHaveLength(1);
expect(screen.queryByText(/No filters yet/i)).toBeNull();
});

it("renders the Filter picker + the selected kind's OWN controls", () => {
S().addFilterSlot("vhs");
render(<FilterStack />);
expect(screen.getByLabelText("Filter")).toBeTruthy();
// VHS shows its own param sliders
for (const name of ["TRACK", "BLEED", "SNOW", "WOBBLE", "AMOUNT"]) {
expect(screen.getByLabelText(name)).toBeTruthy();
}
});

it("switching the filter kind swaps the whole control set", () => {
const id = S().addFilterSlot("vhs");
render(<FilterStack />);
expect(screen.queryByLabelText("TRACK")).toBeTruthy();
expect(screen.queryByLabelText("TONE")).toBeNull();

fireEvent.change(screen.getByLabelText("Filter"), { target: { value: "sepia" } });
expect(S().filterSlots.find((s) => s.id === id)?.kind).toBe("sepia");
// now Sepia's controls render, VHS's are gone
expect(screen.queryByLabelText("TONE")).toBeTruthy();
expect(screen.queryByLabelText("TRACK")).toBeNull();
});

it("a param slider writes back to the slot (0..100 -> 0..1)", () => {
const id = S().addFilterSlot("vhs");
render(<FilterStack />);
fireEvent.change(screen.getByLabelText("TRACK"), { target: { value: "80" } });
expect(S().filterSlots.find((s) => s.id === id)?.params.tracking).toBeCloseTo(0.8);
});

it("REMOVE drops the card", () => {
S().addFilterSlot("vhs");
render(<FilterStack />);
fireEvent.click(screen.getByRole("button", { name: "REMOVE" }));
expect(S().filterSlots).toHaveLength(0);
});

it("reorder nudges move a slot and are disabled at the ends", () => {
const a = S().addFilterSlot("vhs");
const b = S().addFilterSlot("sepia");
render(<FilterStack />);
const ups = screen.getAllByRole("button", { name: "Move filter up" });
expect((ups[0] as HTMLButtonElement).disabled).toBe(true);
fireEvent.click(ups[1]);
expect(S().filterSlots.map((s) => s.id)).toEqual([b, a]);
});

it("the card header shows the kind's swatch", () => {
S().addFilterSlot("noir");
const { container } = render(<FilterStack />);
// swatch chip is an aria-hidden span with a background colour
expect(container.querySelector('span[aria-hidden]')).toBeTruthy();
});
});
154 changes: 154 additions & 0 deletions frontend/src/editor/components/FilterStack.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// Filters section for the Overlays panel — a stack of opinionated looks
// (VHS / Super-8 / Decay / Noir / Sepia / Instant). ADD appends a filter
// card; each card picks a kind and renders THAT kind's OWN controls (read
// from FxDefinition.filterParams), so a VHS card shows TRACK/BLEED/SNOW and a
// Sepia card shows TONE/CONTRAST/FADE — no shared macro block. Card order
// top→bottom is the serial compose order. Reuses the panel's card + slider
// idioms.
import { useEditorStore } from "../store";
import { fxCatalog } from "../fx/catalog";
import type { FilterSlot, FxKind } from "../fx/types";
import { ChunkyButton } from "./ChunkyButton";
import { ParamSlider } from "./ParamSlider";
import { ChevronLeftIcon, PlusIcon, TrashIcon } from "./icons";

/** The shippable filter kinds, in picker order. */
const FILTER_KINDS: FxKind[] = ["vhs", "super8", "decay", "noir", "sepia", "polaroid"];

export function FilterStack() {
const slots = useEditorStore((s) => s.filterSlots);
const addFilterSlot = useEditorStore((s) => s.addFilterSlot);
const setFilterKind = useEditorStore((s) => s.setFilterKind);
const setFilterParam = useEditorStore((s) => s.setFilterParam);
const removeFilterSlot = useEditorStore((s) => s.removeFilterSlot);
const moveFilterSlot = useEditorStore((s) => s.moveFilterSlot);

return (
<section className="flex flex-col gap-3">
<div className="flex items-center justify-between">
<span className="label">Filters · {slots.length}</span>
<ChunkyButton
size="sm"
variant="primary"
iconLeft={<PlusIcon />}
=> addFilterSlot(FILTER_KINDS[0])}
>
ADD
</ChunkyButton>
</div>

{slots.length === 0 && (
<div className="rounded-md bg-paper-deep shadow-pressed py-6 text-center">
<p className="text-xs text-ink-2">
No filters yet — press ADD to stack a look.
</p>
</div>
)}

<div className="flex flex-col gap-3">
{slots.map((slot, idx) => (
<FilterCard
key={slot.id}
slot={slot}
idx={idx}
total={slots.length}
=> setFilterKind(slot.id, kind)}
v) => setFilterParam(slot.id, key, v)}
=> removeFilterSlot(slot.id)}
=> moveFilterSlot(slot.id, dir)}
/>
))}
</div>
</section>
);
}

interface CardProps {
slot: FilterSlot;
idx: number;
total: number;
onKind: (kind: FxKind) => void;
onParam: (key: string, value: number) => void;
onRemove: () => void;
onMove: (dir: -1 | 1) => void;
}

function FilterCard({ slot, idx, total, onKind, onParam, onRemove, onMove }: CardProps) {
const def = fxCatalog[slot.kind];
const params = def.filterParams ?? [];
return (
<div className="rounded-md bg-paper-deep p-3 shadow-pressed flex flex-col gap-2">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2 min-w-0">
<span
aria-hidden
className="inline-block w-3 h-3 rounded-full border border-rule shrink-0"
style={{ background: def.capsuleColor }}
/>
<span className="label truncate">#{idx + 1}</span>
</div>
<div className="flex items-center gap-1 shrink-0">
<NudgeButton dir="up" disabled={idx === 0} => onMove(-1)} />
<NudgeButton dir="down" disabled={idx === total - 1} => onMove(1)} />
<ChunkyButton size="sm" variant="ghost" iconLeft={<TrashIcon />} >
REMOVE
</ChunkyButton>
</div>
</div>

<label className="flex flex-col gap-1">
<span className="label">Filter</span>
<select
aria-label="Filter"
value={slot.kind}
=> onKind(e.target.value as FxKind)}
className="bg-paper-hi border border-rule rounded-md h-10 px-2 font-mono text-sm"
>
{FILTER_KINDS.map((k) => (
<option key={k} value={k}>
{fxCatalog[k].label}
</option>
))}
</select>
</label>

{params.map((p) => {
const raw = slot.params[p.id] ?? p.defaultValue;
return (
<ParamSlider
key={p.id}
label={p.label}
value={Math.round(raw * 100)}
min={Math.round(p.min * 100)}
max={Math.round(p.max * 100)}
unit={p.id === "amount" ? "%" : undefined}
bipolar={p.min < 0}
=> onParam(p.id, v / 100)}
/>
);
})}
</div>
);
}

function NudgeButton({
dir,
disabled,
onClick,
}: {
dir: "up" | "down";
disabled: boolean;
onClick: () => void;
}) {
return (
<button
type="button"
aria-label={dir === "up" ? "Move filter up" : "Move filter down"}
disabled={disabled}
>
className="h-7 w-7 flex items-center justify-center rounded-md bg-paper-hi border border-rule text-ink-2 hover:text-ink disabled:text-ink-3 disabled:cursor-default"
>
<ChevronLeftIcon className={dir === "up" ? "rotate-90" : "-rotate-90"} />
</button>
);
}
10 changes: 9 additions & 1 deletion frontend/src/editor/components/OverlaysPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { TextOverlay, VisualizerConfig } from "../types";
import { useEditorStore } from "../store";
import { ChunkyButton } from "./ChunkyButton";
import { SegmentedControl } from "./SegmentedControl";
import { FilterStack } from "./FilterStack";
import { ColorGradePanel } from "./ColorGradePanel";
import { PlusIcon, TrashIcon } from "./icons";

const VIS_OPTIONS: { value: VisualizerConfig["type"] | ""; label: string }[] = [
Expand Down Expand Up @@ -53,7 +55,9 @@ export function OverlaysPanel() {
<div className="flex flex-col gap-5">
<header>
<h2 className="font-display text-lg leading-none">Overlays & FX</h2>
<p className="text-xs text-ink-2 mt-1">Text overlays + audio visualizer.</p>
<p className="text-xs text-ink-2 mt-1">
Filters · text overlays · audio visualizer.
</p>
</header>

<div className="flex flex-col gap-2">
Expand Down Expand Up @@ -83,6 +87,10 @@ export function OverlaysPanel() {
</select>
</div>

<ColorGradePanel />

<FilterStack />

<div className="flex items-center justify-between">
<span className="label">Text overlays · {overlays.length}</span>
<ChunkyButton size="sm" variant="primary" iconLeft={<PlusIcon />} >
Expand Down
39 changes: 39 additions & 0 deletions frontend/src/editor/components/ParamSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Shared panel slider — matches QualitySlider's idiom (label-left, mono
// value-right, range accent-hot). Used by the Color-grade section and every
// filter card. Values are integers; `bipolar` prints a leading "+" and shows
// a centre-zero range.
interface Props {
label: string;
value: number;
min: number;
max: number;
unit?: string;
/** Centre-zero param — show a leading "+" on positive values. */
bipolar?: boolean;
onChange: (v: number) => void;
}

export function ParamSlider({ label, value, min, max, unit, bipolar, onChange }: Props) {
const display = bipolar && value > 0 ? `+${value}` : `${value}`;
return (
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<span className="label">{label}</span>
<span className="font-mono text-[10px] tracking-label uppercase text-ink-2">
{display}
{unit ?? ""}
</span>
</div>
<input
type="range"
aria-label={label}
min={min}
max={max}
step={1}
value={value}
=> onChange(parseInt(e.target.value, 10))}
className="w-full accent-hot"
/>
</div>
);
}
Loading
Loading
0