korlibs-archive / korim

Korim: Kotlin cORoutines IMaging, Bitmap and Vector graphics for Multiplatform Kotlin

Home Page:https://korlibs.soywiz.com/korim/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Best way to load image from iOS CMSampleBuffer or ByteArray?

luca992 opened this issue · comments

I've tried going through the docs. But, I'm a bit confused. What would be the best way to load an image from ios's CMSampleBuffer or a CMSampleBuffer dumped into a ByteArray?

Never mind, figured it out. I think it should be something like this:

fun NSData.toIntArray(): IntArray = IntArray(this@toIntArray.length.toInt() / 4 ).apply {
    usePinned {
        memcpy(it.addressOf(0), this@toIntArray.bytes, this@toIntArray.length)
    }
}
suspend fun displayImage(w: Int, h: Int, imageData: NSData){

    val image = NativeImage(w, h, RgbaArray(imageData.toIntArray()))
    image.toNonNativeBmp().showImageAndWait() // display not implemented
}