Skip to content

Commit

Permalink
fixed decoding TIFF to specific size for conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Jan 27, 2024
1 parent ec93b3f commit c778bd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}
Expand All @@ -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)
}
Expand Down

0 comments on commit c778bd6

Please sign in to comment.