Graphite icon indicating copy to clipboard operation
Graphite copied to clipboard

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

Open adamgerhant opened this issue 1 year ago • 1 comments

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

adamgerhant avatar Mar 27 '24 23:03 adamgerhant

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.)

Keavon avatar Mar 27 '24 23:03 Keavon