linebender / color

Color in Rust.
Apache License 2.0
39 stars 5 forks source link

Implementation of Rgba8 type #41

Closed raphlinus closed 2 weeks ago

raphlinus commented 2 weeks ago

Adds Rgba8 type and some conversions and formatting.

This PR also changes the serialization of srgb to use the color function. If legacy RGB serialization is desired, the client can convert to Rgba8 first.

Closes #24.

raphlinus commented 2 weeks ago

I'm pushing this partly for discussion. There's not a huge amount of functionality attached to the new type - maybe that's a good thing, we should encourage all actual manipulation (including parsing) to happen in with the f32-based types.

tomcur commented 2 weeks ago

This PR also changes the serialization of srgb to use the color function. If legacy RGB serialization is desired, the client can convert to Rgba8 first.

I believe that follows the spec, which does that unless the color was constructed directly from a named color or from a named color space (if I'm reading this correctly – note it excludes the color function). The named color space functions that map to RGB clamp during parse-time according to the spec, so can be represented as legacy RGB when serialized.

e.g.,

rgba(50, 75, 100, 0.8) serializes to rgba(50, 75, 100, 0.8) color(srgb 0.1 0.2 0.3 / 0.8) serializes to color(srgb 0.1 0.2 0.3 / 0.8)

In my experimental draft #39 I'm trying to find a nice implementation according to spec.

raphlinus commented 2 weeks ago

Great, I'll merge this and then we can consider further refinements separately.