mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Introduce Split/Combine Channels nodes (#1153)
* Add Channel Extrataction Node * Add hacky BlendModes for Inserting Color Channels * Fix Channel Exporter * Add Monochrome Option and Multi Output Node * Fix Input Mapping * Fix Formatting * Split Alpha Extraction to seperate node * Remove unnecessary functionality * Add Alpha Channel as an output to the extract channel node * Fix compilation * Add unpolished 'Combine Channels' Node * Fix Rebasing Issues * Add a bit of polish * Fix Rebase Issues * Switch from 'ColorChannel' to 'RedGreenBlue' I initially added an enum to hold color channels called 'ColorChannel', but while implementing the nodes, there somebody allready added a similar enum so I switched to that type * Add correct names * Add Improvement - Some Performance Improvements - Some Formatting Improvements * Add some improvements Most of this stuff was done by TrueDoctor in my Luchbreak :D * Implement IO Improvements - Converted primary output from split node to a dummy output - Removed primary Input from split node * Fix Formatting * Fix Combine RGB Node (hopefully final :D ) * Swap around Inputs and Outputs Move from ARGB -> RGBA * Improve naming * More naming fixes * Fix Replace -> Into * Rename Replacment -> Insertion * Add blank assist area --------- Co-authored-by: Keavon Chambers <keavon@keavon.com> Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
@@ -140,6 +140,11 @@ pub trait RGB: Pixel {
|
||||
self.blue()
|
||||
}
|
||||
}
|
||||
pub trait RGBMut: RGB {
|
||||
fn set_red(&mut self, red: Self::ColorChannel);
|
||||
fn set_green(&mut self, green: Self::ColorChannel);
|
||||
fn set_blue(&mut self, blue: Self::ColorChannel);
|
||||
}
|
||||
|
||||
pub trait AssociatedAlpha: RGB + Alpha {
|
||||
fn to_unassociated<Out: UnassociatedAlpha>(&self) -> Out;
|
||||
|
||||
@@ -46,7 +46,7 @@ impl core::fmt::Display for LuminanceCalculation {
|
||||
}
|
||||
|
||||
impl BlendMode {
|
||||
pub fn list() -> [BlendMode; 26] {
|
||||
pub fn list() -> [BlendMode; 29] {
|
||||
[
|
||||
BlendMode::Normal,
|
||||
BlendMode::Multiply,
|
||||
@@ -74,6 +74,9 @@ impl BlendMode {
|
||||
BlendMode::Saturation,
|
||||
BlendMode::Color,
|
||||
BlendMode::Luminosity,
|
||||
BlendMode::InsertRed,
|
||||
BlendMode::InsertGreen,
|
||||
BlendMode::InsertBlue,
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -121,6 +124,11 @@ pub enum BlendMode {
|
||||
Saturation,
|
||||
Color,
|
||||
Luminosity,
|
||||
|
||||
// Other Stuff
|
||||
InsertRed,
|
||||
InsertGreen,
|
||||
InsertBlue,
|
||||
}
|
||||
|
||||
impl core::fmt::Display for BlendMode {
|
||||
@@ -157,6 +165,10 @@ impl core::fmt::Display for BlendMode {
|
||||
BlendMode::Saturation => write!(f, "Saturation"),
|
||||
BlendMode::Color => write!(f, "Color"),
|
||||
BlendMode::Luminosity => write!(f, "Luminosity"),
|
||||
|
||||
BlendMode::InsertRed => write!(f, "Insert Red"),
|
||||
BlendMode::InsertGreen => write!(f, "Insert Green"),
|
||||
BlendMode::InsertBlue => write!(f, "Insert Blue"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,6 +190,30 @@ fn luminance_color_node(color: Color, luminance_calc: LuminanceCalculation) -> C
|
||||
color.map_rgb(|_| luminance)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct ExtractChannelNode<TargetChannel> {
|
||||
channel: TargetChannel,
|
||||
}
|
||||
|
||||
#[node_macro::node_fn(ExtractChannelNode)]
|
||||
fn extract_channel_node(color: Color, channel: RedGreenBlue) -> Color {
|
||||
let extracted_value = match channel {
|
||||
RedGreenBlue::Red => color.r(),
|
||||
RedGreenBlue::Green => color.g(),
|
||||
RedGreenBlue::Blue => color.b(),
|
||||
};
|
||||
return color.map_rgb(|_| extracted_value);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct ExtractAlphaNode;
|
||||
|
||||
#[node_macro::node_fn(ExtractAlphaNode)]
|
||||
fn extract_alpha_node(color: Color) -> Color {
|
||||
let alpha = color.a();
|
||||
Color::from_rgbaf32(alpha, alpha, alpha, 1.0).unwrap()
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct LevelsNode<InputStart, InputMid, InputEnd, OutputStart, OutputEnd> {
|
||||
input_start: InputStart,
|
||||
@@ -397,6 +433,10 @@ fn blend_node(input: (Color, Color), blend_mode: BlendMode, opacity: f64) -> Col
|
||||
BlendMode::Saturation => background.blend_saturation(foreground),
|
||||
BlendMode::Color => background.blend_color(foreground),
|
||||
BlendMode::Luminosity => background.blend_luminosity(foreground),
|
||||
|
||||
BlendMode::InsertRed => foreground.with_red(background.r()),
|
||||
BlendMode::InsertGreen => foreground.with_green(background.g()),
|
||||
BlendMode::InsertBlue => foreground.with_blue(background.b()),
|
||||
};
|
||||
|
||||
background.alpha_blend(target_color.to_associated_alpha(opacity as f32))
|
||||
|
||||
@@ -12,7 +12,7 @@ use spirv_std::num_traits::Euclid;
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
|
||||
use super::{Alpha, AssociatedAlpha, Luminance, Pixel, Rec709Primaries, RGB, SRGB};
|
||||
use super::{Alpha, AssociatedAlpha, Luminance, Pixel, RGBMut, Rec709Primaries, RGB, SRGB};
|
||||
|
||||
#[repr(C)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
@@ -86,6 +86,17 @@ impl RGB for Color {
|
||||
self.blue
|
||||
}
|
||||
}
|
||||
impl RGBMut for Color {
|
||||
fn set_red(&mut self, red: Self::ColorChannel) {
|
||||
self.red = red;
|
||||
}
|
||||
fn set_green(&mut self, green: Self::ColorChannel) {
|
||||
self.green = green;
|
||||
}
|
||||
fn set_blue(&mut self, blue: Self::ColorChannel) {
|
||||
self.blue = blue;
|
||||
}
|
||||
}
|
||||
|
||||
impl Pixel for Color {
|
||||
#[cfg(not(target_arch = "spirv"))]
|
||||
@@ -391,6 +402,42 @@ impl Color {
|
||||
Color::from_hsla(hue, saturation, lightness, alpha)
|
||||
}
|
||||
|
||||
pub fn with_alpha(&self, alpha: f32) -> Color {
|
||||
Color {
|
||||
red: self.red,
|
||||
green: self.green,
|
||||
blue: self.blue,
|
||||
alpha,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_red(&self, red: f32) -> Color {
|
||||
Color {
|
||||
red,
|
||||
green: self.green,
|
||||
blue: self.blue,
|
||||
alpha: self.alpha,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_green(&self, green: f32) -> Color {
|
||||
Color {
|
||||
red: self.red,
|
||||
green,
|
||||
blue: self.blue,
|
||||
alpha: self.alpha,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_blue(&self, blue: f32) -> Color {
|
||||
Color {
|
||||
red: self.red,
|
||||
green: self.green,
|
||||
blue,
|
||||
alpha: self.alpha,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn blend_normal(_c_b: f32, c_s: f32) -> f32 {
|
||||
c_s
|
||||
|
||||
Reference in New Issue
Block a user