11 /* Render blur in half x half dimenstions. Add one pixel padding in all
12 * directions (2 pixels horizontally, 2 pixels vertically).
14 #define BLUR_BUFFER_WIDTH (320/2 + 2)
15 #define BLUR_BUFFER_HEIGHT (240/2 + 2)
16 #define BLUR_BUFFER_SIZE (BLUR_BUFFER_WIDTH * BLUR_BUFFER_HEIGHT)
17 static unsigned char *blurBuffer, *blurBuffer2;
19 /* TODO: Load palette from file */
20 static unsigned short palette[256];
22 void clearBlurBuffer();
23 void drawPatternOnBlurBuffer();
27 static int init(void);
28 static void destroy(void);
29 static void start(long trans_time);
30 static void stop(long trans_time);
31 static void draw(void);
33 static unsigned int lastFrameTime = 0;
34 static float lastFrameDuration = 0.0f;
35 static struct screen scr = {
44 struct screen *thunder_screen(void)
53 blurBuffer = malloc(BLUR_BUFFER_SIZE);
54 blurBuffer2 = malloc(BLUR_BUFFER_SIZE);
58 /* For now, map to blue */
59 for (i = 0; i < 256; i++) {
66 static void destroy(void)
75 static void start(long trans_time)
77 lastFrameTime = time_msec;
81 static void draw(void)
84 lastFrameDuration = (time_msec - lastFrameTime) / 1000.0f;
85 lastFrameTime = time_msec;
87 drawPatternOnBlurBuffer();
94 void clearBlurBuffer() {
95 /* Clear the whole buffer (including its padding ) */
96 memset(blurBuffer, 0, BLUR_BUFFER_SIZE);
97 memset(blurBuffer2, 0, BLUR_BUFFER_SIZE);
100 void drawPatternOnBlurBuffer() {
102 unsigned char *dst = blurBuffer + BLUR_BUFFER_WIDTH + 1;
103 int starty, stopy, startx, stopx;
105 starty = rand() % 60;
106 stopy = starty + rand() % 60;
107 startx = rand() % 80;
108 stopx = startx + rand() % 80;
110 if (rand() % 2) return;
112 for (j = starty; j < stopy; j++) {
113 for (i = startx; i < stopx; i++) {
114 dst[i + j * BLUR_BUFFER_WIDTH] = 255;
122 unsigned char *src = blurBuffer + BLUR_BUFFER_WIDTH + 1;
123 unsigned char *dst = blurBuffer2 + BLUR_BUFFER_WIDTH + 1;
125 for (j = 0; j < 120; j++) {
126 for (i = 0; i < 160; i++) {
127 *dst = (*(src - 1) + *(src + 1) + *(src - BLUR_BUFFER_WIDTH) + *(src + BLUR_BUFFER_WIDTH)) >> 2;
131 /* Just skip the padding since we went through the scanline in the inner loop (except from the padding) */
136 /* Swap blur buffers */
138 blurBuffer = blurBuffer2;
143 unsigned int *dst1 = (unsigned int*) vmem_back;
144 unsigned int *dst2 = dst1 + 160; /* We're writing two pixels at once */
145 unsigned char *src1 = blurBuffer + BLUR_BUFFER_WIDTH + 1;
146 unsigned char *src2 = src1 + BLUR_BUFFER_WIDTH;
147 unsigned char tl, tr, bl, br;
150 for (j = 0; j < 120; j++) {
151 for (i = 0; i < 160; i++) {
153 tr = (*src1 + *(src1 + 1)) >> 1;
154 bl = (*src1 + *src2) >> 1;
155 br = tr + ((*src2 + *(src2 + 1)) >> 1) >> 1;
157 /* Pack 2 pixels in each 32 bit word */
158 *dst1 = (palette[tr] << 16) | palette[tl];
159 *dst2 = (palette[br] << 16) | palette[bl];
166 /* Again, skip padding */
170 /* For now, skip a scanline */