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 335 - Win32, windib, Fullscreen, 8-bit
Summary: Win32, windib, Fullscreen, 8-bit
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 1.2.11
Hardware: x86 Windows (95/98/ME)
: P1 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-04 10:11 UTC by Facundo Dominguez
Modified: 2007-07-03 02:06 UTC (History)
1 user (show)

See Also:


Attachments
The image needed for running the sample code. (14.88 KB, image/bmp)
2006-10-04 10:14 UTC, Facundo Dominguez
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Facundo Dominguez 2006-10-04 10:11:43 UTC
Hello:
     The following code shows wrong colors with the windib video driver.
I test it on a Pentium II and AMD athlon both with WIN98.
     I used SDL-1.2.11 with mingw.
     This just happens with fullscreen mode.
     I found an email from March 2000 with the same warning
([SDL] SDL-1.1.0, Win32, GDI, Fullscreen, 8-bit)
     The work around I found was to use the directx video driver.
     On linux the colors are fine. 

    The image used can be found on
   http://www.fing.edu.uy/~fdomin/planet2.bmp

#include "SDL.h"

int main(int argc,char** argv){

   SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
   SDL_Surface * screen = SDL_SetVideoMode(640, 480, 8,SDL_HWPALETTE);
   SDL_Surface * s=SDL_LoadBMP("planet2.bmp");
   SDL_SetColors(screen, s->format->palette->colors,  
0,s->format->palette->ncolors);

   SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
   SDL_Rect r={(screen->w-s->w)>>1,(screen->h-s->h)>>1,s->w,s->h};
   SDL_BlitSurface(s,NULL,screen,&r);
   SDL_Flip(screen);

   SDL_Delay(1000);

   SDL_Quit();
   return 0;
}
Comment 1 Facundo Dominguez 2006-10-04 10:14:02 UTC
Created attachment 165 [details]
The image needed for running the sample code.
Comment 2 Dmitry Yakimov 2006-10-05 09:18:50 UTC
I'll look into it, it may be related to the bug #213

-- Dmitry Yakimov
Comment 3 Dmitry Yakimov 2006-10-08 15:13:05 UTC
Very interesting. Your bitmap is shown as you described in 'wrong colors' in IrfanView and MS Paint (8bpp screen mode), so SDL not the only one.

If I open a palette in IrfanView palette viewer - I can see there the bluish colors I see in the resulted image, so I can't see _strange_ colors.

I've made a simple experiment - loaded your bitmap in photoshop, then converted to RGB format, then converted back to 8bpp mode (photoshop generated a new palette), after that a new bitmap has been shown OK.

SDL_HWPALETTE does not matter, the one thing that does matter is SDL_FULLSCREEN, that is because in full screen a color depth of the whole screen is going to be 8 bpp with help of ChangeSettingsEx.

Why this bitmap having exact this palette is shown good when screen is in RGB format and window has got 8 bpp format - I do not know. May be it does not fit 100% in windows palette management? Anybody knows?

I recommend you to recreate a palette for this bitmap in more smart software.
Let us know your ideas about this.
Comment 4 Facundo Dominguez 2006-10-18 17:57:03 UTC
Well, I make another experiment.

I read over there that windows (didn't say which version) reserves the first ten colors and the last ten colors of the palette.

Then I edited the planet2.bmp palette to set these palette positions to the windows default colors.
The experiment made obvious that these palette positions are used exactly in the zone of the image that is shown with wrong colors. 

But windows default colors are not the colors displayed by sdl. 
I think your observations and mine fit the following hipothesis:
* The image colors are somewhere and somehow mapped to the palette composed of the 20 reserved colors of windows and other 236 colors taken from the image palette.
Comment 5 Ryan C. Gordon 2007-06-02 13:58:56 UTC
Bumping a bunch of bugs to Priority 1 for consideration for the 1.2.12 release.

--ryan.

Comment 6 Sam Lantinga 2007-06-22 22:00:57 UTC
Yes, it looks like that's exactly what happens.

The fix is to save the system palette entries, call
SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC)
and then restore the system palette entries at focus loss or shutdown, as described here:
http://msdn2.microsoft.com/en-us/library/ms532605.aspx
Comment 7 Sam Lantinga 2007-07-03 02:06:11 UTC
This is fixed in subversion revision 3122