mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 06:38:03 +08:00
Update graphene-cli and fix no-std compilation for graphene-core (#1428)
* Initialize wgpu executor from graphene cli * Make `graphene-core` `no-std` complient again * Implemnt image similarity calculation * Add nan checks * Make image comparison optional * Feature gate quantization to reduce the number of warnings
This commit is contained in:
@@ -4,6 +4,7 @@ pub struct LogToConsoleNode;
|
||||
|
||||
#[node_macro::node_fn(LogToConsoleNode)]
|
||||
fn log_to_console<T: core::fmt::Debug>(value: T) -> T {
|
||||
#[cfg(not(target_arch = "spirv"))]
|
||||
debug!("{:#?}", value);
|
||||
value
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ use core::marker::PhantomData;
|
||||
use core::ops::{Add, Div, Mul, Rem, Sub};
|
||||
use num_traits::Pow;
|
||||
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use spirv_std::num_traits::float::Float;
|
||||
|
||||
// Add
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
pub struct AddNode;
|
||||
|
||||
@@ -150,13 +150,27 @@ fn dequantize_fn<'a>(color: PackedPixel, quantization: [Quantization; 4]) -> Col
|
||||
|
||||
pub fn dequantize_color(color: PackedPixel, quant: [Quantization; 4]) -> Color {
|
||||
let mut offset = 0;
|
||||
let r = decode(color.0, offset, quant[0]);
|
||||
let mut r = decode(color.0, offset, quant[0]);
|
||||
offset += quant[0].bits();
|
||||
let g = decode(color.0, offset, quant[1]);
|
||||
let mut g = decode(color.0, offset, quant[1]);
|
||||
offset += quant[1].bits();
|
||||
let b = decode(color.0, offset, quant[2]);
|
||||
let mut b = decode(color.0, offset, quant[2]);
|
||||
offset += quant[2].bits();
|
||||
let a = decode(color.0, offset, quant[3]);
|
||||
let mut a = decode(color.0, offset, quant[3]);
|
||||
if a.is_nan() {
|
||||
a = 0.;
|
||||
}
|
||||
|
||||
if r.is_nan() {
|
||||
r = 0.;
|
||||
}
|
||||
|
||||
if g.is_nan() {
|
||||
g = 0.;
|
||||
}
|
||||
if b.is_nan() {
|
||||
b = 0.;
|
||||
}
|
||||
|
||||
Color::from_rgbaf32_unchecked(r, g, b, a)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ use glam::DVec2;
|
||||
|
||||
pub use self::color::{Color, Luma, SRGBA8};
|
||||
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use spirv_std::num_traits::float::Float;
|
||||
|
||||
pub mod adjustments;
|
||||
pub mod bbox;
|
||||
#[cfg(not(target_arch = "spirv"))]
|
||||
@@ -14,6 +17,7 @@ pub mod brightness_contrast;
|
||||
#[cfg(not(target_arch = "spirv"))]
|
||||
pub mod brush_cache;
|
||||
pub mod color;
|
||||
#[cfg(not(target_arch = "spirv"))]
|
||||
pub mod curve;
|
||||
pub mod discrete_srgb;
|
||||
pub use adjustments::*;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use super::curve::{Curve, CurveManipulatorGroup, ValueMapperNode};
|
||||
use super::{Channel, Color, ImageFrame, Node, RGBMut};
|
||||
use super::{Channel, Color, Node, RGBMut};
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
use super::ImageFrame;
|
||||
|
||||
use bezier_rs::{Bezier, TValue};
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
|
||||
use core::fmt::Debug;
|
||||
@@ -890,14 +893,17 @@ fn exposure(color: Color, exposure: f32, offset: f32, gamma_correction: f32) ->
|
||||
|
||||
const WINDOW_SIZE: usize = 1024;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct GenerateCurvesNode<OutputChannel, Curve> {
|
||||
curve: Curve,
|
||||
_channel: core::marker::PhantomData<OutputChannel>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[node_macro::node_fn(GenerateCurvesNode<_Channel>)]
|
||||
fn generate_curves<_Channel: Channel + super::Linear>(_primary: (), curve: Curve) -> ValueMapperNode<_Channel> {
|
||||
use bezier_rs::{Bezier, TValue};
|
||||
let [mut pos, mut param]: [[f32; 2]; 2] = [[0.; 2], curve.first_handle];
|
||||
let mut lut = vec![_Channel::from_f64(0.); WINDOW_SIZE];
|
||||
let end = CurveManipulatorGroup {
|
||||
@@ -934,11 +940,13 @@ fn generate_curves<_Channel: Channel + super::Linear>(_primary: (), curve: Curve
|
||||
ValueMapperNode::new(lut)
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ColorFillNode<C> {
|
||||
color: C,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[node_macro::node_fn(ColorFillNode)]
|
||||
pub fn color_fill_node(mut image_frame: ImageFrame<Color>, color: Color) -> ImageFrame<Color> {
|
||||
for pixel in &mut image_frame.image.data {
|
||||
@@ -951,12 +959,14 @@ pub fn color_fill_node(mut image_frame: ImageFrame<Color>, color: Color) -> Imag
|
||||
image_frame
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct ColorOverlayNode<Color, BlendMode, Opacity> {
|
||||
color: Color,
|
||||
blend_mode: BlendMode,
|
||||
opacity: Opacity,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[node_macro::node_fn(ColorOverlayNode)]
|
||||
pub fn color_overlay_node(mut image: ImageFrame<Color>, color: Color, blend_mode: BlendMode, opacity: f32) -> ImageFrame<Color> {
|
||||
let opacity = (opacity / 100.).clamp(0., 1.);
|
||||
|
||||
Reference in New Issue
Block a user