more benchmarks
This commit is contained in:
parent
e1a4d7edc4
commit
b3b844ea0e
|
@ -17,6 +17,25 @@ proc invertOriginal(a: Image) =
|
||||||
rgba.a = 255 - rgba.a
|
rgba.a = 255 - rgba.a
|
||||||
a.setRgbaUnsafe(x, y, rgba)
|
a.setRgbaUnsafe(x, y, rgba)
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
timeIt "fillOriginal":
|
timeIt "fillOriginal":
|
||||||
var a = newImage(2560, 1440)
|
var a = newImage(2560, 1440)
|
||||||
for i in 0 ..< iterations:
|
for i in 0 ..< iterations:
|
||||||
|
@ -38,3 +57,23 @@ timeIt "invert":
|
||||||
var a = newImage(2560, 1440)
|
var a = newImage(2560, 1440)
|
||||||
for i in 0 ..< iterations:
|
for i in 0 ..< iterations:
|
||||||
a.invert()
|
a.invert()
|
||||||
|
|
||||||
|
timeIt "applyOpacityOriginal":
|
||||||
|
var a = newImage(2560, 1440)
|
||||||
|
for i in 0 ..< iterations:
|
||||||
|
a = a.applyOpacityOriginal(0.5)
|
||||||
|
|
||||||
|
timeIt "applyOpacity":
|
||||||
|
var a = newImage(2560, 1440)
|
||||||
|
for i in 0 ..< iterations:
|
||||||
|
a = a.applyOpacity(0.5)
|
||||||
|
|
||||||
|
timeIt "sharpOpacityOriginal":
|
||||||
|
var a = newImage(2560, 1440)
|
||||||
|
for i in 0 ..< iterations:
|
||||||
|
a = a.sharpOpacityOriginal()
|
||||||
|
|
||||||
|
timeIt "sharpOpacity":
|
||||||
|
var a = newImage(2560, 1440)
|
||||||
|
for i in 0 ..< iterations:
|
||||||
|
a = a.sharpOpacity()
|
||||||
|
|
Loading…
Reference in a new issue