Convert dehaze, empty_image, extend_image_to_bounds, and image to record kernels

This commit is contained in:
Dennis Kobert
2026-08-23 10:11:34 +00:00
parent 73b2ef1d58
commit 2c15dc838e
3 changed files with 96 additions and 84 deletions
+18 -25
View File
@@ -1,5 +1,4 @@
use core_types::context::Ctx;
use core_types::list::List;
use core_types::registry::types::Percentage;
use image::{DynamicImage, GenericImage, GenericImageView, GrayImage, ImageBuffer, Luma, Rgba, RgbaImage};
use ndarray::{Array2, ArrayBase, Dim, OwnedRepr};
@@ -8,33 +7,27 @@ use raster_types::{CPU, Raster};
use std::cmp::{max, min};
#[node_macro::node(category("Raster: Filter"))]
fn dehaze(_: impl Ctx, image_frame: List<Raster<CPU>>, strength: Percentage) -> List<Raster<CPU>> {
image_frame
.into_iter()
.map(|mut row| {
let image = std::mem::replace(row.element_mut(), Raster::new_cpu(Image::default()));
// Prepare the image data for processing
let image_data = bytemuck::cast_vec(image.data.clone());
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.");
let dynamic_image: DynamicImage = image_buffer.into();
fn dehaze(_: impl Ctx, image_frame: Raster<CPU>, strength: Percentage) -> Raster<CPU> {
let image = image_frame;
// Prepare the image data for processing
let image_data = bytemuck::cast_vec(image.data.clone());
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.");
let dynamic_image: DynamicImage = image_buffer.into();
// Run the dehaze algorithm
let dehazed_dynamic_image = dehaze_image(dynamic_image, strength / 100.);
// Run the dehaze algorithm
let dehazed_dynamic_image = dehaze_image(dynamic_image, strength / 100.);
// Prepare the image data for returning
let buffer = dehazed_dynamic_image.to_rgba32f().into_raw();
let color_vec = bytemuck::cast_vec(buffer);
let dehazed_image = Image {
width: image.width,
height: image.height,
data: color_vec,
base64_string: None,
};
// Prepare the image data for returning
let buffer = dehazed_dynamic_image.to_rgba32f().into_raw();
let color_vec = bytemuck::cast_vec(buffer);
let dehazed_image = Image {
width: image.width,
height: image.height,
data: color_vec,
base64_string: None,
};
*row.element_mut() = Raster::new_cpu(dehazed_image);
row
})
.collect()
Raster::new_cpu(dehazed_image)
}
// There is no real point in modifying these values because they do not change the final result all that much.