Calculation fix

We should set min and max to source size. 
Otherwise it will not work properly if the target window size smaller than source.