Do color filling on background thread

This commit is contained in:
Naveen
2022-10-10 23:12:21 +05:30
parent 2c4dccdda9
commit 294609c643
4 changed files with 7 additions and 8 deletions

View File

@ -3,7 +3,6 @@ package com.simplemobiletools.draw.pro.extensions
import android.graphics.Bitmap import android.graphics.Bitmap
import com.simplemobiletools.draw.pro.helpers.QueueLinearFloodFiller import com.simplemobiletools.draw.pro.helpers.QueueLinearFloodFiller
fun Bitmap.floodFill(color: Int, x: Int, y: Int, tolerance: Int = 10): Bitmap { fun Bitmap.floodFill(color: Int, x: Int, y: Int, tolerance: Int = 10): Bitmap {
val floodFiller = QueueLinearFloodFiller(this).apply { val floodFiller = QueueLinearFloodFiller(this).apply {
fillColor = color fillColor = color

View File

@ -4,11 +4,9 @@ import android.graphics.Bitmap
import android.graphics.Color import android.graphics.Color
import java.util.* import java.util.*
// Original algorithm by J. Dunlap http:// www.codeproject.com/KB/GDI-plus/queuelinearflood-fill.aspx // Original algorithm by J. Dunlap http:// www.codeproject.com/KB/GDI-plus/queuelinearflood-fill.aspx
// Java port by Owen Kaluza // Java port by Owen Kaluza
// Android port by Darrin Smith (Standard Android) // Android port by Darrin Smith (Standard Android)
class QueueLinearFloodFiller(img: Bitmap) { class QueueLinearFloodFiller(img: Bitmap) {
var image: Bitmap? = null var image: Bitmap? = null

View File

@ -3,7 +3,6 @@ package com.simplemobiletools.draw.pro.models
import android.graphics.Bitmap import android.graphics.Bitmap
import java.io.Serializable import java.io.Serializable
sealed class CanvasOp : Serializable { sealed class CanvasOp : Serializable {
class PathOp( class PathOp(
val path: MyPath, val path: MyPath,

View File

@ -393,9 +393,12 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
if (contains(touchedX, touchedY)) { if (contains(touchedX, touchedY)) {
val bitmap = getBitmap() val bitmap = getBitmap()
val color = mPaintOptions.color val color = mPaintOptions.color
val img = bitmap.floodFill(color = color, x = touchedX, y = touchedY)
addOperation(CanvasOp.BitmapOp(img)) ensureBackgroundThread {
invalidate() val img = bitmap.floodFill(color = color, x = touchedX, y = touchedY)
addOperation(CanvasOp.BitmapOp(img))
post { invalidate() }
}
} }
} }
@ -408,7 +411,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
mPath.lineTo(mCurX + 1, mCurY + 2) mPath.lineTo(mCurX + 1, mCurY + 2)
mPath.lineTo(mCurX + 1, mCurY) mPath.lineTo(mCurX + 1, mCurY)
} }
mOperations.add(CanvasOp.PathOp(mPath, mPaintOptions)) addOperation(CanvasOp.PathOp(mPath, mPaintOptions))
} }
private fun addOperation(operation: CanvasOp) { private fun addOperation(operation: CanvasOp) {