diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index 3982508..4b421c8 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -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: diff --git a/src/pixie/images.nim b/src/pixie/images.nim index bae3620..d8737ee 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -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) diff --git a/tests/fileformats/svg/diffs/dragon2.png b/tests/fileformats/svg/diffs/dragon2.png new file mode 100644 index 0000000..18ecc64 Binary files /dev/null and b/tests/fileformats/svg/diffs/dragon2.png differ diff --git a/tests/fileformats/svg/dragon2.svg b/tests/fileformats/svg/dragon2.svg new file mode 100644 index 0000000..e27b53a --- /dev/null +++ b/tests/fileformats/svg/dragon2.svg @@ -0,0 +1,1379 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/fileformats/svg/masters/dragon2.png b/tests/fileformats/svg/masters/dragon2.png new file mode 100644 index 0000000..ef957cc Binary files /dev/null and b/tests/fileformats/svg/masters/dragon2.png differ diff --git a/tests/fileformats/svg/rendered/dragon2.png b/tests/fileformats/svg/rendered/dragon2.png new file mode 100644 index 0000000..5f1b8c5 Binary files /dev/null and b/tests/fileformats/svg/rendered/dragon2.png differ diff --git a/tests/test_svg.nim b/tests/test_svg.nim index e978626..c9f6d43 100644 --- a/tests/test_svg.nim +++ b/tests/test_svg.nim @@ -13,7 +13,8 @@ const files = [ "Ghostscript_Tiger", "scale", "miterlimit", - "dashes" + "dashes", + "dragon2" ] proc doDiff(rendered: Image, name: string) =