Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Add video effect settings and cube LUT import

Bitti58ce0a8c2dbb
diff --git a/src-tauri/src/project/commands/clips.rs b/src-tauri/src/project/commands/clips.rs
index a13a57b..2931d40 100644
--- a/src-tauri/src/project/commands/clips.rs
+++ b/src-tauri/src/project/commands/clips.rs
@@ -142,6 +142,11 @@ pub(super) fn apply(
transform: None,
look: None,
chroma_key: None,
+ sharpen: None,
+ blur: None,
+ color_correction: None,
+ vignette: None,
+ lut: None,
transition: None,
});
}
diff --git a/src-tauri/src/project/timeline.rs b/src-tauri/src/project/timeline.rs
index 1e50a90..c2f58c8 100644
--- a/src-tauri/src/project/timeline.rs
+++ b/src-tauri/src/project/timeline.rs
@@ -40,6 +40,16 @@ pub(crate) struct TimelineClip {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) chroma_key: Option<ClipChromaKey>,
#[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) sharpen: Option<ClipAmount>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) blur: Option<ClipBlur>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) color_correction: Option<ClipColorCorrection>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) vignette: Option<ClipAmount>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) lut: Option<ClipLut>,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) transition: Option<ClipTransition>,
}
@@ -64,6 +74,36 @@ pub(crate) struct ClipChromaKey {
pub(crate) tolerance: f64,
}
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub(crate) struct ClipAmount {
+ pub(crate) amount: f64,
+}
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub(crate) struct ClipBlur {
+ pub(crate) radius: f64,
+}
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub(crate) struct ClipColorCorrection {
+ pub(crate) exposure: f64,
+ pub(crate) contrast: f64,
+ pub(crate) saturation: f64,
+}
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub(crate) struct ClipLut {
+ pub(crate) intensity: f64,
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub(crate) table: Option<LutTable>,
+}
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct LutTable {
+ pub(crate) name: String,
+ pub(crate) size: usize,
+ pub(crate) domain_min: [f64; 3],
+ pub(crate) domain_max: [f64; 3],
+ pub(crate) values: Vec<f64>,
+}
+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ClipTransition {
diff --git a/src-tauri/src/project/validation/timeline.rs b/src-tauri/src/project/validation/timeline.rs
index 31d4dce..5a1475a 100644
--- a/src-tauri/src/project/validation/timeline.rs
+++ b/src-tauri/src/project/validation/timeline.rs
@@ -61,6 +61,29 @@ pub(super) fn validate(config: &mut ProjectConfig) -> Result<(), String> {
return Err(format!("Clip '{}' has an invalid transition.", clip.id));
}
}
+ let within = |value: f64, min: f64, max: f64| value.is_finite() && (min..=max).contains(&value);
+ if clip.sharpen.as_ref().is_some_and(|v| !within(v.amount, 0.0, 200.0))
+ || clip.blur.as_ref().is_some_and(|v| !within(v.radius, 0.0, 24.0))
+ || clip.vignette.as_ref().is_some_and(|v| !within(v.amount, 0.0, 100.0))
+ || clip.color_correction.as_ref().is_some_and(|v| !within(v.exposure, -4.0, 4.0) || !within(v.contrast, -100.0, 100.0) || !within(v.saturation, 0.0, 200.0))
+ {
+ return Err(format!("Clip '{}' has invalid video effects.", clip.id));
+ }
+ if let Some(lut) = &clip.lut {
+ if !within(lut.intensity, 0.0, 100.0) {
+ return Err(format!("Clip '{}' has invalid LUT intensity.", clip.id));
+ }
+ if let Some(table) = &lut.table {
+ if !(2..=65).contains(&table.size)
+ || table.name.is_empty() || table.name.chars().count() > 256
+ || table.values.len() != table.size.pow(3) * 3
+ || table.values.iter().any(|v| !within(*v, -65504.0, 65504.0))
+ || (0..3).any(|i| !table.domain_min[i].is_finite() || !table.domain_max[i].is_finite() || table.domain_min[i] >= table.domain_max[i])
+ {
+ return Err(format!("Clip '{}' has an invalid LUT table.", clip.id));
+ }
+ }
+ }
}
}
Ok(())
diff --git a/src-tauri/src/tests/persistence.rs b/src-tauri/src/tests/persistence.rs
index b18cc6f..c3ef1b8 100644
--- a/src-tauri/src/tests/persistence.rs
+++ b/src-tauri/src/tests/persistence.rs
@@ -164,6 +164,32 @@ fn deleting_a_project_removes_its_folder_and_every_file_inside_it() {
assert!(parent.path().is_dir());
}
+#[test]
+fn video_effects_survive_save_and_reopen() {
+ let mut json = serde_json::to_value(fixture()).unwrap();
+ let clip = &mut json["timeline"]["tracks"][0]["clips"][0];
+ clip["sharpen"] = serde_json::json!({"amount": 60});
+ clip["blur"] = serde_json::json!({"radius": 4});
+ clip["colorCorrection"] = serde_json::json!({"exposure": 1, "contrast": 20, "saturation": 80});
+ clip["vignette"] = serde_json::json!({"amount": 30});
+ clip["lut"] = serde_json::json!({"intensity": 70, "table": {
+ "name": "Identity", "size": 2, "domainMin": [0, 0, 0], "domainMax": [1, 1, 1],
+ "values": [0,0,0, 1,0,0, 0,1,0, 1,1,0, 0,0,1, 1,0,1, 0,1,1, 1,1,1]
+ }});
+ let config = without_derived_project_state(validate_and_normalize_config(serde_json::from_value(json).unwrap()).unwrap());
+ let root = tempfile::tempdir().unwrap();
+ let created = create_project_in(root.path(), &config).unwrap();
+ let folder = PathBuf::from(&created.folder_path);
+ write_project(&folder, &config).unwrap();
+ assert_eq!(read_project(&folder).unwrap().config, config);
+ let mut invalid = config.clone();
+ invalid.timeline.tracks[0].clips[0].lut.as_mut().unwrap().table.as_mut().unwrap().values.pop();
+ assert!(validate_and_normalize_config(invalid).unwrap_err().contains("LUT table"));
+ let mut invalid = config.clone();
+ invalid.timeline.tracks[0].clips[0].blur.as_mut().unwrap().radius = 25.0;
+ assert!(validate_and_normalize_config(invalid).unwrap_err().contains("video effects"));
+}
+
#[test]
fn deletion_refuses_a_different_project_identity_and_keeps_the_folder() {
let parent = tempfile::tempdir().unwrap();
diff --git a/src/lib/effectSettings.test.ts b/src/lib/effectSettings.test.ts
new file mode 100644
index 0000000..ebc90dc
--- /dev/null
+++ b/src/lib/effectSettings.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it } from "vitest";
+import { parseCube } from "./effectSettings";
+import { timelineClipSchema } from "./project";
+import { clipFrameStyle, clipVisualSettings } from "./export";
+
+export const identityCube = `TITLE "Identity"
+LUT_3D_SIZE 2
+0 0 0
+1 0 0
+0 1 0
+1 1 0
+0 0 1
+1 0 1
+0 1 1
+1 1 1`;
+
+describe("3D cube import", () => {
+ it("preserves red-fastest ordering, comments, title and nonstandard domains", () => {
+ const table = parseCube(identityCube.replace("LUT_3D_SIZE 2", "# comment\r\nLUT_3D_SIZE 2\r\nDOMAIN_MIN -1 -2 -3\r\nDOMAIN_MAX 2 3 4"), "test.cube");
+ expect(table).toMatchObject({ name: "Identity", size: 2, domainMin: [-1, -2, -3], domainMax: [2, 3, 4] });
+ expect(table.values.slice(3, 9)).toEqual([1, 0, 0, 0, 1, 0]);
+ });
+ it("accepts Resolve input ranges", () => {
+ expect(parseCube(identityCube.replace("LUT_3D_SIZE 2", "LUT_3D_SIZE 2\nLUT_3D_INPUT_RANGE 0 2"), "test.cube").domainMax).toEqual([2, 2, 2]);
+ });
+ it.each([
+ identityCube.replace("LUT_3D_SIZE 2", "LUT_3D_SIZE 66"),
+ identityCube.replace("LUT_3D_SIZE 2", "LUT_1D_SIZE 2"),
+ identityCube.replace("LUT_3D_SIZE 2", "LUT_3D_SIZE 2\nDOMAIN_MAX 0 1 1"),
+ identityCube.replace("LUT_3D_SIZE 2", "LUT_3D_SIZE 2\nLUT_3D_SIZE 2"),
+ identityCube.replace("1 1 1", "1 NaN 1"),
+ identityCube.replace("1 1 1", ""),
+ identityCube + "\n1 1 1",
+ ])("rejects malformed or unsupported tables", (text) => {
+ expect(() => parseCube(text, "bad.cube")).toThrow();
+ });
+});
+
+it("retains effects through project parsing and export frame planning", () => {
+ const clip = timelineClipSchema.parse({
+ id: "clip", assetId: "asset", trackId: "track", label: "Test", startMs: 0, durationMs: 1000,
+ sharpen: { amount: 60 }, blur: { radius: 4 }, vignette: { amount: 30 },
+ colorCorrection: { exposure: 1, contrast: 20, saturation: 80 },
+ lut: { intensity: 70, table: parseCube(identityCube, "identity.cube") },
+ });
+ const reopened = timelineClipSchema.parse(JSON.parse(JSON.stringify(clip)));
+ expect(clipFrameStyle(clipVisualSettings(reopened), 500)).toMatchObject({
+ sharpen: clip.sharpen, blur: clip.blur, vignette: clip.vignette, colorCorrection: clip.colorCorrection, lut: clip.lut,
+ });
+ expect(timelineClipSchema.safeParse({ ...clip, blur: { radius: 25 } }).success).toBe(false);
+ expect(timelineClipSchema.safeParse({ ...clip, lut: { ...clip.lut, table: { ...clip.lut!.table, values: [] } } }).success).toBe(false);
+});
diff --git a/src/lib/effectSettings.ts b/src/lib/effectSettings.ts
new file mode 100644
index 0000000..e26108b
--- /dev/null
+++ b/src/lib/effectSettings.ts
@@ -0,0 +1,82 @@
+import { z } from "zod";
+
+const triple = z.tuple([z.number().finite(), z.number().finite(), z.number().finite()]);
+export const lutTableSchema = z.object({
+ name: z.string().min(1).max(256),
+ size: z.number().int().min(2).max(65),
+ domainMin: triple,
+ domainMax: triple,
+ values: z.array(z.number().finite().min(-65504).max(65504)).max(65 ** 3 * 3),
+}).superRefine((table, context) => {
+ if (table.values.length !== table.size ** 3 * 3) context.addIssue({ code: "custom", message: "LUT row count does not match its size." });
+ if (table.domainMin.some((min, i) => min >= table.domainMax[i])) context.addIssue({ code: "custom", message: "LUT domain maximum must exceed minimum." });
+});
+
+export const effectSchemas = {
+ sharpen: z.object({ amount: z.number().finite().min(0).max(200) }).nullish(),
+ blur: z.object({ radius: z.number().finite().min(0).max(24) }).nullish(),
+ colorCorrection: z.object({
+ exposure: z.number().finite().min(-4).max(4),
+ contrast: z.number().finite().min(-100).max(100),
+ saturation: z.number().finite().min(0).max(200),
+ }).nullish(),
+ vignette: z.object({ amount: z.number().finite().min(0).max(100) }).nullish(),
+ lut: z.object({ intensity: z.number().finite().min(0).max(100), table: lutTableSchema.nullish() }).nullish(),
+};
+export type VideoEffects = z.infer<z.ZodObject<typeof effectSchemas>>;
+export type LutTable = z.infer<typeof lutTableSchema>;
+export const hasVideoEffects = (effects: VideoEffects): boolean => Boolean(
+ effects.sharpen || effects.blur || effects.colorCorrection || effects.vignette || effects.lut,
+);
+
+export const MAX_LUT_FILE_BYTES = 16 * 1024 * 1024;
+
+/** Adobe/Resolve 3D .cube, red index varying fastest. Reject shapers explicitly. */
+export function parseCube(text: string, filename: string): LutTable {
+ if (text.length > MAX_LUT_FILE_BYTES) throw new Error("LUT files must be smaller than 16 MB.");
+ let name = filename.slice(0, 256) || "Imported LUT";
+ let size = 0;
+ let domainMin: [number, number, number] = [0, 0, 0];
+ let domainMax: [number, number, number] = [1, 1, 1];
+ const values: number[] = [];
+ const seen = new Set<string>();
+ for (const [index, raw] of text.replace(/^\uFEFF/, "").split(/\r?\n/).entries()) {
+ const line = raw.replace(/#.*$/, "").trim();
+ if (!line) continue;
+ const [tag, ...args] = line.split(/\s+/);
+ const fail = (message: string): never => { throw new Error(`Line ${index + 1}: ${message}`); };
+ if (/^[A-Za-z_]/.test(tag)) {
+ if (values.length) fail("LUT headers must come before color rows.");
+ if (seen.has(tag)) fail(`Duplicate ${tag} header.`);
+ seen.add(tag);
+ if (tag === "TITLE") {
+ const title = /^TITLE\s+"([^"]+)"$/.exec(line);
+ if (!title) fail("Expected a quoted LUT title.");
+ name = title![1].slice(0, 256);
+ } else if (tag === "LUT_3D_SIZE") {
+ size = Number(args[0]);
+ if (args.length !== 1 || !Number.isInteger(size) || size < 2 || size > 65) fail("Supported 3D LUT sizes are 2–65.");
+ } else if (tag === "DOMAIN_MIN" || tag === "DOMAIN_MAX") {
+ const numbers = args.map(Number);
+ if (numbers.length !== 3 || !numbers.every(Number.isFinite)) fail("Expected three finite domain values.");
+ if (tag === "DOMAIN_MIN") domainMin = numbers as typeof domainMin;
+ else domainMax = numbers as typeof domainMax;
+ } else if (tag === "LUT_3D_INPUT_RANGE") {
+ const numbers = args.map(Number);
+ if (numbers.length !== 2 || !numbers.every(Number.isFinite)) fail("Expected two finite input range values.");
+ domainMin = [numbers[0], numbers[0], numbers[0]];
+ domainMax = [numbers[1], numbers[1], numbers[1]];
+ } else fail(`${tag} is unsupported. Choose a 3D .cube LUT without a 1D shaper.`);
+ continue;
+ }
+ if (!size) fail("LUT_3D_SIZE must precede color rows.");
+ const row = [tag, ...args].map(Number);
+ if (row.length !== 3 || !row.every((value) => Number.isFinite(value) && Math.abs(value) <= 65504)) fail("Expected three finite color values within ±65504.");
+ values.push(...row);
+ if (values.length > size ** 3 * 3) fail("Too many color rows for this LUT size.");
+ }
+ if (seen.has("LUT_3D_INPUT_RANGE") && (seen.has("DOMAIN_MIN") || seen.has("DOMAIN_MAX"))) throw new Error("Use either DOMAIN_MIN/MAX or LUT_3D_INPUT_RANGE, not both.");
+ const parsed = lutTableSchema.safeParse({ name, size, domainMin, domainMax, values });
+ if (!parsed.success) throw new Error(parsed.error.issues[0].message);
+ return parsed.data;
+}
diff --git a/src/lib/export.ts b/src/lib/export.ts
index b8dc529..4e903a9 100644
--- a/src/lib/export.ts
+++ b/src/lib/export.ts
@@ -38,7 +38,9 @@ export interface ExportSettings {
quality: QualityId;
}
-export interface ClipVisualSettings {
+import type { VideoEffects } from "./effectSettings";
+
+export interface ClipVisualSettings extends VideoEffects {
transform: ClipTransform;
look: ClipLook;
chromaKey?: ClipChromaKey | null;
@@ -57,6 +59,11 @@ export const clipVisualSettings = (clip: TimelineClip): ClipVisualSettings => ({
transform: clipTransform(clip),
look: clipLook(clip),
chromaKey: clip.chromaKey,
+ sharpen: clip.sharpen,
+ blur: clip.blur,
+ colorCorrection: clip.colorCorrection,
+ vignette: clip.vignette,
+ lut: clip.lut,
transition: clipTransition(clip),
});
diff --git a/src/lib/project.ts b/src/lib/project.ts
index ccc760e..02c2ea7 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -1,4 +1,5 @@
import { z } from "zod";
+import { effectSchemas } from "./effectSettings";
import { normalizeShotTagSelection, shotTagClauses, SHOT_TAG_ID_PATTERN, type ShotTagClauses, type ShotTagSelection } from "./shot-tags";
export const PROJECT_FILE_NAME = "slopus.json";
@@ -201,6 +202,7 @@ export const clipTransitionSchema = z.object({
});
export const timelineClipSchema = z.object({
+ ...effectSchemas,
id: idSchema,
assetId: idSchema,
trackId: idSchema,