MRG: extending Basile Pinsard's fixes to gifti

Extending Basile's changes with some more tests and some minor refactoring.