Fast'ish putpixel/getpixel code and demo

Hi, I’ve written up some fairly fast pixel put/get routines - and encapsulated
them into a little demo which tests out lots of vid modes and speeds
(file attached).

The files of main interest, ignoring the demo stuff are:

PixDemo/src/SDL_PutPixel.c
PixDemo/src/SDL_GetPixel.c
PixDemo/include/SDL_Pixel.h

Here’s a snippet of the C functions provided (there are also lots of
other pitch-depth-hardwired macros for really fast pixel access):

SDL_PutPixel(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 rgb);
SDL_LowerPutPixel(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 rgb);
SDL_GetCacheLowerPutPixel(SDL_Surface *dst);

SDL_GetPixel(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 * rgb);
SDL_LowerGetPixel(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 * rgb);
SDL_GetCacheLowerGetPixel(SDL_Surface *dst);

There’s 4 levels of pixel access supported, each progressively quicker and
less flexible. Everything up to and including level 3 is generic for any
surface. I don’t evisage level 4 being used much.

1. SDL_Put/GetPixel              -- slow, clips and locks surfaces
2. SDL_LowerPut/GetPixel         -- no clipping assumes already locked
3. SDL_CachePut/GetPixel         -- precalculated function suitable for 
									surface and in doing so negates need 
								    for u pitch and depth switches.
4. SDL_Put/Get<width x bpp>Pixel -- macros specific to a surface type

Level 3 is completely generic and competes fairly well with (!) FillRect for the
majority of surfaces. Here’s some performance figures (from the demo)

pixdemo: Screen 640x480 @ 8 bits per pixel
pixdemo: Running 25 loops for each PutPixel routine to test fps
		 Also testing output from each GetPixel routine.
 => SDL_PutPixel()                             --  6.63 FPS
 => SDL_LowerPutPixel()                        --  10.28 FPS
 => SDL_GetCacheLowerPutPixel()                --  16.79 FPS
 => SDL_PutPixel_640x8bpp()                    --  20.60 FPS
 => SDL_FillRect()           (for comparison!) --  24.55 FPS

Please let me know if anyone is interested-at-all in this.

Thanks!

Neil–

Neil McGill mailto:Neil_McGill *8^) . .
Software Developer:ISDN, Cisco Systems Ltd ~~""~""~"~"|~"~
3rd Floor, 96 Commercial Street, Edinburgh, EH6 6LX, UK ||| |||
Tel: 0131 561 3622 Fax: 0131 561 3601 Mob: 07714 226 281 .:|||||:.:|||||:.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: PixDemo.tgz
Type: application/octet-stream
Size: 23649 bytes
Desc:
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/19991026/ec1ccb3f/attachment.obj

I’m. i’m.
get me the code plzOn Tue, 26 Oct 1999, Neil McGill wrote:

Hi, I’ve written up some fairly fast pixel put/get routines - and encapsulated
them into a little demo which tests out lots of vid modes and speeds
(file attached).

The files of main interest, ignoring the demo stuff are:

PixDemo/src/SDL_PutPixel.c
PixDemo/src/SDL_GetPixel.c
PixDemo/include/SDL_Pixel.h

Here’s a snippet of the C functions provided (there are also lots of
other pitch-depth-hardwired macros for really fast pixel access):

SDL_PutPixel(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 rgb);
SDL_LowerPutPixel(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 rgb);
SDL_GetCacheLowerPutPixel(SDL_Surface *dst);

SDL_GetPixel(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 * rgb);
SDL_LowerGetPixel(SDL_Surface *dst, Sint16 x, Sint16 y, Uint32 * rgb);
SDL_GetCacheLowerGetPixel(SDL_Surface *dst);

There’s 4 levels of pixel access supported, each progressively quicker and
less flexible. Everything up to and including level 3 is generic for any
surface. I don’t evisage level 4 being used much.

  1. SDL_Put/GetPixel – slow, clips and locks surfaces
  2. SDL_LowerPut/GetPixel – no clipping assumes already locked
  3. SDL_CachePut/GetPixel – precalculated function suitable for
    surface and in doing so negates need
    for u pitch and depth switches.
  4. SDL_Put/GetPixel – macros specific to a surface type

Level 3 is completely generic and competes fairly well with (!) FillRect for the
majority of surfaces. Here’s some performance figures (from the demo)

pixdemo: Screen 640x480 @ 8 bits per pixel
pixdemo: Running 25 loops for each PutPixel routine to test fps
Also testing output from each GetPixel routine.
=> SDL_PutPixel() – 6.63 FPS
=> SDL_LowerPutPixel() – 10.28 FPS
=> SDL_GetCacheLowerPutPixel() – 16.79 FPS
=> SDL_PutPixel_640x8bpp() – 20.60 FPS
=> SDL_FillRect() (for comparison!) – 24.55 FPS

Please let me know if anyone is interested-at-all in this.

Thanks!

Neil

Neil McGill <mailto:nmcgill at cisco.com> *8^) . .
Software Developer:ISDN, Cisco Systems Ltd ~~""~""~"~"|~"~
3rd Floor, 96 Commercial Street, Edinburgh, EH6 6LX, UK ||| |||
Tel: 0131 561 3622 Fax: 0131 561 3601 Mob: 07714 226 281 .:|||||:.:|||||:.

Pensa alla vita: usa le cinture di sicurezza.

Michel Morelli michel at enter.it
http://ziobudda.enter.it
Italian Linux FAQ http://ziobudda.enter.it/FAQ/
Italian Linux Press http://ziobudda.enter.it/ILP/