Created
September 14, 2023 01:18
-
-
Save wchargin/f15374daf6877bb60224147683f8be6d to your computer and use it in GitHub Desktop.
qqlrs patch: debug pass to show progress of layout through flow line groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/art.rs b/src/art.rs | |
index 78e28bf..970b0e0 100644 | |
--- a/src/art.rs | |
+++ b/src/art.rs | |
@@ -813,6 +813,7 @@ impl MarginChecker { | |
#[derive(Debug, Clone)] | |
pub struct Point { | |
+ pub group_idx: u32, | |
pub position: (f64, f64), | |
pub scale: f64, | |
pub primary_color: Hsb, | |
@@ -821,6 +822,7 @@ pub struct Point { | |
} | |
#[derive(Debug, Copy, Clone, PartialEq)] | |
pub struct Hsb(pub f64, pub f64, pub f64); | |
+#[derive(Clone)] | |
pub struct Points(pub Vec<Point>); | |
impl Hsb { | |
@@ -883,7 +885,7 @@ impl Points { | |
let margin_checker = MarginChecker::from_traits(traits); | |
let mut all_points = Vec::new(); | |
- for group in grouped_flow_lines.0 { | |
+ for (i, group) in grouped_flow_lines.0.into_iter().enumerate() { | |
if rng.odds(color_change_odds.group) { | |
primary_color_idx = | |
pick_next_color(&color_scheme.primary_seq, primary_color_idx, rng); | |
@@ -893,6 +895,7 @@ impl Points { | |
} | |
Self::build_group( | |
&mut all_points, | |
+ i as u32, | |
color_db, | |
group, | |
color_scheme, | |
@@ -915,6 +918,7 @@ impl Points { | |
#[allow(clippy::too_many_arguments)] | |
fn build_group( | |
dest: &mut Vec<Point>, | |
+ group_idx: u32, | |
color_db: &ColorDb, | |
group: FlowLineGroup, | |
color_scheme: &ColorScheme, | |
@@ -975,6 +979,7 @@ impl Points { | |
primary_color = perturb_color(primary_color, primary_color_spec, rng); | |
secondary_color = perturb_color(secondary_color, secondary_color_spec, rng); | |
dest.push(Point { | |
+ group_idx, | |
position: (x, y), | |
scale, | |
primary_color, | |
@@ -1103,12 +1108,36 @@ impl PaintCtx { | |
} | |
} | |
+#[derive(Debug, Copy, Clone)] | |
+enum PaintSpec { | |
+ All, | |
+ OnlyBg, | |
+ OnlyGroup(u32), | |
+} | |
+impl PaintSpec { | |
+ fn paint_bg(&self) -> bool { | |
+ match self { | |
+ PaintSpec::All => true, | |
+ PaintSpec::OnlyBg => true, | |
+ PaintSpec::OnlyGroup(_) => false, | |
+ } | |
+ } | |
+ fn prune_points(&self, points: &mut Points) { | |
+ match self { | |
+ PaintSpec::All => (), | |
+ PaintSpec::OnlyBg => points.0.clear(), | |
+ PaintSpec::OnlyGroup(desired) => points.0.retain(|p| p.group_idx == *desired), | |
+ } | |
+ } | |
+} | |
+ | |
fn paint( | |
canvas_width: i32, | |
traits: &Traits, | |
color_db: &ColorDb, | |
config: &Config, | |
mut points: Points, | |
+ paint_spec: PaintSpec, | |
color_scheme: &ColorScheme, | |
colors_used: &mut HashSet<ColorKey>, | |
rng: &mut Rng, | |
@@ -1126,6 +1155,7 @@ fn paint( | |
.expect("invalid background"); | |
&Hsb(spec.hue, spec.sat, spec.bright).to_rgb().to_source() | |
}; | |
+ paint_spec.prune_points(&mut points); | |
let hsteps: u32 = config.chunks.w.into(); | |
let vsteps: u32 = config.chunks.h.into(); | |
@@ -1176,14 +1206,16 @@ fn paint( | |
f64::from(top_px) * height_ratio + full_fvp.top(), | |
); | |
let mut pctx = PaintCtx::new(config, &fvp, canvas_width); | |
- pctx.dt.fill_rect( | |
- 0.0, | |
- 0.0, | |
- pctx.dt.width() as f32, | |
- pctx.dt.height() as f32, | |
- background_color, | |
- &DrawOptions::new(), | |
- ); | |
+ if paint_spec.paint_bg() { | |
+ pctx.dt.fill_rect( | |
+ 0.0, | |
+ 0.0, | |
+ pctx.dt.width() as f32, | |
+ pctx.dt.height() as f32, | |
+ background_color, | |
+ &DrawOptions::new(), | |
+ ); | |
+ } | |
let mut colors_used = HashSet::new(); | |
paint_onto_ctx( | |
&mut pctx, | |
@@ -1536,19 +1568,48 @@ pub fn draw(seed: &[u8; 32], color_db: &ColorDb, config: &Config, canvas_width: | |
); | |
eprintln!("laid out points"); | |
let num_points = points.0.len() as u64; | |
- let dt = paint( | |
+ let mut acc = paint( | |
canvas_width, | |
&traits, | |
color_db, | |
&config, | |
- points, | |
+ points.clone(), | |
+ PaintSpec::OnlyBg, | |
&color_scheme, | |
&mut colors_used, | |
- &mut rng, | |
+ &mut rng.clone(), | |
); | |
+ acc.write_png(format!("out-{:04}.png", 0)) | |
+ .expect("writing background"); | |
+ for group_idx in 0..points.0.last().map_or(0, |p| p.group_idx + 1) { | |
+ let points = points.clone(); | |
+ let dt = paint( | |
+ canvas_width, | |
+ &traits, | |
+ color_db, | |
+ &config, | |
+ points, | |
+ PaintSpec::OnlyGroup(group_idx), | |
+ &color_scheme, | |
+ &mut colors_used, | |
+ &mut rng, | |
+ ); | |
+ acc.draw_image_at( | |
+ 0.0, | |
+ 0.0, | |
+ &raqote::Image { | |
+ width: dt.width(), | |
+ height: dt.height(), | |
+ data: dt.get_data(), | |
+ }, | |
+ &DrawOptions::new(), | |
+ ); | |
+ acc.write_png(format!("out-{:04}.png", group_idx + 1)) | |
+ .expect(&format!("writing group {}", group_idx)); | |
+ } | |
eprintln!("drew points"); | |
Render { | |
- dt, | |
+ dt: acc, | |
num_points, | |
colors_used, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -framerate 3 -f image2 -i out-%04d.png out.webm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment