A Few Simple Bitmap Exporters

A place for your artistic side. Discuss techniques and tools for pixel art on the NES, GBC, or similar platforms.

Moderator: Moderators

Post Reply
User avatar
segaloco
Posts: 258
Joined: Fri Aug 25, 2023 11:56 am
Contact:

A Few Simple Bitmap Exporters

Post by segaloco »

Hello, I wanted to share a few tools I threw together for my own purposes the past week or so: https://gitlab.com/segaloco/misc/-/tree ... sole_tools

After the link are three tools, chrtobmp, banktobmp, and bgtobmp.

Chrtobmp is the crux of the set and takes a single, 16-byte PPU character on the standard input and spits out a 4bpp indexed color Windows bitmap, either supplying colors from a built-in palette or optionally taking a 4-byte PPU palette binary as an argument. I've only tested it on target aarch64-unknown-linux-gnu, but tried to make it platform and endianness agnostic. One plan I have is to harmonize my bitmap handling routine interfaces with those presented by wingdi.h so that way, if one wanted to, the code could be used with the native bitmap handler on Windows instead, integrated with GDI components, etc. While it is 2C02 character focused, I may try and extend it or use it as a base for other tile formats.

Banktobmp is then a script that uses this, along with ImageMagick's montage tool, to convert a bank of character graphics into a 16x32 bitmap of the tiles. Similarly, an optional palette can be provided, otherwise the underlying default behavior of chrtobmp is used. It's not the most efficient way to go about things, it first converts each tile into an individual 4bpp bitmap ala chrtobmp and *then* uses montage to combine all of those back together. A more efficient approach would convert all of the desired tiles into raw 4bpp but then stand up that whole array under one bitmap immediately, but that would likely require implementation in C or a more general set of bitmap CLI utilities and a pipeable command that *just* does the 2bpp->4bpp conversion

Finally, bgtobmp operates somewhat similarly, but rather than taking a whole list of tiles and building them into a sequential 16x32 map, this tool only extracts a single bank, so just the first 256 tiles provided in the file on the first argument. Like the other tools, an optional palette can be provided as the closing argument. The mapping file, a full 1024 byte 2C02 background map, is then converted into a 32x32 matrix of tiles by bitmap filename which is then supplied as the argument list to montage.

So basically, with a CHR bank in hand (all examples assume default palette):

To extract the first tile as a bitmap:

Code: Select all

dd if=CHR.bin bs=16 skip=0 count=1 | chrtobmp >out.bmp
To extract the fifth tile as a bitmap:

Code: Select all

dd if=CHR.bin bs=16 skip=4 count=1 | chrtobmp >out.bmp
To convert the bank to a 16x32 bitmap:

Code: Select all

banktobmp <CHR.bin >out.bmp
To generate a bitmap of the mapping title_map.bin from the low page of the bank:

Code: Select all

bgtobmp CHR.bin <title_map.bin >out.bmp
High page would obviously just be filtering CHR.bin first to scrape off the low page of characters.

These are not bug free, I haven't done a whole lot of bounds checking or testing with marginal values. Per my license in the repository, banktobmp and bgtobmp are public domain and I disclaim any liabilities. Chrtobmp, on the other hand, is BSD licensed, so the usual terms of that license apply. That said, if you start building some really cool suite of programs using this work, be cool and give credit if you can, or better, reach out, you'll find I'm certainly interested in helping others use what I create, I just make no guarantees that help is going to be what you asked for.

Anywho, feel free to fork, raise a merge, etc. if you want to play with these. Lastly, if you would do anything different, just do it, these are tools I wrote for me, not anyone else, so if they aren't perfect for you, they're open source :)
zzo38
Posts: 1096
Joined: Mon Feb 07, 2011 12:46 pm

Re: A Few Simple Bitmap Exporters

Post by zzo38 »

(Note: Gitlab is not working for me and I do not like Gitlab. So, I have not reviewed your software, other than the description you had provided on here.)

My own "Farbfeld Utilities" software includes programs which can do a similar thing, although it does not currently include a BMP encoder (it does include PNG and some other formats, but you can use ImageMagick to encode BMP if you need to). The file bitff can convert NES/Famicom format (and some other formats) as a single vertical strip of all tiles (you can still use dd like you did, if you want only one tile), and ff-strip can automatically rearrange the tiles into a grid, instead of only vertical arrangement. (It is also FOSS.)
(Free Hero Mesh - FOSS puzzle game engine)
User avatar
segaloco
Posts: 258
Joined: Fri Aug 25, 2023 11:56 am
Contact:

Re: A Few Simple Bitmap Exporters

Post by segaloco »

I'll have to check those out, I like the idea of anything that works well with stdin/stdout, because yeah like you said you can use stuff like dd and split for the concern of chunking a file up rather than also having to implement that sort of thing. Pipeability is one of the guiding principles of little one-shot utilities like this I build lately, then I can just keep stringing them together instead of rewriting the same bits over and over again. The trade off is efficiency but with Moore's Law and such, it makes more sense to focus on simplicity than performance for many applications these days.
Post Reply