imfile: some state flags where not properly preserved for readmode != 0