mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
all: use color.NRGBA in public API
color.RGBA has two problems with regards to using it. First the color values need to be premultiplied, whereas most APIs have non-premultiplied values. This is mainly to preserve color components with low alpha values. Second there are two ways to premultiply with sRGB. One is to premultiply after sRGB conversion, the other is before. This makes using the API more confusing. Using color.NRGBA in sRGB makes it align with CSS.e Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
+5
-4
@@ -7,6 +7,7 @@ import (
|
||||
"image/color"
|
||||
"image/draw"
|
||||
|
||||
"gioui.org/internal/f32color"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/unit"
|
||||
@@ -14,12 +15,12 @@ import (
|
||||
)
|
||||
|
||||
type Icon struct {
|
||||
Color color.RGBA
|
||||
Color color.NRGBA
|
||||
src []byte
|
||||
// Cached values.
|
||||
op paint.ImageOp
|
||||
imgSize int
|
||||
imgColor color.RGBA
|
||||
imgColor color.NRGBA
|
||||
}
|
||||
|
||||
// NewIcon returns a new Icon from IconVG data.
|
||||
@@ -28,7 +29,7 @@ func NewIcon(data []byte) (*Icon, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Icon{src: data, Color: color.RGBA{A: 0xff}}, nil
|
||||
return &Icon{src: data, Color: color.NRGBA{A: 0xff}}, nil
|
||||
}
|
||||
|
||||
func (ic *Icon) Layout(gtx layout.Context, sz unit.Value) layout.Dimensions {
|
||||
@@ -49,7 +50,7 @@ func (ic *Icon) image(sz int) paint.ImageOp {
|
||||
img := image.NewRGBA(image.Rectangle{Max: image.Point{X: sz, Y: int(float32(sz) * dy / dx)}})
|
||||
var ico iconvg.Rasterizer
|
||||
ico.SetDstImage(img, img.Bounds(), draw.Src)
|
||||
m.Palette[0] = ic.Color
|
||||
m.Palette[0] = f32color.NRGBAToRGBA(ic.Color)
|
||||
iconvg.Decode(&ico, ic.src, &iconvg.DecodeOptions{
|
||||
Palette: &m.Palette,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user