I’m not sure if the G4 is Big endian or Little endian. I will explain my
problem better:
I’ve this function (that multiplies the RED, GREEN and BLUE channels of
a Surface by a constant), that I use to fade in and out, and to increase
or decrease the RED, GREEN or BLUE level of an image:
void surface_fader(SDL_Surface *surface,float r_factor,float
g_factor,float b_factor)
{
int i,x,y,offs;
Uint8 rtable[256],gtable[256],btable[256];
Uint8 *pixels = (Uint8 *)(surface->pixels);
if (surface->format->BytesPerPixel!=4) return;
for(i=0;i<256;i++) {
rtable[i]=(Uint8)(i*r_factor);
gtable[i]=(Uint8)(i*g_factor);
btable[i]=(Uint8)(i*b_factor);
} /* for */
for(y=0;y<surface->h;y++) {
for(x=0,offs=y*surface->pitch;x<surface->w;x++,offs+=4) {
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
pixels[offs]=rtable[pixels[offs]];
pixels[offs+1]=gtable[pixels[offs+1]];
pixels[offs+2]=btable[pixels[offs+2]];
} else {
pixels[offs+3]=rtable[pixels[offs+3]];
pixels[offs+2]=gtable[pixels[offs+2]];
pixels[offs+1]=btable[pixels[offs+1]];
} /* if */
} /* for */
} /* for */
} /* surface_fader */
And I’ve got to replace it with:
void surface_fader(SDL_Surface *surface,float r_factor,float
g_factor,float b_factor)
{
int i,x,y,offs;
Uint8 rtable[256],gtable[256],btable[256];
Uint8 *pixels = (Uint8 *)(surface->pixels);
if (surface->format->BytesPerPixel!=4) return;
for(i=0;i<256;i++) {
rtable[i]=(Uint8)(i*r_factor);
gtable[i]=(Uint8)(i*g_factor);
btable[i]=(Uint8)(i*b_factor);
} /* for */
for(y=0;y<surface->h;y++) {
for(x=0,offs=y*surface->pitch;x<surface->w;x++,offs+=4) {
pixels[offs+3]=rtable[pixels[offs+3]];
pixels[offs+2]=gtable[pixels[offs+2]];
pixels[offs+1]=btable[pixels[offs+1]];
} /* for */
} /* for */
} /* surface_fader */
The first version works fine in WINDOWS, and I don’t know why it doen’t
work in Mac. am I missing something?