fix(reader): Return the original image if split bitmap failed

This commit is contained in:
Ahmad Ansori Palembani 2024-08-31 21:40:33 +07:00
parent 03043ef01b
commit c1dd80bd71
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -600,6 +600,8 @@ class PagerPageHolder(
scope.launchUI { progressIndicator.completeAndFadeOut() } scope.launchUI { progressIndicator.completeAndFadeOut() }
return imageSource return imageSource
} }
// Try to split
if (page.longPage == true && viewer.config.splitPages) { if (page.longPage == true && viewer.config.splitPages) {
val imageBitmap = try { val imageBitmap = try {
BitmapFactory.decodeStream(imageSource.peek().inputStream()) BitmapFactory.decodeStream(imageSource.peek().inputStream())
@ -608,17 +610,24 @@ class PagerPageHolder(
return imageSource return imageSource
} }
val isLTR = (viewer !is R2LPagerViewer).xor(viewer.config.invertDoublePages) val isLTR = (viewer !is R2LPagerViewer).xor(viewer.config.invertDoublePages)
return ImageUtil.splitBitmap(imageBitmap, (page.firstHalf == false).xor(!isLTR)) { return try {
scope.launchUI { ImageUtil.splitBitmap(imageBitmap, (page.firstHalf == false).xor(!isLTR)) {
if (it == 100) { scope.launchUI {
progressIndicator.completeAndFadeOut() if (it == 100) {
} else { progressIndicator.completeAndFadeOut()
progressIndicator.setProgress(it) } else {
progressIndicator.setProgress(it)
}
} }
} }
} catch (e: NullPointerException) {
Logger.e(e) { "Cannot split page" }
imageSource
} }
} }
if (imageSource2 == null) { if (imageSource2 == null) {
// Detect if page is wide enough to be split
if (viewer.config.splitPages && page.longPage == null) { if (viewer.config.splitPages && page.longPage == null) {
val imageBitmap = try { val imageBitmap = try {
BitmapFactory.decodeStream(imageSource.peek().inputStream()) BitmapFactory.decodeStream(imageSource.peek().inputStream())
@ -663,7 +672,10 @@ class PagerPageHolder(
} }
return supportHingeIfThere(imageSource) return supportHingeIfThere(imageSource)
} }
// Too wide to be merged
if (page.fullPage == true) return supportHingeIfThere(imageSource) if (page.fullPage == true) return supportHingeIfThere(imageSource)
val imageBitmap = try { val imageBitmap = try {
BitmapFactory.decodeStream(imageSource.peek().inputStream()) BitmapFactory.decodeStream(imageSource.peek().inputStream())
} catch (e: Exception) { } catch (e: Exception) {