mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 15:28:04 +08:00
Update #[min/max] node macro attributes to #[soft/hard]_[min/max] and make them clamp their input data (#2464)
* Fix min and max macro not enforcing limits when data flows * Use trait based clamping * Remove min/max from testing * cargo fmt * Resolve into min, and hard_min * cargo fmt * fix traits * cargo fmt * fix tests * rename as soft_x * Add validation code * Clean up (not compiling because of DVec2 clamping) * Avoid needing to add trait bounds to node definitions * Code review --------- Co-authored-by: Dennis Kobert <dennis@kobert.dev> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -1399,7 +1399,7 @@ async fn posterize<T: Adjust<Color>>(
|
||||
)]
|
||||
mut input: T,
|
||||
#[default(4)]
|
||||
#[min(2.)]
|
||||
#[hard_min(2.)]
|
||||
levels: u32,
|
||||
) -> T {
|
||||
input.adjust(|color| {
|
||||
@@ -1435,6 +1435,7 @@ async fn exposure<T: Adjust<Color>>(
|
||||
offset: f64,
|
||||
#[default(1.)]
|
||||
#[range((0.01, 10.))]
|
||||
#[hard_min(0.0001)]
|
||||
gamma_correction: f64,
|
||||
) -> T {
|
||||
input.adjust(|color| {
|
||||
|
||||
@@ -930,6 +930,8 @@ impl Color {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn gamma(&self, gamma: f32) -> Color {
|
||||
let gamma = gamma.max(0.0001);
|
||||
|
||||
// From https://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-6-gamma-correction/
|
||||
let inverse_gamma = 1. / gamma;
|
||||
self.map_rgb(|c: f32| c.powf(inverse_gamma))
|
||||
|
||||
Reference in New Issue
Block a user