mirror of
https://github.com/immich-app/immich.git
synced 2025-12-23 09:15:05 +03:00
fix(mobile): decoding at higher resolution than necessary (#21503)
This commit is contained in:
@@ -202,8 +202,7 @@ class ThumbnailsImpl(context: Context) : ThumbnailApi {
|
|||||||
val source = ImageDecoder.createSource(resolver, uri)
|
val source = ImageDecoder.createSource(resolver, uri)
|
||||||
signal.throwIfCanceled()
|
signal.throwIfCanceled()
|
||||||
ImageDecoder.decodeBitmap(source) { decoder, info, _ ->
|
ImageDecoder.decodeBitmap(source) { decoder, info, _ ->
|
||||||
val sampleSize =
|
val sampleSize = max(1, min(info.size.width / targetWidth, info.size.height / targetHeight))
|
||||||
getSampleSize(info.size.width, info.size.height, targetWidth, targetHeight)
|
|
||||||
decoder.setTargetSampleSize(sampleSize)
|
decoder.setTargetSampleSize(sampleSize)
|
||||||
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
|
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
|
||||||
decoder.setTargetColorSpace(ColorSpace.get(ColorSpace.Named.SRGB))
|
decoder.setTargetColorSpace(ColorSpace.get(ColorSpace.Named.SRGB))
|
||||||
@@ -216,15 +215,4 @@ class ThumbnailsImpl(context: Context) : ThumbnailApi {
|
|||||||
ref.get()
|
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()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user