Wrap opacity/blend_mode in alpha_blending struct for graphic elements

This commit is contained in:
Keavon Chambers
2023-12-08 20:15:37 -08:00
parent 10f2fa92e5
commit e459e599b4
15 changed files with 111 additions and 96 deletions

View File

@@ -356,7 +356,7 @@ async fn brush(image: ImageFrame<Color>, bounds: ImageFrame<Color>, strokes: Vec
let opaque_image = ImageFrame {
image: Image::new(bbox.size().x as u32, bbox.size().y as u32, Color::WHITE),
transform: background_bounds,
blend_mode: BlendMode::Normal,
..Default::default()
};
let mut erase_restore_mask = opaque_image;
@@ -410,11 +410,7 @@ mod test {
#[test]
fn test_translate_node() {
let image = Image::new(10, 10, Color::TRANSPARENT);
let mut image = ImageFrame {
image,
transform: DAffine2::IDENTITY,
blend_mode: BlendMode::Normal,
};
let mut image = ImageFrame { image, ..Default::default() };
image.translate(DVec2::new(1., 2.));
let translate_node = TranslateNode::new(ClonedNode::new(image));
let image = translate_node.eval(DVec2::new(1., 2.));

View File

@@ -90,7 +90,7 @@ async fn map_gpu<'a: 'input>(image: ImageFrame<Color>, node: DocumentNode, edito
height: image.image.height,
},
transform: image.transform,
blend_mode: image.blend_mode,
alpha_blending: image.alpha_blending,
};
// TODO: The cache should be based on the network topology not the node name
@@ -142,7 +142,7 @@ async fn map_gpu<'a: 'input>(image: ImageFrame<Color>, node: DocumentNode, edito
height: image.image.height,
},
transform: image.transform,
blend_mode: image.blend_mode,
alpha_blending: image.alpha_blending,
}
}
@@ -588,6 +588,6 @@ async fn blend_gpu_image(foreground: ImageFrame<Color>, background: ImageFrame<C
height: background.image.height,
},
transform: background.transform,
blend_mode: background.blend_mode,
alpha_blending: background.alpha_blending,
}
}

View File

@@ -8,7 +8,7 @@ use graphene_core::transform::{Footprint, Transform};
use crate::wasm_application_io::WasmEditorApi;
use graphene_core::raster::bbox::{AxisAlignedBbox, Bbox};
use graphene_core::value::CopiedNode;
use graphene_core::{Color, Node};
use graphene_core::{AlphaBlending, Color, Node};
use std::collections::HashMap;
use std::fmt::Debug;
@@ -115,7 +115,7 @@ fn sample(footprint: Footprint, image_frame: ImageFrame<Color>) -> ImageFrame<Co
ImageFrame {
image,
transform: new_transform,
blend_mode: image_frame.blend_mode,
alpha_blending: image_frame.alpha_blending,
}
}
@@ -309,7 +309,7 @@ where
let mut new_background = ImageFrame {
image: new_background,
transform: transfrom,
blend_mode: background.blend_mode,
alpha_blending: background.alpha_blending,
};
new_background = blend_image(background, new_background, map_fn);
@@ -422,7 +422,7 @@ fn extend_image_to_bounds_node(image: ImageFrame<Color>, bounds: DAffine2) -> Im
ImageFrame {
image: new_img,
transform: new_texture_to_layer_space,
blend_mode: image.blend_mode,
alpha_blending: image.alpha_blending,
}
}
@@ -457,8 +457,11 @@ fn empty_image<_P: Pixel>(transform: DAffine2, color: _P) -> ImageFrame<_P> {
let image = Image::new(width, height, color);
let blend_mode = BlendMode::Normal;
ImageFrame { image, transform, blend_mode }
ImageFrame {
image,
transform,
alpha_blending: AlphaBlending::default(),
}
}
macro_rules! generate_imaginate_node {
@@ -495,7 +498,7 @@ macro_rules! generate_imaginate_node {
use std::hash::Hasher;
let mut hasher = rustc_hash::FxHasher::default();
frame.image.hash(&mut hasher);
let hash =hasher.finish();
let hash = hasher.finish();
Box::pin(async move {
let controller: std::pin::Pin<Box<dyn std::future::Future<Output = ImaginateController>>> = controller;
@@ -505,16 +508,12 @@ macro_rules! generate_imaginate_node {
let image = super::imaginate::imaginate(frame.image, editor_api, controller, $($val,)*).await;
self.cache.lock().unwrap().insert(hash, image.clone());
return ImageFrame {
image,
..frame
}
return ImageFrame { image, ..frame }
}
let image = self.cache.lock().unwrap().get(&hash).cloned().unwrap_or_default();
ImageFrame {
image,
..frame
}
ImageFrame { image, ..frame }
})
}
}
@@ -549,7 +548,7 @@ fn image_frame<_P: Pixel>(image: Image<_P>, transform: DAffine2) -> graphene_cor
graphene_core::raster::ImageFrame {
image,
transform,
blend_mode: BlendMode::Normal,
alpha_blending: AlphaBlending::default(),
}
}
@@ -576,7 +575,7 @@ fn pixel_noise(width: u32, height: u32, seed: u32, noise_type: NoiseType) -> gra
ImageFrame::<Color> {
image,
transform: DAffine2::from_scale(DVec2::new(width as f64, height as f64)),
blend_mode: BlendMode::Normal,
alpha_blending: AlphaBlending::default(),
}
}
@@ -621,7 +620,7 @@ fn mandelbrot_node(footprint: Footprint) -> ImageFrame<Color> {
ImageFrame {
image: Image { width, height, data },
transform: DAffine2::from_translation(offset) * DAffine2::from_scale(size),
blend_mode: BlendMode::Normal,
..Default::default()
}
}

View File

@@ -279,8 +279,7 @@ fn decode_image_node<'a: 'input>(data: Arc<[u8]>) -> ImageFrame<Color> {
width: image.width(),
height: image.height(),
},
transform: glam::DAffine2::IDENTITY,
blend_mode: graphene_core::raster::BlendMode::Normal,
..Default::default()
};
image
}