This mask handling intertwines and thereby duplicates some logic: Can't it be changed to first work on the simple half height images and then do the height scaling in a separate step (logic like this should be used for the output screen too, right? So, one could think of moving it to some other function for removing code ducplication)?

But that's really minor anyway.