From 98c6ed0308426eeabde24d739ca31b07637f5498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9stor=20Sancho?= Date: Sat, 7 Dec 2024 11:15:05 +0100 Subject: [PATCH] -th and -tv options in `PNG2SPR` --- changelog.MD | 2 ++ readme.MD | 4 +++- src/sprite.c | 20 +++++++++++++++++--- src/sprite.h | 7 +++++-- test/verticalsprites-th.png.spr | 1 + test/verticalsprites-tv.png.spr | 1 + test/verticalsprites.png | Bin 0 -> 416 bytes 7 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 test/verticalsprites-th.png.spr create mode 100644 test/verticalsprites-tv.png.spr create mode 100644 test/verticalsprites.png diff --git a/changelog.MD b/changelog.MD index 9845b20..b345f73 100644 --- a/changelog.MD +++ b/changelog.MD @@ -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 diff --git a/readme.MD b/readme.MD index a1c6cb4..84f7960 100644 --- a/readme.MD +++ b/readme.MD @@ -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 diff --git a/src/sprite.c b/src/sprite.c index a2fca50..251e2c4 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -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) { @@ -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) { @@ -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); + } } } } diff --git a/src/sprite.h b/src/sprite.h index 03123fa..066a890 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -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); diff --git a/test/verticalsprites-th.png.spr b/test/verticalsprites-th.png.spr new file mode 100644 index 0000000..af85b06 --- /dev/null +++ b/test/verticalsprites-th.png.spr @@ -0,0 +1 @@ +!1A#3C"2B$4D \ No newline at end of file diff --git a/test/verticalsprites-tv.png.spr b/test/verticalsprites-tv.png.spr new file mode 100644 index 0000000..43af65f --- /dev/null +++ b/test/verticalsprites-tv.png.spr @@ -0,0 +1 @@ +!1A"2B#3C$4D \ No newline at end of file diff --git a/test/verticalsprites.png b/test/verticalsprites.png new file mode 100644 index 0000000000000000000000000000000000000000..1b960474d1b059e22d371c81cdb1f88c66f39273 GIT binary patch literal 416 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;R0X`wF4h|0g|NqZSn|c%|!dc)ESb$b#xJG%x_k*35eH`|Qy$dmz)+)5S4Fx3__l6hDrIZjBrxR~eGF|~-bzvR;$1YU`H a%ROSq6lZyBe@z?|$_$>aelF{r5}E)qxLoD{ literal 0 HcmV?d00001