Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some small changes #14

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fc4a885
fix string type mismatch
fountainment Aug 31, 2018
0d36471
changes from cherrysoda-engine
fountainment May 2, 2022
6dfa7d5
Binary string options
Nebulaxin May 1, 2023
377bb72
Added time check & switched to C++ 20
Nebulaxin May 1, 2023
4f29670
Added output splitting
Nebulaxin May 4, 2023
e054a9f
Added --nozero option
Nebulaxin May 6, 2023
4611d88
Added linux build
Nebulaxin May 6, 2023
d1391fe
Fixed time measurement
Nebulaxin May 9, 2023
8b3afe3
Updated Readme
Nebulaxin May 9, 2023
601ea05
Small fixes
Nebulaxin May 10, 2023
8080f81
Fixed json and binary format
Nebulaxin May 21, 2023
bc0eb6e
Updated version
Nebulaxin May 28, 2023
3ccdcde
Added width and height options
Nebulaxin Jul 11, 2023
9c35a71
Updated third party libraries, replaced VS with CMake
Nebulaxin Mar 30, 2024
e94c978
Formatted files
Nebulaxin Mar 30, 2024
1e1ddc8
Fixed formatting and JSON output
Nebulaxin Mar 30, 2024
02137da
Fixed paths with backslash
Nebulaxin Apr 2, 2024
bc2973b
Refactored inputs
Nebulaxin Apr 3, 2024
ebc696d
Removed time measurement
Nebulaxin Apr 3, 2024
23d3c14
Removed time.cpp from CMakeLists.txt
Nebulaxin Apr 3, 2024
15addbd
Removed ReadString from binary.cpp
Nebulaxin Apr 3, 2024
1da06f6
Changed ReadShort to use little endian
Nebulaxin Apr 3, 2024
5bfb432
Changed hashing and file reading
Nebulaxin Apr 5, 2024
127d0f8
Added heuristic and stretch options
Nebulaxin Apr 7, 2024
df74943
Fixed output directory
Nebulaxin Apr 7, 2024
e5cded3
Made hashing and bitmap loading recursive
Nebulaxin Apr 8, 2024
c61cdaa
Fixed indentation in help message
Nebulaxin Apr 8, 2024
7133a9a
Fixed JSON format
Nebulaxin Apr 8, 2024
9123023
Fixed bitmap name
Nebulaxin Apr 8, 2024
9f9d453
Updated Readme
Nebulaxin Apr 8, 2024
07817e8
Updated building instructions
Nebulaxin Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
40 changes: 2 additions & 38 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,38 +1,2 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
*.ilk
*.pdb
*.tlog
*.log
Debug/*
Release/*
*.opendb
*.db
*.suo
build
.vscode
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.1.2)

project(crunch VERSION 0.12 LANGUAGES C CXX)

add_executable(crunch
crunch/main.cpp

crunch/third_party/lodepng.cpp
crunch/third_party/MaxRectsBinPack.cpp
crunch/third_party/Rect.cpp

crunch/binary.cpp
crunch/bitmap.cpp
crunch/cli.cpp
crunch/hash.cpp
crunch/options.cpp
crunch/packer.cpp
)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
target_compile_features(crunch PUBLIC cxx_std_20)
177 changes: 135 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# crunch
# crunch v0.13

This is a command line tool that will pack a bunch of images into a single, larger image. It was designed for [Celeste](http://www.celestegame.com/), but could be very helpful for other games.

It is designed using libraries with permissible licenses, so you are able to use it freely in your commercial and non-commercial projects. Please see each source file for its respective copyright and license.

### Features
## Features

- Export XML, JSON, or binary data
- Trim excess transparency
Expand All @@ -16,11 +16,11 @@ It is designed using libraries with permissible licenses, so you are able to use
- Caching to prevent redundant builds
- Multi-image atlas when the sprites don't fit

### What does it do?
## What does it do?

Given a folder with several images, like so:

```
```text
images/
player.png
tree.png
Expand All @@ -29,7 +29,7 @@ images/

It will output something like this:

```
```text
bin/
images.png
images.xml
Expand All @@ -40,7 +40,7 @@ Where `images.png` is the packed image, `images.xml` is an xml file describing w

There is also an option to use a binary format instead of xml.

### Usage
## Usage

`crunch [OUTPUT] [INPUT1,INPUT2,INPUT3...] [OPTIONS...]`

Expand All @@ -50,52 +50,145 @@ For example...

This will output the following files:

```
```text
bin/atlases/atlas.png
bin/atlases/atlas.json
bin/atlases/atlas.hash
```

### Options

| option | alias | description |
| ------------- | ------------- | ------------|
| -d | --default | use default settings (-x -p -t -u)
| -x | --xml | saves the atlas data as a .xml file
| -b | --binary | saves the atlas data as a .bin file
| -j | --json | saves the atlas data as a .json file
| -p | --premultiply | premultiplies the pixels of the bitmaps by their alpha channel
| -t | --trim | trims excess transparency off the bitmaps
| -v | --verbose | print to the debug console as the packer works
| -f | --force | ignore caching, forcing the packer to repack
| -u | --unique | remove duplicate bitmaps from the atlas
| -r | --rotate | enabled rotating bitmaps 90 degrees clockwise when packing
| -s# | --size# | max atlas size (# can be 4096, 2048, 1024, 512, 256, 128, or 64)
| -p# | --pad# | padding between images (# can be from 0 to 16)

### Binary Format

```
[int16] num_textures (below block is repeated this many times)
[string] name
[int16] num_images (below block is repeated this many times)
[string] img_name
[int16] img_x
[int16] img_y
[int16] img_width
[int16] img_height
[int16] img_frame_x (if --trim enabled)
[int16] img_frame_y (if --trim enabled)
[int16] img_frame_width (if --trim enabled)
[int16] img_frame_height (if --trim enabled)
[byte] img_rotated (if --rotate enabled)
## Options

| option | alias | description |
| --------------- | --------------- | --------------- |
| `--default` | `-d` | use default settings (`-x -p -t -u`) |
| `--xml` | `-x` | saves the atlas data as a `.xml` file |
| `--json` | `-j` | saves the atlas data as a `.json` file |
| `--binary` | `-b` | saves the atlas data as a `.bin` file |
| `--size N` | `-s N` | max atlas size (`N` can be `4096`, `2048`, `1024`, `512`, `256`, `128`, or `64`) |
| `--width N` | `-w N` | max atlas width (overrides `--size`) (`N` can be `4096`, `2048`, `1024`, `512`, `256`, `128`, or `64`) |
| `--height N` | `-h N` | max atlas height (overrides `--size`) (`N` can be `4096`, `2048`, `1024`, `512`, `256`, `128`, or `64`) |
| `--pad N` | `-pd N` | padding between images (`N` can be from `0` to `16`) |
| `--stretch N` | `-st N` | makes images' edges stretched by N pixels (`N` can be from `0` to `16`) |
| `--premultiply` | `-p` | premultiplies the pixels of the bitmaps by their alpha channel |
| `--unique` | `-u` | remove duplicate bitmaps from the atlas |
| `--trim` | `-t` | trims excess transparency off the bitmaps |
| `--rotate` | `-r` | enabled rotating bitmaps 90 degrees clockwise when packing |
| `--heuristic` | `-hr` | use specific heuristic rule for packing images (`H` can be `bssf` (BestShortSideFit), `blsf` (BestLongSideFit), `baf` (BestAreaFit), `blr` (BottomLeftRule), `cpr` (ContactPointRule)) |
| `--binstr T` | `-bs T` | string type in binary format (`T` can be: `0` - null-termainated, `16` - prefixed (int16), `7` - 7-bit prefixed) |
| `--force` | `-f` | ignore caching, forcing the packer to repack |
| `--verbose` | `-v` | print to the debug console as the packer works |
| `--time` | `-tm` | use file's last write time instead of its content for hashing |
| `--split` | `-sp` | split output textures by subdirectories |
| `--nozero` | `-nz` | if there's only one packed texture, then zero at the end of its name will be omitted (ex. `images0.png` -> `images.png`) |

## Binary Format

```text
crch (0x68637263 in hex or 1751347811 in decimal (little endian))
[int16] version (current version is 0)
[byte] --trim enabled
[byte] --rotate enabled
[byte] string type (0 - null-termainated, 1 - prefixed (int16), 2 - 7-bit prefixed)
[int16] num_textures (below block is repeated this many times)
[string] name
[int16] num_images (below block is repeated this many times)
[string] img_name
[int16] img_x
[int16] img_y
[int16] img_width
[int16] img_height
[int16] img_frame_x (if --trim enabled)
[int16] img_frame_y (if --trim enabled)
[int16] img_frame_width (if --trim enabled)
[int16] img_frame_height (if --trim enabled)
[byte] img_rotated (if --rotate enabled)
```

### License
## Splitting

Unless otherwise specified in a source file, everything in this project falls under the following license:
If `--split` (or `-sp`) is enabled output textures will be split by subdirectories.

For example:

`crunch bin/images images -b -sp` with input images

```text
images/
chars/
player.png
enemy.png
other/
tree.png
box.png
```

will output

```text
bin/
images_chars.png (with player.png and enemy.png)
images_chars.hash
images_chars.bin
images_other.png (with tree.png and box.png)
images_other.hash
images_other.bin
images.bin
```

If `player.png` is the only changed image then only `images_chars.bin` will be packed
and `images_other.bin` will be reused in `images.bin`.

This can be used for faster packing: unchanged subdirectories will be skipped
instead of packing unchanged images.

But there're some limitations:

- multiple inputs and images as inputs are not supported
- images in input directory itself will be ignored and not packed

## Building

### Windows

Create `build` directory:

```text
mkdir build
cd build
```

- Visual Studio:

```text
cmake -DCMAKE_BUILD_TYPE=Release ..
```

- MinGW:

```text
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=C:/your/mingw/path/gcc.exe -DCMAKE_CXX_COMPILER=C:/your/mingw/path/g++.exe -G "MinGW Makefiles" ..
```

Build command is same for both:

```text
cmake --build . --config Release
```

### Linux

```text
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
```

## License

Unless otherwise specified in a source file, everything in this project falls under the following license:

```text
MIT License

Copyright (c) 2017 Chevy Ray Johnston
Expand Down
28 changes: 0 additions & 28 deletions crunch.sln

This file was deleted.

Loading