Skip to content

Commit 41c9387

Browse files
committed
Merge branch 'collect_instances' into readd-upload-texture
2 parents 04b3ce4 + a180a24 commit 41c9387

5 files changed

Lines changed: 287 additions & 278 deletions

File tree

node-graph/gcore/src/instances.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ impl<T> Instances<T> {
2727
}
2828
}
2929

30+
pub fn new_instance(instance: Instance<T>) -> Self {
31+
Self {
32+
instance: vec![instance.instance],
33+
transform: vec![instance.transform],
34+
alpha_blending: vec![instance.alpha_blending],
35+
source_node_id: vec![instance.source_node_id],
36+
}
37+
}
38+
39+
pub fn with_capacity(capacity: usize) -> Self {
40+
Self {
41+
instance: Vec::with_capacity(capacity),
42+
transform: Vec::with_capacity(capacity),
43+
alpha_blending: Vec::with_capacity(capacity),
44+
source_node_id: Vec::with_capacity(capacity),
45+
}
46+
}
47+
3048
pub fn push(&mut self, instance: Instance<T>) {
3149
self.instance.push(instance.instance);
3250
self.transform.push(instance.transform);
@@ -161,6 +179,18 @@ unsafe impl<T: StaticType + 'static> StaticType for Instances<T> {
161179
type Static = Instances<T>;
162180
}
163181

182+
impl<T> FromIterator<Instance<T>> for Instances<T> {
183+
fn from_iter<I: IntoIterator<Item = Instance<T>>>(iter: I) -> Self {
184+
let iter = iter.into_iter();
185+
let (lower, _) = iter.size_hint();
186+
let mut instances = Self::with_capacity(lower);
187+
for instance in iter {
188+
instances.push(instance);
189+
}
190+
instances
191+
}
192+
}
193+
164194
fn one_daffine2_default() -> Vec<DAffine2> {
165195
vec![DAffine2::IDENTITY]
166196
}

node-graph/graster-nodes/src/dehaze.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,33 @@ use std::cmp::{max, min};
88

99
#[node_macro::node(category("Raster: Filter"))]
1010
async fn dehaze(_: impl Ctx, image_frame: RasterDataTable<CPU>, strength: Percentage) -> RasterDataTable<CPU> {
11-
let mut result_table = RasterDataTable::default();
12-
13-
for mut image_frame_instance in image_frame.instance_iter() {
14-
let image = image_frame_instance.instance;
15-
// Prepare the image data for processing
16-
let image_data = bytemuck::cast_vec(image.data.clone());
17-
let image_buffer = image::Rgba32FImage::from_raw(image.width, image.height, image_data).expect("Failed to convert internal image format into image-rs data type.");
18-
let dynamic_image: DynamicImage = image_buffer.into();
19-
20-
// Run the dehaze algorithm
21-
let dehazed_dynamic_image = dehaze_image(dynamic_image, strength / 100.);
22-
23-
// Prepare the image data for returning
24-
let buffer = dehazed_dynamic_image.to_rgba32f().into_raw();
25-
let color_vec = bytemuck::cast_vec(buffer);
26-
let dehazed_image = Image {
27-
width: image.width,
28-
height: image.height,
29-
data: color_vec,
30-
base64_string: None,
31-
};
32-
33-
image_frame_instance.instance = Raster::new_cpu(dehazed_image);
34-
image_frame_instance.source_node_id = None;
35-
result_table.push(image_frame_instance);
36-
}
37-
38-
result_table
11+
image_frame
12+
.instance_iter()
13+
.map(|mut image_frame_instance| {
14+
let image = image_frame_instance.instance;
15+
// Prepare the image data for processing
16+
let image_data = bytemuck::cast_vec(image.data.clone());
17+
let image_buffer = image::Rgba32FImage::from_raw(image.width, image.height, image_data).expect("Failed to convert internal image format into image-rs data type.");
18+
let dynamic_image: DynamicImage = image_buffer.into();
19+
20+
// Run the dehaze algorithm
21+
let dehazed_dynamic_image = dehaze_image(dynamic_image, strength / 100.);
22+
23+
// Prepare the image data for returning
24+
let buffer = dehazed_dynamic_image.to_rgba32f().into_raw();
25+
let color_vec = bytemuck::cast_vec(buffer);
26+
let dehazed_image = Image {
27+
width: image.width,
28+
height: image.height,
29+
data: color_vec,
30+
base64_string: None,
31+
};
32+
33+
image_frame_instance.instance = Raster::new_cpu(dehazed_image);
34+
image_frame_instance.source_node_id = None;
35+
image_frame_instance
36+
})
37+
.collect()
3938
}
4039

4140
// There is no real point in modifying these values because they do not change the final result all that much.

node-graph/graster-nodes/src/filter.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,26 @@ async fn blur(
2020
/// Opt to incorrectly apply the filter with color calculations in gamma space for compatibility with the results from other software.
2121
gamma: bool,
2222
) -> RasterDataTable<CPU> {
23-
let mut result_table = RasterDataTable::default();
24-
25-
for mut image_instance in image_frame.instance_iter() {
26-
let image = image_instance.instance.clone();
27-
28-
// Run blur algorithm
29-
let blurred_image = if radius < 0.1 {
30-
// Minimum blur radius
31-
image.clone()
32-
} else if box_blur {
33-
Raster::new_cpu(box_blur_algorithm(image.into_data(), radius, gamma))
34-
} else {
35-
Raster::new_cpu(gaussian_blur_algorithm(image.into_data(), radius, gamma))
36-
};
37-
38-
image_instance.instance = blurred_image;
39-
image_instance.source_node_id = None;
40-
result_table.push(image_instance);
41-
}
42-
43-
result_table
23+
image_frame
24+
.instance_iter()
25+
.map(|mut image_instance| {
26+
let image = image_instance.instance.clone();
27+
28+
// Run blur algorithm
29+
let blurred_image = if radius < 0.1 {
30+
// Minimum blur radius
31+
image.clone()
32+
} else if box_blur {
33+
Raster::new_cpu(box_blur_algorithm(image.into_data(), radius, gamma))
34+
} else {
35+
Raster::new_cpu(gaussian_blur_algorithm(image.into_data(), radius, gamma))
36+
};
37+
38+
image_instance.instance = blurred_image;
39+
image_instance.source_node_id = None;
40+
image_instance
41+
})
42+
.collect()
4443
}
4544

4645
// 1D gaussian kernel

0 commit comments

Comments
 (0)