I'm working on a very small 2d library to load and display SFF files (m.u.g.e.n. uses this file format for the gfx, and it's nothing more than a bunch of 8 bit PCXs grouped in a file with some extra info, like axis).
My questions are:
Do you recommend using SDL_BlitSurface instead of the function dibujar(), considering the conversion SDL should make if I'm using a 16bit surface as the main window?
Do you recommend using assembly to do this very fast? (It's worth it?)
class SFF_Images
{
int numimages;
SFF_Image ** imagenes;
//blah blah blah
}
class SFF_Image
{
int group, index
int x,y
char *pal
char *rawdata
//more bla blah and foo
}
This is the code I use for drawing an Image onscreen:
void dibujar(SDL_Surface*pantalla, unsigned char*pixels,unsigned char*paleta, int alto, int ancho, int x, int y, int ex, int ey)
{
Uint16 r,g,b;
Uint16 ix,sy,dx,iy;
//To avoid of-screen drawing = SDL Parachute deploy!
ix=-(x-ex<0)*(x-ex);
sy=-(y-ey<0)*(y-ey);
dx=-(W-(x+ancho-ex)<0)*(W-(x+ancho-ex));
iy=-(H-(y+alto-ey)<0)*(H-(y+alto-ey));
SDL_LockSurface(pantalla);
SDL_FillRect(pantalla, NULL, SDL_MapRGB(pantalla->format,0xFF,0,0xFF));
for(int i=sy;i<alto-iy;++i)
{
for(int j=ix;j<ancho-dx;++j)
{
r=Uint16(paleta[3*pixels[ancho*i+j]+0])>>(pantalla->format->Rloss);
g=Uint16(paleta[3*pixels[ancho*i+j]+1])>>(pantalla->format->Gloss);
b=Uint16(paleta[3*pixels[ancho*i+j]+2])>>(pantalla->format->Bloss);
r=r<<(pantalla->format->Rshift);
g=g<<(pantalla->format->Gshift);
b=b<<(pantalla->format->Bshift);
((Uint16*)(pantalla->pixels))[(i+y-ey)*pantalla->pitch/2+j+x-ex]=r|g|b;
}
}
SDL_UnlockSurface(pantalla);
}