segaloco
Experienced Member
- Joined
- Apr 30, 2023
- Messages
- 483
Wanted to share a little utility I put together that'll be part of a growing toolchain. The tool is "chrtopng" and can be found here: https://gitlab.com/segaloco/misc/-/blob/master/2C02_tools/chrtopng.c
There is a manual page along with it in the repo. It's the next version of the BMP tools found in the same directory, with the latter being less generalized. I wanted to revamp the interface of that tooling anyway and figured a format with native 2bpp was the way to go.
Anywho, a plethora of examples are available in another thread here: https://forums.nesdev.org/viewtopic.php?t=25701
The short of it is though this utility will take any number of NES PPU (Ricoh 2C02) character tiles from an input file and create a 2bpp indexed PNG on the standard output. A default palette is provided but one can also be given as a file.
Additionally, by default a row is defined as 16 tiles wide, the image will wrap if more than 16 tiles are provided, although this can be adjusted via an option. Finally, the maximum number of tiles processed is also capped at 256 by default, this is used to size a fixed-size buffer. This can be raised or lowered, although the image is generally sized only as large as it needs to be to display the passed data, if it is shy of the maximum, a smaller image is produced.
The linked thread contains numerous examples but one case is inspecting a portion of a larger bank of tiles. Knowing the coordinates of a tile, one can use dd(1) to first pare down a BLOB and then chrtopng to convert the results. Then further tooling can act on that PNG:
This also demonstrates the palette and row width options.
Anywho, it's BSD licensed, I was lazy and haven't provided build instrumentation, my command-line is:
My thought is folks who may find this useful can probably figure out how to build a libpng consumer. The larger toolset I'll be putting together around this and some other low-level bits will have a more conventional build provision.
Anywho, enjoy!
P.S. Wasn't sure if this was the best place for it. Out of the various descriptions this feels most like a tool.
There is a manual page along with it in the repo. It's the next version of the BMP tools found in the same directory, with the latter being less generalized. I wanted to revamp the interface of that tooling anyway and figured a format with native 2bpp was the way to go.
Anywho, a plethora of examples are available in another thread here: https://forums.nesdev.org/viewtopic.php?t=25701
The short of it is though this utility will take any number of NES PPU (Ricoh 2C02) character tiles from an input file and create a 2bpp indexed PNG on the standard output. A default palette is provided but one can also be given as a file.
Additionally, by default a row is defined as 16 tiles wide, the image will wrap if more than 16 tiles are provided, although this can be adjusted via an option. Finally, the maximum number of tiles processed is also capped at 256 by default, this is used to size a fixed-size buffer. This can be raised or lowered, although the image is generally sized only as large as it needs to be to display the passed data, if it is shy of the maximum, a smaller image is produced.
The linked thread contains numerous examples but one case is inspecting a portion of a larger bank of tiles. Knowing the coordinates of a tile, one can use dd(1) to first pare down a BLOB and then chrtopng to convert the results. Then further tooling can act on that PNG:
This also demonstrates the palette and row width options.
Anywho, it's BSD licensed, I was lazy and haven't provided build instrumentation, my command-line is:
Code:
cc -O2 -I/usr/include/libpng16 -o chrtopng chrtopng.c -lpng
My thought is folks who may find this useful can probably figure out how to build a libpng consumer. The larger toolset I'll be putting together around this and some other low-level bits will have a more conventional build provision.
Anywho, enjoy!
P.S. Wasn't sure if this was the best place for it. Out of the various descriptions this feels most like a tool.
