Question on RLE

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
johnnystarr
Posts: 22
Joined: Thu Dec 27, 2012 8:15 pm

Question on RLE

Post by johnnystarr »

My RLE idea is to store 2x2 meta tiles for my backgrounds. The idea I came up with is to have the left nibble
be the repeat number and the right nibble to be the tile number. Instead of the right nibble being 0 - F, it would
be 0-9. A-F in the right nibble would be a bank switch for the 10 tileset.

Code: Select all

bg:
   .db $0A ; bank A
   .db $F3 ; draw tile number 3 from bank A 16 times
   .db $0B ; bank B
   .db $82 ; draw tile number 2 from bank B 8 times
   .db $83 ; draw tile nubmer 3 from bank B 8 times
Of course, I will probably want to draw vertical columns because it will be a side scroller.

The reason for this post is that I'm not sure if I am taking the correct approach here. I have seen links to packBits
elsewhere, but I haven't tested yet.

The goal is to get the most compressed nametables possible because I am running NROM for now.

Thanks,
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Question on RLE

Post by Dwedit »

Using 4 bits for the number of tiles and 4 bits for the tile number isn't that new, Zelda 2 and Dragon Warrior were doing exactly that. But they did it horizontally, not vertically.
But using A-F as tile numbers to select a bank is a waste of encoding space, since the length isn't used anymore.

Suggestions:
0-D = tiles
E = repeat whatever was in the previous column, use the length# for the number of tiles to take.
F = switch bank of 14 tiles, use length as the bank number instead of a length.

Or throw out vertical RLE entirely, and use reusable big blocks of metatiles, such as 4x4 metatiles, or 8x8 metatiles.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Re: Question on RLE

Post by 3gengames »

You can use the top 2 bits to identify a bank for a tile since they won't be used and then pull the attributes from a table in said bank. Or sacrafice the first few metatiles as operators for the bank changes, so 0-3 would be bank switches and then 4 to 255 would be the attribute-4. I myself would either use the top 2 bits as the attribute and let the LEVEL data contain the bank used for the level of metatiles. If that was not an option, I'd probably choose the "pull attribute from bank" and let the top 2 bits signify the bank.

And as for horizontal compression, I'd say a dictionary-based scheme (With RLE encoded entries?) would provide best size/level size ratio. If you keep standard metatiles (for floor, blank, etc.) you can even re-use lots of the strips on the screen. :) Just a few ideas, hope they help.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Question on RLE

Post by tokumaru »

johnnystarr wrote:The goal is to get the most compressed nametables possible
You will certainly not get that with RLE. Throw it a simple checkerboard pattern and RLE won't compress a single bit, it will probably expand the data, actually. If you want better compression you must have a way to repeat patterns longer than 1 symbol.
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Re: Question on RLE

Post by Bregalad »

You should check my CompressTools, which have about 7-8 different compression schemes available. By default it compresses data using all the algorithms, and display info so you can see the ones which works the best for your data.

What you describe is not new, it is what I call "Bitpack RLE". What you describe is a particular case where the data is 4 bit and run length is 4 bit, but the same concept can apply from 1 bit of data + 7 bit of run lenght to 7 bit of data + 1 bit of run length (in this case it's either a single byte or a run of 2).
Post Reply