PagerPageHolder: Move chooseBackground call to IO thread (#5737)

* ImageUtil.chooseBackground: Use built-in decoder

* PagerPageHolder: Move chooseBackground call to IO thread

Also move stuffs and reuse image stream as bytes
This commit is contained in:
Ivan Iskandar
2021-08-19 20:15:45 +07:00
committed by GitHub
parent da16110e1c
commit 11a8046c5f
2 changed files with 28 additions and 21 deletions

View File

@@ -18,7 +18,6 @@ import androidx.core.graphics.green
import androidx.core.graphics.red
import tachiyomi.decoder.Format
import tachiyomi.decoder.ImageDecoder
import tachiyomi.decoder.ImageType
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStream
@@ -181,11 +180,9 @@ object ImageUtil {
* Algorithm for determining what background to accompany a comic/manga page
*/
fun chooseBackground(context: Context, imageStream: InputStream): Drawable {
imageStream.mark(imageStream.available() + 1)
val image = BitmapFactory.decodeStream(imageStream)
imageStream.reset()
val decoder = ImageDecoder.newInstance(imageStream)
val image = decoder?.decode()
decoder?.recycle()
val whiteColor = Color.WHITE
if (image == null) return ColorDrawable(whiteColor)