google / iconvg

IconVG is a compact, binary format for simple vector graphics: icons, logos, glyphs and emoji.
Apache License 2.0
676 stars 11 forks source link

Gradients through transparent colors #24

Closed Hixie closed 3 years ago

Hixie commented 3 years ago

The spec specifies that colors use premultiplied alpha. This causes problems for gradients that go through fully transparent (0x00000000) colors, since there is no way to know what the lerped color value should be. For example, a gradient from (RGBA) 0x00000000 to 0xFFFF00FF could be going from transparent black to opaque yellow, or transparent yellow to opaque yellow, or transparent green to opaque yellow, each of which has rather different effects.

The spec does not specify how to handle this.

Some of the golden images suggest that 0x00000000 should be treated as fully-transparent whatever-happens-to-be-the-next-stop?

Hixie commented 3 years ago

(It's not clear what that means when the two colors on either side are different, though...)

nigeltao commented 3 years ago

The spec does not specify how to handle this.

The spec (the "Colors and Gradients" section) says:

Interpolation between explicit gradient stops also uses alpha-premultiplied color, unlike SVG. The halfway color between opaque bright red = RGBA(1, 0, 0, 1) and transparent black = RGBA(0, 0, 0, 0), which is RGBA(½, 0, 0, ½), is a 50% opaque bright red, not a 50% opaque dark red. The halfway point still has 100% Saturation and 100% Value (in the HSV Hue Saturation Value sense). It just has smaller alpha.

Does that answer your question?

Hixie commented 3 years ago

Ah, yes, I missed that that was referring to interpolation, despite reading that paragraph several times. :-)