Clean up VectorFloodFiller
This commit is contained in:
parent
e3653cb12b
commit
d82d6b7acf
|
@ -12,9 +12,9 @@ import java.util.Queue
|
||||||
class VectorFloodFiller(image: Bitmap) {
|
class VectorFloodFiller(image: Bitmap) {
|
||||||
val path = MyPath()
|
val path = MyPath()
|
||||||
|
|
||||||
private var width = 0
|
private val width: Int
|
||||||
private var height = 0
|
private val height: Int
|
||||||
private var pixels: IntArray? = null
|
private val pixels: IntArray
|
||||||
|
|
||||||
private lateinit var pixelsChecked: BooleanArray
|
private lateinit var pixelsChecked: BooleanArray
|
||||||
private lateinit var ranges: Queue<FloodFillRange>
|
private lateinit var ranges: Queue<FloodFillRange>
|
||||||
|
@ -29,12 +29,12 @@ class VectorFloodFiller(image: Bitmap) {
|
||||||
width = image.width
|
width = image.width
|
||||||
height = image.height
|
height = image.height
|
||||||
pixels = IntArray(width * height)
|
pixels = IntArray(width * height)
|
||||||
image.getPixels(pixels!!, 0, width, 0, 0, width, height)
|
image.getPixels(pixels, 0, width, 0, 0, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun prepare() {
|
private fun prepare() {
|
||||||
// Called before starting flood-fill
|
// Called before starting flood-fill
|
||||||
pixelsChecked = BooleanArray(pixels!!.size)
|
pixelsChecked = BooleanArray(pixels.size)
|
||||||
ranges = LinkedList()
|
ranges = LinkedList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class VectorFloodFiller(image: Bitmap) {
|
||||||
prepare()
|
prepare()
|
||||||
|
|
||||||
// Get starting color.
|
// Get starting color.
|
||||||
val startPixel = pixels!!.getOrNull(width * y + x) ?: return
|
val startPixel = pixels.getOrNull(width * y + x) ?: return
|
||||||
if (startPixel == fillColor) {
|
if (startPixel == fillColor) {
|
||||||
// No-op.
|
// No-op.
|
||||||
return
|
return
|
||||||
|
@ -137,9 +137,9 @@ class VectorFloodFiller(image: Bitmap) {
|
||||||
|
|
||||||
// Sees if a pixel is within the color tolerance range.
|
// Sees if a pixel is within the color tolerance range.
|
||||||
private fun isPixelColorWithinTolerance(px: Int): Boolean {
|
private fun isPixelColorWithinTolerance(px: Int): Boolean {
|
||||||
val red = pixels!![px] ushr 16 and 0xff
|
val red = pixels[px] ushr 16 and 0xff
|
||||||
val green = pixels!![px] ushr 8 and 0xff
|
val green = pixels[px] ushr 8 and 0xff
|
||||||
val blue = pixels!![px] and 0xff
|
val blue = pixels[px] and 0xff
|
||||||
return red >= startColorRed - tolerance && red <= startColorRed + tolerance && green >= startColorGreen - tolerance && green <= startColorGreen + tolerance && blue >= startColorBlue - tolerance && blue <= startColorBlue + tolerance
|
return red >= startColorRed - tolerance && red <= startColorRed + tolerance && green >= startColorGreen - tolerance && green <= startColorGreen + tolerance && blue >= startColorBlue - tolerance && blue <= startColorBlue + tolerance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue