code wiki / (root) / nx_x11_pixmap_kat_test.nx

nx_x11_pixmap_kat_test.nx source

↩ module page · 81 lines · 2876 B

1// nx_x11_pixmap_kat_test.nx -- minimal pixmap paint+capture KAT. 2// 3// CreatePixmap 100x60. 4// CreateGC with foreground = 0x00FF0000 (red in RGB / X-byte-G-byte-R-byte 5// on a typical 24-bit visual). 6// PolyFillRectangle covering entire pixmap. 7// GetImage 100x60. 8// Verify first pixel bytes are red-ish (any non-zero R channel). 9// 10// expect_exit: 0. 11// license_tier: ORIGINAL 12 13import "nx_syscalls.nx" 14import "nx_x11_connect.nx" 15import "nx_x11_window.nx" 16import "nx_x11_paint.nx" 17import "nx_x11_pixmap.nx" 18import "nx_x11_get_image.nx" 19 20func dump_dec(l0: i64, l1: i64, v: i64) -> i64 { 21 let lab: *u8 = sys_mmap(8) 22 lab[0]=l0 as u8; lab[1]=l1 as u8; lab[2]=0x3D 23 sys_write(2, lab, 3) 24 var av: i64 = v 25 if av < 0 { let neg: *u8 = sys_mmap(8); neg[0]=0x2D; sys_write(2, neg, 1); av = 0 - av } 26 let buf: *u8 = sys_mmap(16); var pos: i64 = 0 27 if av == 0 { buf[0]=0x30; pos = 1 } 28 var x: i64 = av 29 while x > 0 { buf[pos] = (0x30 + (x % 10)) as u8; x = x / 10; pos = pos + 1 } 30 let out: *u8 = sys_mmap(16); var oi: i64 = 0 31 while oi < pos { out[oi] = buf[pos - 1 - oi]; oi = oi + 1 } 32 sys_write(2, out, pos) 33 let nl: *u8 = sys_mmap(8); nl[0]=0x0A; sys_write(2, nl, 1) 34 return 0 35} 36 37func main() -> i64 { 38 let rc: i64 = nx_x11_connect_local(0) 39 if rc < 0 { return 1 } 40 let c: *X11Conn = rc as *X11Conn 41 42 // Need a window for the pixmap's screen context. 43 let wid: i64 = nx_x11_create_window(c, 0, 0, 100, 60, 0, 0) 44 if wid < 0 { return 2 } 45 // Don't map -- it's just a screen-context anchor. 46 47 let pix: i64 = nx_x11_create_pixmap(c, wid, 100, 60, c.root_depth) 48 if pix < 0 { return 3 } 49 dump_dec(0x50, 0x49, pix) 50 51 let gc: i64 = nx_x11_create_gc(c, pix, 0x00FF0000) // red 52 if gc < 0 { return 4 } 53 dump_dec(0x47, 0x43, gc) 54 55 nx_x11_fill_rect(c, pix, gc, 0, 0, 100, 60) 56 57 // Flush + check for errors. 58 let f1: i64 = nx_x11_flush_via_get_input_focus(c) 59 dump_dec(0x46, 0x31, f1) 60 61 // GetImage 100x60 (BGRX = 4 bytes/pixel = 24000 bytes). 62 let buf: *u8 = sys_mmap(100 * 60 * 4 + 64) 63 let got: i64 = nx_x11_get_image(c, pix, 0, 0, 100, 60, 64 buf, 100 * 60 * 4 + 64) 65 dump_dec(0x47, 0x54, got) 66 if got < 0 { return 5 } 67 68 // First pixel bytes. For 24bpp ZPixmap on RGB888 visual with 69 // little-endian byte order, the 4 bytes per pixel are: 70 // b, g, r, x (B-channel first in memory) 71 // So R=byte2 should be 0xFF if our paint worked. 72 dump_dec(0x50, 0x30, (buf[0] & 0xff) as i64) // P0= first byte 73 dump_dec(0x50, 0x31, (buf[1] & 0xff) as i64) // P1= 74 dump_dec(0x50, 0x32, (buf[2] & 0xff) as i64) // P2= 75 dump_dec(0x50, 0x33, (buf[3] & 0xff) as i64) // P3= 76 dump_dec(0x50, 0x35, (buf[5] & 0xff) as i64) 77 dump_dec(0x50, 0x36, (buf[6] & 0xff) as i64) 78 79 sys_close(c.fd) 80 return 0 81}