From b79340989f39a5d58e69617ce7d2470d45d38474 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Mon, 29 Aug 2022 23:02:34 +0600 Subject: [PATCH] Fix IndexOutOfBoundsException when using Split tall images (#7892) Also little cleanup --- .../reader/viewer/webtoon/WebtoonAdapter.kt | 2 +- .../kanade/tachiyomi/util/system/ImageUtil.kt | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt index 4c01839f0..9351008db 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonAdapter.kt @@ -32,7 +32,7 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter val splitPath = splitImagePath(imageFilePath, splitData.index) - val region = Rect(0, splitData.topOffset, splitData.outputImageWidth, splitData.bottomOffset) + val region = Rect(0, splitData.topOffset, splitData.splitWidth, splitData.bottomOffset) FileOutputStream(splitPath).use { outputStream -> val splitBitmap = bitmapRegionDecoder.decodeRegion(region, options) @@ -232,7 +232,7 @@ object ImageUtil { } logcat { "Success: Split #${splitData.index + 1} with topOffset=${splitData.topOffset} " + - "height=${splitData.outputImageHeight} bottomOffset=${splitData.bottomOffset}" + "height=${splitData.splitHeight} bottomOffset=${splitData.bottomOffset}" } } imageFile.delete() @@ -274,15 +274,13 @@ object ImageUtil { logcat { "WebtoonSplit #${splitData.index} with topOffset=${splitData.topOffset} " + - "outputImageHeight=${splitData.outputImageHeight} bottomOffset=${splitData.bottomOffset}" + "splitHeight=${splitData.splitHeight} bottomOffset=${splitData.bottomOffset}" } - val options = extractImageOptions(imageStream).apply { inJustDecodeBounds = false } - - val region = Rect(0, splitData.topOffset, splitData.outputImageWidth, splitData.bottomOffset) + val region = Rect(0, splitData.topOffset, splitData.splitWidth, splitData.bottomOffset) try { - val splitBitmap = bitmapRegionDecoder.decodeRegion(region, options) + val splitBitmap = bitmapRegionDecoder.decodeRegion(region, null) val outputStream = ByteArrayOutputStream() splitBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream) return ByteArrayInputStream(outputStream.toByteArray()) @@ -302,7 +300,7 @@ object ImageUtil { val imageHeight = outHeight val imageWidth = outWidth - val splitHeight = (getDisplayMaxHeightInPx * 1.5).toInt() + val splitHeight = getDisplayMaxHeightInPx * 2 // -1 so it doesn't try to split when imageHeight = splitHeight val partCount = (imageHeight - 1) / splitHeight + 1 val optimalSplitHeight = imageHeight / partCount @@ -334,10 +332,10 @@ object ImageUtil { data class SplitData( val index: Int, val topOffset: Int, - val outputImageHeight: Int, - val outputImageWidth: Int, + val splitHeight: Int, + val splitWidth: Int, ) { - val bottomOffset = topOffset + outputImageHeight + val bottomOffset = topOffset + splitHeight } /**