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:
Egon Elbre
2022-07-01 22:09:16 +03:00
committed by Elias Naur
parent 2adf4efcbd
commit 3670f70c01
4 changed files with 109 additions and 3 deletions
+20
View File
@@ -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})
}
})
}