summaryrefslogtreecommitdiff
path: root/README.org
blob: b47e3a3a4fd2921a79935e3c6dc8527d3be90b15 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

* =imbricate= Makes Tilesheets For Games

  The =imbricate= produces tile sheets from a directory tree the
  leaves of which are PNG image files.  

  The PNG files can be of any size.  The =imbricate= tool will attempt
  to pack the tiles into a square tile sheet.

  Imbricate also produces an "index file" for the tilesheet, providing
  a name and a location of each individual image.  The index can be in
  Lisp or JSON formats.  

** Example

*** Running =imbricate=

 Suppose you have a bunch of separate directional pad (DPad) buttons:

 #+BEGIN_EXAMPLE

 $ tree
 .
 └── Dpad
     ├── DownLeft.png
     ├── Down.png
     ├── DownRight.png
     ├── Left.png
     ├── Right.png
     ├── UpLeft.png
     ├── UP.png
     └── UpRight.png


 #+END_EXAMPLE

 To create a single image that contains all of them, just do:

 #+BEGIN_EXAMPLE

 $ imbricate Dpad/ dpad

 Reading images from disk........
 Creating Layout........
 Constructing tilesheet........
 Writing to disk...
 ALL DONE

 #+END_EXAMPLE

 Now your working directory shoul look like:

 #+BEGIN_EXAMPLE

 $ tree 
 .
 ├── Dpad
 │   ├── DownLeft.png
 │   ├── Down.png
 │   ├── DownRight.png
 │   ├── Left.png
 │   ├── Right.png
 │   ├── UpLeft.png
 │   ├── UP.png
 │   └── UpRight.png
 ├── dpad.bad.txt
 ├── dpad-index.lisp
 └── dpad.png


 #+END_EXAMPLE

*** The Output

 The file =dpad.bad.txt= is hopefully empty. It contains information
 about processing errors that =imbricate= may have encountered.

 The file =dpad.png= is the resulting image - it should contain
 everything from the target directory.

 The file =dpad-index.lisp= is a list of plists. For the above
 example, it looks like this:

#+BEGIN_EXAMPLE

$ cat dpad-index.lisp 

((:|name| "Dpad.Down" :|x| 54 :|y| 108 :|width| 54 :|height| 54)
 (:|name| "Dpad.DownLeft" :|x| 0 :|y| 162 :|width| 54 :|height| 54)
 (:|name| "Dpad.DownRight" :|x| 54 :|y| 54 :|width| 54 :|height| 54)
 (:|name| "Dpad.Left" :|x| 108 :|y| 0 :|width| 54 :|height| 54)
 (:|name| "Dpad.Right" :|x| 0 :|y| 108 :|width| 54 :|height| 54)
 (:|name| "Dpad.UP" :|x| 54 :|y| 0 :|width| 54 :|height| 54)
 (:|name| "Dpad.UpLeft" :|x| 0 :|y| 54 :|width| 54 :|height| 54)
 (:|name| "Dpad.UpRight" :|x| 0 :|y| 0 :|width| 54 :|height| 54)) 

#+END_EXAMPLE

*** JSON Output

You can opt for JSON output instead of Lisp by passing the =-json=
option to =imbricate= after all the other arguments:

#+BEGIN_EXAMPLE

$ imbricate Dpad dpad -json

$ cat dpad-index.json   # this is after M-x json-pretty-print-buffer in emacs

[
  {
    "name": "Dpad.Down",
    "x": 54,
    "y": 108,
    "width": 54,
    "height": 54
  },
  {
    "name": "Dpad.DownLeft",
    "x": 0,
    "y": 162,
    "width": 54,
    "height": 54
  },
  {
    "name": "Dpad.DownRight",
    "x": 54,
    "y": 54,
    "width": 54,
    "height": 54
  },
  {
    "name": "Dpad.Left",
    "x": 108,
    "y": 0,
    "width": 54,
    "height": 54
  },
  {
    "name": "Dpad.Right",
    "x": 0,
    "y": 108,
    "width": 54,
    "height": 54
  },
  {
    "name": "Dpad.UP",
    "x": 54,
    "y": 0,
    "width": 54,
    "height": 54
  },
  {
    "name": "Dpad.UpLeft",
    "x": 0,
    "y": 54,
    "width": 54,
    "height": 54
  },
  {
    "name": "Dpad.UpRight",
    "x": 0,
    "y": 0,
    "width": 54,
    "height": 54
  }
]


#+END_EXAMPLE


** Building

Assuming that you have [[https://github.com/roswell/roswell][roswell]] installed:

: $ ros use sbcl 
: $ git clone https://github.com/cbeo/imbricate.git 
: $ cd imbricate.git
: $ ros build imbricate.ros

I copy the resulting executable to =~/.local/bin=, which is in my =PATH=.

: $ cp imbricate ~/.local/bin


** Caveats

I made this for my own use but released it thinking it might be useful
for others.

Presently, the tool only works with PNG files that have RGBA
format. (i.e each pixel takes up 4 bytes).