Skip to content

Commit de874a1

Browse files
Don't use hardware bitmaps when generating color palette from an image
1 parent d74d959 commit de874a1

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

shared/src/androidMain/kotlin/com/mr3y/ludi/shared/ui/components/LudiAsyncImage.android.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ package com.mr3y.ludi.shared.ui.components
33
import androidx.compose.ui.graphics.ImageBitmap
44
import androidx.compose.ui.graphics.asImageBitmap
55
import coil3.Bitmap
6+
import coil3.request.ImageRequest
7+
import coil3.request.allowHardware
8+
9+
actual fun ImageRequest.Builder.platformSpecificConfig(allowHardware: Boolean): ImageRequest.Builder = this.allowHardware(allowHardware)
610

711
actual fun Bitmap.asImageBitmap(): ImageBitmap = this.asImageBitmap()

shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/components/LudiAsyncImage.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ fun LudiAsyncImage(
2323
contentScale: ContentScale = ContentScale.Fit,
2424
alignment: Alignment = Alignment.Center,
2525
customMemoryCacheKey: String? = null,
26+
allowBitmapHardware: Boolean = true,
2627
filterQuality: FilterQuality = FilterQuality.Low
2728
) {
2829
val context = LocalPlatformContext.current
2930
coil3.compose.AsyncImage(
3031
model = ImageRequest.Builder(context)
3132
.data(url)
3233
.memoryCacheKey(customMemoryCacheKey)
34+
.platformSpecificConfig(allowBitmapHardware)
3335
.build(),
3436
contentDescription = contentDescription,
3537
transform = { state ->
@@ -47,4 +49,6 @@ fun LudiAsyncImage(
4749
)
4850
}
4951

52+
expect fun ImageRequest.Builder.platformSpecificConfig(allowHardware: Boolean): ImageRequest.Builder
53+
5054
expect fun Bitmap.asImageBitmap(): ImageBitmap

shared/src/commonMain/kotlin/com/mr3y/ludi/shared/ui/screens/discover/GameCards.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ fun TrendingGameCard(
165165
contentDescription = null,
166166
// Set a custom memory cache key to avoid overwriting the displayed image in the cache
167167
customMemoryCacheKey = "$imageUrl.palette",
168+
allowBitmapHardware = false,
168169
contentScale = ContentScale.Crop,
169170
alignment = rememberParallaxAlignment(lazyListState, key = game?.id)
170171
)

shared/src/desktopMain/kotlin/com/mr3y/ludi/shared/ui/components/LudiAsyncImage.desktop.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ package com.mr3y.ludi.shared.ui.components
33
import androidx.compose.ui.graphics.ImageBitmap
44
import androidx.compose.ui.graphics.asComposeImageBitmap
55
import coil3.Bitmap
6+
import coil3.request.ImageRequest
7+
8+
actual fun ImageRequest.Builder.platformSpecificConfig(allowHardware: Boolean): ImageRequest.Builder = this
69

710
actual fun Bitmap.asImageBitmap(): ImageBitmap = this.asComposeImageBitmap()

0 commit comments

Comments
 (0)