#include "Gfx.h" #include "Kullers.h" static void *bitmap = (void*)0; unsigned long g_width, g_height; unsigned long minx, miny, maxx, maxy; void Gfx_init( void *offscreen, int width, int height ) { maxx = g_width = width; maxy = g_height = height; bitmap = offscreen; minx = miny = 0; } void Gfx_destroy( void ) { // if( bitmap ) // free( bitmap ); } void Gfx_clear( void ) { unsigned long *dest = ((unsigned long *)bitmap) + miny * g_width + minx; int nochy = maxy - miny; while( nochy-- ) { memset( dest, 0, (maxx - minx) << 2); dest += g_width; } minx = g_width; miny = g_height; maxx = 0; maxy = 0; } int getkulleroff( int radius ) { int sum = 0; while( --radius>0 ) sum += radius*radius; return sum; } void Gfx_kuller( int x, int y, int radius, unsigned long r, unsigned long g, unsigned long b ) { unsigned long *dest = ((unsigned long *)bitmap) + y * g_width + x; unsigned char *src = Kullers + getkulleroff( radius ) - 1; int xoffs = g_width - radius; int nochy = radius; if( minx > x ) minx = x; if( miny > y ) miny = y; if( maxx < x + radius ) maxx = x + radius; if( maxy < y + radius ) maxy = y + radius; while( nochy-- >0 ) { int nochx = radius; while( nochx-- >0 ) { if( *(++src) ) { int this_r = ((r * (int)*src) >> 8); int this_g = ((g * (int)*src) >> 8); int this_b = ((b * (int)*src) >> 8); *(dest++) = (this_r<<16) | (this_g<<8) | this_b; } else { dest++; } } dest += xoffs; } }