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
This commit is contained in:
Keavon Chambers
2025-05-12 18:40:48 -07:00
committed by GitHub
parent 0022680336
commit d3b5dc5712
5 changed files with 21 additions and 110 deletions

View File

@@ -3,7 +3,7 @@ use crate::instances::Instances;
use crate::raster::bbox::AxisAlignedBbox;
use crate::raster::image::ImageFrameTable;
use crate::vector::VectorDataTable;
use crate::{Artboard, ArtboardGroupTable, CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicGroupTable, OwnedContextImpl};
use crate::{Artboard, CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicGroupTable, OwnedContextImpl};
use core::f64;
use glam::{DAffine2, DMat2, DVec2};
@@ -137,11 +137,6 @@ impl From<()> for Footprint {
}
}
#[node_macro::node(category("Debug"))]
fn cull<T>(_: impl Ctx, #[implementations(VectorDataTable, GraphicGroupTable, Artboard, ImageFrameTable<Color>, ArtboardGroupTable)] data: T) -> T {
data
}
impl core::hash::Hash for Footprint {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.transform.to_cols_array().iter().for_each(|x| x.to_le_bytes().hash(state));

View File

@@ -17,7 +17,7 @@ use std::marker::PhantomData;
#[derive(Debug, DynAny)]
pub enum Error {
IO(std::io::Error),
Image(image::ImageError),
Image(::image::ImageError),
}
impl From<std::io::Error> for Error {
@@ -49,9 +49,9 @@ fn sample_image(ctx: impl ExtractFootprint + Clone + Send, image_frame: ImageFra
return ImageFrameTable::one_empty_image();
}
let image_buffer = image::Rgba32FImage::from_raw(image.width, image.height, data).expect("Failed to convert internal image format into image-rs data type.");
let image_buffer = ::image::Rgba32FImage::from_raw(image.width, image.height, data).expect("Failed to convert internal image format into image-rs data type.");
let dynamic_image: image::DynamicImage = image_buffer.into();
let dynamic_image: ::image::DynamicImage = image_buffer.into();
let offset = (intersection.start - image_bounds.start).max(DVec2::ZERO);
let offset_px = image_size.transform_vector2(offset).as_uvec2();
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
new_width = viewport_resolution_x as u32;
new_height = viewport_resolution_y as u32;
// TODO: choose filter based on quality requirements
cropped.resize_exact(new_width, new_height, image::imageops::Triangle)
cropped.resize_exact(new_width, new_height, ::image::imageops::Triangle)
} else {
cropped
};
@@ -375,6 +375,12 @@ fn empty_image(_: impl Ctx, transform: DAffine2, color: Color) -> ImageFrameTabl
result
}
/// Constructs a raster image.
#[node_macro::node(category(""))]
fn image(_: impl Ctx, _primary: (), image: ImageFrameTable<Color>) -> ImageFrameTable<Color> {
image
}
// #[cfg(feature = "serde")]
// macro_rules! generate_imaginate_node {
// ($($val:ident: $t:ident: $o:ty,)*) => {

View File

@@ -83,7 +83,10 @@ fn decode_image(_: impl Ctx, data: Arc<[u8]>) -> ImageFrameTable<Color> {
};
let image = image.to_rgba32f();
let image = Image {
data: image.chunks(4).map(|pixel| Color::from_unassociated_alpha(pixel[0], pixel[1], pixel[2], pixel[3])).collect(),
data: image
.chunks(4)
.map(|pixel| Color::from_unassociated_alpha(pixel[0], pixel[1], pixel[2], pixel[3]).to_linear_srgb())
.collect(),
width: image.width(),
height: image.height(),
..Default::default()