Add raster layers

This commit is contained in:
Skyler Lehmkuhl
2026-03-01 13:16:49 -05:00
parent 4b638b882f
commit 1c7256a12e
33 changed files with 1262 additions and 8 deletions
@@ -104,6 +104,9 @@ impl Action for AddClipInstanceAction {
AnyLayer::Group(_) => {
return Err("Cannot add clip instances directly to group layers".to_string());
}
AnyLayer::Raster(_) => {
return Err("Cannot add clip instances directly to group layers".to_string());
}
}
self.executed = true;
@@ -142,6 +145,9 @@ impl Action for AddClipInstanceAction {
AnyLayer::Group(_) => {
// Group layers don't have clip instances, nothing to rollback
}
AnyLayer::Raster(_) => {
// Raster layers don't have clip instances, nothing to rollback
}
}
self.executed = false;
@@ -137,6 +137,7 @@ impl Action for AddLayerAction {
AnyLayer::Video(_) => "Add video layer",
AnyLayer::Effect(_) => "Add effect layer",
AnyLayer::Group(_) => "Add group layer",
AnyLayer::Raster(_) => "Add raster layer",
}
.to_string()
}
@@ -36,6 +36,7 @@ impl Action for LoopClipInstancesAction {
AnyLayer::Video(vl) => &mut vl.clip_instances,
AnyLayer::Effect(el) => &mut el.clip_instances,
AnyLayer::Group(_) => continue,
AnyLayer::Raster(_) => continue,
};
for (instance_id, _old_dur, new_dur, _old_lb, new_lb) in loops {
@@ -59,6 +60,7 @@ impl Action for LoopClipInstancesAction {
AnyLayer::Video(vl) => &mut vl.clip_instances,
AnyLayer::Effect(el) => &mut el.clip_instances,
AnyLayer::Group(_) => continue,
AnyLayer::Raster(_) => continue,
};
for (instance_id, old_dur, _new_dur, old_lb, _new_lb) in loops {
@@ -31,6 +31,7 @@ pub mod convert_to_movie_clip;
pub mod region_split;
pub mod toggle_group_expansion;
pub mod group_layers;
pub mod raster_stroke;
pub use add_clip_instance::AddClipInstanceAction;
pub use add_effect::AddEffectAction;
@@ -60,3 +61,4 @@ pub use convert_to_movie_clip::ConvertToMovieClipAction;
pub use region_split::RegionSplitAction;
pub use toggle_group_expansion::ToggleGroupExpansionAction;
pub use group_layers::GroupLayersAction;
pub use raster_stroke::RasterStrokeAction;
@@ -57,6 +57,7 @@ impl Action for MoveClipInstancesAction {
AnyLayer::Video(vl) => &vl.clip_instances,
AnyLayer::Effect(el) => &el.clip_instances,
AnyLayer::Group(_) => &[],
AnyLayer::Raster(_) => &[],
};
if let Some(instance) = clip_instances.iter().find(|ci| ci.id == *member_instance_id) {
@@ -95,6 +96,7 @@ impl Action for MoveClipInstancesAction {
AnyLayer::Vector(vl) => &vl.clip_instances,
AnyLayer::Effect(el) => &el.clip_instances,
AnyLayer::Group(_) => &[],
AnyLayer::Raster(_) => &[],
};
let group: Vec<(Uuid, f64, f64)> = moves.iter().filter_map(|(id, old_start, _)| {
@@ -129,6 +131,7 @@ impl Action for MoveClipInstancesAction {
AnyLayer::Video(vl) => &mut vl.clip_instances,
AnyLayer::Effect(el) => &mut el.clip_instances,
AnyLayer::Group(_) => continue,
AnyLayer::Raster(_) => continue,
};
// Update timeline_start for each clip instance
@@ -155,6 +158,7 @@ impl Action for MoveClipInstancesAction {
AnyLayer::Video(vl) => &mut vl.clip_instances,
AnyLayer::Effect(el) => &mut el.clip_instances,
AnyLayer::Group(_) => continue,
AnyLayer::Raster(_) => continue,
};
// Restore original timeline_start for each clip instance
@@ -0,0 +1,81 @@
//! Raster stroke action — records and undoes a brush stroke on a RasterLayer.
//!
//! The brush engine paints directly into `RasterKeyframe::raw_pixels` during the
//! drag (via `document_mut()`). This action captures the pixel buffer state
//! *before* and *after* the stroke so it can be undone / redone without
//! re-running the brush engine.
//!
//! `execute` → swap in `buffer_after`
//! `rollback` → swap in `buffer_before`
use crate::action::Action;
use crate::document::Document;
use crate::layer::AnyLayer;
use uuid::Uuid;
/// Action that records a single brush stroke for undo/redo.
///
/// The stroke must already be painted into the document's `raw_pixels` before
/// this action is executed for the first time.
pub struct RasterStrokeAction {
layer_id: Uuid,
time: f64,
/// Raw RGBA pixels *before* the stroke (for rollback / undo)
buffer_before: Vec<u8>,
/// Raw RGBA pixels *after* the stroke (for execute / redo)
buffer_after: Vec<u8>,
width: u32,
height: u32,
}
impl RasterStrokeAction {
/// Create the action.
///
/// * `buffer_before` – raw RGBA pixels captured just before the stroke began.
/// * `buffer_after` – raw RGBA pixels captured just after the stroke finished.
pub fn new(
layer_id: Uuid,
time: f64,
buffer_before: Vec<u8>,
buffer_after: Vec<u8>,
width: u32,
height: u32,
) -> Self {
Self { layer_id, time, buffer_before, buffer_after, width, height }
}
}
impl Action for RasterStrokeAction {
fn execute(&mut self, document: &mut Document) -> Result<(), String> {
let kf = get_keyframe_mut(document, &self.layer_id, self.time, self.width, self.height)?;
kf.raw_pixels = self.buffer_after.clone();
Ok(())
}
fn rollback(&mut self, document: &mut Document) -> Result<(), String> {
let kf = get_keyframe_mut(document, &self.layer_id, self.time, self.width, self.height)?;
kf.raw_pixels = self.buffer_before.clone();
Ok(())
}
fn description(&self) -> String {
"Paint stroke".to_string()
}
}
fn get_keyframe_mut<'a>(
document: &'a mut Document,
layer_id: &Uuid,
time: f64,
width: u32,
height: u32,
) -> Result<&'a mut crate::raster_layer::RasterKeyframe, String> {
let layer = document
.get_layer_mut(layer_id)
.ok_or_else(|| format!("Layer {} not found", layer_id))?;
let raster = match layer {
AnyLayer::Raster(rl) => rl,
_ => return Err("Not a raster layer".to_string()),
};
Ok(raster.ensure_keyframe_at(time, width, height))
}
@@ -45,6 +45,7 @@ impl Action for RemoveClipInstancesAction {
AnyLayer::Video(vl) => &mut vl.clip_instances,
AnyLayer::Effect(el) => &mut el.clip_instances,
AnyLayer::Group(_) => continue,
AnyLayer::Raster(_) => continue,
};
// Find and remove the instance, saving it for rollback
@@ -70,6 +71,7 @@ impl Action for RemoveClipInstancesAction {
AnyLayer::Video(vl) => &mut vl.clip_instances,
AnyLayer::Effect(el) => &mut el.clip_instances,
AnyLayer::Group(_) => continue,
AnyLayer::Raster(_) => continue,
};
clip_instances.push(instance);
@@ -113,6 +113,7 @@ impl Action for SplitClipInstanceAction {
AnyLayer::Video(vl) => &vl.clip_instances,
AnyLayer::Effect(el) => &el.clip_instances,
AnyLayer::Group(_) => return Err("Cannot split clip instances on group layers".to_string()),
AnyLayer::Raster(_) => return Err("Cannot split clip instances on group layers".to_string()),
};
let instance = clip_instances
@@ -232,6 +233,9 @@ impl Action for SplitClipInstanceAction {
AnyLayer::Group(_) => {
return Err("Cannot split clip instances on group layers".to_string());
}
AnyLayer::Raster(_) => {
return Err("Cannot split clip instances on group layers".to_string());
}
}
self.executed = true;
@@ -290,6 +294,9 @@ impl Action for SplitClipInstanceAction {
AnyLayer::Group(_) => {
// Group layers don't have clip instances, nothing to rollback
}
AnyLayer::Raster(_) => {
// Raster layers don't have clip instances, nothing to rollback
}
}
self.executed = false;
@@ -100,6 +100,7 @@ impl Action for TransformClipInstancesAction {
}
AnyLayer::Effect(_) => {}
AnyLayer::Group(_) => {}
AnyLayer::Raster(_) => {}
}
Ok(())
}
@@ -138,6 +139,7 @@ impl Action for TransformClipInstancesAction {
}
AnyLayer::Effect(_) => {}
AnyLayer::Group(_) => {}
AnyLayer::Raster(_) => {}
}
Ok(())
}
@@ -100,6 +100,7 @@ impl Action for TrimClipInstancesAction {
AnyLayer::Video(vl) => &vl.clip_instances,
AnyLayer::Effect(el) => &el.clip_instances,
AnyLayer::Group(_) => &[],
AnyLayer::Raster(_) => &[],
};
if let Some(instance) = clip_instances.iter().find(|ci| ci.id == *member_instance_id) {
@@ -136,6 +137,7 @@ impl Action for TrimClipInstancesAction {
AnyLayer::Video(vl) => &vl.clip_instances,
AnyLayer::Effect(el) => &el.clip_instances,
AnyLayer::Group(_) => &[],
AnyLayer::Raster(_) => &[],
};
if let Some(instance) = clip_instances.iter().find(|ci| ci.id == *member_instance_id) {
@@ -179,6 +181,7 @@ impl Action for TrimClipInstancesAction {
AnyLayer::Vector(vl) => &vl.clip_instances,
AnyLayer::Effect(el) => &el.clip_instances,
AnyLayer::Group(_) => &[],
AnyLayer::Raster(_) => &[],
};
let instance = clip_instances.iter()
@@ -271,6 +274,7 @@ impl Action for TrimClipInstancesAction {
AnyLayer::Video(vl) => &mut vl.clip_instances,
AnyLayer::Effect(el) => &mut el.clip_instances,
AnyLayer::Group(_) => continue,
AnyLayer::Raster(_) => continue,
};
// Apply trims
@@ -310,6 +314,7 @@ impl Action for TrimClipInstancesAction {
AnyLayer::Video(vl) => &mut vl.clip_instances,
AnyLayer::Effect(el) => &mut el.clip_instances,
AnyLayer::Group(_) => continue,
AnyLayer::Raster(_) => continue,
};
// Restore original trim values