Add alpha to Extract Channel node and remove Extract Alpha node (#1731)

* add `TaggedValue::RedGreenBlueAlpha`

* add alpha to `ExtractChannelNode`

* remove `ExtractAlphaNode` from `Split Channels`

* remove `ExtractAlphaNode`
This commit is contained in:
Karthik Prakash 2024-04-18 04:14:14 +05:30 committed by GitHub
parent 438c45eb80
commit 3019cc7253
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 70 additions and 33 deletions

View file

@ -256,22 +256,14 @@ pub struct ExtractChannelNode<TargetChannel> {
}
#[node_macro::node_fn(ExtractChannelNode)]
fn extract_channel_node(color: Color, channel: RedGreenBlue) -> Color {
fn extract_channel_node(color: Color, channel: RedGreenBlueAlpha) -> Color {
let extracted_value = match channel {
RedGreenBlue::Red => color.r(),
RedGreenBlue::Green => color.g(),
RedGreenBlue::Blue => color.b(),
RedGreenBlueAlpha::Red => color.r(),
RedGreenBlueAlpha::Green => color.g(),
RedGreenBlueAlpha::Blue => color.b(),
RedGreenBlueAlpha::Alpha => color.a(),
};
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.).unwrap()
color.map_rgba(|_| extracted_value)
}
#[derive(Debug, Clone, Copy, Default)]
@ -606,6 +598,27 @@ impl core::fmt::Display for RedGreenBlue {
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "std", derive(specta::Type))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, DynAny)]
pub enum RedGreenBlueAlpha {
Red,
Green,
Blue,
Alpha,
}
impl core::fmt::Display for RedGreenBlueAlpha {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
RedGreenBlueAlpha::Red => write!(f, "Red"),
RedGreenBlueAlpha::Green => write!(f, "Green"),
RedGreenBlueAlpha::Blue => write!(f, "Blue"),
RedGreenBlueAlpha::Alpha => write!(f, "Alpha"),
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "std", derive(specta::Type))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, DynAny)]