Yes, that's a better approach. You need to (try to) adapt to the IO unit as received, because it can be renegotiated at any Tversion.
thats basicly what we did too, plus that if dy <= 0, we
split the scanline that fits in the display buffer and
recursively call unloadimage() on the rest instead of
failing.