Add pattern stamp tool

This commit is contained in:
Skyler Lehmkuhl
2026-03-06 08:40:17 -05:00
parent 1d9d702a59
commit 7d55443b2a
7 changed files with 127 additions and 10 deletions
@@ -303,7 +303,8 @@ impl BrushEngine {
RasterBlendMode::Erase => 1u32,
RasterBlendMode::Smudge => 2u32,
RasterBlendMode::CloneStamp => 3u32,
RasterBlendMode::Healing => 4u32,
RasterBlendMode::Healing => 4u32,
RasterBlendMode::PatternStamp => 5u32,
};
let push_dab = |dabs: &mut Vec<GpuDab>,
@@ -360,15 +361,18 @@ impl BrushEngine {
state, bs, pt.x, pt.y, base_r, pt.pressure, stroke.color,
);
if !matches!(base_blend, RasterBlendMode::Smudge) {
let (cr2, cg2, cb2) = if matches!(base_blend, RasterBlendMode::CloneStamp | RasterBlendMode::Healing) {
let (cr2, cg2, cb2, ndx2, ndy2) = if matches!(base_blend, RasterBlendMode::CloneStamp | RasterBlendMode::Healing) {
// Store offset in color_r/color_g; shader adds it per-pixel.
let (ox, oy) = stroke.clone_src_offset.unwrap_or((0.0, 0.0));
(ox, oy, 0.0)
(ox, oy, 0.0, 0.0, 0.0)
} else if matches!(base_blend, RasterBlendMode::PatternStamp) {
// ndx = pattern_type, ndy = pattern_scale
(cr, cg, cb, stroke.pattern_type as f32, stroke.pattern_scale)
} else {
(cr, cg, cb)
(cr, cg, cb, 0.0, 0.0)
};
push_dab(&mut dabs, &mut bbox, ex, ey, r, o, cr2, cg2, cb2,
0.0, 0.0, 0.0);
ndx2, ndy2, 0.0);
}
}
}
@@ -486,6 +490,11 @@ impl BrushEngine {
push_dab(&mut dabs, &mut bbox,
ex, ey, radius2, opacity2, ox, oy, 0.0,
0.0, 0.0, 0.0);
} else if matches!(base_blend, RasterBlendMode::PatternStamp) {
// ndx = pattern_type, ndy = pattern_scale
push_dab(&mut dabs, &mut bbox,
ex, ey, radius2, opacity2, cr, cg, cb,
stroke.pattern_type as f32, stroke.pattern_scale, 0.0);
} else {
push_dab(&mut dabs, &mut bbox,
ex, ey, radius2, opacity2, cr, cg, cb,
@@ -518,15 +527,18 @@ impl BrushEngine {
last_smooth_x, last_smooth_y,
base_r, last_pressure, stroke.color,
);
let (cr2, cg2, cb2) = if matches!(base_blend, RasterBlendMode::CloneStamp | RasterBlendMode::Healing) {
let (cr2, cg2, cb2, ndx2, ndy2) = if matches!(base_blend, RasterBlendMode::CloneStamp | RasterBlendMode::Healing) {
// Store offset in color_r/color_g; shader adds it per-pixel.
let (ox, oy) = stroke.clone_src_offset.unwrap_or((0.0, 0.0));
(ox, oy, 0.0)
(ox, oy, 0.0, 0.0, 0.0)
} else if matches!(base_blend, RasterBlendMode::PatternStamp) {
// ndx = pattern_type, ndy = pattern_scale
(cr, cg, cb, stroke.pattern_type as f32, stroke.pattern_scale)
} else {
(cr, cg, cb)
(cr, cg, cb, 0.0, 0.0)
};
push_dab(&mut dabs, &mut bbox, ex, ey, r, o, cr2, cg2, cb2,
0.0, 0.0, 0.0);
ndx2, ndy2, 0.0);
}
}
@@ -22,6 +22,8 @@ pub enum RasterBlendMode {
CloneStamp,
/// Healing brush: color-corrected clone stamp (preserves source texture, shifts color to match destination)
Healing,
/// Pattern stamp: paint with a repeating procedural tile pattern
PatternStamp,
}
impl Default for RasterBlendMode {
@@ -57,9 +59,17 @@ pub struct StrokeRecord {
/// None for all non-clone-stamp blend modes.
#[serde(default)]
pub clone_src_offset: Option<(f32, f32)>,
/// Pattern stamp: procedural pattern type (0=Checkerboard, 1=Dots, 2=H-Lines, 3=V-Lines, 4=Diagonal, 5=Crosshatch)
#[serde(default)]
pub pattern_type: u32,
/// Pattern stamp: tile size in pixels
#[serde(default = "default_pattern_scale")]
pub pattern_scale: f32,
pub points: Vec<StrokePoint>,
}
fn default_pattern_scale() -> f32 { 32.0 }
/// Specifies how the raster content transitions to the next keyframe
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum TweenType {