2020-12-04 06:11:54 +00:00
|
|
|
import chroma, pixie, benchy
|
2020-12-03 20:21:58 +00:00
|
|
|
|
|
|
|
proc fillOriginal(a: Image, rgba: ColorRGBA) =
|
|
|
|
for y in 0 ..< a.height:
|
|
|
|
for x in 0 ..< a.width:
|
|
|
|
a.setRgbaUnsafe(x, y, rgba)
|
|
|
|
|
|
|
|
proc invertOriginal(a: Image) =
|
|
|
|
for y in 0 ..< a.height:
|
|
|
|
for x in 0 ..< a.width:
|
|
|
|
var rgba = a.getRgbaUnsafe(x, y)
|
|
|
|
rgba.r = 255 - rgba.r
|
|
|
|
rgba.g = 255 - rgba.g
|
|
|
|
rgba.b = 255 - rgba.b
|
|
|
|
rgba.a = 255 - rgba.a
|
|
|
|
a.setRgbaUnsafe(x, y, rgba)
|
|
|
|
|
2020-12-03 20:32:50 +00:00
|
|
|
proc applyOpacityOriginal(a: Image, opacity: float32): Image =
|
|
|
|
result = newImage(a.width, a.height)
|
|
|
|
let op = (255 * opacity).uint32
|
|
|
|
for y in 0 ..< a.height:
|
|
|
|
for x in 0 ..< a.width:
|
|
|
|
var rgba = a.getRgbaUnsafe(x, y)
|
|
|
|
rgba.a = ((rgba.a.uint32 * op) div 255).clamp(0, 255).uint8
|
|
|
|
result.setRgbaUnsafe(x, y, rgba)
|
|
|
|
|
|
|
|
proc sharpOpacityOriginal(a: Image): Image =
|
|
|
|
result = newImage(a.width, a.height)
|
|
|
|
for y in 0 ..< a.height:
|
|
|
|
for x in 0 ..< a.width:
|
|
|
|
var rgba = a.getRgbaUnsafe(x, y)
|
|
|
|
if rgba.a == 0:
|
|
|
|
result.setRgbaUnsafe(x, y, rgba(0, 0, 0, 0))
|
|
|
|
else:
|
|
|
|
result.setRgbaUnsafe(x, y, rgba(255, 255, 255, 255))
|
|
|
|
|
2020-12-04 06:11:54 +00:00
|
|
|
var a = newImage(2560, 1440)
|
|
|
|
|
2020-12-03 20:21:58 +00:00
|
|
|
timeIt "fillOriginal":
|
2020-12-04 06:11:54 +00:00
|
|
|
a.fillOriginal(rgba(255, 255, 255, 255))
|
2020-12-03 20:21:58 +00:00
|
|
|
doAssert a[0, 0] == rgba(255, 255, 255, 255)
|
2020-12-04 06:11:54 +00:00
|
|
|
keep(a)
|
2020-12-03 20:21:58 +00:00
|
|
|
|
|
|
|
timeIt "fill":
|
2020-12-04 06:11:54 +00:00
|
|
|
a.fill(rgba(255, 255, 255, 255))
|
2020-12-03 20:21:58 +00:00
|
|
|
doAssert a[0, 0] == rgba(255, 255, 255, 255)
|
2020-12-04 06:11:54 +00:00
|
|
|
keep(a)
|
2020-12-03 20:21:58 +00:00
|
|
|
|
|
|
|
timeIt "invertOriginal":
|
2020-12-04 06:11:54 +00:00
|
|
|
a.invertOriginal()
|
|
|
|
keep(a)
|
2020-12-03 20:21:58 +00:00
|
|
|
|
|
|
|
timeIt "invert":
|
2020-12-04 06:11:54 +00:00
|
|
|
a.invert()
|
|
|
|
keep(a)
|
2020-12-03 20:32:50 +00:00
|
|
|
|
|
|
|
timeIt "applyOpacityOriginal":
|
2020-12-04 06:11:54 +00:00
|
|
|
a = a.applyOpacityOriginal(0.5)
|
|
|
|
keep(a)
|
2020-12-03 20:32:50 +00:00
|
|
|
|
|
|
|
timeIt "applyOpacity":
|
2020-12-04 06:11:54 +00:00
|
|
|
a.applyOpacity(0.5)
|
|
|
|
keep(a)
|
2020-12-03 20:32:50 +00:00
|
|
|
|
|
|
|
timeIt "sharpOpacityOriginal":
|
2020-12-04 06:11:54 +00:00
|
|
|
a = a.sharpOpacityOriginal()
|
|
|
|
keep(a)
|
2020-12-03 20:32:50 +00:00
|
|
|
|
|
|
|
timeIt "sharpOpacity":
|
2020-12-04 06:11:54 +00:00
|
|
|
a.sharpOpacity()
|
|
|
|
keep(a)
|