code wiki / _hdl_build / nx_blitproof.nx
nx_blitproof.nx source
↩ module page · 30 lines · 1237 B
1// nx_blitproof.nx -- prove br_blit_rgb: decode the fox JPEG, composite it (scaled) onto a white RGBA
2// framebuffer, write the framebuffer to PNG. Proves the image-into-page paint primitive in isolation.
3import "nx_syscalls.nx"
4import "nx_browser_render.nx"
5import "nx_img_to_rgb.nx"
6import "nx_png_write.nx"
7
8func main() -> i64 {
9 let W: i64 = 500
10 let H: i64 = 350
11 let px: *u8 = sys_mmap(W * H * 4)
12 var i: i64 = 0
13 while i < W * H * 4 { px[i] = 255 as u8; i = i + 1 } // white background
14 let fb: *Framebuffer = sys_mmap(NX_FRAMEBUFFER_BYTES) as *Framebuffer
15 nx_framebuffer_init(fb, px, W, H)
16 let wh: *i64 = sys_mmap(16) as *i64
17 let rgb: *u8 = nx_img_to_rgb("_offc/fetched.png\x00" as *u8, wh) // the -B-fetched Safari screenshot
18 if (rgb as i64) == 0 { return 1 }
19 br_blit_rgb(fb, 20, 25, 460, 300, rgb, wh[0], wh[1]) // fetched image scaled into a box at (20,25)
20 let rgbout: *u8 = sys_mmap(W * H * 3)
21 var j: i64 = 0
22 while j < W * H {
23 rgbout[j * 3 + 0] = px[j * 4 + 0]
24 rgbout[j * 3 + 1] = px[j * 4 + 1]
25 rgbout[j * 3 + 2] = px[j * 4 + 2]
26 j = j + 1
27 }
28 nx_png_write_rgb("_offc/blitproof_fetched.png\x00" as *u8, rgbout, W, H)
29 return 0
30}