Merge pull request #333 from guzba/master

add dragon2 test
This commit is contained in:
treeform 2021-12-03 13:46:51 -08:00 committed by GitHub
commit 8cf2339090
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 1392 additions and 12 deletions

View file

@ -151,12 +151,6 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx =
if opacity.len > 0:
result.opacity = clamp(parseFloat(opacity), 0, 1)
if fillOpacity.len > 0:
result.fill.opacity = clamp(parseFloat(fillOpacity), 0, 1)
if strokeOpacity.len > 0:
result.strokeOpacity = clamp(parseFloat(strokeOpacity), 0, 1)
if fillRule == "":
discard # Inherit
elif fillRule == "nonzero":
@ -197,6 +191,12 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx =
result.stroke = parseHtmlColor(stroke).rgbx
result.shouldStroke = true
if fillOpacity.len > 0:
result.fill.opacity = parseFloat(fillOpacity).clamp(0, 1)
if strokeOpacity.len > 0:
result.strokeOpacity = parseFloat(strokeOpacity).clamp(0, 1)
if strokeWidth == "":
discard # Inherit
else:

View file

@ -62,7 +62,7 @@ proc getRgbaUnsafe*(image: Image, x, y: int): ColorRGBX {.inline, raises: [].} =
## Gets a color from (x, y) coordinates.
## * No bounds checking *
## Make sure that x, y are in bounds.
## Failure in the assumptions will case unsafe memory reads.
## Failure in the assumptions will cause unsafe memory reads.
result = image.data[image.width * y + x]
proc `[]`*(image: Image, x, y: int): ColorRGBX {.inline, raises: [].} =
@ -80,7 +80,7 @@ proc setRgbaUnsafe*(
## Sets a color from (x, y) coordinates.
## * No bounds checking *
## Make sure that x, y are in bounds.
## Failure in the assumptions will case unsafe memory writes.
## Failure in the assumptions will cause unsafe memory writes.
image.data[image.dataIndex(x, y)] = color.asRgbx()
proc `[]=`*(image: Image, x, y: int, color: SomeColor) {.inline, raises: [].} =
@ -133,7 +133,7 @@ proc isOneColor*(image: Image): bool {.raises: [].} =
## Checks if the entire image is the same color.
result = true
let color = image.getRgbaUnsafe(0, 0)
let color = image.data[0]
var i: int
when defined(amd64) and not defined(pixieNoSimd):
@ -419,6 +419,7 @@ proc applyOpacity*(target: Image | Mask, opacity: float32) {.raises: [].} =
let
oddMask = mm_set1_epi16(cast[int16](0xff00))
div255 = mm_set1_epi16(cast[int16](0x8081))
zeroVec = mm_setzero_si128()
opacityVec = mm_slli_epi16(mm_set1_epi16(cast[int16](opacity)), 8)
for _ in 0 ..< byteLen div 16:
when type(target) is Image:
@ -428,8 +429,7 @@ proc applyOpacity*(target: Image | Mask, opacity: float32) {.raises: [].} =
let values = mm_loadu_si128(target.data[index].addr)
let eqZero = mm_cmpeq_epi16(values, mm_setzero_si128())
if mm_movemask_epi8(eqZero) != 0xffff:
if mm_movemask_epi8(mm_cmpeq_epi16(values, zeroVec)) != 0xffff:
var
valuesEven = mm_slli_epi16(mm_andnot_si128(oddMask, values), 8)
valuesOdd = mm_and_si128(values, oddMask)

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 705 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

View file

@ -13,7 +13,8 @@ const files = [
"Ghostscript_Tiger",
"scale",
"miterlimit",
"dashes"
"dashes",
"dragon2"
]
proc doDiff(rendered: Image, name: string) =