forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using Color Palletes in psp

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Tue Jul 07, 2009 2:19 pm    Post subject: Using Color Palletes in psp Reply with quote

i'm about to start learning textures and they show how to load a text and set it as the texture i get that so far but what if i have an image like a gif or png that has a pallete how do i display that and i'm also not to familiar with palletes anyway could someone point me in the right direction because wiki doesnt seem to have much info on color palletes or i'm searching for it wrong because i'd like to know how they work
Back to top
View user's profile Send private message MSN Messenger
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Jul 08, 2009 1:52 am    Post subject: Reply with quote

Look at the video code in Basilisk II - it does 4 and 8 bit palette modes (among others). The biggest "gotcha" to watch out for with 4 bit palettes is that the pixels in the bytes are swapped compared to every other platform in the world.
Back to top
View user's profile Send private message AIM Address
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Wed Jul 08, 2009 2:03 am    Post subject: Reply with quote

i have no idea what your are talking about i'm just learning the gu is there some sort of tuturial on this and could someone explain palletes in the first place i looked it up on wiki so i know what they are but the image also has pixels so are the image pixel data just numbers like 1,2,3,etc that are supposed to be used for the pallete and if so then how do i change colors in the image and how do i tell the gu to display this image
Back to top
View user's profile Send private message MSN Messenger
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Wed Jul 08, 2009 6:40 am    Post subject: Reply with quote

Paletted mode is simple - you have a color lookup table with a max of 256 entries. You use a GU command to set those entries. This color lookup table can have 16 bit or 32 bit entries, with the same values as the 16/32 bit texture pixel formats, like 8888. Once you have a lookup table with entries, the next thing is the texture itself. An eight bit palette mode uses one byte per pixel, with that byte being an index into the color lookup table. A four bit palette mode uses 4 four bits per pixel, with that nibble being an index into the color lookup table. Since you have two pixels per byte, the natural question is which nibble is which pixel? On every other system in the world, bits 7 to 4 of the byte are the first pixel (from left to right), and bits 3 to 0 are the second pixel. On the PSP, it's the opposite of that. So if you look at routines that work on PSP four bit textures, you'll see code that swaps those nibbles.

We can get more complex, as the PSP allows you to shift, mask, and offset the data used to form the index into the color table, but you should save that until you have a better grasp of paletted textures. So if you look at the eight bit code in B2, you find

Code:
   sceGuStart(GU_DIRECT,list);
   sceGuClutMode(GU_PSM_8888,0,0xFF,0);           // 32-bit palette, shift = 0, mask = 0xFF, start = 0
   sceGuClutLoad((256/(32/4)),clut256);         // upload 32 blocks (each block is 32 bytes / bytesPerColorEntry)
   sceGuEnable(GU_TEXTURE_2D);
   sceGuTexMode(GU_PSM_T8,0,0,0);
   sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
   sceGuTexFilter(GU_LINEAR, GU_LINEAR);


sceGuClutMode sets the format of the entries, the shift, the mask, and the offset. For "normal" usage, just set the shift and offset to 0, and the mask to 255. sceGuClutLoad loads the entries of the lookup table, with the length specified as blocks of 32 bytes (because of minimum DMA sizes I imagine). That's all you need for the color lookup table. The rest is normal texture setting and drawing, but with the texture format specified as 8 bit (GU_PSM_T8). That's all there is to it.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group