MCPcopy
hub / github.com/tdewolff/canvas / BenchmarkToRasterizer

Function BenchmarkToRasterizer

path_test.go:959–992  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

957}
958
959func BenchmarkToRasterizer(b *testing.B) {
960 res := DPMM(10.0)
961 data, err := os.ReadFile("resources/netherlands.path")
962 if err != nil {
963 panic(err)
964 }
965 p, err := ParseSVGPath(string(data))
966 if err != nil {
967 panic(err)
968 }
969 bounds := p.FastBounds()
970 p = p.Transform(Identity.Scale(1.0, -1.0).Translate(-bounds.X0, -bounds.Y1))
971
972 w, h := math.Ceil(float64(res)*bounds.W()), math.Ceil(float64(res)*bounds.H())
973 rect := image.Rect(0, 0, int(w), int(h))
974 img := image.NewRGBA(rect)
975 ras := &vector.Rasterizer{}
976 ras.Reset(int(w), int(h))
977
978 src := image.NewUniform(image.Black)
979 p.ToVectorRasterizer(ras, res)
980 ras.Draw(img, rect, src, image.Point{0, 0})
981
982 f, _ := os.Create("ToRasterizer.png")
983 defer f.Close()
984 (&png.Encoder{}).Encode(f, img)
985
986 b.ResetTimer()
987 for i := 0; i < b.N; i++ {
988 ras.Reset(int(w), int(h))
989 p.ToVectorRasterizer(ras, res)
990 ras.Draw(img, rect, src, image.Point{0, 0})
991 }
992}
993
994func BenchmarkToScanx(b *testing.B) {
995 res := DPMM(10.0)

Callers

nothing calls this directly

Calls 13

DPMMFunction · 0.85
ParseSVGPathFunction · 0.85
FastBoundsMethod · 0.80
WMethod · 0.80
HMethod · 0.80
ToVectorRasterizerMethod · 0.80
TransformMethod · 0.65
DrawMethod · 0.65
EncodeMethod · 0.65
TranslateMethod · 0.45
ScaleMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected