@@ -12,9 +12,9 @@ import java.util.Queue
1212class VectorFloodFiller (image : Bitmap ) {
1313 val path = MyPath ()
1414
15- private var width = 0
16- private var height = 0
17- private var pixels: IntArray? = null
15+ private val width: Int
16+ private val height: Int
17+ private val pixels: IntArray
1818
1919 private lateinit var pixelsChecked: BooleanArray
2020 private lateinit var ranges: Queue <FloodFillRange >
@@ -29,12 +29,12 @@ class VectorFloodFiller(image: Bitmap) {
2929 width = image.width
3030 height = image.height
3131 pixels = IntArray (width * height)
32- image.getPixels(pixels!! , 0 , width, 0 , 0 , width, height)
32+ image.getPixels(pixels, 0 , width, 0 , 0 , width, height)
3333 }
3434
3535 private fun prepare () {
3636 // Called before starting flood-fill
37- pixelsChecked = BooleanArray (pixels!! .size)
37+ pixelsChecked = BooleanArray (pixels.size)
3838 ranges = LinkedList ()
3939 }
4040
@@ -45,7 +45,7 @@ class VectorFloodFiller(image: Bitmap) {
4545 prepare()
4646
4747 // Get starting color.
48- val startPixel = pixels!! .getOrNull(width * y + x) ? : return
48+ val startPixel = pixels.getOrNull(width * y + x) ? : return
4949 if (startPixel == fillColor) {
5050 // No-op.
5151 return
@@ -137,9 +137,9 @@ class VectorFloodFiller(image: Bitmap) {
137137
138138 // Sees if a pixel is within the color tolerance range.
139139 private fun isPixelColorWithinTolerance (px : Int ): Boolean {
140- val red = pixels!! [px] ushr 16 and 0xff
141- val green = pixels!! [px] ushr 8 and 0xff
142- val blue = pixels!! [px] and 0xff
140+ val red = pixels[px] ushr 16 and 0xff
141+ val green = pixels[px] ushr 8 and 0xff
142+ val blue = pixels[px] and 0xff
143143 return red >= startColorRed - tolerance && red <= startColorRed + tolerance && green >= startColorGreen - tolerance && green <= startColorGreen + tolerance && blue >= startColorBlue - tolerance && blue <= startColorBlue + tolerance
144144 }
145145
0 commit comments