mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Fix default value for the Output node (#1042)
* Fix default value for output node * Don't set frame transform to zero * Fix typo in hash function * Clear frame on empty image --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -8,7 +8,7 @@ use graph_craft::document::*;
|
||||
use graph_craft::imaginate_input::ImaginateSamplingMethod;
|
||||
|
||||
use graph_craft::NodeIdentifier;
|
||||
use graphene_core::raster::{Color, Image, LuminanceCalculation};
|
||||
use graphene_core::raster::{Color, Image, ImageFrame, LuminanceCalculation};
|
||||
use graphene_core::*;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
@@ -176,7 +176,7 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
||||
inputs: vec![DocumentInputType {
|
||||
name: "In",
|
||||
data_type: FrontendGraphDataType::Raster,
|
||||
default: NodeInput::value(TaggedValue::Image(Image::empty()), true),
|
||||
default: NodeInput::value(TaggedValue::ImageFrame(ImageFrame::empty()), true),
|
||||
}],
|
||||
outputs: vec![],
|
||||
properties: |_document_node, _node_id, _context| node_properties::string_properties("The graph's output is rendered into the frame"),
|
||||
|
||||
@@ -245,34 +245,39 @@ impl NodeGraphExecutor {
|
||||
if let Some(imaginate_node) = imaginate_node {
|
||||
responses.push_back(self.generate_imaginate(network, imaginate_node, (document, document_id), layer_path, image_frame, persistent_data)?);
|
||||
} else {
|
||||
let ImageFrame { mut image, transform } = self.execute_network(network, image_frame)?;
|
||||
let ImageFrame { image, transform } = self.execute_network(network, image_frame)?;
|
||||
|
||||
// If no image was generated, use the input image
|
||||
// If no image was generated, clear the frame
|
||||
if image.width == 0 || image.height == 0 {
|
||||
image = graphene_core::raster::Image::from_image_data(&image_data, width, height);
|
||||
responses.push_back(DocumentMessage::FrameClear.into());
|
||||
} else {
|
||||
// Update the image data
|
||||
let (image_data, _size) = Self::encode_img(image, None, image::ImageOutputFormat::Bmp)?;
|
||||
|
||||
responses.push_back(
|
||||
Operation::SetNodeGraphFrameImageData {
|
||||
layer_path: layer_path.clone(),
|
||||
image_data: image_data.clone(),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
let mime = "image/bmp".to_string();
|
||||
let image_data = std::sync::Arc::new(image_data);
|
||||
let image_data = vec![FrontendImageData {
|
||||
path: layer_path.clone(),
|
||||
image_data,
|
||||
mime,
|
||||
}];
|
||||
responses.push_back(FrontendMessage::UpdateImageData { document_id, image_data }.into());
|
||||
}
|
||||
|
||||
let (image_data, _size) = Self::encode_img(image, None, image::ImageOutputFormat::Bmp)?;
|
||||
|
||||
responses.push_back(
|
||||
Operation::SetNodeGraphFrameImageData {
|
||||
layer_path: layer_path.clone(),
|
||||
image_data: image_data.clone(),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
let mime = "image/bmp".to_string();
|
||||
let image_data = std::sync::Arc::new(image_data);
|
||||
let image_data = vec![FrontendImageData {
|
||||
path: layer_path.clone(),
|
||||
image_data,
|
||||
mime,
|
||||
}];
|
||||
responses.push_back(FrontendMessage::UpdateImageData { document_id, image_data }.into());
|
||||
|
||||
// Update the transform based on the graph output
|
||||
let transform = transform.to_cols_array();
|
||||
responses.push_back(Operation::SetLayerTransform { path: layer_path, transform }.into());
|
||||
// Don't update the frame's transform if the new transform is DAffine2::ZERO.
|
||||
if !transform.abs_diff_eq(DAffine2::ZERO, f64::EPSILON) {
|
||||
// Update the transform based on the graph output
|
||||
let transform = transform.to_cols_array();
|
||||
responses.push_back(Operation::SetLayerTransform { path: layer_path.clone(), transform }.into());
|
||||
responses.push_back(Operation::SetLayerVisibility { path: layer_path, visible: true }.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user