We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1886

Summary: SDL_image 2.0rc: TGA channels mixed up on some platforms
Product: SDL_image Reporter: Steffen Hein <steffen-hein>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: unspecified   
Hardware: x86   
OS: Windows (All)   
Attachments: Screenshot showing the result on OSX and Windows

Description Steffen Hein 2013-06-02 17:56:44 UTC
Created attachment 1168 [details]
Screenshot showing the result on OSX and Windows

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
Comment 1 Sam Lantinga 2013-06-02 23:57:53 UTC
Fixed, thanks for the report!
http://hg.libsdl.org/SDL_image/rev/1ff9cd8cf18b
Comment 2 Steffen Hein 2013-06-03 05:12:29 UTC
Thanks for the fast response!
Works correctly in 2.0rc2.

-Steffen
Comment 3 Sam Lantinga 2013-06-03 22:52:23 UTC
Great! You're welcome. :)