mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-18 18:38:05 +08:00
Upgrade to the Rust 2024 edition (#2367)
* Update to rust 2024 edition * Fixes * Clean up imports * Cargo fmt again --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -6,15 +6,13 @@ use crate::raster::curve::{Curve, CurveManipulatorGroup, ValueMapperNode};
|
||||
use crate::raster::image::{Image, ImageFrameTable};
|
||||
use crate::raster::{Channel, Color, Pixel};
|
||||
use crate::registry::types::{Angle, Percentage, SignedPercentage};
|
||||
use crate::vector::style::GradientStops;
|
||||
use crate::vector::VectorDataTable;
|
||||
use crate::vector::style::GradientStops;
|
||||
use crate::{Ctx, Node};
|
||||
use crate::{GraphicElement, GraphicGroupTable};
|
||||
|
||||
use dyn_any::DynAny;
|
||||
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt::Debug;
|
||||
use dyn_any::DynAny;
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use spirv_std::num_traits::float::Float;
|
||||
@@ -574,11 +572,7 @@ async fn threshold<T: Adjust<Color>>(
|
||||
LuminanceCalculation::MaximumChannels => color.maximum_rgb_channels(),
|
||||
};
|
||||
|
||||
if luminance >= min_luminance && luminance <= max_luminance {
|
||||
Color::WHITE
|
||||
} else {
|
||||
Color::BLACK
|
||||
}
|
||||
if luminance >= min_luminance && luminance <= max_luminance { Color::WHITE } else { Color::BLACK }
|
||||
});
|
||||
image
|
||||
}
|
||||
@@ -720,7 +714,7 @@ impl Adjust<Color> for Color {
|
||||
}
|
||||
impl Adjust<Color> for Option<Color> {
|
||||
fn adjust(&mut self, map_fn: impl Fn(&Color) -> Color) {
|
||||
if let Some(ref mut v) = self {
|
||||
if let Some(v) = self {
|
||||
*v = map_fn(v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use dyn_any::DynAny;
|
||||
|
||||
use glam::{DAffine2, DVec2};
|
||||
|
||||
#[cfg_attr(not(target_arch = "spirv"), derive(Debug))]
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
use crate::Color;
|
||||
use crate::graphene_core::raster::image::ImageFrameTable;
|
||||
use crate::raster::Image;
|
||||
use crate::vector::brush_stroke::BrushStroke;
|
||||
use crate::vector::brush_stroke::BrushStyle;
|
||||
use crate::Color;
|
||||
|
||||
use dyn_any::DynAny;
|
||||
|
||||
use core::hash::Hash;
|
||||
use dyn_any::DynAny;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
use super::discrete_srgb::{float_to_srgb_u8, srgb_u8_to_float};
|
||||
use super::{Alpha, AlphaMut, AssociatedAlpha, Luminance, LuminanceMut, Pixel, RGBMut, Rec709Primaries, RGB, SRGB};
|
||||
|
||||
use super::{Alpha, AlphaMut, AssociatedAlpha, Luminance, LuminanceMut, Pixel, RGB, RGBMut, Rec709Primaries, SRGB};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use core::hash::Hash;
|
||||
use dyn_any::DynAny;
|
||||
use half::f16;
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use spirv_std::num_traits::Euclid;
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use spirv_std::num_traits::float::Float;
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use spirv_std::num_traits::Euclid;
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use core::hash::Hash;
|
||||
use half::f16;
|
||||
use std::fmt::Write;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -663,11 +661,7 @@ impl Color {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn blend_darker_color(&self, other: Color) -> Color {
|
||||
if self.average_rgb_channels() <= other.average_rgb_channels() {
|
||||
*self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
if self.average_rgb_channels() <= other.average_rgb_channels() { *self } else { other }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -682,11 +676,7 @@ impl Color {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn blend_color_dodge(c_b: f32, c_s: f32) -> f32 {
|
||||
if c_s == 1. {
|
||||
1.
|
||||
} else {
|
||||
(c_b / (1. - c_s)).min(1.)
|
||||
}
|
||||
if c_s == 1. { 1. } else { (c_b / (1. - c_s)).min(1.) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -696,11 +686,7 @@ impl Color {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn blend_lighter_color(&self, other: Color) -> Color {
|
||||
if self.average_rgb_channels() >= other.average_rgb_channels() {
|
||||
*self
|
||||
} else {
|
||||
other
|
||||
}
|
||||
if self.average_rgb_channels() >= other.average_rgb_channels() { *self } else { other }
|
||||
}
|
||||
|
||||
pub fn blend_softlight(c_b: f32, c_s: f32) -> f32 {
|
||||
@@ -745,11 +731,7 @@ impl Color {
|
||||
}
|
||||
|
||||
pub fn blend_hard_mix(c_b: f32, c_s: f32) -> f32 {
|
||||
if Color::blend_linear_light(c_b, c_s) < 0.5 {
|
||||
0.
|
||||
} else {
|
||||
1.
|
||||
}
|
||||
if Color::blend_linear_light(c_b, c_s) < 0.5 { 0. } else { 1. }
|
||||
}
|
||||
|
||||
pub fn blend_difference(c_b: f32, c_s: f32) -> f32 {
|
||||
@@ -765,11 +747,7 @@ impl Color {
|
||||
}
|
||||
|
||||
pub fn blend_divide(c_b: f32, c_s: f32) -> f32 {
|
||||
if c_b == 0. {
|
||||
1.
|
||||
} else {
|
||||
c_b / c_s
|
||||
}
|
||||
if c_b == 0. { 1. } else { c_b / c_s }
|
||||
}
|
||||
|
||||
pub fn blend_hue(&self, c_s: Color) -> Color {
|
||||
@@ -988,20 +966,12 @@ impl Color {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn srgb_to_linear(channel: f32) -> f32 {
|
||||
if channel <= 0.04045 {
|
||||
channel / 12.92
|
||||
} else {
|
||||
((channel + 0.055) / 1.055).powf(2.4)
|
||||
}
|
||||
if channel <= 0.04045 { channel / 12.92 } else { ((channel + 0.055) / 1.055).powf(2.4) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn linear_to_srgb(channel: f32) -> f32 {
|
||||
if channel <= 0.0031308 {
|
||||
channel * 12.92
|
||||
} else {
|
||||
1.055 * channel.powf(1. / 2.4) - 0.055
|
||||
}
|
||||
if channel <= 0.0031308 { channel * 12.92 } else { 1.055 * channel.powf(1. / 2.4) - 0.055 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use super::{Channel, Linear, LuminanceMut};
|
||||
use crate::Node;
|
||||
|
||||
use dyn_any::{DynAny, StaticType, StaticTypeSized};
|
||||
|
||||
use core::ops::{Add, Mul, Sub};
|
||||
use dyn_any::{DynAny, StaticType, StaticTypeSized};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, DynAny, specta::Type)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
|
||||
@@ -85,11 +85,7 @@ pub fn float_to_srgb_u8(mut f: f32) -> u8 {
|
||||
let lerp = bias.wrapping_add(mult * lerp_idx) >> 24;
|
||||
|
||||
// Adjust linear interpolation to the correct value.
|
||||
if f > CRITICAL_POINTS[lerp as usize] {
|
||||
lerp as u8 + 1
|
||||
} else {
|
||||
lerp as u8
|
||||
}
|
||||
if f > CRITICAL_POINTS[lerp as usize] { lerp as u8 + 1 } else { lerp as u8 }
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
@@ -156,11 +152,7 @@ mod tests {
|
||||
|
||||
// https://microsoft.github.io/DirectX-Specs/d3d/archive/D3D11_3_FunctionalSpec.htm#SRGBtoFLOAT
|
||||
fn srgb_to_float_ref(f: f32) -> f32 {
|
||||
if f <= 0.04045f32 {
|
||||
f / 12.92f32
|
||||
} else {
|
||||
((f + 0.055f32) / 1.055f32).powf(2.4_f32)
|
||||
}
|
||||
if f <= 0.04045f32 { f / 12.92f32 } else { ((f + 0.055f32) / 1.055f32).powf(2.4_f32) }
|
||||
}
|
||||
|
||||
fn srgb_u8_to_float_ref(c: u8) -> f32 {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use super::discrete_srgb::float_to_srgb_u8;
|
||||
use super::Color;
|
||||
use crate::instances::Instances;
|
||||
use crate::transform::TransformMut;
|
||||
use super::discrete_srgb::float_to_srgb_u8;
|
||||
use crate::AlphaBlending;
|
||||
use crate::GraphicElement;
|
||||
use crate::instances::Instances;
|
||||
use crate::transform::TransformMut;
|
||||
use alloc::vec::Vec;
|
||||
use core::hash::{Hash, Hasher};
|
||||
use dyn_any::StaticType;
|
||||
|
||||
Reference in New Issue
Block a user