Limit picture upscale factor

Change-Id: I11ea154db505d352ba19d0dbba57c915e3c1d458
This commit is contained in:
SpiritCroc 2021-05-22 14:55:35 +02:00
parent 4f46f470d6
commit 27cedd62d1
1 changed files with 12 additions and 2 deletions

View File

@ -316,10 +316,20 @@ class ImageContentRenderer @Inject constructor(private val localFilesHelper: Loc
?: data.url?.takeIf { localFilesHelper.isLocalFile(data.url) && data.allowNonMxcUrls })
private fun processSize(data: Data, mode: Mode): Size {
val maxImageWidth = data.maxWidth
val maxImageHeight = data.maxHeight
var maxImageWidth = data.maxWidth
var maxImageHeight = data.maxHeight
val width = data.width ?: maxImageWidth
val height = data.height ?: maxImageHeight
// Avoid excessive upscaling
val maxUpscale = dimensionConverter.dpToPx(4)
if (width in 1 until maxImageWidth) {
maxImageWidth = min(maxImageWidth, width*maxUpscale)
}
if (height in 1 until maxImageHeight) {
maxImageHeight = min(maxImageHeight, height*maxUpscale)
}
var finalWidth = -1
var finalHeight = -1