New node: Flatten Raster

This commit is contained in:
Keavon Chambers
2026-02-20 13:35:12 -08:00
parent ba177c4c5d
commit 5a1503fc98
2 changed files with 55 additions and 1 deletions

View File

@@ -156,6 +156,54 @@ pub trait IntoGraphicTable {
flatten_table(&mut output, content);
output
}
/// Deeply flattens any raster content within a graphic table, discarding non-raster content, and returning a table of only raster elements.
fn into_flattened_raster_table(self) -> Table<Raster<CPU>>
where
Self: std::marker::Sized,
{
let content = self.into_graphic_table();
fn flatten_table(output_raster_table: &mut Table<Raster<CPU>>, current_graphic_table: Table<Graphic>) {
for current_graphic_row in current_graphic_table.iter() {
let current_graphic = current_graphic_row.element.clone();
let source_node_id = *current_graphic_row.source_node_id;
match current_graphic {
// If we're allowed to recurse, flatten any tables we encounter
Graphic::Graphic(mut current_graphic_table) => {
// Apply the parent graphic's transform to all child elements
for graphic in current_graphic_table.iter_mut() {
*graphic.transform = *current_graphic_row.transform * *graphic.transform;
}
flatten_table(output_raster_table, current_graphic_table);
}
// Push any leaf RasterCPU elements we encounter
Graphic::RasterCPU(raster_table) => {
for current_raster_row in raster_table.iter() {
output_raster_table.push(TableRow {
element: current_raster_row.element.clone(),
transform: *current_graphic_row.transform * *current_raster_row.transform,
alpha_blending: AlphaBlending {
blend_mode: current_raster_row.alpha_blending.blend_mode,
opacity: current_graphic_row.alpha_blending.opacity * current_raster_row.alpha_blending.opacity,
fill: current_raster_row.alpha_blending.fill,
clip: current_raster_row.alpha_blending.clip,
},
source_node_id,
});
}
}
_ => {}
}
}
}
let mut output = Table::new();
flatten_table(&mut output, content);
output
}
}
impl IntoGraphicTable for Table<Graphic> {