This commit is contained in:
Ryan Oldenburg 2022-07-31 19:28:05 -05:00
parent e107f85fb0
commit 31bd588b17
2 changed files with 7 additions and 14 deletions

View file

@ -507,18 +507,10 @@ proc magnifyBy2Sse2*(image: Image, power = 1): Image {.simd.} =
result.width * 4 result.width * 4
) )
proc applyCoverage*(rgbxVec, coverage: M128i): M128i {.inline.} = template applyCoverage*(rgbxVec, coverage: M128i): M128i =
## Unpack the first 4 coverage bytes.
proc unpackAlphaValues(v: M128i): M128i {.inline.} = var unpacked = mm_unpacklo_epi8(mm_setzero_si128(), coverage)
## Unpack the first 32 bits into 4 rgba(0, 0, 0, value). unpacked = mm_unpacklo_epi8(mm_setzero_si128(), unpacked)
result = mm_unpacklo_epi8(mm_setzero_si128(), v)
result = mm_unpacklo_epi8(mm_setzero_si128(), result)
let
oddMask = mm_set1_epi16(0xff00)
div255 = mm_set1_epi16(0x8081)
var unpacked = unpackAlphaValues(coverage)
unpacked = mm_or_si128(unpacked, mm_srli_epi32(unpacked, 16)) unpacked = mm_or_si128(unpacked, mm_srli_epi32(unpacked, 16))
var var
@ -548,6 +540,8 @@ proc blendLineCoverageOverwriteSse2*(
rgbxVec = mm_set1_epi32(cast[uint32](rgbx)) rgbxVec = mm_set1_epi32(cast[uint32](rgbx))
vecZero = mm_setzero_si128() vecZero = mm_setzero_si128()
vec255 = mm_set1_epi8(255) vec255 = mm_set1_epi8(255)
oddMask = mm_set1_epi16(0xff00)
div255 = mm_set1_epi16(0x8081)
while i < len - 16: while i < len - 16:
let let
coverage = mm_loadu_si128(coverages[i].addr) coverage = mm_loadu_si128(coverages[i].addr)

View file

@ -5,8 +5,7 @@ const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis in q
var font = readFont("tests/fonts/Roboto-Regular_1.ttf") var font = readFont("tests/fonts/Roboto-Regular_1.ttf")
font.size = 16 font.size = 16
let let image = newImage(500, 300)
image = newImage(500, 300)
timeIt "typeset": timeIt "typeset":
discard font.typeset(text, bounds = vec2(image.width.float32, 0)) discard font.typeset(text, bounds = vec2(image.width.float32, 0))