All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.com.seiko.imageloader.component.decoder.ImageIODecoder.kt Maven / Gradle / Ivy

The newest version!
package com.seiko.imageloader.component.decoder

import androidx.compose.ui.graphics.toPainter
import com.seiko.imageloader.option.Options
import com.seiko.imageloader.util.isGif
import kotlinx.coroutines.runInterruptible
import okio.BufferedSource
import javax.imageio.ImageIO

class ImageIODecoder(
    private val source: BufferedSource,
) : Decoder {

    override suspend fun decode(): DecodeResult {
        val image = runInterruptible {
            ImageIO.read(source.inputStream())
        }
        return DecodeResult.OfPainter(
            painter = image.toPainter(),
        )
    }

    class Factory : Decoder.Factory {
        override fun create(source: DecodeSource, options: Options): Decoder? {
            if (isGif(source.source)) return null
            return ImageIODecoder(source.source)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy