Hello, is there an ETA for skiko-android being pub...
# compose-android
h
Hello, is there an ETA for skiko-android being published on mavenCentral?
m
I didn’t even know that there is a plan for such a thing.
h
ios and awt versions are available
and some others
s
I wonder the same. https://repo.maven.apache.org/maven2/org/jetbrains/skiko/ still has no skiko-android and the sample instructs us to build it locally. I need to apply an imageFilter to the Paint object and that seems only be possible using skiko, but not the native SKIA coming with Android. 😕
a
You won't be able to use skiko classes with jetpack compose
s
That's not my intention. I want to calculate the variance of laplacian for an image.
Copy code
fun Image.calcVarianceOfLaplacian(): Double {

    val surface = Surface.makeRasterN32Premul(width, height)

    surface.canvas.drawImageRect(
        image = this,
        dst = Rect(0f, 0f, width.toFloat(), height.toFloat()),
        paint = laplaceEdgeDetectorFilterSkiaPaint
    )

    val newImage = surface.makeImageSnapshot()

    val bitmap = Bitmap.makeFromImage(newImage)

    return bitmap.calcRedVariance()
}
Copy code
/**
 * Laplace edge detection filter
 *
 * Same as OpenCV:
 * Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_BGR2GRAY)
 * Imgproc.Laplacian(grayImage, destination, CvType.CV_64F, 1, 1.0, 0.0, Core.BORDER_ISOLATED)
 */
@Suppress("MagicNumber")
val laplaceEdgeDetectorFilterSkiaPaint: Paint = Paint().apply {

    colorFilter = grayscaleSkiaColorFilter

    imageFilter = ImageFilter.makeMatrixConvolution(
        kernelW = 3,
        kernelH = 3,
        kernel = floatArrayOf(
            0F, 1F, 0F,
            1F, -4F, 1F,
            0F, 1F, 0F
        ),
        gain = 1F,
        bias = 0F,
        offsetX = 1,
        offsetY = 1,
        tileMode = FilterTileMode.CLAMP,
        convolveAlpha = false,
        input = null,
        crop = null
    )
}
The problem is: While there is an
colorFilter
and Android, there is no
imageFilter
I tried applying this programmatically:
Copy code
@Suppress("NestedBlockDepth", "MagicNumber")
fun applyLaplaceFilter(inputBitmap: Bitmap): Bitmap {

    var width = inputBitmap.width
    var height = inputBitmap.height

    /* Create a new Bitmap to store the result */
    var resultBitmap = Bitmap.createBitmap(width, height, inputBitmap.config)

    /* Iterate through each pixel in the inputBitmap */
    for (y in 1 until height - 1) {
        for (x in 1 until width - 1) {
            var sum = 0

            /* Apply Laplace filter to each pixel and its neighbors */
            for (i in -1..1) {
                for (j in -1..1) {
                    var pixel = inputBitmap.getPixel(x + i, y + j)
                    var gray =
                        (Color.red(pixel) * 0.299 + Color.green(pixel) * 0.587 + Color.blue(pixel) * 0.114).toInt()
                    sum += gray * LAPLACE_FILTER.get(i + 1).get(j + 1)
                }
            }

            /* Ensure the value is in the valid range [0, 255] */
            var newValue = max(0.0, min(255.0, sum.toDouble())).toInt()
            resultBitmap.setPixel(x, y, Color.rgb(newValue, newValue, newValue))
        }
    }

    return resultBitmap
}
But as you might expect it's super slow. By a factor of 100.
The background is sharpness evaluation.
a
It might work then
s
Is there a way to apply an imageFilter on Android? Maybe I just don't see it.
a
Seems like no, maybe from the NDK
s
I don't find anything and ChatGPT doesn't know, too. I ask again in the channel.