nx_toner_meter.nx source
↩ module page · 32 lines · 1663 B
1const K_MAGIC_1000000: i64 = 1000000
2const K_MAGIC_50000: i64 = 50000
3// nx_toner_meter.nx -- REAL toner measurement that ignores the printer's lying gauge. Toner consumed by a
4// page is proportional to its INK COVERAGE (fraction of full-black). Because our sovereign stack owns the
5// page bitmap, we measure EXACT coverage per page -- more accurate than the printer (which counts pages and
6// assumes a flat 5%) and works for ANY cartridge (genuine or aftermarket) because it's physics, not a chip.
7//
8// Coverage is returned in PPM (parts per million of full-black): 0 = blank page, 1,000,000 = solid black,
9// 50,000 = the ISO/IEC 19752 "standard page" (5% coverage). For sgray_8: 0x00=black(full toner),
10// 0xFF=white(none); darkness = 255 - pixel.
11//
12// NEVER-BRICK (#26): pure integer arithmetic, no syscalls. Sovereign (no imports). license_tier: ORIGINAL
13// genealogy_id: project-printer-management-ipp-sclass-2026-06-20
14
15// coverage of an 8-bit grayscale bitmap (npix pixels, 1 byte each) in PPM of full-black.
16func nx_toner_coverage_ppm(bm: *u8, npix: i64) -> i64 {
17 if npix <= 0 { return 0 }
18 var sum: i64 = 0
19 var i: i64 = 0
20 while i < npix {
21 sum = sum + (255 - (bm[i] as i64))
22 i = i + 1
23 }
24 // fraction = sum / (255*npix); in PPM = sum*1_000_000/(255*npix). (no overflow: < 2.2e15 for a letter page)
25 return (sum * K_MAGIC_1000000) / (255 * npix)
26}
27
28// the same coverage expressed in "standard ISO pages" x1000 (milli-std-pages), for human display:
29// 50,000 ppm = 1.000 std page = 1000 milli-std-pages.
30func nx_toner_std_pages_milli(coverage_ppm: i64) -> i64 {
31 return coverage_ppm * 1000 / K_MAGIC_50000
32}