png2chr, chr2png

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

Moderator: Moderators

Post Reply
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

png2chr, chr2png

Post by calima »

Cheers forum. I work on Linux, there were close to no tools, so I wrote a png2chr converter and its reverse. I did find python scripts for that, but who uses python :P

https://github.com/clbr/nes

With this I can edit in gimp/mtpaint and be happy. It uses the palette index directly - palette 0 is bg, 1, 2 and 3 are passed on as-is. Save the PNG as indexed, and it will be accepted if it has 4 or less colors total.

Probably will run on Windows as-is, but again, who uses that. It's quite sad most tools are closed source and provided for Windows only.
Memblers wrote:And something like a PNG2CHR converter hopefully could be provided in exe format.
Rahsennor
Posts: 479
Joined: Thu Aug 20, 2015 3:09 am

Re: png2chr, chr2png

Post by Rahsennor »

I knew there had to be other NES enthusiasts on Linux. Cheers. :beer: :)

I got started on writing some tools of my own before I got sidetracked by the lack of a decent NSF player, but all I have to show for it is a simple nametable viewer (no editing yet; I've been using NESST in Wine) and a tool to convert nametables into the map format used by my scrolling engine. If I ever do get anything done, I'll be sure to share it.
lidnariq
Posts: 11430
Joined: Sun Apr 13, 2008 11:12 am

Re: png2chr, chr2png

Post by lidnariq »

My own analog (uses PGMs instead): viewtopic.php?p=117763#p117763
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: png2chr, chr2png

Post by tepples »

A little bit of code review:

Code: Select all

if (cols * rows > 512) die("Too large to fit in the 8kb CHR ROM\n")
This limit is unnecessary for three reasons: MMC, CHR RAM, and post-processing tools that generate a nametable.

Code: Select all

if (pix > 3) die("Palette has too many colors (%u) at %u,%u\n", pix, x, y);
But why? I want to use colors 5, 6, 7, 9, 10, 11, 13, 14, and 15 to remind myself of in which palette a particular object should be drawn.

Do you plan on adding 8x16 tile support or support for CHR formats other than that of the NES? Because I wrote a converter in Python that uses format strings: NES is 0;1, Game Boy is 0;1, SMS is 0,1,2,3, Genesis is 3210, Super NES is 0,1;2,3, Super NES 3-bit is 0,1;2, Mode 7 is 76543210, etc. It's included with my project templates for NES and Super NES.
Rahsennor wrote:I knew there had to be other NES enthusiasts on Linux.
I use Xubuntu.
Rahsennor wrote:I got started on writing some tools of my own before I got sidetracked by the lack of a decent NSF player
Let me guess: You're on Fedora, and you're feeling Red Hat's fear of Nintendo's legal department. Here on Debian family distributions, I can just sudo apt-get install fceux and then fceux Thwaite.nsf.
Rahsennor
Posts: 479
Joined: Thu Aug 20, 2015 3:09 am

Re: png2chr, chr2png

Post by Rahsennor »

tepples wrote:I use Xubuntu.
Me too, until I got tired of Canonical breaking everything they possibly could and switched to Debian. It's missing some bells and whistles, but at least I can expect the programs in the official repositories to actually work. :roll:
tepples wrote:Let me guess: You're on Fedora, and you're feeling Red Hat's fear of Nintendo's legal department. Here on Debian family distributions, I can just sudo apt-get install fceux and then fceux Thwaite.nsf.
I have a lot of homebrew NSFs in my collection that use non-standard rates. Otherwise, yes, FCEUX does the trick. I prefer blargg's synth, but it's woefully broken, and I can't make heads or tails out of the source to fix it myself.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: png2chr, chr2png

Post by calima »

tepples wrote:

Code: Select all

if (cols * rows > 512) die("Too large to fit in the 8kb CHR ROM\n")
This limit is unnecessary for three reasons: MMC, CHR RAM, and post-processing tools that generate a nametable.
Yes, but my current project does not use any mappers or tricks, only the basic nes cart. So I want it to bail if too large, by default - maybe options could be added for other settings.

Code: Select all

if (pix > 3) die("Palette has too many colors (%u) at %u,%u\n", pix, x, y);
But why? I want to use colors 5, 6, 7, 9, 10, 11, 13, 14, and 15 to remind myself of in which palette a particular object should be drawn.
The assumption is that there is an error in the image in that case, and the output would be broken/unexpected.
Do you plan on adding 8x16 tile support or support for CHR formats other than that of the NES? Because I wrote a converter in Python that uses format strings: NES is 0;1, Game Boy is 0;1, SMS is 0,1,2,3, Genesis is 3210, Super NES is 0,1;2,3, Super NES 3-bit is 0,1;2, Mode 7 is 76543210, etc. It's included with my project templates for NES and Super NES.
Not at the moment.


OT, but how can I get famitone2-compatible music created? I don't trust the closed binaries enough to run them in Wine, only in a no-network VM, and that's too much of a PITA to set up for anything NT-based (3.11 and 9x are small enough to not take gigs of space and hours to install, but I don't think famitracker would run?). Seems no DOS tracker can export to it either.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: png2chr, chr2png

Post by calima »

Just confirming that Famitracker requires XP minimum. Sigh.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: png2chr, chr2png

Post by tepples »

Continuing security updates require Vista minimum. If you're stuck on Windows 98, I recommend using FamiTracker in Wine in Linux. How is FamiTracker "closed binaries"? Is it that building the project from its source archive requires the use of a non-free compiler, and you're worried about a backdoored compiler? And how is Wine in Linux in a VM unacceptable?
User avatar
mikejmoffitt
Posts: 1353
Joined: Sun May 27, 2012 8:43 pm

Re: png2chr, chr2png

Post by mikejmoffitt »

I'm sensing a bitterness towards Windows here. I'd rather not use it, but if there's a tool you need that requires it and you aren't willing to port or reimplement it on your own, then what's the problem with using WINE? Part of my development workflow for my game (unfortunately) has one script that uses WINE to run a few conversion tools that aren't easily brought to Linux. If this is a matter of security concerns, reconsider the appropriateness of this paranoia high level of security consciousness for what you're doing.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: png2chr, chr2png

Post by tepples »

For what it's worth:

Today, while working on this, I discovered the FamiTone2 tools work correctly in Wine. So if you can spin up a Linux instance with Wine, there shouldn't be much of a problem.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: png2chr, chr2png

Post by calima »

Oh I already setup an XP VM. Took only an hour to install and 5 gigs of space, such efficiency.

@mikejmoffitt

I've been on the dark side in a past life, I know what can be done. So, nowadays I do not allow anything untrusted access to my data, or the network.

@tepples

I had read reports that FamiTracker did not fully work in Wine, that it crashed occasionally and sometimes did not play all sounds. That would have prevented a Linux VM with Wine.

The source being available does not mean the binary corresponds to the published source. That combined with the reports it does not work in Wine fully meant building it myself would not have been useful.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: png2chr, chr2png

Post by tepples »

calima wrote:I had read reports that FamiTracker did not fully work in Wine
How many years old were those reports? The version of Wine in Ubuntu 14.04 LTS runs it fine. Though I had to turn down the frequency and turn up the buffer length to get things like ModPlug Tracker and FamiTracker to run, I'm not sure whether that's a Wine bug or a limit of the 1-core, 2-thread Atom N450 CPU in my laptop.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: png2chr, chr2png

Post by calima »

Small flexibility update, and added an identical tiles checker. It immediately pointed out my current font has an identical 0 and O, tsk tsk.

@tepples

Many reports, but yeah, possibly old.
Post Reply