Skip to content

Commit f06b054

Browse files
authored
fix(mobile): decoding at higher resolution than necessary (#21503)
1 parent 0df910c commit f06b054

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

mobile/android/app/src/main/kotlin/app/alextran/immich/images/ThumbnailsImpl.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ class ThumbnailsImpl(context: Context) : ThumbnailApi {
202202
val source = ImageDecoder.createSource(resolver, uri)
203203
signal.throwIfCanceled()
204204
ImageDecoder.decodeBitmap(source) { decoder, info, _ ->
205-
val sampleSize =
206-
getSampleSize(info.size.width, info.size.height, targetWidth, targetHeight)
205+
val sampleSize = max(1, min(info.size.width / targetWidth, info.size.height / targetHeight))
207206
decoder.setTargetSampleSize(sampleSize)
208207
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
209208
decoder.setTargetColorSpace(ColorSpace.get(ColorSpace.Named.SRGB))
@@ -216,15 +215,4 @@ class ThumbnailsImpl(context: Context) : ThumbnailApi {
216215
ref.get()
217216
}
218217
}
219-
220-
private fun getSampleSize(fullWidth: Int, fullHeight: Int, reqWidth: Int, reqHeight: Int): Int {
221-
return 1 shl max(
222-
0, floor(
223-
min(
224-
log2(fullWidth / reqWidth.toDouble()),
225-
log2(fullHeight / reqHeight.toDouble()),
226-
)
227-
).toInt()
228-
)
229-
}
230218
}

0 commit comments

Comments
 (0)