Skip to content

Commit

Permalink
Upgraded to 2.0.7, upgraded coil
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Nov 10, 2024
1 parent 153090a commit a1b2201
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 54 deletions.
7 changes: 4 additions & 3 deletions app/src/main/java/com/awxkee/avif/coil/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.net.toUri
import coil.imageLoader
import coil.load
import coil.util.DebugLogger
import coil3.imageLoader
import coil3.load
import coil3.request.bitmapConfig
import coil3.util.DebugLogger
import com.awxkee.avif.coil.databinding.ActivityMainBinding
import com.github.awxkee.avifcoil.decoder.animation.AnimatedAvifDecoder

Expand Down
4 changes: 2 additions & 2 deletions avifcoillibrary/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
api("io.coil-kt:coil:2.7.0")
api("com.github.awxkee:avif-coder:2.0.6")
api("io.coil-kt.coil3:coil:3.0.2")
api("com.github.awxkee:avif-coder:2.0.7")
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ package com.github.awxkee.avifcoil.decoder
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.os.Build
import coil.ImageLoader
import coil.decode.DecodeResult
import coil.decode.Decoder
import coil.fetch.SourceResult
import coil.request.Options
import coil.size.Scale
import coil.size.pxOrElse
import coil3.ImageLoader
import coil3.asImage
import coil3.decode.DecodeResult
import coil3.decode.Decoder
import coil3.fetch.SourceFetchResult
import coil3.request.Options
import coil3.request.allowHardware
import coil3.request.allowRgb565
import coil3.request.bitmapConfig
import coil3.size.Scale
import coil3.size.ScaleDrawable
import coil3.size.Size
import coil3.size.pxOrElse
import com.radzivon.bartoshyk.avif.coder.HeifCoder
import com.radzivon.bartoshyk.avif.coder.PreferredColorConfig
import com.radzivon.bartoshyk.avif.coder.ScaleMode
import kotlinx.coroutines.runInterruptible
import okio.ByteString.Companion.encodeUtf8

class HeifDecoder(
private val source: SourceResult,
private val source: SourceFetchResult,
private val options: Options,
private val imageLoader: ImageLoader,
private val exceptionLogger: ((Exception) -> Unit)? = null,
Expand All @@ -58,31 +64,39 @@ class HeifDecoder(
// ColorSpace is preferred to be ignored due to lib is trying to handle all color profile by itself
val sourceData = source.source.source().readByteArray()

var mPreferredColorConfig: PreferredColorConfig = when (options.config) {
var mPreferredColorConfig: PreferredColorConfig = when (options.bitmapConfig) {
Bitmap.Config.ALPHA_8 -> PreferredColorConfig.RGBA_8888
Bitmap.Config.RGB_565 -> if (options.allowRgb565) PreferredColorConfig.RGB_565 else PreferredColorConfig.DEFAULT
Bitmap.Config.ARGB_8888 -> PreferredColorConfig.RGBA_8888
else -> PreferredColorConfig.DEFAULT
else -> {
if (options.allowHardware) {
PreferredColorConfig.DEFAULT
} else {
PreferredColorConfig.RGBA_8888
}
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && options.config == Bitmap.Config.RGBA_F16) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && options.bitmapConfig == Bitmap.Config.RGBA_F16) {
mPreferredColorConfig = PreferredColorConfig.RGBA_F16
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && options.config == Bitmap.Config.HARDWARE) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && options.bitmapConfig == Bitmap.Config.HARDWARE) {
mPreferredColorConfig = PreferredColorConfig.HARDWARE
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && options.config == Bitmap.Config.RGBA_1010102) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && options.bitmapConfig == Bitmap.Config.RGBA_1010102) {
mPreferredColorConfig = PreferredColorConfig.RGBA_1010102
}

if (options.size == coil.size.Size.ORIGINAL) {
if (options.size == Size.ORIGINAL) {
val originalImage =
coder.decode(
sourceData,
preferredColorConfig = mPreferredColorConfig
)
return@runInterruptible DecodeResult(
BitmapDrawable(
options.context.resources,
originalImage
), false
ScaleDrawable(
BitmapDrawable(
options.context.resources,
originalImage
), options.scale
).asImage(), false
)
}

Expand All @@ -102,10 +116,12 @@ class HeifDecoder(
scaleMode,
)
return@runInterruptible DecodeResult(
BitmapDrawable(
options.context.resources,
originalImage
), true
ScaleDrawable(
BitmapDrawable(
options.context.resources,
originalImage
), options.scale
).asImage(), true
)
} catch (e: Exception) {
exceptionLogger?.invoke(e)
Expand All @@ -115,7 +131,7 @@ class HeifDecoder(

class Factory : Decoder.Factory {
override fun create(
result: SourceResult,
result: SourceFetchResult,
options: Options,
imageLoader: ImageLoader
): Decoder? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,27 @@ import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Build
import coil.ImageLoader
import coil.decode.DecodeResult
import coil.decode.Decoder
import coil.fetch.SourceResult
import coil.request.Options
import coil.size.Scale
import coil.size.Size
import coil.size.pxOrElse
import coil3.ImageLoader
import coil3.asImage
import coil3.decode.DecodeResult
import coil3.decode.Decoder
import coil3.fetch.SourceFetchResult
import coil3.request.Options
import coil3.request.allowHardware
import coil3.request.allowRgb565
import coil3.request.bitmapConfig
import coil3.size.Scale
import coil3.size.ScaleDrawable
import coil3.size.Size
import coil3.size.pxOrElse
import com.radzivon.bartoshyk.avif.coder.AvifAnimatedDecoder
import com.radzivon.bartoshyk.avif.coder.PreferredColorConfig
import com.radzivon.bartoshyk.avif.coder.ScaleMode
import kotlinx.coroutines.runInterruptible
import okio.ByteString.Companion.encodeUtf8

public class AnimatedAvifDecoder(
private val source: SourceResult,
private val source: SourceFetchResult,
private val options: Options,
private val preheatFrames: Int,
private val exceptionLogger: ((Exception) -> Unit)? = null,
Expand All @@ -58,27 +63,35 @@ public class AnimatedAvifDecoder(
// ColorSpace is preferred to be ignored due to lib is trying to handle all color profile by itself
val sourceData = source.source.source().readByteArray()

var mPreferredColorConfig: PreferredColorConfig = when (options.config) {
var mPreferredColorConfig: PreferredColorConfig = when (options.bitmapConfig) {
Bitmap.Config.ALPHA_8 -> PreferredColorConfig.RGBA_8888
Bitmap.Config.RGB_565 -> if (options.allowRgb565) PreferredColorConfig.RGB_565 else PreferredColorConfig.DEFAULT
Bitmap.Config.ARGB_8888 -> PreferredColorConfig.RGBA_8888
else -> PreferredColorConfig.DEFAULT
else -> {
if (options.allowHardware) {
PreferredColorConfig.DEFAULT
} else {
PreferredColorConfig.RGBA_8888
}
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && options.config == Bitmap.Config.RGBA_F16) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && options.bitmapConfig == Bitmap.Config.RGBA_F16) {
mPreferredColorConfig = PreferredColorConfig.RGBA_F16
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && options.config == Bitmap.Config.HARDWARE) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && options.bitmapConfig == Bitmap.Config.HARDWARE) {
mPreferredColorConfig = PreferredColorConfig.HARDWARE
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && options.config == Bitmap.Config.RGBA_1010102) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && options.bitmapConfig == Bitmap.Config.RGBA_1010102) {
mPreferredColorConfig = PreferredColorConfig.RGBA_1010102
}

if (options.size == Size.ORIGINAL) {
val originalImage = AvifAnimatedDecoder(sourceData)
return@runInterruptible DecodeResult(
drawable = originalImage.drawable(
colorConfig = mPreferredColorConfig,
scaleMode = ScaleMode.FIT,
),
ScaleDrawable(
originalImage.drawable(
colorConfig = mPreferredColorConfig,
scaleMode = ScaleMode.FIT,
), options.scale
).asImage(),
isSampled = false
)
}
Expand All @@ -93,12 +106,14 @@ public class AnimatedAvifDecoder(
val originalImage = AvifAnimatedDecoder(sourceData)

DecodeResult(
drawable = originalImage.drawable(
dstWidth = dstWidth,
dstHeight = dstHeight,
colorConfig = mPreferredColorConfig,
scaleMode = scaleMode
),
ScaleDrawable(
originalImage.drawable(
dstWidth = dstWidth,
dstHeight = dstHeight,
colorConfig = mPreferredColorConfig,
scaleMode = scaleMode
), options.scale
).asImage(),
isSampled = true
)
} catch (e: Exception) {
Expand Down Expand Up @@ -152,7 +167,7 @@ public class AnimatedAvifDecoder(
) : Decoder.Factory {

override fun create(
result: SourceResult,
result: SourceFetchResult,
options: Options,
imageLoader: ImageLoader,
): Decoder? {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.7.1" apply false
id("com.android.application") version "8.7.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}

0 comments on commit a1b2201

Please sign in to comment.