nx_timeline_demo.nx source
↩ module page · 93 lines · 3907 B
1// nx_timeline_demo.nx -- VISIBLE proof of R4b: assemble two REAL gallery stills
2// into a 6-frame timeline (clipA held, 2-frame crossfade, clipB held) using
3// nx_timeline_plan + nx_xfade_frame, emitting tl_0..tl_5.bmp. Flip through them
4// to SEE the stitched cut-with-dissolve. Sovereign throughout.
5// license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_image.nx"
8import "nx_png_decoder.nx"
9import "nx_gradient_blend.nx"
10import "nx_transition.nx"
11import "nx_timeline.nx"
12import "nx_bmp.nx"
13
14func gp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
15func gn(v: i64) -> i64 {
16 let bb: *u8 = sys_mmap(28)
17 var m: i64 = v
18 if m < 0 { sys_write(1, "-\x00" as *u8, 1); m = 0 - m }
19 let t: *u8 = sys_mmap(28)
20 var k: i64 = 0
21 if m == 0 { t[0] = 48 as u8; k = 1 }
22 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
23 var i: i64 = 0
24 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
25 sys_write(1, bb, k)
26 return 0
27}
28func png2img(path: *u8) -> *Image {
29 let szp: *i64 = sys_mmap(16) as *i64
30 let buf: *u8 = sys_read_file(path, szp)
31 if (buf as i64) == 0 { return 0 as *Image }
32 let r: *NxPngResult = nx_png_decode(buf, szp[0])
33 if (r as i64) == 0 { return 0 as *Image }
34 if r.error_code != NX_PNG_OK { return 0 as *Image }
35 let raw: *u8 = sys_mmap(40)
36 let img: *Image = raw as *Image
37 img.pixels = r.pixels; img.width = r.header.width; img.height = r.header.height
38 img.channels = r.n_channels; img.stride = r.header.width * r.n_channels
39 return img
40}
41// write "knowledge/staging/media/tl_<i>.bmp" into buf
42func tlpath(buf: *u8, i: i64) -> i64 {
43 let pre: *u8 = "knowledge/staging/media/tl_\x00" as *u8
44 var p: i64 = 0
45 while pre[p] != (0 as u8) { buf[p] = pre[p]; p = p + 1 }
46 buf[p] = (48 + i) as u8; p = p + 1
47 let suf: *u8 = ".bmp\x00" as *u8
48 var s: i64 = 0
49 while suf[s] != (0 as u8) { buf[p + s] = suf[s]; s = s + 1 }
50 buf[p + s] = 0 as u8
51 return 0
52}
53
54func main() -> i64 {
55 let a: *Image = png2img("knowledge/staging/media/gallery/20260612_000008_c21f8b7c_3860894667_laptop.png\x00" as *u8)
56 let b: *Image = png2img("knowledge/staging/media/gallery/20260612_000130_287bd5eb_2221482208_laptop.png\x00" as *u8)
57 if (a as i64) == 0 { gp("tl_demo: A decode failed\n\x00" as *u8); return 1 }
58 if (b as i64) == 0 { gp("tl_demo: B decode failed\n\x00" as *u8); return 2 }
59
60 let lens: *i64 = sys_mmap(64) as *i64
61 let wins: *i64 = sys_mmap(64) as *i64
62 let recs: *i64 = sys_mmap(64 * 6 * 8) as *i64
63 lens[0] = 4; lens[1] = 4; wins[0] = 2
64 let nf: i64 = nx_timeline_plan(lens, 2, wins, NX_GB_Q, recs, 64)
65 gp("tl_demo timeline frames=\x00" as *u8); gn(nf); gp("\n\x00" as *u8)
66
67 let out: *Image = nx_image_alloc(a.width, a.height, 3)
68 let pathbuf: *u8 = sys_mmap(256)
69 var i: i64 = 0
70 while i < nf {
71 let mode: i64 = recs[i * 6 + 0]
72 let sa: i64 = recs[i * 6 + 1]
73 let sb: i64 = recs[i * 6 + 3]
74 let prog: i64 = recs[i * 6 + 5]
75 var imgA: *Image = a
76 if sa == 1 { imgA = b }
77 if mode == 0 {
78 nx_xfade_frame(imgA, imgA, 0, NX_GB_CURVE_LINEAR, out)
79 gp(" tl_\x00" as *u8); gn(i); gp(" straight clip\x00" as *u8); gn(sa); gp("\n\x00" as *u8)
80 }
81 if mode == 1 {
82 var imgB: *Image = a
83 if sb == 1 { imgB = b }
84 nx_xfade_frame(imgA, imgB, prog, NX_GB_CURVE_SMOOTHSTEP, out)
85 gp(" tl_\x00" as *u8); gn(i); gp(" XFADE clip\x00" as *u8); gn(sa); gp("->clip\x00" as *u8); gn(sb); gp(" prog=\x00" as *u8); gn(prog); gp("\n\x00" as *u8)
86 }
87 tlpath(pathbuf, i)
88 bmp_write(out, pathbuf)
89 i = i + 1
90 }
91 gp("tl_demo done -> knowledge/staging/media/tl_0..\x00" as *u8); gn(nf - 1); gp(".bmp (flip through to see the stitch)\n\x00" as *u8)
92 return 0
93}