How do you fade an image in 16 bpp (or higher)?

I’ve got a little problem…

How do you fade an image in 16 bpp (or higher)??? I’ve never worked with a
bit depth higher than 8…

/Folke

“PONTUS FOLKESSON” <pontus.folkesson at swipnet.se> wrote

How do you fade an image in 16 bpp (or higher)??? I’ve never
worked with a bit depth higher than 8…

well, there’s two ways. first i’ll let you know about the
’real way’. instead of changing the colors in the colormap
to do the fade, you now need to change the colors in the
actual image. the code should work just about the same, just
that now there’s a lot more data to work on

pseudocode for colormap fade (8bpp)…
for each color in colormap:
color.red /= 2
color.grn /= 2
color.blu /= 2

now to do this for a trucolor (>8bpp) the code changes slightly…
for each pixel in image:
pixel.red /= 2
pixel.grn /= 2
pixel.blu /= 2

of course, you’ll likely need to call SDL_MapRGB and SDL_GetRGB
to get the RGB values from the actual pixel value.

anyways, you’ll quickly find there’s a lot more work to be done
to fade out the images with the higher color counts. if you’re
just doing an intro screen or whatnot, you may decide to leave
the screen in 8bit mode for the intros and then switch to 16bit
for the actual game.

the other ‘new and free’ method involves setting the video
cards gamma ramps. this won’t be supported on everyone’s hardware
just yet, so i’m not sure if this should be the only method you use.
the SDL_SetGamma function is pretty easy to use though and can be
used to cheaply fade out the whole screen. i haven’t used this feature
myself, so i don’t know if you can detect if it is available or not?
i also assume changing the gamma while windowed is not what everyone
will like either.

the other ‘new and free’ method involves setting the video
cards gamma ramps. this won’t be supported on everyone’s hardware
just yet, so i’m not sure if this should be the only method you use.
the SDL_SetGamma function is pretty easy to use though and can be
used to cheaply fade out the whole screen. i haven’t used this feature
myself, so i don’t know if you can detect if it is available or not?
i also assume changing the gamma while windowed is not what everyone
will like either.

Correct on all points.
The gamma code works fairly well on many cards with XFree86 4.0
I haven’t implemented the windows code yet, but that should work
on a similar number of cards.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

“Sam Lantinga” wrote

so i don’t know if you can detect if it is available or not?

Correct on all points.
The gamma code works fairly well on many cards with XFree86 4.0

(good to know i wasn’t leading anyone astray :] )
about the detection part. would it be wise/worthwhile to add
a gamma field to the SDL_VideoInfo struct? the only chore part
here would be updating the SDL_GetVideoInfo code for each driver.
i’m not needing it, but just thinking ahead

“PONTUS FOLKESSON” <pontus.folkesson at swipnet.se> wrote in message
news:8p5vn2$mu6$1 at ftp.lokigames.com

I’ve got a little problem…

How do you fade an image in 16 bpp (or higher)??? I’ve never worked with a
bit depth higher than 8…

I would try per-surface alpha.–
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

“Sam Lantinga” wrote

so i don’t know if you can detect if it is available or not?

Correct on all points.
The gamma code works fairly well on many cards with XFree86 4.0

(good to know i wasn’t leading anyone astray :] )
about the detection part. would it be wise/worthwhile to add
a gamma field to the SDL_VideoInfo struct? the only chore part
here would be updating the SDL_GetVideoInfo code for each driver.
i’m not needing it, but just thinking ahead

It depends on the video mode. The proper way to do it is probably
to set a video mode and then try to retrieve the gamma ramps. It’s
possible for a driver to support setting them and not retrieving them,
but it’s unlikely.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

“PONTUS FOLKESSON” <pontus.folkesson at swipnet.se> wrote in message
news:8p5vn2$mu6$1 at ftp.lokigames.com

I’ve got a little problem…

How do you fade an image in 16 bpp (or higher)??? I’ve never worked with a
bit depth higher than 8…

I would try per-surface alpha.

That’s an interesting idea, I gotta try that… :slight_smile:

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

I’ve got a little problem…

How do you fade an image in 16 bpp (or higher)??? I’ve never worked with a
bit depth higher than 8…

You have to poke around the image to do it. Read every pixel, fudge every
pixel by your fading system, rewrite the pixel. It’s best done using
double buffering; do all the pixel fudging in the backbuffer, then recopy
to the main buffer. To fudge your pixels to either fade in or out, the
best way is to work with pixels in HSV (if you’re fading to or from black)
or HLS (if you’re fading to or from white), modifying the value or
lightness parameter at a rate consistent with how fast you want to fade.
There are simpler ways than performing HSV conversions for every pixel in
your image every time, and then converting back to RGB, such as just
decrementing each of the RGB pixels until they’re all zero, but in my
experience, while these might be faster, they don’t maintain the colors
properly. It’s not too noticeable with a fast fade, but for slow fades,
there will be marked color shifts in some areas which may not look very
good. At least using HLS or HSV maintains your image’s hue and
saturation, so you don’t get these shifts.

I dunno; I guess one thing you could do with the MMX instruction set is
speed up these sorts of things. You could perform the RGB-HSV-RGB
conversion in parallel on several pixels with the MMX SIMD instructions.On Wed, 6 Sep 2000, PONTUS FOLKESSON wrote:


Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
ICSM-F Development Team, UP Diliman +63 (917) 4458925
PGP Key available at http://home.pacific.net.ph/~dido/dido.pgp

i also assume changing the gamma while windowed is not what everyone
will like either.

Whether the gamma change affects the rest of the display depends on your
system, but you are correct in that you can’t rely on any definite behaviour.

The gamma code works fairly well on many cards with XFree86 4.0
I haven’t implemented the windows code yet, but that should work
on a similar number of cards.

It also works well on all Suns with DirectColor support that I’ve tried.

I haven’t made up my mind about whether gamma support in 8-bit mode is
worthwhile. It is easy to add and won’t affect performance when it isn’t
used, but I don’t know if people actually need it — those who use
8-bit mode may prefer doing it by hand. Opinions?

I haven’t made up my mind about whether gamma support in 8-bit mode is
worthwhile. It is easy to add and won’t affect performance when it isn’t
used, but I don’t know if people actually need it — those who use
8-bit mode may prefer doing it by hand. Opinions?

I think we should add it. When somebody requests a gamma change, it would
be great to support it on as many cases as possible.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software