simplify
This commit is contained in:
parent
a4fbb5365e
commit
23deffc761
1 changed files with 32 additions and 34 deletions
|
@ -46,10 +46,6 @@ type
|
||||||
requiresAntiAliasing: bool
|
requiresAntiAliasing: bool
|
||||||
bottom: int
|
bottom: int
|
||||||
|
|
||||||
Partitioning = object
|
|
||||||
partitions: seq[Partition]
|
|
||||||
startY, partitionHeight: uint32
|
|
||||||
|
|
||||||
Fixed32 = int32 ## 24.8 fixed point
|
Fixed32 = int32 ## 24.8 fixed point
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -1123,49 +1119,51 @@ proc requiresAntiAliasing(entries: var seq[PartitionEntry]): bool =
|
||||||
|
|
||||||
proc partitionSegments(
|
proc partitionSegments(
|
||||||
segments: seq[(Segment, int16)], top, height: int
|
segments: seq[(Segment, int16)], top, height: int
|
||||||
): Partitioning =
|
): seq[Partition] =
|
||||||
## Puts segments into the height partitions they intersect with.
|
## Puts segments into the height partitions they intersect with.
|
||||||
let
|
let
|
||||||
maxPartitions = max(1, height div 4).uint32
|
maxPartitions = max(1, height div 4).uint32
|
||||||
numPartitions = min(maxPartitions, max(1, segments.len div 2).uint32)
|
numPartitions = min(maxPartitions, max(1, segments.len div 2).uint32)
|
||||||
|
|
||||||
result.partitions.setLen(numPartitions)
|
result.setLen(numPartitions)
|
||||||
result.startY = top.uint32
|
|
||||||
result.partitionHeight = height.uint32 div numPartitions
|
let
|
||||||
|
startY = top.uint32
|
||||||
|
partitionHeight = height.uint32 div numPartitions
|
||||||
|
|
||||||
for (segment, winding) in segments:
|
for (segment, winding) in segments:
|
||||||
var entry = initPartitionEntry(segment, winding)
|
var entry = initPartitionEntry(segment, winding)
|
||||||
if result.partitionHeight == 0:
|
if partitionHeight == 0:
|
||||||
result.partitions[0].entries.add(move entry)
|
result[0].entries.add(move entry)
|
||||||
else:
|
else:
|
||||||
var
|
var
|
||||||
atPartition = max(0, segment.at.y - result.startY.float32).uint32
|
atPartition = max(0, segment.at.y - startY.float32).uint32
|
||||||
toPartition = max(0, segment.to.y - result.startY.float32).uint32
|
toPartition = max(0, segment.to.y - startY.float32).uint32
|
||||||
atPartition = atPartition div result.partitionHeight
|
atPartition = atPartition div partitionHeight
|
||||||
toPartition = toPartition div result.partitionHeight
|
toPartition = toPartition div partitionHeight
|
||||||
atPartition = min(atPartition, result.partitions.high.uint32)
|
atPartition = min(atPartition, result.high.uint32)
|
||||||
toPartition = min(toPartition, result.partitions.high.uint32)
|
toPartition = min(toPartition, result.high.uint32)
|
||||||
for i in atPartition .. toPartition:
|
for i in atPartition .. toPartition:
|
||||||
result.partitions[i].entries.add(entry)
|
result[i].entries.add(entry)
|
||||||
|
|
||||||
# Set the bottom values for the partitions (y value where this partition ends)
|
# Set the bottom values for the partitions (y value where this partition ends)
|
||||||
|
|
||||||
var partitionBottom = top + result.partitionHeight.int
|
var partitionBottom = top + partitionHeight.int
|
||||||
|
|
||||||
for partition in result.partitions.mitems:
|
for partition in result.mitems:
|
||||||
partition.bottom = partitionBottom
|
partition.bottom = partitionBottom
|
||||||
partition.requiresAntiAliasing =
|
partition.requiresAntiAliasing =
|
||||||
requiresAntiAliasing(partition.entries)
|
requiresAntiAliasing(partition.entries)
|
||||||
partitionBottom += result.partitionHeight.int
|
partitionBottom += partitionHeight.int
|
||||||
|
|
||||||
# Ensure the final partition goes to the actual bottom
|
# Ensure the final partition goes to the actual bottom
|
||||||
# This is needed since the final partition includes
|
# This is needed since the final partition includes
|
||||||
# height - (height div numPartitions) * numPartitions
|
# height - (height div numPartitions) * numPartitions
|
||||||
result.partitions[^1].bottom = top + height
|
result[^1].bottom = top + height
|
||||||
|
|
||||||
proc maxEntryCount(partitioning: var Partitioning): int =
|
proc maxEntryCount(partitions: var seq[Partition]): int =
|
||||||
for i in 0 ..< partitioning.partitions.len:
|
for i in 0 ..< partitions.len:
|
||||||
result = max(result, partitioning.partitions[i].entries.len)
|
result = max(result, partitions[i].entries.len)
|
||||||
|
|
||||||
proc fixed32(f: float32): Fixed32 {.inline.} =
|
proc fixed32(f: float32): Fixed32 {.inline.} =
|
||||||
Fixed32(f * 256)
|
Fixed32(f * 256)
|
||||||
|
@ -1256,14 +1254,14 @@ proc computeCoverage(
|
||||||
aa: var bool,
|
aa: var bool,
|
||||||
width: int,
|
width: int,
|
||||||
y, startX: int,
|
y, startX: int,
|
||||||
partitioning: var Partitioning,
|
partitions: var seq[Partition],
|
||||||
partitionIndex: var int,
|
partitionIndex: var int,
|
||||||
windingRule: WindingRule
|
windingRule: WindingRule
|
||||||
) {.inline.} =
|
) {.inline.} =
|
||||||
if y >= partitioning.partitions[partitionIndex].bottom:
|
if y >= partitions[partitionIndex].bottom:
|
||||||
inc partitionIndex
|
inc partitionIndex
|
||||||
|
|
||||||
aa = partitioning.partitions[partitionIndex].requiresAntiAliasing
|
aa = partitions[partitionIndex].requiresAntiAliasing
|
||||||
|
|
||||||
let
|
let
|
||||||
quality = if aa: 5 else: 1 # Must divide 255 cleanly (1, 3, 5, 15, 17, 51, 85)
|
quality = if aa: 5 else: 1 # Must divide 255 cleanly (1, 3, 5, 15, 17, 51, 85)
|
||||||
|
@ -1275,7 +1273,7 @@ proc computeCoverage(
|
||||||
for m in 0 ..< quality:
|
for m in 0 ..< quality:
|
||||||
yLine += offset
|
yLine += offset
|
||||||
numHits = 0
|
numHits = 0
|
||||||
for entry in partitioning.partitions[partitionIndex].entries.mitems:
|
for entry in partitions[partitionIndex].entries.mitems:
|
||||||
if entry.segment.at.y <= yLine and entry.segment.to.y >= yLine:
|
if entry.segment.at.y <= yLine and entry.segment.to.y >= yLine:
|
||||||
let x =
|
let x =
|
||||||
if entry.m == 0:
|
if entry.m == 0:
|
||||||
|
@ -1800,10 +1798,10 @@ proc fillShapes(
|
||||||
raise newException(PixieError, "Path int overflow detected")
|
raise newException(PixieError, "Path int overflow detected")
|
||||||
|
|
||||||
var
|
var
|
||||||
partitioning = partitionSegments(segments, startY, pathHeight - startY)
|
partitions = partitionSegments(segments, startY, pathHeight - startY)
|
||||||
partitionIndex: int
|
partitionIndex: int
|
||||||
coverages = newSeq[uint8](pathWidth)
|
coverages = newSeq[uint8](pathWidth)
|
||||||
hits = newSeq[(Fixed32, int16)](partitioning.maxEntryCount)
|
hits = newSeq[(Fixed32, int16)](partitions.maxEntryCount)
|
||||||
numHits: int
|
numHits: int
|
||||||
aa: bool
|
aa: bool
|
||||||
|
|
||||||
|
@ -1816,7 +1814,7 @@ proc fillShapes(
|
||||||
image.width,
|
image.width,
|
||||||
y,
|
y,
|
||||||
startX,
|
startX,
|
||||||
partitioning,
|
partitions,
|
||||||
partitionIndex,
|
partitionIndex,
|
||||||
windingRule
|
windingRule
|
||||||
)
|
)
|
||||||
|
@ -1871,10 +1869,10 @@ proc fillShapes(
|
||||||
raise newException(PixieError, "Path int overflow detected")
|
raise newException(PixieError, "Path int overflow detected")
|
||||||
|
|
||||||
var
|
var
|
||||||
partitioning = partitionSegments(segments, startY, pathHeight)
|
partitions = partitionSegments(segments, startY, pathHeight)
|
||||||
partitionIndex: int
|
partitionIndex: int
|
||||||
coverages = newSeq[uint8](pathWidth)
|
coverages = newSeq[uint8](pathWidth)
|
||||||
hits = newSeq[(Fixed32, int16)](partitioning.maxEntryCount)
|
hits = newSeq[(Fixed32, int16)](partitions.maxEntryCount)
|
||||||
numHits: int
|
numHits: int
|
||||||
aa: bool
|
aa: bool
|
||||||
|
|
||||||
|
@ -1887,7 +1885,7 @@ proc fillShapes(
|
||||||
mask.width,
|
mask.width,
|
||||||
y,
|
y,
|
||||||
startX,
|
startX,
|
||||||
partitioning,
|
partitions,
|
||||||
partitionIndex,
|
partitionIndex,
|
||||||
windingRule
|
windingRule
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue