mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
internal/f32color: optimize LinearFromSRGB
Previously each call was ~100ns, the new implementation is ~1ns. Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
@@ -36,3 +36,23 @@ func TestLinearToRGBARoundtrip(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sink RGBA
|
||||
|
||||
func BenchmarkLinearFromSRGB(b *testing.B) {
|
||||
b.Run("opaque", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0xFF})
|
||||
}
|
||||
})
|
||||
b.Run("translucent", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0x50})
|
||||
}
|
||||
})
|
||||
b.Run("transparent", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
sink = LinearFromSRGB(color.NRGBA{R: byte(i), G: byte(i >> 8), B: byte(i >> 16), A: 0x00})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user