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 

Fast mirror image

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



Joined: 09 Apr 2006
Posts: 15

PostPosted: Tue Aug 08, 2006 8:44 pm    Post subject: Fast mirror image Reply with quote

Hello guy
I use SDL for display image but when i need mirror my image i locked surface and for-loop width and height to swap pixel and draw to surface.
That's a problem it very slow. Anybody have a fast algorithm for mirror image please help me..... :-(
best regards
wing64
_________________
kjdflkdfdfsdf
Back to top
View user's profile Send private message
tmator_



Joined: 10 Jun 2006
Posts: 9

PostPosted: Tue Aug 08, 2006 9:57 pm    Post subject: Reply with quote

can you post your code ?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
wing64



Joined: 09 Apr 2006
Posts: 15

PostPosted: Thu Aug 10, 2006 1:05 pm    Post subject: Reply with quote

Here this code for mirror surface
Code:

if (SDL_MUSTLOCK(src))
   SDL_LockSurface(src);
if (SDL_MUSTLOCK(des))
   SDL_LockSurface(des);

Uint8* sdata = (Uint8*)src->pixels;
Uint16 spitch = src->pitch;

Uint8* ddata = (Uint8*)des->pixels;
Uint16 dpitch = des->pitch;
int x = 0, y = 0, xend = (src->w + 1) / 2;

for (y = 0; y < src->h; y++)
{
   for (x = 0; x < xend; x++)
   {
      ddata = ((Uint8 *) des->pixels) + y * dpitch + x;
      sdata = ((Uint8 *) src->pixels) + y * spitch + src->w-1 - x;
      *((Uint8 *) ddata) = *((Uint8 *) sdata);


      ddata = ((Uint8 *) des->pixels) + y * dpitch + des->w-1 - x;
      sdata = ((Uint8 *) src->pixels) + y * spitch + x;
      *((Uint8 *) ddata) = *((Uint8 *) sdata);
   }
}

if (SDL_MUSTLOCK(src))
   SDL_UnlockSurface(src);
if (SDL_MUSTLOCK(des))
   SDL_UnlockSurface(des);

_________________
kjdflkdfdfsdf
Back to top
View user's profile Send private message
Npl



Joined: 01 Apr 2005
Posts: 5

PostPosted: Thu Aug 24, 2006 4:35 am    Post subject: Reply with quote

Having uneeded multiplications in your code is generally a bad idea, using forward differences solves that. Also its better to use a pointer that advances instead of calculating offsets, saves instructions.

Code:

if (SDL_MUSTLOCK(src))
   SDL_LockSurface(src);
if (SDL_MUSTLOCK(des))
   SDL_LockSurface(des);

int x = 0, y = 0, xend = src->w;
int deltaD = des->pitch - xend, deltaS = src->pitch + xend ;

Uint8* ddata = (Uint8 *) des->pixels;
Uint8* sdata = (Uint8 *) src->pixels + src->w - 1;

for (y = 0; y < src->h; y++)
{
   x=0;
#ifdef UNROLLOOP
   for (; x < xend-3; x+=4)
   {
      ddata[0] = sdata[3];
      ddata[1] = sdata[2];
      ddata[2] = sdata[1];
      ddata[3] = sdata[0];
      ddata += 4;
      sdata -= 4;
   }
#endif /* UNROLLOOP */
   for (; x < xend; x++)
   {
      *ddata++ = *sdata--;
   }

         ddata +=  deltaD;
         sdata +=  deltaS;
}

if (SDL_MUSTLOCK(src))
   SDL_UnlockSurface(src);
if (SDL_MUSTLOCK(des))
   SDL_UnlockSurface(des);


generally the code in UNROLLOOP is not needed, but should be a bit faster. I dont think you could optimize much further without using assembly
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 -> PS2 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