//! End-to-end chain: **codestream → hyper-latent → scale indices**, with no fixture //! input beyond the normative assets. //! //! ```text //! test256.bin → parse_container → SOZ → mANS fac decode → −31 → z //! → decode_hyper_scale(z) → i_s //! ``` //! //! Both links were validated independently (the entropy path from marker syntax, the //! scale net from its ONNX); this runs them as one pipeline off raw bytes and requires //! the result to be byte-exact against the reference `i_s`. //! //! env: WAI_JPEGAI_CHAIN_FIXTURE = e2e_chain_fixture.json //! { codestream:[u8], cdfs_y:[u8;160*63], per_channel, z_shape, i_s_expected } //! WAI_JPEGAI_HYPERSCALE_WEIGHTS = hyperscale_y_weights.json #![cfg(all(feature = "neural_int", feature = "legacy_int"))] use wai::jpegai_bitstream::{find_segment, parse_container, Marker}; use wai::jpegai_mans::MansDecoder; use wai::jpegai_synthesis::{decode_hyper_scale, IntNet}; const Z_OFFSET: i64 = 31; #[test] fn codestream_to_scale_indices() { let fx = match std::env::var("WAI_JPEGAI_CHAIN_FIXTURE") { Ok(p) if std::path::Path::new(&p).exists() => p, _ => { eprintln!("skip: set WAI_JPEGAI_CHAIN_FIXTURE"); return; } }; let wj = match std::env::var("WAI_JPEGAI_HYPERSCALE_WEIGHTS") { Ok(p) if std::path::Path::new(&p).exists() => p, _ => { eprintln!("skip: set WAI_JPEGAI_HYPERSCALE_WEIGHTS"); return; } }; let v: serde_json::Value = serde_json::from_slice(&std::fs::read(&fx).unwrap()).unwrap(); let u8v = |k: &str| v[k].as_array().unwrap().iter().map(|x| x.as_u64().unwrap() as u8).collect::>(); let data = u8v("codestream"); let cdfs = u8v("cdfs_y"); let per_channel = v["per_channel"].as_u64().unwrap() as usize; let zs: Vec = v["z_shape"].as_array().unwrap().iter().map(|x| x.as_u64().unwrap() as usize).collect(); let (c, zh, zw) = (zs[1], zs[2], zs[3]); let i_s_expected: Vec = v["i_s_expected"].as_array().unwrap().iter().map(|x| x.as_i64().unwrap()).collect(); // 1. codestream → SOZ → z (luma plane) let segs = parse_container(&data); let soz = find_segment(&segs, Marker::Soz).expect("SOZ"); let mem = &data[soz.start..soz.start + soz.len]; let mut dec = MansDecoder::new(mem, &[mem.len() as u32]); let mut symbols = vec![0u8; c * per_channel]; dec.decode_factorize(&cdfs, &mut symbols, c, per_channel); let z: Vec = symbols.iter().map(|&s| s as i64 - Z_OFFSET).collect(); assert_eq!(z.len(), c * zh * zw, "z is [{c}, {zh}, {zw}]"); eprintln!("z from codestream: {} vals, {} non-zero", z.len(), z.iter().filter(|&&x| x != 0).count()); // 2. z → hyper-scale net → i_s let net = IntNet::from_json(&serde_json::from_slice(&std::fs::read(&wj).unwrap()).unwrap()).unwrap(); let (i_s, co, ho, wo) = decode_hyper_scale(&z, c, zh, zw, &net); eprintln!("i_s: [{co},{ho},{wo}] = {} vals", i_s.len()); assert_eq!(i_s.len(), i_s_expected.len()); let mism = i_s.iter().zip(&i_s_expected).filter(|(a, b)| a != b).count(); if let Some((i, (a, b))) = i_s.iter().zip(&i_s_expected).enumerate().find(|(_, (a, b))| a != b) { eprintln!("first mismatch @ {i}: got {a} exp {b}"); } eprintln!("i_s from codestream: {}/{} exact", i_s.len() - mism, i_s.len()); assert_eq!(mism, 0, "codestream → z → i_s must be byte-exact"); }