-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.lisp
39 lines (31 loc) · 1.17 KB
/
lib.lisp
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
29
30
31
32
33
34
35
36
37
38
39
(in-package :flowfps)
(declaim (optimize (speed 3) (debug 1) (safety 1)))
(defun open-apply-write (input-image-path output-image-path filter)
(let* ((image-target (read-png-file input-image-path))
(image-static (copy-image image-target)))
(declare (type 8-bit-rgba-image image-target))
(declare (type 8-bit-rgba-image image-static))
(funcall filter image-target image-static)
(write-png-file output-image-path image-target)))
(defmacro image-iterate (image y x &rest body)
`(with-image-bounds (height width) ,image
(loop for ,y below height do
(loop for ,x below width do
,@body))))
(defmacro pixel-bind (image y x r g b a &rest body)
`(multiple-value-bind (,r ,g ,b ,a) (pixel ,image ,y ,x)
(declare (type (unsigned-byte 8) ,r ,g ,b ,a))
,@body))
(defun rgb+ (value factor)
(min (+ value factor) 255))
(defun rgb- (value factor)
(max (- value factor) 0))
(defun rgb/ (value factor)
(nth-value 0 (round (/ value factor))))
(defun rgb-fit (value)
(cond
((< value 0) 0)
((> value 255) 255)
(t (nth-value 0 (round value)))))
(defun rgb-noise (value factor)
(rgb- (rgb+ value (random factor)) (random factor)))