Skip to content

Commit 579166f

Browse files
committed
f32: switch to f32 params
1 parent 68f195c commit 579166f

File tree

5 files changed

+41
-35
lines changed

5 files changed

+41
-35
lines changed

editor/src/messages/portfolio/document/node_graph/node_properties.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ pub(crate) fn property_from_type(
147147
Type::Concrete(concrete_type) => {
148148
match concrete_type.alias.as_ref().map(|x| x.as_ref()) {
149149
// Aliased types (ambiguous values)
150-
Some("Percentage") => number_widget(default_info, number_input.percentage().min(min(0.)).max(max(100.))).into(),
151-
Some("SignedPercentage") => number_widget(default_info, number_input.percentage().min(min(-100.)).max(max(100.))).into(),
152-
Some("Angle") => number_widget(default_info, number_input.mode_range().min(min(-180.)).max(max(180.)).unit(unit.unwrap_or("°"))).into(),
150+
Some("Percentage") | Some("PercentageF32") => number_widget(default_info, number_input.percentage().min(min(0.)).max(max(100.))).into(),
151+
Some("SignedPercentage") | Some("SignedPercentageF32") => number_widget(default_info, number_input.percentage().min(min(-100.)).max(max(100.))).into(),
152+
Some("Angle") | Some("AngleF32") => number_widget(default_info, number_input.mode_range().min(min(-180.)).max(max(180.)).unit(unit.unwrap_or("°"))).into(),
153153
Some("Multiplier") => number_widget(default_info, number_input.unit(unit.unwrap_or("x"))).into(),
154154
Some("PixelLength") => number_widget(default_info, number_input.min(min(0.)).unit(unit.unwrap_or(" px"))).into(),
155155
Some("Length") => number_widget(default_info, number_input.min(min(0.))).into(),

node-graph/gbrush/src/brush.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub async fn create_brush_texture(brush_style: &BrushStyle) -> Raster<CPU> {
137137
}
138138

139139
pub fn blend_with_mode(background: TableRow<Raster<CPU>>, foreground: TableRow<Raster<CPU>>, blend_mode: BlendMode, opacity: f64) -> TableRow<Raster<CPU>> {
140-
let opacity = opacity / 100.;
140+
let opacity = opacity as f32 / 100.;
141141
match std::hint::black_box(blend_mode) {
142142
// Normal group
143143
BlendMode::Normal => blend_image_closure(foreground, background, |a, b| blend_colors(a, b, BlendMode::Normal, opacity)),

node-graph/gcore-shaders/src/registry.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
pub mod types {
22
/// 0% - 100%
33
pub type Percentage = f64;
4+
/// 0% - 100%
5+
pub type PercentageF32 = f32;
46
/// -100% - 100%
57
pub type SignedPercentage = f64;
8+
/// -100% - 100%
9+
pub type SignedPercentageF32 = f32;
610
/// -180° - 180°
711
pub type Angle = f64;
12+
/// -180° - 180°
13+
pub type AngleF32 = f32;
814
/// Ends in the unit of x
915
pub type Multiplier = f64;
1016
/// Non-negative integer with px unit

node-graph/graster-nodes/src/adjustments.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use graphene_core::raster_types::{CPU, Raster};
1111
use graphene_core::table::Table;
1212
use graphene_core_shaders::color::Color;
1313
use graphene_core_shaders::context::Ctx;
14-
use graphene_core_shaders::registry::types::{Angle, Percentage, SignedPercentage};
14+
use graphene_core_shaders::registry::types::{AngleF32, PercentageF32, SignedPercentageF32};
1515
#[cfg(not(feature = "std"))]
1616
use num_traits::float::Float;
1717

@@ -149,8 +149,8 @@ fn brightness_contrast<T: Adjust<Color>>(
149149
GradientStops,
150150
)]
151151
mut input: T,
152-
brightness: SignedPercentage,
153-
contrast: SignedPercentage,
152+
brightness: SignedPercentageF32,
153+
contrast: SignedPercentageF32,
154154
use_classic: bool,
155155
) -> T {
156156
if use_classic {
@@ -239,11 +239,11 @@ fn levels<T: Adjust<Color>>(
239239
GradientStops,
240240
)]
241241
mut image: T,
242-
#[default(0.)] shadows: Percentage,
243-
#[default(50.)] midtones: Percentage,
244-
#[default(100.)] highlights: Percentage,
245-
#[default(0.)] output_minimums: Percentage,
246-
#[default(100.)] output_maximums: Percentage,
242+
#[default(0.)] shadows: PercentageF32,
243+
#[default(50.)] midtones: PercentageF32,
244+
#[default(100.)] highlights: PercentageF32,
245+
#[default(0.)] output_minimums: PercentageF32,
246+
#[default(100.)] output_maximums: PercentageF32,
247247
) -> T {
248248
image.adjust(|color| {
249249
let color = color.to_gamma_srgb();
@@ -310,22 +310,22 @@ fn black_and_white<T: Adjust<Color>>(
310310
#[default(Color::BLACK)] tint: Table<Color>,
311311
#[default(40.)]
312312
#[range((-200., 300.))]
313-
reds: Percentage,
313+
reds: PercentageF32,
314314
#[default(60.)]
315315
#[range((-200., 300.))]
316-
yellows: Percentage,
316+
yellows: PercentageF32,
317317
#[default(40.)]
318318
#[range((-200., 300.))]
319-
greens: Percentage,
319+
greens: PercentageF32,
320320
#[default(60.)]
321321
#[range((-200., 300.))]
322-
cyans: Percentage,
322+
cyans: PercentageF32,
323323
#[default(20.)]
324324
#[range((-200., 300.))]
325-
blues: Percentage,
325+
blues: PercentageF32,
326326
#[default(80.)]
327327
#[range((-200., 300.))]
328-
magentas: Percentage,
328+
magentas: PercentageF32,
329329
) -> T {
330330
let tint: Option<Color> = tint.into();
331331
let tint = tint.unwrap_or(Color::BLACK);
@@ -383,9 +383,9 @@ fn hue_saturation<T: Adjust<Color>>(
383383
GradientStops,
384384
)]
385385
mut input: T,
386-
hue_shift: Angle,
387-
saturation_shift: SignedPercentage,
388-
lightness_shift: SignedPercentage,
386+
hue_shift: AngleF32,
387+
saturation_shift: SignedPercentageF32,
388+
lightness_shift: SignedPercentageF32,
389389
) -> T {
390390
input.adjust(|color| {
391391
let color = color.to_gamma_srgb();
@@ -441,8 +441,8 @@ fn threshold<T: Adjust<Color>>(
441441
GradientStops,
442442
)]
443443
mut image: T,
444-
#[default(50.)] min_luminance: Percentage,
445-
#[default(100.)] max_luminance: Percentage,
444+
#[default(50.)] min_luminance: PercentageF32,
445+
#[default(100.)] max_luminance: PercentageF32,
446446
luminance_calc: LuminanceCalculation,
447447
) -> T {
448448
image.adjust(|color| {
@@ -487,7 +487,7 @@ fn vibrance<T: Adjust<Color>>(
487487
GradientStops,
488488
)]
489489
mut image: T,
490-
vibrance: SignedPercentage,
490+
vibrance: SignedPercentageF32,
491491
) -> T {
492492
image.adjust(|color| {
493493
let vibrance = vibrance as f32 / 100.;
@@ -959,21 +959,21 @@ fn exposure<T: Adjust<Color>>(
959959
GradientStops,
960960
)]
961961
mut input: T,
962-
exposure: f64,
963-
offset: f64,
962+
exposure: f32,
963+
offset: f32,
964964
#[default(1.)]
965965
#[range((0.01, 10.))]
966966
#[hard_min(0.0001)]
967-
gamma_correction: f64,
967+
gamma_correction: f32,
968968
) -> T {
969969
input.adjust(|color| {
970970
let adjusted = color
971971
// Exposure
972-
.map_rgb(|c: f32| c * 2_f32.powf(exposure as f32))
972+
.map_rgb(|c: f32| c * 2_f32.powf(exposure))
973973
// Offset
974-
.map_rgb(|c: f32| c + offset as f32)
974+
.map_rgb(|c: f32| c + offset)
975975
// Gamma correction
976-
.gamma(gamma_correction as f32);
976+
.gamma(gamma_correction);
977977

978978
adjusted.map_rgb(|c: f32| c.clamp(0., 1.))
979979
});

node-graph/graster-nodes/src/blending_nodes.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use graphene_core::table::Table;
88
use graphene_core_shaders::Ctx;
99
use graphene_core_shaders::blending::BlendMode;
1010
use graphene_core_shaders::color::{Color, Pixel};
11-
use graphene_core_shaders::registry::types::Percentage;
11+
use graphene_core_shaders::registry::types::PercentageF32;
1212

1313
pub trait Blend<P: Pixel> {
1414
fn blend(&self, under: &Self, blend_fn: impl Fn(P, P) -> P) -> Self;
@@ -81,7 +81,7 @@ mod blend_std {
8181
}
8282

8383
#[inline(always)]
84-
pub fn blend_colors(foreground: Color, background: Color, blend_mode: BlendMode, opacity: f64) -> Color {
84+
pub fn blend_colors(foreground: Color, background: Color, blend_mode: BlendMode, opacity: f32) -> Color {
8585
let target_color = match blend_mode {
8686
// Other utility blend modes (hidden from the normal list) - do not have alpha blend
8787
BlendMode::Erase => return background.alpha_subtract(foreground),
@@ -151,7 +151,7 @@ fn blend<T: Blend<Color> + Send>(
151151
)]
152152
under: T,
153153
blend_mode: BlendMode,
154-
#[default(100.)] opacity: Percentage,
154+
#[default(100.)] opacity: PercentageF32,
155155
) -> T {
156156
over.blend(&under, |a, b| blend_colors(a, b, blend_mode, opacity / 100.))
157157
}
@@ -168,7 +168,7 @@ fn color_overlay<T: Adjust<Color>>(
168168
mut image: T,
169169
#[default(Color::BLACK)] color: Table<Color>,
170170
blend_mode: BlendMode,
171-
#[default(100.)] opacity: Percentage,
171+
#[default(100.)] opacity: PercentageF32,
172172
) -> T {
173173
let opacity = (opacity as f32 / 100.).clamp(0., 1.);
174174

@@ -204,7 +204,7 @@ mod test {
204204
let overlay_color = Color::GREEN;
205205

206206
// 100% of the output should come from the multiplied value
207-
let opacity = 100_f64;
207+
let opacity = 100.;
208208

209209
let result = super::color_overlay(
210210
(),

0 commit comments

Comments
 (0)