commit 1a84d39

Devine Lu Linvega  ·  2024-11-19 23:46:25 +0000 UTC
parent c0dccb0
New 1bpp implementation
1 files changed,  +24, -9
+24, -9
 1@@ -45,10 +45,9 @@ screen_2bpp(Uint8 *layer, Uint8 *addr, Uint16 x1, Uint16 y1, Uint16 color, int f
 2 static void
 3 screen_1bpp(Uint8 *layer, Uint8 *addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
 4 {
 5-	int xi, y;
 6-	Uint16 top = y1, bottom = y1 + 8, left = x1, right = x1 + 8, offset2 = 0;
 7-	int row, w = uxn_screen.width, opaque = (color % 5);
 8-	Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
 9+	int x, y;
10+	Uint16 top = y1, bottom = y1 + 8, left = x1, right = x1 + 8, offset2 = 0, offset3 = 0;
11+	int row, opaque = (color % 5);
12 	/* find vertical bounds */
13 	if(y1 > 0xfff8){
14 		top = 0;
15@@ -57,16 +56,32 @@ screen_1bpp(Uint8 *layer, Uint8 *addr, Uint16 x1, Uint16 y1, Uint16 color, int f
16 	}
17 	else if(y1 > uxn_screen.height)
18 		return;
19-	
20+	else if(y1 >  uxn_screen.height - 8){
21+		bottom =  uxn_screen.height;
22+	}
23 
24+	/* find hor bounds  */
25+	if(x1 > 0xfff8){
26+		left = 0;
27+		if(right > 0x8000) right = 0;
28+		offset3 = 0 - x1;
29+	}
30+	else if(x1 > uxn_screen.width)
31+		return; 
32+	else if(x1 >  uxn_screen.width - 8){
33+		right =  uxn_screen.width;
34+	}
35+	
36 	for(y = top; y < bottom; y++) {
37 		int yi = y-top;
38 		int offset = fy < 0 ? 7 - yi : yi;
39 		int byte = addr[offset+(offset2*fy)];
40-		/* printf("- %d[%d=%d.. %d]\n", y, yi, y-top, offset2); */
41-		for(x = x1 + xmod, row = y * w, xi = 0; x != xmax; x -= fx, xi++) {
42-			Uint8 ch = (byte >> xi) & 1;
43-			if((opaque || ch) && x < w)
44+		row = y * uxn_screen.width;
45+		for(x = left; x < right; x++) {
46+			int xi = x - left + offset3;
47+			int offx =  fx > 0 ? (7-xi) : xi;
48+			Uint8 ch = (byte >> offx) & 1;
49+			if((opaque || ch))
50 				layer[x + row] = blending[ch][color];
51 		}
52 	}