-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrip-bw-sprite.scm
41 lines (35 loc) · 1.24 KB
/
rip-bw-sprite.scm
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
40
41
(use-syntax (ice-9 syncase))
(use-modules (ice-9 format))
(define filename "pokegra-w.narc")
(define outdir "scmtest")
(define ENOENT 2)
(define EEXIST 17)
(define (mkdir-if-not-exist dir)
(catch 'system-error
(lambda () (mkdir dir) #t)
(lambda (key subr msg args rest)
(define code (car rest))
(if (eq? code EEXIST)
#f
(throw key subr msg args rest)))))
(define-syntax dotimes (syntax-rules ()
((dotimes (var times) body ...)
(let loop ((var 0) (ret #f))
(if (< var times)
(loop (1+ var) (begin body ...))
ret)))))
(mkdir-if-not-exist outdir)
(let* ((n 3)
(base (* n 20))
(narc (load-narc filename))
(ncgr (narc-load-file narc (+ base 2) 'NCGR))
(ncer (narc-load-file narc (+ base 4) 'NCER))
(nanr (narc-load-file narc (+ base 5) 'NANR))
(nmcr (narc-load-file narc (+ base 6) 'NMCR))
(nclr (narc-load-file narc (+ base 19) 'NCLR))
(cell 0))
(dotimes (frame 28)
(let ((image (make-image '(192 128))))
(image-set-palette-from-nclr image nclr)
(nmcr-draw nmcr cell (* frame 7) nanr ncer ncgr image '(96 112))
(image-save-png image (format #f "~a/~a.~2,'0d.png" outdir cell frame)))))