xref: /haiku/src/add-ons/screen_savers/nebula/DrawStars.c (revision ca8ed5ea660fb6275799a3b7f138b201c41a667b)
1 /*
2  * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Copyright 2015, Augustin Cavalier <waddlesplash>. All rights reserved.
4  * Distributed under the terms of the MIT License.
5  *
6  * Effect from corTeX / Optimum.
7  */
8 
9 #include <SupportDefs.h>
10 
11 #include "DrawStars.h"
12 
13 
14 // Hand-translated from x86 assembly.
15 /* draw a star (5 pixels) */
16 void draw_stars(int star_width, char* dstParam, char incParam)
17 {
18 	unsigned char* dst;
19 	unsigned char inc, al, cl;
20 	dst = (unsigned char*)dstParam;
21 	inc = (unsigned char)incParam;
22 
23 	dst[star_width] += inc;
24 	if (dst[star_width] < inc) {
25 		// Overflowed.
26 		dst[star_width] = 255;
27 	}
28 
29 	inc >>= 1;
30 	cl = dst[star_width - 1];
31 	cl += inc;
32 	if (cl < inc) {
33 		*dst = 255;
34 		dst[star_width - 1] = 255;
35 	} else {
36 		al = *dst;
37 		al += inc;
38 		if (al >= inc)
39 			*dst = al;
40 		else
41 			*dst = 255;
42 		dst[star_width - 1] = cl;
43 	}
44 
45 	al = dst[star_width * 2];
46 	cl = dst[star_width + 1];
47 	al += inc;
48 	cl += inc;
49 	if (al < inc) {
50 		if (cl >= inc) {
51 			dst[star_width * 2] = 255;
52 			dst[star_width + 1] = cl;
53 			return;
54 		}
55 	} else {
56 		if (cl >= inc) {
57 			dst[star_width * 2] = al;
58 			dst[star_width + 1] = cl;
59 			return;
60 		}
61 	}
62 
63 	dst[star_width * 2] = 255;
64 	dst[star_width + 1] = 255;
65 }
66