From f06b0540871481c2c8b32c13710752cab04cae47 Mon Sep 17 00:00:00 2001 From: Mert <101130780+mertalev@users.noreply.github.com> Date: Tue, 2 Sep 2025 11:03:17 -0400 Subject: [PATCH] fix(mobile): decoding at higher resolution than necessary (#21503) --- .../app/alextran/immich/images/ThumbnailsImpl.kt | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/mobile/android/app/src/main/kotlin/app/alextran/immich/images/ThumbnailsImpl.kt b/mobile/android/app/src/main/kotlin/app/alextran/immich/images/ThumbnailsImpl.kt index 9426ba43dc..1b1716f55c 100644 --- a/mobile/android/app/src/main/kotlin/app/alextran/immich/images/ThumbnailsImpl.kt +++ b/mobile/android/app/src/main/kotlin/app/alextran/immich/images/ThumbnailsImpl.kt @@ -202,8 +202,7 @@ class ThumbnailsImpl(context: Context) : ThumbnailApi { val source = ImageDecoder.createSource(resolver, uri) signal.throwIfCanceled() ImageDecoder.decodeBitmap(source) { decoder, info, _ -> - val sampleSize = - getSampleSize(info.size.width, info.size.height, targetWidth, targetHeight) + val sampleSize = max(1, min(info.size.width / targetWidth, info.size.height / targetHeight)) decoder.setTargetSampleSize(sampleSize) decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE decoder.setTargetColorSpace(ColorSpace.get(ColorSpace.Named.SRGB)) @@ -216,15 +215,4 @@ class ThumbnailsImpl(context: Context) : ThumbnailApi { ref.get() } } - - private fun getSampleSize(fullWidth: Int, fullHeight: Int, reqWidth: Int, reqHeight: Int): Int { - return 1 shl max( - 0, floor( - min( - log2(fullWidth / reqWidth.toDouble()), - log2(fullHeight / reqHeight.toDouble()), - ) - ).toInt() - ) - } }