tile and sub palette sorting

Talk about anything else you want

Moderator: BigEvilCorporation

Post Reply
tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

tile and sub palette sorting

Post by tomaitheous » Tue Jan 06, 2009 6:41 am

I'm currently working a project that requires sorting palette association to tiles. I have 1400 tiles for the first level that sit in VRAM.

My dilemma was that I did not create these tiles myself. This is a port project and the source is a huge bitmap file. Isolating which sub palettes wasn't too hard, but trying to identify 8x8 tiles from a group of 1400 is. A lot of them look similar and share colors, but the slight difference make identifying them near impossible.

I came up with a method to embedded the sub palette into the RGB data.

It works like this:

For 9bit RGB you have a total of 8 steps when translating to 24bit RGB.

n=0 to 7. step=32-26.
converted_value=n*step.

Normally one would use a step of 36 as it maps closer to whats on the real hardware luminance wise. But what if you embed small differences in the steps?

Code: Select all

array = { 0,0,0
          0,0,1
          0,1,0
          1,0,0
          //etc 
          }  
so now you have:

Code: Select all

 If(n>0) { converted_value=n*(36-array[(sub_pal*3)+i]); }
 else { converted_value=array[(sub_pal*3)+i]; }
i = red(0), green(1), or blue(2).

Now, you output each sub palettes as a single palette file and you also create one large palette file from all the 16color sub palette files. Each sub palette entry would indexed by 16 colors.

Now, with the individual sub palettes - you force the specific tileset to the new colors. If it's PS, just load a custom palette back into the indexed colored image to replace with the new values. Do this for all the tiles. Whether it's a large single picture or just multiple tilesets, combine layers into a single one and convert to indexed color with 'custom'. Use the master palette you created and the app should automatically assign the pixel colors to the correct palette index.

When converting the 8bit pixel data to 4bit, the lower 4bit will be direct pixel # and the upper 4bit will be the sub palette #. Easy peasy pumpkin pie.

This was very helpful for me when using mappy too, since it doesn't mess with the palette or pixel order. Just be aware mappy will 'miss' some tiles when removing redundant ones because the upper 4bits of the pixel data. So you'll need to run another pass externally for your conversion util after you converted the tiles to 4bit pixel format.

Post Reply