├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── COPYING ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── bors.toml ├── sheep ├── Cargo.toml ├── benches │ └── maxrects.rs ├── examples │ └── simple_pack │ │ ├── main.rs │ │ └── resources │ │ └── logo.png └── src │ ├── format │ ├── amethyst.rs │ ├── mod.rs │ └── named.rs │ ├── lib.rs │ ├── pack │ ├── maxrects.rs │ ├── mod.rs │ └── simple.rs │ └── sprite.rs └── sheep_cli ├── Cargo.toml └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # These are backup files generated by rustfmt 6 | **/*.rs.bk -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | script: 3 | - cargo build --verbose 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog][kc], and this project adheres to 6 | [Semantic Versioning][sv]. 7 | 8 | [kc]: http://keepachangelog.com/ 9 | [sv]: http://semver.org/ 10 | 11 | ## sheep 0.3.0, sheep_cli 0.3.0 - 2019-08 12 | 13 | ### Added 14 | 15 | - Trimming functionality added. ([#14]) 16 | - Pretty-print functionality for toml output added ([#18]) 17 | - Aliasing sprite duplicates functionality added ([#22]) 18 | - PNG Compression support for CLI added ([#27]) 19 | 20 | ### Modified 21 | 22 | - `Named` format moved to `amethyst` feature set, removed from `default` ([#17]) 23 | 24 | [#14]: https://github.com/amethyst/sheep/pull/14 25 | [#17]: https://github.com/amethyst/sheep/pull/17 26 | [#18]: https://github.com/amethyst/sheep/pull/18 27 | [#22]: https://github.com/amethyst/sheep/pull/22 28 | [#27]: https://github.com/amethyst/sheep/pull/27 29 | 30 | ## sheep 0.2.1, sheep_cli 0.2.0 - 2019-07 31 | 32 | - Initial [crates.io](https://crates.io) release 33 | 34 | ### Added 35 | 36 | - Maxrects packer added. ([#10]) 37 | - Support for multiple output textures added. ([#10]) 38 | - Benchmarks added. ([#10]) 39 | 40 | [#10]: https://github.com/amethyst/sheep/pull/10 41 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be 4 | copied, modified, or distributed except according to those terms. 5 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "adler32" 5 | version = "1.0.3" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | 8 | [[package]] 9 | name = "ansi_term" 10 | version = "0.11.0" 11 | source = "registry+https://github.com/rust-lang/crates.io-index" 12 | dependencies = [ 13 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 14 | ] 15 | 16 | [[package]] 17 | name = "arrayvec" 18 | version = "0.4.8" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | dependencies = [ 21 | "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", 22 | ] 23 | 24 | [[package]] 25 | name = "atty" 26 | version = "0.2.11" 27 | source = "registry+https://github.com/rust-lang/crates.io-index" 28 | dependencies = [ 29 | "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", 30 | "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 31 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 32 | ] 33 | 34 | [[package]] 35 | name = "autocfg" 36 | version = "0.1.5" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | 39 | [[package]] 40 | name = "base64" 41 | version = "0.9.3" 42 | source = "registry+https://github.com/rust-lang/crates.io-index" 43 | dependencies = [ 44 | "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 45 | "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 46 | ] 47 | 48 | [[package]] 49 | name = "bit-vec" 50 | version = "0.6.1" 51 | source = "registry+https://github.com/rust-lang/crates.io-index" 52 | 53 | [[package]] 54 | name = "bitflags" 55 | version = "1.0.4" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | 58 | [[package]] 59 | name = "build_const" 60 | version = "0.2.1" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | 63 | [[package]] 64 | name = "byteorder" 65 | version = "1.2.7" 66 | source = "registry+https://github.com/rust-lang/crates.io-index" 67 | 68 | [[package]] 69 | name = "cc" 70 | version = "1.0.38" 71 | source = "registry+https://github.com/rust-lang/crates.io-index" 72 | 73 | [[package]] 74 | name = "cfg-if" 75 | version = "0.1.6" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | 78 | [[package]] 79 | name = "clap" 80 | version = "2.32.0" 81 | source = "registry+https://github.com/rust-lang/crates.io-index" 82 | dependencies = [ 83 | "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 84 | "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", 85 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 86 | "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 87 | "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 88 | "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 89 | "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", 90 | ] 91 | 92 | [[package]] 93 | name = "cloudabi" 94 | version = "0.0.3" 95 | source = "registry+https://github.com/rust-lang/crates.io-index" 96 | dependencies = [ 97 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 98 | ] 99 | 100 | [[package]] 101 | name = "cloudflare-zlib" 102 | version = "0.2.3" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | dependencies = [ 105 | "cloudflare-zlib-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 106 | ] 107 | 108 | [[package]] 109 | name = "cloudflare-zlib-sys" 110 | version = "0.2.0" 111 | source = "registry+https://github.com/rust-lang/crates.io-index" 112 | dependencies = [ 113 | "cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", 114 | ] 115 | 116 | [[package]] 117 | name = "color_quant" 118 | version = "1.0.1" 119 | source = "registry+https://github.com/rust-lang/crates.io-index" 120 | 121 | [[package]] 122 | name = "crc" 123 | version = "1.8.1" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | dependencies = [ 126 | "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 127 | ] 128 | 129 | [[package]] 130 | name = "crc32fast" 131 | version = "1.2.0" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | dependencies = [ 134 | "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 135 | ] 136 | 137 | [[package]] 138 | name = "crossbeam-deque" 139 | version = "0.2.0" 140 | source = "registry+https://github.com/rust-lang/crates.io-index" 141 | dependencies = [ 142 | "crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 143 | "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 144 | ] 145 | 146 | [[package]] 147 | name = "crossbeam-epoch" 148 | version = "0.3.1" 149 | source = "registry+https://github.com/rust-lang/crates.io-index" 150 | dependencies = [ 151 | "arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 152 | "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 153 | "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 154 | "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 155 | "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 156 | "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", 157 | "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 158 | ] 159 | 160 | [[package]] 161 | name = "crossbeam-utils" 162 | version = "0.2.2" 163 | source = "registry+https://github.com/rust-lang/crates.io-index" 164 | dependencies = [ 165 | "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 166 | ] 167 | 168 | [[package]] 169 | name = "deflate" 170 | version = "0.7.19" 171 | source = "registry+https://github.com/rust-lang/crates.io-index" 172 | dependencies = [ 173 | "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 174 | "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 175 | ] 176 | 177 | [[package]] 178 | name = "either" 179 | version = "1.5.0" 180 | source = "registry+https://github.com/rust-lang/crates.io-index" 181 | 182 | [[package]] 183 | name = "fuchsia-cprng" 184 | version = "0.1.1" 185 | source = "registry+https://github.com/rust-lang/crates.io-index" 186 | 187 | [[package]] 188 | name = "gif" 189 | version = "0.10.1" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | dependencies = [ 192 | "color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 193 | "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 194 | ] 195 | 196 | [[package]] 197 | name = "glob" 198 | version = "0.3.0" 199 | source = "registry+https://github.com/rust-lang/crates.io-index" 200 | 201 | [[package]] 202 | name = "image" 203 | version = "0.20.1" 204 | source = "registry+https://github.com/rust-lang/crates.io-index" 205 | dependencies = [ 206 | "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 207 | "gif 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", 208 | "jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", 209 | "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 210 | "num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 211 | "num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 212 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 213 | "png 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 214 | "scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", 215 | "tiff 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 216 | ] 217 | 218 | [[package]] 219 | name = "image" 220 | version = "0.21.2" 221 | source = "registry+https://github.com/rust-lang/crates.io-index" 222 | dependencies = [ 223 | "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 224 | "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 225 | "num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 226 | "num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 227 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 228 | "png 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", 229 | ] 230 | 231 | [[package]] 232 | name = "inflate" 233 | version = "0.4.3" 234 | source = "registry+https://github.com/rust-lang/crates.io-index" 235 | dependencies = [ 236 | "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 237 | ] 238 | 239 | [[package]] 240 | name = "itertools" 241 | version = "0.8.0" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | dependencies = [ 244 | "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", 245 | ] 246 | 247 | [[package]] 248 | name = "jpeg-decoder" 249 | version = "0.1.15" 250 | source = "registry+https://github.com/rust-lang/crates.io-index" 251 | dependencies = [ 252 | "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 253 | "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 254 | ] 255 | 256 | [[package]] 257 | name = "lazy_static" 258 | version = "1.2.0" 259 | source = "registry+https://github.com/rust-lang/crates.io-index" 260 | 261 | [[package]] 262 | name = "libc" 263 | version = "0.2.44" 264 | source = "registry+https://github.com/rust-lang/crates.io-index" 265 | 266 | [[package]] 267 | name = "lzw" 268 | version = "0.10.0" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | 271 | [[package]] 272 | name = "memoffset" 273 | version = "0.2.1" 274 | source = "registry+https://github.com/rust-lang/crates.io-index" 275 | 276 | [[package]] 277 | name = "miniz_oxide" 278 | version = "0.2.3" 279 | source = "registry+https://github.com/rust-lang/crates.io-index" 280 | dependencies = [ 281 | "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 282 | ] 283 | 284 | [[package]] 285 | name = "nodrop" 286 | version = "0.1.13" 287 | source = "registry+https://github.com/rust-lang/crates.io-index" 288 | 289 | [[package]] 290 | name = "num-derive" 291 | version = "0.2.3" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | dependencies = [ 294 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 295 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", 296 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", 297 | "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", 298 | ] 299 | 300 | [[package]] 301 | name = "num-integer" 302 | version = "0.1.39" 303 | source = "registry+https://github.com/rust-lang/crates.io-index" 304 | dependencies = [ 305 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 306 | ] 307 | 308 | [[package]] 309 | name = "num-iter" 310 | version = "0.1.37" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | dependencies = [ 313 | "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 314 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 315 | ] 316 | 317 | [[package]] 318 | name = "num-rational" 319 | version = "0.2.1" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | dependencies = [ 322 | "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", 323 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 324 | ] 325 | 326 | [[package]] 327 | name = "num-traits" 328 | version = "0.2.6" 329 | source = "registry+https://github.com/rust-lang/crates.io-index" 330 | 331 | [[package]] 332 | name = "num_cpus" 333 | version = "1.8.0" 334 | source = "registry+https://github.com/rust-lang/crates.io-index" 335 | dependencies = [ 336 | "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", 337 | ] 338 | 339 | [[package]] 340 | name = "oxipng" 341 | version = "2.2.2" 342 | source = "registry+https://github.com/rust-lang/crates.io-index" 343 | dependencies = [ 344 | "bit-vec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", 345 | "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 346 | "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", 347 | "cloudflare-zlib 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 348 | "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", 349 | "image 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)", 350 | "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 351 | "miniz_oxide 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 352 | "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 353 | "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 354 | "rgb 0.8.13 (registry+https://github.com/rust-lang/crates.io-index)", 355 | "wild 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 356 | "zopfli 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 357 | ] 358 | 359 | [[package]] 360 | name = "png" 361 | version = "0.12.0" 362 | source = "registry+https://github.com/rust-lang/crates.io-index" 363 | dependencies = [ 364 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 365 | "deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)", 366 | "inflate 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 367 | "num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 368 | ] 369 | 370 | [[package]] 371 | name = "png" 372 | version = "0.14.1" 373 | source = "registry+https://github.com/rust-lang/crates.io-index" 374 | dependencies = [ 375 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 376 | "deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)", 377 | "inflate 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 378 | "num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", 379 | ] 380 | 381 | [[package]] 382 | name = "png" 383 | version = "0.15.0" 384 | source = "registry+https://github.com/rust-lang/crates.io-index" 385 | dependencies = [ 386 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 387 | "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 388 | "deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)", 389 | "inflate 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 390 | ] 391 | 392 | [[package]] 393 | name = "proc-macro2" 394 | version = "0.4.24" 395 | source = "registry+https://github.com/rust-lang/crates.io-index" 396 | dependencies = [ 397 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 398 | ] 399 | 400 | [[package]] 401 | name = "quote" 402 | version = "0.6.10" 403 | source = "registry+https://github.com/rust-lang/crates.io-index" 404 | dependencies = [ 405 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", 406 | ] 407 | 408 | [[package]] 409 | name = "rand" 410 | version = "0.6.5" 411 | source = "registry+https://github.com/rust-lang/crates.io-index" 412 | dependencies = [ 413 | "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 414 | "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", 415 | "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 416 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 417 | "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 418 | "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 419 | "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 420 | "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 421 | "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 422 | "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 423 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 424 | ] 425 | 426 | [[package]] 427 | name = "rand_chacha" 428 | version = "0.1.1" 429 | source = "registry+https://github.com/rust-lang/crates.io-index" 430 | dependencies = [ 431 | "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 432 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 433 | ] 434 | 435 | [[package]] 436 | name = "rand_core" 437 | version = "0.3.1" 438 | source = "registry+https://github.com/rust-lang/crates.io-index" 439 | dependencies = [ 440 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 441 | ] 442 | 443 | [[package]] 444 | name = "rand_core" 445 | version = "0.4.0" 446 | source = "registry+https://github.com/rust-lang/crates.io-index" 447 | 448 | [[package]] 449 | name = "rand_hc" 450 | version = "0.1.0" 451 | source = "registry+https://github.com/rust-lang/crates.io-index" 452 | dependencies = [ 453 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 454 | ] 455 | 456 | [[package]] 457 | name = "rand_isaac" 458 | version = "0.1.1" 459 | source = "registry+https://github.com/rust-lang/crates.io-index" 460 | dependencies = [ 461 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 462 | ] 463 | 464 | [[package]] 465 | name = "rand_jitter" 466 | version = "0.1.4" 467 | source = "registry+https://github.com/rust-lang/crates.io-index" 468 | dependencies = [ 469 | "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", 470 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 471 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 472 | ] 473 | 474 | [[package]] 475 | name = "rand_os" 476 | version = "0.1.3" 477 | source = "registry+https://github.com/rust-lang/crates.io-index" 478 | dependencies = [ 479 | "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 480 | "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 481 | "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", 482 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 483 | "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 484 | "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 485 | ] 486 | 487 | [[package]] 488 | name = "rand_pcg" 489 | version = "0.1.2" 490 | source = "registry+https://github.com/rust-lang/crates.io-index" 491 | dependencies = [ 492 | "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 493 | "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 494 | ] 495 | 496 | [[package]] 497 | name = "rand_xorshift" 498 | version = "0.1.1" 499 | source = "registry+https://github.com/rust-lang/crates.io-index" 500 | dependencies = [ 501 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 502 | ] 503 | 504 | [[package]] 505 | name = "rayon" 506 | version = "1.0.3" 507 | source = "registry+https://github.com/rust-lang/crates.io-index" 508 | dependencies = [ 509 | "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 510 | "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", 511 | "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", 512 | ] 513 | 514 | [[package]] 515 | name = "rayon-core" 516 | version = "1.4.1" 517 | source = "registry+https://github.com/rust-lang/crates.io-index" 518 | dependencies = [ 519 | "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 520 | "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 521 | "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", 522 | "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 523 | ] 524 | 525 | [[package]] 526 | name = "rdrand" 527 | version = "0.4.0" 528 | source = "registry+https://github.com/rust-lang/crates.io-index" 529 | dependencies = [ 530 | "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 531 | ] 532 | 533 | [[package]] 534 | name = "redox_syscall" 535 | version = "0.1.43" 536 | source = "registry+https://github.com/rust-lang/crates.io-index" 537 | 538 | [[package]] 539 | name = "redox_termios" 540 | version = "0.1.1" 541 | source = "registry+https://github.com/rust-lang/crates.io-index" 542 | dependencies = [ 543 | "redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", 544 | ] 545 | 546 | [[package]] 547 | name = "rgb" 548 | version = "0.8.13" 549 | source = "registry+https://github.com/rust-lang/crates.io-index" 550 | 551 | [[package]] 552 | name = "ron" 553 | version = "0.4.0" 554 | source = "registry+https://github.com/rust-lang/crates.io-index" 555 | dependencies = [ 556 | "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", 557 | "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", 558 | "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", 559 | ] 560 | 561 | [[package]] 562 | name = "safemem" 563 | version = "0.3.0" 564 | source = "registry+https://github.com/rust-lang/crates.io-index" 565 | 566 | [[package]] 567 | name = "scoped_threadpool" 568 | version = "0.1.9" 569 | source = "registry+https://github.com/rust-lang/crates.io-index" 570 | 571 | [[package]] 572 | name = "scopeguard" 573 | version = "0.3.3" 574 | source = "registry+https://github.com/rust-lang/crates.io-index" 575 | 576 | [[package]] 577 | name = "serde" 578 | version = "1.0.89" 579 | source = "registry+https://github.com/rust-lang/crates.io-index" 580 | dependencies = [ 581 | "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", 582 | ] 583 | 584 | [[package]] 585 | name = "serde_derive" 586 | version = "1.0.80" 587 | source = "registry+https://github.com/rust-lang/crates.io-index" 588 | dependencies = [ 589 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", 590 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", 591 | "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", 592 | ] 593 | 594 | [[package]] 595 | name = "sheep" 596 | version = "0.3.0" 597 | dependencies = [ 598 | "image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", 599 | "ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 600 | "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", 601 | "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", 602 | "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", 603 | "twox-hash 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 604 | ] 605 | 606 | [[package]] 607 | name = "sheep_cli" 608 | version = "0.3.0" 609 | dependencies = [ 610 | "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", 611 | "image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", 612 | "oxipng 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 613 | "png 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", 614 | "ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 615 | "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", 616 | "sheep 0.3.0", 617 | ] 618 | 619 | [[package]] 620 | name = "smallvec" 621 | version = "0.6.10" 622 | source = "registry+https://github.com/rust-lang/crates.io-index" 623 | 624 | [[package]] 625 | name = "strsim" 626 | version = "0.7.0" 627 | source = "registry+https://github.com/rust-lang/crates.io-index" 628 | 629 | [[package]] 630 | name = "syn" 631 | version = "0.15.22" 632 | source = "registry+https://github.com/rust-lang/crates.io-index" 633 | dependencies = [ 634 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", 635 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", 636 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 637 | ] 638 | 639 | [[package]] 640 | name = "termion" 641 | version = "1.5.1" 642 | source = "registry+https://github.com/rust-lang/crates.io-index" 643 | dependencies = [ 644 | "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", 645 | "redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", 646 | "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 647 | ] 648 | 649 | [[package]] 650 | name = "textwrap" 651 | version = "0.10.0" 652 | source = "registry+https://github.com/rust-lang/crates.io-index" 653 | dependencies = [ 654 | "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 655 | ] 656 | 657 | [[package]] 658 | name = "tiff" 659 | version = "0.2.1" 660 | source = "registry+https://github.com/rust-lang/crates.io-index" 661 | dependencies = [ 662 | "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 663 | "lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", 664 | "num-derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 665 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", 666 | ] 667 | 668 | [[package]] 669 | name = "twox-hash" 670 | version = "1.4.2" 671 | source = "registry+https://github.com/rust-lang/crates.io-index" 672 | dependencies = [ 673 | "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", 674 | ] 675 | 676 | [[package]] 677 | name = "typed-arena" 678 | version = "1.5.0" 679 | source = "registry+https://github.com/rust-lang/crates.io-index" 680 | 681 | [[package]] 682 | name = "unicode-width" 683 | version = "0.1.5" 684 | source = "registry+https://github.com/rust-lang/crates.io-index" 685 | 686 | [[package]] 687 | name = "unicode-xid" 688 | version = "0.1.0" 689 | source = "registry+https://github.com/rust-lang/crates.io-index" 690 | 691 | [[package]] 692 | name = "vec_map" 693 | version = "0.8.1" 694 | source = "registry+https://github.com/rust-lang/crates.io-index" 695 | 696 | [[package]] 697 | name = "wild" 698 | version = "2.0.2" 699 | source = "registry+https://github.com/rust-lang/crates.io-index" 700 | dependencies = [ 701 | "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 702 | ] 703 | 704 | [[package]] 705 | name = "winapi" 706 | version = "0.3.6" 707 | source = "registry+https://github.com/rust-lang/crates.io-index" 708 | dependencies = [ 709 | "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 710 | "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 711 | ] 712 | 713 | [[package]] 714 | name = "winapi-i686-pc-windows-gnu" 715 | version = "0.4.0" 716 | source = "registry+https://github.com/rust-lang/crates.io-index" 717 | 718 | [[package]] 719 | name = "winapi-x86_64-pc-windows-gnu" 720 | version = "0.4.0" 721 | source = "registry+https://github.com/rust-lang/crates.io-index" 722 | 723 | [[package]] 724 | name = "zopfli" 725 | version = "0.4.0" 726 | source = "registry+https://github.com/rust-lang/crates.io-index" 727 | dependencies = [ 728 | "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 729 | "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", 730 | "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", 731 | "typed-arena 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", 732 | ] 733 | 734 | [metadata] 735 | "checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" 736 | "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 737 | "checksum arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f405cc4c21cd8b784f6c8fc2adf9bc00f59558f0049b5ec21517f875963040cc" 738 | "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" 739 | "checksum autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "22130e92352b948e7e82a49cdb0aa94f2211761117f29e052dd397c1ac33542b" 740 | "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" 741 | "checksum bit-vec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a4523a10839ffae575fb08aa3423026c8cb4687eef43952afb956229d4f246f7" 742 | "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" 743 | "checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" 744 | "checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" 745 | "checksum cc 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "ce400c638d48ee0e9ab75aef7997609ec57367ccfe1463f21bf53c3eca67bf46" 746 | "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" 747 | "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" 748 | "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" 749 | "checksum cloudflare-zlib 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1c581010ccdab7db2940508a181af6217d1fbb7c1497d5a5162f00b9d2b3e70" 750 | "checksum cloudflare-zlib-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7e195cb274a0d6ee87e718838a09baecd7cbc9f6075dac256a84cb5842739c06" 751 | "checksum color_quant 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbb57365263e881e805dc77d94697c9118fd94d8da011240555aa7b23445bd" 752 | "checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" 753 | "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" 754 | "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" 755 | "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" 756 | "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" 757 | "checksum deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8a6abb26e16e8d419b5c78662aa9f82857c2386a073da266840e474d5055ec86" 758 | "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" 759 | "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" 760 | "checksum gif 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4bca55ac1f213920ce3527ccd62386f1f15fa3f1714aeee1cf93f2c416903f" 761 | "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" 762 | "checksum image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44665b4395d1844c96e7dc8ed5754782a1cdfd9ef458a80bbe45702681450504" 763 | "checksum image 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)" = "99198e595d012efccf12abf4abc08da2d97be0b0355a2b08d101347527476ba4" 764 | "checksum inflate 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6f53b811ee8e2057ccf9643ca6b4277de90efaf5e61e55fd5254576926bb4245" 765 | "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" 766 | "checksum jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c8b7d43206b34b3f94ea9445174bda196e772049b9bddbc620c9d29b2d20110d" 767 | "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" 768 | "checksum libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)" = "10923947f84a519a45c8fefb7dd1b3e8c08747993381adee176d7a82b4195311" 769 | "checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" 770 | "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" 771 | "checksum miniz_oxide 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5f6d7b3dd914b70db7cef7ab9dc74339ffcadf4d033464a987237bb0b9418cd4" 772 | "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" 773 | "checksum num-derive 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8af1847c907c2f04d7bfd572fb25bbb4385c637fe5be163cf2f8c5d778fe1e7d" 774 | "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" 775 | "checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124" 776 | "checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10" 777 | "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" 778 | "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" 779 | "checksum oxipng 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d67ce5cdb09fc0c53e328f2df0f6ebd2ec3582d2f1eaf4b1cdc9dfe991cd5020" 780 | "checksum png 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f54b9600d584d3b8a739e1662a595fab051329eff43f20e7d8cc22872962145b" 781 | "checksum png 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "63daf481fdd0defa2d1d2be15c674fbfa1b0fd71882c303a91f9a79b3252c359" 782 | "checksum png 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8422b27bb2c013dd97b9aef69e161ce262236f49aaf46a0489011c8ff0264602" 783 | "checksum proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)" = "77619697826f31a02ae974457af0b29b723e5619e113e9397b8b82c6bd253f09" 784 | "checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c" 785 | "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" 786 | "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" 787 | "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" 788 | "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" 789 | "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" 790 | "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" 791 | "checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" 792 | "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" 793 | "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" 794 | "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" 795 | "checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" 796 | "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" 797 | "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" 798 | "checksum redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "679da7508e9a6390aeaf7fbd02a800fdc64b73fe2204dd2c8ae66d22d9d5ad5d" 799 | "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" 800 | "checksum rgb 0.8.13 (registry+https://github.com/rust-lang/crates.io-index)" = "4f089652ca87f5a82a62935ec6172a534066c7b97be003cc8f702ee9a7a59c92" 801 | "checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f" 802 | "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" 803 | "checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" 804 | "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" 805 | "checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" 806 | "checksum serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)" = "225de307c6302bec3898c51ca302fc94a7a1697ef0845fcee6448f33c032249c" 807 | "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" 808 | "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" 809 | "checksum syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)" = "ae8b29eb5210bc5cf63ed6149cbf9adfc82ac0be023d8735c176ee74a2db4da7" 810 | "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" 811 | "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" 812 | "checksum tiff 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a2cc6c4fd13cb1cfd20abdb196e794ceccb29371855b7e7f575945f920a5b3c2" 813 | "checksum twox-hash 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7834480552ffc48e1930ceddd701f47d2234319d80b7bcbbe2fe7202933c101" 814 | "checksum typed-arena 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f70f5c346cc11bc044ae427ab2feae213350dca9e2d637047797d5ff316a646" 815 | "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" 816 | "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" 817 | "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" 818 | "checksum wild 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "97d34fecce28871e5c0e059deae21ef7f7d13b98a5964b24c58b3735c8052fc8" 819 | "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" 820 | "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 821 | "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 822 | "checksum zopfli 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4079b79464426ade2a1b0177fb0ce8396ba6b4084267407e333573c666073964" 823 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["sheep", "sheep_cli"] 3 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 Amethyst Foundation 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any 2 | person obtaining a copy of this software and associated 3 | documentation files (the "Software"), to deal in the 4 | Software without restriction, including without 5 | limitation the rights to use, copy, modify, merge, 6 | publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software 8 | is furnished to do so, subject to the following 9 | conditions: 10 | 11 | The above copyright notice and this permission notice 12 | shall be included in all copies or substantial portions 13 | of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sheep 🐑 2 | 3 | [![Build Status](https://travis-ci.org/amethyst/sheep.svg?branch=master)](https://travis-ci.org/amethyst/sheep) 4 | [![Crates.io](https://img.shields.io/crates/v/sheep)](https://crates.io/crates/sheep) 5 | 6 | `sheep` (Sprite**shee**t **p**acker) is a lightweight and modular library used to create spritesheets. It aims to impose as little restrictions as possible on the usage of its API so that it can be used in asset pipelines. 7 | 8 | The project is in heavy development and the API might change a few times until we reach a stable version, but the general flow of inputting bytes and receiving metadata and a byte vec will remain the same. 9 | 10 | ## Usage 11 | 12 | To use the CLI, simply install it with cargo: 13 | 14 | ``` 15 | cargo install sheep_cli 16 | ``` 17 | 18 | Usagen hints are provided. To see all options, simply run the command with no arguments. Options can be passed to the packers using the `--options` flag, as space separated `key=value` pairs. 19 | By default, the `maxrects` packer will be used, see [packers](#Packers) for more information. 20 | 21 | **Example:** 22 | 23 | ``` 24 | sheep pack --options max_width=1024 max_height=1024 sprites/*.png 25 | ``` 26 | 27 | If you want to use the CLI from source, simple clone the repo and run `cargo run -- ...`. For an example on how to use the library directly, please see the `simple_pack` example in the `sheep/examples` directory. 28 | 29 | ## Implementing your own `Packer` and `Format` 30 | 31 | Sheep achieves its modularity by letting you choose the implementation it will use for packing the sprites and encoding the metadata. Right now, two common packing algorithms are provided (`SimplePacker` and `MaxrectsPacker`, see [packers](#Packers)), as well as the data format used by the [amethyst engine](https://github.com/amethyst/amethyst) (`AmethystFormat`). There will be more in the future, however, you can also choose your own packing algorithm and format: 32 | 33 | #### Implementing `Packer` 34 | 35 | ```rust 36 | pub struct MyPacker; 37 | 38 | impl Packer for MyPacker { 39 | fn pack(sprites: &[SpriteData]) -> PackerResult { 40 | // Spritedata contains an id for the sprite to reference back 41 | // to it, and the dimensions of the sprite. 42 | 43 | // The expected output is the dimensions of the resulting spritesheet, 44 | // as well as all the anchors for the sprites (i.e. their positions). 45 | PackerResult { dimensions, anchors } 46 | } 47 | } 48 | ``` 49 | 50 | #### Implementing `Format` 51 | 52 | ```rust 53 | pub struct MyFormat; 54 | 55 | // This is the format that will be output by encode, and you'll probably want 56 | // to serialize later. 57 | #[derive(Serialize)] 58 | pub struct Foo {} 59 | 60 | impl Format for AmethystFOrmat { 61 | type Data = Foo; 62 | 63 | fn encode(dimensions: (u32, u32), sprites: &[SpriteAnchor]) -> Self::Data { 64 | // Encode the spritesheet dimensions and sprite positions into 65 | // your chosen data format here. 66 | 67 | Foo {} 68 | } 69 | } 70 | ``` 71 | 72 | #### Using your custom `impl`s 73 | 74 | To use custom packers or formatters, simply pass them as type parameters when calling the functions: 75 | 76 | ```rust 77 | let sprite_sheet = sheep::pack::(sprites, 4); 78 | let meta = sheep::encode::(&sprite_sheet); 79 | ``` 80 | 81 | ## Packers 82 | 83 | Right now, there are two implementations to choose from: 84 | 85 | - MAXRECTS (**recommended**) 86 | 87 | Implementation of the maxrects sprite packing algorithm. The paper and original implementation used as a reference for this can be found [here](https://github.com/juj/RectangleBinPack). This algorithm should yield optimal results in most scenarios. 88 | 89 | - simple 90 | 91 | A naive implementation that will sort the sprites by area and then pack them all into a single texture. This won't scale very well since you can't limit the maximum size of the resulting sprite sheet, but can be quicker than maxrects in simple scenarios. 92 | 93 | ## Roadmap 94 | 95 | Here are the planned features for `sheep`: 96 | 97 | - ~~Support for multiple output textures (bins)~~ 98 | - ~~Smart output texture sizing~~ 99 | - More packing algorithms 100 | - ~~MAXRECTS~~ 101 | - Skyline 102 | - More meta formats 103 | - More image formats 104 | 105 | ## License 106 | 107 | `sheep` is dual licensed under MIT and Apache, see `COPYING`. 108 | -------------------------------------------------------------------------------- /bors.toml: -------------------------------------------------------------------------------- 1 | # Test suite must pass on both Travis and GitLab before merging into `master`. 2 | status = [ 3 | "continuous-integration/travis-ci/push", 4 | ] 5 | 6 | # Do not allow pull requests with these labels to be merged. 7 | block_labels = [ 8 | "status: blocked", 9 | "status: discussing", 10 | "status: in progress", 11 | "status: needs triage" 12 | ] 13 | 14 | # This feature is rarely useful and more often problematic, so we turn it off. 15 | delete_merged_branches = false 16 | -------------------------------------------------------------------------------- /sheep/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sheep" 3 | version = "0.3.0" 4 | authors = ["Hilmar Wiegand "] 5 | description = "Modular and lightweight spritesheet packing library" 6 | keywords = ["sdk", "amethyst", "sprites", "2d", "packing"] 7 | categories = ["game-engines"] 8 | 9 | homepage = "https://amethyst.rs/" 10 | repository = "https://github.com/amethyst/sheep" 11 | 12 | readme = "../README.md" 13 | license = "MIT/Apache-2.0" 14 | 15 | [features] 16 | default = ["amethyst"] 17 | amethyst = ["serde", "serde_derive"] 18 | 19 | [badges] 20 | travis-ci = { repository = "amethyst/sheep", branch = "master" } 21 | 22 | [dependencies] 23 | serde = { version = "1", optional = true } 24 | serde_derive = { version = "1", optional = true } 25 | twox-hash = "1.4.2" 26 | smallvec = "0.6" 27 | 28 | [dev-dependencies] 29 | image = "0.20" 30 | ron = "0.4" 31 | 32 | [[example]] 33 | name = "simple_pack" 34 | path = "examples/simple_pack/main.rs" 35 | -------------------------------------------------------------------------------- /sheep/benches/maxrects.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | extern crate sheep; 4 | 5 | use test::Bencher; 6 | use sheep::{Packer, SpriteData, MaxrectsPacker, MaxrectsOptions}; 7 | 8 | #[bench] 9 | fn bench_pack(b: &mut Bencher) { 10 | let mut sprites = (0..1000) 11 | .map(|i| SpriteData::new(i, (100, 100))) 12 | .collect::>(); 13 | 14 | let smaller_sprites = (0..1000) 15 | .map(|i| SpriteData::new(i, (80, 80))) 16 | .collect::>(); 17 | 18 | sprites.extend(smaller_sprites.into_iter()); 19 | 20 | let options = MaxrectsOptions::default() 21 | .preferred_width(1000 * 100) 22 | .preferred_height(1000 * 100); 23 | 24 | b.iter(|| { 25 | let result = MaxrectsPacker::pack(&sprites, options); 26 | let _ = test::black_box(&result); 27 | }); 28 | } -------------------------------------------------------------------------------- /sheep/examples/simple_pack/main.rs: -------------------------------------------------------------------------------- 1 | extern crate image; 2 | extern crate sheep; 3 | 4 | use sheep::{AmethystFormat, InputSprite, SimplePacker}; 5 | use std::{fs::File, io::prelude::*}; 6 | 7 | fn main() { 8 | // First, we get the raw, uncompressed pixel data of the image. These 9 | // can come from any sources and even be generated in code, but for 10 | // simplicity's sake we're using the image crate here. 11 | let img = 12 | image::open("sheep/examples/simple_pack/resources/logo.png").expect("Failed to open image"); 13 | let img = img.as_rgba8().expect("Failed to convert image to rgba8"); 14 | 15 | let dimensions = img.dimensions(); 16 | let bytes = img 17 | .pixels() 18 | .flat_map(|it| it.data.iter().map(|it| *it)) 19 | .collect::>(); 20 | 21 | // We'll just repeat the same sprite 16 times and pack it into a texture. 22 | let sprites = (0..16) 23 | .map(|_| InputSprite { 24 | dimensions, 25 | bytes: bytes.clone(), 26 | }).collect::>(); 27 | 28 | // Do the actual packing! 4 defines the stride, since we're using rgba8 we 29 | // have 4 bytes per pixel. 30 | let results = sheep::pack::(sprites, 4, Default::default()); 31 | 32 | // SimplePacker always returns a single result. Other packers can return 33 | // multiple sheets; should they, for example, choose to enforce a maximum 34 | // texture size per sheet. 35 | let sprite_sheet = results 36 | .into_iter() 37 | .next() 38 | .expect("Should have returned a spritesheet"); 39 | 40 | // Now, we can encode the sprite sheet in a format of our choosing to 41 | // save things such as offsets, positions of the sprites and so on. 42 | let meta = sheep::encode::(&sprite_sheet, ()); 43 | 44 | // Next, we save the output to a file using the image crate again. 45 | let outbuf = image::RgbaImage::from_vec( 46 | sprite_sheet.dimensions.0, 47 | sprite_sheet.dimensions.1, 48 | sprite_sheet.bytes, 49 | ).expect("Failed to construct image from sprite sheet bytes"); 50 | 51 | outbuf.save("out.png").expect("Failed to save image"); 52 | 53 | // Lastly, we serialize the meta info using serde. This can be any format 54 | // you want, just implement the trait and pass it to encode. 55 | let mut meta_file = File::create("out.ron").expect("Failed to create meta file"); 56 | let meta_str = ron::ser::to_string(&meta).expect("Failed to encode meta file"); 57 | 58 | meta_file 59 | .write_all(meta_str.as_bytes()) 60 | .expect("Failed to write meta file"); 61 | } 62 | -------------------------------------------------------------------------------- /sheep/examples/simple_pack/resources/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/amethyst/sheep/58798f288dd625318892e89d74e991c0be140836/sheep/examples/simple_pack/resources/logo.png -------------------------------------------------------------------------------- /sheep/src/format/amethyst.rs: -------------------------------------------------------------------------------- 1 | use super::Format; 2 | use SpriteAnchor; 3 | 4 | pub struct AmethystFormat; 5 | 6 | #[derive(Clone, Debug, PartialEq, Serialize)] 7 | pub struct SpritePosition { 8 | pub x: f32, 9 | pub y: f32, 10 | pub width: f32, 11 | pub height: f32, 12 | pub offsets: Option<[f32; 2]>, 13 | } 14 | 15 | #[derive(Clone, Debug, PartialEq, Serialize)] 16 | pub struct SerializedSpriteSheet { 17 | pub texture_width: f32, 18 | pub texture_height: f32, 19 | pub sprites: Vec, 20 | } 21 | 22 | impl Format for AmethystFormat { 23 | type Data = SerializedSpriteSheet; 24 | type Options = (); 25 | 26 | fn encode( 27 | dimensions: (u32, u32), 28 | sprites: &[SpriteAnchor], 29 | _options: Self::Options, 30 | ) -> Self::Data { 31 | let sprite_positions = sprites 32 | .iter() 33 | .map(|it| SpritePosition { 34 | x: it.position.0 as f32, 35 | y: it.position.1 as f32, 36 | width: it.dimensions.0 as f32, 37 | height: it.dimensions.1 as f32, 38 | offsets: None, 39 | }) 40 | .collect::>(); 41 | 42 | SerializedSpriteSheet { 43 | texture_width: dimensions.0 as f32, 44 | texture_height: dimensions.1 as f32, 45 | sprites: sprite_positions, 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sheep/src/format/mod.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "amethyst")] 2 | pub mod amethyst; 3 | 4 | #[cfg(feature = "amethyst")] 5 | pub mod named; 6 | 7 | use SpriteAnchor; 8 | 9 | pub trait Format { 10 | type Data; 11 | type Options; 12 | 13 | fn encode( 14 | dimensions: (u32, u32), 15 | sprites: &[SpriteAnchor], 16 | options: Self::Options, 17 | ) -> Self::Data; 18 | } 19 | -------------------------------------------------------------------------------- /sheep/src/format/named.rs: -------------------------------------------------------------------------------- 1 | use super::Format; 2 | use SpriteAnchor; 3 | 4 | pub struct AmethystNamedFormat; 5 | 6 | /// `NameSprite` represents a field in a `SerializedNamedSpriteSheet`. 7 | /// All of the fields, except `name`, mimic the `SpritePosition` struct. 8 | #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] 9 | pub struct NamedSpritePosition { 10 | pub name: String, 11 | pub x: f32, 12 | pub y: f32, 13 | pub width: f32, 14 | pub height: f32, 15 | pub offsets: Option<[f32; 2]>, 16 | } 17 | 18 | impl From<(&SpriteAnchor, String)> for NamedSpritePosition { 19 | fn from(anchor: (&SpriteAnchor, String)) -> NamedSpritePosition { 20 | return NamedSpritePosition { 21 | name: anchor.1, 22 | x: anchor.0.position.0 as f32, 23 | y: anchor.0.position.1 as f32, 24 | width: anchor.0.dimensions.0 as f32, 25 | height: anchor.0.dimensions.1 as f32, 26 | offsets: None, 27 | }; 28 | } 29 | } 30 | 31 | /// `SerializedNamedSpriteSheet` is the serializable representation of the sprite sheet. 32 | /// It is similar to `SerializedSpriteSheet`, except that it has a `Vec` of `NamedSpritePosition`s 33 | /// instead of `SpriteAnchor`s 34 | #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] 35 | pub struct SerializedNamedSpriteSheet { 36 | pub texture_width: f32, 37 | pub texture_height: f32, 38 | pub sprites: Vec, 39 | } 40 | 41 | impl Format for AmethystNamedFormat { 42 | type Data = SerializedNamedSpriteSheet; 43 | type Options = Vec; 44 | 45 | fn encode( 46 | dimensions: (u32, u32), 47 | sprites: &[SpriteAnchor], 48 | options: Self::Options, 49 | ) -> Self::Data { 50 | let sprite_positions = sprites 51 | .iter() 52 | .map(|anchor| (anchor, options[anchor.id].clone())) 53 | .map(Into::into) 54 | .collect::>(); 55 | 56 | SerializedNamedSpriteSheet { 57 | texture_width: dimensions.0 as f32, 58 | texture_height: dimensions.1 as f32, 59 | sprites: sprite_positions, 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sheep/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "amethyst")] 2 | extern crate serde; 3 | 4 | #[cfg(feature = "amethyst")] 5 | #[macro_use] 6 | extern crate serde_derive; 7 | 8 | extern crate smallvec; 9 | extern crate twox_hash; 10 | 11 | mod format; 12 | mod pack; 13 | mod sprite; 14 | 15 | pub use { 16 | format::Format, 17 | pack::{ 18 | maxrects::{MaxrectsOptions, MaxrectsPacker}, 19 | simple::SimplePacker, 20 | Packer, PackerResult, 21 | }, 22 | sprite::{InputSprite, Sprite, SpriteAnchor, SpriteData}, 23 | }; 24 | 25 | #[cfg(feature = "amethyst")] 26 | pub use format::amethyst::{AmethystFormat, SerializedSpriteSheet, SpritePosition}; 27 | #[cfg(feature = "amethyst")] 28 | pub use format::named::{AmethystNamedFormat, NamedSpritePosition, SerializedNamedSpriteSheet}; 29 | 30 | use sprite::{create_pixel_buffer, write_sprite}; 31 | 32 | use smallvec::SmallVec; 33 | use std::collections::hash_map::HashMap; 34 | use std::hash::BuildHasherDefault; 35 | use twox_hash::XxHash64; 36 | 37 | #[derive(Debug, Clone)] 38 | pub struct SpriteSheet { 39 | pub bytes: Vec, 40 | pub stride: usize, 41 | pub dimensions: (u32, u32), 42 | anchors: Vec, 43 | } 44 | 45 | pub fn pack( 46 | input: Vec, 47 | stride: usize, 48 | options: P::Options, 49 | ) -> Vec { 50 | let mut hashes: HashMap<&[u8], usize, BuildHasherDefault> = Default::default(); 51 | let mut aliases: HashMap> = HashMap::with_capacity(input.len()); 52 | for (id, sprite) in input.iter().enumerate() { 53 | let alias_id = hashes.entry(sprite.bytes.as_slice()).or_insert(id); 54 | aliases.entry(*alias_id).or_default().push(id); 55 | } 56 | 57 | let sprites = input 58 | .into_iter() 59 | .enumerate() 60 | .map(|(id, sprite)| Sprite::from_input(id, sprite)) 61 | .collect::>(); 62 | let sprite_data = sprites 63 | .iter() 64 | .enumerate() 65 | .filter(|(id, _)| aliases.contains_key(id)) 66 | .map(|(_, it)| it.data) 67 | .collect::>(); 68 | 69 | let packer_result = P::pack(&sprite_data, options); 70 | 71 | packer_result 72 | .into_iter() 73 | .map(|mut sheet| { 74 | let mut buffer = create_pixel_buffer(sheet.dimensions, stride); 75 | let mut aliased_anchors = Vec::::new(); 76 | for anchor in &sheet.anchors { 77 | write_sprite( 78 | &mut buffer, 79 | sheet.dimensions, 80 | stride, 81 | &sprites[anchor.id], 82 | &anchor, 83 | ); 84 | aliased_anchors.extend( 85 | aliases[&anchor.id] 86 | .iter() 87 | .skip(1) 88 | .map(|id| SpriteAnchor { id: *id, ..*anchor }), 89 | ); 90 | } 91 | sheet.anchors.extend(aliased_anchors); 92 | 93 | SpriteSheet { 94 | bytes: buffer, 95 | stride: stride, 96 | dimensions: sheet.dimensions, 97 | anchors: sheet.anchors, 98 | } 99 | }) 100 | .collect() 101 | } 102 | 103 | pub fn encode(sprite_sheet: &SpriteSheet, options: F::Options) -> F::Data 104 | where 105 | F: Format, 106 | { 107 | F::encode(sprite_sheet.dimensions, &sprite_sheet.anchors, options) 108 | } 109 | 110 | pub fn trim(input: &[InputSprite], stride: usize, alpha_channel_index: usize) -> Vec { 111 | input 112 | .iter() 113 | .map(|sprite| sprite.trimmed(stride, alpha_channel_index)) 114 | .collect() 115 | } 116 | 117 | #[cfg(test)] 118 | mod tests { 119 | // Note this useful idiom: importing names from outer (for mod tests) scope. 120 | use super::*; 121 | #[test] 122 | fn alias_test() { 123 | let bytes1 = vec![0, 0, 0, 0]; 124 | let bytes2 = vec![1, 1, 1, 1]; 125 | let dimensions = (1, 1); 126 | let sprite1 = InputSprite { 127 | bytes: bytes1, 128 | dimensions, 129 | }; 130 | let sprite2 = InputSprite { 131 | bytes: bytes2, 132 | dimensions, 133 | }; 134 | 135 | let input = vec![sprite1.clone(), sprite1, sprite2]; 136 | let sheets = pack::(input, 4, ()); 137 | 138 | assert_eq!(sheets[0].anchors.len(), 3); 139 | assert_eq!(sheets[0].bytes.len(), 8); 140 | } 141 | 142 | #[test] 143 | fn alias_with_trimming_test() { 144 | let bytes1 = vec![1, 1, 1, 1]; 145 | let bytes2 = vec![1, 1, 1, 1, 1, 1, 1, 0]; 146 | let sprite1 = InputSprite { 147 | bytes: bytes1, 148 | dimensions: (1, 1), 149 | }; 150 | let sprite2 = InputSprite { 151 | bytes: bytes2, 152 | dimensions: (2, 1), 153 | }; 154 | 155 | let input = vec![sprite2.clone(), sprite1.clone(), sprite1, sprite2]; 156 | let input = trim(input.as_slice(), 4, 3); 157 | let sheets = pack::(input, 4, ()); 158 | 159 | assert_eq!(sheets[0].anchors.len(), 4); 160 | assert_eq!(sheets[0].bytes.len(), 4); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /sheep/src/pack/maxrects.rs: -------------------------------------------------------------------------------- 1 | use {Packer, PackerResult, SpriteAnchor, SpriteData}; 2 | 3 | pub struct MaxrectsPacker; 4 | 5 | #[derive(Copy, Clone)] 6 | pub struct MaxrectsOptions { 7 | max_width: u32, 8 | max_height: u32, 9 | } 10 | 11 | impl Default for MaxrectsOptions { 12 | fn default() -> Self { 13 | MaxrectsOptions { 14 | max_width: 4096, 15 | max_height: 4096, 16 | } 17 | } 18 | } 19 | 20 | impl MaxrectsOptions { 21 | pub fn max_width(mut self, width: u32) -> Self { 22 | self.max_width = width; 23 | self 24 | } 25 | 26 | pub fn max_height(mut self, height: u32) -> Self { 27 | self.max_height = height; 28 | self 29 | } 30 | } 31 | 32 | impl Packer for MaxrectsPacker { 33 | type Options = MaxrectsOptions; 34 | 35 | fn pack(sprites: &[SpriteData], options: MaxrectsOptions) -> Vec { 36 | let mut bins = Vec::new(); 37 | let mut oversized = Vec::new(); 38 | 39 | // First, filter out all oversized sprites 40 | let mut sprites = sprites 41 | .iter() 42 | .enumerate() 43 | .filter(|(i, sprite)| { 44 | if sprite.dimensions.0 > options.max_width 45 | || sprite.dimensions.1 > options.max_height 46 | { 47 | oversized.push(MaxRectsBin::oversized(sprite.dimensions, *i)); 48 | false 49 | } else { 50 | true 51 | } 52 | }) 53 | .map(|(_, sprite)| *sprite) 54 | .collect::>(); 55 | 56 | // Now, keep inserting as many as possible into each bin until 57 | // all sprites have been placed. Since all oversized rects have 58 | // already been filtered out, this will always terminate. 59 | while !sprites.is_empty() { 60 | let mut bin = MaxRectsBin::new(options.max_width, options.max_height); 61 | sprites = bin.insert_sprites(&sprites); 62 | bins.push(bin); 63 | } 64 | 65 | bins.extend(oversized.into_iter()); 66 | let result = bins 67 | .into_iter() 68 | .map(|bin| bin.to_result()) 69 | .collect::>(); 70 | 71 | result 72 | } 73 | } 74 | 75 | #[derive(Debug, Clone, Copy, PartialEq)] 76 | struct Rect { 77 | pub min_x: u32, 78 | pub min_y: u32, 79 | pub max_x: u32, 80 | pub max_y: u32, 81 | } 82 | 83 | impl Rect { 84 | pub fn xywh(x: u32, y: u32, width: u32, height: u32) -> Self { 85 | Rect { 86 | min_x: x, 87 | min_y: y, 88 | max_x: x + width, 89 | max_y: y + height, 90 | } 91 | } 92 | 93 | pub fn new(min_x: u32, min_y: u32, max_x: u32, max_y: u32) -> Self { 94 | Rect { 95 | min_x, 96 | min_y, 97 | max_x, 98 | max_y, 99 | } 100 | } 101 | 102 | pub fn contains(&self, other: &Rect) -> bool { 103 | self.min_x <= other.min_x 104 | && self.min_y <= other.min_y 105 | && self.max_x >= other.max_x 106 | && self.max_y >= other.max_y 107 | } 108 | 109 | pub fn no_intersection(&self, other: &Rect) -> bool { 110 | self.min_x >= other.max_x 111 | || self.max_x <= other.min_x 112 | || self.min_y >= other.max_y 113 | || self.max_y <= other.min_y 114 | } 115 | } 116 | 117 | #[derive(Debug, Clone, Copy, PartialEq)] 118 | enum ScoreResult { 119 | NoFit, 120 | FitFound(RectScore), 121 | } 122 | 123 | // NOTE(happenslol): The score represents the leftover 124 | // space in case of a placement, thus _lower is better_ 125 | #[derive(Debug, Clone, Copy, PartialEq)] 126 | struct RectScore { 127 | placement: Rect, 128 | primary: i32, 129 | secondary: i32, 130 | } 131 | 132 | #[derive(Debug, Clone)] 133 | struct MaxRectsBin { 134 | bin_width: u32, 135 | bin_height: u32, 136 | used: Vec<(Rect, usize)>, 137 | free: Vec, 138 | oversized: bool, 139 | } 140 | 141 | impl MaxRectsBin { 142 | pub fn new(width: u32, height: u32) -> Self { 143 | MaxRectsBin { 144 | bin_width: width, 145 | bin_height: height, 146 | used: Vec::new(), 147 | free: vec![Rect::xywh(0, 0, width, height)], 148 | oversized: false, 149 | } 150 | } 151 | 152 | pub fn oversized(dimensions: (u32, u32), index: usize) -> Self { 153 | let used_rect = Rect::xywh(0, 0, dimensions.0, dimensions.1); 154 | 155 | MaxRectsBin { 156 | bin_width: dimensions.0, 157 | bin_height: dimensions.1, 158 | used: vec![(used_rect, index)], 159 | free: vec![], 160 | oversized: true, 161 | } 162 | } 163 | 164 | pub fn to_result(&self) -> PackerResult { 165 | let anchors = self 166 | .used 167 | .iter() 168 | .map(|(rect, id)| SpriteAnchor { 169 | id: *id, 170 | position: (rect.min_x, rect.min_y), 171 | dimensions: (rect.max_x - rect.min_x, rect.max_y - rect.min_y), 172 | }) 173 | .collect::>(); 174 | 175 | let w = anchors 176 | .iter() 177 | .map(|a| a.position.0 + a.dimensions.0) 178 | .max() 179 | .unwrap_or(0); 180 | 181 | let h = anchors 182 | .iter() 183 | .map(|a| a.position.1 + a.dimensions.1) 184 | .max() 185 | .unwrap_or(0); 186 | 187 | PackerResult { 188 | dimensions: (w, h), 189 | anchors, 190 | } 191 | } 192 | 193 | pub fn insert_sprites(&mut self, sprites: &[SpriteData]) -> Vec { 194 | let mut sprites = sprites.iter().cloned().collect::>(); 195 | let mut placed = Vec::new(); 196 | 197 | while !sprites.is_empty() { 198 | // Score all rects and sort them by their score, best score first 199 | let mut placeable = sprites 200 | .iter() 201 | .filter_map(|sprite| { 202 | match self.score_rect(sprite.dimensions.0, sprite.dimensions.1) { 203 | ScoreResult::NoFit => None, 204 | ScoreResult::FitFound(score) => Some((score, *sprite)), 205 | } 206 | }) 207 | .collect::>(); 208 | 209 | // If the placeable list is empty at this point, we can break out and 210 | // return all SpriteDatas we were not able to place 211 | if placeable.is_empty() { 212 | break; 213 | } 214 | 215 | placeable.sort_by_key(|(score, _)| score.primary); 216 | let (score, sprite) = { 217 | // Find out if there's multiple with the best score 218 | let best_scored = placeable 219 | .iter() 220 | .filter(|(score, _)| score.primary == placeable[0].0.primary) 221 | .collect::>(); 222 | 223 | // If not, we have found the next best fit! Othweise, take the 224 | // next best by the secondary score 225 | if best_scored.len() == 1 { 226 | best_scored[0] 227 | } else { 228 | best_scored 229 | .iter() 230 | .min_by_key(|(score, _)| score.secondary) 231 | .expect("Unreachable") 232 | } 233 | }; 234 | 235 | self.place_rect(score.placement, sprite.id); 236 | sprites.retain(|s| s.id != sprite.id); 237 | placed.push(sprite.id); 238 | } 239 | 240 | sprites 241 | } 242 | 243 | pub fn score_rect(&self, width: u32, height: u32) -> ScoreResult { 244 | use std::cmp::{max, min}; 245 | 246 | // We score by best short side fit, since it's the best performing 247 | // strategy according to the reference implementation 248 | let mut best_short = std::u32::MAX; 249 | let mut best_long = std::u32::MAX; 250 | let mut placement = Rect::new(0, 0, 0, 0); 251 | let mut fit_found = false; 252 | 253 | for rect in &self.free { 254 | let other_width = (rect.max_x - rect.min_x) as i32; 255 | let other_height = (rect.max_y - rect.min_y) as i32; 256 | 257 | let leftover_horiz = (other_width - width as i32).abs() as u32; 258 | let leftover_vert = (other_height - height as i32).abs() as u32; 259 | 260 | let short_side_fit = min(leftover_horiz, leftover_vert); 261 | let long_side_fit = max(leftover_horiz, leftover_vert); 262 | 263 | if short_side_fit < best_short 264 | || (short_side_fit == best_short && long_side_fit < best_long) 265 | { 266 | best_short = short_side_fit; 267 | best_long = long_side_fit; 268 | placement = Rect::xywh(rect.min_x, rect.min_y, width, height); 269 | fit_found = true; 270 | } 271 | } 272 | 273 | if !fit_found { 274 | ScoreResult::NoFit 275 | } else { 276 | ScoreResult::FitFound(RectScore { 277 | placement, 278 | primary: best_short as i32, 279 | secondary: best_long as i32, 280 | }) 281 | } 282 | } 283 | 284 | fn place_rect(&mut self, rect: Rect, sprite_id: usize) { 285 | let mut to_process = self.free.len(); 286 | let mut i = 0; 287 | 288 | while i < to_process { 289 | if self.free[i].no_intersection(&rect) { 290 | i += 1; 291 | continue; 292 | } 293 | 294 | let to_split = self.free.swap_remove(i); 295 | self.split_rect(to_split, rect); 296 | to_process -= 1; 297 | } 298 | 299 | remove_redundant_rects(&mut self.free); 300 | self.used.push((rect, sprite_id)); 301 | } 302 | 303 | fn split_rect(&mut self, split: Rect, place: Rect) { 304 | if place.min_x < split.max_x && place.max_x > split.min_x { 305 | // New node at the top side of the placed node. 306 | if place.min_y > split.min_y && place.min_y < split.max_y { 307 | let height = split.max_y - split.min_y; 308 | let new_min_y = place.min_y - split.min_y; 309 | 310 | self.free.push(Rect { 311 | min_y: new_min_y, 312 | max_y: new_min_y + height, 313 | ..split 314 | }) 315 | } 316 | 317 | if place.max_y < split.max_y { 318 | let new_min_y = place.max_y; 319 | let height = split.max_y - place.max_y; 320 | 321 | self.free.push(Rect { 322 | min_y: new_min_y, 323 | max_y: new_min_y + height, 324 | ..split 325 | }); 326 | } 327 | } 328 | 329 | if place.min_y < split.max_y && place.max_y > split.min_y { 330 | // New node at the left side of the placed node. 331 | if place.min_x > split.min_x && place.min_x < split.max_x { 332 | let width = place.min_x - split.min_x; 333 | 334 | self.free.push(Rect { 335 | max_x: split.min_x + width, 336 | ..split 337 | }); 338 | } 339 | 340 | // New node at the right side of the placed node. 341 | if place.max_x < split.max_x { 342 | let new_min_x = place.max_x; 343 | let width = split.max_x - place.max_x; 344 | 345 | self.free.push(Rect { 346 | min_x: new_min_x, 347 | max_x: new_min_x + width, 348 | ..split 349 | }); 350 | } 351 | } 352 | } 353 | } 354 | 355 | fn remove_redundant_rects(rects: &mut Vec) { 356 | let mut i = 0; 357 | while let Some(next) = rects.get(i).cloned() { 358 | // check if it's contained by any other rect 359 | if rects[i + 1..].iter().any(|s| s.contains(&next)) { 360 | // if so, discard it and keep going 361 | rects.swap_remove(i); 362 | continue; 363 | } 364 | 365 | // otherwise, prune all unprocessed rects that are 366 | // contained by our rect and accept it 367 | for j in ((i + 1)..rects.len()).rev() { 368 | if next.contains(&rects[j]) { 369 | rects.swap_remove(j); 370 | } 371 | } 372 | 373 | i += 1; 374 | } 375 | } 376 | 377 | #[cfg(test)] 378 | mod tests { 379 | use super::*; 380 | 381 | #[test] 382 | fn remove_redundant() { 383 | let mut rects = Vec::new(); 384 | for i in 0..10 { 385 | rects.push(Rect::xywh(i * 10, 0, 10, 10)); 386 | rects.push(Rect::xywh(i * 10 + 2, 2, 6, 6)); 387 | } 388 | 389 | assert_eq!(rects.len(), 20); 390 | remove_redundant_rects(&mut rects); 391 | assert_eq!(rects.len(), 10); 392 | 393 | for rect in &rects { 394 | assert_eq!((rect.max_x - rect.min_x), 10); 395 | assert_eq!((rect.max_y - rect.min_y), 10); 396 | } 397 | } 398 | 399 | #[test] 400 | fn pack_regular() { 401 | let mut sprites = (0..10) 402 | .map(|i| SpriteData::new(i, (10, 10))) 403 | .collect::>(); 404 | 405 | let options = MaxrectsOptions::default() 406 | .max_width(10 * 10) 407 | .max_height(10 * 10); 408 | 409 | let result = MaxrectsPacker::pack(&sprites, options); 410 | let first = result.iter().next().expect("should have 1 result"); 411 | 412 | assert_eq!(result.len(), 1); 413 | 414 | // They'll all be packed into 1 column in this example, so they output 415 | // will be shrunk to fit the entire width plus 1 column. 416 | assert_eq!(first.dimensions.0, 10); 417 | assert_eq!(first.dimensions.1, 10 * 10); 418 | 419 | // The new sprite will bu pushed to the next line 420 | sprites.push(SpriteData::new(11, (10, 20))); 421 | let result = MaxrectsPacker::pack(&sprites, options); 422 | let first = result.iter().next().expect("should have 1 result"); 423 | 424 | assert_eq!(first.dimensions.0, 30); 425 | assert_eq!(first.dimensions.1, 100); 426 | } 427 | 428 | #[test] 429 | fn pack_multiple() { 430 | let sprites = (0..500) 431 | .map(|i| SpriteData::new(i, (10, 10))) 432 | .collect::>(); 433 | 434 | let options = MaxrectsOptions::default() 435 | .max_width(10 * 10) 436 | .max_height(10 * 10); 437 | 438 | let result = MaxrectsPacker::pack(&sprites, options); 439 | assert_eq!(result.len(), 5); 440 | } 441 | 442 | #[test] 443 | fn pack_oversized() { 444 | let oversized = (0..1000) 445 | .map(|i| SpriteData::new(i, (100, 100))) 446 | .collect::>(); 447 | 448 | let options = MaxrectsOptions::default() 449 | .max_width(50) 450 | .max_height(50); 451 | 452 | let result = MaxrectsPacker::pack(&oversized, options); 453 | 454 | assert_eq!(result.len(), oversized.len()); 455 | for bin in result { 456 | assert_eq!(bin.dimensions.0, 100); 457 | assert_eq!(bin.dimensions.1, 100); 458 | } 459 | } 460 | } 461 | -------------------------------------------------------------------------------- /sheep/src/pack/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod maxrects; 2 | pub mod simple; 3 | 4 | use {SpriteAnchor, SpriteData}; 5 | 6 | #[derive(Debug, Clone)] 7 | pub struct PackerResult { 8 | pub dimensions: (u32, u32), 9 | pub anchors: Vec, 10 | } 11 | 12 | pub trait Packer { 13 | type Options; 14 | 15 | fn pack(sprites: &[SpriteData], options: Self::Options) -> Vec; 16 | } 17 | -------------------------------------------------------------------------------- /sheep/src/pack/simple.rs: -------------------------------------------------------------------------------- 1 | use std::cmp::{min, Ordering}; 2 | use {Packer, PackerResult, SpriteAnchor, SpriteData}; 3 | 4 | pub struct SimplePacker; 5 | 6 | impl Packer for SimplePacker { 7 | type Options = (); 8 | 9 | fn pack(sprites: &[SpriteData], _options: ()) -> Vec { 10 | let mut sprites = sprites.iter().cloned().collect::>(); 11 | 12 | let mut free = Vec::new(); 13 | let mut absolute = Vec::new(); 14 | 15 | sprites.sort_by(compare_area); 16 | sprites.reverse(); 17 | free.push((0, 0)); 18 | 19 | for sprite in sprites.iter() { 20 | // Push the sprite to the next free anchor 21 | let next_free = *free.first().expect("No free anchor"); 22 | absolute.push(SpriteAnchor::new(sprite.id, next_free, sprite.dimensions)); 23 | 24 | // find new anchors 25 | let mut new_right = (next_free.0 + sprite.dimensions.0, next_free.1); 26 | let mut new_bottom = (next_free.0, next_free.1 + sprite.dimensions.1); 27 | 28 | // still finding new anchors 29 | for i in 1..(free.len() - 1) { 30 | // If we removed an anchor after the first round, 31 | // we might be out of bounds at this point 32 | if i > 1 && i >= free.len() { 33 | break; 34 | } 35 | 36 | if free[i].0 >= free[0].0 && free[i].0 <= new_right.0 { 37 | new_right.1 = min(new_right.1, free[i].1); 38 | free.remove(i); 39 | continue; 40 | } 41 | 42 | if free[i].1 >= free[0].1 && free[i].1 <= new_bottom.1 { 43 | new_bottom.0 = min(new_bottom.0, free[i].0); 44 | free.remove(i); 45 | continue; 46 | } 47 | } 48 | 49 | // remove first, push new anchors 50 | free.remove(0); 51 | 52 | if !free.contains(&new_right) { 53 | free.push(new_right); 54 | } 55 | 56 | if !free.contains(&new_bottom) { 57 | free.push(new_bottom); 58 | } 59 | 60 | free.sort_by(compare_pos); 61 | } 62 | 63 | let width = free 64 | .iter() 65 | .max_by(|a, b| a.0.cmp(&b.0)) 66 | .expect("Invalid: No free anchors") 67 | .0; 68 | 69 | let height = free 70 | .iter() 71 | .max_by(|a, b| a.1.cmp(&b.1)) 72 | .expect("Invalid: No free anchors") 73 | .1; 74 | 75 | // Finally sort the anchors so that they are in the same order as the 76 | // input sprites 77 | absolute.sort_by_key(|s| s.id); 78 | 79 | let result = PackerResult { 80 | dimensions: (width, height), 81 | anchors: absolute, 82 | }; 83 | 84 | vec![result] 85 | } 86 | } 87 | 88 | fn compare_area(a: &SpriteData, b: &SpriteData) -> Ordering { 89 | (a.dimensions.0 * a.dimensions.1).cmp(&(b.dimensions.0 * b.dimensions.1)) 90 | } 91 | 92 | fn compare_pos(a: &(u32, u32), b: &(u32, u32)) -> Ordering { 93 | // NOTE(happenslol): We might overflow here quickly if the output 94 | // sprite becomes too big, so we use u64s. This is why this algorithm 95 | // doesn't scale very well... 96 | let a = (a.0 as u64, a.1 as u64); 97 | let b = (b.0 as u64, b.1 as u64); 98 | 99 | (a.0.pow(4) + a.1.pow(4)).cmp(&(b.0.pow(4) + b.1.pow(4))) 100 | } 101 | 102 | #[cfg(test)] 103 | mod tests { 104 | use super::*; 105 | 106 | #[test] 107 | fn pack_square() { 108 | let sprites = (0..16) 109 | .map(|i| SpriteData::new(i, (20, 20))) 110 | .collect::>(); 111 | 112 | let result = SimplePacker::pack(&sprites, ()); 113 | 114 | assert_eq!(result[0].dimensions.0, 20 * 4); 115 | assert_eq!(result[0].dimensions.1, 20 * 4); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /sheep/src/sprite.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, Clone)] 2 | pub struct InputSprite { 3 | pub bytes: Vec, 4 | pub dimensions: (u32, u32), 5 | } 6 | 7 | impl InputSprite { 8 | pub fn trimmed(&self, stride: usize, alpha_channel_index: usize) -> InputSprite { 9 | let stride = stride as u32; 10 | let alpha_channel_index = alpha_channel_index as u32; 11 | 12 | let mut top_ident = self.dimensions.1; 13 | let mut left_ident = self.dimensions.0; 14 | 15 | // not including right and bottom 16 | let mut right_ident = 0; 17 | let mut bottom_ident = 0; 18 | 19 | 'outer_top: for y in 0..self.dimensions.1 { 20 | let row_offset = y * self.dimensions.0 * stride; 21 | 22 | for x in 0..self.dimensions.0 { 23 | let index = row_offset + x * stride + alpha_channel_index; 24 | if self.bytes[index as usize] != 0 { 25 | left_ident = left_ident.min(x); 26 | right_ident = right_ident.max(x + 1); 27 | top_ident = y; 28 | break 'outer_top; 29 | } 30 | } 31 | } 32 | 33 | // if whole image is transparent, this loop won't run 34 | 'outer_bottom: for y in (top_ident..self.dimensions.1).rev() { 35 | let row_offset = y * self.dimensions.0 * stride; 36 | 37 | // reverse for cache friendliness 38 | for x in (0..self.dimensions.0).rev() { 39 | let index = row_offset + x * stride + alpha_channel_index; 40 | if self.bytes[index as usize] != 0 { 41 | left_ident = left_ident.min(x); 42 | right_ident = right_ident.max(x + 1); 43 | bottom_ident = y + 1; 44 | break 'outer_bottom; 45 | } 46 | } 47 | } 48 | 49 | // image is completly transparent 50 | if top_ident == self.dimensions.1 { 51 | // NOTE: not sure, maybe return non empty image 52 | // in order not to break something unexpectedly? 53 | return InputSprite { 54 | bytes: vec![], 55 | dimensions: (0, 0), 56 | }; 57 | } 58 | 59 | // left ident can only decrease and right ident can only increase, 60 | // so we only look at pixels that can change them 61 | for y in top_ident..bottom_ident { 62 | let row_offset = y * self.dimensions.0 * stride; 63 | for x in 0..left_ident { 64 | let index = row_offset + x * stride + alpha_channel_index; 65 | if self.bytes[index as usize] != 0 { 66 | left_ident = x; 67 | break; 68 | } 69 | } 70 | 71 | for x in (right_ident..self.dimensions.0).rev() { 72 | let index = row_offset + x * stride + alpha_channel_index; 73 | if self.bytes[index as usize] != 0 { 74 | right_ident = x + 1; 75 | break; 76 | } 77 | } 78 | } 79 | 80 | let trimmed_dimensions = (right_ident - left_ident, bottom_ident - top_ident); 81 | let mut trimmed_buffer = create_pixel_buffer(trimmed_dimensions, stride as usize); 82 | for y in 0..trimmed_dimensions.1 { 83 | let sprite_y = (y + top_ident) * self.dimensions.0 * stride; 84 | let trimmed_y = y * trimmed_dimensions.0 * stride; 85 | 86 | for x in 0..trimmed_dimensions.0 { 87 | let sprite_x = (x + left_ident) * stride; 88 | let trimmed_x = x * stride; 89 | 90 | for i in 0..stride { 91 | let sprite_idx = (sprite_y + sprite_x + i) as usize; 92 | let trimmed_idx = (trimmed_y + trimmed_x + i) as usize; 93 | 94 | trimmed_buffer[trimmed_idx] = self.bytes[sprite_idx]; 95 | } 96 | } 97 | } 98 | 99 | InputSprite { 100 | bytes: trimmed_buffer, 101 | dimensions: trimmed_dimensions, 102 | } 103 | } 104 | } 105 | 106 | #[derive(Debug, Clone)] 107 | pub struct Sprite { 108 | pub bytes: Vec, 109 | pub data: SpriteData, 110 | } 111 | 112 | impl Sprite { 113 | pub fn from_input(index: usize, input: InputSprite) -> Sprite { 114 | Sprite { 115 | bytes: input.bytes, 116 | data: SpriteData { 117 | id: index, 118 | dimensions: input.dimensions, 119 | }, 120 | } 121 | } 122 | } 123 | 124 | #[derive(Debug, Clone, Copy)] 125 | pub struct SpriteData { 126 | pub id: usize, 127 | pub dimensions: (u32, u32), 128 | } 129 | 130 | impl SpriteData { 131 | pub fn new(id: usize, dimensions: (u32, u32)) -> Self { 132 | SpriteData { id, dimensions } 133 | } 134 | } 135 | 136 | #[derive(Debug, Clone, Copy)] 137 | pub struct SpriteAnchor { 138 | pub id: usize, 139 | pub position: (u32, u32), 140 | pub dimensions: (u32, u32), 141 | } 142 | 143 | impl SpriteAnchor { 144 | pub fn new(id: usize, position: (u32, u32), dimensions: (u32, u32)) -> Self { 145 | SpriteAnchor { 146 | id, 147 | position, 148 | dimensions, 149 | } 150 | } 151 | } 152 | 153 | pub fn create_pixel_buffer(dimensions: (u32, u32), stride: usize) -> Vec { 154 | let length = (dimensions.0 as usize) * (dimensions.1 as usize) * stride; 155 | (0..length).map(|_| 0).collect::>() 156 | } 157 | 158 | pub fn write_sprite( 159 | buffer: &mut Vec, 160 | dimensions: (u32, u32), 161 | stride: usize, 162 | sprite: &Sprite, 163 | anchor: &SpriteAnchor, 164 | ) { 165 | let stride = stride as u32; 166 | 167 | for y in 0..sprite.data.dimensions.1 { 168 | let sprite_y = y * sprite.data.dimensions.0 * stride; 169 | let buffer_y = (y + anchor.position.1) * dimensions.0 * stride; 170 | 171 | for x in 0..sprite.data.dimensions.0 { 172 | let sprite_x = x * stride; 173 | let buffer_x = (x + anchor.position.0) * stride; 174 | 175 | for i in 0..stride { 176 | let sprite_idx = (sprite_y + sprite_x + i) as usize; 177 | let buffer_idx = (buffer_y + buffer_x + i) as usize; 178 | 179 | buffer[buffer_idx] = sprite.bytes[sprite_idx]; 180 | } 181 | } 182 | } 183 | } 184 | 185 | #[cfg(test)] 186 | mod tests { 187 | use super::*; 188 | 189 | #[test] 190 | fn trim_fully_transparent() { 191 | let dimensions = (2, 2); 192 | let bytes: Vec = [ 193 | [255, 255, 255, 0], 194 | [0, 0, 0, 0], 195 | [127, 127, 127, 0], 196 | [0, 128, 0, 0], 197 | ] 198 | .iter() 199 | .flatten() 200 | .cloned() 201 | .collect(); 202 | 203 | let trimmed_sprite = InputSprite { dimensions, bytes }.trimmed(4, 3); 204 | assert_eq!(trimmed_sprite.bytes.len(), 0); 205 | assert_eq!(trimmed_sprite.dimensions, (0, 0)); 206 | } 207 | 208 | #[test] 209 | fn trim_fully_opaque() { 210 | let dimensions = (2, 2); 211 | let bytes: Vec = [ 212 | [255, 255, 255, 255], 213 | [0, 0, 0, 255], 214 | [127, 127, 127, 255], 215 | [0, 128, 0, 255], 216 | ] 217 | .iter() 218 | .flatten() 219 | .cloned() 220 | .collect(); 221 | 222 | let trimmed_sprite = InputSprite { 223 | dimensions, 224 | bytes: bytes.clone(), 225 | } 226 | .trimmed(4, 3); 227 | assert_eq!(trimmed_sprite.bytes, bytes); 228 | assert_eq!(trimmed_sprite.dimensions, dimensions); 229 | } 230 | 231 | #[test] 232 | fn trim_half_transparent_different_stride() { 233 | let dimensions = (4, 2); 234 | 235 | //input output 236 | // □□■□ □■ 237 | // □■□□ ■□ 238 | let bytes: Vec = [ 239 | // first row 240 | [255, 255, 0, 200], 241 | [0, 35, 0, 0], 242 | [127, 127, 255, 0], 243 | [0, 128, 0, 20], 244 | // second row 245 | [10, 0, 0, 0], 246 | [0, 35, 10, 10], 247 | [20, 30, 0, 0], 248 | [10, 50, 0, 15], 249 | ] 250 | .iter() 251 | .flatten() 252 | .cloned() 253 | .collect(); 254 | 255 | let expected: Vec = [ 256 | // first row 257 | [0, 35, 0, 0], 258 | [127, 127, 255, 0], 259 | // second row 260 | [0, 35, 10, 10], 261 | [20, 30, 0, 0], 262 | ] 263 | .iter() 264 | .flatten() 265 | .cloned() 266 | .collect(); 267 | 268 | let trimmed_sprite = InputSprite { dimensions, bytes }.trimmed(4, 2); 269 | assert_eq!(trimmed_sprite.bytes, expected); 270 | assert_eq!(trimmed_sprite.dimensions, (2, 2)); 271 | } 272 | } 273 | -------------------------------------------------------------------------------- /sheep_cli/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sheep_cli" 3 | version = "0.3.0" 4 | authors = ["Hilmar Wiegand "] 5 | description = "Modular and lightweight spritesheet packer" 6 | keywords = ["sdk", "amethyst", "sprites", "packing", "cli"] 7 | categories = ["game-engines"] 8 | 9 | homepage = "https://amethyst.rs/" 10 | repository = "https://github.com/amethyst/sheep" 11 | 12 | readme = "../README.md" 13 | license = "MIT/Apache-2.0" 14 | 15 | [badges] 16 | travis-ci = { repository = "amethyst/sheep", branch = "master" } 17 | 18 | [dependencies] 19 | serde = "1.0.89" 20 | sheep = { path = "../sheep", version = "0.3.0" } 21 | image = "0.20" 22 | clap = "2.32" 23 | ron = "0.4" 24 | oxipng = "2.2" 25 | png = "0.15" 26 | 27 | [[bin]] 28 | name = "sheep" 29 | path = "src/main.rs" 30 | -------------------------------------------------------------------------------- /sheep_cli/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate clap; 2 | extern crate image; 3 | extern crate ron; 4 | extern crate serde; 5 | extern crate sheep; 6 | 7 | use clap::{App, AppSettings, Arg, SubCommand}; 8 | use serde::Serialize; 9 | use sheep::{ 10 | AmethystFormat, AmethystNamedFormat, InputSprite, MaxrectsOptions, MaxrectsPacker, 11 | SimplePacker, SpriteSheet, 12 | }; 13 | use std::str::FromStr; 14 | use std::{fs::File, io::prelude::*}; 15 | 16 | const DEFAULT_FORMAT: &'static str = "amethyst"; 17 | const DEFAULT_PACKER: &'static str = "maxrects"; 18 | 19 | const AVAILABLE_FORMATS: [&'static str; 2] = ["amethyst", "amethyst_named"]; 20 | const AVAILABLE_PACKERS: [&'static str; 2] = ["simple", "maxrects"]; 21 | 22 | fn main() { 23 | let app = App::new("sheep") 24 | .version(env!("CARGO_PKG_VERSION")) 25 | .author(env!("CARGO_PKG_AUTHORS")) 26 | .about(env!("CARGO_PKG_DESCRIPTION")) 27 | .setting(AppSettings::SubcommandRequiredElseHelp) 28 | .subcommand( 29 | SubCommand::with_name("pack") 30 | .about("Packs supplied images into a spritesheet") 31 | .arg(Arg::with_name("INPUT").required(true).multiple(true)) 32 | .arg( 33 | Arg::with_name("output") 34 | .help("Output filename without file extension") 35 | .short("o") 36 | .long("out") 37 | .takes_value(true) 38 | .required(false) 39 | .default_value("out"), 40 | ) 41 | .arg( 42 | Arg::with_name("packer") 43 | .help("Packing algorithm to use") 44 | .possible_values(&AVAILABLE_PACKERS) 45 | .short("p") 46 | .long("packer") 47 | .takes_value(true) 48 | .required(false) 49 | .default_value(DEFAULT_PACKER), 50 | ) 51 | .arg( 52 | Arg::with_name("format") 53 | .help("Determines the fields present in the serialized output") 54 | .possible_values(&AVAILABLE_FORMATS) 55 | .short("f") 56 | .long("format") 57 | .takes_value(true) 58 | .required(false) 59 | .default_value(DEFAULT_FORMAT), 60 | ) 61 | .arg( 62 | Arg::with_name("options") 63 | .help("Settings that will be passed to the selected packer") 64 | .short("s") 65 | .long("options") 66 | .takes_value(true) 67 | .multiple(true) 68 | .required(false), 69 | ) 70 | .arg( 71 | Arg::with_name("pretty") 72 | .help("The resulting .ron-file is formatted") 73 | .long("pretty") 74 | .required(false), 75 | ) 76 | .arg( 77 | Arg::with_name("trim") 78 | .help("Trim transparent sprite sides") 79 | .short("t") 80 | .long("trim"), 81 | ) 82 | .arg( 83 | Arg::with_name("compress") 84 | .help("Use png compression") 85 | .short("c") 86 | .long("compress"), 87 | ), 88 | ); 89 | 90 | let matches = app.get_matches(); 91 | 92 | match matches.subcommand() { 93 | ("pack", Some(matches)) => { 94 | let input = matches 95 | .values_of("INPUT") 96 | .map(|values| values.map(|it| String::from(it)).collect::>()) 97 | .unwrap_or(Vec::new()); 98 | 99 | let out = matches 100 | .value_of("output") 101 | .expect("Unreachable: param has default value"); 102 | 103 | let mut sprites = load_images(&input); 104 | 105 | if matches.is_present("trim") { 106 | // stride is 4 and alpha index is 3 because rgba8 is used by default 107 | sprites = sheep::trim(sprites.as_slice(), 4, 3); 108 | } 109 | 110 | // NOTE(happenslol): By default, we're using rgba8 right now, 111 | // so the stride is always 4 112 | let results = match matches.value_of("packer") { 113 | Some("maxrects") => { 114 | let max_width = matches 115 | .values_of("options") 116 | .and_then(|mut options| options.find(|o| o.starts_with("max_width"))) 117 | .and_then(|found| found.split("=").nth(1)) 118 | .and_then(|value| value.parse::().ok()) 119 | .unwrap_or(4096); 120 | 121 | let max_height = matches 122 | .values_of("options") 123 | .and_then(|mut options| options.find(|o| o.starts_with("max_height"))) 124 | .and_then(|found| found.split("=").nth(1)) 125 | .and_then(|value| value.parse::().ok()) 126 | .unwrap_or(4096); 127 | 128 | let options = MaxrectsOptions::default() 129 | .max_width(max_width) 130 | .max_height(max_height); 131 | 132 | sheep::pack::(sprites, 4, options) 133 | } 134 | Some("simple") => sheep::pack::(sprites, 4, ()), 135 | _ => panic!("Unknown packer"), 136 | }; 137 | 138 | if results.is_empty() { 139 | panic!("No output was produced"); 140 | } 141 | 142 | let is_single_sheet = results.len() == 1; 143 | 144 | for (i, sheet) in results.iter().enumerate() { 145 | let filename = if i == 0 && is_single_sheet { 146 | String::from(out) 147 | } else { 148 | format!("{}-{:02}", out, i) 149 | }; 150 | 151 | let compress = matches.is_present("compress"); 152 | write_image(&filename, sheet, compress); 153 | 154 | let pretty = matches.is_present("pretty"); 155 | 156 | match matches.value_of("format") { 157 | Some("amethyst_named") => { 158 | let names = get_filenames(&input); 159 | let meta = sheep::encode::(&sheet, names); 160 | write_meta(&filename, meta, pretty); 161 | } 162 | Some("amethyst") => { 163 | let meta = sheep::encode::(&sheet, ()); 164 | write_meta(&filename, meta, pretty); 165 | } 166 | _ => panic!("Unknown format"), 167 | }; 168 | } 169 | } 170 | _ => {} 171 | } 172 | } 173 | 174 | fn get_filenames(input: &[String]) -> Vec { 175 | input 176 | .iter() 177 | .map(|path| { 178 | std::path::PathBuf::from(&path) 179 | .file_stem() 180 | .and_then(|name| name.to_str()) 181 | .map(|name| String::from_str(name).expect("could not parse string from file name")) 182 | .expect("Failed to extract file name") 183 | }) 184 | .collect() 185 | } 186 | 187 | fn load_images(input: &[String]) -> Vec { 188 | input 189 | .iter() 190 | .map(|path| { 191 | let img = image::open(&path).expect("Failed to open image"); 192 | let img_owned; 193 | let img = { 194 | if let Some(img) = img.as_rgba8() { 195 | img 196 | } else { 197 | img_owned = img.to_rgba(); 198 | &img_owned 199 | } 200 | }; 201 | 202 | let dimensions = img.dimensions(); 203 | let bytes = img 204 | .pixels() 205 | .flat_map(|it| it.data.iter().map(|it| *it)) 206 | .collect::>(); 207 | 208 | InputSprite { dimensions, bytes } 209 | }) 210 | .collect() 211 | } 212 | 213 | fn write_image(output_path: &str, sheet: &SpriteSheet, compress: bool) { 214 | let filename = format!("{}.png", output_path); 215 | 216 | let mut png_bytes = Vec::::new(); 217 | { 218 | let mut encoder = png::Encoder::new(&mut png_bytes, sheet.dimensions.0, sheet.dimensions.1); 219 | encoder.set_color(png::ColorType::RGBA); 220 | encoder.set_depth(png::BitDepth::Eight); 221 | encoder.set_compression(png::Compression::Fast); 222 | encoder.set_filter(png::FilterType::NoFilter); 223 | let mut writer = encoder.write_header().expect("Failed to write png header"); 224 | writer 225 | .write_image_data(&sheet.bytes) 226 | .expect("Failed to write png data"); 227 | } 228 | let png_bytes = if compress { 229 | // you can read about presets in oxipng readme on github 230 | // level 2 is sufficently fast on modern CPU's and 231 | // provides 30-50% compression 232 | // higher preset levels execute much (> 6x) slover and 233 | // can only give about 10% additional compression 234 | let options = oxipng::Options::from_preset(2); 235 | oxipng::optimize_from_memory(png_bytes.as_slice(), &options) 236 | .expect("Failed to compress png") 237 | } else { 238 | png_bytes 239 | }; 240 | 241 | let mut file = File::create(filename).expect("Failed to create image file"); 242 | file.write_all(png_bytes.as_slice()) 243 | .expect("Failed to write image to file"); 244 | } 245 | 246 | fn write_meta(output_path: &str, meta: S, pretty: bool) { 247 | let mut meta_file = 248 | File::create(format!("{}.ron", output_path)).expect("Failed to create meta file"); 249 | 250 | let meta_str = if pretty { 251 | ron::ser::to_string_pretty(&meta, ron::ser::PrettyConfig::default()) 252 | } else { 253 | ron::ser::to_string(&meta) 254 | } 255 | .expect("Failed to encode meta file"); 256 | 257 | meta_file 258 | .write_all(meta_str.as_bytes()) 259 | .expect("Failed to write meta file"); 260 | } 261 | --------------------------------------------------------------------------------