Thanks, y’all! The simple white balancing algorithm is almost an exact copy of the algorithm used in GIMP:
https://docs.gimp.org/nl/gimp-layer-white-balance.html
The color restoration/color balancing algorithm is my own invention, but typing “unsupervised color photo/film restoration”, “gray world”, and “color constancy” in google scholar will provide some interesting reading material.