The haze removal filter in darktable does magic on the resulting image, it solves the blacklevel issues at least for the ov5640. This is quite a complicated algorithm to implement from scratch. It would probably be the neatest to make a small executable that takes in a tiff file, runs the dehazing with sane default arguments and then writes a new tiff file preserving all tags and exif blocks.
Issue now tracked here: https://gitlab.com/postmarketOS/megapixels/-/issues/4