This commit is contained in:
Ryan Oldenburg 2021-01-22 18:29:35 -06:00
parent e9d340d6a4
commit 52eb2d2037
2 changed files with 9 additions and 8 deletions

View file

@ -1,4 +1,4 @@
version = "0.0.13" version = "0.0.14"
author = "Andre von Houck and Ryan Oldenburg" author = "Andre von Houck and Ryan Oldenburg"
description = "Full-featured 2d graphics library for Nim." description = "Full-featured 2d graphics library for Nim."
license = "MIT" license = "MIT"

View file

@ -82,7 +82,7 @@ proc fill*(image: Image, rgba: ColorRgba) =
# When supported, SIMD fill until we run out of room. # When supported, SIMD fill until we run out of room.
let m = mm_set1_epi32(cast[int32](rgba)) let m = mm_set1_epi32(cast[int32](rgba))
while i < image.data.len - 4: while i < image.data.len - 4:
mm_store_si128(image.data[i].addr, m) mm_storeu_si128(image.data[i].addr, m)
i += 4 i += 4
else: else:
when sizeof(int) == 8: when sizeof(int) == 8:
@ -99,13 +99,14 @@ proc fill*(image: Image, rgba: ColorRgba) =
proc invert*(image: Image) = proc invert*(image: Image) =
## Inverts all of the colors and alpha. ## Inverts all of the colors and alpha.
let vec255 = mm_set1_epi8(255)
var i: int var i: int
while i < image.data.len - 4: when defined(amd64):
var m = mm_loadu_si128(image.data[i].addr) let vec255 = mm_set1_epi8(255)
m = mm_sub_epi8(vec255, m) while i < image.data.len - 4:
mm_store_si128(image.data[i].addr, m) var m = mm_loadu_si128(image.data[i].addr)
i += 4 m = mm_sub_epi8(vec255, m)
mm_storeu_si128(image.data[i].addr, m)
i += 4
for j in i ..< image.data.len: for j in i ..< image.data.len:
var rgba = image.data[j] var rgba = image.data[j]
rgba.r = 255 - rgba.r rgba.r = 255 - rgba.r