Porting from Rust. Almost there.
Some NaN's are sneaking in somewhere in the gamma/quantization process...