/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

package ca.gosyer.jui.ui.util.compose

import android.graphics.BitmapFactory
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import com.seiko.imageloader.Image
import io.ktor.client.statement.HttpResponse
import io.ktor.client.statement.bodyAsChannel
import io.ktor.utils.io.jvm.javaio.toInputStream

actual suspend fun HttpResponse.toImageBitmap(): ImageBitmap {
    return BitmapFactory.decodeStream(bodyAsChannel().toInputStream()).asImageBitmap()
}

actual fun Image.asImageBitmap(): ImageBitmap {
    return asImageBitmap()
}
