Skip to content

Commit d3b5dc5

Browse files
authored
Clean up 'Image' node by removing old 'Cull' node in sub-network (#2643)
* Clean up 'Image' node by removing old 'Cull' node in sub-network * Fix gamma correction on Decode Image node
1 parent 0022680 commit d3b5dc5

File tree

5 files changed

+21
-110
lines changed

5 files changed

+21
-110
lines changed

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 4 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
473473
node_template: NodeTemplate {
474474
document_node: DocumentNode {
475475
implementation: DocumentNodeImplementation::Network(NodeNetwork {
476-
exports: vec![NodeInput::node(NodeId(2), 0)],
476+
exports: vec![NodeInput::node(NodeId(1), 0)],
477477
nodes: [
478478
DocumentNode {
479479
inputs: vec![NodeInput::value(TaggedValue::None, false), NodeInput::scope("editor-api"), NodeInput::network(concrete!(String), 1)],
@@ -487,12 +487,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
487487
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_std::wasm_application_io::DecodeImageNode")),
488488
..Default::default()
489489
},
490-
DocumentNode {
491-
inputs: vec![NodeInput::node(NodeId(1), 0)],
492-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::transform::CullNode")),
493-
manual_composition: Some(concrete!(Context)),
494-
..Default::default()
495-
},
496490
]
497491
.into_iter()
498492
.enumerate()
@@ -525,14 +519,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
525519
},
526520
..Default::default()
527521
},
528-
DocumentNodeMetadata {
529-
persistent_metadata: DocumentNodePersistentMetadata {
530-
display_name: "Cull".to_string(),
531-
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(14, 0)),
532-
..Default::default()
533-
},
534-
..Default::default()
535-
},
536522
]
537523
.into_iter()
538524
.enumerate()
@@ -845,41 +831,13 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
845831
PropertiesRow::with_override("Cellular Jitter", "TODO", WidgetOverride::Custom("noise_properties_cellular_jitter".to_string())),
846832
],
847833
output_names: vec!["Image".to_string()],
848-
network_metadata: Some(NodeNetworkMetadata {
849-
persistent_metadata: NodeNetworkPersistentMetadata {
850-
node_metadata: [
851-
DocumentNodeMetadata {
852-
persistent_metadata: DocumentNodePersistentMetadata {
853-
display_name: "Noise Pattern".to_string(),
854-
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
855-
..Default::default()
856-
},
857-
..Default::default()
858-
},
859-
DocumentNodeMetadata {
860-
persistent_metadata: DocumentNodePersistentMetadata {
861-
display_name: "Cull".to_string(),
862-
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
863-
..Default::default()
864-
},
865-
..Default::default()
866-
},
867-
]
868-
.into_iter()
869-
.enumerate()
870-
.map(|(id, node)| (NodeId(id as u64), node))
871-
.collect(),
872-
..Default::default()
873-
},
874-
..Default::default()
875-
}),
876834
..Default::default()
877835
},
878836
},
879837
description: Cow::Borrowed("Generates different noise patterns."),
880838
properties: None,
881839
},
882-
// TODO: This needs to work with resolution-aware (raster with footprint, post-Cull node) data.
840+
// TODO: This needs to work with resolution-aware data.
883841
// TODO: Auto-generate this from its proto node macro
884842
DocumentNodeDefinition {
885843
identifier: "Mask",
@@ -906,7 +864,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
906864
description: Cow::Borrowed("TODO"),
907865
properties: None,
908866
},
909-
// TODO: This needs to work with resolution-aware (raster with footprint, post-Cull node) data.
867+
// TODO: This needs to work with resolution-aware data.
910868
// TODO: Auto-generate this from its proto node macro
911869
DocumentNodeDefinition {
912870
identifier: "Insert Channel",
@@ -934,7 +892,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
934892
description: Cow::Borrowed("TODO"),
935893
properties: None,
936894
},
937-
// TODO: This needs to work with resolution-aware (raster with footprint, post-Cull node) data.
895+
// TODO: This needs to work with resolution-aware data.
938896
DocumentNodeDefinition {
939897
identifier: "Combine Channels",
940898
category: "Raster",
@@ -1244,58 +1202,6 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
12441202
description: Cow::Borrowed("TODO"),
12451203
properties: None,
12461204
},
1247-
DocumentNodeDefinition {
1248-
identifier: "Image",
1249-
category: "Raster",
1250-
node_template: NodeTemplate {
1251-
document_node: DocumentNode {
1252-
implementation: DocumentNodeImplementation::Network(NodeNetwork {
1253-
exports: vec![NodeInput::node(NodeId(0), 0)],
1254-
nodes: vec![DocumentNode {
1255-
inputs: vec![NodeInput::network(concrete!(ImageFrameTable<Color>), 1)],
1256-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::transform::CullNode")),
1257-
manual_composition: Some(concrete!(Context)),
1258-
..Default::default()
1259-
}]
1260-
.into_iter()
1261-
.enumerate()
1262-
.map(|(id, node)| (NodeId(id as u64), node))
1263-
.collect(),
1264-
..Default::default()
1265-
}),
1266-
inputs: vec![
1267-
NodeInput::value(TaggedValue::None, false),
1268-
NodeInput::value(TaggedValue::ImageFrame(ImageFrameTable::one_empty_image()), false),
1269-
],
1270-
..Default::default()
1271-
},
1272-
persistent_node_metadata: DocumentNodePersistentMetadata {
1273-
input_properties: vec![("Empty", "TODO").into(), ("Image", "TODO").into()],
1274-
output_names: vec!["Image".to_string()],
1275-
network_metadata: Some(NodeNetworkMetadata {
1276-
persistent_metadata: NodeNetworkPersistentMetadata {
1277-
node_metadata: [DocumentNodeMetadata {
1278-
persistent_metadata: DocumentNodePersistentMetadata {
1279-
display_name: "Cull".to_string(),
1280-
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(0, 0)),
1281-
..Default::default()
1282-
},
1283-
..Default::default()
1284-
}]
1285-
.into_iter()
1286-
.enumerate()
1287-
.map(|(id, node)| (NodeId(id as u64), node))
1288-
.collect(),
1289-
..Default::default()
1290-
},
1291-
..Default::default()
1292-
}),
1293-
..Default::default()
1294-
},
1295-
},
1296-
description: Cow::Borrowed("TODO"),
1297-
properties: None,
1298-
},
12991205
#[cfg(feature = "gpu")]
13001206
DocumentNodeDefinition {
13011207
identifier: "Uniform",

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
461461
}
462462
};
463463

464-
const REPLACEMENTS: [(&str, &str); 34] = [
464+
const REPLACEMENTS: [(&str, &str); 35] = [
465465
("graphene_core::AddArtboardNode", "graphene_core::graphic_element::AppendArtboardNode"),
466466
("graphene_core::ConstructArtboardNode", "graphene_core::graphic_element::ToArtboardNode"),
467467
("graphene_core::ToGraphicElementNode", "graphene_core::graphic_element::ToElementNode"),
@@ -500,6 +500,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
500500
("graphene_core::vector::generator_nodes::StarGenerator", "graphene_core::vector::generator_nodes::StarNode"),
501501
("graphene_std::executor::BlendGpuImageNode", "graphene_std::gpu_nodes::BlendGpuImageNode"),
502502
("graphene_std::raster::SampleNode", "graphene_std::raster::SampleImageNode"),
503+
("graphene_core::transform::CullNode", "graphene_core::ops::IdentityNode"),
503504
];
504505
let mut network = document.network_interface.document_network().clone();
505506
network.generate_node_paths(&[]);

node-graph/gcore/src/transform.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::instances::Instances;
33
use crate::raster::bbox::AxisAlignedBbox;
44
use crate::raster::image::ImageFrameTable;
55
use crate::vector::VectorDataTable;
6-
use crate::{Artboard, ArtboardGroupTable, CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicGroupTable, OwnedContextImpl};
6+
use crate::{Artboard, CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicGroupTable, OwnedContextImpl};
77
use core::f64;
88
use glam::{DAffine2, DMat2, DVec2};
99

@@ -137,11 +137,6 @@ impl From<()> for Footprint {
137137
}
138138
}
139139

140-
#[node_macro::node(category("Debug"))]
141-
fn cull<T>(_: impl Ctx, #[implementations(VectorDataTable, GraphicGroupTable, Artboard, ImageFrameTable<Color>, ArtboardGroupTable)] data: T) -> T {
142-
data
143-
}
144-
145140
impl core::hash::Hash for Footprint {
146141
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
147142
self.transform.to_cols_array().iter().for_each(|x| x.to_le_bytes().hash(state));

node-graph/gstd/src/raster.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::marker::PhantomData;
1717
#[derive(Debug, DynAny)]
1818
pub enum Error {
1919
IO(std::io::Error),
20-
Image(image::ImageError),
20+
Image(::image::ImageError),
2121
}
2222

2323
impl From<std::io::Error> for Error {
@@ -49,9 +49,9 @@ fn sample_image(ctx: impl ExtractFootprint + Clone + Send, image_frame: ImageFra
4949
return ImageFrameTable::one_empty_image();
5050
}
5151

52-
let image_buffer = image::Rgba32FImage::from_raw(image.width, image.height, data).expect("Failed to convert internal image format into image-rs data type.");
52+
let image_buffer = ::image::Rgba32FImage::from_raw(image.width, image.height, data).expect("Failed to convert internal image format into image-rs data type.");
5353

54-
let dynamic_image: image::DynamicImage = image_buffer.into();
54+
let dynamic_image: ::image::DynamicImage = image_buffer.into();
5555
let offset = (intersection.start - image_bounds.start).max(DVec2::ZERO);
5656
let offset_px = image_size.transform_vector2(offset).as_uvec2();
5757
let cropped = dynamic_image.crop_imm(offset_px.x, offset_px.y, size_px.x, size_px.y);
@@ -66,7 +66,7 @@ fn sample_image(ctx: impl ExtractFootprint + Clone + Send, image_frame: ImageFra
6666
new_width = viewport_resolution_x as u32;
6767
new_height = viewport_resolution_y as u32;
6868
// TODO: choose filter based on quality requirements
69-
cropped.resize_exact(new_width, new_height, image::imageops::Triangle)
69+
cropped.resize_exact(new_width, new_height, ::image::imageops::Triangle)
7070
} else {
7171
cropped
7272
};
@@ -375,6 +375,12 @@ fn empty_image(_: impl Ctx, transform: DAffine2, color: Color) -> ImageFrameTabl
375375
result
376376
}
377377

378+
/// Constructs a raster image.
379+
#[node_macro::node(category(""))]
380+
fn image(_: impl Ctx, _primary: (), image: ImageFrameTable<Color>) -> ImageFrameTable<Color> {
381+
image
382+
}
383+
378384
// #[cfg(feature = "serde")]
379385
// macro_rules! generate_imaginate_node {
380386
// ($($val:ident: $t:ident: $o:ty,)*) => {

node-graph/gstd/src/wasm_application_io.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ fn decode_image(_: impl Ctx, data: Arc<[u8]>) -> ImageFrameTable<Color> {
8383
};
8484
let image = image.to_rgba32f();
8585
let image = Image {
86-
data: image.chunks(4).map(|pixel| Color::from_unassociated_alpha(pixel[0], pixel[1], pixel[2], pixel[3])).collect(),
86+
data: image
87+
.chunks(4)
88+
.map(|pixel| Color::from_unassociated_alpha(pixel[0], pixel[1], pixel[2], pixel[3]).to_linear_srgb())
89+
.collect(),
8790
width: image.width(),
8891
height: image.height(),
8992
..Default::default()

0 commit comments

Comments
 (0)