move mask invert out
This commit is contained in:
parent
cf81556100
commit
8a07e3cf9b
2 changed files with 20 additions and 10 deletions
|
@ -213,17 +213,15 @@ proc getValueSmooth*(mask: Mask, x, y: float32): uint8 {.raises: [].} =
|
||||||
|
|
||||||
proc invert*(mask: Mask) {.raises: [].} =
|
proc invert*(mask: Mask) {.raises: [].} =
|
||||||
## Inverts all of the values - creates a negative of the mask.
|
## Inverts all of the values - creates a negative of the mask.
|
||||||
var i: int
|
when allowSimd and compiles(invertImageSimd):
|
||||||
when defined(amd64) and allowSimd:
|
invertMaskSimd(
|
||||||
let vec255 = mm_set1_epi8(255)
|
cast[ptr UncheckedArray[uint8]](mask.data[0].addr),
|
||||||
for _ in 0 ..< mask.data.len div 16:
|
mask.data.len
|
||||||
var values = mm_loadu_si128(mask.data[i].addr)
|
)
|
||||||
values = mm_sub_epi8(vec255, values)
|
return
|
||||||
mm_storeu_si128(mask.data[i].addr, values)
|
|
||||||
i += 16
|
|
||||||
|
|
||||||
for j in i ..< mask.data.len:
|
for i in 0 ..< mask.data.len:
|
||||||
mask.data[j] = 255 - mask.data[j]
|
mask.data[i] = 255 - mask.data[i]
|
||||||
|
|
||||||
proc spread*(mask: Mask, spread: float32) {.raises: [PixieError].} =
|
proc spread*(mask: Mask, spread: float32) {.raises: [PixieError].} =
|
||||||
## Grows the mask by spread.
|
## Grows the mask by spread.
|
||||||
|
|
|
@ -255,3 +255,15 @@ when defined(amd64):
|
||||||
data[i] = rgbx
|
data[i] = rgbx
|
||||||
|
|
||||||
toPremultipliedAlphaSimd(cast[ptr UncheckedArray[uint32]](data), len)
|
toPremultipliedAlphaSimd(cast[ptr UncheckedArray[uint32]](data), len)
|
||||||
|
|
||||||
|
proc invertMaskSimd*(data: ptr UncheckedArray[uint8], len: int) =
|
||||||
|
var i: int
|
||||||
|
let vec255 = mm_set1_epi8(255)
|
||||||
|
for _ in 0 ..< len div 16:
|
||||||
|
var values = mm_loadu_si128(data[i].addr)
|
||||||
|
values = mm_sub_epi8(vec255, values)
|
||||||
|
mm_storeu_si128(data[i].addr, values)
|
||||||
|
i += 16
|
||||||
|
|
||||||
|
for j in i ..< len:
|
||||||
|
data[j] = 255 - data[j]
|
||||||
|
|
Loading…
Reference in a new issue