f
This commit is contained in:
parent
f065b18689
commit
bffe8a9839
1 changed files with 4 additions and 4 deletions
|
@ -62,7 +62,7 @@ proc getRgbaUnsafe*(image: Image, x, y: int): ColorRGBX {.inline, raises: [].} =
|
||||||
## Gets a color from (x, y) coordinates.
|
## Gets a color from (x, y) coordinates.
|
||||||
## * No bounds checking *
|
## * No bounds checking *
|
||||||
## Make sure that x, y are in bounds.
|
## 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]
|
result = image.data[image.width * y + x]
|
||||||
|
|
||||||
proc `[]`*(image: Image, x, y: int): ColorRGBX {.inline, raises: [].} =
|
proc `[]`*(image: Image, x, y: int): ColorRGBX {.inline, raises: [].} =
|
||||||
|
@ -80,7 +80,7 @@ proc setRgbaUnsafe*(
|
||||||
## Sets a color from (x, y) coordinates.
|
## Sets a color from (x, y) coordinates.
|
||||||
## * No bounds checking *
|
## * No bounds checking *
|
||||||
## Make sure that x, y are in bounds.
|
## 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()
|
image.data[image.dataIndex(x, y)] = color.asRgbx()
|
||||||
|
|
||||||
proc `[]=`*(image: Image, x, y: int, color: SomeColor) {.inline, raises: [].} =
|
proc `[]=`*(image: Image, x, y: int, color: SomeColor) {.inline, raises: [].} =
|
||||||
|
@ -419,6 +419,7 @@ proc applyOpacity*(target: Image | Mask, opacity: float32) {.raises: [].} =
|
||||||
let
|
let
|
||||||
oddMask = mm_set1_epi16(cast[int16](0xff00))
|
oddMask = mm_set1_epi16(cast[int16](0xff00))
|
||||||
div255 = mm_set1_epi16(cast[int16](0x8081))
|
div255 = mm_set1_epi16(cast[int16](0x8081))
|
||||||
|
zeroVec = mm_setzero_si128()
|
||||||
opacityVec = mm_slli_epi16(mm_set1_epi16(cast[int16](opacity)), 8)
|
opacityVec = mm_slli_epi16(mm_set1_epi16(cast[int16](opacity)), 8)
|
||||||
for _ in 0 ..< byteLen div 16:
|
for _ in 0 ..< byteLen div 16:
|
||||||
when type(target) is Image:
|
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 values = mm_loadu_si128(target.data[index].addr)
|
||||||
|
|
||||||
let eqZero = mm_cmpeq_epi16(values, mm_setzero_si128())
|
if mm_movemask_epi8(mm_cmpeq_epi16(values, zeroVec)) != 0xffff:
|
||||||
if mm_movemask_epi8(eqZero) != 0xffff:
|
|
||||||
var
|
var
|
||||||
valuesEven = mm_slli_epi16(mm_andnot_si128(oddMask, values), 8)
|
valuesEven = mm_slli_epi16(mm_andnot_si128(oddMask, values), 8)
|
||||||
valuesOdd = mm_and_si128(values, oddMask)
|
valuesOdd = mm_and_si128(values, oddMask)
|
||||||
|
|
Loading…
Reference in a new issue