in place sharp and apply opacity
This commit is contained in:
parent
b3b844ea0e
commit
a69a4327a0
2 changed files with 4 additions and 6 deletions
|
@ -347,19 +347,17 @@ proc shadow*(
|
|||
result.fill(color)
|
||||
result.draw(shadow, blendMode = bmMask)
|
||||
|
||||
proc applyOpacity*(image: Image, opacity: float32): Image =
|
||||
proc applyOpacity*(image: Image, opacity: float32) =
|
||||
## Multiplies alpha of the image by opacity.
|
||||
result = newImage(image.width, image.height)
|
||||
let op = (255 * opacity).uint32
|
||||
for i in 0 ..< image.data.len:
|
||||
var rgba = image.data[i]
|
||||
rgba.a = ((rgba.a.uint32 * op) div 255).clamp(0, 255).uint8
|
||||
image.data[i] = rgba
|
||||
|
||||
proc sharpOpacity*(image: Image): Image =
|
||||
proc sharpOpacity*(image: Image) =
|
||||
## Sharpens the opacity to extreme.
|
||||
## A = 0 stays 0. Anything else turns into 255.
|
||||
result = newImage(image.width, image.height)
|
||||
for i in 0 ..< image.data.len:
|
||||
var rgba = image.data[i]
|
||||
if rgba.a == 0:
|
||||
|
|
|
@ -66,7 +66,7 @@ timeIt "applyOpacityOriginal":
|
|||
timeIt "applyOpacity":
|
||||
var a = newImage(2560, 1440)
|
||||
for i in 0 ..< iterations:
|
||||
a = a.applyOpacity(0.5)
|
||||
a.applyOpacity(0.5)
|
||||
|
||||
timeIt "sharpOpacityOriginal":
|
||||
var a = newImage(2560, 1440)
|
||||
|
@ -76,4 +76,4 @@ timeIt "sharpOpacityOriginal":
|
|||
timeIt "sharpOpacity":
|
||||
var a = newImage(2560, 1440)
|
||||
for i in 0 ..< iterations:
|
||||
a = a.sharpOpacity()
|
||||
a.sharpOpacity()
|
||||
|
|
Loading…
Reference in a new issue