-
Notifications
You must be signed in to change notification settings - Fork 1
/
adjust_brightness.nim
28 lines (26 loc) · 981 Bytes
/
adjust_brightness.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from chroma import rgbx, darken, Color
from pixie import Image, readImage, autoStraightAlpha, writeFile
from os import splitFile, `/`, changeFileExt
from std/times import cpuTime
import cligen
proc themain(darkenedTo: float32, input: string, output = "") =
let start = cpuTime()
var img = readImage input
for colordata in img.data.mitems:
let thergba = autoStraightAlpha colordata
let color = Color(
r: float32(thergba.r) / 255.0,
g: float32(thergba.g) / 255.0,
b: float32(thergba.b) / 255.0,
a: float32(thergba.a) / 255.0,
)
let newc = color.darken darkenedTo
colordata = rgbx(uint8(newc.r * 255.0), uint8(newc.g * 255.0),
uint8(newc.b * 255.0), uint8(newc.a * 255.0))
var fname = output
if fname == "":
let (dir, f, ext) = splitFile input
fname = dir / (f & "-darkened").changeFileExt(ext)
img.writeFile(fname)
echo "ended darkening after ", cpuTime() - start, " seconds"
dispatch(themain)