diff options
| author | erdgeist <> | 2003-05-13 12:05:12 +0000 |
|---|---|---|
| committer | erdgeist <> | 2003-05-13 12:05:12 +0000 |
| commit | 866f0ad8030ea2ceea22a4d61e6ff0006546c3fa (patch) | |
| tree | 54f3af1248bce246e1dd92b196b818271d21f2f6 /Gfx.c | |
Here we go
Diffstat (limited to 'Gfx.c')
| -rwxr-xr-x | Gfx.c | 65 |
1 files changed, 65 insertions, 0 deletions
| @@ -0,0 +1,65 @@ | |||
| 1 | #include "Gfx.h" | ||
| 2 | #include "Kullers.h" | ||
| 3 | |||
| 4 | static void *bitmap = (void*)0; | ||
| 5 | unsigned long g_width, g_height; | ||
| 6 | unsigned long minx, miny, maxx, maxy; | ||
| 7 | |||
| 8 | void Gfx_init( void *offscreen, int width, int height ) { | ||
| 9 | maxx = g_width = width; | ||
| 10 | maxy = g_height = height; | ||
| 11 | bitmap = offscreen; | ||
| 12 | minx = miny = 0; | ||
| 13 | } | ||
| 14 | |||
| 15 | void Gfx_destroy( void ) { | ||
| 16 | // if( bitmap ) | ||
| 17 | // free( bitmap ); | ||
| 18 | } | ||
| 19 | |||
| 20 | void Gfx_clear( void ) { | ||
| 21 | unsigned long *dest = ((unsigned long *)bitmap) + miny * g_width + minx; | ||
| 22 | int nochy = maxy - miny; | ||
| 23 | |||
| 24 | while( nochy-- ) { | ||
| 25 | memset( dest, 0, (maxx - minx) << 2); | ||
| 26 | dest += g_width; | ||
| 27 | } | ||
| 28 | |||
| 29 | minx = g_width; miny = g_height; | ||
| 30 | maxx = 0; maxy = 0; | ||
| 31 | } | ||
| 32 | |||
| 33 | int getkulleroff( int radius ) { | ||
| 34 | int sum = 0; | ||
| 35 | while( --radius>0 ) | ||
| 36 | sum += radius*radius; | ||
| 37 | return sum; | ||
| 38 | } | ||
| 39 | |||
| 40 | void Gfx_kuller( int x, int y, int radius, unsigned long r, unsigned long g, unsigned long b ) { | ||
| 41 | unsigned long *dest = ((unsigned long *)bitmap) + y * g_width + x; | ||
| 42 | unsigned char *src = Kullers + getkulleroff( radius ) - 1; | ||
| 43 | int xoffs = g_width - radius; | ||
| 44 | int nochy = radius; | ||
| 45 | |||
| 46 | if( minx > x ) minx = x; | ||
| 47 | if( miny > y ) miny = y; | ||
| 48 | if( maxx < x + radius ) maxx = x + radius; | ||
| 49 | if( maxy < y + radius ) maxy = y + radius; | ||
| 50 | |||
| 51 | while( nochy-- >0 ) { | ||
| 52 | int nochx = radius; | ||
| 53 | while( nochx-- >0 ) { | ||
| 54 | if( *(++src) ) { | ||
| 55 | int this_r = ((r * (int)*src) >> 8); | ||
| 56 | int this_g = ((g * (int)*src) >> 8); | ||
| 57 | int this_b = ((b * (int)*src) >> 8); | ||
| 58 | *(dest++) = (this_r<<16) | (this_g<<8) | this_b; | ||
| 59 | } else { | ||
| 60 | dest++; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | dest += xoffs; | ||
| 64 | } | ||
| 65 | } | ||
