Skip to content

Commit

Permalink
lbm, pcx, png, tga: tweak conditional endian compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Sep 12, 2019
1 parent b657402 commit f20b2fb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
22 changes: 9 additions & 13 deletions IMG_lbm.c
Expand Up @@ -454,19 +454,15 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
{
finalcolor = pixelcolor;
}
if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
{
*ptr++ = (Uint8)(finalcolor>>16);
*ptr++ = (Uint8)(finalcolor>>8);
*ptr++ = (Uint8)(finalcolor);
}
else
{
*ptr++ = (Uint8)(finalcolor);
*ptr++ = (Uint8)(finalcolor>>8);
*ptr++ = (Uint8)(finalcolor>>16);
}

#if SDL_BYTEORDER == SDL_LIL_ENDIAN
*ptr++ = (Uint8)(finalcolor>>16);
*ptr++ = (Uint8)(finalcolor>>8);
*ptr++ = (Uint8)(finalcolor);
#else
*ptr++ = (Uint8)(finalcolor);
*ptr++ = (Uint8)(finalcolor>>8);
*ptr++ = (Uint8)(finalcolor>>16);
#endif
maskBit = maskBit>>1;
}
}
Expand Down
18 changes: 9 additions & 9 deletions IMG_pcx.c
Expand Up @@ -143,15 +143,15 @@ SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src)
bits = 8;
} else if(pcxh.BitsPerPixel == 8 && pcxh.NPlanes == 3) {
bits = 24;
if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) {
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
} else {
Rmask = 0xFF0000;
Gmask = 0x00FF00;
Bmask = 0x0000FF;
}
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
#else
Rmask = 0xFF0000;
Gmask = 0x00FF00;
Bmask = 0x0000FF;
#endif
} else {
error = "unsupported PCX format";
goto done;
Expand Down
24 changes: 12 additions & 12 deletions IMG_png.c
Expand Up @@ -495,18 +495,18 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
Rmask = Gmask = Bmask = Amask = 0 ;
num_channels = lib.png_get_channels(png_ptr, info_ptr);
if ( color_type != PNG_COLOR_TYPE_PALETTE ) {
if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) {
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
Amask = (num_channels == 4) ? 0xFF000000 : 0;
} else {
int s = (num_channels == 4) ? 0 : 8;
Rmask = 0xFF000000 >> s;
Gmask = 0x00FF0000 >> s;
Bmask = 0x0000FF00 >> s;
Amask = 0x000000FF >> s;
}
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
Amask = (num_channels == 4) ? 0xFF000000 : 0;
#else
int s = (num_channels == 4) ? 0 : 8;
Rmask = 0xFF000000 >> s;
Gmask = 0x00FF0000 >> s;
Bmask = 0x0000FF00 >> s;
Amask = 0x000000FF >> s;
#endif
}
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
bit_depth*num_channels, Rmask,Gmask,Bmask,Amask);
Expand Down
12 changes: 8 additions & 4 deletions IMG_tga.c
Expand Up @@ -169,18 +169,20 @@ SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src)
alpha = 1;
/* fallthrough */
case 24:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
{
int s = alpha ? 0 : 8;
amask = 0x000000ff >> s;
rmask = 0x0000ff00 >> s;
gmask = 0x00ff0000 >> s;
bmask = 0xff000000 >> s;
} else {
}
#else
amask = alpha ? 0xff000000 : 0;
rmask = 0x00ff0000;
gmask = 0x0000ff00;
bmask = 0x000000ff;
}
#endif
break;

default:
Expand Down Expand Up @@ -300,13 +302,15 @@ SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src)
} else {
SDL_RWread(src, dst, w * bpp, 1);
}
if(SDL_BYTEORDER == SDL_BIG_ENDIAN && bpp == 2) {
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
if(bpp == 2) {
/* swap byte order */
int x;
Uint16 *p = (Uint16 *)dst;
for(x = 0; x < w; x++)
p[x] = SDL_Swap16(p[x]);
}
#endif
dst += lstep;
}
return img;
Expand Down

0 comments on commit f20b2fb

Please sign in to comment.