Packing a PNG image into a GB ROM (and vice versa)

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
tepples
Posts: 21802
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Packing a PNG image into a GB ROM (and vice versa)

Post by tepples » Mon Oct 01, 2018 9:08 pm

I've managed to produce a file that's a valid GB ROM (tested on my GB Pocket) and a valid PNG image.
This is a ROM.
This is a ROM.
gbpng.gb.png (32 KiB) Viewed 4926 times
Rules: Only RST $28, $30, and $38 may be used, not $00-$20, and $28 must start with LD L,L. There must also be enough free space at the end of the ROM to hold the PNG.
Attachments
gbpng-0.01.zip
This is a source code.
(30.83 KiB) Downloaded 264 times

nocash
Posts: 1113
Joined: Fri Feb 24, 2012 12:09 pm
Contact:

Re: Packing a PNG image into a GB ROM

Post by nocash » Tue Oct 02, 2018 6:29 am

Impressive, but the 32Kbyte PNG file is larger than a 160x144pix BMP file? Does it support compressed PNG's, too? Ah, no, got it! It is compressed, with the 32kbyte "png" file containing the decompressor code in first some bytes, and the main part of the image at offset 4000h..4603h? I always thought .gif would compress better at low color depths, but that PNG is actually smaller than the same image stored as 4bpp GIF.

Now I am wondering what happens if you open the image in your gameboy's email client... no, no, never ever never open email attachments on your gameboy ; )

tepples
Posts: 21802
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Packing a PNG image into a GB ROM

Post by tepples » Tue Oct 02, 2018 7:06 am

nocash wrote:Impressive, but the 32Kbyte PNG file is larger than a 160x144pix BMP file?
Yes. The PNG file contains the ROM in a prGm chunk.
nocash wrote:It is compressed, with the 32kbyte "png" file containing the decompressor code in first some bytes, and the main part of the image at offset 4000h..4603h?
It actually stores two copies of the image: one for the GB to display, compressed with a less space-efficient but more time-efficient codec, and one for PNG viewers to display. The GB ignores the PNG, and PNG viewers ignore the program. The PNG and the pic inside the ROM can look different and usually will in practice. It can be used, for example, to embed a screenshot into the last 4K of a game. Or it can be used to upload (say) yet another port of Magic Floor to forums whose file type whitelist is authoritarian, but not so much that they recompress all uploaded images. I just made them the same because I was lazy time constrained.

Speaking of which, I've got a couple questions about Magic Floor that I'll take to private messages.

Post Reply