Skip to content

Commit

Permalink
Fixed bug 1886 - SDL_image 2.0rc: TGA channels mixed up on some platf…
Browse files Browse the repository at this point in the history
…orms

 Steffen Hein

I'm running into a problem when loading TGA files on different platforms with SDL_image 2.0rc1. It works fine on OSX and iOS (AFAIK SDL_image uses the operating system routines on these platforms), but on Windows and Linux, the channels are mixed up.


The textures I used for this bug report can be downloaded here:
  http://www.dexsoft-games.com/models/medieval_free.html
  http://www.dexsoft-games.com/freebies/models/medieval_free_mesh.7z

Excerpt from my texture loading function:

  [...]

  if( is_tga ) {
      source_image = IMG_LoadTyped_RW(rw, FALSE, "TGA");
  } else {
      source_image = IMG_Load_RW(rw, FALSE);
  }

  printf("Flags:    %x\n",    source_image->flags);
  printf("Size:     %dx%d\n", source_image->w, source_image->h);
  printf("PF BPP:   %d\n",    source_image->format->BitsPerPixel);
  printf("PF Rmask: %08x\n",  source_image->format->Rmask);
  printf("PF Gmask: %08x\n",  source_image->format->Gmask);
  printf("PF Bmask: %08x\n",  source_image->format->Bmask);
  printf("PF Amask: %08x\n",  source_image->format->Amask);

  // Convert into suitable format for OpenGL upload
  SDL_Surface *format_template = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
  SDL_Surface *image = SDL_ConvertSurface(source_image, format_template->format, 0);

  [...]

Result on OSX/iOS:

  Loading texture: 'models/medieval_free_dex/doorwindow_set.tga'
  Flags:    0
  Size:     512x512
  PF BPP:   32
  PF Rmask: 00ff0000
  PF Gmask: 0000ff00
  PF Bmask: 000000ff
  PF Amask: ff000000

Result on Windows/Linux:

  Loading texture: 'models/medieval_free_dex/doorwindow_set.tga'
  Flags:    0
  Size:     512x512
  PF BPP:   32
  PF Rmask: 0000ff00
  PF Gmask: 00ff0000
  PF Bmask: ff000000
  PF Amask: 000000ff


Thanks!
-Steffen
  • Loading branch information
slouken committed Jun 3, 2013
1 parent 2ffc698 commit 4ae4233
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion IMG_tga.c
Expand Up @@ -169,7 +169,7 @@ SDL_Surface *IMG_LoadTGA_RW(SDL_RWops *src)
alpha = 1;
/* fallthrough */
case 24:
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
{
int s = alpha ? 0 : 8;
amask = 0x000000ff >> s;
Expand Down

0 comments on commit 4ae4233

Please sign in to comment.