Fix animated image detection (#5826)

(cherry picked from commit bd033db84c5b7fe2dbb01886f99c0df456b8f930)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt
This commit is contained in:
Ivan Iskandar 2021-09-01 04:43:29 +07:00 committed by Jobobby04
parent 09a6e3661f
commit 44b6983b3d

View File

@ -362,17 +362,17 @@ class PagerPageHolder(
mergePages(stream, stream2) mergePages(stream, stream2)
} }
// SY <-- // SY <--
val bais = ByteArrayInputStream(itemStream.readBytes())
try { try {
val streamBytes = itemStream.readBytes() val isAnimated = ImageUtil.isAnimatedAndSupported(bais)
val isAnimated = ImageUtil.isAnimatedAndSupported(stream) bais.reset()
val background = if (!isAnimated && viewer.config.automaticBackground) { val background = if (!isAnimated && viewer.config.automaticBackground) {
ByteArrayInputStream(streamBytes).use { bais -> ImageUtil.chooseBackground(context, bais)
ImageUtil.chooseBackground(context, bais)
}
} else { } else {
null null
} }
Triple(streamBytes, isAnimated, background) bais.reset()
Triple(bais, isAnimated, background)
} finally { } finally {
stream.close() stream.close()
itemStream.close() itemStream.close()
@ -380,15 +380,15 @@ class PagerPageHolder(
} }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.doOnNext { (streamBytes, isAnimated, background) -> .doOnNext { (bais, isAnimated, background) ->
ByteArrayInputStream(streamBytes).use { bais -> bais.use {
if (!isAnimated) { if (!isAnimated) {
this.background = background this.background = background
initSubsamplingImageView().apply { initSubsamplingImageView().apply {
setImage(ImageSource.inputStream(bais)) setImage(ImageSource.inputStream(it))
} }
} else { } else {
initImageView().setImage(bais) initImageView().setImage(it)
} }
} }
} }