What is SDL RLE acceleration?

Hello!!!

What the SDL RLE acceleration does???

thanks!

Hello!!!

What the SDL RLE acceleration does???

RLE accelleration is used when using a colorkey (that is, when you pick
a particular color in your surface that you wish to be transparent…
it’s like the transparency capabilities of GIF images).

RLE (Run-Length-Encoding) is a way of compressing data so that repeats
are made smaller. For example, if you had an image that looked like this:--------
–####–
-######-
-######-
–####–

("-" is white and “#” is black)

Instead of saying “white,” “white, white, white, white, white,” …
“white, white, black, black, black, black, white, white…”, etc.,
(storing each and every pixel)…

the RLE version would say “10 whites, 4 blacks, 3 whites, 6 blacks,
2 whites, 6 blacks, 3 whites, 4 blacks, 10 whites,” which in many cases
would save lots of space in a file.

How this works in SDL when doing colorkey blitting is by replacing this
kind of code:

if (pixel != the_transparent_color)
draw_pixel(…);

which would result in “width * height” ‘if’ comparisons, the RLE blitting
speeds this up by using memcpy() to copy chunks of non-transparent pixels
all at once (much in the way that an SDL_BlitSurface() works when dealing
with an image that does NOT have a colorkey)

Whew… Hope that made sense…

-bill!
(who’s distracted by what’s going on in the living room :slight_smile: )

Hello!!!

What the SDL RLE acceleration does???

RLE accelleration is used when using a colorkey (that is, when you pick
a particular color in your surface that you wish to be transparent…
it’s like the transparency capabilities of GIF images).

RLE (Run-Length-Encoding) is a way of compressing data so that repeats
are made smaller. For example, if you had an image that looked like this:


–####–
-######-
-######-
–####–

("-" is white and “#” is black)

Instead of saying “white,” “white, white, white, white, white,” …
“white, white, black, black, black, black, white, white…”, etc.,
(storing each and every pixel)…

the RLE version would say “10 whites, 4 blacks, 3 whites, 6 blacks,
2 whites, 6 blacks, 3 whites, 4 blacks, 10 whites,” which in many cases
would save lots of space in a file.

How this works in SDL when doing colorkey blitting is by replacing this
kind of code:

if (pixel != the_transparent_color)
draw_pixel(…);

which would result in “width * height” ‘if’ comparisons, the RLE blitting
speeds this up by using memcpy() to copy chunks of non-transparent pixels
all at once (much in the way that an SDL_BlitSurface() works when dealing
with an image that does NOT have a colorkey)

and how to uses this ?
if i do:

planet = SDL_LoadBMP(“image/planet1.bmp”);
planet_image = SDL_DisplayFormat(planet);
then i go and put it onto an surface - where to put it ?
and how exactly is the colorkey definde in r g b ??

Thankz

joachimOn Son, 18 Jun 2000, you wrote:

Whew… Hope that made sense…

-bill!
(who’s distracted by what’s going on in the living room :slight_smile: )

From:
Joachim Schiele
[ http://www.dune2.de || Linux - my way! ]

and how to uses this ?
if i do:

planet = SDL_LoadBMP(“image/planet1.bmp”);
planet_image = SDL_DisplayFormat(planet);
then i go and put it onto an surface - where to put it ?
and how exactly is the colorkey definde in r g b ??

temp = SDL_LoadBMP(“image/planet1.bmp”);
SDL_SetColorKey(temp, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
SDL_MapRGB(temp -> format,
r, g, b));
planet_image = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);

-bill!

(Notice I used “temp”, and then free’d it afterwards… no point in
keeping two copies of image in memory if you’re only using one of them)

(Also note: There’s no error checking in my example. You must check to
see if temp is NULL… if so, you were unable to load the image.
Check SDL_SetColorKey() for -1… if so, the call failed.
And check planet_image for NULL… if so, the DisplayFormat() call failed.
(Most of this would only happen due to lack of memory…))

thanks!!