diff --git a/android/app/src/main/java/tv/orbit/classic/CatchUp.kt b/android/app/src/main/java/tv/orbit/classic/CatchUp.kt index 6ad0a698..1190e731 100644 --- a/android/app/src/main/java/tv/orbit/classic/CatchUp.kt +++ b/android/app/src/main/java/tv/orbit/classic/CatchUp.kt @@ -306,7 +306,7 @@ private fun CatchUpTile(entry: CatchUpEntry, nowMs: Long, on: Boolean, session: Column(modifier.background(if (on) Navy else Panel, corner).border(if (on) 3.dp else 0.dp, if (on) Yellow else Color.Transparent, corner)) { Box(Modifier.fillMaxWidth().height(96.dp).clip(RoundedCornerShape(topStart = 8.dp, topEnd = 8.dp)).background(Deep)) { val seriesId = remember(entry.channel, entry.show.startMs) { (entry.channel as? ScheduledChannel)?.seriesIdAt(entry.show.startMs) } - if (session != null) QueuedArtwork(session, entry.show.media.item.id, seriesId, Modifier.matchParentSize()) + if (session != null) QueuedArtwork(session, entry.show.media.item.id, seriesId, Modifier.matchParentSize(), maxWidthPx = CATCH_UP_CARD_PICTURE_PX) val mark = ChannelBrands.forNumber(entry.channel.number) Box(Modifier.padding(6.dp).background(Navy.copy(alpha = .8f), RoundedCornerShape(4.dp)).padding(horizontal = 5.dp, vertical = 3.dp)) { if (mark != null) Image(cachedPainter(mark.logo), mark.displayName, Modifier.width(56.dp).height(16.dp)) @@ -369,3 +369,6 @@ internal fun DriftWaiting(modifier: Modifier = Modifier) { } } } + +/** A Catch Up card's picture is about 400 pixels wide on the box; decoded no smaller than this (profiling fix B). */ +internal const val CATCH_UP_CARD_PICTURE_PX = 480 diff --git a/android/app/src/main/java/tv/orbit/classic/ProgrammeArtwork.kt b/android/app/src/main/java/tv/orbit/classic/ProgrammeArtwork.kt index 50dd9192..2d022c11 100644 --- a/android/app/src/main/java/tv/orbit/classic/ProgrammeArtwork.kt +++ b/android/app/src/main/java/tv/orbit/classic/ProgrammeArtwork.kt @@ -78,13 +78,34 @@ internal fun ProgrammeArtwork(session: EmbySampleSession, channel: SampleChannel } } +/** + * Decodes a fetched picture no wider than it needs to be (profiling fix B, 8 November 2026): Catch Up's cards drew + * 1280-pixel pictures, about 3.7 MB each, at card size. Halving until the next halving would go below [maxWidthPx] keeps + * it sharp at that size and uses a quarter of the memory or less. + */ +internal fun artworkSampleSize(width: Int, maxWidthPx: Int?): Int { + if (maxWidthPx == null || maxWidthPx <= 0 || width <= 0) return 1 + var sample = 1 + while (width / (sample * 2) >= maxWidthPx) sample *= 2 + return sample +} + +internal fun decodeArtwork(bytes: ByteArray, maxWidthPx: Int?): android.graphics.Bitmap? { + if (maxWidthPx == null) return BitmapFactory.decodeByteArray(bytes, 0, bytes.size) + val bounds = BitmapFactory.Options().apply { inJustDecodeBounds = true } + BitmapFactory.decodeByteArray(bytes, 0, bytes.size, bounds) + return BitmapFactory.decodeByteArray(bytes, 0, bytes.size, BitmapFactory.Options().apply { inSampleSize = artworkSampleSize(bounds.outWidth, maxWidthPx) }) +} + /** A small picture of what's queued next (Up next in the watching bar), undimmed; nothing while it loads or if there isn't one. */ @Composable -internal fun QueuedArtwork(session: EmbySampleSession, itemId: String, seriesId: String?, modifier: Modifier = Modifier) { +internal fun QueuedArtwork(session: EmbySampleSession, itemId: String, seriesId: String?, modifier: Modifier = Modifier, + /** The widest it's shown, in pixels; a smaller copy is decoded for a small card (profiling fix B). Null: as fetched. */ + maxWidthPx: Int? = null) { val context = LocalContext.current val picture by produceState(null, itemId, seriesId) { value = if (itemId.isEmpty()) null else withContext(Dispatchers.IO) { - runCatching { loadArtwork(ArtworkCache(Workspaces.current(context).artworkDir), itemId, seriesId, session::fetchArtwork)?.let { BitmapFactory.decodeByteArray(it, 0, it.size)?.asImageBitmap() } }.getOrNull() + runCatching { loadArtwork(ArtworkCache(Workspaces.current(context).artworkDir), itemId, seriesId, session::fetchArtwork)?.let { decodeArtwork(it, maxWidthPx)?.asImageBitmap() } }.getOrNull() } } picture?.let { Image(it, null, modifier, contentScale = ContentScale.Crop) } diff --git a/android/app/src/test/java/tv/orbit/classic/ArtworkSampleSizeTest.kt b/android/app/src/test/java/tv/orbit/classic/ArtworkSampleSizeTest.kt new file mode 100644 index 00000000..c95f4232 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/ArtworkSampleSizeTest.kt @@ -0,0 +1,14 @@ +package tv.orbit.classic + +import org.junit.Assert.assertEquals +import org.junit.Test + +/** 8 November 2026 (profiling fix B): a card's picture is decoded smaller, never below the size it's shown. */ +class ArtworkSampleSizeTest { + @Test fun halvesOnlyWhileStillWideEnough() { + assertEquals(2, artworkSampleSize(1280, CATCH_UP_CARD_PICTURE_PX)) // 640 px, shown at about 400 + assertEquals(1, artworkSampleSize(900, CATCH_UP_CARD_PICTURE_PX)) // 450 would be too small + assertEquals(4, artworkSampleSize(1920, 480)) + assertEquals(1, artworkSampleSize(1280, null)); assertEquals(1, artworkSampleSize(0, 480)) + } +}