IMG_Load and SDL_Surface flags

I load an image with IMG_load from SDL_image library. I am trying to find if
IMG_Load returns a SWSURFACE or a HWSURFACE.

I type :

if( my_surface->flags & SDL_SWSURFACE )…
or
if( my_surface->flags & SDL_HWSURFACE )…

Both cases return false… because flags is 0
Is it a bug or a feature ???

Just another question :

Does IMG_Load calls SDL_DisplayFormat before returning the surface ?

thnx :slight_smile:

Hello !

I load an image with IMG_load from SDL_image library. I am trying to find if
IMG_Load returns a SWSURFACE or a HWSURFACE.

SDL_image always returns SWSurfaces.

Does IMG_Load calls SDL_DisplayFormat before returning the surface ?

No, it returns them as they come from disk, memory, …
8 Bit, 16 Bit, 24 Bit, …

CU

You should note that SDL_SWSURFACE isn’t really a flag at all, it is
defined as 0.

To test whether a surface is in hardware is

if( my_surface->flags & SDL_HWSURFACE )

If this fails, its in software.

Hello !

You should note that SDL_SWSURFACE isn’t really a flag at all, it is
defined as 0.

To test whether a surface is in hardware is

if( my_surface->flags & SDL_HWSURFACE )

Better is to test :

if( (my_surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )

CU

El Friday 21 December 2007 01:45:36 Torsten Giebl escribi?:

You should note that SDL_SWSURFACE isn’t really a flag at all, it is
defined as 0.

To test whether a surface is in hardware is

if( my_surface->flags & SDL_HWSURFACE )

Better is to test :

if( (my_surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE )

Why? Those SDL_ flags always have only one bit set. Isn’t it the usual way of
implementing it? Otherwise it could exist clashes between flags.

Hello !

Why? Those SDL_ flags always have only one bit set. Isn’t it the usual way of
implementing it? Otherwise it could exist clashes between flags.

In which case ?

CU

El Friday 21 December 2007 13:15:59 Torsten Giebl escribi?:

Why? Those SDL_ flags always have only one bit set. Isn’t it the usual
way of implementing it? Otherwise it could exist clashes between flags.

In which case ?

If you had three features:

1001 A
0010 B
0001 C

and the bitfield where “1001”, the following test would be incorrect:

if( bitfield & C) /* (bitfield & C) == C would also fail */
printf( “we have C!”); /No, we had A instead/

because there are common bits between A and C.

All the code I’ve seen until today relies on the flags not having any bit in
common, that is, being powers of 2. However it seems that SDL doesn’t work
this way, because those flag definitions are written in terms of 0x1, 0x2,
0x4 and 0xA, the last instead of 0x8. I’m a bit confused why it has been done
so.

Any thoughts?

SDL_OPENGLBLIT has the form 0xA, in bineray 1010, but it is deprecated
so I guess it can be whatever. That is the only flag I see that
doesn’t directly obey the power of two rule. However, it only appears
to have the effect of turning on SDL_HWSURFACE, which is relatively
harmless.