mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 02:58:11 +08:00
Refactor many usages of Color to natively store linear not gamma (#2457)
This commit is contained in:
@@ -454,7 +454,7 @@ export class Gradient {
|
||||
}
|
||||
}
|
||||
|
||||
// All channels range from 0 to 1
|
||||
// All channels range are represented by 0-1, sRGB, gamma.
|
||||
export class Color {
|
||||
readonly red!: number;
|
||||
|
||||
|
||||
@@ -481,12 +481,13 @@ impl EditorHandle {
|
||||
/// Update primary color with values on a scale from 0 to 1.
|
||||
#[wasm_bindgen(js_name = updatePrimaryColor)]
|
||||
pub fn update_primary_color(&self, red: f32, green: f32, blue: f32, alpha: f32) -> Result<(), JsValue> {
|
||||
let primary_color = match Color::from_rgbaf32(red, green, blue, alpha) {
|
||||
Some(color) => color,
|
||||
None => return Err(Error::new("Invalid color").into()),
|
||||
let Some(primary_color) = Color::from_rgbaf32(red, green, blue, alpha) else {
|
||||
return Err(Error::new("Invalid color").into());
|
||||
};
|
||||
|
||||
let message = ToolMessage::SelectPrimaryColor { color: primary_color };
|
||||
let message = ToolMessage::SelectPrimaryColor {
|
||||
color: primary_color.to_linear_srgb(),
|
||||
};
|
||||
self.dispatch(message);
|
||||
|
||||
Ok(())
|
||||
@@ -495,12 +496,13 @@ impl EditorHandle {
|
||||
/// Update secondary color with values on a scale from 0 to 1.
|
||||
#[wasm_bindgen(js_name = updateSecondaryColor)]
|
||||
pub fn update_secondary_color(&self, red: f32, green: f32, blue: f32, alpha: f32) -> Result<(), JsValue> {
|
||||
let secondary_color = match Color::from_rgbaf32(red, green, blue, alpha) {
|
||||
Some(color) => color,
|
||||
None => return Err(Error::new("Invalid color").into()),
|
||||
let Some(secondary_color) = Color::from_rgbaf32(red, green, blue, alpha) else {
|
||||
return Err(Error::new("Invalid color").into());
|
||||
};
|
||||
|
||||
let message = ToolMessage::SelectSecondaryColor { color: secondary_color };
|
||||
let message = ToolMessage::SelectSecondaryColor {
|
||||
color: secondary_color.to_linear_srgb(),
|
||||
};
|
||||
self.dispatch(message);
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user