             
             for j in 0..<height {
                 
-                let min_y = max(0, j - _r) - j
-                let max_y = min(height - 1, j + _r) - j
+                let min_y = max(0, j - _r1) - j
+                let max_y = min(height - 1, j + _r1) - j
                 
                 for i in 0..<width {
                     
-                    let min_x = max(0, i - _r) - i
-                    let max_x = min(width - 1, i + _r) - i
+                    let min_x = max(0, i - _r0) - i
+                    let max_x = min(width - 1, i + _r0) - i
                     
                     var kernel = texture + min_x + min_y * width
                     

                        for x in min_x...max_x {
                            
                            let _k = _kernel.pointee
                            let w = Pixel.Scalar.exp(_c0 * Pixel.Scalar(x * x + y * y) + _c1 * dot(_p, _k))
                            
                            s += w * _k
                            t += w

@inlinable
@inline(__always)
public func BilateralFilter<Pixel>(_ texture: Texture<Pixel>, _ spatial: Double, _ range: Double) -> Texture<Pixel> {
    return BilateralFilter(texture, Size(width: spatial, height: spatial), range)
}

@inlinable
@inline(__always)
public func BilateralFilter<Pixel>(_ image: Image<Pixel>, _ spatial: Size, _ range: Double) -> Image<Pixel> {
    return Image(texture: BilateralFilter(Texture(image: image), spatial, range), resolution: image.resolution, colorSpace: image.colorSpace)
}

@inlinable
@inline(__always)
public func BilateralFilter<Pixel>(_ texture: Texture<Pixel>, _ spatial: Size, _ range: Double) -> Texture<Pixel> {
    
    precondition(spatial.width > 0 || spatial.height > 0, "spatial is less than or equal to zero.")
    precondition(range > 0, "range is less than or equal to zero.")
    
    @inline(__always)
