Undo dw/dh calculation

And correctly handle the case when the image offset is zero.