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 

How to swizzle image data when using a palette?

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



Joined: 28 Dec 2009
Posts: 16

PostPosted: Thu Apr 08, 2010 12:42 pm    Post subject: How to swizzle image data when using a palette? Reply with quote

Now I've known it is faster after the image data is swizzled, although I didn't know what's the meaning of the word "swizzle". ;-)

And I want to use a palette(A.K.A. Color LookUp Table), to make the image data smaller.

Then how should I swizzle the color index of each pixel ?


Swizzle the color index as normal?
Back to top
View user's profile Send private message
anmabagima



Joined: 01 Oct 2009
Posts: 96

PostPosted: Thu Apr 08, 2010 4:53 pm    Post subject: Reply with quote

Hi,

swizzling the image data means changing the order of the pixels to a block format which supports the way the GU reads the data from the memory in a way that it improves performance - this is my understanding. The swizzling itself is independend from the real data of the pixel, which means independent from the pixel format. As far as I understood the swizzling takes place on bytes regardless of the pixel format. With google you will find some swizzle source code.

I've used the following code to swizzle an image (found on the net):
Code:
void swizzle(unsigned char* out, unsigned char* in, unsigned int width, unsigned int height)
{
   unsigned int i,j;
   unsigned int rowblocks = (width / 16);

   for (j = 0; j < height; ++j)
   {
      for (i = 0; i < width; ++i)
      {
         unsigned int blockx = i / 16;
         unsigned int blocky = j / 8;

         unsigned int x = (i - blockx*16);
         unsigned int y = (j - blocky*8);
         unsigned int block_index = blockx + ((blocky) * rowblocks);
         unsigned int block_address = block_index * 16 * 8;

         out[block_address + x + y * 16] = in[i+j*width];
      }
   }
}
if you have a pixel format like 8888 , than you need to set width as image width*pixelsize. As you have palette values I assume a pixel is just 1 byte wide. Which means you can path the image width as it is.

Hope this helps...
Back to top
View user's profile Send private message
yokfran



Joined: 28 Dec 2009
Posts: 16

PostPosted: Fri Apr 09, 2010 2:26 am    Post subject: Reply with quote

anmabagima wrote:
Hi,

swizzling the image data means changing the order of the pixels to a block format which supports the way the GU reads the data from the memory in a way that it improves performance - this is my understanding. The swizzling itself is independend from the real data of the pixel, which means independent from the pixel format. As far as I understood the swizzling takes place on bytes regardless of the pixel format. With google you will find some swizzle source code.

I've used the following code to swizzle an image (found on the net):
Code:
void swizzle(unsigned char* out, unsigned char* in, unsigned int width, unsigned int height)
{
   unsigned int i,j;
   unsigned int rowblocks = (width / 16);

   for (j = 0; j < height; ++j)
   {
      for (i = 0; i < width; ++i)
      {
         unsigned int blockx = i / 16;
         unsigned int blocky = j / 8;

         unsigned int x = (i - blockx*16);
         unsigned int y = (j - blocky*8);
         unsigned int block_index = blockx + ((blocky) * rowblocks);
         unsigned int block_address = block_index * 16 * 8;

         out[block_address + x + y * 16] = in[i+j*width];
      }
   }
}
if you have a pixel format like 8888 , than you need to set width as image width*pixelsize. As you have palette values I assume a pixel is just 1 byte wide. Which means you can path the image width as it is.

Hope this helps...


Thanks for the reply :-)

If with palette pass "widthPow2 * colorIndexSize", or pass "widthPow2 * pixelColorSize". Right?

I'll remeber this.

Thanks for the explain. I finally know what "swizzle" mean. Haha :-)
Back to top
View user's profile Send private message
anmabagima



Joined: 01 Oct 2009
Posts: 96

PostPosted: Fri Apr 09, 2010 5:26 pm    Post subject: Reply with quote

Hi,

if you use palette picture than the picture does not contain real pixeldata but index to the palette, therefore
Code:
widthPow2 * colorIndexSize
would be the right one.

However, the direct translation of "swizzle" into German language is also very amusing :o)
Back to top
View user's profile Send private message
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