Use pointers instead of structs to handle rleBitmap objects
[dosdemo] / src / grise.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5 #include <assert.h>
6 #include "imago2.h"
7 #include "demo.h"
8 #include "screen.h"
9
10 /* APPROX. 170 FPS Minimum */
11
12 typedef struct {
13         unsigned int w, h;
14         unsigned char *scans;
15 } RLEBitmap;
16
17 static RLEBitmap *rleCreate(unsigned int w, unsigned int h);
18 static void rleDestroy(RLEBitmap *b);
19 static void rleBlit(unsigned short *dst, int dstW, int dstH, int dstStride, 
20         RLEBitmap *bitmap, int blitX, int blitY);
21 static void rleBlitScale(unsigned short *dst, int dstW, int dstH, int dstStride,
22         RLEBitmap *bitmap, int blitX, int blitY, float scaleX, float scaleY);
23 static void rleBlitScaleInv(unsigned short *dst, int dstW, int dstH, int dstStride,
24         RLEBitmap *bitmap, int blitX, int blitY, float scaleX, float scaleY);
25 static RLEBitmap *rleEncode(RLEBitmap *b, unsigned char *pixels, unsigned int w, unsigned int h);
26
27 static void updatePropeller(float t);
28
29 #define BG_FILENAME "data/grise.png"
30 #define GROBJ_01_FILENAME "data/grobj_01.png"
31
32 #define BB_SIZE 512     /* Let's use a power of 2. Maybe we'll zoom/rotate the effect */
33
34 /* Every backBuffer scanline is guaranteed to have that many dummy pixels before and after */
35 #define PIXEL_PADDING 32
36
37 /* Make sure this is less than PIXEL_PADDING*/
38 #define MAX_DISPLACEMENT 16
39
40 #define MIN_SCROLL PIXEL_PADDING
41 #define MAX_SCROLL (backgroundW - fb_width - MIN_SCROLL)
42
43 #define FAR_SCROLL_SPEED 15.0f
44 #define NEAR_SCROLL_SPEED 120.0f
45
46 #define HORIZON_HEIGHT 100
47 #define REFLECTION_HEIGHT (240 - HORIZON_HEIGHT)
48
49 #define NORMALMAP_SCANLINE 372
50
51 static int init(void);
52 static void destroy(void);
53 static void start(long trans_time);
54 static void stop(long trans_time);
55 static void draw(void);
56
57 static void convert32To16(unsigned int *src32, unsigned short *dst16, unsigned int pixelCount);
58 static void processNormal();
59 static void initScrollTables();
60 static void updateScrollTables(float dt);
61
62
63
64 static unsigned short *background = 0;
65 static unsigned int backgroundW = 0;
66 static unsigned int backgroundH = 0;
67
68 static unsigned int lastFrameTime = 0;
69 static float lastFrameDuration = 0.0f;
70
71 static short *displacementMap;
72
73 static unsigned short *backBuffer;
74
75 static float scrollScaleTable[REFLECTION_HEIGHT];
76 static float scrollTable[REFLECTION_HEIGHT];
77 static int scrollTableRounded[REFLECTION_HEIGHT];
78 static int scrollModTable[REFLECTION_HEIGHT];
79 static float nearScrollAmount = 0.0f;
80
81 static char miniFXBuffer[1024];
82
83 static RLEBitmap *grobj = 0;
84
85 static struct screen scr = {
86         "galaxyrise",
87         init,
88         destroy,
89         start,
90         stop,
91         draw
92 };
93
94 struct screen *grise_screen(void)
95 {
96         return &scr;
97 }
98
99
100 static int init(void)
101 {
102         unsigned char *tmpBitmap;
103         int tmpBitmapW, tmpBitmapH;
104
105         /* Allocate back buffer */
106         backBuffer = (unsigned short*) calloc(BB_SIZE * BB_SIZE, sizeof(unsigned short));
107
108         /* grise.png contains the background (horizon), baked reflection and normalmap for displacement */
109         if (!(background = img_load_pixels(BG_FILENAME, &backgroundW, &backgroundH, IMG_FMT_RGBA32))) {
110                 fprintf(stderr, "failed to load image " BG_FILENAME "\n");
111                 return -1;
112         }
113
114         /* Convert to 16bpp */
115         convert32To16((unsigned int*)background, background, backgroundW * NORMALMAP_SCANLINE); /* Normalmap will keep its 32 bit color */
116
117         /* Load reflected objects */
118         if (!(tmpBitmap = img_load_pixels(GROBJ_01_FILENAME, &tmpBitmapW, &tmpBitmapH, IMG_FMT_GREY8))) {
119                 fprintf(stderr, "failed to load image " GROBJ_01_FILENAME "\n");
120                 return -1;
121         }
122
123         grobj = rleEncode(0, tmpBitmap, tmpBitmapW, tmpBitmapH);
124
125         img_free_pixels(tmpBitmap);
126
127         initScrollTables();
128
129         processNormal();
130
131 #ifdef MIKE_PC
132         return 0xCAFE;
133 #else
134         return 0;
135 #endif
136 }
137
138 static void destroy(void)
139 {
140         free(backBuffer);
141         backBuffer = 0;
142
143         img_free_pixels(background);
144
145         rleDestroy(grobj);
146 }
147
148 static void start(long trans_time)
149 {
150         lastFrameTime = time_msec;
151 }
152
153 static void stop(long trans_time)
154 {
155 }
156
157
158
159
160 static void draw(void)
161 {       
162         int scroll = MIN_SCROLL + (MAX_SCROLL - MIN_SCROLL) * mouse_x / fb_width;
163         unsigned short *dst = backBuffer + PIXEL_PADDING;
164         unsigned short *src = background + scroll;
165         int scanline = 0;
166         int i = 0;
167         short *dispScanline;
168         int d;
169
170         lastFrameDuration = (time_msec - lastFrameTime) / 1000.0f;
171         lastFrameTime = time_msec;
172
173         /* Update mini-effects here */
174         updatePropeller(time_msec / 1000.0f);
175
176         /* First, render the horizon */
177         for (scanline = 0; scanline < HORIZON_HEIGHT; scanline++) {
178                 memcpy(dst, src, fb_width * 2);
179                 src += backgroundW;
180                 dst += BB_SIZE;
181         }
182         
183         /* Create scroll offsets for all scanlines of the normalmap */
184         updateScrollTables(lastFrameDuration);
185
186         /* Render the baked reflection one scanline below its place, so that 
187          * the displacement that follows will be done in a cache-friendly way
188          */
189         src -= PIXEL_PADDING; /* We want to also fill the PADDING pixels here */
190         dst = backBuffer + (HORIZON_HEIGHT + 1) * BB_SIZE;
191         for (scanline = 0; scanline < REFLECTION_HEIGHT; scanline++) {
192                 memcpy(dst, src, (fb_width + PIXEL_PADDING) * 2);
193                 src += backgroundW;
194                 dst += BB_SIZE;
195         }
196
197         /* Blit reflections first, to be  displaced */
198         for (i = 0; i < 5; i++) rleBlitScaleInv(backBuffer + PIXEL_PADDING, fb_width, fb_height, BB_SIZE, grobj, 134 + (i-3) * 60, 235, 1.0f, 1.8f);
199
200         /* Perform displacement */
201         dst = backBuffer + HORIZON_HEIGHT * BB_SIZE + PIXEL_PADDING;
202         src = dst + BB_SIZE; /* The pixels to be displaced are 1 scanline below */
203         dispScanline = displacementMap;
204         for (scanline = 0; scanline < REFLECTION_HEIGHT; scanline++) {
205                 for (i = 0; i < fb_width; i++) {
206                         d = dispScanline[(i + scrollTableRounded[scanline]) % scrollModTable[scanline]];
207                         *dst++ = src[i + d];
208                 }
209                 src += backgroundW;
210                 dst += BB_SIZE - fb_width;
211                 dispScanline += backgroundW;
212         }
213
214         /* Then after displacement, blit the objects */
215         for (i = 0; i < 5; i++) rleBlit(backBuffer + PIXEL_PADDING, fb_width, fb_height, BB_SIZE, grobj, 134 + (i-3) * 60, 100);
216
217         for (scanline = 0; scanline < 32; scanline++) {
218                 for (i = 0; i < 32; i++) {
219                         backBuffer[PIXEL_PADDING + scanline * BB_SIZE + i] = miniFXBuffer[i + 32 * scanline] ? 0xFFFF : 0x0000;
220                 }
221         }
222
223         /* Blit effect to framebuffer */
224         src = backBuffer + PIXEL_PADDING;
225         dst = vmem_back;
226         for (scanline = 0; scanline < fb_height; scanline++) {
227                 memcpy(dst, src, fb_width * 2);
228                 src += BB_SIZE; 
229                 dst += fb_width;
230         }
231
232         swap_buffers(0);
233 }
234
235 /* src and dst can be the same */
236 static void convert32To16(unsigned int *src32, unsigned short *dst16, unsigned int pixelCount) {
237         unsigned int p;
238         while (pixelCount) {
239                 p = *src32++;
240                 *dst16++ =      ((p << 8) & 0xF800)             /* R */
241                         |               ((p >> 5) & 0x07E0)             /* G */
242                         |               ((p >> 19) & 0x001F);   /* B */
243                 pixelCount--;
244         }
245 }
246
247 /* Normal map preprocessing */
248 /* Scale normal with depth and unpack R component (horizontal component) */
249 static void processNormal() {
250         int scanline;
251         int i;
252         int x;
253         short maxDisplacement = 0;
254         short minDisplacement = 256;
255         unsigned short *dst;
256         short *dst2;
257         unsigned int *normalmap = (unsigned int*)background;
258         normalmap += NORMALMAP_SCANLINE * backgroundW;
259         dst = (unsigned short*)normalmap;
260         displacementMap = (short*)dst;
261         dst2 = displacementMap;
262
263         for (scanline = 0; scanline < REFLECTION_HEIGHT; scanline++) {
264                 scrollModTable[scanline] = (int) (backgroundW / scrollScaleTable[scanline] + 0.5f);
265                 for (i = 0; i < backgroundW; i++) {
266                         x = (int)(i * scrollScaleTable[scanline] + 0.5f);
267                         if (x < backgroundW) {
268                                 *dst = (unsigned short)(normalmap[x] >> 8) & 0xFF;
269                                 if ((short)*dst > maxDisplacement) maxDisplacement = (short)(*dst);
270                                 if ((short)*dst < minDisplacement) minDisplacement = (short)(*dst);
271                         } else {
272                                 *dst = 0;
273                         }
274                         dst++;
275                 }
276                 normalmap += backgroundW;
277         }
278
279         if (maxDisplacement == minDisplacement) {
280                 printf("Warning: grise normalmap fucked up\n");
281                 return;
282         }
283
284         /* Second pass - subtract half maximum displacement to displace in both directions */
285         for (scanline = 0; scanline < REFLECTION_HEIGHT; scanline++) {
286                 for (i = 0; i < backgroundW; i++) {
287                         /* Remember that MIN_SCROLL is the padding around the screen, so ti's the maximum displacement we can get (positive & negative) */
288                         *dst2 = 2 * MAX_DISPLACEMENT * (*dst2 - minDisplacement) / (maxDisplacement - minDisplacement) - MAX_DISPLACEMENT;
289                         *dst2 = (short)((float)*dst2 / scrollScaleTable[scanline] + 0.5f); /* Displacements must also scale with distance*/
290                         dst2++;
291                 }
292         }
293 }
294
295 static float distanceScale(int scanline) {
296         float farScale, t;
297         farScale = (float)NEAR_SCROLL_SPEED / (float)FAR_SCROLL_SPEED;
298         t = (float)scanline / ((float)REFLECTION_HEIGHT - 1);
299         return 1.0f / (1.0f / farScale + (1.0f - 1.0f / farScale) * t);
300 }
301
302 static void initScrollTables() {
303         int i = 0;
304         for (i = 0; i < REFLECTION_HEIGHT; i++) {
305                 scrollScaleTable[i] = distanceScale(i);
306                 scrollTable[i] = 0.0f;
307                 scrollTableRounded[i] = 0;
308         }
309 }
310
311
312 static void updateScrollTables(float dt) {
313         int i = 0;
314         
315         nearScrollAmount += dt * NEAR_SCROLL_SPEED;
316         nearScrollAmount = (float) fmod(nearScrollAmount, 512.0f);
317
318         for (i = 0; i < REFLECTION_HEIGHT; i++) {
319                 scrollTable[i] = nearScrollAmount / scrollScaleTable[i];
320                 scrollTableRounded[i] = (int)(scrollTable[i] + 0.5f) % scrollModTable[i];
321         }
322 }
323
324 /* -------------------------------------------------------------------------------------------------
325  *                                   RLE STUFF                                                                           
326  * -------------------------------------------------------------------------------------------------
327  */
328 /* Limit streak count per scanline so we can directly jump to specific scanline */
329 #define RLE_STREAKS_PER_SCANLINE 4
330 /* Every streak is encoded by 2 bytes: offset and count of black pixels in the streak */
331 #define RLE_BYTES_PER_SCANLINE RLE_STREAKS_PER_SCANLINE * 2
332 #define RLE_FILL_COLOR 0
333 #define RLE_FILL_COLOR_32 ((RLE_FILL_COLOR << 16) | RLE_FILL_COLOR)
334
335 #define RLE_FIXED_BITS 16
336
337 static RLEBitmap *rleCreate(unsigned int w, unsigned int h) {
338         RLEBitmap *ret = (RLEBitmap*)malloc(sizeof(RLEBitmap));
339         ret->w = w;
340         ret->h = h;
341
342         /* Add some padding at the end of the buffer, with the worst case for a scanline (w/2 streaks) */
343         ret->scans = (unsigned char*) calloc(h * RLE_BYTES_PER_SCANLINE + w, 1);
344
345         return ret;
346 }
347
348 static void rleDestroy(RLEBitmap *b) {
349         if (!b) return;
350         free(b->scans);
351         free(b);
352 }
353
354 static RLEBitmap *rleEncode(RLEBitmap *b, unsigned char *pixels, unsigned int w, unsigned int h) {
355         int scanline;
356         int i;
357         int penActive = 0;
358         int counter = 0;
359         int accum = 0;
360         unsigned char *output;
361
362         /* https://www.youtube.com/watch?v=RKMR02o1I88&feature=youtu.be&t=55 */
363         if (!b) b = rleCreate(w, h);
364
365         for (scanline = 0; scanline < h; scanline++) {
366                 output = b->scans + scanline * RLE_BYTES_PER_SCANLINE;
367                 accum = 0;
368                 for (i = 0; i < w; i++) {
369                         if (*pixels++) {
370                                 if (penActive) {
371                                         if (counter >= PIXEL_PADDING) {
372                                                 *output++ = (unsigned char) counter;
373                                                 counter = 0;
374                                                 *output++ = (unsigned char)accum;
375                                         }
376                                         counter++;
377                                         accum++;
378                                 } else {
379                                         *output++ = (unsigned char)accum;
380                                         counter = 1;
381                                         accum++;
382                                         penActive = 1;
383                                 }
384                         } else {
385                                 if (penActive) {
386                                         *output++ = (unsigned char)counter;
387                                         counter = 1;
388                                         accum++;
389                                         penActive = 0;
390                                 } else {
391                                         counter++;
392                                         accum++;
393                                 }
394                         }
395                 }
396
397                 if (penActive) {
398                         *output++ = (unsigned char)counter;
399                 }
400                 penActive = 0;
401                 counter = 0;
402         }
403
404         return b;
405 }
406
407 static void rleBlit(unsigned short *dst, int dstW, int dstH, int dstStride,
408         RLEBitmap *bitmap, int blitX, int blitY) 
409 {
410         int scanline = 0;
411         int streakPos = 0;
412         int streakLength = 0;
413         int streak = 0;
414         unsigned char *input = bitmap->scans;
415         unsigned short *output;
416         unsigned int *output32;
417
418         dst += blitX + blitY * dstStride;
419
420         for (scanline = blitY; scanline < blitY + bitmap->h; scanline++) {
421                 if (scanline < 0 || scanline >= dstH) continue;
422                 for (streak = 0; streak < RLE_STREAKS_PER_SCANLINE; streak++) {
423                         streakPos = *input++;
424                         streakLength = *input++;
425
426                         if ((streakPos + blitX) <= 0) continue;
427
428                         output = dst + streakPos;
429
430                         /* Check if we need to write the first pixel as 16bit */
431                         if (streakLength % 2) {
432                                 *output++ = RLE_FILL_COLOR;
433                         }
434
435                         /* Then, write 2 pixels at a time */
436                         streakLength >>= 1;
437                         output32 = (unsigned int*) output;
438                         while (streakLength--) {
439                                 *output32++ = RLE_FILL_COLOR_32;
440                         }
441                 }
442
443                 dst += dstStride;
444         }
445 }
446
447 static void interpolateScan(unsigned char *output, unsigned char *a, unsigned char *b, float t) {
448         static int div = 1 << 23;
449         int ti, i;
450
451         t += 1.0f;
452         ti = (*((unsigned int*)&t)) & 0x7FFFFF;
453         
454         for (i = 0; i < RLE_BYTES_PER_SCANLINE; i++) {
455                 if (*a == 0) {
456                         *output++ = *b++;
457                         a++;
458                 } else {
459                         if (*b == 0) {
460                                 *output++ = *a++;
461                                 b++;
462                         } else {
463                                 *output++ = ((*b++ * ti) + (*a++ * (div - ti))) >> 23;
464                         }
465                 }
466         }
467 }
468
469 static void rleBlitScale(unsigned short *dst, int dstW, int dstH, int dstStride,
470         RLEBitmap *bitmap, int blitX, int blitY, float scaleX, float scaleY)
471 {
472         int scanline = 0;
473         int streakPos = 0;
474         int streakLength = 0;
475         int streak = 0;
476         unsigned short *output;
477         unsigned int *output32;
478         unsigned char *input;
479         int scanlineCounter = 0;
480         static unsigned char scan[512];
481
482         int blitW = (int)(bitmap->w * scaleX + 0.5f);
483         int blitH = (int)(bitmap->h * scaleY + 0.5f);
484
485         /* From this point on, scaleY will be inverted */
486         scaleY = 1.0f / scaleY;
487
488         int scaleXFixed = (int)(scaleX * (float)(1 << RLE_FIXED_BITS) + 0.5f);
489         
490         dst += blitX + blitY * dstStride;
491
492         for (scanline = blitY; scanline < blitY + blitH; scanline++) {
493                 float normalScan = scanlineCounter * scaleY; /* ScaleY  is inverted */
494                 unsigned char *scan0 = bitmap->scans + RLE_BYTES_PER_SCANLINE * (int)normalScan;
495                 unsigned char *scan1 = scan0 + RLE_BYTES_PER_SCANLINE;
496                 normalScan -= (int)normalScan;
497                 interpolateScan(scan, scan0, scan1, normalScan);
498                 input = scan;
499                 scanlineCounter++;
500
501                 if (scanline < 0 || scanline >= dstH) continue;
502                 for (streak = 0; streak < RLE_STREAKS_PER_SCANLINE; streak++) {
503                         streakPos = (*input++ * scaleXFixed) >> RLE_FIXED_BITS;
504                         streakLength = (*input++ * scaleXFixed) >> RLE_FIXED_BITS;
505
506                         if ((streakPos + blitX) <= 0) continue;
507
508                         output = dst + streakPos;
509
510                         /* Check if we need to write the first pixel as 16bit */
511                         if (streakLength % 2) {
512                                 *output++ = RLE_FILL_COLOR;
513                         }
514
515                         /* Then, write 2 pixels at a time */
516                         streakLength >>= 1;
517                         output32 = (unsigned int*)output;
518                         while (streakLength--) {
519                                 *output32++ = RLE_FILL_COLOR_32;
520                         }
521                 }
522
523                 dst += dstStride;
524         }
525 }
526
527
528
529 static void rleBlitScaleInv(unsigned short *dst, int dstW, int dstH, int dstStride,
530         RLEBitmap *bitmap, int blitX, int blitY, float scaleX, float scaleY)
531 {
532         int scanline = 0;
533         int streakPos = 0;
534         int streakLength = 0;
535         int streak = 0;
536         unsigned short *output;
537         unsigned int *output32;
538         unsigned char *input;
539         int scanlineCounter = 0;
540         static unsigned char scan[512];
541
542         int blitW = (int)(bitmap->w * scaleX + 0.5f);
543         int blitH = (int)(bitmap->h * scaleY + 0.5f);
544
545         /* From this point on, scaleY will be inverted */
546         scaleY = 1.0f / scaleY;
547
548         int scaleXFixed = (int)(scaleX * (float)(1 << RLE_FIXED_BITS) + 0.5f);
549
550         dst += blitX + blitY * dstStride;
551
552         for (scanline = blitY; scanline > blitY - blitH; scanline--) {
553                 float normalScan = scanlineCounter * scaleY; /* ScaleY is inverted */
554                 unsigned char *scan0 = bitmap->scans + RLE_BYTES_PER_SCANLINE * (int)normalScan;
555                 unsigned char *scan1 = scan0 + RLE_BYTES_PER_SCANLINE;
556                 normalScan -= (int)normalScan;
557                 interpolateScan(scan, scan0, scan1, normalScan);
558                 input = scan;
559                 scanlineCounter++;
560
561                 if (scanline < 0 || scanline >= dstH) continue;
562                 for (streak = 0; streak < RLE_STREAKS_PER_SCANLINE; streak++) {
563                         streakPos = (*input++ * scaleXFixed) >> RLE_FIXED_BITS;
564                         streakLength = (*input++ * scaleXFixed) >> RLE_FIXED_BITS;
565
566                         if ((streakPos + blitX) <= 0) continue;
567
568                         output = dst + streakPos;
569
570                         /* Check if we need to write the first pixel as 16bit */
571                         if (streakLength % 2) {
572                                 *output++ = RLE_FILL_COLOR;
573                         }
574
575                         /* Then, write 2 pixels at a time */
576                         streakLength >>= 1;
577                         output32 = (unsigned int*)output;
578                         while (streakLength--) {
579                                 *output32++ = RLE_FILL_COLOR_32;
580                         }
581                 }
582
583                 dst -= dstStride;
584         }
585 }
586
587 /* -------------------------------------------------------------------------------------------------
588 *                                   PROPELLER STUFF
589 * -------------------------------------------------------------------------------------------------
590 */
591
592 #define PROPELLER_CIRCLE_RADIUS 18
593 #define PROPELLER_CIRCLE_RADIUS_SQ (PROPELLER_CIRCLE_RADIUS * PROPELLER_CIRCLE_RADIUS)
594
595 static struct {
596         int circleX[3];
597         int circleY[3];
598 } propellerState;
599
600 static void updatePropeller(float t) {
601         int i, j;
602         int cx, cy, count = 0;
603         char *dst;
604         float x = 0.0f;
605         float y = 18.0f;
606         float nx, ny;
607         float cost, sint;
608         static float sin120 = 0.86602540378f;
609         static float cos120 = -0.5f;
610
611         /* Rotate */
612         sint = sin(t);
613         cost = cos(t);
614         nx = x * cost - y * sint;
615         ny = y * cost + x * sint;
616         x = nx;
617         y = ny;
618         propellerState.circleX[0] = (int)(x + 0.5f) + 16;
619         propellerState.circleY[0] = (int)(y + 0.5f) + 16;
620
621         /* Rotate by 120 degrees, for the second circle */
622         nx = x * cos120 - y * sin120;
623         ny = y * cos120 + x * sin120;
624         x = nx;
625         y = ny;
626         propellerState.circleX[1] = (int)(x + 0.5f) + 16;
627         propellerState.circleY[1] = (int)(y + 0.5f) + 16;
628
629         /* 3rd circle */
630         nx = x * cos120 - y * sin120;
631         ny = y * cos120 + x * sin120;
632         x = nx;
633         y = ny;
634         propellerState.circleX[2] = (int)(x + 0.5f) + 16;
635         propellerState.circleY[2] = (int)(y + 0.5f) + 16;
636
637         /* Write effect to the mini fx buffer*/
638         dst = miniFXBuffer;
639         for (j = 0; j < 32; j++) {
640                 for (i = 0; i < 32; i++) {
641                         count = 0;
642
643                         /* First circle */
644                         cx = propellerState.circleX[0] - i;
645                         cy = propellerState.circleY[0] - j;
646                         if (cx*cx + cy*cy < PROPELLER_CIRCLE_RADIUS_SQ) count++;
647
648                         /* 2nd circle */
649                         cx = propellerState.circleX[1] - i;
650                         cy = propellerState.circleY[1] - j;
651                         if (cx*cx + cy*cy < PROPELLER_CIRCLE_RADIUS_SQ) count++;
652
653                         /* 3rd circle */
654                         cx = propellerState.circleX[2] - i;
655                         cy = propellerState.circleY[2] - j;
656                         if (cx*cx + cy*cy < PROPELLER_CIRCLE_RADIUS_SQ) count++;
657
658                         *dst++ = count >= 2;
659                 }
660         }
661 }