Palette format

Post Reply
digithree

Palette format

Post by digithree » Wed Jan 12, 2011 10:51 pm

I'm trying to create my own sprite palettes which I can copy over the palette that grit creates but I'm not sure about the format.

The image file I'm using is a 32x32 PNG with a 16 colour indexed palette created with Photoshop. The grit switch file I'm using is

Code: Select all

# Set the warning/log level to 3
-W3
# Tell grit to include a palette (the first index in it will be transparent)
-p
# Tile the image
-gt
# Set the bit depth to 4 (16 colors)
-gB4
I tried to create an array to replace the palette supplied with the grit conversion of my image. I couldn't really find much information on the palette format but in the libnds example "Graphics/Sprites/sprite_extended_palettes/source/template.c" the palette elements seem to be two byte (u16 type) or rather 15 bit colour codes. Apparently you can use the macro RGB15(r,g,b) to create a colour entry (though it might be only for the extended palette, I'm not sure...).

However when I tried copying the following array

Code: Select all

uint16 spherePalRed[16] = { 0, RGB15(29,0,0), RGB15(27,0,0), RGB15(25,0,0),
						RGB15(23,0,0), RGB15(21,0,0), RGB15(19,0,0), RGB15(17,0,0),
						RGB15(15,0,0), RGB15(13,0,0), RGB15(11,0,0), RGB15(9,0,0),
						RGB15(7,0,0), RGB15(5,0,0), RGB15(3,0,0), RGB15(31,0,0) };
with this function call

Code: Select all

dmaCopyHalfWords(SPRITE_DMA_CHANNEL,
                     &spherePalRed,
                     &SPRITE_PALETTE[nextAvailableSpriteNum * COLORS_PER_PALETTE],
                     COLORS_PER_PALETTE);
all sprite pixels, except the pixels set in the PNG as transparent, were black.

I assumed the palette created would have 16 colours but when I looked at the header file it creates, the palette is 256, not 16

Code: Select all

//	sphereWhite, 32x32@4, 
//	+ palette 256 entries, not compressed
//	+ 16 tiles not compressed
//	Total size: 512 + 512 = 1024
So I'm pretty confused. Can anyone in the know help me out?

User avatar
vuurrobin
Posts: 219
Joined: Fri Jul 11, 2008 8:49 pm
Location: The Netherlands
Contact:

Re: Palette format

Post by vuurrobin » Thu Jan 13, 2011 1:20 am

with the dma copy, I think that the second parameter shouldn't have a '&' token. like this:

Code: Select all

dmaCopyHalfWords(SPRITE_DMA_CHANNEL,
                     spherePalRed,
                     &SPRITE_PALETTE[nextAvailableSpriteNum * COLORS_PER_PALETTE],
                     COLORS_PER_PALETTE);

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: Palette format

Post by zeromus » Thu Jan 13, 2011 3:57 am

are you putting the sprite on the main engine? because thats the palette you chose to write to. Are you sure youve assigned that palette to that sprite?

I'm not sure why it would generate a 256 entry palette. that seems weird. but you can do -pn16 to force it to only output 16. be careful that you havent used 16 colors in addition to transparent. you can only have 15 actual colors.

digithree

Re: Palette format

Post by digithree » Thu Jan 13, 2011 10:34 pm

vuurrobin, you were totally right, I was getting the address of the pointer variable I was using instead of using the pointer, basic error! I thought I had the whole concept wrong but after I did that everything worked so turn out it was alright.

Not sure about why the palette size is 256 but it might be to do with Photoshop not creating the right palette. When I reopen the supposedly 16 colour paletted image it's actually got 256 colours... maybe I'm not doing it right. Anyway it doesn't matter too much, I'd like to fix it but not much of Photoshop expert.

Thanks a lot!

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: Palette format

Post by zeromus » Thu Jan 13, 2011 10:47 pm

it hasnt got to do with photoshop, i had already checked it. grit really makes a 256 palette when there are only 16 colors.

WinterMute
Site Admin
Posts: 1858
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Palette format

Post by WinterMute » Fri Jan 14, 2011 12:34 am

it's done that way for 16x16 palettes - grit assumes the palette is already organised as 16x16 and will adjust the palette number in the maps it generates.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 56 guests