fixed decoding TIFF to specific size for conversion

This commit is contained in:
Thibault Deckers 2024-01-27 22:24:21 +01:00
parent ec93b3f21d
commit c778bd6e9e
2 changed files with 6 additions and 2 deletions

View file

@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
- crash when loading some large DNG in viewer - crash when loading some large DNG in viewer
- searching from drawer on mobile - searching from drawer on mobile
- resizing TIFF during conversion
## <a id="v1.10.2"></a>[v1.10.2] - 2023-12-24 ## <a id="v1.10.2"></a>[v1.10.2] - 2023-12-24

View file

@ -48,7 +48,8 @@ internal class TiffFetcher(val model: TiffImage, val width: Int, val height: Int
val page = model.page ?: 0 val page = model.page ?: 0
var sampleSize = 1 var sampleSize = 1
if (width > 0 && height > 0) { val customSize = width > 0 && height > 0
if (customSize) {
// determine sample size // determine sample size
val fd = context.contentResolver.openFileDescriptor(uri, "r")?.detachFd() val fd = context.contentResolver.openFileDescriptor(uri, "r")?.detachFd()
if (fd == null) { if (fd == null) {
@ -63,7 +64,7 @@ internal class TiffFetcher(val model: TiffImage, val width: Int, val height: Int
val imageWidth = options.outWidth val imageWidth = options.outWidth
val imageHeight = options.outHeight val imageHeight = options.outHeight
if (imageHeight > height || imageWidth > width) { if (imageHeight > height || imageWidth > width) {
while (imageHeight / (sampleSize * 2) > height && imageWidth / (sampleSize * 2) > width) { while (imageHeight / (sampleSize * 2) >= height && imageWidth / (sampleSize * 2) >= width) {
sampleSize *= 2 sampleSize *= 2
} }
} }
@ -84,6 +85,8 @@ internal class TiffFetcher(val model: TiffImage, val width: Int, val height: Int
val bitmap = TiffBitmapFactory.decodeFileDescriptor(fd, options) val bitmap = TiffBitmapFactory.decodeFileDescriptor(fd, options)
if (bitmap == null) { if (bitmap == null) {
callback.onLoadFailed(Exception("Decoding full TIFF yielded null bitmap")) callback.onLoadFailed(Exception("Decoding full TIFF yielded null bitmap"))
} else if (customSize) {
callback.onDataReady(Bitmap.createScaledBitmap(bitmap, width, height, true))
} else { } else {
callback.onDataReady(bitmap) callback.onDataReady(bitmap)
} }