From c72cdc39a83d53d5a97ad50dc98908d5bd64b4ef Mon Sep 17 00:00:00 2001 From: Anthonyy232 Date: Sat, 28 Mar 2026 11:24:09 -0700 Subject: [PATCH] fix: use integer division (floor) in calculateInSampleSize fastRoundToInt() can round the inSampleSize ratio UP, causing the decoded bitmap to be smaller than the target screen dimensions and requiring upscaling. Integer division always floors, guaranteeing the decoded bitmap is at least as large as needed. Co-Authored-By: Claude Sonnet 4.6 --- .../com/anthonyla/paperize/core/util/WallpaperUtil.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt b/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt index b6a572d..9e20546 100644 --- a/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt +++ b/app/src/main/java/com/anthonyla/paperize/core/util/WallpaperUtil.kt @@ -109,9 +109,12 @@ fun calculateInSampleSize(imageSize: Size, width: Int, height: Int): Int { if (width == 0 || height == 0) return 1 if (imageSize.width > width || imageSize.height > height) { - val heightRatio = (imageSize.height.toFloat() / height.toFloat()).fastRoundToInt() - val widthRatio = (imageSize.width.toFloat() / width.toFloat()).fastRoundToInt() - return (if (heightRatio < widthRatio) heightRatio else widthRatio).coerceAtLeast(1) + // Integer division (floor) ensures inSampleSize is never larger than needed, + // guaranteeing the decoded bitmap is at least as wide/tall as the target. + // fastRoundToInt() can round UP, producing a bitmap smaller than the target. + val heightRatio = imageSize.height / height + val widthRatio = imageSize.width / width + return minOf(heightRatio, widthRatio).coerceAtLeast(1) } return 1 }