code wiki / (root) / nx_transition.nx

nx_transition.nx source

↩ module page · 65 lines · 2360 B

1// nx_transition.nx -- frame transitions for the editor (R4: stitch+transitions). 2// Crossfade / dissolve / fade between two nx_image frames, reusing the eased 3// blend kernel nx_gradient_blend_q14 (LINEAR/SMOOTHSTEP/EASE_IN_OUT/SHARP) so 4// transitions are SMOOTH, not just linear -- the "s-class" quality the editor 5// wants. progress in [0, NX_GB_Q]: 0 = pure A, NX_GB_Q = pure B. 6// 7// This is the per-frame transition PRIMITIVE. The timeline assembler (walk a 8// clip list, emit cut frames + a transition window between clips) is the next 9// rung and composes this. Pure i64 over nx_image. 10// 11// genealogy_id: cross_dissolve_compositing + perlin_smoothstep_easing 12// lineage_id: per_pixel_eased_blend + fade 13// license_tier: ORIGINAL 14import "nx_syscalls.nx" 15import "nx_image.nx" 16import "nx_gradient_blend.nx" 17 18// Crossfade frame A -> B at progress (0..NX_GB_Q) with an easing curve. 19// out must be pre-allocated at A/B's size; channels read via bounds-checked get. 20func nx_xfade_frame(a: *Image, b: *Image, progress_q14: i64, curve: i64, out: *Image) -> i64 { 21 let w: i64 = out.width 22 let h: i64 = out.height 23 let ch: i64 = out.channels 24 var y: i64 = 0 25 while y < h { 26 var x: i64 = 0 27 while x < w { 28 var c: i64 = 0 29 while c < ch { 30 let av: i64 = nx_image_get(a, x, y, c) 31 let bv: i64 = nx_image_get(b, x, y, c) 32 let m: i64 = nx_gradient_blend_q14(av, bv, progress_q14, curve) 33 nx_image_set(out, x, y, c, m) 34 c = c + 1 35 } 36 x = x + 1 37 } 38 y = y + 1 39 } 40 return 0 41} 42 43// Fade between black and A. progress 0 = black, NX_GB_Q = full A (fade-IN). 44// Fade-OUT = call with (NX_GB_Q - progress). 45func nx_fade_frame(a: *Image, progress_q14: i64, curve: i64, out: *Image) -> i64 { 46 let w: i64 = out.width 47 let h: i64 = out.height 48 let ch: i64 = out.channels 49 var y: i64 = 0 50 while y < h { 51 var x: i64 = 0 52 while x < w { 53 var c: i64 = 0 54 while c < ch { 55 let av: i64 = nx_image_get(a, x, y, c) 56 let m: i64 = nx_gradient_blend_q14(0, av, progress_q14, curve) 57 nx_image_set(out, x, y, c, m) 58 c = c + 1 59 } 60 x = x + 1 61 } 62 y = y + 1 63 } 64 return 0 65}