@@ -90,21 +90,28 @@ function interpolateBilinear(
90
90
const px0 = Math . floor ( column ) ;
91
91
const py0 = Math . floor ( row ) ;
92
92
93
- if ( px0 === column && py0 === row ) {
94
- return interpolateBorder ( px0 , py0 , channel , image ) ;
95
- }
96
-
97
93
const px1 = px0 + 1 ;
98
94
const py1 = py0 + 1 ;
99
95
100
- const vx0y0 = interpolateBorder ( px0 , py0 , channel , image ) ;
101
- const vx1y0 = interpolateBorder ( px1 , py0 , channel , image ) ;
102
- const vx0y1 = interpolateBorder ( px0 , py1 , channel , image ) ;
103
- const vx1y1 = interpolateBorder ( px1 , py1 , channel , image ) ;
104
-
105
- const r1 = ( px1 - column ) * vx0y0 + ( column - px0 ) * vx1y0 ;
106
- const r2 = ( px1 - column ) * vx0y1 + ( column - px0 ) * vx1y1 ;
107
- return round ( ( py1 - row ) * r1 + ( row - py0 ) * r2 ) ;
96
+ if ( px1 < image . width && py1 < image . height && px0 >= 0 && py0 >= 0 ) {
97
+ const vx0y0 = image . getValue ( px0 , py0 , channel ) ;
98
+ const vx1y0 = image . getValue ( px1 , py0 , channel ) ;
99
+ const vx0y1 = image . getValue ( px0 , py1 , channel ) ;
100
+ const vx1y1 = image . getValue ( px1 , py1 , channel ) ;
101
+
102
+ const r1 = ( px1 - column ) * vx0y0 + ( column - px0 ) * vx1y0 ;
103
+ const r2 = ( px1 - column ) * vx0y1 + ( column - px0 ) * vx1y1 ;
104
+ return round ( ( py1 - row ) * r1 + ( row - py0 ) * r2 ) ;
105
+ } else {
106
+ const vx0y0 = interpolateBorder ( px0 , py0 , channel , image ) ;
107
+ const vx1y0 = interpolateBorder ( px1 , py0 , channel , image ) ;
108
+ const vx0y1 = interpolateBorder ( px0 , py1 , channel , image ) ;
109
+ const vx1y1 = interpolateBorder ( px1 , py1 , channel , image ) ;
110
+
111
+ const r1 = ( px1 - column ) * vx0y0 + ( column - px0 ) * vx1y0 ;
112
+ const r2 = ( px1 - column ) * vx0y1 + ( column - px0 ) * vx1y1 ;
113
+ return round ( ( py1 - row ) * r1 + ( row - py0 ) * r2 ) ;
114
+ }
108
115
}
109
116
110
117
/**
0 commit comments