fixed decoding TIFF to specific size for conversion
This commit is contained in:
parent
ec93b3f21d
commit
c778bd6e9e
2 changed files with 6 additions and 2 deletions
|
@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
- crash when loading some large DNG in viewer
|
||||
- searching from drawer on mobile
|
||||
- resizing TIFF during conversion
|
||||
|
||||
## <a id="v1.10.2"></a>[v1.10.2] - 2023-12-24
|
||||
|
||||
|
|
|
@ -48,7 +48,8 @@ internal class TiffFetcher(val model: TiffImage, val width: Int, val height: Int
|
|||
val page = model.page ?: 0
|
||||
|
||||
var sampleSize = 1
|
||||
if (width > 0 && height > 0) {
|
||||
val customSize = width > 0 && height > 0
|
||||
if (customSize) {
|
||||
// determine sample size
|
||||
val fd = context.contentResolver.openFileDescriptor(uri, "r")?.detachFd()
|
||||
if (fd == null) {
|
||||
|
@ -63,7 +64,7 @@ internal class TiffFetcher(val model: TiffImage, val width: Int, val height: Int
|
|||
val imageWidth = options.outWidth
|
||||
val imageHeight = options.outHeight
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +85,8 @@ internal class TiffFetcher(val model: TiffImage, val width: Int, val height: Int
|
|||
val bitmap = TiffBitmapFactory.decodeFileDescriptor(fd, options)
|
||||
if (bitmap == null) {
|
||||
callback.onLoadFailed(Exception("Decoding full TIFF yielded null bitmap"))
|
||||
} else if (customSize) {
|
||||
callback.onDataReady(Bitmap.createScaledBitmap(bitmap, width, height, true))
|
||||
} else {
|
||||
callback.onDataReady(bitmap)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue