mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
WIP graster-nodes: change Color params to Option<Color>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
//! custom BufferStruct impl for graphite
|
||||
|
||||
use crate::color::Color;
|
||||
use crate::shaders::buffer_struct::BufferStruct;
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Zeroable, Pod)]
|
||||
pub struct OptionalColorBuffer(u32, <Color as BufferStruct>::Buffer);
|
||||
|
||||
unsafe impl BufferStruct for Option<Color> {
|
||||
type Buffer = OptionalColorBuffer;
|
||||
|
||||
#[inline]
|
||||
fn write(from: Self) -> Self::Buffer {
|
||||
match from {
|
||||
None => OptionalColorBuffer(0, Color::write(Color::default())),
|
||||
Some(t) => OptionalColorBuffer(1, Color::write(t)),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read(from: Self::Buffer) -> Self {
|
||||
match from.0 {
|
||||
1 => Some(Color::read(from.1)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
use bytemuck::Pod;
|
||||
|
||||
mod glam;
|
||||
mod graphite;
|
||||
mod primitive;
|
||||
|
||||
/// A BufferStruct is a "parallel representation" of the original struct with some fundamental types remapped. This
|
||||
|
||||
@@ -341,7 +341,7 @@ fn black_and_white<T: Adjust<Color>>(
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
#[default(Color::BLACK)] tint: Color,
|
||||
#[default(Color::BLACK)] tint: Option<Color>,
|
||||
#[default(40.)]
|
||||
#[range((-200., 300.))]
|
||||
reds: PercentageF32,
|
||||
@@ -361,6 +361,8 @@ fn black_and_white<T: Adjust<Color>>(
|
||||
#[range((-200., 300.))]
|
||||
magentas: PercentageF32,
|
||||
) -> T {
|
||||
let tint = tint.unwrap_or(Color::BLACK);
|
||||
|
||||
image.adjust(|color| {
|
||||
let color = color.to_gamma_srgb();
|
||||
|
||||
|
||||
@@ -169,11 +169,12 @@ fn color_overlay<T: Adjust<Color>>(
|
||||
)]
|
||||
#[gpu_image]
|
||||
mut image: T,
|
||||
#[default(Color::BLACK)] color: Color,
|
||||
#[default(Color::BLACK)] color: Option<Color>,
|
||||
blend_mode: BlendMode,
|
||||
#[default(100.)] opacity: PercentageF32,
|
||||
) -> T {
|
||||
let opacity = (opacity as f32 / 100.).clamp(0., 1.);
|
||||
let color = color.unwrap_or(Color::BLACK);
|
||||
|
||||
image.adjust(|pixel| {
|
||||
let image = pixel.map_rgb(|channel| channel * (1. - opacity));
|
||||
@@ -206,7 +207,7 @@ mod test {
|
||||
// 100% of the output should come from the multiplied value
|
||||
let opacity = 100.;
|
||||
|
||||
let result = super::color_overlay((), Table::new_from_element(Raster::new_cpu(image.clone())), overlay_color, BlendMode::Multiply, opacity);
|
||||
let result = super::color_overlay((), Table::new_from_element(Raster::new_cpu(image.clone())), Some(overlay_color), BlendMode::Multiply, opacity);
|
||||
let result = result.iter().next().unwrap().element;
|
||||
|
||||
// The output should just be the original green and alpha channels (as we multiply them by 1 and other channels by 0)
|
||||
|
||||
@@ -51,6 +51,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||
#[cfg(feature = "gpu")]
|
||||
into_node!(from: Table<Raster<GPU>>, to: Table<Graphic>),
|
||||
// into_node!(from: Table<Raster<CPU>>, to: Table<Raster<SRGBA8>>),
|
||||
into_node!(from: Table<Color>, to: Option<Color>),
|
||||
#[cfg(feature = "gpu")]
|
||||
into_node!(from: &WasmEditorApi, to: &WgpuExecutor),
|
||||
// =============
|
||||
|
||||
Reference in New Issue
Block a user