mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-05 05:48:02 +00:00
Instance tables refactor part 7: Remove RasterDataType and add Raster<CPU>/Raster<GPU>
This commit is contained in:
parent
5cacab2e39
commit
6111440afd
34 changed files with 560 additions and 826 deletions
|
@ -30,8 +30,9 @@ use glam::{DAffine2, DVec2, IVec2};
|
||||||
use graph_craft::document::value::TaggedValue;
|
use graph_craft::document::value::TaggedValue;
|
||||||
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
|
use graph_craft::document::{NodeId, NodeInput, NodeNetwork, OldNodeNetwork};
|
||||||
use graphene_core::raster::BlendMode;
|
use graphene_core::raster::BlendMode;
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
use graphene_core::raster_types::RasterDataTable;
|
||||||
use graphene_core::vector::style::ViewMode;
|
use graphene_core::vector::style::ViewMode;
|
||||||
|
use graphene_std::raster_types::Raster;
|
||||||
use graphene_std::renderer::{ClickTarget, Quad};
|
use graphene_std::renderer::{ClickTarget, Quad};
|
||||||
use graphene_std::vector::{PointId, path_bool_lib};
|
use graphene_std::vector::{PointId, path_bool_lib};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -864,7 +865,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||||
|
|
||||||
responses.add(DocumentMessage::AddTransaction);
|
responses.add(DocumentMessage::AddTransaction);
|
||||||
|
|
||||||
let layer = graph_modification_utils::new_image_layer(RasterDataTable::new(image), layer_node_id, self.new_layer_parent(true), responses);
|
let layer = graph_modification_utils::new_image_layer(RasterDataTable::new(Raster::new_cpu(image)), layer_node_id, self.new_layer_parent(true), responses);
|
||||||
|
|
||||||
if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
responses.add(NodeGraphMessage::SetDisplayName {
|
responses.add(NodeGraphMessage::SetDisplayName {
|
||||||
|
|
|
@ -5,14 +5,14 @@ use crate::messages::prelude::*;
|
||||||
use bezier_rs::Subpath;
|
use bezier_rs::Subpath;
|
||||||
use glam::{DAffine2, DVec2, IVec2};
|
use glam::{DAffine2, DVec2, IVec2};
|
||||||
use graph_craft::document::NodeId;
|
use graph_craft::document::NodeId;
|
||||||
|
use graphene_core::Artboard;
|
||||||
use graphene_core::raster::BlendMode;
|
use graphene_core::raster::BlendMode;
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
use graphene_core::raster_types::{CPU, RasterDataTable};
|
||||||
use graphene_core::text::{Font, TypesettingConfig};
|
use graphene_core::text::{Font, TypesettingConfig};
|
||||||
use graphene_core::vector::PointId;
|
use graphene_core::vector::PointId;
|
||||||
use graphene_core::vector::VectorModificationType;
|
use graphene_core::vector::VectorModificationType;
|
||||||
use graphene_core::vector::brush_stroke::BrushStroke;
|
use graphene_core::vector::brush_stroke::BrushStroke;
|
||||||
use graphene_core::vector::style::{Fill, Stroke};
|
use graphene_core::vector::style::{Fill, Stroke};
|
||||||
use graphene_core::{Artboard, Color};
|
|
||||||
|
|
||||||
#[impl_message(Message, DocumentMessage, GraphOperation)]
|
#[impl_message(Message, DocumentMessage, GraphOperation)]
|
||||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
|
@ -66,7 +66,7 @@ pub enum GraphOperationMessage {
|
||||||
},
|
},
|
||||||
NewBitmapLayer {
|
NewBitmapLayer {
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
image_frame: RasterDataTable<Color>,
|
image_frame: RasterDataTable<CPU>,
|
||||||
parent: LayerNodeIdentifier,
|
parent: LayerNodeIdentifier,
|
||||||
insert_index: usize,
|
insert_index: usize,
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,13 +8,13 @@ use glam::{DAffine2, DVec2, IVec2};
|
||||||
use graph_craft::concrete;
|
use graph_craft::concrete;
|
||||||
use graph_craft::document::value::TaggedValue;
|
use graph_craft::document::value::TaggedValue;
|
||||||
use graph_craft::document::{NodeId, NodeInput};
|
use graph_craft::document::{NodeId, NodeInput};
|
||||||
|
use graphene_core::Artboard;
|
||||||
use graphene_core::raster::BlendMode;
|
use graphene_core::raster::BlendMode;
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
use graphene_core::raster_types::{CPU, RasterDataTable};
|
||||||
use graphene_core::text::{Font, TypesettingConfig};
|
use graphene_core::text::{Font, TypesettingConfig};
|
||||||
use graphene_core::vector::brush_stroke::BrushStroke;
|
use graphene_core::vector::brush_stroke::BrushStroke;
|
||||||
use graphene_core::vector::style::{Fill, Stroke};
|
use graphene_core::vector::style::{Fill, Stroke};
|
||||||
use graphene_core::vector::{PointId, VectorModificationType};
|
use graphene_core::vector::{PointId, VectorModificationType};
|
||||||
use graphene_core::{Artboard, Color};
|
|
||||||
use graphene_std::GraphicGroupTable;
|
use graphene_std::GraphicGroupTable;
|
||||||
use graphene_std::vector::{VectorData, VectorDataTable};
|
use graphene_std::vector::{VectorData, VectorDataTable};
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ impl<'a> ModifyInputsContext<'a> {
|
||||||
self.network_interface.move_node_to_chain_start(&stroke_id, layer, &[]);
|
self.network_interface.move_node_to_chain_start(&stroke_id, layer, &[]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_image_data(&mut self, image_frame: RasterDataTable<Color>, layer: LayerNodeIdentifier) {
|
pub fn insert_image_data(&mut self, image_frame: RasterDataTable<CPU>, layer: LayerNodeIdentifier) {
|
||||||
let transform = resolve_document_node_type("Transform").expect("Transform node does not exist").default_node_template();
|
let transform = resolve_document_node_type("Transform").expect("Transform node does not exist").default_node_template();
|
||||||
let image = resolve_document_node_type("Image")
|
let image = resolve_document_node_type("Image")
|
||||||
.expect("Image node does not exist")
|
.expect("Image node does not exist")
|
||||||
|
|
|
@ -15,8 +15,8 @@ use graph_craft::concrete;
|
||||||
use graph_craft::document::value::*;
|
use graph_craft::document::value::*;
|
||||||
use graph_craft::document::*;
|
use graph_craft::document::*;
|
||||||
use graphene_core::raster::brush_cache::BrushCache;
|
use graphene_core::raster::brush_cache::BrushCache;
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
|
||||||
use graphene_core::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, NoiseType, RedGreenBlueAlpha};
|
use graphene_core::raster::{CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, NoiseType, RedGreenBlueAlpha};
|
||||||
|
use graphene_core::raster_types::{CPU, RasterDataTable};
|
||||||
use graphene_core::text::{Font, TypesettingConfig};
|
use graphene_core::text::{Font, TypesettingConfig};
|
||||||
use graphene_core::transform::Footprint;
|
use graphene_core::transform::Footprint;
|
||||||
use graphene_core::vector::VectorDataTable;
|
use graphene_core::vector::VectorDataTable;
|
||||||
|
@ -608,7 +608,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
exports: vec![NodeInput::node(NodeId(3), 0)],
|
exports: vec![NodeInput::node(NodeId(3), 0)],
|
||||||
nodes: [
|
nodes: [
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![NodeInput::network(concrete!(RasterDataTable<Color>), 0)],
|
inputs: vec![NodeInput::network(concrete!(RasterDataTable<CPU>), 0)],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<_, RasterDataTable<SRGBA8>>")),
|
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<_, RasterDataTable<SRGBA8>>")),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
@ -852,7 +852,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
nodes: [
|
nodes: [
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![
|
inputs: vec![
|
||||||
NodeInput::network(concrete!(RasterDataTable<Color>), 0),
|
NodeInput::network(concrete!(RasterDataTable<CPU>), 0),
|
||||||
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Red), false),
|
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Red), false),
|
||||||
],
|
],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::raster::adjustments::ExtractChannelNode")),
|
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::raster::adjustments::ExtractChannelNode")),
|
||||||
|
@ -861,7 +861,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
},
|
},
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![
|
inputs: vec![
|
||||||
NodeInput::network(concrete!(RasterDataTable<Color>), 0),
|
NodeInput::network(concrete!(RasterDataTable<CPU>), 0),
|
||||||
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Green), false),
|
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Green), false),
|
||||||
],
|
],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::raster::adjustments::ExtractChannelNode")),
|
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::raster::adjustments::ExtractChannelNode")),
|
||||||
|
@ -870,7 +870,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
},
|
},
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![
|
inputs: vec![
|
||||||
NodeInput::network(concrete!(RasterDataTable<Color>), 0),
|
NodeInput::network(concrete!(RasterDataTable<CPU>), 0),
|
||||||
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Blue), false),
|
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Blue), false),
|
||||||
],
|
],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::raster::adjustments::ExtractChannelNode")),
|
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::raster::adjustments::ExtractChannelNode")),
|
||||||
|
@ -879,7 +879,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
},
|
},
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![
|
inputs: vec![
|
||||||
NodeInput::network(concrete!(RasterDataTable<Color>), 0),
|
NodeInput::network(concrete!(RasterDataTable<CPU>), 0),
|
||||||
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Alpha), false),
|
NodeInput::value(TaggedValue::RedGreenBlueAlpha(RedGreenBlueAlpha::Alpha), false),
|
||||||
],
|
],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::raster::adjustments::ExtractChannelNode")),
|
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::raster::adjustments::ExtractChannelNode")),
|
||||||
|
@ -959,13 +959,13 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
exports: vec![NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(1), 0)],
|
exports: vec![NodeInput::node(NodeId(0), 0), NodeInput::node(NodeId(1), 0)],
|
||||||
nodes: [
|
nodes: [
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![NodeInput::network(concrete!(RasterDataTable<Color>), 0), NodeInput::value(TaggedValue::XY(XY::X), false)],
|
inputs: vec![NodeInput::network(concrete!(RasterDataTable<CPU>), 0), NodeInput::value(TaggedValue::XY(XY::X), false)],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::ExtractXyNode")),
|
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::ExtractXyNode")),
|
||||||
manual_composition: Some(generic!(T)),
|
manual_composition: Some(generic!(T)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![NodeInput::network(concrete!(RasterDataTable<Color>), 0), NodeInput::value(TaggedValue::XY(XY::Y), false)],
|
inputs: vec![NodeInput::network(concrete!(RasterDataTable<CPU>), 0), NodeInput::value(TaggedValue::XY(XY::Y), false)],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::ExtractXyNode")),
|
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::ExtractXyNode")),
|
||||||
manual_composition: Some(generic!(T)),
|
manual_composition: Some(generic!(T)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -1029,7 +1029,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
exports: vec![NodeInput::node(NodeId(0), 0)],
|
exports: vec![NodeInput::node(NodeId(0), 0)],
|
||||||
nodes: vec![DocumentNode {
|
nodes: vec![DocumentNode {
|
||||||
inputs: vec![
|
inputs: vec![
|
||||||
NodeInput::network(concrete!(RasterDataTable<Color>), 0),
|
NodeInput::network(concrete!(RasterDataTable<CPU>), 0),
|
||||||
NodeInput::network(concrete!(Vec<graphene_core::vector::brush_stroke::BrushStroke>), 1),
|
NodeInput::network(concrete!(Vec<graphene_core::vector::brush_stroke::BrushStroke>), 1),
|
||||||
NodeInput::network(concrete!(BrushCache), 2),
|
NodeInput::network(concrete!(BrushCache), 2),
|
||||||
],
|
],
|
||||||
|
@ -1784,7 +1784,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![NodeInput::network(concrete!(RasterDataTable<Color>), 0), NodeInput::node(NodeId(0), 0)],
|
inputs: vec![NodeInput::network(concrete!(RasterDataTable<CPU>), 0), NodeInput::node(NodeId(0), 0)],
|
||||||
manual_composition: Some(generic!(T)),
|
manual_composition: Some(generic!(T)),
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("wgpu_executor::UploadTextureNode")),
|
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("wgpu_executor::UploadTextureNode")),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -2646,7 +2646,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
|
||||||
// exports: vec![NodeInput::node(NodeId(1), 0)],
|
// exports: vec![NodeInput::node(NodeId(1), 0)],
|
||||||
// nodes: [
|
// nodes: [
|
||||||
// DocumentNode {
|
// DocumentNode {
|
||||||
// inputs: vec![NodeInput::network(concrete!(RasterDataTable<Color>), 0)],
|
// inputs: vec![NodeInput::network(concrete!(RasterDataTable<CPU>), 0)],
|
||||||
// implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode"),
|
// implementation: DocumentNodeImplementation::proto("graphene_core::memo::MonitorNode"),
|
||||||
// manual_composition: Some(concrete!(Context)),
|
// manual_composition: Some(concrete!(Context)),
|
||||||
// skip_deduplication: true,
|
// skip_deduplication: true,
|
||||||
|
|
|
@ -12,24 +12,23 @@ use graph_craft::Type;
|
||||||
use graph_craft::document::value::TaggedValue;
|
use graph_craft::document::value::TaggedValue;
|
||||||
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput};
|
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput};
|
||||||
use graphene_core::raster::curve::Curve;
|
use graphene_core::raster::curve::Curve;
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
|
||||||
use graphene_core::raster::{
|
use graphene_core::raster::{
|
||||||
BlendMode, CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, LuminanceCalculation, NoiseType, RedGreenBlue, RedGreenBlueAlpha, RelativeAbsolute,
|
BlendMode, CellularDistanceFunction, CellularReturnType, Color, DomainWarpType, FractalType, LuminanceCalculation, NoiseType, RedGreenBlue, RedGreenBlueAlpha, RelativeAbsolute,
|
||||||
SelectiveColorChoice,
|
SelectiveColorChoice,
|
||||||
};
|
};
|
||||||
|
use graphene_core::raster_types::{CPU, GPU, RasterDataTable};
|
||||||
use graphene_core::text::Font;
|
use graphene_core::text::Font;
|
||||||
use graphene_core::vector::generator_nodes::grid;
|
use graphene_core::vector::generator_nodes::grid;
|
||||||
use graphene_core::vector::misc::CentroidType;
|
use graphene_core::vector::misc::CentroidType;
|
||||||
use graphene_core::vector::style::{GradientType, LineCap, LineJoin};
|
use graphene_core::vector::style::{GradientType, LineCap, LineJoin};
|
||||||
use graphene_std::animation::RealTimeMode;
|
use graphene_std::animation::RealTimeMode;
|
||||||
use graphene_std::application_io::TextureDataTable;
|
|
||||||
use graphene_std::ops::XY;
|
use graphene_std::ops::XY;
|
||||||
use graphene_std::transform::{Footprint, ReferencePoint};
|
use graphene_std::transform::{Footprint, ReferencePoint};
|
||||||
use graphene_std::vector::VectorDataTable;
|
use graphene_std::vector::VectorDataTable;
|
||||||
use graphene_std::vector::misc::ArcType;
|
use graphene_std::vector::misc::ArcType;
|
||||||
use graphene_std::vector::misc::{BooleanOperation, GridType};
|
use graphene_std::vector::misc::{BooleanOperation, GridType};
|
||||||
use graphene_std::vector::style::{Fill, FillChoice, FillType, GradientStops};
|
use graphene_std::vector::style::{Fill, FillChoice, FillType, GradientStops};
|
||||||
use graphene_std::{GraphicGroupTable, NodeInputDecleration, RasterDataType};
|
use graphene_std::{GraphicGroupTable, NodeInputDecleration};
|
||||||
|
|
||||||
pub(crate) fn string_properties(text: &str) -> Vec<LayoutGroup> {
|
pub(crate) fn string_properties(text: &str) -> Vec<LayoutGroup> {
|
||||||
let widget = TextLabel::new(text).widget_holder();
|
let widget = TextLabel::new(text).widget_holder();
|
||||||
|
@ -190,7 +189,7 @@ pub(crate) fn property_from_type(
|
||||||
// GRAPHICAL DATA TYPES
|
// GRAPHICAL DATA TYPES
|
||||||
// ====================
|
// ====================
|
||||||
Some(x) if x == TypeId::of::<VectorDataTable>() => vector_data_widget(default_info).into(),
|
Some(x) if x == TypeId::of::<VectorDataTable>() => vector_data_widget(default_info).into(),
|
||||||
Some(x) if x == TypeId::of::<RasterDataType>() || x == TypeId::of::<RasterDataTable<Color>>() || x == TypeId::of::<TextureDataTable>() => raster_widget(default_info).into(),
|
Some(x) if x == TypeId::of::<RasterDataTable<CPU>>() || x == TypeId::of::<RasterDataTable<GPU>>() => raster_widget(default_info).into(),
|
||||||
Some(x) if x == TypeId::of::<GraphicGroupTable>() => group_widget(default_info).into(),
|
Some(x) if x == TypeId::of::<GraphicGroupTable>() => group_widget(default_info).into(),
|
||||||
// ============
|
// ============
|
||||||
// STRUCT TYPES
|
// STRUCT TYPES
|
||||||
|
|
|
@ -156,7 +156,8 @@ impl InstanceLayout for GraphicElement {
|
||||||
match self {
|
match self {
|
||||||
Self::GraphicGroup(instances) => instances.identifier(),
|
Self::GraphicGroup(instances) => instances.identifier(),
|
||||||
Self::VectorData(instances) => instances.identifier(),
|
Self::VectorData(instances) => instances.identifier(),
|
||||||
Self::RasterDataType(_) => "RasterDataType".to_string(),
|
Self::RasterDataCPU(_) => "RasterDataCPU".to_string(),
|
||||||
|
Self::RasterDataGPU(_) => "RasterDataGPU".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Don't put a breadcrumb for GraphicElement
|
// Don't put a breadcrumb for GraphicElement
|
||||||
|
@ -167,7 +168,8 @@ impl InstanceLayout for GraphicElement {
|
||||||
match self {
|
match self {
|
||||||
Self::GraphicGroup(instances) => instances.layout_with_breadcrumb(data),
|
Self::GraphicGroup(instances) => instances.layout_with_breadcrumb(data),
|
||||||
Self::VectorData(instances) => instances.layout_with_breadcrumb(data),
|
Self::VectorData(instances) => instances.layout_with_breadcrumb(data),
|
||||||
Self::RasterDataType(_) => label("Raster frame not supported"),
|
Self::RasterDataCPU(_) => label("Raster frame not supported"),
|
||||||
|
Self::RasterDataGPU(_) => label("Raster frame not supported"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use graph_craft::document::value::TaggedValue;
|
||||||
use graph_craft::document::{NodeId, NodeInput};
|
use graph_craft::document::{NodeId, NodeInput};
|
||||||
use graphene_core::Color;
|
use graphene_core::Color;
|
||||||
use graphene_core::raster::BlendMode;
|
use graphene_core::raster::BlendMode;
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
use graphene_core::raster_types::{CPU, GPU, RasterDataTable};
|
||||||
use graphene_core::text::{Font, TypesettingConfig};
|
use graphene_core::text::{Font, TypesettingConfig};
|
||||||
use graphene_core::vector::style::Gradient;
|
use graphene_core::vector::style::Gradient;
|
||||||
use graphene_std::vector::{ManipulatorPointId, PointId, SegmentId, VectorModificationType};
|
use graphene_std::vector::{ManipulatorPointId, PointId, SegmentId, VectorModificationType};
|
||||||
|
@ -207,7 +207,7 @@ pub fn new_vector_layer(subpaths: Vec<Subpath<PointId>>, id: NodeId, parent: Lay
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new bitmap layer.
|
/// Create a new bitmap layer.
|
||||||
pub fn new_image_layer(image_frame: RasterDataTable<Color>, id: NodeId, parent: LayerNodeIdentifier, responses: &mut VecDeque<Message>) -> LayerNodeIdentifier {
|
pub fn new_image_layer(image_frame: RasterDataTable<CPU>, id: NodeId, parent: LayerNodeIdentifier, responses: &mut VecDeque<Message>) -> LayerNodeIdentifier {
|
||||||
let insert_index = 0;
|
let insert_index = 0;
|
||||||
responses.add(GraphOperationMessage::NewBitmapLayer {
|
responses.add(GraphOperationMessage::NewBitmapLayer {
|
||||||
id,
|
id,
|
||||||
|
@ -425,8 +425,6 @@ impl<'a> NodeGraphLayer<'a> {
|
||||||
pub fn is_raster_layer(layer: LayerNodeIdentifier, network_interface: &mut NodeNetworkInterface) -> bool {
|
pub fn is_raster_layer(layer: LayerNodeIdentifier, network_interface: &mut NodeNetworkInterface) -> bool {
|
||||||
let layer_input_type = network_interface.input_type(&InputConnector::node(layer.to_node(), 1), &[]).0.nested_type().clone();
|
let layer_input_type = network_interface.input_type(&InputConnector::node(layer.to_node(), 1), &[]).0.nested_type().clone();
|
||||||
|
|
||||||
layer_input_type == concrete!(graphene_std::RasterDataType)
|
layer_input_type == concrete!(RasterDataTable<CPU>) || layer_input_type == concrete!(RasterDataTable<GPU>)
|
||||||
|| layer_input_type == concrete!(graphene_core::raster::image::RasterDataTable<graphene_core::Color>)
|
|
||||||
|| layer_input_type == concrete!(graphene_core::application_io::TextureDataTable)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::instances::Instances;
|
|
||||||
use crate::text::FontCache;
|
use crate::text::FontCache;
|
||||||
use crate::transform::Footprint;
|
use crate::transform::Footprint;
|
||||||
use crate::vector::style::ViewMode;
|
use crate::vector::style::ViewMode;
|
||||||
|
@ -53,7 +52,7 @@ impl Size for web_sys::HtmlCanvasElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type TextureDataTable = Instances<ImageTexture>;
|
// pub type TextureDataTable = Instances<ImageTexture>;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ImageTexture {
|
pub struct ImageTexture {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::application_io::{ImageTexture, TextureDataTable};
|
|
||||||
use crate::instances::{Instance, Instances};
|
use crate::instances::{Instance, Instances};
|
||||||
use crate::raster::BlendMode;
|
use crate::raster::BlendMode;
|
||||||
use crate::raster::image::{Image, RasterDataTable};
|
use crate::raster::image::Image;
|
||||||
|
use crate::raster_types::{CPU, GPU, Raster, RasterDataTable};
|
||||||
use crate::transform::TransformMut;
|
use crate::transform::TransformMut;
|
||||||
use crate::uuid::NodeId;
|
use crate::uuid::NodeId;
|
||||||
use crate::vector::{VectorData, VectorDataTable};
|
use crate::vector::{VectorData, VectorDataTable};
|
||||||
|
@ -124,22 +124,17 @@ impl From<VectorDataTable> for GraphicGroupTable {
|
||||||
}
|
}
|
||||||
impl From<Image<Color>> for GraphicGroupTable {
|
impl From<Image<Color>> for GraphicGroupTable {
|
||||||
fn from(image: Image<Color>) -> Self {
|
fn from(image: Image<Color>) -> Self {
|
||||||
Self::new(GraphicElement::RasterDataType(RasterDataType::RasterData(RasterDataTable::new(image))))
|
Self::new(GraphicElement::RasterDataCPU(RasterDataTable::<CPU>::new(Raster::new_cpu(image))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<RasterDataTable<Color>> for GraphicGroupTable {
|
impl From<RasterDataTable<CPU>> for GraphicGroupTable {
|
||||||
fn from(image_frame: RasterDataTable<Color>) -> Self {
|
fn from(raster_data_table: RasterDataTable<CPU>) -> Self {
|
||||||
Self::new(GraphicElement::RasterDataType(RasterDataType::RasterData(image_frame)))
|
Self::new(GraphicElement::RasterDataCPU(raster_data_table))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<ImageTexture> for GraphicGroupTable {
|
impl From<RasterDataTable<GPU>> for GraphicGroupTable {
|
||||||
fn from(image_texture: ImageTexture) -> Self {
|
fn from(raster_data_table: RasterDataTable<GPU>) -> Self {
|
||||||
Self::new(GraphicElement::RasterDataType(RasterDataType::TextureData(TextureDataTable::new(image_texture))))
|
Self::new(GraphicElement::RasterDataGPU(raster_data_table))
|
||||||
}
|
|
||||||
}
|
|
||||||
impl From<TextureDataTable> for GraphicGroupTable {
|
|
||||||
fn from(texture_frame: TextureDataTable) -> Self {
|
|
||||||
Self::new(GraphicElement::RasterDataType(RasterDataType::TextureData(texture_frame)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +146,8 @@ pub enum GraphicElement {
|
||||||
GraphicGroup(GraphicGroupTable),
|
GraphicGroup(GraphicGroupTable),
|
||||||
/// A vector shape, equivalent to the SVG <path> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
|
/// A vector shape, equivalent to the SVG <path> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
|
||||||
VectorData(VectorDataTable),
|
VectorData(VectorDataTable),
|
||||||
RasterDataType(RasterDataType),
|
RasterDataCPU(RasterDataTable<CPU>),
|
||||||
|
RasterDataGPU(RasterDataTable<GPU>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for GraphicElement {
|
impl Default for GraphicElement {
|
||||||
|
@ -189,51 +185,86 @@ impl GraphicElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_raster(&self) -> Option<&RasterDataType> {
|
pub fn as_raster(&self) -> Option<&RasterDataTable<CPU>> {
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::RasterDataType(raster) => Some(raster),
|
GraphicElement::RasterDataCPU(raster) => Some(raster),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_raster_mut(&mut self) -> Option<&mut RasterDataType> {
|
pub fn as_raster_mut(&mut self) -> Option<&mut RasterDataTable<CPU>> {
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::RasterDataType(raster) => Some(raster),
|
GraphicElement::RasterDataCPU(raster) => Some(raster),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename to Raster
|
// // TODO: Rename to Raster
|
||||||
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
|
// #[derive(Clone, Debug, Hash, PartialEq, DynAny)]
|
||||||
pub enum RasterDataType {
|
// pub enum RasterDataType {
|
||||||
/// A CPU-based bitmap image with a finite position and extent, equivalent to the SVG <image> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image
|
// /// A CPU-based bitmap image with a finite position and extent, equivalent to the SVG <image> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image
|
||||||
// TODO: Rename to ImageTable
|
// // TODO: Rename to ImageTable
|
||||||
RasterData(RasterDataTable<Color>),
|
// RasterData(RasterDataTable<CPU>),
|
||||||
/// A GPU texture with a finite position and extent
|
// /// A GPU texture with a finite position and extent
|
||||||
// TODO: Rename to ImageTextureTable
|
// // TODO: Rename to ImageTextureTable
|
||||||
TextureData(TextureDataTable),
|
// TextureData(TextureDataTable),
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl<'de> serde::Deserialize<'de> for RasterDataType {
|
// impl<'de> serde::Deserialize<'de> for RasterDataType {
|
||||||
|
// fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
// where
|
||||||
|
// D: serde::Deserializer<'de>,
|
||||||
|
// {
|
||||||
|
// Ok(RasterDataType::RasterData(RasterDataTable::new(Image::deserialize(deserializer)?)))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// impl serde::Serialize for RasterDataType {
|
||||||
|
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
// where
|
||||||
|
// S: serde::Serializer,
|
||||||
|
// {
|
||||||
|
// match self {
|
||||||
|
// RasterDataType::RasterData(_) => self.serialize(serializer),
|
||||||
|
// RasterDataType::TextureData(_) => todo!(),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
impl<'de> serde::Deserialize<'de> for Raster<CPU> {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: serde::Deserializer<'de>,
|
D: serde::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
Ok(RasterDataType::RasterData(RasterDataTable::new(Image::deserialize(deserializer)?)))
|
Ok(Raster::new_cpu(Image::deserialize(deserializer)?))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl serde::Serialize for RasterDataType {
|
impl serde::Serialize for Raster<CPU> {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: serde::Serializer,
|
S: serde::Serializer,
|
||||||
{
|
{
|
||||||
match self {
|
self.data().serialize(serializer)
|
||||||
RasterDataType::RasterData(_) => self.serialize(serializer),
|
|
||||||
RasterDataType::TextureData(_) => todo!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl<'de> serde::Deserialize<'de> for Raster<GPU> {
|
||||||
|
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl serde::Serialize for Raster<GPU> {
|
||||||
|
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Some [`ArtboardData`] with some optional clipping bounds that can be exported.
|
/// Some [`ArtboardData`] with some optional clipping bounds that can be exported.
|
||||||
|
@ -324,8 +355,8 @@ async fn to_element<Data: Into<GraphicElement> + 'n>(
|
||||||
#[implementations(
|
#[implementations(
|
||||||
GraphicGroupTable,
|
GraphicGroupTable,
|
||||||
VectorDataTable,
|
VectorDataTable,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
TextureDataTable,
|
RasterDataTable<GPU>,
|
||||||
)]
|
)]
|
||||||
data: Data,
|
data: Data,
|
||||||
) -> GraphicElement {
|
) -> GraphicElement {
|
||||||
|
@ -338,8 +369,8 @@ async fn to_group<Data: Into<GraphicGroupTable> + 'n>(
|
||||||
#[implementations(
|
#[implementations(
|
||||||
GraphicGroupTable,
|
GraphicGroupTable,
|
||||||
VectorDataTable,
|
VectorDataTable,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
TextureDataTable,
|
RasterDataTable<GPU>,
|
||||||
)]
|
)]
|
||||||
element: Data,
|
element: Data,
|
||||||
) -> GraphicGroupTable {
|
) -> GraphicGroupTable {
|
||||||
|
@ -391,8 +422,8 @@ async fn to_artboard<Data: Into<GraphicGroupTable> + 'n>(
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Context -> GraphicGroupTable,
|
Context -> GraphicGroupTable,
|
||||||
Context -> VectorDataTable,
|
Context -> VectorDataTable,
|
||||||
Context -> RasterDataTable<Color>,
|
Context -> RasterDataTable<CPU>,
|
||||||
Context -> TextureDataTable,
|
Context -> RasterDataTable<GPU>,
|
||||||
)]
|
)]
|
||||||
contents: impl Node<Context<'static>, Output = Data>,
|
contents: impl Node<Context<'static>, Output = Data>,
|
||||||
label: String,
|
label: String,
|
||||||
|
@ -437,24 +468,28 @@ async fn append_artboard(_ctx: impl Ctx, mut artboards: ArtboardGroupTable, artb
|
||||||
|
|
||||||
// TODO: Remove this one
|
// TODO: Remove this one
|
||||||
impl From<Image<Color>> for GraphicElement {
|
impl From<Image<Color>> for GraphicElement {
|
||||||
fn from(image_frame: Image<Color>) -> Self {
|
fn from(raster_data: Image<Color>) -> Self {
|
||||||
GraphicElement::RasterDataType(RasterDataType::RasterData(RasterDataTable::new(image_frame)))
|
GraphicElement::RasterDataCPU(RasterDataTable::<CPU>::new(Raster::new_cpu(raster_data)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<RasterDataTable<Color>> for GraphicElement {
|
impl From<RasterDataTable<CPU>> for GraphicElement {
|
||||||
fn from(image_frame: RasterDataTable<Color>) -> Self {
|
fn from(raster_data: RasterDataTable<CPU>) -> Self {
|
||||||
GraphicElement::RasterDataType(RasterDataType::RasterData(image_frame))
|
GraphicElement::RasterDataCPU(raster_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Remove this one
|
impl From<RasterDataTable<GPU>> for GraphicElement {
|
||||||
impl From<ImageTexture> for GraphicElement {
|
fn from(raster_data: RasterDataTable<GPU>) -> Self {
|
||||||
fn from(image_texture: ImageTexture) -> Self {
|
GraphicElement::RasterDataGPU(raster_data)
|
||||||
GraphicElement::RasterDataType(RasterDataType::TextureData(TextureDataTable::new(image_texture)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<TextureDataTable> for GraphicElement {
|
impl From<Raster<CPU>> for GraphicElement {
|
||||||
fn from(texture_data: TextureDataTable) -> Self {
|
fn from(raster_data: Raster<CPU>) -> Self {
|
||||||
GraphicElement::RasterDataType(RasterDataType::TextureData(texture_data))
|
GraphicElement::RasterDataCPU(RasterDataTable::new(raster_data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<Raster<GPU>> for GraphicElement {
|
||||||
|
fn from(raster_data: Raster<GPU>) -> Self {
|
||||||
|
GraphicElement::RasterDataGPU(RasterDataTable::new(raster_data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Remove this one
|
// TODO: Remove this one
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
mod quad;
|
mod quad;
|
||||||
mod rect;
|
mod rect;
|
||||||
|
|
||||||
use crate::raster::image::RasterDataTable;
|
|
||||||
use crate::raster::{BlendMode, Image};
|
use crate::raster::{BlendMode, Image};
|
||||||
|
use crate::raster_types::{CPU, GPU, RasterDataTable};
|
||||||
use crate::transform::{Footprint, Transform};
|
use crate::transform::{Footprint, Transform};
|
||||||
use crate::uuid::{NodeId, generate_uuid};
|
use crate::uuid::{NodeId, generate_uuid};
|
||||||
use crate::vector::style::{Fill, Stroke, ViewMode};
|
use crate::vector::style::{Fill, Stroke, ViewMode};
|
||||||
use crate::vector::{PointId, VectorDataTable};
|
use crate::vector::{PointId, VectorDataTable};
|
||||||
use crate::{Artboard, ArtboardGroupTable, Color, GraphicElement, GraphicGroupTable, RasterDataType};
|
use crate::{Artboard, ArtboardGroupTable, Color, GraphicElement, GraphicGroupTable};
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use bezier_rs::Subpath;
|
use bezier_rs::Subpath;
|
||||||
use dyn_any::DynAny;
|
use dyn_any::DynAny;
|
||||||
|
@ -843,7 +843,7 @@ impl GraphicElementRendered for ArtboardGroupTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicElementRendered for RasterDataTable<Color> {
|
impl GraphicElementRendered for RasterDataTable<CPU> {
|
||||||
fn render_svg(&self, render: &mut SvgRender, _render_params: &RenderParams) {
|
fn render_svg(&self, render: &mut SvgRender, _render_params: &RenderParams) {
|
||||||
for instance in self.instance_ref_iter() {
|
for instance in self.instance_ref_iter() {
|
||||||
let transform = *instance.transform * render.transform;
|
let transform = *instance.transform * render.transform;
|
||||||
|
@ -923,12 +923,9 @@ impl GraphicElementRendered for RasterDataTable<Color> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicElementRendered for RasterDataType {
|
impl GraphicElementRendered for RasterDataTable<GPU> {
|
||||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
fn render_svg(&self, _render: &mut SvgRender, _render_params: &RenderParams) {
|
||||||
match self {
|
log::warn!("tried to render texture as an svg");
|
||||||
RasterDataType::RasterData(image) => image.render_svg(render, render_params),
|
|
||||||
RasterDataType::TextureData(_) => log::warn!("tried to render texture as an svg"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "vello")]
|
#[cfg(feature = "vello")]
|
||||||
|
@ -952,67 +949,36 @@ impl GraphicElementRendered for RasterDataType {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match self {
|
for instance in self.instance_ref_iter() {
|
||||||
RasterDataType::RasterData(image) => {
|
let image = vello::peniko::Image::new(vec![].into(), peniko::Format::Rgba8, instance.instance.data().width(), instance.instance.data().height()).with_extend(peniko::Extend::Repeat);
|
||||||
for instance in image.instance_ref_iter() {
|
|
||||||
let image = &instance.instance;
|
|
||||||
if image.data.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let image = vello::peniko::Image::new(image.to_flat_u8().0.into(), peniko::Format::Rgba8, image.width, image.height).with_extend(peniko::Extend::Repeat);
|
|
||||||
|
|
||||||
render_stuff(image, *instance.transform, *instance.alpha_blending);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RasterDataType::TextureData(image_texture) => {
|
|
||||||
for instance in image_texture.instance_ref_iter() {
|
|
||||||
let image =
|
|
||||||
vello::peniko::Image::new(vec![].into(), peniko::Format::Rgba8, instance.instance.texture.width(), instance.instance.texture.height()).with_extend(peniko::Extend::Repeat);
|
|
||||||
|
|
||||||
let id = image.data.id();
|
let id = image.data.id();
|
||||||
context.resource_overrides.insert(id, instance.instance.texture.clone());
|
context.resource_overrides.insert(id, instance.instance.data_owned());
|
||||||
|
|
||||||
render_stuff(image, *instance.transform, *instance.alpha_blending);
|
render_stuff(image, *instance.transform, *instance.alpha_blending);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> {
|
fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||||
let calculate_transform = |instance_transform| {
|
self.instance_ref_iter()
|
||||||
let transform: DAffine2 = transform * instance_transform;
|
.flat_map(|instance| {
|
||||||
|
let transform = transform * *instance.transform;
|
||||||
(transform.matrix2.determinant() != 0.).then(|| (transform * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box())
|
(transform.matrix2.determinant() != 0.).then(|| (transform * Quad::from_box([DVec2::ZERO, DVec2::ONE])).bounding_box())
|
||||||
};
|
})
|
||||||
|
.reduce(Quad::combine_bounds)
|
||||||
match self {
|
|
||||||
RasterDataType::RasterData(instances) => instances.instance_ref_iter().flat_map(|instance| calculate_transform(*instance.transform)).reduce(Quad::combine_bounds),
|
|
||||||
RasterDataType::TextureData(instances) => instances.instance_ref_iter().flat_map(|instance| calculate_transform(*instance.transform)).reduce(Quad::combine_bounds),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_metadata(&self, metadata: &mut RenderMetadata, footprint: Footprint, element_id: Option<NodeId>) {
|
fn collect_metadata(&self, metadata: &mut RenderMetadata, footprint: Footprint, element_id: Option<NodeId>) {
|
||||||
let Some(element_id) = element_id else { return };
|
let Some(element_id) = element_id else { return };
|
||||||
|
|
||||||
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
||||||
|
|
||||||
metadata.click_targets.insert(element_id, vec![ClickTarget::new(subpath, 0.)]);
|
metadata.click_targets.insert(element_id, vec![ClickTarget::new(subpath, 0.)]);
|
||||||
metadata.upstream_footprints.insert(element_id, footprint);
|
metadata.upstream_footprints.insert(element_id, footprint);
|
||||||
|
|
||||||
match self {
|
|
||||||
RasterDataType::RasterData(instances) => {
|
|
||||||
// TODO: Find a way to handle more than one row of the graphical data table
|
// TODO: Find a way to handle more than one row of the graphical data table
|
||||||
if let Some(image) = instances.instance_ref_iter().next() {
|
if let Some(image) = self.instance_ref_iter().next() {
|
||||||
metadata.local_transforms.insert(element_id, *image.transform);
|
metadata.local_transforms.insert(element_id, *image.transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RasterDataType::TextureData(instances) => {
|
|
||||||
// TODO: Find a way to handle more than one row of the graphical data table
|
|
||||||
if let Some(image_texture) = instances.instance_ref_iter().next() {
|
|
||||||
metadata.local_transforms.insert(element_id, *image_texture.transform);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
|
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
|
||||||
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
let subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
||||||
|
@ -1024,7 +990,8 @@ impl GraphicElementRendered for GraphicElement {
|
||||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams) {
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::VectorData(vector_data) => vector_data.render_svg(render, render_params),
|
GraphicElement::VectorData(vector_data) => vector_data.render_svg(render, render_params),
|
||||||
GraphicElement::RasterDataType(raster) => raster.render_svg(render, render_params),
|
GraphicElement::RasterDataCPU(raster) => raster.render_svg(render, render_params),
|
||||||
|
GraphicElement::RasterDataGPU(_raster) => (),
|
||||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.render_svg(render, render_params),
|
GraphicElement::GraphicGroup(graphic_group) => graphic_group.render_svg(render, render_params),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1033,15 +1000,17 @@ impl GraphicElementRendered for GraphicElement {
|
||||||
fn render_to_vello(&self, scene: &mut Scene, transform: DAffine2, context: &mut RenderContext, render_params: &RenderParams) {
|
fn render_to_vello(&self, scene: &mut Scene, transform: DAffine2, context: &mut RenderContext, render_params: &RenderParams) {
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::VectorData(vector_data) => vector_data.render_to_vello(scene, transform, context, render_params),
|
GraphicElement::VectorData(vector_data) => vector_data.render_to_vello(scene, transform, context, render_params),
|
||||||
|
GraphicElement::RasterDataCPU(raster) => raster.render_to_vello(scene, transform, context, render_params),
|
||||||
|
GraphicElement::RasterDataGPU(raster) => raster.render_to_vello(scene, transform, context, render_params),
|
||||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.render_to_vello(scene, transform, context, render_params),
|
GraphicElement::GraphicGroup(graphic_group) => graphic_group.render_to_vello(scene, transform, context, render_params),
|
||||||
GraphicElement::RasterDataType(raster) => raster.render_to_vello(scene, transform, context, render_params),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
fn bounding_box(&self, transform: DAffine2, include_stroke: bool) -> Option<[DVec2; 2]> {
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::VectorData(vector_data) => vector_data.bounding_box(transform, include_stroke),
|
GraphicElement::VectorData(vector_data) => vector_data.bounding_box(transform, include_stroke),
|
||||||
GraphicElement::RasterDataType(raster) => raster.bounding_box(transform, include_stroke),
|
GraphicElement::RasterDataCPU(raster) => raster.bounding_box(transform, include_stroke),
|
||||||
|
GraphicElement::RasterDataGPU(raster) => raster.bounding_box(transform, include_stroke),
|
||||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.bounding_box(transform, include_stroke),
|
GraphicElement::GraphicGroup(graphic_group) => graphic_group.bounding_box(transform, include_stroke),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1059,21 +1028,20 @@ impl GraphicElementRendered for GraphicElement {
|
||||||
metadata.local_transforms.insert(element_id, *vector_data.transform);
|
metadata.local_transforms.insert(element_id, *vector_data.transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GraphicElement::RasterDataType(raster_frame) => {
|
GraphicElement::RasterDataCPU(raster_frame) => {
|
||||||
metadata.upstream_footprints.insert(element_id, footprint);
|
metadata.upstream_footprints.insert(element_id, footprint);
|
||||||
match raster_frame {
|
|
||||||
RasterDataType::RasterData(instances) => {
|
|
||||||
// TODO: Find a way to handle more than one row of images
|
// TODO: Find a way to handle more than one row of images
|
||||||
if let Some(image) = instances.instance_ref_iter().next() {
|
if let Some(image) = raster_frame.instance_ref_iter().next() {
|
||||||
metadata.local_transforms.insert(element_id, *image.transform);
|
metadata.local_transforms.insert(element_id, *image.transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RasterDataType::TextureData(instances) => {
|
GraphicElement::RasterDataGPU(raster_frame) => {
|
||||||
// TODO: Find a way to handle more than one row of image textures
|
metadata.upstream_footprints.insert(element_id, footprint);
|
||||||
if let Some(image_texture) = instances.instance_ref_iter().next() {
|
|
||||||
metadata.local_transforms.insert(element_id, *image_texture.transform);
|
// TODO: Find a way to handle more than one row of images
|
||||||
}
|
if let Some(image) = raster_frame.instance_ref_iter().next() {
|
||||||
}
|
metadata.local_transforms.insert(element_id, *image.transform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1081,7 +1049,8 @@ impl GraphicElementRendered for GraphicElement {
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::VectorData(vector_data) => vector_data.collect_metadata(metadata, footprint, element_id),
|
GraphicElement::VectorData(vector_data) => vector_data.collect_metadata(metadata, footprint, element_id),
|
||||||
GraphicElement::RasterDataType(raster) => raster.collect_metadata(metadata, footprint, element_id),
|
GraphicElement::RasterDataCPU(raster) => raster.collect_metadata(metadata, footprint, element_id),
|
||||||
|
GraphicElement::RasterDataGPU(raster) => raster.collect_metadata(metadata, footprint, element_id),
|
||||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.collect_metadata(metadata, footprint, element_id),
|
GraphicElement::GraphicGroup(graphic_group) => graphic_group.collect_metadata(metadata, footprint, element_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1089,7 +1058,8 @@ impl GraphicElementRendered for GraphicElement {
|
||||||
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
|
fn add_upstream_click_targets(&self, click_targets: &mut Vec<ClickTarget>) {
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::VectorData(vector_data) => vector_data.add_upstream_click_targets(click_targets),
|
GraphicElement::VectorData(vector_data) => vector_data.add_upstream_click_targets(click_targets),
|
||||||
GraphicElement::RasterDataType(raster) => raster.add_upstream_click_targets(click_targets),
|
GraphicElement::RasterDataCPU(raster) => raster.add_upstream_click_targets(click_targets),
|
||||||
|
GraphicElement::RasterDataGPU(raster) => raster.add_upstream_click_targets(click_targets),
|
||||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.add_upstream_click_targets(click_targets),
|
GraphicElement::GraphicGroup(graphic_group) => graphic_group.add_upstream_click_targets(click_targets),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1098,7 +1068,8 @@ impl GraphicElementRendered for GraphicElement {
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::VectorData(vector_data) => vector_data.contains_artboard(),
|
GraphicElement::VectorData(vector_data) => vector_data.contains_artboard(),
|
||||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.contains_artboard(),
|
GraphicElement::GraphicGroup(graphic_group) => graphic_group.contains_artboard(),
|
||||||
GraphicElement::RasterDataType(raster) => raster.contains_artboard(),
|
GraphicElement::RasterDataCPU(raster) => raster.contains_artboard(),
|
||||||
|
GraphicElement::RasterDataGPU(raster) => raster.contains_artboard(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,7 +1077,8 @@ impl GraphicElementRendered for GraphicElement {
|
||||||
match self {
|
match self {
|
||||||
GraphicElement::VectorData(vector_data) => vector_data.new_ids_from_hash(reference),
|
GraphicElement::VectorData(vector_data) => vector_data.new_ids_from_hash(reference),
|
||||||
GraphicElement::GraphicGroup(graphic_group) => graphic_group.new_ids_from_hash(reference),
|
GraphicElement::GraphicGroup(graphic_group) => graphic_group.new_ids_from_hash(reference),
|
||||||
GraphicElement::RasterDataType(_) => (),
|
GraphicElement::RasterDataCPU(_) => (),
|
||||||
|
GraphicElement::RasterDataGPU(_) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub mod instances;
|
||||||
pub mod logic;
|
pub mod logic;
|
||||||
pub mod misc;
|
pub mod misc;
|
||||||
pub mod ops;
|
pub mod ops;
|
||||||
|
pub mod raster_types;
|
||||||
pub mod structural;
|
pub mod structural;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::Ctx;
|
use crate::Ctx;
|
||||||
use crate::raster::BlendMode;
|
use crate::raster::BlendMode;
|
||||||
use crate::raster::image::RasterDataTable;
|
use crate::raster_types::{CPU, RasterDataTable};
|
||||||
use crate::registry::types::{Fraction, Percentage};
|
use crate::registry::types::{Fraction, Percentage};
|
||||||
use crate::vector::style::GradientStops;
|
use crate::vector::style::GradientStops;
|
||||||
use crate::{Color, Node};
|
use crate::{Color, Node};
|
||||||
|
@ -453,7 +453,7 @@ fn color_value(_: impl Ctx, _primary: (), #[default(Color::BLACK)] color: Option
|
||||||
// _: impl Ctx,
|
// _: impl Ctx,
|
||||||
// #[implementations(
|
// #[implementations(
|
||||||
// Color,
|
// Color,
|
||||||
// RasterDataTable<Color>,
|
// RasterDataTable<CPU>,
|
||||||
// GradientStops,
|
// GradientStops,
|
||||||
// )]
|
// )]
|
||||||
// mut image: T,
|
// mut image: T,
|
||||||
|
@ -515,7 +515,7 @@ fn unwrap<T: Default>(_: impl Ctx, #[implementations(Option<f64>, Option<f32>, O
|
||||||
|
|
||||||
/// Meant for debugging purposes, not general use. Clones the input value.
|
/// Meant for debugging purposes, not general use. Clones the input value.
|
||||||
#[node_macro::node(category("Debug"))]
|
#[node_macro::node(category("Debug"))]
|
||||||
fn clone<'i, T: Clone + 'i>(_: impl Ctx, #[implementations(&RasterDataTable<Color>)] value: &'i T) -> T {
|
fn clone<'i, T: Clone + 'i>(_: impl Ctx, #[implementations(&RasterDataTable<CPU>)] value: &'i T) -> T {
|
||||||
value.clone()
|
value.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pub use self::color::{Color, Luma, SRGBA8};
|
pub use self::color::{Color, Luma, SRGBA8};
|
||||||
use crate::Ctx;
|
use crate::Ctx;
|
||||||
use crate::GraphicGroupTable;
|
use crate::GraphicGroupTable;
|
||||||
use crate::raster::image::RasterDataTable;
|
use crate::raster_types::{CPU, RasterDataTable};
|
||||||
use crate::registry::types::Percentage;
|
use crate::registry::types::Percentage;
|
||||||
use crate::vector::VectorDataTable;
|
use crate::vector::VectorDataTable;
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
@ -310,7 +310,7 @@ impl SetBlendMode for GraphicGroupTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl SetBlendMode for RasterDataTable<Color> {
|
impl SetBlendMode for RasterDataTable<CPU> {
|
||||||
fn set_blend_mode(&mut self, blend_mode: BlendMode) {
|
fn set_blend_mode(&mut self, blend_mode: BlendMode) {
|
||||||
for instance in self.instance_mut_iter() {
|
for instance in self.instance_mut_iter() {
|
||||||
instance.alpha_blending.blend_mode = blend_mode;
|
instance.alpha_blending.blend_mode = blend_mode;
|
||||||
|
@ -324,7 +324,7 @@ fn blend_mode<T: SetBlendMode>(
|
||||||
#[implementations(
|
#[implementations(
|
||||||
GraphicGroupTable,
|
GraphicGroupTable,
|
||||||
VectorDataTable,
|
VectorDataTable,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
)]
|
)]
|
||||||
mut value: T,
|
mut value: T,
|
||||||
blend_mode: BlendMode,
|
blend_mode: BlendMode,
|
||||||
|
@ -340,7 +340,7 @@ fn opacity<T: MultiplyAlpha>(
|
||||||
#[implementations(
|
#[implementations(
|
||||||
GraphicGroupTable,
|
GraphicGroupTable,
|
||||||
VectorDataTable,
|
VectorDataTable,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
)]
|
)]
|
||||||
mut value: T,
|
mut value: T,
|
||||||
#[default(100.)] factor: Percentage,
|
#[default(100.)] factor: Percentage,
|
||||||
|
|
|
@ -4,8 +4,9 @@ use crate::raster::curve::{CubicSplines, CurveManipulatorGroup};
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use crate::raster::curve::{Curve, ValueMapperNode};
|
use crate::raster::curve::{Curve, ValueMapperNode};
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use crate::raster::image::{Image, RasterDataTable};
|
use crate::raster::image::Image;
|
||||||
use crate::raster::{Channel, Color, Pixel};
|
use crate::raster::{Channel, Color, Pixel};
|
||||||
|
use crate::raster_types::{CPU, Raster, RasterDataTable};
|
||||||
use crate::registry::types::{Angle, Percentage, SignedPercentage};
|
use crate::registry::types::{Angle, Percentage, SignedPercentage};
|
||||||
use crate::vector::VectorDataTable;
|
use crate::vector::VectorDataTable;
|
||||||
use crate::vector::style::GradientStops;
|
use crate::vector::style::GradientStops;
|
||||||
|
@ -265,7 +266,7 @@ fn luminance<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut input: T,
|
mut input: T,
|
||||||
|
@ -289,7 +290,7 @@ fn extract_channel<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut input: T,
|
mut input: T,
|
||||||
|
@ -312,7 +313,7 @@ fn make_opaque<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut input: T,
|
mut input: T,
|
||||||
|
@ -337,7 +338,7 @@ fn brightness_contrast<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut input: T,
|
mut input: T,
|
||||||
|
@ -426,7 +427,7 @@ fn levels<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut image: T,
|
mut image: T,
|
||||||
|
@ -493,7 +494,7 @@ async fn black_and_white<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut image: T,
|
mut image: T,
|
||||||
|
@ -565,7 +566,7 @@ async fn hue_saturation<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut input: T,
|
mut input: T,
|
||||||
|
@ -599,7 +600,7 @@ async fn invert<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut input: T,
|
mut input: T,
|
||||||
|
@ -621,7 +622,7 @@ async fn threshold<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut image: T,
|
mut image: T,
|
||||||
|
@ -663,19 +664,19 @@ impl Blend<Color> for Option<Color> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Blend<Color> for RasterDataTable<Color> {
|
impl Blend<Color> for RasterDataTable<CPU> {
|
||||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
||||||
let mut result_table = self.clone();
|
let mut result_table = self.clone();
|
||||||
|
|
||||||
for (over, under) in result_table.instance_mut_iter().zip(under.instance_ref_iter()) {
|
for (over, under) in result_table.instance_mut_iter().zip(under.instance_ref_iter()) {
|
||||||
let data = over.instance.data.iter().zip(under.instance.data.iter()).map(|(a, b)| blend_fn(*a, *b)).collect();
|
let data = over.instance.data.iter().zip(under.instance.data.iter()).map(|(a, b)| blend_fn(*a, *b)).collect();
|
||||||
|
|
||||||
*over.instance = Image {
|
*over.instance = Raster::new_cpu(Image {
|
||||||
data,
|
data,
|
||||||
width: over.instance.width,
|
width: over.instance.width,
|
||||||
height: over.instance.height,
|
height: over.instance.height,
|
||||||
base64_string: None,
|
base64_string: None,
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
result_table
|
result_table
|
||||||
|
@ -706,14 +707,14 @@ async fn blend<T: Blend<Color> + Send>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
over: T,
|
over: T,
|
||||||
#[expose]
|
#[expose]
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
under: T,
|
under: T,
|
||||||
|
@ -795,13 +796,13 @@ impl Adjust<Color> for GradientStops {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<P: Pixel> Adjust<P> for RasterDataTable<P>
|
impl Adjust<Color> for RasterDataTable<CPU>
|
||||||
where
|
where
|
||||||
GraphicElement: From<Image<P>>,
|
GraphicElement: From<Image<Color>>,
|
||||||
{
|
{
|
||||||
fn adjust(&mut self, map_fn: impl Fn(&P) -> P) {
|
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
||||||
for instance in self.instance_mut_iter() {
|
for instance in self.instance_mut_iter() {
|
||||||
for c in instance.instance.data.iter_mut() {
|
for c in instance.instance.data_mut().data.iter_mut() {
|
||||||
*c = map_fn(c);
|
*c = map_fn(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -829,7 +830,7 @@ async fn gradient_map<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut image: T,
|
mut image: T,
|
||||||
|
@ -865,7 +866,7 @@ async fn vibrance<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut image: T,
|
mut image: T,
|
||||||
|
@ -1037,7 +1038,7 @@ async fn channel_mixer<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut image: T,
|
mut image: T,
|
||||||
|
@ -1166,7 +1167,7 @@ async fn selective_color<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut image: T,
|
mut image: T,
|
||||||
|
@ -1309,9 +1310,9 @@ impl MultiplyAlpha for GraphicGroupTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<P: Pixel> MultiplyAlpha for RasterDataTable<P>
|
impl MultiplyAlpha for RasterDataTable<CPU>
|
||||||
where
|
where
|
||||||
GraphicElement: From<Image<P>>,
|
GraphicElement: From<Image<Color>>,
|
||||||
{
|
{
|
||||||
fn multiply_alpha(&mut self, factor: f64) {
|
fn multiply_alpha(&mut self, factor: f64) {
|
||||||
for instance in self.instance_mut_iter() {
|
for instance in self.instance_mut_iter() {
|
||||||
|
@ -1331,7 +1332,7 @@ async fn posterize<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut input: T,
|
mut input: T,
|
||||||
|
@ -1364,7 +1365,7 @@ async fn exposure<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut input: T,
|
mut input: T,
|
||||||
|
@ -1438,7 +1439,7 @@ fn color_overlay<T: Adjust<Color>>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Color,
|
Color,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GradientStops,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
mut image: T,
|
mut image: T,
|
||||||
|
@ -1488,7 +1489,8 @@ fn color_overlay<T: Adjust<Color>>(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::raster::adjustments::BlendMode;
|
use crate::raster::adjustments::BlendMode;
|
||||||
use crate::raster::image::{Image, RasterDataTable};
|
use crate::raster::image::Image;
|
||||||
|
use crate::raster_types::{Raster, RasterDataTable};
|
||||||
use crate::{Color, Node};
|
use crate::{Color, Node};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
|
@ -1514,7 +1516,7 @@ mod test {
|
||||||
// 100% of the output should come from the multiplied value
|
// 100% of the output should come from the multiplied value
|
||||||
let opacity = 100_f64;
|
let opacity = 100_f64;
|
||||||
|
|
||||||
let result = super::color_overlay((), RasterDataTable::new(image.clone()), overlay_color, BlendMode::Multiply, opacity);
|
let result = super::color_overlay((), RasterDataTable::new(Raster::new_cpu(image.clone())), overlay_color, BlendMode::Multiply, opacity);
|
||||||
let result = result.instance_ref_iter().next().unwrap().instance;
|
let result = result.instance_ref_iter().next().unwrap().instance;
|
||||||
|
|
||||||
// The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0)
|
// The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::Color;
|
|
||||||
use crate::instances::Instance;
|
use crate::instances::Instance;
|
||||||
use crate::raster::Image;
|
use crate::raster_types::CPU;
|
||||||
|
use crate::raster_types::Raster;
|
||||||
use crate::vector::brush_stroke::BrushStroke;
|
use crate::vector::brush_stroke::BrushStroke;
|
||||||
use crate::vector::brush_stroke::BrushStyle;
|
use crate::vector::brush_stroke::BrushStyle;
|
||||||
use core::hash::Hash;
|
use core::hash::Hash;
|
||||||
|
@ -17,19 +17,19 @@ struct BrushCacheImpl {
|
||||||
|
|
||||||
// The strokes that have been fully processed and blended into the background.
|
// The strokes that have been fully processed and blended into the background.
|
||||||
#[cfg_attr(feature = "serde", serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance"))]
|
#[cfg_attr(feature = "serde", serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance"))]
|
||||||
background: Instance<Image<Color>>,
|
background: Instance<Raster<CPU>>,
|
||||||
#[cfg_attr(feature = "serde", serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance"))]
|
#[cfg_attr(feature = "serde", serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance"))]
|
||||||
blended_image: Instance<Image<Color>>,
|
blended_image: Instance<Raster<CPU>>,
|
||||||
#[cfg_attr(feature = "serde", serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance"))]
|
#[cfg_attr(feature = "serde", serde(deserialize_with = "crate::graphene_core::raster::image::migrate_image_frame_instance"))]
|
||||||
last_stroke_texture: Instance<Image<Color>>,
|
last_stroke_texture: Instance<Raster<CPU>>,
|
||||||
|
|
||||||
// A cache for brush textures.
|
// A cache for brush textures.
|
||||||
#[cfg_attr(feature = "serde", serde(skip))]
|
#[cfg_attr(feature = "serde", serde(skip))]
|
||||||
brush_texture_cache: HashMap<BrushStyle, Image<Color>>,
|
brush_texture_cache: HashMap<BrushStyle, Raster<CPU>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BrushCacheImpl {
|
impl BrushCacheImpl {
|
||||||
fn compute_brush_plan(&mut self, mut background: Instance<Image<Color>>, input: &[BrushStroke]) -> BrushPlan {
|
fn compute_brush_plan(&mut self, mut background: Instance<Raster<CPU>>, input: &[BrushStroke]) -> BrushPlan {
|
||||||
// Do background invalidation.
|
// Do background invalidation.
|
||||||
if background != self.background {
|
if background != self.background {
|
||||||
self.background = background.clone();
|
self.background = background.clone();
|
||||||
|
@ -57,7 +57,7 @@ impl BrushCacheImpl {
|
||||||
|
|
||||||
// Check if the first non-blended stroke is an extension of the last one.
|
// Check if the first non-blended stroke is an extension of the last one.
|
||||||
let mut first_stroke_texture = Instance {
|
let mut first_stroke_texture = Instance {
|
||||||
instance: Image::default(),
|
instance: Raster::<CPU>::default(),
|
||||||
transform: glam::DAffine2::ZERO,
|
transform: glam::DAffine2::ZERO,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -84,7 +84,7 @@ impl BrushCacheImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cache_results(&mut self, input: Vec<BrushStroke>, blended_image: Instance<Image<Color>>, last_stroke_texture: Instance<Image<Color>>) {
|
pub fn cache_results(&mut self, input: Vec<BrushStroke>, blended_image: Instance<Raster<CPU>>, last_stroke_texture: Instance<Raster<CPU>>) {
|
||||||
self.prev_input = input;
|
self.prev_input = input;
|
||||||
self.blended_image = blended_image;
|
self.blended_image = blended_image;
|
||||||
self.last_stroke_texture = last_stroke_texture;
|
self.last_stroke_texture = last_stroke_texture;
|
||||||
|
@ -99,8 +99,8 @@ impl Hash for BrushCacheImpl {
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct BrushPlan {
|
pub struct BrushPlan {
|
||||||
pub strokes: Vec<BrushStroke>,
|
pub strokes: Vec<BrushStroke>,
|
||||||
pub background: Instance<Image<Color>>,
|
pub background: Instance<Raster<CPU>>,
|
||||||
pub first_stroke_texture: Instance<Image<Color>>,
|
pub first_stroke_texture: Instance<Raster<CPU>>,
|
||||||
pub first_stroke_point_skip: usize,
|
pub first_stroke_point_skip: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,22 +164,22 @@ impl BrushCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compute_brush_plan(&self, background: Instance<Image<Color>>, input: &[BrushStroke]) -> BrushPlan {
|
pub fn compute_brush_plan(&self, background: Instance<Raster<CPU>>, input: &[BrushStroke]) -> BrushPlan {
|
||||||
let mut inner = self.inner.lock().unwrap();
|
let mut inner = self.inner.lock().unwrap();
|
||||||
inner.compute_brush_plan(background, input)
|
inner.compute_brush_plan(background, input)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cache_results(&self, input: Vec<BrushStroke>, blended_image: Instance<Image<Color>>, last_stroke_texture: Instance<Image<Color>>) {
|
pub fn cache_results(&self, input: Vec<BrushStroke>, blended_image: Instance<Raster<CPU>>, last_stroke_texture: Instance<Raster<CPU>>) {
|
||||||
let mut inner = self.inner.lock().unwrap();
|
let mut inner = self.inner.lock().unwrap();
|
||||||
inner.cache_results(input, blended_image, last_stroke_texture)
|
inner.cache_results(input, blended_image, last_stroke_texture)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cached_brush(&self, style: &BrushStyle) -> Option<Image<Color>> {
|
pub fn get_cached_brush(&self, style: &BrushStyle) -> Option<Raster<CPU>> {
|
||||||
let inner = self.inner.lock().unwrap();
|
let inner = self.inner.lock().unwrap();
|
||||||
inner.brush_texture_cache.get(style).cloned()
|
inner.brush_texture_cache.get(style).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn store_brush(&self, style: BrushStyle, brush: Image<Color>) {
|
pub fn store_brush(&self, style: BrushStyle, brush: Raster<CPU>) {
|
||||||
let mut inner = self.inner.lock().unwrap();
|
let mut inner = self.inner.lock().unwrap();
|
||||||
inner.brush_texture_cache.insert(style, brush);
|
inner.brush_texture_cache.insert(style, brush);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
|
use crate::{
|
||||||
|
AlphaBlending,
|
||||||
|
instances::{Instance, Instances},
|
||||||
|
raster_types::Raster,
|
||||||
|
};
|
||||||
|
|
||||||
use super::Color;
|
use super::Color;
|
||||||
use super::discrete_srgb::float_to_srgb_u8;
|
use super::discrete_srgb::float_to_srgb_u8;
|
||||||
use crate::AlphaBlending;
|
|
||||||
use crate::GraphicElement;
|
|
||||||
use crate::instances::{Instance, Instances};
|
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::hash::{Hash, Hasher};
|
use core::hash::{Hash, Hasher};
|
||||||
use dyn_any::StaticType;
|
use dyn_any::{DynAny, StaticType};
|
||||||
use glam::{DAffine2, DVec2};
|
use glam::{DAffine2, DVec2};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
|
@ -208,9 +211,39 @@ impl<P: Pixel> IntoIterator for Image<P> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Eventually remove this migration document upgrade code
|
// TODO: Eventually remove this migration document upgrade code
|
||||||
pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<RasterDataTable<Color>, D::Error> {
|
pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<RasterDataTable<CPU>, D::Error> {
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
type ImageFrameTable<P> = Instances<Image<P>>;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
|
||||||
|
enum RasterFrame {
|
||||||
|
/// A CPU-based bitmap image with a finite position and extent, equivalent to the SVG <image> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image
|
||||||
|
ImageFrame(ImageFrameTable<Color>),
|
||||||
|
}
|
||||||
|
impl<'de> serde::Deserialize<'de> for RasterFrame {
|
||||||
|
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
|
Ok(RasterFrame::ImageFrame(ImageFrameTable::new(Image::deserialize(deserializer)?)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl serde::Serialize for RasterFrame {
|
||||||
|
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
|
match self {
|
||||||
|
RasterFrame::ImageFrame(image_instances) => image_instances.serialize(serializer),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
|
pub enum GraphicElement {
|
||||||
|
/// Equivalent to the SVG <g> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g
|
||||||
|
GraphicGroup(GraphicGroupTable),
|
||||||
|
/// A vector shape, equivalent to the SVG <path> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
|
||||||
|
VectorData(VectorDataTable),
|
||||||
|
RasterFrame(RasterFrame),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, PartialEq, specta::Type)]
|
#[derive(Clone, Default, Debug, PartialEq, specta::Type)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct ImageFrame<P: Pixel> {
|
pub struct ImageFrame<P: Pixel> {
|
||||||
|
@ -218,13 +251,13 @@ pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) ->
|
||||||
}
|
}
|
||||||
impl From<ImageFrame<Color>> for GraphicElement {
|
impl From<ImageFrame<Color>> for GraphicElement {
|
||||||
fn from(image_frame: ImageFrame<Color>) -> Self {
|
fn from(image_frame: ImageFrame<Color>) -> Self {
|
||||||
GraphicElement::RasterDataType(crate::RasterDataType::RasterData(RasterDataTable::new(image_frame.image)))
|
GraphicElement::RasterFrame(RasterFrame::ImageFrame(ImageFrameTable::new(image_frame.image)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<GraphicElement> for ImageFrame<Color> {
|
impl From<GraphicElement> for ImageFrame<Color> {
|
||||||
fn from(element: GraphicElement) -> Self {
|
fn from(element: GraphicElement) -> Self {
|
||||||
match element {
|
match element {
|
||||||
GraphicElement::RasterDataType(crate::RasterDataType::RasterData(image)) => Self {
|
GraphicElement::RasterFrame(RasterFrame::ImageFrame(image)) => Self {
|
||||||
image: image.instance_ref_iter().next().unwrap().instance.clone(),
|
image: image.instance_ref_iter().next().unwrap().instance.clone(),
|
||||||
},
|
},
|
||||||
_ => panic!("Expected Image, found {:?}", element),
|
_ => panic!("Expected Image, found {:?}", element),
|
||||||
|
@ -255,27 +288,59 @@ pub fn migrate_image_frame<'de, D: serde::Deserializer<'de>>(deserializer: D) ->
|
||||||
Image(Image<Color>),
|
Image(Image<Color>),
|
||||||
OldImageFrame(OldImageFrame<Color>),
|
OldImageFrame(OldImageFrame<Color>),
|
||||||
ImageFrame(Instances<ImageFrame<Color>>),
|
ImageFrame(Instances<ImageFrame<Color>>),
|
||||||
RasterDataTable(RasterDataTable<Color>),
|
ImageFrameTable(ImageFrameTable<Color>),
|
||||||
|
RasterDataTable(RasterDataTable<CPU>),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(match FormatVersions::deserialize(deserializer)? {
|
Ok(match FormatVersions::deserialize(deserializer)? {
|
||||||
FormatVersions::Image(image) => RasterDataTable::new(image),
|
FormatVersions::Image(image) => RasterDataTable::new(Raster::new_cpu(image)),
|
||||||
FormatVersions::OldImageFrame(image_frame_with_transform_and_blending) => {
|
FormatVersions::OldImageFrame(image_frame_with_transform_and_blending) => {
|
||||||
let OldImageFrame { image, transform, alpha_blending } = image_frame_with_transform_and_blending;
|
let OldImageFrame { image, transform, alpha_blending } = image_frame_with_transform_and_blending;
|
||||||
let mut image_frame_table = RasterDataTable::new(image);
|
let mut image_frame_table = RasterDataTable::new(Raster::new_cpu(image));
|
||||||
*image_frame_table.instance_mut_iter().next().unwrap().transform = transform;
|
*image_frame_table.instance_mut_iter().next().unwrap().transform = transform;
|
||||||
*image_frame_table.instance_mut_iter().next().unwrap().alpha_blending = alpha_blending;
|
*image_frame_table.instance_mut_iter().next().unwrap().alpha_blending = alpha_blending;
|
||||||
image_frame_table
|
image_frame_table
|
||||||
}
|
}
|
||||||
FormatVersions::ImageFrame(image_frame) => RasterDataTable::new(image_frame.instance_ref_iter().next().unwrap().instance.image.clone()),
|
FormatVersions::ImageFrame(image_frame) => RasterDataTable::new(Raster::new_cpu(image_frame.instance_ref_iter().next().unwrap().instance.image.clone())),
|
||||||
FormatVersions::RasterDataTable(image_frame_table) => image_frame_table,
|
FormatVersions::ImageFrameTable(image_frame_table) => RasterDataTable::new(Raster::new_cpu(image_frame_table.instance_ref_iter().next().unwrap().instance.clone())),
|
||||||
|
FormatVersions::RasterDataTable(raster_data_table) => raster_data_table,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Eventually remove this migration document upgrade code
|
// TODO: Eventually remove this migration document upgrade code
|
||||||
pub fn migrate_image_frame_instance<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Instance<Image<Color>>, D::Error> {
|
pub fn migrate_image_frame_instance<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result<Instance<Raster<CPU>>, D::Error> {
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
type ImageFrameTable<P> = Instances<Image<P>>;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
|
||||||
|
enum RasterFrame {
|
||||||
|
/// A CPU-based bitmap image with a finite position and extent, equivalent to the SVG <image> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image
|
||||||
|
ImageFrame(ImageFrameTable<Color>),
|
||||||
|
}
|
||||||
|
impl<'de> serde::Deserialize<'de> for RasterFrame {
|
||||||
|
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
|
Ok(RasterFrame::ImageFrame(ImageFrameTable::new(Image::deserialize(deserializer)?)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl serde::Serialize for RasterFrame {
|
||||||
|
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
|
match self {
|
||||||
|
RasterFrame::ImageFrame(image_instances) => image_instances.serialize(serializer),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
|
||||||
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
|
pub enum GraphicElement {
|
||||||
|
/// Equivalent to the SVG <g> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g
|
||||||
|
GraphicGroup(GraphicGroupTable),
|
||||||
|
/// A vector shape, equivalent to the SVG <path> tag: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
|
||||||
|
VectorData(VectorDataTable),
|
||||||
|
RasterFrame(RasterFrame),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, PartialEq, specta::Type)]
|
#[derive(Clone, Default, Debug, PartialEq, specta::Type)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct ImageFrame<P: Pixel> {
|
pub struct ImageFrame<P: Pixel> {
|
||||||
|
@ -283,13 +348,13 @@ pub fn migrate_image_frame_instance<'de, D: serde::Deserializer<'de>>(deserializ
|
||||||
}
|
}
|
||||||
impl From<ImageFrame<Color>> for GraphicElement {
|
impl From<ImageFrame<Color>> for GraphicElement {
|
||||||
fn from(image_frame: ImageFrame<Color>) -> Self {
|
fn from(image_frame: ImageFrame<Color>) -> Self {
|
||||||
GraphicElement::RasterDataType(crate::RasterDataType::RasterData(RasterDataTable::new(image_frame.image)))
|
GraphicElement::RasterFrame(RasterFrame::ImageFrame(ImageFrameTable::new(image_frame.image)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<GraphicElement> for ImageFrame<Color> {
|
impl From<GraphicElement> for ImageFrame<Color> {
|
||||||
fn from(element: GraphicElement) -> Self {
|
fn from(element: GraphicElement) -> Self {
|
||||||
match element {
|
match element {
|
||||||
GraphicElement::RasterDataType(crate::RasterDataType::RasterData(image)) => Self {
|
GraphicElement::RasterFrame(RasterFrame::ImageFrame(image)) => Self {
|
||||||
image: image.instance_ref_iter().next().unwrap().instance.clone(),
|
image: image.instance_ref_iter().next().unwrap().instance.clone(),
|
||||||
},
|
},
|
||||||
_ => panic!("Expected Image, found {:?}", element),
|
_ => panic!("Expected Image, found {:?}", element),
|
||||||
|
@ -320,23 +385,23 @@ pub fn migrate_image_frame_instance<'de, D: serde::Deserializer<'de>>(deserializ
|
||||||
Image(Image<Color>),
|
Image(Image<Color>),
|
||||||
OldImageFrame(OldImageFrame<Color>),
|
OldImageFrame(OldImageFrame<Color>),
|
||||||
ImageFrame(Instances<ImageFrame<Color>>),
|
ImageFrame(Instances<ImageFrame<Color>>),
|
||||||
RasterDataTable(RasterDataTable<Color>),
|
RasterDataTable(RasterDataTable<CPU>),
|
||||||
ImageInstance(Instance<Image<Color>>),
|
ImageInstance(Instance<Raster<CPU>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(match FormatVersions::deserialize(deserializer)? {
|
Ok(match FormatVersions::deserialize(deserializer)? {
|
||||||
FormatVersions::Image(image) => Instance {
|
FormatVersions::Image(image) => Instance {
|
||||||
instance: image,
|
instance: Raster::new_cpu(image),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
FormatVersions::OldImageFrame(image_frame_with_transform_and_blending) => Instance {
|
FormatVersions::OldImageFrame(image_frame_with_transform_and_blending) => Instance {
|
||||||
instance: image_frame_with_transform_and_blending.image,
|
instance: Raster::new_cpu(image_frame_with_transform_and_blending.image),
|
||||||
transform: image_frame_with_transform_and_blending.transform,
|
transform: image_frame_with_transform_and_blending.transform,
|
||||||
alpha_blending: image_frame_with_transform_and_blending.alpha_blending,
|
alpha_blending: image_frame_with_transform_and_blending.alpha_blending,
|
||||||
source_node_id: None,
|
source_node_id: None,
|
||||||
},
|
},
|
||||||
FormatVersions::ImageFrame(image_frame) => Instance {
|
FormatVersions::ImageFrame(image_frame) => Instance {
|
||||||
instance: image_frame.instance_ref_iter().next().unwrap().instance.image.clone(),
|
instance: Raster::new_cpu(image_frame.instance_ref_iter().next().unwrap().instance.image.clone()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
FormatVersions::RasterDataTable(image_frame_table) => image_frame_table.instance_iter().next().unwrap_or_default(),
|
FormatVersions::RasterDataTable(image_frame_table) => image_frame_table.instance_iter().next().unwrap_or_default(),
|
||||||
|
@ -344,8 +409,7 @@ pub fn migrate_image_frame_instance<'de, D: serde::Deserializer<'de>>(deserializ
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename to ImageTable
|
// pub type RasterDataTable<P> = Instances<Image<P>>;
|
||||||
pub type RasterDataTable<P> = Instances<Image<P>>;
|
|
||||||
|
|
||||||
impl<P: Debug + Copy + Pixel> Sample for Image<P> {
|
impl<P: Debug + Copy + Pixel> Sample for Image<P> {
|
||||||
type Pixel = P;
|
type Pixel = P;
|
||||||
|
@ -393,22 +457,22 @@ impl From<Image<Color>> for Image<SRGBA8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<RasterDataTable<Color>> for RasterDataTable<SRGBA8> {
|
// impl From<RasterDataTable<CPU>> for RasterDataTable<SRGBA8> {
|
||||||
fn from(image_frame_table: RasterDataTable<Color>) -> Self {
|
// fn from(image_frame_table: RasterDataTable<CPU>) -> Self {
|
||||||
let mut result_table = RasterDataTable::<SRGBA8>::default();
|
// let mut result_table = RasterDataTable::<SRGBA8>::default();
|
||||||
|
|
||||||
for image_frame_instance in image_frame_table.instance_iter() {
|
// for image_frame_instance in image_frame_table.instance_iter() {
|
||||||
result_table.push(Instance {
|
// result_table.push(Instance {
|
||||||
instance: image_frame_instance.instance.into(),
|
// instance: image_frame_instance.instance,
|
||||||
transform: image_frame_instance.transform,
|
// transform: image_frame_instance.transform,
|
||||||
alpha_blending: image_frame_instance.alpha_blending,
|
// alpha_blending: image_frame_instance.alpha_blending,
|
||||||
source_node_id: image_frame_instance.source_node_id,
|
// source_node_id: image_frame_instance.source_node_id,
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
result_table
|
// result_table
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl From<Image<SRGBA8>> for Image<Color> {
|
impl From<Image<SRGBA8>> for Image<Color> {
|
||||||
fn from(image: Image<SRGBA8>) -> Self {
|
fn from(image: Image<SRGBA8>) -> Self {
|
||||||
|
|
102
node-graph/gcore/src/raster_types.rs
Normal file
102
node-graph/gcore/src/raster_types.rs
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
use crate::Color;
|
||||||
|
use crate::instances::Instances;
|
||||||
|
use crate::raster::Image;
|
||||||
|
use core::ops::Deref;
|
||||||
|
use dyn_any::DynAny;
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq, Eq, Copy)]
|
||||||
|
pub struct CPU;
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq, Eq, Copy)]
|
||||||
|
pub struct GPU;
|
||||||
|
|
||||||
|
trait Storage {}
|
||||||
|
impl Storage for CPU {}
|
||||||
|
impl Storage for GPU {}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||||
|
#[allow(private_bounds)]
|
||||||
|
pub struct Raster<T: 'static + Storage> {
|
||||||
|
data: RasterStorage,
|
||||||
|
storage: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl<T: 'static + Storage> dyn_any::StaticType for Raster<T> {
|
||||||
|
type Static = Raster<T>;
|
||||||
|
}
|
||||||
|
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
|
||||||
|
pub enum RasterStorage {
|
||||||
|
Cpu(Image<Color>),
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
Gpu(Arc<wgpu::Texture>),
|
||||||
|
#[cfg(not(feature = "wgpu"))]
|
||||||
|
Gpu(()),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RasterStorage {}
|
||||||
|
impl Raster<CPU> {
|
||||||
|
pub fn new_cpu(image: Image<Color>) -> Self {
|
||||||
|
Self {
|
||||||
|
data: RasterStorage::Cpu(image),
|
||||||
|
storage: CPU,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn data(&self) -> &Image<Color> {
|
||||||
|
let RasterStorage::Cpu(cpu) = &self.data else { unreachable!() };
|
||||||
|
cpu
|
||||||
|
}
|
||||||
|
pub fn data_mut(&mut self) -> &mut Image<Color> {
|
||||||
|
let RasterStorage::Cpu(cpu) = &mut self.data else { unreachable!() };
|
||||||
|
cpu
|
||||||
|
}
|
||||||
|
pub fn into_data(self) -> Image<Color> {
|
||||||
|
let RasterStorage::Cpu(cpu) = self.data else { unreachable!() };
|
||||||
|
cpu
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Default for Raster<CPU> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
data: RasterStorage::Cpu(Image::default()),
|
||||||
|
storage: CPU,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Deref for Raster<CPU> {
|
||||||
|
type Target = Image<Color>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
self.data()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
impl Raster<GPU> {
|
||||||
|
pub fn new_gpu(image: Arc<wgpu::Texture>) -> Self {
|
||||||
|
Self {
|
||||||
|
data: RasterStorage::Gpu(image),
|
||||||
|
storage: GPU,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn data(&self) -> &wgpu::Texture {
|
||||||
|
let RasterStorage::Gpu(gpu) = &self.data else { unreachable!() };
|
||||||
|
gpu
|
||||||
|
}
|
||||||
|
pub fn data_mut(&mut self) -> &mut Arc<wgpu::Texture> {
|
||||||
|
let RasterStorage::Gpu(gpu) = &mut self.data else { unreachable!() };
|
||||||
|
gpu
|
||||||
|
}
|
||||||
|
pub fn data_owned(&self) -> Arc<wgpu::Texture> {
|
||||||
|
let RasterStorage::Gpu(gpu) = &self.data else { unreachable!() };
|
||||||
|
gpu.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "wgpu")]
|
||||||
|
impl Deref for Raster<GPU> {
|
||||||
|
type Target = wgpu::Texture;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
self.data()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub type RasterDataTable<Storage> = Instances<Raster<Storage>>;
|
|
@ -1,9 +1,8 @@
|
||||||
use crate::application_io::TextureDataTable;
|
|
||||||
use crate::instances::Instances;
|
use crate::instances::Instances;
|
||||||
use crate::raster::bbox::AxisAlignedBbox;
|
use crate::raster::bbox::AxisAlignedBbox;
|
||||||
use crate::raster::image::RasterDataTable;
|
use crate::raster_types::{CPU, GPU, RasterDataTable};
|
||||||
use crate::vector::VectorDataTable;
|
use crate::vector::VectorDataTable;
|
||||||
use crate::{Artboard, CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicGroupTable, OwnedContextImpl};
|
use crate::{Artboard, CloneVarArgs, Context, Ctx, ExtractAll, GraphicGroupTable, OwnedContextImpl};
|
||||||
use core::f64;
|
use core::f64;
|
||||||
use glam::{DAffine2, DMat2, DVec2};
|
use glam::{DAffine2, DMat2, DVec2};
|
||||||
|
|
||||||
|
@ -162,8 +161,8 @@ async fn transform<T: 'n + 'static>(
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Context -> VectorDataTable,
|
Context -> VectorDataTable,
|
||||||
Context -> GraphicGroupTable,
|
Context -> GraphicGroupTable,
|
||||||
Context -> RasterDataTable<Color>,
|
Context -> RasterDataTable<CPU>,
|
||||||
Context -> TextureDataTable,
|
Context -> RasterDataTable<GPU>,
|
||||||
)]
|
)]
|
||||||
transform_target: impl Node<Context<'static>, Output = Instances<T>>,
|
transform_target: impl Node<Context<'static>, Output = Instances<T>>,
|
||||||
translate: DVec2,
|
translate: DVec2,
|
||||||
|
@ -194,7 +193,7 @@ async fn transform<T: 'n + 'static>(
|
||||||
#[node_macro::node(category(""))]
|
#[node_macro::node(category(""))]
|
||||||
fn replace_transform<Data, TransformInput: Transform>(
|
fn replace_transform<Data, TransformInput: Transform>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(VectorDataTable, RasterDataTable<Color>, GraphicGroupTable)] mut data: Instances<Data>,
|
#[implementations(VectorDataTable, RasterDataTable<CPU>, GraphicGroupTable)] mut data: Instances<Data>,
|
||||||
#[implementations(DAffine2)] transform: TransformInput,
|
#[implementations(DAffine2)] transform: TransformInput,
|
||||||
) -> Instances<Data> {
|
) -> Instances<Data> {
|
||||||
for data_transform in data.instance_mut_iter() {
|
for data_transform in data.instance_mut_iter() {
|
||||||
|
@ -209,8 +208,8 @@ async fn boundless_footprint<T: 'n + 'static>(
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Context -> VectorDataTable,
|
Context -> VectorDataTable,
|
||||||
Context -> GraphicGroupTable,
|
Context -> GraphicGroupTable,
|
||||||
Context -> RasterDataTable<Color>,
|
Context -> RasterDataTable<CPU>,
|
||||||
Context -> TextureDataTable,
|
Context -> RasterDataTable<GPU>,
|
||||||
Context -> String,
|
Context -> String,
|
||||||
Context -> f64,
|
Context -> f64,
|
||||||
)]
|
)]
|
||||||
|
@ -226,8 +225,8 @@ async fn freeze_real_time<T: 'n + 'static>(
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Context -> VectorDataTable,
|
Context -> VectorDataTable,
|
||||||
Context -> GraphicGroupTable,
|
Context -> GraphicGroupTable,
|
||||||
Context -> RasterDataTable<Color>,
|
Context -> RasterDataTable<CPU>,
|
||||||
Context -> TextureDataTable,
|
Context -> RasterDataTable<GPU>,
|
||||||
Context -> String,
|
Context -> String,
|
||||||
Context -> f64,
|
Context -> f64,
|
||||||
)]
|
)]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::instances::{InstanceRef, Instances};
|
use crate::instances::{InstanceRef, Instances};
|
||||||
use crate::raster::Color;
|
use crate::raster_types::{CPU, RasterDataTable};
|
||||||
use crate::raster::image::RasterDataTable;
|
|
||||||
use crate::transform::TransformMut;
|
use crate::transform::TransformMut;
|
||||||
use crate::vector::VectorDataTable;
|
use crate::vector::VectorDataTable;
|
||||||
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, GraphicElement, GraphicGroupTable, OwnedContextImpl};
|
use crate::{CloneVarArgs, Context, Ctx, ExtractAll, ExtractIndex, ExtractVarArgs, GraphicElement, GraphicGroupTable, OwnedContextImpl};
|
||||||
|
@ -10,7 +9,7 @@ use glam::DVec2;
|
||||||
async fn instance_on_points<T: Into<GraphicElement> + Default + Clone + 'static>(
|
async fn instance_on_points<T: Into<GraphicElement> + Default + Clone + 'static>(
|
||||||
ctx: impl ExtractAll + CloneVarArgs + Sync + Ctx,
|
ctx: impl ExtractAll + CloneVarArgs + Sync + Ctx,
|
||||||
points: VectorDataTable,
|
points: VectorDataTable,
|
||||||
#[implementations(Context -> GraphicGroupTable, Context -> VectorDataTable, Context -> RasterDataTable<Color>)] instance: impl Node<'n, Context<'static>, Output = Instances<T>>,
|
#[implementations(Context -> GraphicGroupTable, Context -> VectorDataTable, Context -> RasterDataTable<CPU>)] instance: impl Node<'n, Context<'static>, Output = Instances<T>>,
|
||||||
reverse: bool,
|
reverse: bool,
|
||||||
) -> GraphicGroupTable {
|
) -> GraphicGroupTable {
|
||||||
let mut result_table = GraphicGroupTable::default();
|
let mut result_table = GraphicGroupTable::default();
|
||||||
|
@ -46,7 +45,7 @@ async fn instance_on_points<T: Into<GraphicElement> + Default + Clone + 'static>
|
||||||
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
|
#[node_macro::node(category("Instancing"), path(graphene_core::vector))]
|
||||||
async fn instance_repeat<T: Into<GraphicElement> + Default + Clone + 'static>(
|
async fn instance_repeat<T: Into<GraphicElement> + Default + Clone + 'static>(
|
||||||
ctx: impl ExtractAll + CloneVarArgs + Ctx,
|
ctx: impl ExtractAll + CloneVarArgs + Ctx,
|
||||||
#[implementations(Context -> GraphicGroupTable, Context -> VectorDataTable, Context -> RasterDataTable<Color>)] instance: impl Node<'n, Context<'static>, Output = Instances<T>>,
|
#[implementations(Context -> GraphicGroupTable, Context -> VectorDataTable, Context -> RasterDataTable<CPU>)] instance: impl Node<'n, Context<'static>, Output = Instances<T>>,
|
||||||
#[default(1)] count: u64,
|
#[default(1)] count: u64,
|
||||||
reverse: bool,
|
reverse: bool,
|
||||||
) -> GraphicGroupTable {
|
) -> GraphicGroupTable {
|
||||||
|
|
|
@ -37,6 +37,7 @@ impl Hash for BrushStyle {
|
||||||
self.hardness.to_bits().hash(state);
|
self.hardness.to_bits().hash(state);
|
||||||
self.flow.to_bits().hash(state);
|
self.flow.to_bits().hash(state);
|
||||||
self.spacing.to_bits().hash(state);
|
self.spacing.to_bits().hash(state);
|
||||||
|
self.blend_mode.hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use super::misc::{CentroidType, point_to_dvec2};
|
||||||
use super::style::{Fill, Gradient, GradientStops, Stroke};
|
use super::style::{Fill, Gradient, GradientStops, Stroke};
|
||||||
use super::{PointId, SegmentDomain, SegmentId, StrokeId, VectorData, VectorDataTable};
|
use super::{PointId, SegmentDomain, SegmentId, StrokeId, VectorData, VectorDataTable};
|
||||||
use crate::instances::{Instance, InstanceMut, Instances};
|
use crate::instances::{Instance, InstanceMut, Instances};
|
||||||
use crate::raster::image::RasterDataTable;
|
use crate::raster_types::{CPU, RasterDataTable};
|
||||||
use crate::registry::types::{Angle, Fraction, IntegerCount, Length, Multiplier, Percentage, PixelLength, PixelSize, SeedValue};
|
use crate::registry::types::{Angle, Fraction, IntegerCount, Length, Multiplier, Percentage, PixelLength, PixelSize, SeedValue};
|
||||||
use crate::renderer::GraphicElementRendered;
|
use crate::renderer::GraphicElementRendered;
|
||||||
use crate::transform::{Footprint, ReferencePoint, Transform};
|
use crate::transform::{Footprint, ReferencePoint, Transform};
|
||||||
|
@ -204,7 +204,7 @@ where
|
||||||
async fn repeat<I: 'n + Send>(
|
async fn repeat<I: 'n + Send>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
// TODO: Implement other GraphicElementRendered types.
|
// TODO: Implement other GraphicElementRendered types.
|
||||||
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<Color>)] instance: Instances<I>,
|
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<CPU>)] instance: Instances<I>,
|
||||||
#[default(100., 100.)]
|
#[default(100., 100.)]
|
||||||
// TODO: When using a custom Properties panel layout in document_node_definitions.rs and this default is set, the widget weirdly doesn't show up in the Properties panel. Investigation is needed.
|
// TODO: When using a custom Properties panel layout in document_node_definitions.rs and this default is set, the widget weirdly doesn't show up in the Properties panel. Investigation is needed.
|
||||||
direction: PixelSize,
|
direction: PixelSize,
|
||||||
|
@ -246,7 +246,7 @@ where
|
||||||
async fn circular_repeat<I: 'n + Send>(
|
async fn circular_repeat<I: 'n + Send>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
// TODO: Implement other GraphicElementRendered types.
|
// TODO: Implement other GraphicElementRendered types.
|
||||||
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<Color>)] instance: Instances<I>,
|
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<CPU>)] instance: Instances<I>,
|
||||||
angle_offset: Angle,
|
angle_offset: Angle,
|
||||||
#[default(5)] radius: f64,
|
#[default(5)] radius: f64,
|
||||||
#[default(5)] instances: IntegerCount,
|
#[default(5)] instances: IntegerCount,
|
||||||
|
@ -286,7 +286,7 @@ async fn copy_to_points<I: 'n + Send>(
|
||||||
points: VectorDataTable,
|
points: VectorDataTable,
|
||||||
#[expose]
|
#[expose]
|
||||||
/// Artwork to be copied and placed at each point.
|
/// Artwork to be copied and placed at each point.
|
||||||
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<Color>)]
|
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<CPU>)]
|
||||||
instance: Instances<I>,
|
instance: Instances<I>,
|
||||||
/// Minimum range of randomized sizes given to each instance.
|
/// Minimum range of randomized sizes given to each instance.
|
||||||
#[default(1)]
|
#[default(1)]
|
||||||
|
@ -370,7 +370,7 @@ where
|
||||||
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
|
#[node_macro::node(category("Vector"), path(graphene_core::vector))]
|
||||||
async fn mirror<I: 'n + Send>(
|
async fn mirror<I: 'n + Send>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<Color>)] instance: Instances<I>,
|
#[implementations(GraphicGroupTable, VectorDataTable, RasterDataTable<CPU>)] instance: Instances<I>,
|
||||||
#[default(ReferencePoint::Center)] reference_point: ReferencePoint,
|
#[default(ReferencePoint::Center)] reference_point: ReferencePoint,
|
||||||
offset: f64,
|
offset: f64,
|
||||||
#[range((-90., 90.))] angle: Angle,
|
#[range((-90., 90.))] angle: Angle,
|
||||||
|
|
|
@ -6,6 +6,7 @@ pub use dyn_any::StaticType;
|
||||||
pub use glam::{DAffine2, DVec2, IVec2, UVec2};
|
pub use glam::{DAffine2, DVec2, IVec2, UVec2};
|
||||||
use graphene_core::raster::brush_cache::BrushCache;
|
use graphene_core::raster::brush_cache::BrushCache;
|
||||||
use graphene_core::raster::{BlendMode, LuminanceCalculation};
|
use graphene_core::raster::{BlendMode, LuminanceCalculation};
|
||||||
|
use graphene_core::raster_types::CPU;
|
||||||
use graphene_core::renderer::RenderMetadata;
|
use graphene_core::renderer::RenderMetadata;
|
||||||
use graphene_core::transform::ReferencePoint;
|
use graphene_core::transform::ReferencePoint;
|
||||||
use graphene_core::uuid::NodeId;
|
use graphene_core::uuid::NodeId;
|
||||||
|
@ -188,7 +189,7 @@ tagged_value! {
|
||||||
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), serde(deserialize_with = "graphene_core::vector::migrate_vector_data"))] // TODO: Eventually remove this migration document upgrade code
|
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), serde(deserialize_with = "graphene_core::vector::migrate_vector_data"))] // TODO: Eventually remove this migration document upgrade code
|
||||||
VectorData(graphene_core::vector::VectorDataTable),
|
VectorData(graphene_core::vector::VectorDataTable),
|
||||||
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), serde(alias = "ImageFrame", deserialize_with = "graphene_core::raster::image::migrate_image_frame"))] // TODO: Eventually remove this migration document upgrade code
|
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), serde(alias = "ImageFrame", deserialize_with = "graphene_core::raster::image::migrate_image_frame"))] // TODO: Eventually remove this migration document upgrade code
|
||||||
RasterData(graphene_core::raster::image::RasterDataTable<Color>),
|
RasterData(graphene_core::raster_types::RasterDataTable<CPU>),
|
||||||
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), serde(deserialize_with = "graphene_core::migrate_graphic_group"))] // TODO: Eventually remove this migration document upgrade code
|
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), serde(deserialize_with = "graphene_core::migrate_graphic_group"))] // TODO: Eventually remove this migration document upgrade code
|
||||||
GraphicGroup(graphene_core::GraphicGroupTable),
|
GraphicGroup(graphene_core::GraphicGroupTable),
|
||||||
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), serde(deserialize_with = "graphene_core::migrate_artboard_group"))] // TODO: Eventually remove this migration document upgrade code
|
#[cfg_attr(all(feature = "serde", target_arch = "wasm32"), serde(deserialize_with = "graphene_core::migrate_artboard_group"))] // TODO: Eventually remove this migration document upgrade code
|
||||||
|
|
|
@ -6,8 +6,9 @@ use graphene_core::instances::Instance;
|
||||||
use graphene_core::raster::adjustments::blend_colors;
|
use graphene_core::raster::adjustments::blend_colors;
|
||||||
use graphene_core::raster::bbox::{AxisAlignedBbox, Bbox};
|
use graphene_core::raster::bbox::{AxisAlignedBbox, Bbox};
|
||||||
use graphene_core::raster::brush_cache::BrushCache;
|
use graphene_core::raster::brush_cache::BrushCache;
|
||||||
use graphene_core::raster::image::{Image, RasterDataTable};
|
use graphene_core::raster::image::Image;
|
||||||
use graphene_core::raster::{Alpha, BitmapMut, BlendMode, Color, Pixel, Sample};
|
use graphene_core::raster::{Alpha, BitmapMut, BlendMode, Color, Pixel, Sample};
|
||||||
|
use graphene_core::raster_types::{CPU, Raster, RasterDataTable};
|
||||||
use graphene_core::renderer::GraphicElementRendered;
|
use graphene_core::renderer::GraphicElementRendered;
|
||||||
use graphene_core::transform::Transform;
|
use graphene_core::transform::Transform;
|
||||||
use graphene_core::value::ClonedNode;
|
use graphene_core::value::ClonedNode;
|
||||||
|
@ -80,11 +81,10 @@ fn brush_stamp_generator(diameter: f64, color: Color, hardness: f64, flow: f64)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(skip_impl)]
|
#[node_macro::node(skip_impl)]
|
||||||
fn blit<P, BlendFn>(mut target: RasterDataTable<P>, texture: Image<P>, positions: Vec<DVec2>, blend_mode: BlendFn) -> RasterDataTable<P>
|
fn blit<BlendFn>(mut target: RasterDataTable<CPU>, texture: Raster<CPU>, positions: Vec<DVec2>, blend_mode: BlendFn) -> RasterDataTable<CPU>
|
||||||
where
|
where
|
||||||
P: Pixel + Alpha + std::fmt::Debug,
|
BlendFn: for<'any_input> Node<'any_input, (Color, Color), Output = Color>,
|
||||||
BlendFn: for<'any_input> Node<'any_input, (P, P), Output = P>,
|
GraphicElement: From<Raster<CPU>>,
|
||||||
GraphicElement: From<Image<P>>,
|
|
||||||
{
|
{
|
||||||
if positions.is_empty() {
|
if positions.is_empty() {
|
||||||
return target;
|
return target;
|
||||||
|
@ -122,7 +122,7 @@ where
|
||||||
for y in blit_area_offset.y..blit_area_offset.y + blit_area_dimensions.y {
|
for y in blit_area_offset.y..blit_area_offset.y + blit_area_dimensions.y {
|
||||||
for x in blit_area_offset.x..blit_area_offset.x + blit_area_dimensions.x {
|
for x in blit_area_offset.x..blit_area_offset.x + blit_area_dimensions.x {
|
||||||
let src_pixel = texture.data[texture_index(x, y)];
|
let src_pixel = texture.data[texture_index(x, y)];
|
||||||
let dst_pixel = &mut target_instance.instance.data[target_index(x + clamp_start.x, y + clamp_start.y)];
|
let dst_pixel = &mut target_instance.instance.data_mut().data[target_index(x + clamp_start.x, y + clamp_start.y)];
|
||||||
*dst_pixel = blend_mode.eval((src_pixel, *dst_pixel));
|
*dst_pixel = blend_mode.eval((src_pixel, *dst_pixel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ where
|
||||||
target
|
target
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_brush_texture(brush_style: &BrushStyle) -> Image<Color> {
|
pub async fn create_brush_texture(brush_style: &BrushStyle) -> Raster<CPU> {
|
||||||
let stamp = brush_stamp_generator(brush_style.diameter, brush_style.color, brush_style.hardness, brush_style.flow);
|
let stamp = brush_stamp_generator(brush_style.diameter, brush_style.color, brush_style.hardness, brush_style.flow);
|
||||||
let transform = DAffine2::from_scale_angle_translation(DVec2::splat(brush_style.diameter), 0., -DVec2::splat(brush_style.diameter / 2.));
|
let transform = DAffine2::from_scale_angle_translation(DVec2::splat(brush_style.diameter), 0., -DVec2::splat(brush_style.diameter / 2.));
|
||||||
let blank_texture = empty_image((), transform, Color::TRANSPARENT).instance_iter().next().unwrap_or_default();
|
let blank_texture = empty_image((), transform, Color::TRANSPARENT).instance_iter().next().unwrap_or_default();
|
||||||
|
@ -141,7 +141,7 @@ pub async fn create_brush_texture(brush_style: &BrushStyle) -> Image<Color> {
|
||||||
image.instance
|
image.instance
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn blend_with_mode(background: Instance<Image<Color>>, foreground: Instance<Image<Color>>, blend_mode: BlendMode, opacity: f64) -> Instance<Image<Color>> {
|
pub fn blend_with_mode(background: Instance<Raster<CPU>>, foreground: Instance<Raster<CPU>>, blend_mode: BlendMode, opacity: f64) -> Instance<Raster<CPU>> {
|
||||||
let opacity = opacity / 100.;
|
let opacity = opacity / 100.;
|
||||||
match std::hint::black_box(blend_mode) {
|
match std::hint::black_box(blend_mode) {
|
||||||
// Normal group
|
// Normal group
|
||||||
|
@ -184,12 +184,12 @@ pub fn blend_with_mode(background: Instance<Image<Color>>, foreground: Instance<
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Raster"))]
|
#[node_macro::node(category("Raster"))]
|
||||||
async fn brush(_: impl Ctx, mut image_frame_table: RasterDataTable<Color>, strokes: Vec<BrushStroke>, cache: BrushCache) -> RasterDataTable<Color> {
|
async fn brush(_: impl Ctx, mut image_frame_table: RasterDataTable<CPU>, strokes: Vec<BrushStroke>, cache: BrushCache) -> RasterDataTable<CPU> {
|
||||||
|
if image_frame_table.is_empty() {
|
||||||
|
image_frame_table.push(Instance::default());
|
||||||
|
}
|
||||||
// TODO: Find a way to handle more than one instance
|
// TODO: Find a way to handle more than one instance
|
||||||
let Some(image_frame_instance) = image_frame_table.instance_ref_iter().next() else {
|
let image_frame_instance = image_frame_table.instance_ref_iter().next().expect("Expected the one instance we just pushed").to_instance_cloned();
|
||||||
return RasterDataTable::default();
|
|
||||||
};
|
|
||||||
let image_frame_instance = image_frame_instance.to_instance_cloned();
|
|
||||||
|
|
||||||
let [start, end] = image_frame_instance.clone().to_table().bounding_box(DAffine2::IDENTITY, false).unwrap_or([DVec2::ZERO, DVec2::ZERO]);
|
let [start, end] = image_frame_instance.clone().to_table().bounding_box(DAffine2::IDENTITY, false).unwrap_or([DVec2::ZERO, DVec2::ZERO]);
|
||||||
let image_bbox = AxisAlignedBbox { start, end };
|
let image_bbox = AxisAlignedBbox { start, end };
|
||||||
|
@ -268,7 +268,7 @@ async fn brush(_: impl Ctx, mut image_frame_table: RasterDataTable<Color>, strok
|
||||||
if has_erase_strokes {
|
if has_erase_strokes {
|
||||||
let opaque_image = Image::new(bbox.size().x as u32, bbox.size().y as u32, Color::WHITE);
|
let opaque_image = Image::new(bbox.size().x as u32, bbox.size().y as u32, Color::WHITE);
|
||||||
let mut erase_restore_mask = Instance {
|
let mut erase_restore_mask = Instance {
|
||||||
instance: opaque_image,
|
instance: Raster::new_cpu(opaque_image),
|
||||||
transform: background_bounds,
|
transform: background_bounds,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -320,7 +320,7 @@ async fn brush(_: impl Ctx, mut image_frame_table: RasterDataTable<Color>, strok
|
||||||
image_frame_table
|
image_frame_table
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn blend_image_closure(foreground: Instance<Image<Color>>, mut background: Instance<Image<Color>>, map_fn: impl Fn(Color, Color) -> Color) -> Instance<Image<Color>> {
|
pub fn blend_image_closure(foreground: Instance<Raster<CPU>>, mut background: Instance<Raster<CPU>>, map_fn: impl Fn(Color, Color) -> Color) -> Instance<Raster<CPU>> {
|
||||||
let foreground_size = DVec2::new(foreground.instance.width as f64, foreground.instance.height as f64);
|
let foreground_size = DVec2::new(foreground.instance.width as f64, foreground.instance.height as f64);
|
||||||
let background_size = DVec2::new(background.instance.width as f64, background.instance.height as f64);
|
let background_size = DVec2::new(background.instance.width as f64, background.instance.height as f64);
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ pub fn blend_image_closure(foreground: Instance<Image<Color>>, mut background: I
|
||||||
let foreground_point = background_to_foreground.transform_point2(background_point);
|
let foreground_point = background_to_foreground.transform_point2(background_point);
|
||||||
|
|
||||||
let source_pixel = foreground.instance.sample(foreground_point);
|
let source_pixel = foreground.instance.sample(foreground_point);
|
||||||
let Some(destination_pixel) = background.instance.get_pixel_mut(x, y) else { continue };
|
let Some(destination_pixel) = background.instance.data_mut().get_pixel_mut(x, y) else { continue };
|
||||||
|
|
||||||
*destination_pixel = map_fn(source_pixel, *destination_pixel);
|
*destination_pixel = map_fn(source_pixel, *destination_pixel);
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ pub fn blend_image_closure(foreground: Instance<Image<Color>>, mut background: I
|
||||||
background
|
background
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn blend_stamp_closure(foreground: BrushStampGenerator<Color>, mut background: Instance<Image<Color>>, map_fn: impl Fn(Color, Color) -> Color) -> Instance<Image<Color>> {
|
pub fn blend_stamp_closure(foreground: BrushStampGenerator<Color>, mut background: Instance<Raster<CPU>>, map_fn: impl Fn(Color, Color) -> Color) -> Instance<Raster<CPU>> {
|
||||||
let background_size = DVec2::new(background.instance.width as f64, background.instance.height as f64);
|
let background_size = DVec2::new(background.instance.width as f64, background.instance.height as f64);
|
||||||
|
|
||||||
// Transforms a point from the background image to the foreground image
|
// Transforms a point from the background image to the foreground image
|
||||||
|
@ -369,7 +369,7 @@ pub fn blend_stamp_closure(foreground: BrushStampGenerator<Color>, mut backgroun
|
||||||
let foreground_point = background_to_foreground.transform_point2(background_point);
|
let foreground_point = background_to_foreground.transform_point2(background_point);
|
||||||
|
|
||||||
let Some(source_pixel) = foreground.sample(foreground_point, area) else { continue };
|
let Some(source_pixel) = foreground.sample(foreground_point, area) else { continue };
|
||||||
let Some(destination_pixel) = background.instance.get_pixel_mut(x, y) else { continue };
|
let Some(destination_pixel) = background.instance.data_mut().get_pixel_mut(x, y) else { continue };
|
||||||
|
|
||||||
*destination_pixel = map_fn(source_pixel, *destination_pixel);
|
*destination_pixel = map_fn(source_pixel, *destination_pixel);
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ mod test {
|
||||||
async fn test_brush_output_size() {
|
async fn test_brush_output_size() {
|
||||||
let image = brush(
|
let image = brush(
|
||||||
(),
|
(),
|
||||||
RasterDataTable::<Color>::new(Image::<Color>::default()),
|
RasterDataTable::<CPU>::new(Raster::new_cpu(Image::<Color>::default())),
|
||||||
vec![BrushStroke {
|
vec![BrushStroke {
|
||||||
trace: vec![crate::vector::brush_stroke::BrushInputSample { position: DVec2::ZERO }],
|
trace: vec![crate::vector::brush_stroke::BrushInputSample { position: DVec2::ZERO }],
|
||||||
style: BrushStyle {
|
style: BrushStyle {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use graph_craft::proto::types::Percentage;
|
use graph_craft::proto::types::Percentage;
|
||||||
use graphene_core::raster::image::{Image, RasterDataTable};
|
use graphene_core::Ctx;
|
||||||
use graphene_core::{Color, Ctx};
|
use graphene_core::raster::image::Image;
|
||||||
|
use graphene_core::raster_types::{CPU, Raster, RasterDataTable};
|
||||||
use image::{DynamicImage, GenericImage, GenericImageView, GrayImage, ImageBuffer, Luma, Rgba, RgbaImage};
|
use image::{DynamicImage, GenericImage, GenericImageView, GrayImage, ImageBuffer, Luma, Rgba, RgbaImage};
|
||||||
use ndarray::{Array2, ArrayBase, Dim, OwnedRepr};
|
use ndarray::{Array2, ArrayBase, Dim, OwnedRepr};
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
|
|
||||||
#[node_macro::node(category("Raster"))]
|
#[node_macro::node(category("Raster"))]
|
||||||
async fn dehaze(_: impl Ctx, image_frame: RasterDataTable<Color>, strength: Percentage) -> RasterDataTable<Color> {
|
async fn dehaze(_: impl Ctx, image_frame: RasterDataTable<CPU>, strength: Percentage) -> RasterDataTable<CPU> {
|
||||||
let mut result_table = RasterDataTable::default();
|
let mut result_table = RasterDataTable::default();
|
||||||
|
|
||||||
for mut image_frame_instance in image_frame.instance_iter() {
|
for mut image_frame_instance in image_frame.instance_iter() {
|
||||||
|
@ -29,7 +30,7 @@ async fn dehaze(_: impl Ctx, image_frame: RasterDataTable<Color>, strength: Perc
|
||||||
base64_string: None,
|
base64_string: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
image_frame_instance.instance = dehazed_image;
|
image_frame_instance.instance = Raster::new_cpu(dehazed_image);
|
||||||
image_frame_instance.source_node_id = None;
|
image_frame_instance.source_node_id = None;
|
||||||
result_table.push(image_frame_instance);
|
result_table.push(image_frame_instance);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use graph_craft::proto::types::PixelLength;
|
use graph_craft::proto::types::PixelLength;
|
||||||
use graphene_core::raster::image::{Image, RasterDataTable};
|
use graphene_core::raster::image::Image;
|
||||||
use graphene_core::raster::{Bitmap, BitmapMut};
|
use graphene_core::raster::{Bitmap, BitmapMut};
|
||||||
|
use graphene_core::raster_types::{CPU, Raster, RasterDataTable};
|
||||||
use graphene_core::{Color, Ctx};
|
use graphene_core::{Color, Ctx};
|
||||||
|
|
||||||
/// Blurs the image with a Gaussian or blur kernel filter.
|
/// Blurs the image with a Gaussian or blur kernel filter.
|
||||||
|
@ -8,7 +9,7 @@ use graphene_core::{Color, Ctx};
|
||||||
async fn blur(
|
async fn blur(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
/// The image to be blurred.
|
/// The image to be blurred.
|
||||||
image_frame: RasterDataTable<Color>,
|
image_frame: RasterDataTable<CPU>,
|
||||||
/// The radius of the blur kernel.
|
/// The radius of the blur kernel.
|
||||||
#[range((0., 100.))]
|
#[range((0., 100.))]
|
||||||
#[hard_min(0.)]
|
#[hard_min(0.)]
|
||||||
|
@ -17,7 +18,7 @@ async fn blur(
|
||||||
box_blur: bool,
|
box_blur: bool,
|
||||||
/// Opt to incorrectly apply the filter with color calculations in gamma space for compatibility with the results from other software.
|
/// Opt to incorrectly apply the filter with color calculations in gamma space for compatibility with the results from other software.
|
||||||
gamma: bool,
|
gamma: bool,
|
||||||
) -> RasterDataTable<Color> {
|
) -> RasterDataTable<CPU> {
|
||||||
let mut result_table = RasterDataTable::default();
|
let mut result_table = RasterDataTable::default();
|
||||||
|
|
||||||
for mut image_instance in image_frame.instance_iter() {
|
for mut image_instance in image_frame.instance_iter() {
|
||||||
|
@ -28,9 +29,9 @@ async fn blur(
|
||||||
// Minimum blur radius
|
// Minimum blur radius
|
||||||
image.clone()
|
image.clone()
|
||||||
} else if box_blur {
|
} else if box_blur {
|
||||||
box_blur_algorithm(image, radius, gamma)
|
Raster::new_cpu(box_blur_algorithm(image.into_data(), radius, gamma))
|
||||||
} else {
|
} else {
|
||||||
gaussian_blur_algorithm(image, radius, gamma)
|
Raster::new_cpu(gaussian_blur_algorithm(image.into_data(), radius, gamma))
|
||||||
};
|
};
|
||||||
|
|
||||||
image_instance.instance = blurred_image;
|
image_instance.instance = blurred_image;
|
||||||
|
|
|
@ -1,455 +0,0 @@
|
||||||
use glam::{DAffine2, DVec2, Mat2, Vec2};
|
|
||||||
use gpu_executor::{ComputePassDimensions, StorageBufferOptions};
|
|
||||||
use graph_craft::document::value::TaggedValue;
|
|
||||||
use graph_craft::document::*;
|
|
||||||
use graph_craft::proto::*;
|
|
||||||
use graphene_core::raster::BlendMode;
|
|
||||||
use graphene_core::raster::image::{Image, RasterDataTable};
|
|
||||||
use graphene_core::*;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use wgpu_executor::{Bindgroup, PipelineLayout, Shader, ShaderIO, ShaderInput, WgpuExecutor};
|
|
||||||
|
|
||||||
// TODO: Move to graph-craft
|
|
||||||
#[node_macro::node(category("Debug: GPU"))]
|
|
||||||
async fn compile_gpu<'a: 'n>(_: impl Ctx, node: &'a DocumentNode, typing_context: TypingContext, io: ShaderIO) -> Result<compilation_client::Shader, String> {
|
|
||||||
let mut typing_context = typing_context;
|
|
||||||
let compiler = graph_craft::graphene_compiler::Compiler {};
|
|
||||||
let DocumentNodeImplementation::Network(ref network) = node.implementation else { panic!() };
|
|
||||||
let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone()).collect();
|
|
||||||
let proto_networks = proto_networks?;
|
|
||||||
|
|
||||||
for network in proto_networks.iter() {
|
|
||||||
typing_context.update(network).expect("Failed to type check network");
|
|
||||||
}
|
|
||||||
// TODO: do a proper union
|
|
||||||
let input_types = proto_networks[0]
|
|
||||||
.inputs
|
|
||||||
.iter()
|
|
||||||
.map(|id| typing_context.type_of(*id).unwrap())
|
|
||||||
.map(|node_io| node_io.return_value.clone())
|
|
||||||
.collect();
|
|
||||||
let output_types = proto_networks.iter().map(|network| typing_context.type_of(network.output).unwrap().return_value.clone()).collect();
|
|
||||||
|
|
||||||
Ok(compilation_client::compile(proto_networks, input_types, output_types, io).await.unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[node_macro::node(category("Debug: GPU"))]
|
|
||||||
async fn blend_gpu_image(_: impl Ctx, foreground: RasterDataTable<Color>, background: RasterDataTable<Color>, blend_mode: BlendMode, opacity: f64) -> RasterDataTable<Color> {
|
|
||||||
let mut result_table = RasterDataTable::default();
|
|
||||||
|
|
||||||
for (foreground_instance, mut background_instance) in foreground.instance_iter().zip(background.instance_iter()) {
|
|
||||||
let foreground_transform = foreground_instance.transform;
|
|
||||||
let background_transform = background_instance.transform;
|
|
||||||
|
|
||||||
let foreground = foreground_instance.instance;
|
|
||||||
let background = background_instance.instance;
|
|
||||||
|
|
||||||
let foreground_size = DVec2::new(foreground.width as f64, foreground.height as f64);
|
|
||||||
let background_size = DVec2::new(background.width as f64, background.height as f64);
|
|
||||||
|
|
||||||
// Transforms a point from the background image to the foreground image
|
|
||||||
let bg_to_fg = DAffine2::from_scale(foreground_size) * foreground_transform.inverse() * background_transform * DAffine2::from_scale(1. / background_size);
|
|
||||||
|
|
||||||
let transform_matrix: Mat2 = bg_to_fg.matrix2.as_mat2();
|
|
||||||
let translation: Vec2 = bg_to_fg.translation.as_vec2();
|
|
||||||
|
|
||||||
log::debug!("Executing gpu blend node!");
|
|
||||||
let compiler = graph_craft::graphene_compiler::Compiler {};
|
|
||||||
|
|
||||||
let network = NodeNetwork {
|
|
||||||
exports: vec![NodeInput::node(NodeId(0), 0)],
|
|
||||||
nodes: [DocumentNode {
|
|
||||||
inputs: vec![NodeInput::Inline(InlineRust::new(
|
|
||||||
format!(
|
|
||||||
r#"graphene_core::raster::adjustments::BlendNode::new(
|
|
||||||
graphene_core::value::CopiedNode::new({}),
|
|
||||||
graphene_core::value::CopiedNode::new({}),
|
|
||||||
).eval((
|
|
||||||
{{
|
|
||||||
let bg_point = Vec2::new(_global_index.x as f32, _global_index.y as f32);
|
|
||||||
let fg_point = (*i4) * bg_point + (*i5);
|
|
||||||
|
|
||||||
if !((fg_point.cmpge(Vec2::ZERO) & bg_point.cmpge(Vec2::ZERO)) == BVec2::new(true, true)) {{
|
|
||||||
Color::from_rgbaf32_unchecked(0., 0., 0., 0.)
|
|
||||||
}} else {{
|
|
||||||
i2[((fg_point.y as u32) * i3 + (fg_point.x as u32)) as usize]
|
|
||||||
}}
|
|
||||||
}},
|
|
||||||
i1[(_global_index.y * i0 + _global_index.x) as usize],
|
|
||||||
))"#,
|
|
||||||
TaggedValue::BlendMode(blend_mode).to_primitive_string(),
|
|
||||||
TaggedValue::F64(opacity).to_primitive_string(),
|
|
||||||
),
|
|
||||||
concrete![Color],
|
|
||||||
))],
|
|
||||||
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::value::CopiedNode".into()),
|
|
||||||
..Default::default()
|
|
||||||
}]
|
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(id, node)| (NodeId(id as u64), node))
|
|
||||||
.collect(),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
log::debug!("compiling network");
|
|
||||||
let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone()).collect();
|
|
||||||
let Ok(proto_networks_result) = proto_networks else {
|
|
||||||
log::error!("Error compiling network in 'blend_gpu_image()");
|
|
||||||
return RasterDataTable::default();
|
|
||||||
};
|
|
||||||
let proto_networks = proto_networks_result;
|
|
||||||
log::debug!("compiling shader");
|
|
||||||
|
|
||||||
let shader = compilation_client::compile(
|
|
||||||
proto_networks,
|
|
||||||
vec![
|
|
||||||
concrete!(u32),
|
|
||||||
concrete!(Color),
|
|
||||||
concrete!(Color),
|
|
||||||
concrete!(u32),
|
|
||||||
concrete_with_name!(Mat2, "Mat2"),
|
|
||||||
concrete_with_name!(Vec2, "Vec2"),
|
|
||||||
],
|
|
||||||
vec![concrete!(Color)],
|
|
||||||
ShaderIO {
|
|
||||||
inputs: vec![
|
|
||||||
ShaderInput::UniformBuffer((), concrete!(u32)), // width of the output image
|
|
||||||
ShaderInput::StorageBuffer((), concrete!(Color)), // background image
|
|
||||||
ShaderInput::StorageBuffer((), concrete!(Color)), // foreground image
|
|
||||||
ShaderInput::UniformBuffer((), concrete!(u32)), // width of the foreground image
|
|
||||||
ShaderInput::UniformBuffer((), concrete_with_name!(Mat2, "Mat2")), // bg_to_fg.matrix2
|
|
||||||
ShaderInput::UniformBuffer((), concrete_with_name!(Vec2, "Vec2")), // bg_to_fg.translation
|
|
||||||
ShaderInput::OutputBuffer((), concrete!(Color)),
|
|
||||||
],
|
|
||||||
output: ShaderInput::OutputBuffer((), concrete!(Color)),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let len = background.data.len();
|
|
||||||
|
|
||||||
let executor = WgpuExecutor::new()
|
|
||||||
.await
|
|
||||||
.expect("Failed to create wgpu executor. Please make sure that webgpu is enabled for your browser.");
|
|
||||||
log::debug!("creating buffer");
|
|
||||||
let width_uniform = executor.create_uniform_buffer(background.width).unwrap();
|
|
||||||
let bg_storage_buffer = executor
|
|
||||||
.create_storage_buffer(
|
|
||||||
background.data.clone(),
|
|
||||||
StorageBufferOptions {
|
|
||||||
cpu_writable: false,
|
|
||||||
gpu_writable: true,
|
|
||||||
cpu_readable: false,
|
|
||||||
storage: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let fg_storage_buffer = executor
|
|
||||||
.create_storage_buffer(
|
|
||||||
foreground.data.clone(),
|
|
||||||
StorageBufferOptions {
|
|
||||||
cpu_writable: false,
|
|
||||||
gpu_writable: true,
|
|
||||||
cpu_readable: false,
|
|
||||||
storage: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let fg_width_uniform = executor.create_uniform_buffer(foreground.width).unwrap();
|
|
||||||
let transform_uniform = executor.create_uniform_buffer(transform_matrix).unwrap();
|
|
||||||
let translation_uniform = executor.create_uniform_buffer(translation).unwrap();
|
|
||||||
let width_uniform = Arc::new(width_uniform);
|
|
||||||
let bg_storage_buffer = Arc::new(bg_storage_buffer);
|
|
||||||
let fg_storage_buffer = Arc::new(fg_storage_buffer);
|
|
||||||
let fg_width_uniform = Arc::new(fg_width_uniform);
|
|
||||||
let transform_uniform = Arc::new(transform_uniform);
|
|
||||||
let translation_uniform = Arc::new(translation_uniform);
|
|
||||||
let output_buffer = executor.create_output_buffer(len, concrete!(Color), false).unwrap();
|
|
||||||
let output_buffer = Arc::new(output_buffer);
|
|
||||||
let readback_buffer = executor.create_output_buffer(len, concrete!(Color), true).unwrap();
|
|
||||||
let readback_buffer = Arc::new(readback_buffer);
|
|
||||||
log::debug!("created buffer");
|
|
||||||
let bind_group = Bindgroup {
|
|
||||||
buffers: vec![
|
|
||||||
width_uniform.clone(),
|
|
||||||
bg_storage_buffer.clone(),
|
|
||||||
fg_storage_buffer.clone(),
|
|
||||||
fg_width_uniform.clone(),
|
|
||||||
transform_uniform.clone(),
|
|
||||||
translation_uniform.clone(),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
let shader = Shader {
|
|
||||||
source: shader.spirv_binary.into(),
|
|
||||||
name: "gpu::eval",
|
|
||||||
io: shader.io,
|
|
||||||
};
|
|
||||||
log::debug!("loading shader");
|
|
||||||
log::debug!("shader: {:?}", shader.source);
|
|
||||||
let shader = executor.load_shader(shader).unwrap();
|
|
||||||
log::debug!("loaded shader");
|
|
||||||
let pipeline = PipelineLayout {
|
|
||||||
shader: shader.into(),
|
|
||||||
entry_point: "eval".to_string(),
|
|
||||||
bind_group: bind_group.into(),
|
|
||||||
output_buffer: output_buffer.clone(),
|
|
||||||
};
|
|
||||||
log::debug!("created pipeline");
|
|
||||||
let compute_pass = executor
|
|
||||||
.create_compute_pass(&pipeline, Some(readback_buffer.clone()), ComputePassDimensions::XY(background.width, background.height))
|
|
||||||
.unwrap();
|
|
||||||
executor.execute_compute_pipeline(compute_pass).unwrap();
|
|
||||||
log::debug!("executed pipeline");
|
|
||||||
log::debug!("reading buffer");
|
|
||||||
let result = executor.read_output_buffer(readback_buffer).await.unwrap();
|
|
||||||
let colors = bytemuck::pod_collect_to_vec::<u8, Color>(result.as_slice());
|
|
||||||
|
|
||||||
let created_image = Image {
|
|
||||||
data: colors,
|
|
||||||
width: background.width,
|
|
||||||
height: background.height,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
background_instance.instance = created_image;
|
|
||||||
background_instance.source_node_id = None;
|
|
||||||
result_table.push(background_instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
result_table
|
|
||||||
}
|
|
||||||
|
|
||||||
// struct ComputePass {
|
|
||||||
// pipeline_layout: PipelineLayout,
|
|
||||||
// readback_buffer: Option<Arc<WgpuShaderInput>>,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl Clone for ComputePass {
|
|
||||||
// fn clone(&self) -> Self {
|
|
||||||
// Self {
|
|
||||||
// pipeline_layout: self.pipeline_layout.clone(),
|
|
||||||
// readback_buffer: self.readback_buffer.clone(),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub struct MapGpuNode<Node, EditorApi> {
|
|
||||||
// node: Node,
|
|
||||||
// editor_api: EditorApi,
|
|
||||||
// cache: Mutex<HashMap<String, ComputePass>>,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[node_macro::old_node_impl(MapGpuNode)]
|
|
||||||
// async fn map_gpu<'a: 'input>(image: RasterDataTable<Color>, node: DocumentNode, editor_api: &'a graphene_core::application_io::EditorApi<WasmApplicationIo>) -> RasterDataTable<Color> {
|
|
||||||
// let image_frame_table = ℑ
|
|
||||||
// let image = image.instance_ref_iter().next().unwrap().instance;
|
|
||||||
|
|
||||||
// log::debug!("Executing gpu node");
|
|
||||||
// let executor = &editor_api.application_io.as_ref().and_then(|io| io.gpu_executor()).unwrap();
|
|
||||||
|
|
||||||
// #[cfg(feature = "image-compare")]
|
|
||||||
// let img: image::DynamicImage = image::Rgba32FImage::from_raw(image.width, image.height, bytemuck::cast_vec(image.data.clone())).unwrap().into();
|
|
||||||
|
|
||||||
// // TODO: The cache should be based on the network topology not the node name
|
|
||||||
// let compute_pass_descriptor = if self.cache.lock().as_ref().unwrap().contains_key("placeholder") {
|
|
||||||
// self.cache.lock().as_ref().unwrap().get("placeholder").unwrap().clone()
|
|
||||||
// } else {
|
|
||||||
// let name = "placeholder".to_string();
|
|
||||||
// let Ok(compute_pass_descriptor) = create_compute_pass_descriptor(node, image_frame_table, executor).await else {
|
|
||||||
// log::error!("Error creating compute pass descriptor in 'map_gpu()");
|
|
||||||
// return RasterDataTable::default();
|
|
||||||
// };
|
|
||||||
// self.cache.lock().as_mut().unwrap().insert(name, compute_pass_descriptor.clone());
|
|
||||||
// log::error!("created compute pass");
|
|
||||||
// compute_pass_descriptor
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let compute_pass = executor
|
|
||||||
// .create_compute_pass(
|
|
||||||
// &compute_pass_descriptor.pipeline_layout,
|
|
||||||
// compute_pass_descriptor.readback_buffer.clone(),
|
|
||||||
// ComputePassDimensions::XY(image.width / 12 + 1, image.height / 8 + 1),
|
|
||||||
// )
|
|
||||||
// .unwrap();
|
|
||||||
// executor.execute_compute_pipeline(compute_pass).unwrap();
|
|
||||||
// log::debug!("executed pipeline");
|
|
||||||
// log::debug!("reading buffer");
|
|
||||||
// let result = executor.read_output_buffer(compute_pass_descriptor.readback_buffer.clone().unwrap()).await.unwrap();
|
|
||||||
// let colors = bytemuck::pod_collect_to_vec::<u8, Color>(result.as_slice());
|
|
||||||
// log::debug!("first color: {:?}", colors[0]);
|
|
||||||
|
|
||||||
// #[cfg(feature = "image-compare")]
|
|
||||||
// let img2: image::DynamicImage = image::Rgba32FImage::from_raw(image.width, image.height, bytemuck::cast_vec(colors.clone())).unwrap().into();
|
|
||||||
// #[cfg(feature = "image-compare")]
|
|
||||||
// let score = image_compare::rgb_hybrid_compare(&img.into_rgb8(), &img2.into_rgb8()).unwrap();
|
|
||||||
// #[cfg(feature = "image-compare")]
|
|
||||||
// log::debug!("score: {:?}", score.score);
|
|
||||||
|
|
||||||
// let new_image = Image {
|
|
||||||
// data: colors,
|
|
||||||
// width: image.width,
|
|
||||||
// height: image.height,
|
|
||||||
// ..Default::default()
|
|
||||||
// };
|
|
||||||
// let mut result = RasterDataTable::new(new_image);
|
|
||||||
// *result.transform_mut() = image_frame_table.transform();
|
|
||||||
// *result.instance_mut_iter().next().unwrap().alpha_blending = *image_frame_table.instance_ref_iter().next().unwrap().alpha_blending;
|
|
||||||
|
|
||||||
// result
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<Node, EditorApi> MapGpuNode<Node, EditorApi> {
|
|
||||||
// pub fn new(node: Node, editor_api: EditorApi) -> Self {
|
|
||||||
// Self {
|
|
||||||
// node,
|
|
||||||
// editor_api,
|
|
||||||
// cache: Mutex::new(HashMap::new()),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async fn create_compute_pass_descriptor<T: Clone + Pixel + StaticTypeSized>(node: DocumentNode, image: &RasterDataTable<T>, executor: &&WgpuExecutor) -> Result<ComputePass, String>
|
|
||||||
// where
|
|
||||||
// GraphicElement: From<Image<T>>,
|
|
||||||
// T::Static: Pixel,
|
|
||||||
// {
|
|
||||||
// let image = image.instance_ref_iter().next().unwrap().instance;
|
|
||||||
|
|
||||||
// let compiler = graph_craft::graphene_compiler::Compiler {};
|
|
||||||
// let inner_network = NodeNetwork::value_network(node);
|
|
||||||
|
|
||||||
// log::debug!("inner_network: {inner_network:?}");
|
|
||||||
// let network = NodeNetwork {
|
|
||||||
// exports: vec![NodeInput::node(NodeId(2), 0)],
|
|
||||||
// nodes: [
|
|
||||||
// DocumentNode {
|
|
||||||
// inputs: vec![NodeInput::Inline(InlineRust::new("i1[(_global_index.y * i0 + _global_index.x) as usize]".into(), concrete![Color]))],
|
|
||||||
// implementation: DocumentNodeImplementation::ProtoNode("graphene_core::value::CopiedNode".into()),
|
|
||||||
// ..Default::default()
|
|
||||||
// },
|
|
||||||
// DocumentNode {
|
|
||||||
// inputs: vec![NodeInput::network(concrete!(u32), 0)],
|
|
||||||
// implementation: DocumentNodeImplementation::ProtoNode("graphene_core::ops::IdentityNode".into()),
|
|
||||||
// ..Default::default()
|
|
||||||
// },
|
|
||||||
// // DocumentNode {
|
|
||||||
// // name: "Index".into(),
|
|
||||||
// // // inputs: vec![NodeInput::Network(concrete!(UVec3))],
|
|
||||||
// // inputs: vec![NodeInput::Inline(InlineRust::new("i1.x as usize".into(), concrete![u32]))],
|
|
||||||
// // implementation: DocumentNodeImplementation::ProtoNode("graphene_core::value::CopiedNode".into()),
|
|
||||||
// // ..Default::default()
|
|
||||||
// // },
|
|
||||||
// // DocumentNode {
|
|
||||||
// // name: "Get Node".into(),
|
|
||||||
// // inputs: vec![NodeInput::node(NodeId(1), 0), NodeInput::node(NodeId(0), 0)],
|
|
||||||
// // implementation: DocumentNodeImplementation::ProtoNode("graphene_core::storage::GetNode".into()),
|
|
||||||
// // ..Default::default()
|
|
||||||
// // },
|
|
||||||
// DocumentNode {
|
|
||||||
// inputs: vec![NodeInput::node(NodeId(0), 0)],
|
|
||||||
// implementation: DocumentNodeImplementation::Network(inner_network),
|
|
||||||
// ..Default::default()
|
|
||||||
// },
|
|
||||||
// // DocumentNode {
|
|
||||||
// // name: "Save Node".into(),
|
|
||||||
// // inputs: vec![
|
|
||||||
// // NodeInput::node(NodeId(5), 0),
|
|
||||||
// // NodeInput::Inline(InlineRust::new(
|
|
||||||
// // "|x| o0[(_global_index.y * i1 + _global_index.x) as usize] = x".into(),
|
|
||||||
// // // "|x|()".into(),
|
|
||||||
// // Type::Fn(Box::new(concrete!(PackedPixel)), Box::new(concrete!(()))),
|
|
||||||
// // )),
|
|
||||||
// // ],
|
|
||||||
// // implementation: DocumentNodeImplementation::ProtoNode("graphene_core::generic::FnMutNode".into()),
|
|
||||||
// // ..Default::default()
|
|
||||||
// // },
|
|
||||||
// ]
|
|
||||||
// .into_iter()
|
|
||||||
// .enumerate()
|
|
||||||
// .map(|(id, node)| (NodeId(id as u64), node))
|
|
||||||
// .collect(),
|
|
||||||
// ..Default::default()
|
|
||||||
// };
|
|
||||||
// log::debug!("compiling network");
|
|
||||||
// let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone()).collect();
|
|
||||||
// log::debug!("compiling shader");
|
|
||||||
// let shader = compilation_client::compile(
|
|
||||||
// proto_networks?,
|
|
||||||
// vec![concrete!(u32), concrete!(Color)],
|
|
||||||
// vec![concrete!(Color)],
|
|
||||||
// ShaderIO {
|
|
||||||
// inputs: vec![
|
|
||||||
// ShaderInput::UniformBuffer((), concrete!(u32)),
|
|
||||||
// ShaderInput::StorageBuffer((), concrete!(Color)),
|
|
||||||
// ShaderInput::OutputBuffer((), concrete!(Color)),
|
|
||||||
// ],
|
|
||||||
// output: ShaderInput::OutputBuffer((), concrete!(Color)),
|
|
||||||
// },
|
|
||||||
// )
|
|
||||||
// .await
|
|
||||||
// .unwrap();
|
|
||||||
|
|
||||||
// let len: usize = image.data.len();
|
|
||||||
|
|
||||||
// let storage_buffer = executor
|
|
||||||
// .create_storage_buffer(
|
|
||||||
// image.data.clone(),
|
|
||||||
// StorageBufferOptions {
|
|
||||||
// cpu_writable: false,
|
|
||||||
// gpu_writable: true,
|
|
||||||
// cpu_readable: false,
|
|
||||||
// storage: true,
|
|
||||||
// },
|
|
||||||
// )
|
|
||||||
// .unwrap();
|
|
||||||
|
|
||||||
// // let canvas = editor_api.application_io.create_surface();
|
|
||||||
|
|
||||||
// // let surface = unsafe { executor.create_surface(canvas) }.unwrap();
|
|
||||||
// // let surface_id = surface.surface_id;
|
|
||||||
|
|
||||||
// // let texture = executor.create_texture_buffer(image.clone(), TextureBufferOptions::Texture).unwrap();
|
|
||||||
|
|
||||||
// // // executor.create_render_pass(texture, surface).unwrap();
|
|
||||||
|
|
||||||
// // let frame = SurfaceFrame {
|
|
||||||
// // surface_id,
|
|
||||||
// // transform: image.transform,
|
|
||||||
// // };
|
|
||||||
// // return frame;
|
|
||||||
|
|
||||||
// log::debug!("creating buffer");
|
|
||||||
// let width_uniform = executor.create_uniform_buffer(image.width).unwrap();
|
|
||||||
|
|
||||||
// let storage_buffer = Arc::new(storage_buffer);
|
|
||||||
// let output_buffer = executor.create_output_buffer(len, concrete!(Color), false).unwrap();
|
|
||||||
// let output_buffer = Arc::new(output_buffer);
|
|
||||||
// let readback_buffer = executor.create_output_buffer(len, concrete!(Color), true).unwrap();
|
|
||||||
// let readback_buffer = Arc::new(readback_buffer);
|
|
||||||
// log::debug!("created buffer");
|
|
||||||
// let bind_group = Bindgroup {
|
|
||||||
// buffers: vec![width_uniform.into(), storage_buffer],
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let shader = Shader {
|
|
||||||
// source: shader.spirv_binary.into(),
|
|
||||||
// name: "gpu::eval",
|
|
||||||
// io: shader.io,
|
|
||||||
// };
|
|
||||||
// log::debug!("loading shader");
|
|
||||||
// let shader = executor.load_shader(shader).unwrap();
|
|
||||||
// log::debug!("loaded shader");
|
|
||||||
// let pipeline = PipelineLayout {
|
|
||||||
// shader: shader.into(),
|
|
||||||
// entry_point: "eval".to_string(),
|
|
||||||
// bind_group: bind_group.into(),
|
|
||||||
// output_buffer,
|
|
||||||
// };
|
|
||||||
// log::debug!("created pipeline");
|
|
||||||
|
|
||||||
// Ok(ComputePass {
|
|
||||||
// pipeline_layout: pipeline,
|
|
||||||
// readback_buffer: Some(readback_buffer),
|
|
||||||
// })
|
|
||||||
// }
|
|
|
@ -1,10 +1,10 @@
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
use graphene_core::raster_types::{CPU, RasterDataTable};
|
||||||
use graphene_core::{Color, Ctx};
|
use graphene_core::{Color, Ctx};
|
||||||
|
|
||||||
#[node_macro::node(category("Raster"))]
|
#[node_macro::node(category("Raster"))]
|
||||||
async fn image_color_palette(
|
async fn image_color_palette(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
image: RasterDataTable<Color>,
|
image: RasterDataTable<CPU>,
|
||||||
#[hard_min(1.)]
|
#[hard_min(1.)]
|
||||||
#[soft_max(28.)]
|
#[soft_max(28.)]
|
||||||
max_size: u32,
|
max_size: u32,
|
||||||
|
@ -64,18 +64,19 @@ async fn image_color_palette(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use graphene_core::raster::image::{Image, RasterDataTable};
|
use graphene_core::raster::image::Image;
|
||||||
|
use graphene_core::raster_types::{Raster, RasterDataTable};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_image_color_palette() {
|
fn test_image_color_palette() {
|
||||||
let result = image_color_palette(
|
let result = image_color_palette(
|
||||||
(),
|
(),
|
||||||
RasterDataTable::new(Image {
|
RasterDataTable::new(Raster::new_cpu(Image {
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
data: vec![Color::from_rgbaf32(0., 0., 0., 1.).unwrap(); 10000],
|
data: vec![Color::from_rgbaf32(0., 0., 0., 1.).unwrap(); 10000],
|
||||||
base64_string: None,
|
base64_string: None,
|
||||||
}),
|
})),
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
assert_eq!(futures::executor::block_on(result), [Color::from_rgbaf32(0., 0., 0., 1.).unwrap()]);
|
assert_eq!(futures::executor::block_on(result), [Color::from_rgbaf32(0., 0., 0., 1.).unwrap()]);
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
pub mod any;
|
pub mod any;
|
||||||
#[cfg(feature = "gpu")]
|
|
||||||
pub mod gpu_nodes;
|
|
||||||
pub mod http;
|
pub mod http;
|
||||||
pub mod raster;
|
pub mod raster;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|
|
@ -3,8 +3,10 @@ use fastnoise_lite;
|
||||||
use glam::{DAffine2, DVec2, Vec2};
|
use glam::{DAffine2, DVec2, Vec2};
|
||||||
use graphene_core::instances::Instance;
|
use graphene_core::instances::Instance;
|
||||||
use graphene_core::raster::bbox::Bbox;
|
use graphene_core::raster::bbox::Bbox;
|
||||||
use graphene_core::raster::image::{Image, RasterDataTable};
|
use graphene_core::raster::{
|
||||||
use graphene_core::raster::{Alpha, AlphaMut, Bitmap, BitmapMut, CellularDistanceFunction, CellularReturnType, Channel, DomainWarpType, FractalType, LinearChannel, Luminance, NoiseType, RGBMut};
|
Alpha, AlphaMut, Bitmap, BitmapMut, CellularDistanceFunction, CellularReturnType, Channel, DomainWarpType, FractalType, Image, LinearChannel, Luminance, NoiseType, RGBMut,
|
||||||
|
};
|
||||||
|
use graphene_core::raster_types::{CPU, Raster, RasterDataTable};
|
||||||
use graphene_core::transform::Transform;
|
use graphene_core::transform::Transform;
|
||||||
use graphene_core::{AlphaBlending, Color, Ctx, ExtractFootprint};
|
use graphene_core::{AlphaBlending, Color, Ctx, ExtractFootprint};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
|
@ -25,7 +27,7 @@ impl From<std::io::Error> for Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Debug: Raster"))]
|
#[node_macro::node(category("Debug: Raster"))]
|
||||||
fn sample_image(ctx: impl ExtractFootprint + Clone + Send, image_frame: RasterDataTable<Color>) -> RasterDataTable<Color> {
|
fn sample_image(ctx: impl ExtractFootprint + Clone + Send, image_frame: RasterDataTable<CPU>) -> RasterDataTable<CPU> {
|
||||||
let mut result_table = RasterDataTable::default();
|
let mut result_table = RasterDataTable::default();
|
||||||
|
|
||||||
for mut image_frame_instance in image_frame.instance_iter() {
|
for mut image_frame_instance in image_frame.instance_iter() {
|
||||||
|
@ -84,7 +86,7 @@ fn sample_image(ctx: impl ExtractFootprint + Clone + Send, image_frame: RasterDa
|
||||||
|
|
||||||
image_frame_instance.transform = new_transform;
|
image_frame_instance.transform = new_transform;
|
||||||
image_frame_instance.source_node_id = None;
|
image_frame_instance.source_node_id = None;
|
||||||
image_frame_instance.instance = image;
|
image_frame_instance.instance = Raster::new_cpu(image);
|
||||||
result_table.push(image_frame_instance)
|
result_table.push(image_frame_instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,11 +97,11 @@ fn sample_image(ctx: impl ExtractFootprint + Clone + Send, image_frame: RasterDa
|
||||||
fn combine_channels(
|
fn combine_channels(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
_primary: (),
|
_primary: (),
|
||||||
#[expose] red: RasterDataTable<Color>,
|
#[expose] red: RasterDataTable<CPU>,
|
||||||
#[expose] green: RasterDataTable<Color>,
|
#[expose] green: RasterDataTable<CPU>,
|
||||||
#[expose] blue: RasterDataTable<Color>,
|
#[expose] blue: RasterDataTable<CPU>,
|
||||||
#[expose] alpha: RasterDataTable<Color>,
|
#[expose] alpha: RasterDataTable<CPU>,
|
||||||
) -> RasterDataTable<Color> {
|
) -> RasterDataTable<CPU> {
|
||||||
let mut result_table = RasterDataTable::default();
|
let mut result_table = RasterDataTable::default();
|
||||||
|
|
||||||
let max_len = red.len().max(green.len()).max(blue.len()).max(alpha.len());
|
let max_len = red.len().max(green.len()).max(blue.len()).max(alpha.len());
|
||||||
|
@ -170,7 +172,7 @@ fn combine_channels(
|
||||||
|
|
||||||
// Add this instance to the result table
|
// Add this instance to the result table
|
||||||
result_table.push(Instance {
|
result_table.push(Instance {
|
||||||
instance: image,
|
instance: Raster::new_cpu(image),
|
||||||
transform,
|
transform,
|
||||||
alpha_blending,
|
alpha_blending,
|
||||||
source_node_id: None,
|
source_node_id: None,
|
||||||
|
@ -184,11 +186,11 @@ fn combine_channels(
|
||||||
fn mask(
|
fn mask(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
/// The image to be masked.
|
/// The image to be masked.
|
||||||
image: RasterDataTable<Color>,
|
image: RasterDataTable<CPU>,
|
||||||
/// The stencil to be used for masking.
|
/// The stencil to be used for masking.
|
||||||
#[expose]
|
#[expose]
|
||||||
stencil: RasterDataTable<Color>,
|
stencil: RasterDataTable<CPU>,
|
||||||
) -> RasterDataTable<Color> {
|
) -> RasterDataTable<CPU> {
|
||||||
// TODO: Support multiple stencil instances
|
// TODO: Support multiple stencil instances
|
||||||
let Some(stencil_instance) = stencil.instance_iter().next() else {
|
let Some(stencil_instance) = stencil.instance_iter().next() else {
|
||||||
// No stencil provided so we return the original image
|
// No stencil provided so we return the original image
|
||||||
|
@ -218,7 +220,7 @@ fn mask(
|
||||||
let mask_point = stencil_instance.transform.transform_point2(local_mask_point.clamp(DVec2::ZERO, DVec2::ONE));
|
let mask_point = stencil_instance.transform.transform_point2(local_mask_point.clamp(DVec2::ZERO, DVec2::ONE));
|
||||||
let mask_point = (DAffine2::from_scale(stencil_size) * stencil_instance.transform.inverse()).transform_point2(mask_point);
|
let mask_point = (DAffine2::from_scale(stencil_size) * stencil_instance.transform.inverse()).transform_point2(mask_point);
|
||||||
|
|
||||||
let image_pixel = image_instance.instance.get_pixel_mut(x, y).unwrap();
|
let image_pixel = image_instance.instance.data_mut().get_pixel_mut(x, y).unwrap();
|
||||||
let mask_pixel = stencil_instance.instance.sample(mask_point);
|
let mask_pixel = stencil_instance.instance.sample(mask_point);
|
||||||
*image_pixel = image_pixel.multiplied_alpha(mask_pixel.l().cast_linear_channel());
|
*image_pixel = image_pixel.multiplied_alpha(mask_pixel.l().cast_linear_channel());
|
||||||
}
|
}
|
||||||
|
@ -231,7 +233,7 @@ fn mask(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category(""))]
|
#[node_macro::node(category(""))]
|
||||||
fn extend_image_to_bounds(_: impl Ctx, image: RasterDataTable<Color>, bounds: DAffine2) -> RasterDataTable<Color> {
|
fn extend_image_to_bounds(_: impl Ctx, image: RasterDataTable<CPU>, bounds: DAffine2) -> RasterDataTable<CPU> {
|
||||||
let mut result_table = RasterDataTable::default();
|
let mut result_table = RasterDataTable::default();
|
||||||
|
|
||||||
for mut image_instance in image.instance_iter() {
|
for mut image_instance in image.instance_iter() {
|
||||||
|
@ -242,7 +244,7 @@ fn extend_image_to_bounds(_: impl Ctx, image: RasterDataTable<Color>, bounds: DA
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let image_data = image_instance.instance.data;
|
let image_data = &image_instance.instance.data;
|
||||||
let (image_width, image_height) = (image_instance.instance.width, image_instance.instance.height);
|
let (image_width, image_height) = (image_instance.instance.width, image_instance.instance.height);
|
||||||
if image_width == 0 || image_height == 0 {
|
if image_width == 0 || image_height == 0 {
|
||||||
for image_instance in empty_image((), bounds, Color::TRANSPARENT).instance_iter() {
|
for image_instance in empty_image((), bounds, Color::TRANSPARENT).instance_iter() {
|
||||||
|
@ -274,7 +276,7 @@ fn extend_image_to_bounds(_: impl Ctx, image: RasterDataTable<Color>, bounds: DA
|
||||||
// let layer_to_new_texture_space = (DAffine2::from_scale(1. / new_scale) * DAffine2::from_translation(new_start) * layer_to_image_space).inverse();
|
// let layer_to_new_texture_space = (DAffine2::from_scale(1. / new_scale) * DAffine2::from_translation(new_start) * layer_to_image_space).inverse();
|
||||||
let new_texture_to_layer_space = image_instance.transform * DAffine2::from_scale(1. / orig_image_scale) * DAffine2::from_translation(new_start) * DAffine2::from_scale(new_scale);
|
let new_texture_to_layer_space = image_instance.transform * DAffine2::from_scale(1. / orig_image_scale) * DAffine2::from_translation(new_start) * DAffine2::from_scale(new_scale);
|
||||||
|
|
||||||
image_instance.instance = new_image;
|
image_instance.instance = Raster::new_cpu(new_image);
|
||||||
image_instance.transform = new_texture_to_layer_space;
|
image_instance.transform = new_texture_to_layer_space;
|
||||||
image_instance.source_node_id = None;
|
image_instance.source_node_id = None;
|
||||||
result_table.push(image_instance);
|
result_table.push(image_instance);
|
||||||
|
@ -284,13 +286,13 @@ fn extend_image_to_bounds(_: impl Ctx, image: RasterDataTable<Color>, bounds: DA
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Debug: Raster"))]
|
#[node_macro::node(category("Debug: Raster"))]
|
||||||
fn empty_image(_: impl Ctx, transform: DAffine2, color: Color) -> RasterDataTable<Color> {
|
fn empty_image(_: impl Ctx, transform: DAffine2, color: Color) -> RasterDataTable<CPU> {
|
||||||
let width = transform.transform_vector2(DVec2::new(1., 0.)).length() as u32;
|
let width = transform.transform_vector2(DVec2::new(1., 0.)).length() as u32;
|
||||||
let height = transform.transform_vector2(DVec2::new(0., 1.)).length() as u32;
|
let height = transform.transform_vector2(DVec2::new(0., 1.)).length() as u32;
|
||||||
|
|
||||||
let image = Image::new(width, height, color);
|
let image = Image::new(width, height, color);
|
||||||
|
|
||||||
let mut result_table = RasterDataTable::new(image);
|
let mut result_table = RasterDataTable::new(Raster::new_cpu(image));
|
||||||
let image_instance = result_table.get_mut(0).unwrap();
|
let image_instance = result_table.get_mut(0).unwrap();
|
||||||
*image_instance.transform = transform;
|
*image_instance.transform = transform;
|
||||||
*image_instance.alpha_blending = AlphaBlending::default();
|
*image_instance.alpha_blending = AlphaBlending::default();
|
||||||
|
@ -301,7 +303,7 @@ fn empty_image(_: impl Ctx, transform: DAffine2, color: Color) -> RasterDataTabl
|
||||||
|
|
||||||
/// Constructs a raster image.
|
/// Constructs a raster image.
|
||||||
#[node_macro::node(category(""))]
|
#[node_macro::node(category(""))]
|
||||||
fn image(_: impl Ctx, _primary: (), image: RasterDataTable<Color>) -> RasterDataTable<Color> {
|
fn image(_: impl Ctx, _primary: (), image: RasterDataTable<CPU>) -> RasterDataTable<CPU> {
|
||||||
image
|
image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +426,7 @@ fn noise_pattern(
|
||||||
cellular_distance_function: CellularDistanceFunction,
|
cellular_distance_function: CellularDistanceFunction,
|
||||||
cellular_return_type: CellularReturnType,
|
cellular_return_type: CellularReturnType,
|
||||||
cellular_jitter: f64,
|
cellular_jitter: f64,
|
||||||
) -> RasterDataTable<Color> {
|
) -> RasterDataTable<CPU> {
|
||||||
let footprint = ctx.footprint();
|
let footprint = ctx.footprint();
|
||||||
let viewport_bounds = footprint.viewport_bounds_in_local_space();
|
let viewport_bounds = footprint.viewport_bounds_in_local_space();
|
||||||
|
|
||||||
|
@ -488,7 +490,7 @@ fn noise_pattern(
|
||||||
|
|
||||||
let mut result = RasterDataTable::default();
|
let mut result = RasterDataTable::default();
|
||||||
result.push(Instance {
|
result.push(Instance {
|
||||||
instance: image,
|
instance: Raster::new_cpu(image),
|
||||||
transform: DAffine2::from_translation(offset) * DAffine2::from_scale(size),
|
transform: DAffine2::from_translation(offset) * DAffine2::from_scale(size),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
@ -553,7 +555,7 @@ fn noise_pattern(
|
||||||
|
|
||||||
let mut result = RasterDataTable::default();
|
let mut result = RasterDataTable::default();
|
||||||
result.push(Instance {
|
result.push(Instance {
|
||||||
instance: image,
|
instance: Raster::new_cpu(image),
|
||||||
transform: DAffine2::from_translation(offset) * DAffine2::from_scale(size),
|
transform: DAffine2::from_translation(offset) * DAffine2::from_scale(size),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
@ -562,7 +564,7 @@ fn noise_pattern(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Raster"))]
|
#[node_macro::node(category("Raster"))]
|
||||||
fn mandelbrot(ctx: impl ExtractFootprint + Send) -> RasterDataTable<Color> {
|
fn mandelbrot(ctx: impl ExtractFootprint + Send) -> RasterDataTable<CPU> {
|
||||||
let footprint = ctx.footprint();
|
let footprint = ctx.footprint();
|
||||||
let viewport_bounds = footprint.viewport_bounds_in_local_space();
|
let viewport_bounds = footprint.viewport_bounds_in_local_space();
|
||||||
|
|
||||||
|
@ -604,7 +606,7 @@ fn mandelbrot(ctx: impl ExtractFootprint + Send) -> RasterDataTable<Color> {
|
||||||
};
|
};
|
||||||
let mut result = RasterDataTable::default();
|
let mut result = RasterDataTable::default();
|
||||||
result.push(Instance {
|
result.push(Instance {
|
||||||
instance: image,
|
instance: Raster::new_cpu(image),
|
||||||
transform: DAffine2::from_translation(offset) * DAffine2::from_scale(size),
|
transform: DAffine2::from_translation(offset) * DAffine2::from_scale(size),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use bezier_rs::{ManipulatorGroup, Subpath};
|
use bezier_rs::{ManipulatorGroup, Subpath};
|
||||||
use glam::{DAffine2, DVec2};
|
use glam::{DAffine2, DVec2};
|
||||||
use graphene_core::RasterDataType;
|
|
||||||
use graphene_core::instances::{Instance, InstanceRef};
|
use graphene_core::instances::{Instance, InstanceRef};
|
||||||
use graphene_core::vector::misc::BooleanOperation;
|
use graphene_core::vector::misc::BooleanOperation;
|
||||||
use graphene_core::vector::style::Fill;
|
use graphene_core::vector::style::Fill;
|
||||||
|
@ -203,7 +202,7 @@ fn flatten_vector_data(graphic_group_table: &GraphicGroupTable) -> VectorDataTab
|
||||||
result_table.push(sub_vector_data);
|
result_table.push(sub_vector_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GraphicElement::RasterDataType(image) => {
|
GraphicElement::RasterDataCPU(image) => {
|
||||||
let make_instance = |transform| {
|
let make_instance = |transform| {
|
||||||
// Convert the image frame into a rectangular subpath with the image's transform
|
// Convert the image frame into a rectangular subpath with the image's transform
|
||||||
let mut subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
let mut subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
||||||
|
@ -217,19 +216,28 @@ fn flatten_vector_data(graphic_group_table: &GraphicGroupTable) -> VectorDataTab
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the parent group's transform to each element of raster data
|
// Apply the parent group's transform to each element of raster data
|
||||||
match image {
|
|
||||||
RasterDataType::RasterData(image) => {
|
|
||||||
for instance in image.instance_ref_iter() {
|
for instance in image.instance_ref_iter() {
|
||||||
result_table.push(make_instance(*element.transform * *instance.transform));
|
result_table.push(make_instance(*element.transform * *instance.transform));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RasterDataType::TextureData(image) => {
|
GraphicElement::RasterDataGPU(image) => {
|
||||||
|
let make_instance = |transform| {
|
||||||
|
// Convert the image frame into a rectangular subpath with the image's transform
|
||||||
|
let mut subpath = Subpath::new_rect(DVec2::ZERO, DVec2::ONE);
|
||||||
|
subpath.apply_transform(transform);
|
||||||
|
|
||||||
|
// Create a vector data table row from the rectangular subpath, with a default black fill
|
||||||
|
let mut instance = VectorData::from_subpath(subpath);
|
||||||
|
instance.style.set_fill(Fill::Solid(Color::BLACK));
|
||||||
|
|
||||||
|
Instance { instance, ..Default::default() }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Apply the parent group's transform to each element of raster data
|
||||||
for instance in image.instance_ref_iter() {
|
for instance in image.instance_ref_iter() {
|
||||||
result_table.push(make_instance(*element.transform * *instance.transform));
|
result_table.push(make_instance(*element.transform * *instance.transform));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
GraphicElement::GraphicGroup(mut graphic_group) => {
|
GraphicElement::GraphicGroup(mut graphic_group) => {
|
||||||
// Apply the parent group's transform to each element of inner group
|
// Apply the parent group's transform to each element of inner group
|
||||||
for sub_element in graphic_group.instance_mut_iter() {
|
for sub_element in graphic_group.instance_mut_iter() {
|
||||||
|
|
|
@ -8,7 +8,8 @@ use graphene_core::application_io::{ApplicationIo, ExportFormat, RenderConfig};
|
||||||
use graphene_core::instances::Instances;
|
use graphene_core::instances::Instances;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use graphene_core::raster::bbox::Bbox;
|
use graphene_core::raster::bbox::Bbox;
|
||||||
use graphene_core::raster::image::{Image, RasterDataTable};
|
use graphene_core::raster::image::Image;
|
||||||
|
use graphene_core::raster_types::{CPU, Raster, RasterDataTable};
|
||||||
use graphene_core::renderer::RenderMetadata;
|
use graphene_core::renderer::RenderMetadata;
|
||||||
use graphene_core::renderer::{GraphicElementRendered, RenderParams, RenderSvgSegmentList, SvgRender, format_transform_matrix};
|
use graphene_core::renderer::{GraphicElementRendered, RenderParams, RenderSvgSegmentList, SvgRender, format_transform_matrix};
|
||||||
use graphene_core::transform::Footprint;
|
use graphene_core::transform::Footprint;
|
||||||
|
@ -76,7 +77,7 @@ async fn load_resource<'a: 'n>(_: impl Ctx, _primary: (), #[scope("editor-api")]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category("Network"))]
|
#[node_macro::node(category("Network"))]
|
||||||
fn decode_image(_: impl Ctx, data: Arc<[u8]>) -> RasterDataTable<Color> {
|
fn decode_image(_: impl Ctx, data: Arc<[u8]>) -> RasterDataTable<CPU> {
|
||||||
let Some(image) = image::load_from_memory(data.as_ref()).ok() else {
|
let Some(image) = image::load_from_memory(data.as_ref()).ok() else {
|
||||||
return RasterDataTable::default();
|
return RasterDataTable::default();
|
||||||
};
|
};
|
||||||
|
@ -91,7 +92,7 @@ fn decode_image(_: impl Ctx, data: Arc<[u8]>) -> RasterDataTable<Color> {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
RasterDataTable::new(image)
|
RasterDataTable::new(Raster::new_cpu(image))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_svg(data: impl GraphicElementRendered, mut render: SvgRender, render_params: RenderParams, footprint: Footprint) -> RenderOutputType {
|
fn render_svg(data: impl GraphicElementRendered, mut render: SvgRender, render_params: RenderParams, footprint: Footprint) -> RenderOutputType {
|
||||||
|
@ -165,13 +166,13 @@ async fn rasterize<T: WasmNotSend + 'n>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
VectorDataTable,
|
VectorDataTable,
|
||||||
RasterDataTable<Color>,
|
RasterDataTable<CPU>,
|
||||||
GraphicGroupTable,
|
GraphicGroupTable,
|
||||||
)]
|
)]
|
||||||
mut data: Instances<T>,
|
mut data: Instances<T>,
|
||||||
footprint: Footprint,
|
footprint: Footprint,
|
||||||
surface_handle: Arc<SurfaceHandle<HtmlCanvasElement>>,
|
surface_handle: Arc<SurfaceHandle<HtmlCanvasElement>>,
|
||||||
) -> RasterDataTable<Color>
|
) -> RasterDataTable<CPU>
|
||||||
where
|
where
|
||||||
Instances<T>: GraphicElementRendered,
|
Instances<T>: GraphicElementRendered,
|
||||||
{
|
{
|
||||||
|
@ -219,8 +220,9 @@ where
|
||||||
let rasterized = context.get_image_data(0., 0., resolution.x as f64, resolution.y as f64).unwrap();
|
let rasterized = context.get_image_data(0., 0., resolution.x as f64, resolution.y as f64).unwrap();
|
||||||
|
|
||||||
let mut result = RasterDataTable::default();
|
let mut result = RasterDataTable::default();
|
||||||
|
let image = Image::from_image_data(&rasterized.data().0, resolution.x as u32, resolution.y as u32);
|
||||||
result.push(Instance {
|
result.push(Instance {
|
||||||
instance: Image::from_image_data(&rasterized.data().0, resolution.x as u32, resolution.y as u32),
|
instance: Raster::new_cpu(image),
|
||||||
transform: footprint.transform,
|
transform: footprint.transform,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
@ -234,7 +236,7 @@ async fn render<'a: 'n, T: 'n + GraphicElementRendered + WasmNotSend>(
|
||||||
editor_api: impl Node<Context<'static>, Output = &'a WasmEditorApi>,
|
editor_api: impl Node<Context<'static>, Output = &'a WasmEditorApi>,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
Context -> VectorDataTable,
|
Context -> VectorDataTable,
|
||||||
Context -> RasterDataTable<Color>,
|
Context -> RasterDataTable<CPU>,
|
||||||
Context -> GraphicGroupTable,
|
Context -> GraphicGroupTable,
|
||||||
Context -> graphene_core::Artboard,
|
Context -> graphene_core::Artboard,
|
||||||
Context -> graphene_core::ArtboardGroupTable,
|
Context -> graphene_core::ArtboardGroupTable,
|
||||||
|
|
|
@ -3,8 +3,8 @@ use glam::{DVec2, UVec2};
|
||||||
use graph_craft::document::value::RenderOutput;
|
use graph_craft::document::value::RenderOutput;
|
||||||
use graph_craft::proto::{NodeConstructor, TypeErasedBox};
|
use graph_craft::proto::{NodeConstructor, TypeErasedBox};
|
||||||
use graphene_core::raster::color::Color;
|
use graphene_core::raster::color::Color;
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
|
||||||
use graphene_core::raster::*;
|
use graphene_core::raster::*;
|
||||||
|
use graphene_core::raster_types::{CPU, GPU, RasterDataTable};
|
||||||
use graphene_core::vector::VectorDataTable;
|
use graphene_core::vector::VectorDataTable;
|
||||||
use graphene_core::{Artboard, GraphicGroupTable, concrete, generic};
|
use graphene_core::{Artboard, GraphicGroupTable, concrete, generic};
|
||||||
use graphene_core::{Cow, ProtoNodeIdentifier, Type};
|
use graphene_core::{Cow, ProtoNodeIdentifier, Type};
|
||||||
|
@ -13,7 +13,7 @@ use graphene_core::{fn_type_fut, future};
|
||||||
use graphene_std::Context;
|
use graphene_std::Context;
|
||||||
use graphene_std::GraphicElement;
|
use graphene_std::GraphicElement;
|
||||||
use graphene_std::any::{ComposeTypeErased, DowncastBothNode, DynAnyNode, IntoTypeErasedNode};
|
use graphene_std::any::{ComposeTypeErased, DowncastBothNode, DynAnyNode, IntoTypeErasedNode};
|
||||||
use graphene_std::application_io::{ImageTexture, TextureDataTable};
|
use graphene_std::application_io::ImageTexture;
|
||||||
use graphene_std::wasm_application_io::*;
|
use graphene_std::wasm_application_io::*;
|
||||||
use node_registry_macros::{async_node, into_node};
|
use node_registry_macros::{async_node, into_node};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
@ -34,17 +34,18 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||||
into_node!(from: VectorDataTable, to: GraphicGroupTable),
|
into_node!(from: VectorDataTable, to: GraphicGroupTable),
|
||||||
into_node!(from: GraphicGroupTable, to: GraphicGroupTable),
|
into_node!(from: GraphicGroupTable, to: GraphicGroupTable),
|
||||||
into_node!(from: GraphicGroupTable, to: GraphicElement),
|
into_node!(from: GraphicGroupTable, to: GraphicElement),
|
||||||
into_node!(from: RasterDataTable<Color>, to: RasterDataTable<Color>),
|
into_node!(from: RasterDataTable<CPU>, to: RasterDataTable<CPU>),
|
||||||
into_node!(from: RasterDataTable<Color>, to: RasterDataTable<SRGBA8>),
|
// into_node!(from: RasterDataTable<CPU>, to: RasterDataTable<SRGBA8>),
|
||||||
into_node!(from: RasterDataTable<Color>, to: GraphicElement),
|
into_node!(from: RasterDataTable<CPU>, to: GraphicElement),
|
||||||
into_node!(from: RasterDataTable<Color>, to: GraphicGroupTable),
|
into_node!(from: RasterDataTable<CPU>, to: GraphicGroupTable),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => RasterDataTable<Color>]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => RasterDataTable<CPU>]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => ImageTexture]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => ImageTexture]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => VectorDataTable]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => VectorDataTable]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => GraphicGroupTable]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => GraphicGroupTable]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => GraphicElement]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => GraphicElement]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Artboard]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Artboard]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => graphene_core::RasterDataType]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => RasterDataTable<CPU>]),
|
||||||
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => RasterDataTable<GPU>]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => graphene_core::instances::Instances<Artboard>]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => graphene_core::instances::Instances<Artboard>]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => String]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => String]),
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => glam::IVec2]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => glam::IVec2]),
|
||||||
|
@ -70,7 +71,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||||
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Box<graphene_core::vector::VectorModification>]),
|
async_node!(graphene_core::memo::MonitorNode<_, _, _>, input: Context, fn_params: [Context => Box<graphene_core::vector::VectorModification>]),
|
||||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Image<Color>]),
|
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Image<Color>]),
|
||||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => VectorDataTable]),
|
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => VectorDataTable]),
|
||||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => RasterDataTable<Color>]),
|
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => RasterDataTable<CPU>]),
|
||||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => GraphicGroupTable]),
|
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => GraphicGroupTable]),
|
||||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Vec<DVec2>]),
|
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Vec<DVec2>]),
|
||||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Arc<WasmSurfaceHandle>]),
|
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => Arc<WasmSurfaceHandle>]),
|
||||||
|
@ -112,9 +113,9 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => ShaderInputFrame]),
|
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => ShaderInputFrame]),
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => TextureDataTable]),
|
async_node!(graphene_core::memo::ImpureMemoNode<_, _, _>, input: Context, fn_params: [Context => RasterDataTable<GPU>]),
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => TextureDataTable]),
|
async_node!(graphene_core::memo::MemoNode<_, _>, input: Context, fn_params: [Context => RasterDataTable<GPU>]),
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
into_node!(from: &WasmEditorApi, to: &WgpuExecutor),
|
into_node!(from: &WasmEditorApi, to: &WgpuExecutor),
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
|
|
|
@ -992,7 +992,7 @@ mod tests {
|
||||||
fn test_async_node() {
|
fn test_async_node() {
|
||||||
let attr = quote!(category("IO"));
|
let attr = quote!(category("IO"));
|
||||||
let input = quote!(
|
let input = quote!(
|
||||||
async fn load_image(api: &WasmEditorApi, #[expose] path: String) -> RasterDataTable<Color> {
|
async fn load_image(api: &WasmEditorApi, #[expose] path: String) -> RasterDataTable<CPU> {
|
||||||
// Implementation details...
|
// Implementation details...
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1016,7 +1016,7 @@ mod tests {
|
||||||
ty: parse_quote!(&WasmEditorApi),
|
ty: parse_quote!(&WasmEditorApi),
|
||||||
implementations: Punctuated::new(),
|
implementations: Punctuated::new(),
|
||||||
},
|
},
|
||||||
output_type: parse_quote!(RasterDataTable<Color>),
|
output_type: parse_quote!(RasterDataTable<CPU>),
|
||||||
is_async: true,
|
is_async: true,
|
||||||
fields: vec![ParsedField::Regular {
|
fields: vec![ParsedField::Regular {
|
||||||
pat_ident: pat_ident("path"),
|
pat_ident: pat_ident("path"),
|
||||||
|
@ -1132,7 +1132,7 @@ mod tests {
|
||||||
fn test_invalid_implementation_syntax() {
|
fn test_invalid_implementation_syntax() {
|
||||||
let attr = quote!(category("Test"));
|
let attr = quote!(category("Test"));
|
||||||
let input = quote!(
|
let input = quote!(
|
||||||
fn test_node(_: (), #[implementations((Footprint, Color), (Footprint, RasterDataTable<Color>))] input: impl Node<Footprint, Output = T>) -> T {
|
fn test_node(_: (), #[implementations((Footprint, Color), (Footprint, RasterDataTable<CPU>))] input: impl Node<Footprint, Output = T>) -> T {
|
||||||
// Implementation details...
|
// Implementation details...
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1158,10 +1158,10 @@ mod tests {
|
||||||
#[implementations((), #tuples, Footprint)] footprint: F,
|
#[implementations((), #tuples, Footprint)] footprint: F,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
() -> Color,
|
() -> Color,
|
||||||
() -> RasterDataTable<Color>,
|
() -> RasterDataTable<CPU>,
|
||||||
() -> GradientStops,
|
() -> GradientStops,
|
||||||
Footprint -> Color,
|
Footprint -> Color,
|
||||||
Footprint -> RasterDataTable<Color>,
|
Footprint -> RasterDataTable<CPU>,
|
||||||
Footprint -> GradientStops,
|
Footprint -> GradientStops,
|
||||||
)]
|
)]
|
||||||
image: impl Node<F, Output = T>,
|
image: impl Node<F, Output = T>,
|
||||||
|
|
|
@ -8,10 +8,10 @@ pub use executor::GpuExecutor;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use glam::{DAffine2, UVec2};
|
use glam::{DAffine2, UVec2};
|
||||||
use gpu_executor::{ComputePassDimensions, GPUConstant, StorageBufferOptions, TextureBufferOptions, TextureBufferType, ToStorageBuffer, ToUniformBuffer};
|
use gpu_executor::{ComputePassDimensions, GPUConstant, StorageBufferOptions, TextureBufferOptions, TextureBufferType, ToStorageBuffer, ToUniformBuffer};
|
||||||
use graphene_core::application_io::{ApplicationIo, EditorApi, ImageTexture, SurfaceHandle, TextureDataTable};
|
use graphene_core::application_io::{ApplicationIo, EditorApi, SurfaceHandle};
|
||||||
use graphene_core::instances::Instance;
|
use graphene_core::instances::Instance;
|
||||||
use graphene_core::raster::image::RasterDataTable;
|
|
||||||
use graphene_core::raster::{Image, SRGBA8};
|
use graphene_core::raster::{Image, SRGBA8};
|
||||||
|
use graphene_core::raster_types::{CPU, GPU, Raster, RasterDataTable};
|
||||||
use graphene_core::transform::{Footprint, Transform};
|
use graphene_core::transform::{Footprint, Transform};
|
||||||
use graphene_core::{Color, Cow, Ctx, ExtractFootprint, Node, SurfaceFrame, Type};
|
use graphene_core::{Color, Cow, Ctx, ExtractFootprint, Node, SurfaceFrame, Type};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
@ -911,8 +911,8 @@ async fn render_texture<'a: 'n>(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[node_macro::node(category(""))]
|
#[node_macro::node(category(""))]
|
||||||
async fn upload_texture<'a: 'n>(_: impl ExtractFootprint + Ctx, input: RasterDataTable<Color>, executor: &'a WgpuExecutor) -> TextureDataTable {
|
async fn upload_texture<'a: 'n>(_: impl ExtractFootprint + Ctx, input: RasterDataTable<CPU>, executor: &'a WgpuExecutor) -> RasterDataTable<GPU> {
|
||||||
let mut result_table = TextureDataTable::default();
|
let mut result_table = RasterDataTable::<GPU>::default();
|
||||||
|
|
||||||
for instance in input.instance_ref_iter() {
|
for instance in input.instance_ref_iter() {
|
||||||
let image = instance.instance;
|
let image = instance.instance;
|
||||||
|
@ -932,7 +932,7 @@ async fn upload_texture<'a: 'n>(_: impl ExtractFootprint + Ctx, input: RasterDat
|
||||||
};
|
};
|
||||||
|
|
||||||
result_table.push(Instance {
|
result_table.push(Instance {
|
||||||
instance: ImageTexture { texture: texture.into() },
|
instance: Raster::new_gpu(texture.into()),
|
||||||
transform: *instance.transform,
|
transform: *instance.transform,
|
||||||
alpha_blending: *instance.alpha_blending,
|
alpha_blending: *instance.alpha_blending,
|
||||||
source_node_id: *instance.source_node_id,
|
source_node_id: *instance.source_node_id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue