Add factory for wavefuncs
tweak image IO

Put off casting to void pointers for as long as possible to allow easier
troubleshooting.  Also simplifies code.