This commit is contained in:
Ryan Oldenburg 2021-01-24 15:31:43 -06:00
parent aec3d91109
commit 60280520b6

View file

@ -175,27 +175,6 @@ proc magnifyBy2*(image: Image): Image =
when defined(release): when defined(release):
{.pop.} {.pop.}
proc draw*(a, b: Image, mat: Mat3, blendMode = bmNormal)
proc draw*(a, b: Image, pos = vec2(0, 0), blendMode = bmNormal) {.inline.}
proc invert*(image: Image) =
## Inverts all of the colors and alpha.
var i: int
when defined(amd64) and not defined(pixieNoSimd):
let vec255 = mm_set1_epi8(255)
while i < image.data.len - 4:
var m = mm_loadu_si128(image.data[i].addr)
m = mm_sub_epi8(vec255, m)
mm_storeu_si128(image.data[i].addr, m)
i += 4
for j in i ..< image.data.len:
var rgba = image.data[j]
rgba.r = 255 - rgba.r
rgba.g = 255 - rgba.g
rgba.b = 255 - rgba.b
rgba.a = 255 - rgba.a
image.data[j] = rgba
proc toAlphy*(image: Image) = proc toAlphy*(image: Image) =
## Converts an image to premultiplied alpha from straight. ## Converts an image to premultiplied alpha from straight.
var i: int var i: int
@ -247,6 +226,27 @@ proc fromAlphy*(image: Image) =
c.g = ((c.g.uint32 * 255) div c.a.uint32).uint8 c.g = ((c.g.uint32 * 255) div c.a.uint32).uint8
c.b = ((c.b.uint32 * 255) div c.a.uint32).uint8 c.b = ((c.b.uint32 * 255) div c.a.uint32).uint8
proc draw*(a, b: Image, mat: Mat3, blendMode = bmNormal)
proc draw*(a, b: Image, pos = vec2(0, 0), blendMode = bmNormal) {.inline.}
proc invert*(image: Image) =
## Inverts all of the colors and alpha.
var i: int
when defined(amd64) and not defined(pixieNoSimd):
let vec255 = mm_set1_epi8(255)
while i < image.data.len - 4:
var m = mm_loadu_si128(image.data[i].addr)
m = mm_sub_epi8(vec255, m)
mm_storeu_si128(image.data[i].addr, m)
i += 4
for j in i ..< image.data.len:
var rgba = image.data[j]
rgba.r = 255 - rgba.r
rgba.g = 255 - rgba.g
rgba.b = 255 - rgba.b
rgba.a = 255 - rgba.a
image.data[j] = rgba
proc getRgbaSmooth*(image: Image, x, y: float32): ColorRGBA {.inline.} = proc getRgbaSmooth*(image: Image, x, y: float32): ColorRGBA {.inline.} =
## Gets a pixel as (x, y) floats. ## Gets a pixel as (x, y) floats.
let let