Colour cycling

Is there an easy way to do that vomit-inducing colour cycling you see
in old games and fractal generators?

I’ve created an 8bit 640x480 palletised surface, and have drawn some
things on it.

The kind of cycling I’d like is the one where each colour in the
palette is shoved one space forwards. I tried doing this with
SDL_SetPalette(), but couldn’t work out how to get the palette for a
surface.

I managed to rotate an empty SDL_Color array’s elements, but of course
an empty SDL_Color array has a palette with all colours set to black,
which doesn’t look very good when cycled :slight_smile:

so if I have an SDL_Surface ‘screen’, how do I get the palette for this
as an SDL_Color array? (or is there a better way?).–
Experience! That most brutal of teachers. But you learn, my God, do you learn.
-C. S. Lewis]------------+
6AD6 865A BF6E 76BB 1FC2 | www.piku.org.uk/public-key.asc@James1
E4C4 DEEA 7D08 D511 E149 | perl -p -e “y/a-zA-Z/n-za-mN-ZA-M/”

Is there an easy way to do that vomit-inducing colour cycling you see
in old games and fractal generators?

Yes.

I’ve created an 8bit 640x480 palletised surface, and have drawn some
things on it.

The kind of cycling I’d like is the one where each colour in the
palette is shoved one space forwards. I tried doing this with
SDL_SetPalette(), but couldn’t work out how to get the palette for a
surface.

I managed to rotate an empty SDL_Color array’s elements, but of course
an empty SDL_Color array has a palette with all colours set to black,
which doesn’t look very good when cycled :slight_smile:

so if I have an SDL_Surface ‘screen’, how do I get the palette for this
as an SDL_Color array? (or is there a better way?).

First, make sure you use SDL_HWPALETTE as a flag passed to
SetVideoMode().
Then, read the screen’s palette from screen->format->palette, writing
the new values to your array of SDL_Color. Then use SDL_SetColors() to
set the new palette.

Easy, right?

-DarrellOn Tuesday, October 9, 2001, at 03:32 PM, James wrote:

And, if it for some reason is impossible to get an 8 bit mode, it may be
possible to “abuse” the gamma correction tables to simulate it in 24 or
32 bit modes. In short, render everything as grayscales, and then
translate the scale into a 256 color palette, that you load into the
gamma tables. You may then play with the gamma tables as you like, as if
they were a “real” h/w palette.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Wednesday 10 October 2001 01:26, Darrell Walisser wrote:

On Tuesday, October 9, 2001, at 03:32 PM, James wrote:

Is there an easy way to do that vomit-inducing colour cycling you see
in old games and fractal generators?

Yes.

I’ve created an 8bit 640x480 palletised surface, and have drawn some
things on it.

The kind of cycling I’d like is the one where each colour in the
palette is shoved one space forwards. I tried doing this with
SDL_SetPalette(), but couldn’t work out how to get the palette for a
surface.

I managed to rotate an empty SDL_Color array’s elements, but of
course an empty SDL_Color array has a palette with all colours set to
black, which doesn’t look very good when cycled :slight_smile:

so if I have an SDL_Surface ‘screen’, how do I get the palette for
this as an SDL_Color array? (or is there a better way?).

First, make sure you use SDL_HWPALETTE as a flag passed to
SetVideoMode().
Then, read the screen’s palette from screen->format->palette, writing
the new values to your array of SDL_Color. Then use SDL_SetColors() to
set the new palette.

Easy, right?

Hello Darrell Walisser. It was Yesterday when you wrote:

| > so if I have an SDL_Surface ‘screen’, how do I get the palette for this
| > as an SDL_Color array? (or is there a better way?).
|
| First, make sure you use SDL_HWPALETTE as a flag passed to
| SetVideoMode().
| Then, read the screen’s palette from screen->format->palette, writing

Ahh, so that’s where the palette lives.

| the new values to your array of SDL_Color. Then use SDL_SetColors() to
| set the new palette.
|
| Easy, right?

Yeah, I suppose it is :-)–
Experience! That most brutal of teachers. But you learn, my God, do you learn.
-C. S. Lewis]------------+
6AD6 865A BF6E 76BB 1FC2 | www.piku.org.uk/public-key.asc@James1
E4C4 DEEA 7D08 D511 E149 | perl -p -e “y/a-zA-Z/n-za-mN-ZA-M/”

Darrell Walisser wrote:

Then, read the screen’s palette from screen->format->palette, writing
the new values to your array of SDL_Color. Then use SDL_SetColors() to
set the new palette.

SDL_SetPalette() is often more practical (it’s a generalisation of
SDL_SetColors()), since it lets you combine palette effects with blits.
See the little demo “testpalette” in the SDL source tarball for an example