Skip to content

Commit 30c70fd

Browse files
committed
palette/moreland: prevent fma optimisations
1 parent b08a3fe commit 30c70fd

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

palette/moreland/convert.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ type rgb struct {
1717
// cieXYZ returns a CIE XYZ color representation of the receiver.
1818
func (c rgb) cieXYZ() cieXYZ {
1919
return cieXYZ{
20-
X: 0.4124*c.R + 0.3576*c.G + 0.1805*c.B,
21-
Y: 0.2126*c.R + 0.7152*c.G + 0.0722*c.B,
22-
Z: 0.0193*c.R + 0.1192*c.G + 0.9505*c.B,
20+
X: float64(0.4124*c.R) + float64(0.3576*c.G) + float64(.1805*c.B),
21+
Y: float64(0.2126*c.R) + float64(0.7152*c.G) + float64(.0722*c.B),
22+
Z: float64(0.0193*c.R) + float64(0.1192*c.G) + float64(.9505*c.B),
2323
}
2424
}
2525

@@ -29,7 +29,7 @@ func (c rgb) sRGBA(alpha float64) sRGBA {
2929
// f converts from a linear RGB component to an sRGB component.
3030
f := func(v float64) float64 {
3131
if v > 0.0031308 {
32-
return 1.055*math.Pow(v, 1/2.4) - 0.055
32+
return float64(1.055*math.Pow(v, 1/2.4)) - 0.055
3333
}
3434
return 12.92 * v
3535
}
@@ -51,9 +51,9 @@ type cieXYZ struct {
5151
// rgb returns a linear RGB representation of the receiver.
5252
func (c cieXYZ) rgb() rgb {
5353
return rgb{
54-
R: c.X*3.2406 + c.Y*-1.5372 + c.Z*-0.4986,
55-
G: c.X*-0.9689 + c.Y*1.8758 + c.Z*0.0415,
56-
B: c.X*0.0557 + c.Y*-0.204 + c.Z*1.057,
54+
R: float64(c.X*3.2406) + float64(c.Y*-1.5372) + float64(c.Z*-0.4986),
55+
G: float64(c.X*-0.9689) + float64(c.Y*1.8758) + float64(c.Z*0.0415),
56+
B: float64(c.X*0.0557) + float64(c.Y*-0.204) + float64(c.Z*1.057),
5757
}
5858
}
5959

@@ -64,14 +64,14 @@ func (c cieXYZ) cieLAB() cieLAB {
6464
if v > 0.008856 {
6565
return math.Pow(v, 1.0/3.0)
6666
}
67-
return 7.787*v + 16.0/116.0
67+
return float64(7.787*v) + float64(16.0/116.0)
6868
}
6969

7070
tempX := f(c.X / 0.9505)
7171
tempY := f(c.Y)
7272
tempZ := f(c.Z / 1.089)
7373
return cieLAB{
74-
L: (116.0 * tempY) - 16.0,
74+
L: float64(116.0*tempY) - 16.0,
7575
A: 500.0 * (tempX - tempY),
7676
B: 200 * (tempY - tempZ),
7777
}

palette/moreland/luminance.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ func (l *luminance) At(v float64) (color.Color, error) {
9595
c2 := l.colors[i]
9696
frac := (scalar - l.scalars[i-1]) / (l.scalars[i] - l.scalars[i-1])
9797
o := cieLAB{
98-
L: frac*(c2.L-c1.L) + c1.L,
99-
A: frac*(c2.A-c1.A) + c1.A,
100-
B: frac*(c2.B-c1.B) + c1.B,
98+
L: float64(frac*(c2.L-c1.L)) + float64(c1.L),
99+
A: float64(frac*(c2.A-c1.A)) + float64(c1.A),
100+
B: float64(frac*(c2.B-c1.B)) + float64(c1.B),
101101
}.cieXYZ().rgb().sRGBA(l.alpha)
102102
o.clamp()
103103
return o, nil
@@ -179,7 +179,7 @@ func (l luminance) Palette(n int) palette.Palette {
179179
var v float64
180180
c := make([]color.Color, n)
181181
for i := 0; i < n; i++ {
182-
v = l.min + delta*float64(i)
182+
v = l.min + float64(delta*float64(i))
183183
var err error
184184
c[i], err = l.At(v)
185185
if err != nil {

palette/moreland/smooth.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,20 @@ func (p *smoothDiverging) interpolateMSHDiverging(scalar, convergePoint float64)
145145
// interpolation factor
146146
interp := scalar / convergePoint
147147
return msh{
148-
M: (p.convergeM-p.start.M)*interp + p.start.M,
148+
M: float64((p.convergeM-p.start.M)*interp) + p.start.M,
149149
S: p.start.S * (1 - interp),
150-
H: p.start.H + startHTwist*interp,
150+
H: p.start.H + float64(startHTwist*interp),
151151
}
152152
}
153153
// interpolation factors
154154
interp1 := (scalar - 1) / (convergePoint - 1)
155155
interp2 := (scalar/convergePoint - 1)
156156
var H float64
157157
if scalar > convergePoint {
158-
H = p.end.H + endHTwist*interp1
158+
H = p.end.H + float64(endHTwist*interp1)
159159
}
160160
return msh{
161-
M: (p.convergeM-p.end.M)*interp1 + p.end.M,
161+
M: float64((p.convergeM-p.end.M)*interp1) + p.end.M,
162162
S: p.end.S * interp2,
163163
H: H,
164164
}
@@ -173,7 +173,7 @@ func (p smoothDiverging) Palette(n int) palette.Palette {
173173
delta := (p.max - p.min) / float64(n-1)
174174
c := make([]color.Color, n)
175175
for i := range c {
176-
v := p.min + delta*float64(i)
176+
v := p.min + float64(delta*float64(i))
177177
var err error
178178
c[i], err = p.At(v)
179179
if err != nil {

0 commit comments

Comments
 (0)