Skip to content

Commit

Permalink
palette/moreland: prevent fma optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jun 13, 2024
1 parent b08a3fe commit 30c70fd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions palette/moreland/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type rgb struct {
// cieXYZ returns a CIE XYZ color representation of the receiver.
func (c rgb) cieXYZ() cieXYZ {
return cieXYZ{
X: 0.4124*c.R + 0.3576*c.G + 0.1805*c.B,
Y: 0.2126*c.R + 0.7152*c.G + 0.0722*c.B,
Z: 0.0193*c.R + 0.1192*c.G + 0.9505*c.B,
X: float64(0.4124*c.R) + float64(0.3576*c.G) + float64(.1805*c.B),
Y: float64(0.2126*c.R) + float64(0.7152*c.G) + float64(.0722*c.B),
Z: float64(0.0193*c.R) + float64(0.1192*c.G) + float64(.9505*c.B),
}
}

Expand All @@ -29,7 +29,7 @@ func (c rgb) sRGBA(alpha float64) sRGBA {
// f converts from a linear RGB component to an sRGB component.
f := func(v float64) float64 {
if v > 0.0031308 {
return 1.055*math.Pow(v, 1/2.4) - 0.055
return float64(1.055*math.Pow(v, 1/2.4)) - 0.055
}
return 12.92 * v
}
Expand All @@ -51,9 +51,9 @@ type cieXYZ struct {
// rgb returns a linear RGB representation of the receiver.
func (c cieXYZ) rgb() rgb {
return rgb{
R: c.X*3.2406 + c.Y*-1.5372 + c.Z*-0.4986,
G: c.X*-0.9689 + c.Y*1.8758 + c.Z*0.0415,
B: c.X*0.0557 + c.Y*-0.204 + c.Z*1.057,
R: float64(c.X*3.2406) + float64(c.Y*-1.5372) + float64(c.Z*-0.4986),
G: float64(c.X*-0.9689) + float64(c.Y*1.8758) + float64(c.Z*0.0415),
B: float64(c.X*0.0557) + float64(c.Y*-0.204) + float64(c.Z*1.057),
}
}

Expand All @@ -64,14 +64,14 @@ func (c cieXYZ) cieLAB() cieLAB {
if v > 0.008856 {
return math.Pow(v, 1.0/3.0)
}
return 7.787*v + 16.0/116.0
return float64(7.787*v) + float64(16.0/116.0)
}

tempX := f(c.X / 0.9505)
tempY := f(c.Y)
tempZ := f(c.Z / 1.089)
return cieLAB{
L: (116.0 * tempY) - 16.0,
L: float64(116.0*tempY) - 16.0,
A: 500.0 * (tempX - tempY),
B: 200 * (tempY - tempZ),
}
Expand Down
8 changes: 4 additions & 4 deletions palette/moreland/luminance.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (l *luminance) At(v float64) (color.Color, error) {
c2 := l.colors[i]
frac := (scalar - l.scalars[i-1]) / (l.scalars[i] - l.scalars[i-1])
o := cieLAB{
L: frac*(c2.L-c1.L) + c1.L,
A: frac*(c2.A-c1.A) + c1.A,
B: frac*(c2.B-c1.B) + c1.B,
L: float64(frac*(c2.L-c1.L)) + float64(c1.L),
A: float64(frac*(c2.A-c1.A)) + float64(c1.A),
B: float64(frac*(c2.B-c1.B)) + float64(c1.B),
}.cieXYZ().rgb().sRGBA(l.alpha)
o.clamp()
return o, nil
Expand Down Expand Up @@ -179,7 +179,7 @@ func (l luminance) Palette(n int) palette.Palette {
var v float64
c := make([]color.Color, n)
for i := 0; i < n; i++ {
v = l.min + delta*float64(i)
v = l.min + float64(delta*float64(i))
var err error
c[i], err = l.At(v)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions palette/moreland/smooth.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ func (p *smoothDiverging) interpolateMSHDiverging(scalar, convergePoint float64)
// interpolation factor
interp := scalar / convergePoint
return msh{
M: (p.convergeM-p.start.M)*interp + p.start.M,
M: float64((p.convergeM-p.start.M)*interp) + p.start.M,
S: p.start.S * (1 - interp),
H: p.start.H + startHTwist*interp,
H: p.start.H + float64(startHTwist*interp),
}
}
// interpolation factors
interp1 := (scalar - 1) / (convergePoint - 1)
interp2 := (scalar/convergePoint - 1)
var H float64
if scalar > convergePoint {
H = p.end.H + endHTwist*interp1
H = p.end.H + float64(endHTwist*interp1)
}
return msh{
M: (p.convergeM-p.end.M)*interp1 + p.end.M,
M: float64((p.convergeM-p.end.M)*interp1) + p.end.M,
S: p.end.S * interp2,
H: H,
}
Expand All @@ -173,7 +173,7 @@ func (p smoothDiverging) Palette(n int) palette.Palette {
delta := (p.max - p.min) / float64(n-1)
c := make([]color.Color, n)
for i := range c {
v := p.min + delta*float64(i)
v := p.min + float64(delta*float64(i))
var err error
c[i], err = p.At(v)
if err != nil {
Expand Down

0 comments on commit 30c70fd

Please sign in to comment.