code wiki / _hdl_build / nx_aa_raster_test.nx
nx_aa_raster_test.nx source
↩ module page · 44 lines · 2117 B
1// nx_aa_raster_test.nx -- R1 proof for the sovereign AA rasterizer. Renders an 'O' (outer+inner 12-gon =
2// a ring, holes-via-even-odd) and a filled triangle into a coverage buffer, alpha-blits them BLACK onto a
3// white RGB image, writes a PNG. Smooth curved + diagonal edges == the AA core works (the path to real fonts).
4import "nx_aa_raster.nx"
5import "nx_png_write.nx"
6
7func main() -> i64 {
8 let W: i64 = 128
9 let H: i64 = 64
10 let ss: i64 = 4 // grid is 512 x 256
11
12 let xs: *i64 = sys_mmap(8 * 32) as *i64
13 let ys: *i64 = sys_mmap(8 * 32) as *i64
14 // --- 'O' outer 12-gon, center (110,128) r=100 ---
15 xs[0]=210;ys[0]=128; xs[1]=197;ys[1]=178; xs[2]=160;ys[2]=215; xs[3]=110;ys[3]=228
16 xs[4]=60; ys[4]=215; xs[5]=23; ys[5]=178; xs[6]=10; ys[6]=128; xs[7]=23; ys[7]=78
17 xs[8]=60; ys[8]=41; xs[9]=110;ys[9]=28; xs[10]=160;ys[10]=41; xs[11]=197;ys[11]=78
18 // --- 'O' inner 12-gon, center (110,128) r=58 (the counter / hole) ---
19 xs[12]=168;ys[12]=128; xs[13]=160;ys[13]=157; xs[14]=139;ys[14]=178; xs[15]=110;ys[15]=186
20 xs[16]=81; ys[16]=178; xs[17]=60; ys[17]=157; xs[18]=52; ys[18]=128; xs[19]=60; ys[19]=99
21 xs[20]=81; ys[20]=78; xs[21]=110;ys[21]=70; xs[22]=139;ys[22]=78; xs[23]=160;ys[23]=99
22 // --- filled triangle in the right half ---
23 xs[24]=290;ys[24]=210; xs[25]=490;ys[25]=210; xs[26]=390;ys[26]=40
24
25 let cstart: *i64 = sys_mmap(8 * 3) as *i64
26 let clen: *i64 = sys_mmap(8 * 3) as *i64
27 cstart[0]=0; clen[0]=12
28 cstart[1]=12; clen[1]=12
29 cstart[2]=24; clen[2]=3
30
31 let cov: *u8 = sys_mmap(W * H)
32 aa_render(xs, ys, cstart, clen, 3, cov, W, H, ss)
33
34 // white RGB canvas
35 let rgb: *u8 = sys_mmap(W * H * 3)
36 var i: i64 = 0
37 while i < W * H * 3 { rgb[i] = 255 as u8; i = i + 1 }
38 // alpha-blit the coverage BLACK over the whole canvas (cov is already W x H positioned)
39 aa_blit(rgb, W, H, 0, 0, cov, W, H, 0, 0, 0)
40
41 nx_png_write_rgb("_offc/nx_aa_O.png\x00" as *u8, rgb, W, H)
42 sys_write(1, "aa_raster_test: wrote _offc/nx_aa_O.png\n\x00" as *u8, 40)
43 return 0
44}