rgbds icon indicating copy to clipboard operation
rgbds copied to clipboard

Feature request: More flexible "reverse mode" in rgbgfx

Open Rangi42 opened this issue 3 years ago • 6 comments

I'd like to remove bpp2png.c from our projects and recommend rgbgfx -r, but bpp2png has two conveniences:

  • It can guess a width based on the 2bpp size, or default to 128px, so you don't have to specify one.
  • It can pad an image with blank tiles if the specified width doesn't perfectly divide it, which is not uncommon for images that have had some trailing tiles removed with rgbgfx -x (or gfx.c's --trim-whitespace).

(I also think it's more intuitive to not have to specify -o as the input file, but it arguably makes sense for rgbgfx since -t, -a, and -p all become inputs instead of outputs too.)

Rangi42 avatar Oct 14 '22 20:10 Rangi42

I also think it's more intuitive to not have to specify -o as the input file

The main rationale behind this was that you could simply add -r to a command to reverse it.

evie-calico avatar Oct 14 '22 20:10 evie-calico

Doesn't -x already add blank tiles to the end of the input? If not, maybe that should be added.

As for guessing the input size, unless the image is perfectly square, the guess is at best 50/50. A default width is not appropriate in general, only for a single project. (And even then, you can just specify the flag instead. No?)

ISSOtm avatar Oct 15 '22 08:10 ISSOtm

-x has to specify how many tiles to pad, which you may not know offhand; -r N could just add however many tiles are necessary to make a rectangular image.

Regarding a default width, it could just use "any PNG width that can be re-generated the same way". For example, if you have 4x6-tile PNG and convert it to 2BPP, and you reverse-generate a PNG with "-r auto", it could end up as 4x6, 6x4, 12x2, 1x24, etc; any of those would be accurate to the original data.

Rangi42 avatar Oct 15 '22 15:10 Rangi42

Yes, but my point is that if you specified -x as input, you can also specify the same in "reverse mode".

Those wouldn't be accurate to the original data, since they wouldn't even be the same width.

ISSOtm avatar Oct 15 '22 15:10 ISSOtm

The use case is for when you have a .2bpp from somewhere, and want to view it as a png, without having to check its filesize, divide by 16, and calculate a valid width. (Or use the always-valid but hard-to-view -r 1.) The result is accurate in that it can get the exact same .2bpp back, so for example, you can take a project full of .2bpp files and replace them all with .pngs without breaking the build.

Rangi42 avatar Oct 16 '22 00:10 Rangi42

Then the best guess to take is 1, which is equivalent to -r 1. Is it not sufficient to view the file, press up in the terminal, change the argument to -r, and pick something else?

ISSOtm avatar Oct 16 '22 08:10 ISSOtm

The first half of this was implemented: -r 0 picks a reasonable width for the reversed image.

@ISSOtm A suggestion for the second half: -r 8 -x 0 would set -x to whatever value is needed to make -r 8 work.

Rangi42 avatar Aug 07 '24 00:08 Rangi42

I don't like that idea, because -x 0 is a valid RGBGFX input.

How about: if there aren't a multiple of 8 tiles and no tilemap is specified and -x is not already specified, the error messages also prints help: To proceed anyway with some blank tiles, try passing `-x 4`.

ISSOtm avatar Aug 07 '24 07:08 ISSOtm