GraphiteEditor / Graphite

2D vector & raster editor that melds traditional layers & tools with a modern node-based, non-destructive, procedural workflow.
https://graphite.rs
Apache License 2.0
7.3k stars 386 forks source link

Color::from_rgb_str() and Color::rgb_hex() inconsistency #1710

Open adamgerhant opened 3 months ago

adamgerhant commented 3 months ago

When creating a color from a hex string with Color::from_rgb_str(), the hex string returned with Color::rgb_hex() is different.

Example:

let hex_color_before = "cccccc";
use graphene_core::raster::color::Color;
let color = Color::from_rgb_str(hex_color_before).unwrap();
let hex_color_after = color.rgb_hex();
console_log::init_with_level(log::Level::Info);
log::info!("rgb_hex: {:?}", hex_color_after); //logs "999999"

I'm pretty sure this is not intended behavior

Keavon commented 3 months ago

This is because Color::from_rgb_str() gets mapped from gamma to linear but Color::rgb_hex() doesn't map it back to gamma before printing the output. So that's definitely a bug, although I'll have to consult with @TrueDoctor to decide which part of that process should be fixed. I'm inclined to say that we want all colors to be linear, meaning we convert back to gamma before printing in Color::rgb_hex() (then we have to trace any other usages of that function where we might be accidentally using the wrong linear/gamma and fix it in those too.)