-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrip-bw-cells.scm
43 lines (36 loc) · 1.3 KB
/
rip-bw-cells.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
42
43
(use-syntax (ice-9 syncase))
(define filename "pokegra-w.narc")
(define outdir "cells")
(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)
(define (rip-cells n ncer ncgr nclr outdir)
(let ((image (make-image)))
(image-set-palette-from-nclr image nclr)
(dotimes (i (ncer-get-cell-count ncer))
(image-set-pixels-from-ncer image ncer i ncgr)
(image-save-png image (format #f "~a/~a-~a.png" outdir n i)))))
(let ((narc (load-narc filename)))
(dotimes (n 711)
(let ((base (* n 20)))
(let ((ncgr (narc-load-file narc (+ base 2) 'NCGR))
(ncer (narc-load-file narc (+ base 4) 'NCER))
(nclr (narc-load-file narc (+ base 18) 'NCLR))
(outdir_n (format #f "~a/~a" outdir n)))
(format #t "~a~%" n)
(mkdir-if-not-exist outdir_n)
(rip-cells n ncer ncgr nclr outdir_n)))))