better cairo benchmark
This commit is contained in:
parent
943961677b
commit
0f3b0712b5
2 changed files with 109 additions and 69 deletions
|
@ -1,96 +1,141 @@
|
||||||
import benchy, cairo, chroma, math, pixie
|
import benchy, cairo, chroma, math, pixie, pixie/paths {.all.}, strformat
|
||||||
|
|
||||||
|
proc doDiff(a, b: Image, name: string) =
|
||||||
|
let (diffScore, diffImage) = diff(a, b)
|
||||||
|
echo &"{name} score: {diffScore}"
|
||||||
|
diffImage.writeFile(&"{name}_diff.png")
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.moveTo(0, 0)
|
||||||
|
path.lineTo(1920, 0)
|
||||||
|
path.lineTo(1920, 1080)
|
||||||
|
path.lineTo(0, 1080)
|
||||||
|
path.closePath()
|
||||||
|
|
||||||
|
let shapes = path.commandsToShapes(true, 1)
|
||||||
|
|
||||||
let
|
let
|
||||||
surface = imageSurfaceCreate(FORMAT_ARGB32, 1920, 1080)
|
surface = imageSurfaceCreate(FORMAT_ARGB32, 1920, 1080)
|
||||||
ctx = surface.create()
|
ctx = surface.create()
|
||||||
|
|
||||||
ctx.setSourceRgba(0, 0, 1, 1)
|
ctx.setSourceRgba(0, 0, 1, 1)
|
||||||
|
|
||||||
timeIt "cairo1":
|
timeIt "cairo1":
|
||||||
ctx.newPath()
|
ctx.newPath()
|
||||||
ctx.moveTo(0, 0)
|
ctx.moveTo(shapes[0][0].x, shapes[0][0].y)
|
||||||
ctx.lineTo(1920, 0)
|
for shape in shapes:
|
||||||
ctx.lineTo(1920, 1080)
|
for v in shape:
|
||||||
ctx.lineTo(0, 1080)
|
ctx.lineTo(v.x, v.y)
|
||||||
ctx.closePath()
|
|
||||||
ctx.fill()
|
ctx.fill()
|
||||||
surface.flush()
|
surface.flush()
|
||||||
|
|
||||||
# discard surface.writeToPng("cairo1.png")
|
# discard surface.writeToPng("cairo1.png")
|
||||||
|
|
||||||
let a = newImage(1920, 1080)
|
let a = newImage(1920, 1080)
|
||||||
a.fill(rgba(255, 255, 255, 255))
|
|
||||||
|
|
||||||
timeIt "pixie1":
|
timeIt "pixie1":
|
||||||
let p = newPath()
|
let p = newPath()
|
||||||
p.moveTo(0, 0)
|
p.moveTo(shapes[0][0])
|
||||||
p.lineTo(1920, 0)
|
for shape in shapes:
|
||||||
p.lineTo(1920, 1080)
|
for v in shape:
|
||||||
p.lineTo(0, 1080)
|
p.lineTo(v)
|
||||||
p.closePath()
|
|
||||||
a.fillPath(p, rgba(0, 0, 255, 255))
|
a.fillPath(p, rgba(0, 0, 255, 255))
|
||||||
|
|
||||||
# a.writeFile("pixie1.png")
|
# a.writeFile("pixie1.png")
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
let path = newPath()
|
||||||
|
path.moveTo(500, 240)
|
||||||
|
path.lineTo(1500, 240)
|
||||||
|
path.lineTo(1920, 600)
|
||||||
|
path.lineTo(0, 600)
|
||||||
|
path.closePath()
|
||||||
|
|
||||||
|
let shapes = path.commandsToShapes(true, 1)
|
||||||
|
|
||||||
let
|
let
|
||||||
surface = imageSurfaceCreate(FORMAT_ARGB32, 1920, 1080)
|
surface = imageSurfaceCreate(FORMAT_ARGB32, 1920, 1080)
|
||||||
ctx = surface.create()
|
ctx = surface.create()
|
||||||
|
|
||||||
ctx.setSourceRgba(0, 0, 1, 1)
|
|
||||||
|
|
||||||
timeIt "cairo2":
|
timeIt "cairo2":
|
||||||
|
ctx.setSourceRgba(1, 1, 1, 1)
|
||||||
|
let operator = ctx.getOperator()
|
||||||
|
ctx.setOperator(OperatorSource)
|
||||||
|
ctx.paint()
|
||||||
|
ctx.setOperator(operator)
|
||||||
|
|
||||||
|
ctx.setSourceRgba(0, 0, 1, 1)
|
||||||
|
|
||||||
ctx.newPath()
|
ctx.newPath()
|
||||||
ctx.moveTo(500, 240)
|
ctx.moveTo(shapes[0][0].x, shapes[0][0].y)
|
||||||
ctx.lineTo(1500, 240)
|
for shape in shapes:
|
||||||
ctx.lineTo(1920, 600)
|
for v in shape:
|
||||||
ctx.lineTo(0, 600)
|
ctx.lineTo(v.x, v.y)
|
||||||
ctx.closePath()
|
|
||||||
ctx.fill()
|
ctx.fill()
|
||||||
surface.flush()
|
surface.flush()
|
||||||
|
|
||||||
# discard surface.writeToPng("cairo2.png")
|
# discard surface.writeToPng("cairo2.png")
|
||||||
|
|
||||||
let a = newImage(1920, 1080)
|
let a = newImage(1920, 1080)
|
||||||
a.fill(rgba(255, 255, 255, 255))
|
|
||||||
|
|
||||||
timeIt "pixie2":
|
timeIt "pixie2":
|
||||||
|
a.fill(rgba(255, 255, 255, 255))
|
||||||
|
|
||||||
let p = newPath()
|
let p = newPath()
|
||||||
p.moveTo(500, 240)
|
p.moveTo(shapes[0][0])
|
||||||
p.lineTo(1500, 240)
|
for shape in shapes:
|
||||||
p.lineTo(1920, 600)
|
for v in shape:
|
||||||
p.lineTo(0, 600)
|
p.lineTo(v)
|
||||||
p.closePath()
|
|
||||||
a.fillPath(p, rgba(0, 0, 255, 255))
|
a.fillPath(p, rgba(0, 0, 255, 255))
|
||||||
|
|
||||||
# a.writeFile("pixie2.png")
|
# a.writeFile("pixie2.png")
|
||||||
|
|
||||||
# block:
|
block:
|
||||||
# let
|
let path = parsePath("""
|
||||||
# a = imageSurfaceCreate(FORMAT_ARGB32, 1000, 1000)
|
M 100,300
|
||||||
# b = imageSurfaceCreate(FORMAT_ARGB32, 500, 500)
|
A 200,200 0,0,1 500,300
|
||||||
# ac = a.create()
|
A 200,200 0,0,1 900,300
|
||||||
# bc = b.create()
|
Q 900,600 500,900
|
||||||
|
Q 100,600 100,300 z
|
||||||
|
""")
|
||||||
|
|
||||||
# ac.setSourceRgba(1, 0, 0, 1)
|
let shapes = path.commandsToShapes(true, 1)
|
||||||
# ac.newPath()
|
|
||||||
# ac.rectangle(0, 0, 1000, 1000)
|
|
||||||
# ac.fill()
|
|
||||||
|
|
||||||
# bc.setSourceRgba(0, 1, 0, 1)
|
let
|
||||||
# bc.newPath()
|
surface = imageSurfaceCreate(FORMAT_ARGB32, 1000, 1000)
|
||||||
# bc.rectangle(0, 0, 500, 500)
|
ctx = surface.create()
|
||||||
# bc.fill()
|
|
||||||
|
|
||||||
# let pattern = patternCreateForSurface(b)
|
timeIt "cairo3":
|
||||||
|
ctx.setSourceRgba(1, 1, 1, 1)
|
||||||
|
let operator = ctx.getOperator()
|
||||||
|
ctx.setOperator(OperatorSource)
|
||||||
|
ctx.paint()
|
||||||
|
ctx.setOperator(operator)
|
||||||
|
|
||||||
# timeIt "a":
|
ctx.setSourceRgba(1, 0, 0, 1)
|
||||||
# ac.setSource(pattern)
|
|
||||||
# ac.save()
|
|
||||||
# ac.translate(25.2, 25.2)
|
|
||||||
# ac.rectangle(0, 0, 500, 500)
|
|
||||||
# ac.fill()
|
|
||||||
# ac.restore()
|
|
||||||
|
|
||||||
# discard a.writeToPng("a.png")
|
ctx.newPath()
|
||||||
|
ctx.moveTo(shapes[0][0].x, shapes[0][0].y)
|
||||||
|
for shape in shapes:
|
||||||
|
for v in shape:
|
||||||
|
ctx.lineTo(v.x, v.y)
|
||||||
|
ctx.fill()
|
||||||
|
surface.flush()
|
||||||
|
|
||||||
|
# discard surface.writeToPng("cairo3.png")
|
||||||
|
|
||||||
|
let a = newImage(1000, 1000)
|
||||||
|
|
||||||
|
timeIt "pixie3":
|
||||||
|
a.fill(rgba(255, 255, 255, 255))
|
||||||
|
|
||||||
|
let p = newPath()
|
||||||
|
p.moveTo(shapes[0][0])
|
||||||
|
for shape in shapes:
|
||||||
|
for v in shape:
|
||||||
|
p.lineTo(v)
|
||||||
|
a.fillPath(p, rgba(255, 0, 0, 255))
|
||||||
|
|
||||||
|
# a.writeFile("pixie3.png")
|
||||||
|
|
||||||
|
# doDiff(readImage("cairo3.png"), a, "cairo3")
|
||||||
|
|
|
@ -1136,23 +1136,18 @@ proc maxEntryCount(partitioning: Partitioning): int =
|
||||||
for i in 0 ..< partitioning.partitions.len:
|
for i in 0 ..< partitioning.partitions.len:
|
||||||
result = max(result, partitioning.partitions[i].len)
|
result = max(result, partitioning.partitions[i].len)
|
||||||
|
|
||||||
proc insertionSort(
|
proc sortHits(hits: var seq[(float32, int16)], inl, inr: int) =
|
||||||
hits: var seq[(float32, int16)], lo, hi: int
|
|
||||||
) {.inline.} =
|
|
||||||
for i in lo + 1 .. hi:
|
|
||||||
var
|
|
||||||
j = i - 1
|
|
||||||
k = i
|
|
||||||
while j >= 0 and hits[j][0] > hits[k][0]:
|
|
||||||
swap(hits[j + 1], hits[j])
|
|
||||||
dec j
|
|
||||||
dec k
|
|
||||||
|
|
||||||
proc sort(hits: var seq[(float32, int16)], inl, inr: int) =
|
|
||||||
## Quicksort + insertion sort, in-place and faster than standard lib sort.
|
## Quicksort + insertion sort, in-place and faster than standard lib sort.
|
||||||
let n = inr - inl + 1
|
let n = inr - inl + 1
|
||||||
if n < 32:
|
if n < 32: # Use insertion sort for the rest
|
||||||
insertionSort(hits, inl, inr)
|
for i in inl + 1 .. inr:
|
||||||
|
var
|
||||||
|
j = i - 1
|
||||||
|
k = i
|
||||||
|
while j >= 0 and hits[j][0] > hits[k][0]:
|
||||||
|
swap(hits[j + 1], hits[j])
|
||||||
|
dec j
|
||||||
|
dec k
|
||||||
return
|
return
|
||||||
var
|
var
|
||||||
l = inl
|
l = inl
|
||||||
|
@ -1167,8 +1162,8 @@ proc sort(hits: var seq[(float32, int16)], inl, inr: int) =
|
||||||
swap(hits[l], hits[r])
|
swap(hits[l], hits[r])
|
||||||
inc l
|
inc l
|
||||||
dec r
|
dec r
|
||||||
sort(hits, inl, r)
|
sortHits(hits, inl, r)
|
||||||
sort(hits, l, inr)
|
sortHits(hits, l, inr)
|
||||||
|
|
||||||
proc shouldFill(
|
proc shouldFill(
|
||||||
windingRule: WindingRule, count: int
|
windingRule: WindingRule, count: int
|
||||||
|
@ -1258,7 +1253,7 @@ proc computeCoverage(
|
||||||
inc numHits
|
inc numHits
|
||||||
|
|
||||||
if numHits > 0:
|
if numHits > 0:
|
||||||
sort(hits, 0, numHits - 1)
|
sortHits(hits, 0, numHits - 1)
|
||||||
|
|
||||||
if aa:
|
if aa:
|
||||||
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, width):
|
for (prevAt, at, count) in hits.walk(numHits, windingRule, y, width):
|
||||||
|
@ -1991,7 +1986,7 @@ proc overlaps(
|
||||||
if segment.to != at:
|
if segment.to != at:
|
||||||
hits.add((at.x, winding))
|
hits.add((at.x, winding))
|
||||||
|
|
||||||
sort(hits, 0, hits.high)
|
sortHits(hits, 0, hits.high)
|
||||||
|
|
||||||
var count: int
|
var count: int
|
||||||
for (at, winding) in hits:
|
for (at, winding) in hits:
|
||||||
|
|
Loading…
Reference in a new issue