Skip to content

.npf image format

james edited this page Apr 25, 2017 · 5 revisions

Overview

NPF images are very lightweight at the expense of available colors. They can be used for Flipnote Thumbnails, simple icons, or even bottom-screen backgrounds by using the table overflow hack

During tests, we found that we could include approximately 21 npfs -- each at 128 x 92 -- on one page without any issues. For comparison, NTFT and TMB images are each limited to 5 per page.

This image format also shares some similarities with the .nbf format

Format documentation

Header

Start Length Type Description
0 4 Magic "UGAR"
4 4 uint32 LE Section count - always 2
8 4 uint32 LE Section 1 (palette data) length
12 4 uint32 LE Section 2 (image data) length

Palette Data

Colors are stored in rgb555 format, so that each color only uses two bytes of data.

The first byte of this section is actually ignored, as palette index 0 is reserved for transparent pixels. As such there are technically only 15 color palette slots available.

Image Data

First, it's important to note that the width of the image is rounded up to the nearest power of 2. For example, an image that is 50 px wide will be padded to 64 px wide when encoded into a .npf. When you include the image in a page using with an <img> tag, just use the original width for the width attribute (in this case, width="50") and the image will be clipped correctly.

[todo - graphic explaining this]

Each pixel of the image is represented by a four-bit ('nibble') integer that refers to the index of the color in the palette section. Again, note that 0 is reserved for transparent pixels and so it ignores whatever you define in the first palette slot.

The nibbles are reversed, so the first nibble of the first byte is the value for pixel #2, and the second nibble is the value for pixel #1.