summaryrefslogtreecommitdiff
path: root/Gfx.c
blob: 1145f9a83aa048975dbf8d6105cc4028699a1872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#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;
    }
}