Skip to content

Commit

Permalink
-th and -tv options in PNG2SPR
Browse files Browse the repository at this point in the history
  • Loading branch information
theNestruo committed Dec 7, 2024
1 parent 5de6fb0 commit 98c6ed0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelog.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Version history

* 07/12/2024 v3.5
* -th and -tv options in `PNG2SPR`
* 18/08/2024 v3.4
* LodePNG updated to latest version (20230410)
* 06/02/2023 v3.3.1
Expand Down
4 changes: 3 additions & 1 deletion readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ Order of options is non important. Unknown options will be silently ignored. If

* `-8` generate 8x8px sprites
Output is adjusted so it can be used in 8x8px sprites modes
* ` -h` generate half sprites (8x16px, 16b per sprite)
* `-h` generate half sprites (8x16px, 16b per sprite)
Processing order is adjusted so multicolored sprites are grouped by half sprites (8px width, 16px height)
* `-hl` lower colors will have higher priority planes (default)
* `-lh` higher colors will have higher priority planes
These two options allow some control on how the colors get ordered (namely, to avoid the flickering routines make flicker the brigther colors)
* `-th` traverse spritesheet horizontally, then vertically (default)
* `-tv` traverse spritesheet vertically, then horizontally

### PNG2SPR+ only

Expand Down
20 changes: 17 additions & 3 deletions src/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void sprWriterOptions() {
printf("\t-h\tgenerate half sprites (8x16px, 16b per sprite)\n");
printf("\t-lh\tlower colors will have higher priority planes (default)\n");
printf("\t-hl\thigher colors will have higher priority planes\n");
printf("\t-th\ttraverse spritesheet horizontally, then vertically (default)\n");
printf("\t-tv\ttraverse spritesheet vertically, then horizontally\n");
}

void sprWriterInit(struct stSprWriter *this, int argc, char **argv) {
Expand All @@ -42,6 +44,10 @@ void sprWriterInit(struct stSprWriter *this, int argc, char **argv) {
(argEquals(argc, argv, "-lh") != -1) ? 1
: (argEquals(argc, argv, "-hl") != -1) ? -1
: 1;
this->traverseHorizontally =
(argEquals(argc, argv, "-th") != -1) ? 1
: (argEquals(argc, argv, "-tv") != -1) ? 0
: 1;
}

void sprWriterReadSprites(struct stSprWriter *this, struct stBitmap *bitmap) {
Expand All @@ -51,9 +57,17 @@ void sprWriterReadSprites(struct stSprWriter *this, struct stBitmap *bitmap) {

int y, x;
struct stSpriteGroup *it;
for (y = 0, it = this->groups; (y + this->spriteHeight) <= bitmap->height; y += this->spriteHeight) {
for (x = 0; (x + this->spriteWidth) <= bitmap->width; x += this->spriteWidth, it++) {
processSpriteGroup(this, it, bitmap, x, y);
if (this->traverseHorizontally) {
for (y = 0, it = this->groups; (y + this->spriteHeight) <= bitmap->height; y += this->spriteHeight) {
for (x = 0; (x + this->spriteWidth) <= bitmap->width; x += this->spriteWidth, it++) {
processSpriteGroup(this, it, bitmap, x, y);
}
}
} else {
for (x = 0, it = this->groups; (x + this->spriteWidth) <= bitmap->width; x += this->spriteWidth) {
for (y = 0; (y + this->spriteHeight) <= bitmap->height; y += this->spriteHeight, it++) {
processSpriteGroup(this, it, bitmap, x, y);
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ struct stSprWriter {
// Data container
struct stSpriteGroup *groups;
int groupCount;

// Arguments
int spriteWidth;
int spriteHeight;
int colorOrder;
int traverseHorizontally;
};

/* Function prototypes ----------------------------------------------------- */

// Supported arguments:
// -8 generate 8x8px sprites
// -h generate half sprites (8x16px, 16b per sprite
// -h generate half sprites (8x16px, 16b per sprite)
// -hl lower colors will have higher priority planes (default)
// -lh higher colors will have higher priority planes
void sprWriterOptions();

void sprWriterInit(struct stSprWriter *instance, int argc, char **argv);
Expand Down
1 change: 1 addition & 0 deletions test/verticalsprites-th.png.spr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!1A#3C"2B$4D
1 change: 1 addition & 0 deletions test/verticalsprites-tv.png.spr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!1A"2B#3C$4D
Binary file added test/verticalsprites.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 98c6ed0

Please sign in to comment.